diff options
author | Eric Williams | 2016-05-05 14:19:15 +0000 |
---|---|---|
committer | Arun Thondapu | 2016-05-16 10:33:19 +0000 |
commit | f8b43edebb1ad960e4e85bfa444e9a7d284303f1 (patch) | |
tree | 1f0502f581a650135938843d2653e589fa39dbcc | |
parent | fe4f8bb968ea3bc87cd534a5996cb18aa246f3b0 (diff) | |
download | eclipse.platform.swt-f8b43edebb1ad960e4e85bfa444e9a7d284303f1.tar.gz eclipse.platform.swt-f8b43edebb1ad960e4e85bfa444e9a7d284303f1.tar.xz eclipse.platform.swt-f8b43edebb1ad960e4e85bfa444e9a7d284303f1.zip |
Bug 493015: [GTK3] Text widget with SINGLE style and custom background
color: selection not visible
This bug affects Text widgets with a custom foreground/background color
set. The selection background and foreground colors are wrong, the
selection foreground color should be COLOR_LIST_SELECTION_TEXT and the
selection background color should be COLOR_LIST_SELECTION. For some
versions of GTK less than 3.20, improper or no colors were being set at
all.
The fix is to set COLOR_LIST_SELECTION_TEXT when setting the foreground
color of a widget, and to ensure COLOR_LIST_SELECTION is set as a
selected background for Text widgets. This is accomplished via CSS and
gtk_widget_override_color() (for GTK3.14 and below only).
Tested on GTK3.20, 3.18, 3.16, and 3.14. GTK2 is unaffected, no
additional AllNonBrowser JUnit tests fail on GTK3.
Change-Id: I740d3fddf757570b475cf0caa8253f659ac8141b
Signed-off-by: Eric Williams <ericwill@redhat.com>
3 files changed, 15 insertions, 3 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java index e8f535bc0f..5bea0335e8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java @@ -4720,7 +4720,12 @@ void setForegroundColor (long /*int*/ handle, GdkRGBA rgba) { long /*int*/ context = OS.gtk_widget_get_style_context (handle); // Form foreground string String color = display.gtk_rgba_to_css_string(toSet); - String css = "* {color: " + color + ";}"; + String name = OS.GTK_VERSION >= OS.VERSION(3, 20, 0) ? display.gtk_widget_class_get_css_name(handle) + : display.gtk_widget_get_name(handle); + GdkRGBA selectedForeground = display.toGdkRGBA(getDisplay().COLOR_LIST_SELECTION_TEXT); + String selection = OS.GTK_VERSION >= OS.VERSION(3, 20, 0) ? " selection" : ":selected"; + String css = "* {color: " + color + ";}\n" + + name + selection + " {color: " + display.gtk_rgba_to_css_string(selectedForeground) + ";}"; // Cache foreground color cssForeground = css; 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 80bf9082aa..f61d5b14a0 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 @@ -2228,17 +2228,22 @@ void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba } GdkColor defaultColor = getDisplay().COLOR_LIST_SELECTION; GdkRGBA selectedBackground = display.toGdkRGBA (defaultColor); + GdkRGBA selectedForeground = display.toGdkRGBA(display.COLOR_LIST_SELECTION_TEXT); if (OS.GTK3) { String css; String properties; String name; + String selection = OS.GTK_VERSION >= OS.VERSION(3, 20, 0) ? " selection" : ":selected"; if ((style & SWT.SINGLE) != 0) { name = OS.GTK_VERSION >= OS.VERSION(3, 20, 0) ? "entry" : "GtkEntry"; - properties = " {background: " + display.gtk_rgba_to_css_string(background) + ";}\n"; + properties = " {background: " + display.gtk_rgba_to_css_string(background) + ";}\n" + + name + ":selected {background-color: " + display.gtk_rgba_to_css_string(selectedBackground) + ";}\n" + + name + selection + " {color: " + display.gtk_rgba_to_css_string(selectedForeground) + ";}"; } else { name = OS.GTK_VERSION >= OS.VERSION(3, 20, 0) ? "textview text" : "GtkTextView"; properties = " {background-color: " + display.gtk_rgba_to_css_string(background) + ";}\n" - + name + ":selected {background-color: " + display.gtk_rgba_to_css_string(selectedBackground) + ";}"; + + name + ":selected {background-color: " + display.gtk_rgba_to_css_string(selectedBackground) + ";}\n" + + name + selection + " {color: " + display.gtk_rgba_to_css_string(selectedForeground) + ";}"; } css = name + properties; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java index aea7961684..289a12c2b4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java @@ -1619,10 +1619,12 @@ void setForegroundColor (long /*int*/ handle, GdkColor color) { void setForegroundColor (long /*int*/ handle, GdkColor color, boolean setStateActive) { if (OS.GTK3) { GdkRGBA rgba = null; + GdkRGBA selectedForeground = display.toGdkRGBA(display.COLOR_LIST_SELECTION_TEXT); if (color != null) { rgba = display.toGdkRGBA (color); } OS.gtk_widget_override_color (handle, OS.GTK_STATE_FLAG_NORMAL, rgba); + OS.gtk_widget_override_color (handle, OS.GTK_STATE_FLAG_SELECTED, selectedForeground); long /*int*/ context = OS.gtk_widget_get_style_context (handle); OS.gtk_style_context_invalidate (context); return; |