Skip to content

Commit 0f991b5

Browse files
BeckerWdfakurtakov
authored andcommitted
Revert "Compute fg and bg colors for setEditable for StyledText"
This reverts commit 52b0611.
1 parent 3566233 commit 0f991b5

2 files changed

Lines changed: 30 additions & 48 deletions

File tree

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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) {
88168785
public void setEditable(boolean editable) {
88178786
checkWidget();
88188787
this.editable = editable;
8819-
updateColors(this.enabled, this.editable);
88208788
}
88218789
@Override
88228790
public 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
/**

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2026 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 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
@@ -3245,8 +3245,8 @@ public void test_setDoubleClickEnabledZ(){
32453245
@Test
32463246
public void test_setEnabled(){
32473247
// Get colors
3248-
Color disabledBg = text.getDisplay().getSystemColor(SWT.COLOR_WIDGET_DISABLED_FOREGROUND);
3249-
Color disabledFg = text.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY);
3248+
Color disabledBg = text.getDisplay().getSystemColor(SWT.COLOR_TEXT_DISABLED_BACKGROUND);
3249+
Color disabledFg = text.getDisplay().getSystemColor(SWT.COLOR_WIDGET_DISABLED_FOREGROUND);
32503250
Color enabledBg = text.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
32513251
Color enabledFg = text.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
32523252

0 commit comments

Comments
 (0)