diff options
author | Silenio Quarti <silenio> | 2009-04-24 13:24:25 +0000 |
---|---|---|
committer | Silenio Quarti <silenio> | 2009-04-24 13:24:25 +0000 |
commit | 93fa386b571c6e17acc445bb35eb7c1c0ea981f1 (patch) | |
tree | 9719c51f2a0ed976b5a0f35478a5c12972455c11 /bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse | |
parent | 7725eb2962b0d3a5fc612d5b65dd477808281b50 (diff) | |
download | eclipse.platform.swt-93fa386b571c6e17acc445bb35eb7c1c0ea981f1.tar.gz eclipse.platform.swt-93fa386b571c6e17acc445bb35eb7c1c0ea981f1.tar.xz eclipse.platform.swt-93fa386b571c6e17acc445bb35eb7c1c0ea981f1.zip |
273313 - [carbon] Control#getBackground() and getForeground() returns new Color
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse')
12 files changed, 43 insertions, 44 deletions
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 56e5453d05..a958e0a3de 100755 --- 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 @@ -621,8 +621,7 @@ void updateBackground () { if (backgroundImage != null) { nsColor = NSColor.colorWithPatternImage(backgroundImage.handle); } else if (background != null) { - float /*double*/ [] color = background.handle; - nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); + nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]); } else { return; // TODO set to OS default } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Combo.java index ce1cc3319e..e725b4e8e4 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Combo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Combo.java @@ -1254,8 +1254,7 @@ void updateBackground () { if (backgroundImage != null) { nsColor = NSColor.colorWithPatternImage(backgroundImage.handle); } else if (background != null) { - float /*double*/ [] color = background.handle; - nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); + nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]); } else { nsColor = NSColor.textBackgroundColor (); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java index 0c13b96fb0..ab8e9b2259 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java @@ -493,7 +493,7 @@ public boolean isLayoutDeferred () { boolean isOpaque (int /*long*/ id, int /*long*/ sel) { if ((state & CANVAS) != 0) { if (id == view.id) { - if (region == null && background != null && background.handle[3] == 1) { + if (region == null && background != null && background[3] == 1) { return true; } } 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 3e17ddaf61..aca4b58853 100755 --- 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 @@ -56,7 +56,7 @@ public abstract class Control extends Widget implements Drawable { Object layoutData; int drawCount; Menu menu; - Color foreground, background; + float /*double*/ [] foreground, background; Image backgroundImage; Font font; Cursor cursor; @@ -823,14 +823,14 @@ NSView contentView () { return view; } -NSAttributedString createString (String string, Font font, Color foreground, int style, boolean enabled, boolean mnemonics) { +NSAttributedString createString (String string, Font font, float /*double*/ [] foreground, int style, boolean enabled, boolean mnemonics) { NSMutableDictionary dict = ((NSMutableDictionary)new NSMutableDictionary().alloc()).initWithCapacity(5); if (font == null) font = this.font != null ? this.font : defaultFont(); dict.setObject (font.handle, OS.NSFontAttributeName); addTraits(dict, font); if (enabled) { if (foreground != null) { - NSColor color = NSColor.colorWithDeviceRed(foreground.handle[0], foreground.handle[1], foreground.handle[2], foreground.handle[3]); + NSColor color = NSColor.colorWithDeviceRed(foreground[0], foreground[1], foreground[2], foreground[3]); dict.setObject (color, OS.NSForegroundColorAttributeName); } } else { @@ -1105,6 +1105,16 @@ void enableWidget (boolean enabled) { updateCursorRects (isEnabled ()); } +boolean equals(float /*double*/ [] color1, float /*double*/ [] color2) { + if (color1 == color2) return true; + if (color1 == null) return color2 == null; + if (color2 == null) return color1 == null; + for (int i = 0; i < color1.length; i++) { + if (color1 [i] != color2 [i]) return false; + } + return true; +} + NSView eventView () { if (!fetchedEventView) { cachedEventView = (NSView)display.getData(Display.EVENT_VIEW_KEY); @@ -1139,17 +1149,16 @@ void fillBackground (NSView view, NSGraphicsContext context, NSRect rect, int im return; } - Color background = control.background; + float /*double*/ [] background = control.background; float /*double*/ alpha; - if (background == null || background.isDisposed ()) { - background = control.defaultBackground (); + if (background == null) { + background = control.defaultBackground ().handle; alpha = getThemeAlpha (); } else { - alpha = background.handle[3]; + alpha = background[3]; } - float /*double*/ [] color = background.handle; context.saveGraphicsState (); - NSColor.colorWithDeviceRed (color [0], color [1], color [2], alpha).setFill (); + NSColor.colorWithDeviceRed (background [0], background [1], background [2], alpha).setFill (); NSBezierPath.fillRect (rect); context.restoreGraphicsState (); } @@ -1301,7 +1310,7 @@ public Color getBackground () { } Color getBackgroundColor () { - return background != null ? background : defaultBackground (); + return background != null ? Color.cocoa_new (display, background) : defaultBackground (); } /** @@ -1451,7 +1460,7 @@ public Color getForeground () { } Color getForegroundColor () { - return foreground != null ? foreground: defaultForeground (); + return foreground != null ? Color.cocoa_new (display, foreground) : defaultForeground (); } /** @@ -2985,10 +2994,11 @@ public void setBackground (Color color) { if (color != null) { if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); } -// if (equals (background, this.background)) return; - this.background = color; + float /*double*/ [] background = color != null ? color.handle : null; + if (equals (background, this.background)) return; + this.background = background; updateBackground (); - view.setNeedsDisplay(true); + redrawWidget(view, true); } /** @@ -3293,10 +3303,11 @@ public void setForeground (Color color) { if (color != null) { if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); } -// if (equals (foreground, this.foreground)) return; - this.foreground = color; - setForeground (color != null ? color.handle : null); - view.setNeedsDisplay(true); + float /*double*/ [] foreground = color != null ? color.handle : null; + if (equals (foreground, this.foreground)) return; + this.foreground = foreground; + setForeground (foreground); + redrawWidget (view, false); } void setForeground (float /*double*/ [] color) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/DateTime.java index 76a8257c76..929be27a65 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/DateTime.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/DateTime.java @@ -336,8 +336,7 @@ void updateBackground () { if (backgroundImage != null) { nsColor = NSColor.colorWithPatternImage(backgroundImage.handle); } else if (background != null) { - float /*double*/ [] color = background.handle; - nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); + nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]); } else { if ((style & SWT.CALENDAR) != 0) { nsColor = NSColor.controlBackgroundColor (); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java index 97a6e9629b..0f22a2c794 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java @@ -400,8 +400,7 @@ void updateBackground () { if (backgroundImage != null) { nsColor = NSColor.colorWithPatternImage(backgroundImage.handle); } else if (background != null) { - float /*double*/ [] color = background.handle; - nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); + nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]); } else { nsColor = NSColor.clearColor(); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Link.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Link.java index 2430ecd3f0..9ff36907f6 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Link.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Link.java @@ -188,7 +188,7 @@ void enableWidget (boolean enabled) { if (foreground == null) { nsColor = NSColor.textColor (); } else { - nsColor = NSColor.colorWithDeviceRed (foreground.handle [0], foreground.handle [1], foreground.handle [2], 1); + nsColor = NSColor.colorWithDeviceRed (foreground [0], foreground [1], foreground [2], foreground[3]); } } else { nsColor = NSColor.disabledControlTextColor(); @@ -417,8 +417,7 @@ void updateBackground () { if (backgroundImage != null) { nsColor = NSColor.colorWithPatternImage(backgroundImage.handle); } else if (background != null) { - float /*double*/ [] color = background.handle; - nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); + nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]); } setBackground(nsColor); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/List.java index 3f7881d370..186c48ec3a 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/List.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/List.java @@ -1099,8 +1099,7 @@ void updateBackground () { if (backgroundImage != null) { nsColor = NSColor.colorWithPatternImage(backgroundImage.handle); } else if (background != null) { - float /*double*/ [] color = background.handle; - nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); + nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]); } ((NSTableView) view).setBackgroundColor (nsColor); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Spinner.java index d6a78cc046..ac42a12411 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Spinner.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Spinner.java @@ -683,8 +683,7 @@ void updateBackground () { if (backgroundImage != null) { nsColor = NSColor.colorWithPatternImage(backgroundImage.handle); } else if (background != null) { - float /*double*/ [] color = background.handle; - nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); + nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]); } else { nsColor = NSColor.textBackgroundColor (); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java index 060d3b1f56..6b18586fce 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java @@ -2209,8 +2209,7 @@ void updateBackground () { if (backgroundImage != null) { nsColor = NSColor.colorWithPatternImage(backgroundImage.handle); } else if (background != null) { - float /*double*/ [] color = background.handle; - nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); + nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]); } ((NSTableView) view).setBackgroundColor (nsColor); } @@ -2959,8 +2958,7 @@ void tableView_willDisplayCell_forTableColumn_row (int /*long*/ id, int /*long*/ } else { Color foreground = item.cellForeground != null ? item.cellForeground [index] : null; if (foreground == null) foreground = item.foreground; - if (foreground == null) foreground = this.foreground; - if (foreground == null) foreground = defaultForeground(); + if (foreground == null) foreground = getForegroundColor(); color = NSColor.colorWithDeviceRed (foreground.handle [0], foreground.handle [1], foreground.handle [2], 1); } } else { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java index 39bb308107..b4eeab0da2 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java @@ -1426,8 +1426,7 @@ void updateBackground () { if (backgroundImage != null) { nsColor = NSColor.colorWithPatternImage(backgroundImage.handle); } else if (background != null) { - float /*double*/ [] color = background.handle; - nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); + nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]); } else { nsColor = NSColor.textBackgroundColor (); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java index f1ba5d94e9..546bab582e 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java @@ -1955,8 +1955,7 @@ void outlineView_willDisplayCell_forTableColumn_item (int /*long*/ id, int /*lon } else { Color foreground = item.cellForeground != null ? item.cellForeground [index] : null; if (foreground == null) foreground = item.foreground; - if (foreground == null) foreground = this.foreground; - if (foreground == null) foreground = defaultForeground(); + if (foreground == null) foreground = getForegroundColor (); color = NSColor.colorWithDeviceRed (foreground.handle [0], foreground.handle [1], foreground.handle [2], 1); } } else { @@ -2359,8 +2358,7 @@ void updateBackground () { if (backgroundImage != null) { nsColor = NSColor.colorWithPatternImage(backgroundImage.handle); } else if (background != null) { - float /*double*/ [] color = background.handle; - nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); + nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]); } ((NSOutlineView) view).setBackgroundColor (nsColor); } |