Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLakshmi Priya Shanmugam2019-04-08 02:28:16 -0400
committerLakshmi Priya Shanmugam2019-04-24 07:56:16 -0400
commit403ccc34cb26f67e4f6b99d69049e216bd322543 (patch)
tree85009bf6465fabd6f005d101441fa53280067168
parentc737dbd0271f9c2b291ca73083f72096c488d674 (diff)
downloadeclipse.platform.swt-403ccc34cb26f67e4f6b99d69049e216bd322543.tar.gz
eclipse.platform.swt-403ccc34cb26f67e4f6b99d69049e216bd322543.tar.xz
eclipse.platform.swt-403ccc34cb26f67e4f6b99d69049e216bd322543.zip
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
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Link.java18
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java41
2 files changed, 58 insertions, 1 deletions
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
@@ -245,6 +246,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);
NSTextView widget = (NSTextView) view;
@@ -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);
}
@@ -763,6 +783,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 ();
if (selection.x != selection.y) {
@@ -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.
* <p>

Back to the top