diff options
author | Eric Williams | 2019-03-14 15:19:48 +0000 |
---|---|---|
committer | Eric Williams | 2019-03-14 15:32:45 +0000 |
commit | ecc666275b3b7b87d3be7da23a89327dd32efdc4 (patch) | |
tree | c827d81c25c703e2d8a3866d1728bc4a25a194b7 | |
parent | c0b245e799efea834a2f7ff826a012a9e707c15d (diff) | |
download | eclipse.platform.swt-ecc666275b3b7b87d3be7da23a89327dd32efdc4.tar.gz eclipse.platform.swt-ecc666275b3b7b87d3be7da23a89327dd32efdc4.tar.xz eclipse.platform.swt-ecc666275b3b7b87d3be7da23a89327dd32efdc4.zip |
Bug 545406: [GTK3] Text: order of setBackground/setForeground matters
GTK-CSS parsing doesn't handle selection foreground colors well, instead
use manual foreground GdkRGBA tracking just like for background colors.
Change-Id: Ib9a02df6c6845b35f95d2e57093e9b371e134846
Signed-off-by: Eric Williams <ericwill@redhat.com>
3 files changed, 89 insertions, 1 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java index 9faa10358c..461fb20523 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java @@ -105,7 +105,7 @@ public class Text extends Scrollable { /* Text uses non-standard CSS to set its background color, so we need * a global variable to keep track of its background color. */ - GdkRGBA background; + GdkRGBA background, foreground; long /*int*/ indexMark = 0; double cachedAdjustment, currentAdjustment; @@ -2239,6 +2239,19 @@ GdkRGBA getContextBackgroundGdkRGBA () { } @Override +GdkRGBA getContextColorGdkRGBA () { + if (GTK.GTK_VERSION >= OS.VERSION(3, 14, 0)) { + if (foreground != null) { + return foreground; + } else { + return display.COLOR_WIDGET_FOREGROUND_RGBA; + } + } else { + return super.getContextColorGdkRGBA (); + } +} + +@Override void setBackgroundGdkRGBA (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) { /* Setting the background color overrides the selected background color. * To prevent this, we need to re-set the default. This can be done with CSS @@ -2278,6 +2291,17 @@ void setBackgroundGdkRGBA (long /*int*/ context, long /*int*/ handle, GdkRGBA rg } @Override +void setForegroundGdkRGBA (GdkRGBA rgba) { + if (GTK.GTK_VERSION >= OS.VERSION (3, 14, 0)) { + foreground = rgba; + GdkRGBA toSet = rgba == null ? display.COLOR_WIDGET_FOREGROUND_RGBA : rgba; + setForegroundGdkRGBA (handle, toSet); + } else { + super.setForegroundGdkRGBA(rgba); + } +} + +@Override void setCursor (long /*int*/ cursor) { long /*int*/ defaultCursor = 0; if (cursor == 0) { diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug545406_TextForegroundNotApplied.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug545406_TextForegroundNotApplied.java new file mode 100644 index 0000000000..4332541bae --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug545406_TextForegroundNotApplied.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2019 Red Hat and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +public class Bug545406_TextForegroundNotApplied { + + public static void main(String[] args) { + final Display display = new Display(); + + final Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + + final Text text = new Text(shell, SWT.BORDER | SWT.MULTI); + text.setBackground(display.getSystemColor(SWT.COLOR_DARK_GRAY)); + text.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); + + shell.setSize(300, 150); + shell.open(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + display.dispose(); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Text.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Text.java index cf8c36329f..d99dc98d53 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Text.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Text.java @@ -24,6 +24,7 @@ import org.eclipse.swt.events.SegmentListener; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.VerifyListener; +import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.Point; @@ -1155,6 +1156,24 @@ public void test_setFontLorg_eclipse_swt_graphics_Font() { } @Test +public void test_setForegroundAfterBackground() { + makeCleanEnvironment(false); + Color gray = text.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY); + Color white = text.getDisplay().getSystemColor(SWT.COLOR_WHITE); + Color defaultForeground = text.getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND); + + text.setBackground(gray); + assertEquals(text.getForeground(), defaultForeground); + text.setForeground(white); + assertEquals(text.getForeground(), white); + assertEquals(text.getBackground(), gray); + + gray.dispose(); + white.dispose(); + defaultForeground.dispose(); +} + +@Test public void test_setOrientationI() { text.setOrientation(SWT.RIGHT_TO_LEFT); if ((text.getStyle() & SWT.MIRRORED) != 0) { |