diff options
author | Till Brychcy | 2017-04-18 21:39:32 +0000 |
---|---|---|
committer | Lakshmi Shanmugam | 2017-09-07 10:40:09 +0000 |
commit | 0650943303854f471afb27787b61aa951ffc6d5e (patch) | |
tree | ae230daae5dae0c52827d223ecb47037d57ad5cf /bundles | |
parent | bb0fbf37910ce31e91c0b4095fcfe53b905817bc (diff) | |
download | eclipse.platform.swt-0650943303854f471afb27787b61aa951ffc6d5e.tar.gz eclipse.platform.swt-0650943303854f471afb27787b61aa951ffc6d5e.tar.xz eclipse.platform.swt-0650943303854f471afb27787b61aa951ffc6d5e.zip |
Bug 505835 - [Cocoa] Button, do not respect foreground and background
color on MAC
Perform custom coloring for Button background.
Change-Id: I34084136e206e08e8a97fe8198720a093abdd589
Signed-off-by: Till Brychcy <register.eclipse@brychcy.de>
Diffstat (limited to 'bundles')
13 files changed, 225 insertions, 4 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c index b1162fdf9a..89fea469ff 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c @@ -379,6 +379,26 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(CALLBACK_1drawBackgroundInClipRect_1) } #endif +#ifndef NO_CALLBACK_1drawBezelWithFrame_1inView_1 +static jintLong CALLBACK_1drawBezelWithFrame_1inView_1; +static void proc_CALLBACK_1drawBezelWithFrame_1inView_1(id arg0, SEL arg1, NSRect arg2, NSView* arg3) { + ((void (*)(id, SEL, NSRect*, NSView*))CALLBACK_1drawBezelWithFrame_1inView_1)(arg0, arg1, &arg2, arg3); +} +static jintLong CALLBACK_drawBezelWithFrame_inView_(jintLong func) { + CALLBACK_1drawBezelWithFrame_1inView_1 = func; + return (jintLong)proc_CALLBACK_1drawBezelWithFrame_1inView_1; +} +JNIEXPORT jintLong JNICALL OS_NATIVE(CALLBACK_1drawBezelWithFrame_1inView_1) + (JNIEnv *env, jclass that, jintLong arg0) +{ + jintLong rc = 0; + OS_NATIVE_ENTER(env, that, CALLBACK_1drawBezelWithFrame_1inView_1_FUNC); + rc = (jintLong)CALLBACK_drawBezelWithFrame_inView_(arg0); + OS_NATIVE_EXIT(env, that, CALLBACK_1drawBezelWithFrame_1inView_1_FUNC); + return rc; +} +#endif + #ifndef NO_CALLBACK_1drawImage_1withFrame_1inView_1 static jintLong CALLBACK_1drawImage_1withFrame_1inView_1; static void proc_CALLBACK_1drawImage_1withFrame_1inView_1(id arg0, SEL arg1, NSImage* arg2, NSRect arg3, NSView* arg4) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.c index 951fa0111e..7573c46376 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.c @@ -34,6 +34,7 @@ char * OS_nativeFunctionNames[] = { "CALLBACK_1draggedImage_1beganAt_1", "CALLBACK_1draggedImage_1endedAt_1operation_1", "CALLBACK_1drawBackgroundInClipRect_1", + "CALLBACK_1drawBezelWithFrame_1inView_1", "CALLBACK_1drawImage_1withFrame_1inView_1", "CALLBACK_1drawInteriorWithFrame_1inView_1", "CALLBACK_1drawLabel_1inRect_1", diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.h index b3aca449a3..be6e54d407 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.h @@ -44,6 +44,7 @@ typedef enum { CALLBACK_1draggedImage_1beganAt_1_FUNC, CALLBACK_1draggedImage_1endedAt_1operation_1_FUNC, CALLBACK_1drawBackgroundInClipRect_1_FUNC, + CALLBACK_1drawBezelWithFrame_1inView_1_FUNC, CALLBACK_1drawImage_1withFrame_1inView_1_FUNC, CALLBACK_1drawInteriorWithFrame_1inView_1_FUNC, CALLBACK_1drawLabel_1inRect_1_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras index d9d49f3248..154fddbb11 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras @@ -552,6 +552,9 @@ <method selector="attributedTitle" swt_gen="true"> <retval swt_gen="true"></retval> </method> + <method selector="bezelStyle" swt_gen="true"> + <retval swt_gen="true"></retval> + </method> <method selector="setAllowsMixedState:" swt_gen="true"> <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> @@ -600,6 +603,11 @@ <method selector="backgroundColor" swt_gen="true"> <retval swt_gen="true"></retval> </method> + <method selector="drawBezelWithFrame:inView:" swt_gen="true" swt_gen_custom_callback="true" swt_gen_super_msgSend="true"> + <arg swt_gen="true"></arg> + <arg swt_gen="true"></arg> + <retval swt_gen="true"></retval> + </method> <method selector="drawImage:withFrame:inView:" swt_gen="true" swt_gen_custom_callback="true" swt_gen_super_msgSend="true"> <arg swt_gen="true"></arg> <arg swt_gen="true"></arg> @@ -1056,6 +1064,9 @@ <method selector="isEnabled" swt_gen="true"> <retval swt_gen="true"></retval> </method> + <method selector="isHighlighted" swt_gen="true"> + <retval swt_gen="true"></retval> + </method> <method selector="sendAction:to:" swt_gen="true"> <arg swt_gen="true"></arg> <arg swt_gen="true"></arg> @@ -1435,11 +1446,20 @@ <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> </method> + <method selector="drawInBezierPath:angle:" swt_gen="true"> + <arg swt_gen="true"></arg> + <arg swt_gen="true"></arg> + <retval swt_gen="true"></retval> + </method> <method selector="drawInRect:angle:" swt_gen="true"> <arg swt_gen="true"></arg> <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> </method> + <method selector="initWithColors:" swt_gen="true"> + <arg swt_gen="true"></arg> + <retval swt_gen="true"></retval> + </method> <method selector="initWithStartingColor:endingColor:" swt_gen="true"> <arg swt_gen="true"></arg> <arg swt_gen="true"></arg> diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSButton.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSButton.java index ac9edf4477..faa83f9e8c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSButton.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSButton.java @@ -29,6 +29,10 @@ public NSAttributedString attributedTitle() { return result != 0 ? new NSAttributedString(result) : null; } +public long /*int*/ bezelStyle() { + return OS.objc_msgSend(this.id, OS.sel_bezelStyle); +} + public void setAllowsMixedState(boolean allowsMixedState) { OS.objc_msgSend(this.id, OS.sel_setAllowsMixedState_, allowsMixedState); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSButtonCell.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSButtonCell.java index f90fa8993a..35b08c299b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSButtonCell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSButtonCell.java @@ -29,6 +29,10 @@ public NSColor backgroundColor() { return result != 0 ? new NSColor(result) : null; } +public void drawBezelWithFrame(NSRect frame, NSView controlView) { + OS.objc_msgSend(this.id, OS.sel_drawBezelWithFrame_inView_, frame, controlView != null ? controlView.id : 0); +} + public void drawImage(NSImage image, NSRect frame, NSView controlView) { OS.objc_msgSend(this.id, OS.sel_drawImage_withFrame_inView_, image != null ? image.id : 0, frame, controlView != null ? controlView.id : 0); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSControl.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSControl.java index bc1fb2a51d..a3525c9d40 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSControl.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSControl.java @@ -59,6 +59,10 @@ public boolean isEnabled() { return OS.objc_msgSend_bool(this.id, OS.sel_isEnabled); } +public boolean isHighlighted() { + return OS.objc_msgSend_bool(this.id, OS.sel_isHighlighted); +} + public boolean sendAction(long /*int*/ theAction, id theTarget) { return OS.objc_msgSend_bool(this.id, OS.sel_sendAction_to_, theAction, theTarget != null ? theTarget.id : 0); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSGradient.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSGradient.java index 25ac9ae263..0cd55d9623 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSGradient.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSGradient.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -28,10 +28,19 @@ public void drawFromPoint(NSPoint startingPoint, NSPoint endingPoint, long /*int OS.objc_msgSend(this.id, OS.sel_drawFromPoint_toPoint_options_, startingPoint, endingPoint, options); } +public void drawInBezierPath(NSBezierPath path, double /*float*/ angle) { + OS.objc_msgSend(this.id, OS.sel_drawInBezierPath_angle_, path != null ? path.id : 0, angle); +} + public void drawInRect(NSRect rect, double /*float*/ angle) { OS.objc_msgSend(this.id, OS.sel_drawInRect_angle_, rect, angle); } +public NSGradient initWithColors(NSArray colorArray) { + long /*int*/ result = OS.objc_msgSend(this.id, OS.sel_initWithColors_, colorArray != null ? colorArray.id : 0); + return result == this.id ? this : (result != 0 ? new NSGradient(result) : null); +} + public NSGradient initWithStartingColor(NSColor startingColor, NSColor endingColor) { long /*int*/ result = OS.objc_msgSend(this.id, OS.sel_initWithStartingColor_endingColor_, startingColor != null ? startingColor.id : 0, endingColor != null ? endingColor.id : 0); return result == this.id ? this : (result != 0 ? new NSGradient(result) : null); diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java index 6e67c413d4..338419fb4b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java @@ -703,6 +703,8 @@ public static final native long /*int*/ CALLBACK_draggedImage_beganAt_(long /*in public static final native long /*int*/ CALLBACK_draggedImage_endedAt_operation_(long /*int*/ func); /** @method callback_types=void;id;SEL;NSRect;,callback_flags=none;none;none;struct; */ public static final native long /*int*/ CALLBACK_drawBackgroundInClipRect_(long /*int*/ func); +/** @method callback_types=void;id;SEL;NSRect;NSView*;,callback_flags=none;none;none;struct;none; */ +public static final native long /*int*/ CALLBACK_drawBezelWithFrame_inView_(long /*int*/ func); /** @method callback_types=void;id;SEL;NSImage*;NSRect;NSView*;,callback_flags=none;none;none;none;struct;none; */ public static final native long /*int*/ CALLBACK_drawImage_withFrame_inView_(long /*int*/ func); /** @method callback_types=void;id;SEL;NSRect;NSView*;,callback_flags=none;none;none;struct;none; */ @@ -1077,6 +1079,7 @@ public static final long /*int*/ sel_beginSheetForWindow_modalDelegate_didEndSel public static final long /*int*/ sel_beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_ = sel_registerName("beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:"); public static final long /*int*/ sel_beginSheetWithPrintInfo_modalForWindow_delegate_didEndSelector_contextInfo_ = sel_registerName("beginSheetWithPrintInfo:modalForWindow:delegate:didEndSelector:contextInfo:"); public static final long /*int*/ sel_bestRepresentationForDevice_ = sel_registerName("bestRepresentationForDevice:"); +public static final long /*int*/ sel_bezelStyle = sel_registerName("bezelStyle"); public static final long /*int*/ sel_bezierPath = sel_registerName("bezierPath"); public static final long /*int*/ sel_bezierPathByFlatteningPath = sel_registerName("bezierPathByFlatteningPath"); public static final long /*int*/ sel_bezierPathWithRect_ = sel_registerName("bezierPathWithRect:"); @@ -1309,9 +1312,11 @@ public static final long /*int*/ sel_drawAtPoint_ = sel_registerName("drawAtPoin public static final long /*int*/ sel_drawAtPoint_fromRect_operation_fraction_ = sel_registerName("drawAtPoint:fromRect:operation:fraction:"); public static final long /*int*/ sel_drawBackgroundForGlyphRange_atPoint_ = sel_registerName("drawBackgroundForGlyphRange:atPoint:"); public static final long /*int*/ sel_drawBackgroundInClipRect_ = sel_registerName("drawBackgroundInClipRect:"); +public static final long /*int*/ sel_drawBezelWithFrame_inView_ = sel_registerName("drawBezelWithFrame:inView:"); public static final long /*int*/ sel_drawFromPoint_toPoint_options_ = sel_registerName("drawFromPoint:toPoint:options:"); public static final long /*int*/ sel_drawGlyphsForGlyphRange_atPoint_ = sel_registerName("drawGlyphsForGlyphRange:atPoint:"); public static final long /*int*/ sel_drawImage_withFrame_inView_ = sel_registerName("drawImage:withFrame:inView:"); +public static final long /*int*/ sel_drawInBezierPath_angle_ = sel_registerName("drawInBezierPath:angle:"); public static final long /*int*/ sel_drawInRect_ = sel_registerName("drawInRect:"); public static final long /*int*/ sel_drawInRect_angle_ = sel_registerName("drawInRect:angle:"); public static final long /*int*/ sel_drawInRect_fromRect_operation_fraction_ = sel_registerName("drawInRect:fromRect:operation:fraction:"); @@ -1444,6 +1449,7 @@ public static final long /*int*/ sel_initWithBitmapDataPlanes_pixelsWide_pixelsH public static final long /*int*/ sel_initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel_ = sel_registerName("initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:"); public static final long /*int*/ sel_initWithCapacity_ = sel_registerName("initWithCapacity:"); public static final long /*int*/ sel_initWithCharacters_length_ = sel_registerName("initWithCharacters:length:"); +public static final long /*int*/ sel_initWithColors_ = sel_registerName("initWithColors:"); public static final long /*int*/ sel_initWithContainerSize_ = sel_registerName("initWithContainerSize:"); public static final long /*int*/ sel_initWithContentRect_styleMask_backing_defer_ = sel_registerName("initWithContentRect:styleMask:backing:defer:"); public static final long /*int*/ sel_initWithContentRect_styleMask_backing_defer_screen_ = sel_registerName("initWithContentRect:styleMask:backing:defer:screen:"); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java index c570ace79c..8055cfef8b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -54,6 +54,8 @@ public class Button extends Control { */ private boolean lastRadioState; + private static final double /*float*/ [] DEFAULT_DISABLED_FOREGROUND = new double /*float*/ [] { 0.6745f, 0.6745f, 0.6745f, 1.0f }; + static final int EXTRA_HEIGHT = 2; static final int EXTRA_WIDTH = 6; static final int IMAGE_GAP = 2; @@ -329,6 +331,108 @@ void drawImageWithFrameInView (long /*int*/ id, long /*int*/ sel, long /*int*/ i super.drawImageWithFrameInView(id, sel, image, rect, view); } +private static NSRect smallerRect (NSRect cellFrame, double dx, double dy1, double dy2, float lineWidth) { + if (lineWidth == 2) { + dx -= 0.5; + dy1 -= 0.5; + dy2 -= 0.5; + } else if (lineWidth == 0.5) { + dx += 0.25; + dy1 += 0.25; + dy2 += 0.25; + } else if (lineWidth == 0.75) { + dx += 0.125; + dy1 += 0.125; + dy2 += 0.125; + } + NSRect result = new NSRect(); + result.x = cellFrame.x + dx; + result.y = cellFrame.y + dy1; + result.width = cellFrame.width - 2 * dx; + result.height = cellFrame.height - dy1 - dy2; + return result; +} + +@Override +void drawBezelWithFrame_inView (long /*int*/ id, long /*int*/ sel, NSRect cellFrame, long /*int*/ viewid) { + if (this.background != null) { + NSButton button = (NSButton) view; + + final boolean isHighlighted = (style & SWT.TOGGLE) == 0 ? button.isHighlighted() : ((NSButton) view).state() == OS.NSOnState; + + final NSWindow window = button.window(); + final NSButtonCell defaultButtonCell = window == null ? null : window.defaultButtonCell(); + final boolean isDefault = defaultButtonCell != null && defaultButtonCell.id == id; + + double /*float*/ [] borderRGB = getLighterOrDarkerColor(this.background, 0.3, luma(background) >= 0.5); + if (isHighlighted && (style & SWT.FLAT) != 0) { + borderRGB = getLighterOrDarkerColor(borderRGB, 0.2, true); + } + + NSGraphicsContext gc = NSGraphicsContext.currentContext(); + gc.saveGraphicsState(); + + NSBezierPath path; + final float lineWidth; + if (isDefault) { + lineWidth = 2f; + } else if ((style & SWT.FLAT) == 0) { + lineWidth = 0.75f; + } else { + lineWidth = 1f; + } + final long bezelStyle = button.bezelStyle(); + if (bezelStyle == OS.NSRoundedBezelStyle) { + NSRect rect2 = smallerRect(cellFrame, 6.5f, 4.5f, 7.5f, lineWidth); + path = NSBezierPath.bezierPathWithRoundedRect(rect2, 3, 3); + } else if (bezelStyle == OS.NSRegularSquareBezelStyle) { + NSRect rect2 = smallerRect(cellFrame, 2.5f, 2.5f, 3.5f, lineWidth); + path = NSBezierPath.bezierPathWithRoundedRect(rect2, 3, 3); + } else { + NSRect rect2 = smallerRect(cellFrame, 0.5f, 0.5f, 0.5f, lineWidth); + path = NSBezierPath.bezierPathWithRect(rect2); + } + if (!isHighlighted) { + double /*float*/ [] backgroundRGB = this.background; + NSColor backgroundNSColor = NSColor.colorWithDeviceRed(backgroundRGB[0], backgroundRGB[1], backgroundRGB[2], 1f); + + if((style & SWT.FLAT) == 0) { + double /*float*/ [] topRGB = getLighterOrDarkerColor(this.background, 0.2, false); + NSColor topColor = NSColor.colorWithDeviceRed(topRGB[0], topRGB[1], topRGB[2], 1f); + double /*float*/ [] bottomRGB = getLighterOrDarkerColor(this.background, 0.1, true); + NSColor bottomColor = NSColor.colorWithDeviceRed(bottomRGB[0], bottomRGB[1], bottomRGB[2], 1f); + + NSMutableArray ma = NSMutableArray.arrayWithCapacity(4); + ma.addObject(topColor); + ma.addObject(backgroundNSColor); + ma.addObject(backgroundNSColor); + ma.addObject(bottomColor); + NSGradient gradient = ((NSGradient) new NSGradient().alloc()).initWithColors(ma); + gradient.drawInBezierPath(path, 90); + gradient.release(); + } else { + backgroundNSColor.setFill(); + path.fill(); + } + } else { + double /*float*/ [] colorRGB0 = getLighterOrDarkerColor(this.background, 0.1f, true); + NSColor color0 = NSColor.colorWithDeviceRed(colorRGB0[0], colorRGB0[1], colorRGB0[2], 1f); + color0.setFill(); + path.fill(); + } + + // draw border + path.setLineWidth(lineWidth); + NSColor borderNSColor = NSColor.colorWithDeviceRed(borderRGB[0], borderRGB[1], borderRGB[2], 1f); + borderNSColor.setStroke(); + path.stroke(); + + gc.restoreGraphicsState(); + return; + } + super.drawBezelWithFrame_inView(id, sel, cellFrame, viewid); +} + @Override void drawInteriorWithFrame_inView (long /*int*/ id, long /*int*/ sel, NSRect cellRect, long /*int*/ viewid) { if ((style & (SWT.CHECK|SWT.RADIO)) != 0 && backgroundImage != null) { @@ -372,11 +476,20 @@ void drawInteriorWithFrame_inView (long /*int*/ id, long /*int*/ sel, NSRect cel @Override NSRect drawTitleWithFrameInView (long /*int*/ id, long /*int*/ sel, long /*int*/ title, NSRect titleRect, long /*int*/ view) { boolean wrap = (style & SWT.WRAP) != 0 && text.length() != 0; + boolean isEnabled = isEnabled(); if (wrap) { NSSize wrapSize = new NSSize(); wrapSize.width = titleRect.width; wrapSize.height = MAX_SIZE; - NSAttributedString attribStr = createString(text, null, foreground, style, true, true, true); + final double[] foreground2; + if (isEnabled) { + foreground2 = foreground; + } else if (foreground == null) { + foreground2 = DEFAULT_DISABLED_FOREGROUND; + } else { + foreground2 = getLighterOrDarkerColor(foreground, 0.5, luma(foreground) >= 0.5); + } + NSAttributedString attribStr = createString(text, null, foreground2, style, true, true, true); NSRect rect = attribStr.boundingRectWithSize(wrapSize, OS.NSStringDrawingUsesLineFragmentOrigin); switch (style & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) { case SWT.LEFT: @@ -394,6 +507,12 @@ NSRect drawTitleWithFrameInView (long /*int*/ id, long /*int*/ sel, long /*int*/ attribStr.release (); return rect; } + if (!isEnabled && foreground != null) { + NSAttributedString attribStr = createString(text, null, getLighterOrDarkerColor(foreground, 0.5, luma(foreground) >= 0.5), style, false, true, true); + final NSRect result = super.drawTitleWithFrameInView(id, sel, attribStr.id, titleRect, view); + attribStr.release(); + return result; + } return super.drawTitleWithFrameInView(id, sel, title, titleRect, view); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java index 9cc52654fe..fc65b4ba6a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java @@ -5206,4 +5206,28 @@ void updateLayout (boolean all) { /* Do nothing */ } +static double /*float*/ calcDiff (double /*float*/ component, double /*float*/ factor, boolean wantDarker) { + if (wantDarker) { + return component * -1 * factor; + } else { + return (1f - component) * factor; + } +} + +static double /*float*/ [] getLighterOrDarkerColor (double /*float*/ [] pixel, double /*float*/ factor, boolean wantDarker) { + double /*float*/ red = pixel[0]; + double /*float*/ green = pixel[1]; + double /*float*/ blue = pixel[2]; + red += calcDiff(red, factor, wantDarker); + green += calcDiff(green, factor, wantDarker); + blue += calcDiff(blue, factor, wantDarker); + return new double /*float*/ [] { red, green, blue, pixel[3] }; +} + +/** + * @return luma according to ITU BT.709: Y = 0.2126 R + 0.7152 G + 0.0722 B + */ +static double luma (double[] rgbColor) { + return 0.2126f * rgbColor[0] + 0.7152f * rgbColor[1] + 0.0722f * rgbColor[2]; +} } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java index e9f51eac3a..d02bab3441 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -2447,6 +2447,7 @@ void initClasses () { long /*int*/ isFlippedProc = OS.isFlipped_CALLBACK(); long /*int*/ drawRectProc = OS.CALLBACK_drawRect_(proc3); long /*int*/ drawInteriorWithFrameInViewProc = OS.CALLBACK_drawInteriorWithFrame_inView_ (proc4); + long /*int*/ drawBezelWithFrameInViewProc = OS.CALLBACK_drawBezelWithFrame_inView_ (proc4); long /*int*/ drawWithExpansionFrameProc = OS.CALLBACK_drawWithExpansionFrame_inView_ (proc4); long /*int*/ imageRectForBoundsProc = OS.CALLBACK_imageRectForBounds_ (proc3); long /*int*/ titleRectForBoundsProc = OS.CALLBACK_titleRectForBounds_ (proc3); @@ -2514,6 +2515,7 @@ void initClasses () { OS.class_addMethod (cls, OS.sel_drawImage_withFrame_inView_, drawImageWithFrameInViewProc, "@:@{NSRect}@"); OS.class_addMethod (cls, OS.sel_drawTitle_withFrame_inView_, drawTitleWithFrameInViewProc, "@:@{NSRect}@"); OS.class_addMethod(cls, OS.sel_drawInteriorWithFrame_inView_, drawInteriorWithFrameInViewProc, "@:{NSRect}@"); + OS.class_addMethod(cls, OS.sel_drawBezelWithFrame_inView_, drawBezelWithFrameInViewProc, "@:{NSRect}@"); OS.class_addMethod(cls, OS.sel_titleRectForBounds_, titleRectForBoundsProc, "@:{NSRect}"); OS.class_addMethod(cls, OS.sel_cellSizeForBounds_, cellSizeForBoundsProc, "@:{NSRect}"); if (OS.VERSION_MMB >= OS.VERSION_MMB(10, 10, 0)) { @@ -6061,6 +6063,10 @@ static long /*int*/ windowProc(long /*int*/ id, long /*int*/ sel, long /*int*/ a NSRect rect = new NSRect(); OS.memmove(rect, arg0, NSRect.sizeof); widget.drawWithExpansionFrame_inView (id, sel, rect, arg1); + } else if (sel == OS.sel_drawBezelWithFrame_inView_) { + NSRect rect = new NSRect (); + OS.memmove (rect, arg0, NSRect.sizeof); + widget.drawBezelWithFrame_inView (id, sel, rect, arg1); } else if (sel == OS.sel_accessibilityAttributeValue_forParameter_) { return widget.accessibilityAttributeValue_forParameter(id, sel, arg0, arg1); } else if (sel == OS.sel_tableView_didClickTableColumn_) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java index 8b54afb794..9d14565027 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java @@ -732,6 +732,9 @@ void drawInteriorWithFrame_inView (long /*int*/ id, long /*int*/ sel, NSRect cel callSuper(id, sel, cellFrame, view); } +void drawBezelWithFrame_inView (long /*int*/ id, long /*int*/ sel, NSRect cellFrame, long /*int*/ view) { + callSuper(id, sel, cellFrame, view); +} void drawLabelInRect(long /*int*/ id, long /*int*/ sel, boolean shouldTruncateLabel, NSRect rect) { objc_super super_struct = new objc_super(); |