Skip to content

Commit 18583c9

Browse files
committed
Compute foreground and background colors for both setEnabled and
setEditable the foreground and background colors were computed only for setEnabled. This has to be done for setEditable as well to achieve consistency. This commit adds the same update to setEditable function as well. The background color and foreground color for the styled text when the background is not editable doesn't differentiate anything. This commit also adds a different foreground and background color combination.This improves visual differentiation in StyledText. Fixes :#3132
1 parent cc104be commit 18583c9

1 file changed

Lines changed: 44 additions & 21 deletions

File tree

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

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

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8290,8 +8290,10 @@ public void setBackground(Color color) {
82908290
customBackground = color != null && !this.insideSetEnableCall && !backgroundDisabled;
82918291
background = color;
82928292
super.setBackground(color);
8293-
resetCache(0, content.getLineCount());
8294-
setCaretLocations();
8293+
if (content != null) {
8294+
resetCache(0, content.getLineCount());
8295+
setCaretLocations();
8296+
}
82958297
super.redraw();
82968298
}
82978299
/**
@@ -8772,6 +8774,40 @@ public void setDragDetect (boolean dragDetect) {
87728774
checkWidget ();
87738775
this.dragDetect = dragDetect;
87748776
}
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+
* @since 3.134
8785+
*/
8786+
protected void updateColors(boolean enabled, boolean editable) {
8787+
this.insideSetEnableCall = true;
8788+
Display display = getDisplay();
8789+
try {
8790+
if (enabled && editable) {
8791+
if (!customBackground)
8792+
setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
8793+
if (!customForeground)
8794+
setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
8795+
} else if (!enabled) {
8796+
if (!customBackground)
8797+
setBackground(display.getSystemColor(SWT.COLOR_TEXT_DISABLED_BACKGROUND));
8798+
if (!customForeground)
8799+
setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DISABLED_FOREGROUND));
8800+
} else if (!editable) {
8801+
if (!customBackground)
8802+
setBackground(display.getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND));
8803+
if (!customForeground)
8804+
setForeground(display.getSystemColor(SWT.COLOR_GRAY));
8805+
}
8806+
} finally {
8807+
this.insideSetEnableCall = false;
8808+
}
8809+
}
8810+
87758811
/**
87768812
* Sets whether the widget content can be edited.
87778813
*
@@ -8785,28 +8821,13 @@ public void setDragDetect (boolean dragDetect) {
87858821
public void setEditable(boolean editable) {
87868822
checkWidget();
87878823
this.editable = editable;
8824+
updateColors(this.enabled, this.editable);
87888825
}
87898826
@Override
87908827
public void setEnabled(boolean enabled) {
87918828
super.setEnabled(enabled);
8792-
Display display = getDisplay();
87938829
this.enabled = enabled;
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-
}
8830+
updateColors(this.enabled, this.editable);
88108831
}
88118832

88128833
@Override
@@ -8885,8 +8906,10 @@ public void setForeground(Color color) {
88858906
customForeground = color != null && !this.insideSetEnableCall && !foregroundDisabled;
88868907
foreground = color;
88878908
super.setForeground(color);
8888-
resetCache(0, content.getLineCount());
8889-
setCaretLocations();
8909+
if (content != null) {
8910+
resetCache(0, content.getLineCount());
8911+
setCaretLocations();
8912+
}
88908913
super.redraw();
88918914
}
88928915
/**

0 commit comments

Comments
 (0)