diff options
author | Leo Ufimtsev | 2015-03-25 20:05:43 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2015-03-30 16:24:18 +0000 |
commit | 5b40b97f8495883f290419ddc3e69d47e697fa6c (patch) | |
tree | f4719f46a9e038d470e418d453fd05d3c27741f3 | |
parent | 61ac0970c1c501525ee9c1ee8c104c394020c61a (diff) | |
download | eclipse.platform.swt-5b40b97f8495883f290419ddc3e69d47e697fa6c.tar.gz eclipse.platform.swt-5b40b97f8495883f290419ddc3e69d47e697fa6c.tar.xz eclipse.platform.swt-5b40b97f8495883f290419ddc3e69d47e697fa6c.zip |
Bug 462009 - [Gtk3] Button background Color fix (Patch 2)
Tests:
All SWT Button styles *:
- [X] Gtk 3.8 (RHEL 7 native)
- [X] Gtk 3.10 (F21, manual gtk compile)
- [X] Gtk 3.12 (F21, manual gtk compile)
- [X] Gtk 3.14 (F21, native gtk)
- [X] Gtk 3.15.11 (F22, native)
This corrects the issue that checkbox/radiobutton is not visible when
background is applied for some themes (gtk unstyled, ubuntu etc..).
Change-Id: I1d1091b5d949ef153cb7db07e44034a2d2d4dcf2
Signed-off-by: Leo Ufimtsev <lufimtse@redhat.com>
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java | 25 | ||||
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java | 22 |
2 files changed, 41 insertions, 6 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java index d5437aa5cb..8fd50580c9 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java @@ -11,11 +11,11 @@ package org.eclipse.swt.widgets; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.gtk.*; import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; import org.eclipse.swt.events.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.gtk.*; /** * Instances of this class represent a selectable user interface object that @@ -796,8 +796,23 @@ void _setAlignment (int alignment) { } @Override -void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) { //Gtk3. - setBackgroundColorGradient (OS.gtk_widget_get_style_context (handle), handle, rgba); +void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) { + /* Note: this function is called on Gtk3 only */ + + //Pre Gtk 3.10 doesn't handle CSS background color very well for Gtk Check/Radio button. + // 3.10.3 as it was the latest to affect themeing in button. + if (OS.GTK_VERSION < OS.VERSION(3, 10, 3) && (style & (SWT.CHECK | SWT.RADIO)) != 0) { + super.setBackgroundColor (context, handle, rgba); + return; + } + + String css ="* {\n"; + if (rgba != null) { + String color = gtk_rgba_to_css_string (rgba); + css += "background: " + color + ";\n"; + } + css += "}\n"; + gtk_css_provider_load_from_css (context, css); } @Override 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 ac80045ed8..701d6756b9 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 @@ -4086,10 +4086,19 @@ void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba void setBackgroundColorGradient (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) { String css ="* {\n"; if (rgba != null) { - String color = "rgba(" + (int)(rgba.red * 255) + "," + (int)(rgba.green * 255) + "," + (int)(rgba.blue * 255) + "," + (int)(rgba.alpha * 255) + ")"; + String color = gtk_rgba_to_css_string (rgba); + //Note, use 'background-image' CSS class with caution. Not all themes/widgets support it. (e.g button doesn't). + //Use 'background' CSS class where possible instead unless 'background-image' is explicidly supported. css += "background-image: -gtk-gradient (linear, 0 0, 0 1, color-stop(0, " + color + "), color-stop(1, " + color + "));\n"; } css += "}\n"; + gtk_css_provider_load_from_css (context, css); +} + +void gtk_css_provider_load_from_css (long context, String css) { + /* Utility function. */ + //@param css : a 'css java' string like "{\nbackground: red;\n}". + if (provider == 0) { provider = OS.gtk_css_provider_new (); OS.gtk_style_context_add_provider (context, provider, OS.GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); @@ -4098,6 +4107,17 @@ void setBackgroundColorGradient (long /*int*/ context, long /*int*/ handle, GdkR OS.gtk_css_provider_load_from_data (provider, Converter.wcsToMbcs (null, css, true), -1, null); } +String gtk_rgba_to_css_string (GdkRGBA rgba) { + /* + * In GdkRGBA, values are a double between 0-1.<br> + * In CSS, values are typically integers between 0-255.<br> + * I.e, note, there is a slight loss of precision. + * Thus setting/getting color *might* return slight differences. + */ + String color = "rgba(" + (int)(rgba.red * 255) + "," + (int)(rgba.green * 255) + "," + (int)(rgba.blue * 255) + "," + (int)(rgba.alpha * 255) + ")"; + return color; +} + void setBackgroundColor (long /*int*/ handle, GdkColor color) { if (OS.GTK3) { GdkRGBA rgba = null; |