Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Williams2019-05-03 13:51:43 +0000
committerEric Williams2019-08-06 13:43:09 +0000
commit6f7a89a9aab424b92bc846d66939ab93a4ea38d7 (patch)
tree857a42c64a33e993b0470c301f8638bb49221091 /bundles
parentf3664c83ee537adc3df5ea4f3f151cbdf0f47281 (diff)
downloadeclipse.platform.swt-6f7a89a9aab424b92bc846d66939ab93a4ea38d7.tar.gz
eclipse.platform.swt-6f7a89a9aab424b92bc846d66939ab93a4ea38d7.tar.xz
eclipse.platform.swt-6f7a89a9aab424b92bc846d66939ab93a4ea38d7.zip
Bug 4745: [StyledText] StyledText does not provide a disabled look
(1GG00JX) Set background/foreground colors to COLOR_TEXT_DISABLED_BACKGROUND and COLOR_WIDGET_DISABLED_FOREGROUND respectively, to provide a disabled look when StyledText.setEnabled(false) is called. The behaves the same way as the Text widget on GTK does. Change-Id: Id0325993c6206cc660568bff9d094df514194e88 Signed-off-by: Eric Williams <ericwill@redhat.com>
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java52
1 files changed, 51 insertions, 1 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
index 676bc7ff1d..0762e3f3ae 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
@@ -137,6 +137,14 @@ public class StyledText extends Canvas {
Map<Integer, Integer> keyActionMap = new HashMap<>();
Color background = null; // workaround for bug 4791
Color foreground = null; //
+ /** True if a non-default background color is set */
+ boolean customBackground;
+ /** True if a non-default foreground color is set */
+ boolean customForeground;
+ /** False iff the widget is disabled */
+ boolean enabled = true;
+ /** True iff the widget is in the midst of being enabled or disabled */
+ boolean insideSetEnableCall;
Clipboard clipboard;
int clickCount;
int autoScrollDirection = SWT.NULL; // the direction of autoscrolling (up, down, right, left)
@@ -8490,6 +8498,19 @@ public void setAlwaysShowScrollBars(boolean show) {
@Override
public void setBackground(Color color) {
checkWidget();
+ boolean backgroundDisabled = false;
+ if (!this.enabled && color == null) {
+ if (background != null) {
+ Color disabledBg = getDisplay().getSystemColor(SWT.COLOR_TEXT_DISABLED_BACKGROUND);
+ if (background.equals(disabledBg)) {
+ return;
+ } else {
+ color = new Color (getDisplay(), disabledBg.getRGBA());
+ backgroundDisabled = true;
+ }
+ }
+ }
+ customBackground = color != null && !this.insideSetEnableCall && !backgroundDisabled;
background = color;
super.setBackground(color);
resetCache(0, content.getLineCount());
@@ -8934,6 +8955,22 @@ public void setEditable(boolean editable) {
checkWidget();
this.editable = editable;
}
+@Override
+public void setEnabled (boolean enabled) {
+ super.setEnabled(enabled);
+ Display display = getDisplay();
+ this.enabled = enabled;
+ this.insideSetEnableCall = true;
+ if (enabled) {
+ if (!customBackground) setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
+ if (!customForeground) setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
+ } else {
+ setSelectionRange(0,0);
+ if (!customBackground) setBackground(display.getSystemColor(SWT.COLOR_TEXT_DISABLED_BACKGROUND));
+ if (!customForeground) setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DISABLED_FOREGROUND));
+ }
+ this.insideSetEnableCall = false;
+}
/**
* Sets a new font to render text with.
* <p>
@@ -8972,8 +9009,21 @@ public void setFont(Font font) {
@Override
public void setForeground(Color color) {
checkWidget();
+ boolean foregroundDisabled = false;
+ if (!this.enabled && color == null) {
+ if (foreground != null) {
+ Color disabledFg = getDisplay().getSystemColor(SWT.COLOR_WIDGET_DISABLED_FOREGROUND);
+ if (foreground.equals(disabledFg)) {
+ return;
+ } else {
+ color = new Color (getDisplay(), disabledFg.getRGBA());
+ foregroundDisabled = true;
+ }
+ }
+ }
+ customForeground = color != null && !this.insideSetEnableCall && !foregroundDisabled;
foreground = color;
- super.setForeground(getForeground());
+ super.setForeground(color);
resetCache(0, content.getLineCount());
setCaretLocation();
super.redraw();

Back to the top