Skip to content

Background and foreground colors in StyledText aren't recomputed consistently. #3132

@om-11-2024

Description

@om-11-2024

Describe the bug
Computed background and foreground colors are only updated in setEnabled(boolean enabled) method.
For consistency they should be recomputed and updated in every method that changes anything on which the computations depend.
Look at the following code in StyledText.java:

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;
	try {
		if (enabled && editable) {
			if (!customBackground) setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
			if (!customForeground) setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
		} else if(!enabled) {
			if (!customBackground) setBackground(display.getSystemColor(SWT.COLOR_TEXT_DISABLED_BACKGROUND));
			if (!customForeground) setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DISABLED_FOREGROUND));
		} else if(!editable) {
			if (!customBackground) setBackground(display.getSystemColor(SWT.COLOR_TEXT_DISABLED_BACKGROUND));
			if (!customForeground) setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
		}
	}
	finally {
		this.insideSetEnableCall = false;
	}
}

As you can see background and foreground colors are updated in setEnabled(boolean enabled), but aren't updated in setEditable(boolean editable) even though the colors depends on the value of enabled.

Ideally, the colors should be recomputed and updated in every method modifying enabled, editable, customBackground or customForeground.

To Reproduce
Not required.

Expected behavior
The background and foreground colors should be recomputed (just like it happens in setEnabled(boolean enabled) now) in every method in StyledText that modifies any field on which the computation depends: enabled, editable, customBackground or customForeground.

Screenshots
Screenshots aren't applicable here.

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS
  1. Additional OS info (e.g. OS version, Linux Desktop, etc)
    -

  2. JRE/JDK version
    -

Version since
Since at least eclipse.platform.swt tag R4_39.

Workaround (or) Additional context
-

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions