From 403ccc34cb26f67e4f6b99d69049e216bd322543 Mon Sep 17 00:00:00 2001 From: Lakshmi Priya Shanmugam Date: Mon, 8 Apr 2019 11:58:16 +0530 Subject: Bug 540357 - [10.14] Make SWT adapt to switching to dark mode (and back) Widgets should have correct foreground, background colors in the Dark mode. Set default foreground color for Link and Multi-style text. Update multi-style text background color. Change-Id: I49eaee8064edddba3c2e751dd3450b74d02ecacc --- .../cocoa/org/eclipse/swt/widgets/Link.java | 18 ++++++++++ .../cocoa/org/eclipse/swt/widgets/Text.java | 41 +++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) 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 4a7ebb55dd..f0481692ab 100644 --- 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 @@ -19,6 +19,7 @@ import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.cocoa.*; +import org.eclipse.swt.widgets.Display.*; /** * Instances of this class represent a selectable @@ -244,6 +245,14 @@ void drawBackground (long /*int*/ id, NSGraphicsContext context, NSRect rectangl } } +@Override +void drawRect(long id, long sel, NSRect rect) { + super.drawRect(id, sel, rect); + if (display.appAppearance == APPEARANCE.Dark) { + setDefaultForeground(); + } +} + @Override void enableWidget (boolean enabled) { super.enableWidget (enabled); @@ -661,6 +670,15 @@ void setBackgroundImage(NSImage image) { ((NSTextView) view).setDrawsBackground(image == null); } +void setDefaultForeground() { + if (foreground != null) return; + if (getEnabled ()) { + ((NSTextView) view).setTextColor (NSColor.textColor ()); + } else { + ((NSTextView) view).setTextColor (NSColor.disabledControlTextColor ()); + } +} + @Override void setFont(NSFont font) { ((NSTextView) view).setFont(font); 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 450ddaf4da..42be5acb25 100644 --- 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 @@ -17,6 +17,7 @@ import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.internal.cocoa.*; +import org.eclipse.swt.widgets.Display.*; /** * Instances of this class are selectable user interface @@ -687,8 +688,27 @@ void drawBackground (long /*int*/ id, NSGraphicsContext context, NSRect rect) { NSText text = new NSText(id); if (!text.isFieldEditor()) return; } + } else if ((style & SWT.MULTI) != 0) { + if (id != scrollView.id) return; + + /* + * If background image has to be set, call fillBackground(). Else, set background color + * here directly on the NSTextView and return. + */ + if (backgroundImage == null) { + double /*float*/ [] background = this.background; + double /*float*/ alpha; + if (background == null) { + background = defaultBackground ().handle; + alpha = getThemeAlpha (); + } else { + alpha = background[3]; + } + NSColor nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], alpha); + ((NSTextView) view).setBackgroundColor(nsColor); + return; + } } - if ((style & SWT.MULTI) != 0 && id != scrollView.id) return; fillBackground (view, context, rect, -1); } @@ -762,6 +782,14 @@ void drawInteriorWithFrame_inView_searchfield (long /*int*/ id, long /*int*/ sel } } +@Override +void drawRect(long id, long sel, NSRect rect) { + super.drawRect(id, sel, rect); + if (display.appAppearance == APPEARANCE.Dark) { + setDefaultForeground(); + } +} + @Override boolean dragDetect (int x, int y, boolean filter, boolean [] consume) { Point selection = getSelection (); @@ -1792,6 +1820,17 @@ void setBackgroundImage(NSImage image) { } } +void setDefaultForeground() { + if ((style & SWT.MULTI) != 0) { + if (foreground != null) return; + if (getEnabled ()) { + ((NSTextView) view).setTextColor (NSColor.textColor ()); + } else { + ((NSTextView) view).setTextColor (NSColor.disabledControlTextColor ()); + } + } +} + /** * Sets the double click enabled flag. *

-- cgit v1.2.3