11/*******************************************************************************
2- * Copyright (c) 2000, 2026 IBM Corporation and others.
2+ * Copyright (c) 2000, 2021 IBM Corporation and others.
33 *
44 * This program and the accompanying materials
55 * are made available under the terms of the Eclipse Public License 2.0
@@ -149,7 +149,7 @@ public class StyledText extends Canvas {
149149 /** False iff the widget is disabled */
150150 boolean enabled = true ;
151151 /** True iff the widget is in the midst of being enabled or disabled */
152- boolean insideUpdateColorsCall ;
152+ boolean insideSetEnableCall ;
153153 Clipboard clipboard ;
154154 int clickCount ;
155155 int autoScrollDirection = SWT .NULL ; // the direction of autoscrolling (up, down, right, left)
@@ -8278,7 +8278,7 @@ public void setBackground(Color color) {
82788278 boolean backgroundDisabled = false ;
82798279 if (!this .enabled && color == null ) {
82808280 if (background != null ) {
8281- Color disabledBg = getDisplay ().getSystemColor (SWT .COLOR_WIDGET_DISABLED_FOREGROUND );
8281+ Color disabledBg = getDisplay ().getSystemColor (SWT .COLOR_TEXT_DISABLED_BACKGROUND );
82828282 if (background .equals (disabledBg )) {
82838283 return ;
82848284 } else {
@@ -8287,13 +8287,11 @@ public void setBackground(Color color) {
82878287 }
82888288 }
82898289 }
8290- customBackground = color != null && !this .insideUpdateColorsCall && !backgroundDisabled ;
8290+ customBackground = color != null && !this .insideSetEnableCall && !backgroundDisabled ;
82918291 background = color ;
82928292 super .setBackground (color );
8293- if (content != null ) {
8294- resetCache (0 , content .getLineCount ());
8295- setCaretLocations ();
8296- }
8293+ resetCache (0 , content .getLineCount ());
8294+ setCaretLocations ();
82978295 super .redraw ();
82988296}
82998297/**
@@ -8774,35 +8772,6 @@ public void setDragDetect (boolean dragDetect) {
87748772 checkWidget ();
87758773 this .dragDetect = dragDetect ;
87768774}
8777-
8778- /**
8779- * Applies foreground and background colors based on the control's state.
8780- * Custom foreground and background settings are preserved and not overridden.
8781- *
8782- * @param enabled {@code true} if the control is enabled; {@code false} otherwise
8783- * @param editable {@code true} if the control is editable; {@code false} otherwise
8784- *
8785- */
8786- private void updateColors (boolean enabled , boolean editable ) {
8787- this .insideUpdateColorsCall = true ;
8788- Display display = getDisplay ();
8789- try {
8790- if (enabled && editable ) {
8791- if (!customBackground ) setBackground (display .getSystemColor (SWT .COLOR_LIST_BACKGROUND ));
8792- if (!customForeground ) setForeground (display .getSystemColor (SWT .COLOR_LIST_FOREGROUND ));
8793- } else if (!enabled ) {
8794- if (!customBackground ) setBackground (display .getSystemColor (SWT .COLOR_WIDGET_DISABLED_FOREGROUND ));
8795- if (!customForeground ) setForeground (display .getSystemColor (SWT .COLOR_DARK_GRAY ));
8796- } else if (!editable ) {
8797- if (!customBackground ) setBackground (display .getSystemColor (SWT .COLOR_WIDGET_DISABLED_FOREGROUND ));
8798- if (!customForeground ) setForeground (display .getSystemColor (SWT .COLOR_LIST_FOREGROUND ));
8799- }
8800- }
8801- finally {
8802- this .insideUpdateColorsCall = false ;
8803- }
8804- }
8805-
88068775/**
88078776 * Sets whether the widget content can be edited.
88088777 *
@@ -8816,13 +8785,28 @@ private void updateColors(boolean enabled, boolean editable) {
88168785public void setEditable (boolean editable ) {
88178786 checkWidget ();
88188787 this .editable = editable ;
8819- updateColors (this .enabled , this .editable );
88208788}
88218789@ Override
88228790public void setEnabled (boolean enabled ) {
88238791 super .setEnabled (enabled );
8792+ Display display = getDisplay ();
88248793 this .enabled = enabled ;
8825- updateColors (this .enabled , this .editable );
8794+ this .insideSetEnableCall = true ;
8795+ try {
8796+ if (enabled && editable ) {
8797+ if (!customBackground ) setBackground (display .getSystemColor (SWT .COLOR_LIST_BACKGROUND ));
8798+ if (!customForeground ) setForeground (display .getSystemColor (SWT .COLOR_LIST_FOREGROUND ));
8799+ } else if (!enabled ) {
8800+ if (!customBackground ) setBackground (display .getSystemColor (SWT .COLOR_TEXT_DISABLED_BACKGROUND ));
8801+ if (!customForeground ) setForeground (display .getSystemColor (SWT .COLOR_WIDGET_DISABLED_FOREGROUND ));
8802+ } else if (!editable ) {
8803+ if (!customBackground ) setBackground (display .getSystemColor (SWT .COLOR_TEXT_DISABLED_BACKGROUND ));
8804+ if (!customForeground ) setForeground (display .getSystemColor (SWT .COLOR_LIST_FOREGROUND ));
8805+ }
8806+ }
8807+ finally {
8808+ this .insideSetEnableCall = false ;
8809+ }
88268810}
88278811
88288812@ Override
@@ -8889,7 +8873,7 @@ public void setForeground(Color color) {
88898873 boolean foregroundDisabled = false ;
88908874 if (!this .enabled && color == null ) {
88918875 if (foreground != null ) {
8892- Color disabledFg = getDisplay ().getSystemColor (SWT .COLOR_DARK_GRAY );
8876+ Color disabledFg = getDisplay ().getSystemColor (SWT .COLOR_WIDGET_DISABLED_FOREGROUND );
88938877 if (foreground .equals (disabledFg )) {
88948878 return ;
88958879 } else {
@@ -8898,13 +8882,11 @@ public void setForeground(Color color) {
88988882 }
88998883 }
89008884 }
8901- customForeground = color != null && !this .insideUpdateColorsCall && !foregroundDisabled ;
8885+ customForeground = color != null && !this .insideSetEnableCall && !foregroundDisabled ;
89028886 foreground = color ;
89038887 super .setForeground (color );
8904- if (content != null ) {
8905- resetCache (0 , content .getLineCount ());
8906- setCaretLocations ();
8907- }
8888+ resetCache (0 , content .getLineCount ());
8889+ setCaretLocations ();
89088890 super .redraw ();
89098891}
89108892/**
0 commit comments