Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Williams2015-12-02 14:42:59 +0000
committerEric Williams2016-04-01 14:12:03 +0000
commit429cd4e4ecbd8dbfaed902ac7f054c2adda254fe (patch)
tree8803bd3aa164fd8c4e2219bcaa242bc78a6f6c6e /bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt
parent2349244f390a9927eab593ddc499b71cb3f0a70b (diff)
downloadeclipse.platform.swt-429cd4e4ecbd8dbfaed902ac7f054c2adda254fe.tar.gz
eclipse.platform.swt-429cd4e4ecbd8dbfaed902ac7f054c2adda254fe.tar.xz
eclipse.platform.swt-429cd4e4ecbd8dbfaed902ac7f054c2adda254fe.zip
Bug 483097: [GTK3.16+] gtk_widget_override_color is deprecated
This patch is an overhaul of foreground colors for GTK3.16+. Similar to bug 483096, this bug aims to fix and prevent future bugs that will arise from gtk_widget_override_color() being deprecated. This also fixes the last failing foreground test case on GTK3.16. The main feature of this patch is that it converts all (but one case) of foreground colors to use GTK's CSS machinery. Except for Control.checkForeground(), this means that SWT's background and foreground colors are entirely GTK CSS compatible. An important change in this patch affects both CSS backgrounds and foregrounds: since Control uses the same GtkCssProvider for a widget, we need to cache background and foreground values when using CSS. For example, when setting the background color of a widget that already has a foreground color, we need to load not only the "new" background color but also re-load the foreground color to ensure it isn't lost. This is accomplished via Display.gtk_create_css_color_string(). Tested on GTK3.18, 3.16, 3.14, and 2.24. No additional AllNonBrowser JUnit tests fail on GTK3 and GTK2. Change-Id: Ib80f7c51ba2c1c2c922a8f8b51c947f93ac01260 Signed-off-by: Eric Williams <ericwill@redhat.com>
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java69
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java14
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java47
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java157
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java10
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java122
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java16
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java41
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java16
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java21
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java10
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java45
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java21
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java60
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java23
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java32
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java21
17 files changed, 550 insertions, 175 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 9aab8be1a6..13e80d899f 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
@@ -815,14 +815,17 @@ void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba
super.setBackgroundColor (context, handle, rgba);
return;
}
+ // Form background CSS string
+ String css ="* {background : ";
+ String color = display.gtk_rgba_to_css_string (rgba);
+ css += color + ";}";
- 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);
+ // Cache background color
+ cssBackground = css;
+
+ // Apply background color and any cached foreground color
+ String finalCss = display.gtk_css_create_css_color_string (cssBackground, cssForeground, SWT.BACKGROUND);
+ gtk_css_provider_load_from_css (context, finalCss);
}
@Override
@@ -917,18 +920,50 @@ boolean setRadioSelection (boolean value) {
@Override
void setForegroundColor (GdkColor color) {
super.setForegroundColor (color);
- setForegroundColor (fixedHandle, color);
- if (labelHandle != 0) setForegroundColor (labelHandle, color);
- if (imageHandle != 0) setForegroundColor (imageHandle, color);
-
- //Pre 3.10 CSS didn't work. In 3.16 everything will be CSS controlled
- //and themes should control check/radio border color then.
- if (OS.GTK_VERSION >= OS.VERSION(3, 10, 0) && OS.GTK_VERSION < OS.VERSION (3, 16, 0) &&
- (style & (SWT.CHECK | SWT.RADIO)) != 0) {
- gtk_swt_set_border_color (color);
+ if (OS.GTK_VERSION >= OS.VERSION (3, 16, 0)) {
+ GdkRGBA rgba = null;
+ if (color != null) {
+ rgba = display.toGdkRGBA (color);
+ }
+ setForegroundColor (fixedHandle, rgba);
+ if (labelHandle != 0) setForegroundColor (labelHandle, rgba);
+ if (imageHandle != 0) setForegroundColor (imageHandle, rgba);
+ //Pre 3.10 CSS didn't work. In 3.16 everything will be CSS controlled
+ //and themes should control check/radio border color then.
+ } else {
+ setForegroundColor (fixedHandle, color);
+ if (labelHandle != 0) setForegroundColor (labelHandle, color);
+ if (imageHandle != 0) setForegroundColor (imageHandle, color);
+ if (OS.GTK_VERSION >= OS.VERSION(3, 10, 0) && OS.GTK_VERSION < OS.VERSION (3, 16, 0) &&
+ (style & (SWT.CHECK | SWT.RADIO)) != 0) {
+ gtk_swt_set_border_color (color);
+ }
}
}
+@Override
+void setForegroundColor (long /*int*/ handle, GdkRGBA rgba) {
+ GdkRGBA toSet;
+ if (rgba != null) {
+ toSet = rgba;
+ } else {
+ GdkColor defaultForeground = display.COLOR_WIDGET_FOREGROUND;
+ toSet = display.toGdkRGBA (defaultForeground);
+ }
+ long /*int*/ context = OS.gtk_widget_get_style_context (handle);
+
+ // Form foreground string
+ String color = display.gtk_rgba_to_css_string(toSet);
+ String css = "GtkButton {color: " + color + ";}";
+
+ // Cache foreground color
+ cssForeground = css;
+
+ // Apply foreground color and any cached background color
+ String finalCss = display.gtk_css_create_css_color_string (cssBackground, cssForeground, SWT.FOREGROUND);
+ gtk_css_provider_load_from_css(context, finalCss);
+}
+
//GtkCheckButton & it's descendant GtkRadioButton are often invisible or
// very hard to see with certain themes that don't define an icon for Check/Radio buttons.
// Giving them a border color that matches the text color ensures consistent visibility across most themes.
@@ -946,7 +981,7 @@ private void gtk_swt_set_border_color (GdkColor color) {
// ideally we should have a 'constructCssString(..) that accepts attribute-value pairs.
String css_string = "* {\n";
if (rgba != null) {
- String css_color = gtk_rgba_to_css_string (rgba);
+ String css_color = display.gtk_rgba_to_css_string (rgba);
css_string += "border-color: " + css_color + ";\n";
}
css_string += "}\n";
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java
index dff797a026..eced262683 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java
@@ -390,6 +390,20 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
return result;
}
+@Override
+void setForegroundColor (long /*int*/ handle, GdkRGBA rgba) {
+ /* For CSS foreground colors (GTK3.16+) we need to make sure the default
+ * background color stays set if no background color is specified. If no
+ * background color has been set, set cssBackground to be COLOR_WIDGET_BACKGROUND.
+ */
+ if (cssBackground == null) {
+ GdkRGBA defaultBackground = display.toGdkRGBA (display.COLOR_WIDGET_BACKGROUND);
+ cssBackground = "SwtFixed {background-color: " +
+ display.gtk_rgba_to_css_string(defaultBackground) + ";}";
+ }
+ super.setForegroundColor (handle, rgba);
+}
+
/**
* Sets the receiver's caret.
* <p>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
index 103a6f0306..ba40b080e7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
@@ -1910,17 +1910,20 @@ void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba
background = rgba;
String css = "* {\n";
if (rgba != null) {
- String color = gtk_rgba_to_css_string (rgba);
+ String color = display.gtk_rgba_to_css_string (rgba);
css += "background: " + color + ";\n";
}
css += "}\n";
+ // Cache background color
+ cssBackground = css;
+ String finalCss = display.gtk_css_create_css_color_string (cssBackground, cssForeground, SWT.BACKGROUND);
if (entryHandle == 0 || (style & SWT.READ_ONLY) != 0) {
// For read only Combos, we can just apply the background CSS to the GtkToggleButton.
- gtk_css_provider_load_from_css (OS.gtk_widget_get_style_context(buttonHandle), css);
+ gtk_css_provider_load_from_css (OS.gtk_widget_get_style_context(buttonHandle), finalCss);
} else {
if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
// For GTK3.16+, only the GtkEntry needs to be themed.
- gtk_css_provider_load_from_css (OS.gtk_widget_get_style_context(entryHandle), css);
+ gtk_css_provider_load_from_css (OS.gtk_widget_get_style_context(entryHandle), finalCss);
} else {
// Maintain GTK3.14- functionality
setBackgroundColorGradient (OS.gtk_widget_get_style_context (entryHandle), handle, rgba);
@@ -2001,24 +2004,30 @@ void setFontDescription (long /*int*/ font) {
@Override
void setForegroundColor (GdkColor color) {
- super.setForegroundColor (handle, color, false);
- if (entryHandle != 0) {
- setForegroundColor (entryHandle, color, false);
- }
- if (OS.GTK3) {
- GdkRGBA rgba = gdk_color_to_rgba (color);
+ if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
+ GdkRGBA rgba = null;
+ if (color != null) {
+ rgba = display.toGdkRGBA (color);
+ }
+ if (entryHandle != 0) {
+ setForegroundColor (entryHandle, rgba);
+ }
OS.g_object_set (textRenderer, OS.foreground_rgba, rgba, 0);
- } else {
- OS.g_object_set (textRenderer, OS.foreground_gdk, color, 0);
- }
-}
-
-GdkRGBA gdk_color_to_rgba (GdkColor color) {
- GdkRGBA rgba = null;
- if (color != null) {
- rgba = display.toGdkRGBA (color);
+ } else {
+ super.setForegroundColor (handle, color, false);
+ if (entryHandle != 0) {
+ setForegroundColor (entryHandle, color, false);
+ }
+ if (OS.GTK3) {
+ GdkRGBA rgba = null;
+ if (color != null) {
+ rgba = display.toGdkRGBA (color);
+ }
+ OS.g_object_set (textRenderer, OS.foreground_rgba, rgba, 0);
+ } else {
+ OS.g_object_set (textRenderer, OS.foreground_gdk, color, 0);
+ }
}
- return rgba;
}
/**
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 ed36380842..5020621f3e 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
@@ -59,6 +59,7 @@ public abstract class Control extends Widget implements Drawable {
Object layoutData;
Accessible accessible;
Control labelRelation;
+ String cssBackground, cssForeground = " ";
/* these class variables are for the workaround for bug #427776 */
static Callback enterNotifyEventFunc;
@@ -658,8 +659,10 @@ void checkForeground () {
* Feature in GTK 3. The widget foreground is inherited from the immediate
* parent. This is not the expected behavior for SWT. The fix is to avoid
* the inheritance by explicitly setting the default foreground on the widget.
+ *
+ * This can be removed on GTK3.16+.
*/
- if (OS.GTK3) {
+ if (OS.GTK_VERSION < OS.VERSION(3, 16, 0)) {
setForegroundColor (topHandle (), display.COLOR_WIDGET_FOREGROUND);
}
}
@@ -2705,7 +2708,7 @@ GdkColor getContextBackground () {
long /*int*/ fontHandle = fontHandle ();
if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
if (provider != 0) {
- return gtk_css_parse_background (provider);
+ return display.gtk_css_parse_background (provider);
} else {
return display.COLOR_WIDGET_BACKGROUND;
}
@@ -2722,14 +2725,14 @@ GdkColor getContextBackground () {
GdkColor getContextColor () {
long /*int*/ fontHandle = fontHandle ();
- long /*int*/ context = OS.gtk_widget_get_style_context (fontHandle);
- GdkRGBA rgba = new GdkRGBA ();
- if (OS.GTK_VERSION < OS.VERSION(3, 18, 0)) {
- rgba = display.styleContextGetColor (context, OS.GTK_STATE_FLAG_NORMAL, rgba);
+ if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0) && provider != 0) {
+ return display.gtk_css_parse_foreground(provider);
} else {
- rgba = display.styleContextGetColor (context, OS.gtk_widget_get_state_flags(handle), rgba);
+ long /*int*/ context = OS.gtk_widget_get_style_context (fontHandle);
+ GdkRGBA rgba = new GdkRGBA ();
+ rgba = display.styleContextGetColor (context, OS.GTK_STATE_FLAG_NORMAL, rgba);
+ return display.toGdkColor (rgba);
}
- return display.toGdkColor (rgba);
}
GdkColor getBgColor () {
@@ -3618,6 +3621,20 @@ long /*int*/ gtk_unrealize (long /*int*/ widget) {
return 0;
}
+String gtk_widget_get_name(long /*int*/ handle) {
+ long /*int*/ str = OS.gtk_widget_get_name (handle);
+ String name;
+ if (str == 0) {
+ name = "*";
+ } else {
+ int length = OS.strlen (str);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, str, length);
+ name = new String (Converter.mbcsToWcs (null, buffer));
+ }
+ return name;
+}
+
void gtk_widget_size_request (long /*int*/ widget, GtkRequisition requisition) {
gtk_widget_get_preferred_size (widget, requisition);
}
@@ -4204,18 +4221,16 @@ private void _setBackground (Color color) {
void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) {
if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
- long /*int*/ str = OS.gtk_widget_get_name (handle);
- String name;
- if (str == 0) {
- name = "*";
- } else {
- int length = OS.strlen (str);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, str, length);
- name = new String (Converter.mbcsToWcs (null, buffer));
- }
- String css = name + " {background-color: " + gtk_rgba_to_css_string (rgba) + ";}";
- gtk_css_provider_load_from_css (context, css);
+ // Form background string
+ String name = gtk_widget_get_name(handle);
+ String css = name + " {background-color: " + display.gtk_rgba_to_css_string (rgba) + ";}";
+
+ // Cache background
+ cssBackground = css;
+
+ // Apply background color and any cached foreground color
+ String finalCss = display.gtk_css_create_css_color_string (cssBackground, cssForeground, SWT.BACKGROUND);
+ gtk_css_provider_load_from_css (context, finalCss);
} else {
OS.gtk_widget_override_background_color (handle, OS.GTK_STATE_FLAG_NORMAL, rgba);
}
@@ -4224,13 +4239,18 @@ 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 = gtk_rgba_to_css_string (rgba);
+ String color = display.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);
+ //Cache background color
+ cssBackground = css;
+
+ // Apply background color and any cached foreground color
+ String finalCss = display.gtk_css_create_css_color_string (cssBackground, cssForeground, SWT.BACKGROUND);
+ gtk_css_provider_load_from_css (context, finalCss);
}
void gtk_css_provider_load_from_css (long /*int*/ context, String css) {
@@ -4245,68 +4265,6 @@ void gtk_css_provider_load_from_css (long /*int*/ context, String css) {
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.
- * In CSS, values are integers between 0-255 for r, g, and b.
- * Alpha is still a double between 0-1.
- * The final CSS format is: rgba(int, int, int, double)
- * Due to this, there is a slight loss of precision.
- * Setting/getting with CSS *might* yield slight differences.
- */
- GdkRGBA toConvert;
- if (rgba != null) {
- toConvert = rgba;
- } else {
- // If we have a null RGBA, set it to the default COLOR_WIDGET_BACKGROUND.
- GdkColor defaultGdkColor = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND).handle;
- toConvert = display.toGdkRGBA (defaultGdkColor);
- }
- long /*int*/ str = OS.gdk_rgba_to_string (toConvert);
- int length = OS.strlen (str);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, str, length);
- return new String (Converter.mbcsToWcs (null, buffer));
-}
-
-GdkColor gtk_css_parse_background (long /*int*/ provider) {
- String shortOutput;
- int startIndex;
- GdkRGBA rgba = new GdkRGBA ();
- // Fetch the CSS in char/string format from the GtkCssProvider.
- long /*int*/ str = OS.gtk_css_provider_to_string (provider);
- if (str == 0) return display.COLOR_WIDGET_BACKGROUND;
- int length = OS.strlen (str);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, str, length);
- String cssOutput = new String (Converter.mbcsToWcs (null, buffer));
-
- /* Although we only set the property "background-color", we can handle
- * the "background" property as well. We check for either of these cases
- * and extract a GdkRGBA object from the parsed CSS string.
- */
- if (cssOutput.contains ("background-color:")) {
- startIndex = cssOutput.indexOf ("background-color:");
- shortOutput = cssOutput.substring (startIndex + 18);
- // Double check to make sure with have a valid rgb/rgba property
- if (shortOutput.contains ("rgba") || shortOutput.contains ("rgb")) {
- rgba = display.gtk_css_property_to_rgba (shortOutput);
- } else {
- return display.COLOR_WIDGET_BACKGROUND;
- }
- } else if (cssOutput.contains ("background:")) {
- startIndex = cssOutput.indexOf ("background:");
- shortOutput = cssOutput.substring (startIndex + 13);
- // Double check to make sure with have a valid rgb/rgba property
- if (shortOutput.contains ("rgba") || shortOutput.contains ("rgb")) {
- rgba = display.gtk_css_property_to_rgba (shortOutput);
- } else {
- return display.COLOR_WIDGET_BACKGROUND;
- }
- }
- return display.toGdkColor (rgba);
-}
-
void setBackgroundColor (long /*int*/ handle, GdkColor color) {
if (OS.GTK3) {
GdkRGBA rgba = null;
@@ -4744,7 +4702,36 @@ public void setForeground (Color color) {
}
void setForegroundColor (GdkColor color) {
- setForegroundColor (handle, color);
+ GdkRGBA rgba = null;
+ if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
+ if (color != null) {
+ rgba = display.toGdkRGBA (color);
+ }
+ setForegroundColor(handle, rgba);
+ } else {
+ setForegroundColor (handle, color);
+ }
+}
+
+void setForegroundColor (long /*int*/ handle, GdkRGBA rgba) {
+ GdkRGBA toSet = new GdkRGBA();
+ if (rgba != null) {
+ toSet = rgba;
+ } else {
+ GdkColor defaultForeground = display.COLOR_WIDGET_FOREGROUND;
+ toSet = display.toGdkRGBA (defaultForeground);
+ }
+ 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 + ";}";
+
+ // Cache foreground color
+ cssForeground = css;
+
+ // Apply foreground color and any cached background color
+ String finalCss = display.gtk_css_create_css_color_string (cssBackground, cssForeground, SWT.FOREGROUND);
+ gtk_css_provider_load_from_css(context, finalCss);
}
void setInitialBounds () {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java
index cfefd0eee0..f3c1daa5b1 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java
@@ -1402,7 +1402,15 @@ public void setFont (Font font) {
@Override
void setForegroundColor (GdkColor color) {
- setForegroundColor (containerHandle, color, false);
+ if (OS.GTK_VERSION >= OS.VERSION (3, 16, 0)) {
+ GdkRGBA rgba = null;
+ if (color != null) {
+ rgba = display.toGdkRGBA (color);
+ }
+ setForegroundColor (containerHandle, rgba);
+ } else {
+ setForegroundColor (containerHandle, color, false);
+ }
}
@Override
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
index eff7dfea0b..af555afe0f 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
@@ -11,6 +11,9 @@
package org.eclipse.swt.widgets;
+import java.util.regex.*;
+import java.util.regex.Pattern;
+
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.*;
@@ -1691,6 +1694,29 @@ long /*int*/ gtk_cell_renderer_toggle_get_type () {
return toggle_renderer_type;
}
+String gtk_css_create_css_color_string (String background, String foreground, int property) {
+ switch (property) {
+ case SWT.FOREGROUND:
+ if (foreground != null && background != null) {
+ return foreground + "\n" + background;
+ } else if (foreground != null) {
+ return foreground;
+ } else {
+ return "";
+ }
+ case SWT.BACKGROUND:
+ if (foreground != null && background != null) {
+ return background + "\n" + foreground;
+ } else if (background != null) {
+ return background;
+ } else {
+ return "";
+ }
+ default:
+ return "";
+ }
+}
+
String gtk_css_default_theme_values (int swt) {
/*
* This method fetches GTK theme values/properties. This is accomplished
@@ -1771,6 +1797,78 @@ String gtk_css_default_theme_values (int swt) {
}
}
+GdkColor gtk_css_parse_background (long /*int*/ provider) {
+ String shortOutput;
+ int startIndex;
+ GdkRGBA rgba = new GdkRGBA ();
+ // Fetch the CSS in char/string format from the GtkCssProvider.
+ long /*int*/ str = OS.gtk_css_provider_to_string (provider);
+ if (str == 0) return COLOR_WIDGET_BACKGROUND;
+ int length = OS.strlen (str);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, str, length);
+ String cssOutput = new String (Converter.mbcsToWcs (null, buffer));
+
+ /* Although we only set the property "background-color", we can handle
+ * the "background" property as well. We check for either of these cases
+ * and extract a GdkRGBA object from the parsed CSS string.
+ */
+ if (cssOutput.contains ("background-color:")) {
+ startIndex = cssOutput.indexOf ("background-color:");
+ shortOutput = cssOutput.substring (startIndex + 18);
+ // Double check to make sure with have a valid rgb/rgba property
+ if (shortOutput.contains ("rgba") || shortOutput.contains ("rgb")) {
+ rgba = gtk_css_property_to_rgba (shortOutput);
+ } else {
+ return COLOR_WIDGET_BACKGROUND;
+ }
+ } else if (cssOutput.contains ("background:")) {
+ startIndex = cssOutput.indexOf ("background:");
+ shortOutput = cssOutput.substring (startIndex + 13);
+ // Double check to make sure with have a valid rgb/rgba property
+ if (shortOutput.contains ("rgba") || shortOutput.contains ("rgb")) {
+ rgba = gtk_css_property_to_rgba (shortOutput);
+ } else {
+ return COLOR_WIDGET_BACKGROUND;
+ }
+ }
+ return toGdkColor (rgba);
+}
+
+GdkColor gtk_css_parse_foreground (long /*int*/ provider) {
+ String shortOutput;
+ int startIndex;
+ GdkRGBA rgba = new GdkRGBA ();
+ // Fetch the CSS in char/string format from the provider.
+ long /*int*/ str = OS.gtk_css_provider_to_string(provider);
+ if (str == 0) return COLOR_WIDGET_FOREGROUND;
+ int length = OS.strlen (str);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, str, length);
+ String cssOutput = new String (Converter.mbcsToWcs (null, buffer));
+ /*
+ * Because background-color and color have overlapping characters,
+ * a simple String.contains() check will not suffice. This means
+ * that a more encompassing regex is needed to capture "pure" color
+ * properties and filter out things like background-color, border-color,
+ * etc.
+ */
+ String pattern = "[^-]color: rgb[a]?\\([0-9]+,[\\s]?[0-9]+,[\\s]?[0-9]+[,[\\s]*[0-9]+]?\\)";
+ Pattern r = Pattern.compile(pattern);
+ Matcher m = r.matcher(cssOutput);
+ if (m.find()) {
+ String match = m.group(0);
+ if (match.contains("color:")) {
+ startIndex = match.indexOf("color:");
+ shortOutput = match.substring(startIndex + 7);
+ rgba = gtk_css_property_to_rgba(shortOutput);
+ }
+ } else {
+ return COLOR_WIDGET_FOREGROUND;
+ }
+ return toGdkColor (rgba);
+}
+
GdkRGBA gtk_css_property_to_rgba(String property) {
/* Here we convert rgb(...) or rgba(...) properties
* into GdkRGBA objects using gdk_rgba_parse(). Note
@@ -1784,6 +1882,30 @@ GdkRGBA gtk_css_property_to_rgba(String property) {
return rgba;
}
+String gtk_rgba_to_css_string (GdkRGBA rgba) {
+ /*
+ * In GdkRGBA, values are a double between 0-1.
+ * In CSS, values are integers between 0-255 for r, g, and b.
+ * Alpha is still a double between 0-1.
+ * The final CSS format is: rgba(int, int, int, double)
+ * Due to this, there is a slight loss of precision.
+ * Setting/getting with CSS *might* yield slight differences.
+ */
+ GdkRGBA toConvert;
+ if (rgba != null) {
+ toConvert = rgba;
+ } else {
+ // If we have a null RGBA, set it to the default COLOR_WIDGET_BACKGROUND.
+ GdkColor defaultGdkColor = getSystemColor(SWT.COLOR_WIDGET_BACKGROUND).handle;
+ toConvert = toGdkRGBA (defaultGdkColor);
+ }
+ long /*int*/ str = OS.gdk_rgba_to_string (toConvert);
+ int length = OS.strlen (str);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, str, length);
+ return new String (Converter.mbcsToWcs (null, buffer));
+}
+
/**
* Returns the default display. One is created (making the
* thread that invokes this method its user-interface thread)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java
index 90fdeaea37..8bbf942ad7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java
@@ -565,9 +565,19 @@ void setFontDescription (long /*int*/ font) {
}
void setForegroundColor (GdkColor color) {
- setForegroundColor (handle, color);
- if (labelHandle != 0) setForegroundColor (labelHandle, color);
- if (imageHandle != 0) setForegroundColor (imageHandle, color);
+ if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
+ GdkRGBA rgba = null;
+ if (color != null) {
+ rgba = display.toGdkRGBA (color);
+ }
+ parent.setForegroundColor (handle, rgba);
+ if (labelHandle != 0) parent.setForegroundColor (labelHandle, rgba);
+ if (imageHandle != 0) parent.setForegroundColor (imageHandle, rgba);
+ } else {
+ setForegroundColor (handle, color);
+ if (labelHandle != 0) setForegroundColor (labelHandle, color);
+ if (imageHandle != 0) setForegroundColor (imageHandle, color);
+ }
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java
index fb69dcd51b..284fc10a20 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java
@@ -43,6 +43,8 @@ import org.eclipse.swt.internal.gtk.*;
public class Group extends Composite {
long /*int*/ clientHandle, labelHandle;
String text = "";
+ // We use this to keep track of the foreground color
+ GdkRGBA foreground;
/**
* Constructs a new instance of this class given its parent
@@ -145,6 +147,18 @@ Rectangle getClientAreaInPixels () {
return clientRectangle;
}
+@Override
+GdkColor getContextColor () {
+ if (OS.GTK_VERSION >= OS.VERSION (3, 16, 0)) {
+ if (foreground != null) {
+ return display.toGdkColor (foreground);
+ } else {
+ return display.COLOR_WIDGET_FOREGROUND;
+ }
+ } else {
+ return super.getContextColor();
+ }
+}
@Override
void createHandle(int index) {
@@ -315,8 +329,27 @@ void setFontDescription (long /*int*/ font) {
@Override
void setForegroundColor (GdkColor color) {
- super.setForegroundColor (color);
- setForegroundColor (labelHandle, color);
+ if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
+ GdkRGBA rgba = null;
+ if (color != null) {
+ rgba = display.toGdkRGBA (color);
+ }
+ /*
+ * When using CSS, setting the foreground color on an empty label
+ * widget prevents the background from being set. If a user wants
+ * to specify a foreground color before the text is set, store the
+ * color and wait until text is specified to apply it.
+ */
+ if (text.isEmpty()) {
+ foreground = rgba;
+ } else {
+ setForegroundColor (labelHandle, rgba);
+ foreground = rgba;
+ }
+ } else {
+ super.setForegroundColor (color);
+ setForegroundColor(labelHandle, color);
+ }
}
@Override
@@ -369,6 +402,10 @@ public void setText (String string) {
} else {
OS.gtk_frame_set_label_widget (handle, 0);
}
+ // Set the foreground now that the text has been set
+ if (OS.GTK_VERSION >= OS.VERSION (3, 16, 0)) {
+ setForegroundColor (labelHandle, foreground);
+ }
}
@Override
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java
index 88fe1b178b..5c1f8b20bf 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java
@@ -567,9 +567,19 @@ void setFontDescription (long /*int*/ font) {
@Override
void setForegroundColor (GdkColor color) {
super.setForegroundColor (color);
- setForegroundColor (fixedHandle, color);
- if (labelHandle != 0) setForegroundColor (labelHandle, color);
- if (imageHandle != 0) setForegroundColor (imageHandle, color);
+ if (OS.GTK_VERSION >= OS.VERSION (3, 16, 0)) {
+ GdkRGBA rgba = null;
+ if (color != null) {
+ rgba = display.toGdkRGBA (color);
+ }
+ setForegroundColor (fixedHandle, rgba);
+ if (labelHandle != 0) setForegroundColor (labelHandle, rgba);
+ if (imageHandle != 0) setForegroundColor (imageHandle, rgba);
+ } else {
+ setForegroundColor (fixedHandle, color);
+ if (labelHandle != 0) setForegroundColor (labelHandle, color);
+ if (imageHandle != 0) setForegroundColor (imageHandle, color);
+ }
}
@Override
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java
index ae75d62637..462f95e29e 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java
@@ -1355,9 +1355,14 @@ void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba
GdkColor defaultColor = getDisplay().COLOR_LIST_SELECTION;
GdkRGBA selectedBackground = display.toGdkRGBA (defaultColor);
if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
- String css = "GtkTreeView {background-color: " + gtk_rgba_to_css_string(background) + ";}\n"
- + "GtkTreeView:selected {background-color: " + gtk_rgba_to_css_string(selectedBackground) + ";}";
- gtk_css_provider_load_from_css(context, css);
+ String css = "GtkTreeView {background-color: " + display.gtk_rgba_to_css_string(background) + ";}\n"
+ + "GtkTreeView:selected {background-color: " + display.gtk_rgba_to_css_string(selectedBackground) + ";}";
+ // Cache background color
+ cssBackground = css;
+
+ // Apply background color and any foreground color
+ String finalCss = display.gtk_css_create_css_color_string (cssBackground, cssForeground, SWT.BACKGROUND);
+ gtk_css_provider_load_from_css(context, finalCss);
} else {
super.setBackgroundColor(context, handle, rgba);
OS.gtk_widget_override_background_color(handle, OS.GTK_STATE_FLAG_SELECTED, selectedBackground);
@@ -1445,7 +1450,15 @@ public void setItems (String [] items) {
@Override
void setForegroundColor (GdkColor color) {
- setForegroundColor (handle, color, false);
+ if (OS.GTK_VERSION >= OS.VERSION (3, 16, 0)) {
+ GdkRGBA rgba = null;
+ if (color != null) {
+ rgba = display.toGdkRGBA (color);
+ }
+ setForegroundColor (handle, rgba);
+ } else {
+ setForegroundColor (handle, color, false);
+ }
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java
index 7a78418951..4678419d3d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java
@@ -964,7 +964,15 @@ void setCursor (long /*int*/ cursor) {
@Override
void setForegroundColor (GdkColor color) {
- setForegroundColor (handle, color, false);
+ if (OS.GTK_VERSION >= OS.VERSION (3, 16, 0)) {
+ GdkRGBA rgba = null;
+ if (color != null) {
+ rgba = display.toGdkRGBA (color);
+ }
+ setForegroundColor (handle, rgba);
+ } else {
+ setForegroundColor (handle, color, false);
+ }
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java
index 19feb362c2..b5bebc4ac6 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java
@@ -34,7 +34,7 @@ import org.eclipse.swt.internal.gtk.*;
* @noextend This class is not intended to be subclassed by clients.
*/
public class TabItem extends Item {
- long /*int*/ labelHandle, imageHandle, pageHandle;
+ long /*int*/ labelHandle, imageHandle, pageHandle, provider;
Control control;
TabFolder parent;
String toolTipText;
@@ -326,8 +326,47 @@ void setFontDescription (long /*int*/ font) {
void setForegroundColor (GdkColor color) {
/* Don't set the color in vbox handle (it doesn't draw) */
- setForegroundColor (labelHandle, color, false);
- setForegroundColor (imageHandle, color, false);
+ if (OS.GTK_VERSION >= OS.VERSION (3, 16, 0)) {
+ GdkRGBA rgba = null;
+ if (color != null) {
+ rgba = display.toGdkRGBA (color);
+ }
+ setForegroundColor (labelHandle, rgba);
+ setForegroundColor (imageHandle, rgba);
+ } else {
+ setForegroundColor (labelHandle, color, false);
+ setForegroundColor (imageHandle, color, false);
+ }
+
+}
+
+void setForegroundColor (long /*int*/ handle, GdkRGBA rgba) {
+ GdkRGBA toSet = new GdkRGBA();
+ if (rgba != null) {
+ toSet = rgba;
+ } else {
+ GdkColor defaultForeground = display.COLOR_WIDGET_FOREGROUND;
+ toSet = display.toGdkRGBA (defaultForeground);
+ }
+ 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 + ";}";
+
+ // Cache and apply foreground color
+ parent.cssForeground = css;
+ gtk_css_provider_load_from_css(context, css);
+}
+
+void gtk_css_provider_load_from_css (long /*int*/ 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);
+ OS.g_object_unref (provider);
+ }
+ OS.gtk_css_provider_load_from_data (provider, Converter.wcsToMbcs (null, css, true), -1, null);
}
@Override
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
index 08ece3bcff..f6c42af815 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
@@ -3175,9 +3175,14 @@ void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba
GdkColor defaultColor = getDisplay().COLOR_LIST_SELECTION;
GdkRGBA selectedBackground = display.toGdkRGBA (defaultColor);
if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
- String css = "GtkTreeView {background-color: " + gtk_rgba_to_css_string(background) + ";}\n"
- + "GtkTreeView:selected {background-color: " + gtk_rgba_to_css_string(selectedBackground) + ";}";
- gtk_css_provider_load_from_css(context, css);
+ String css = "GtkTreeView {background-color: " + display.gtk_rgba_to_css_string(background) + ";}\n"
+ + "GtkTreeView:selected {background-color: " + display.gtk_rgba_to_css_string(selectedBackground) + ";}";
+ // Cache background color
+ cssBackground = css;
+
+ // Apply background color and any foreground color
+ String finalCss = display.gtk_css_create_css_color_string (cssBackground, cssForeground, SWT.BACKGROUND);
+ gtk_css_provider_load_from_css(context, finalCss);
} else {
super.setBackgroundColor(context, handle, rgba);
OS.gtk_widget_override_background_color(handle, OS.GTK_STATE_FLAG_SELECTED, selectedBackground);
@@ -3264,7 +3269,15 @@ void setFontDescription (long /*int*/ font) {
@Override
void setForegroundColor (GdkColor color) {
- setForegroundColor (handle, color, false);
+ if (OS.GTK_VERSION >= OS.VERSION (3, 16, 0)) {
+ GdkRGBA rgba = null;
+ if (color != null) {
+ rgba = display.toGdkRGBA (color);
+ }
+ setForegroundColor (handle, rgba);
+ } else {
+ setForegroundColor (handle, color, false);
+ }
}
/**
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 379f5ea48a..5c836de3b3 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
@@ -2185,32 +2185,32 @@ GdkColor getContextBackground () {
@Override
void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) {
- background = rgba;
- if ((style & SWT.MULTI) != 0) {
- /* 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
- * on GTK3.16+, or by using GtkStateFlags as an argument to
- * gtk_widget_override_background_color() on versions of GTK3 less than 3.16.
- */
- if (rgba == null) {
- GdkColor temp = display.COLOR_LIST_BACKGROUND;
- background = display.toGdkRGBA (temp);
- } else {
- background = rgba;
- }
- GdkColor defaultColor = display.COLOR_LIST_SELECTION;
- GdkRGBA selectedBackground = display.toGdkRGBA (defaultColor);
- if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
- String css = "GtkTextView {background-color: " + gtk_rgba_to_css_string(background) + ";}\n"
- + "GtkTextView:selected {background-color: " + gtk_rgba_to_css_string(selectedBackground) + ";}";
- gtk_css_provider_load_from_css(context, css);
- } else {
- super.setBackgroundColor(context, handle, rgba);
- OS.gtk_widget_override_background_color(handle, OS.GTK_STATE_FLAG_SELECTED, selectedBackground);
- }
- return;
+ /* 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
+ * on GTK3.16+, or by using GtkStateFlags as an argument to
+ * gtk_widget_override_background_color() on versions of GTK3 less than 3.16.
+ */
+ if (rgba == null) {
+ GdkColor temp = getDisplay().COLOR_LIST_BACKGROUND;
+ background = display.toGdkRGBA (temp);
+ } else {
+ background = rgba;
+ }
+ GdkColor defaultColor = getDisplay().COLOR_LIST_SELECTION;
+ GdkRGBA selectedBackground = display.toGdkRGBA (defaultColor);
+ if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
+ String css = "GtkTextView {background-color: " + display.gtk_rgba_to_css_string(background) + ";}\n"
+ + "GtkTextView:selected {background-color: " + display.gtk_rgba_to_css_string(selectedBackground) + ";}";
+ // Cache background color
+ cssBackground = css;
+
+ // Apply background color and any foreground color
+ String finalCss = display.gtk_css_create_css_color_string (cssBackground, cssForeground, SWT.BACKGROUND);
+ gtk_css_provider_load_from_css(context, finalCss);
+ } else {
+ super.setBackgroundColor(context, handle, rgba);
+ OS.gtk_widget_override_background_color(handle, OS.GTK_STATE_FLAG_SELECTED, selectedBackground);
}
- setBackgroundColorGradient (context, handle, rgba);
}
@Override
@@ -2302,7 +2302,15 @@ void setFontDescription (long /*int*/ font) {
@Override
void setForegroundColor (GdkColor color) {
- setForegroundColor (handle, color, false);
+ if (OS.GTK_VERSION >= OS.VERSION (3, 16, 0)) {
+ GdkRGBA rgba = null;
+ if (color != null) {
+ rgba = display.toGdkRGBA (color);
+ }
+ setForegroundColor (handle, rgba);
+ } else {
+ setForegroundColor (handle, color, false);
+ }
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java
index 12e223f6b7..4dec39ef36 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java
@@ -54,6 +54,7 @@ public class ToolBar extends Composite {
menuItemSelectedFunc = new Callback(ToolBar.class, "MenuItemSelectedProc", 2);
if (menuItemSelectedFunc.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
}
+ String cssBackground, cssForeground = " ";
/**
* Constructs a new instance of this class given its parent
@@ -594,8 +595,15 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
@Override
void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) {
if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
- String css = "GtkToolbar {background-color: " + gtk_rgba_to_css_string(rgba) + "}";
- gtk_css_provider_load_from_css(context, css);
+ // Form background string
+ String css = "GtkToolbar {background-color: " + display.gtk_rgba_to_css_string(rgba) + "}";
+
+ // Cache background color
+ this.cssBackground = css;
+
+ // Apply background color and any foreground color
+ String finalCss = display.gtk_css_create_css_color_string (cssBackground, cssForeground, SWT.BACKGROUND);
+ gtk_css_provider_load_from_css(context, finalCss);
} else {
super.setBackgroundColor(context, handle, rgba);
}
@@ -611,6 +619,17 @@ void setFontDescription (long /*int*/ font) {
relayout ();
}
+void restoreBackground () {
+ /*
+ * We need to restore the cached background color in order to prevent
+ * setting the foreground color from overriding the background color
+ * (or replacing it with black).
+ */
+ long /*int*/ context = OS.gtk_widget_get_style_context(handle);
+ String finalCss = display.gtk_css_create_css_color_string (this.cssBackground, cssForeground, SWT.BACKGROUND);
+ gtk_css_provider_load_from_css (context, finalCss);
+}
+
@Override
void setForegroundColor (GdkColor color) {
super.setForegroundColor (color);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java
index d785bab813..40a0ea9e05 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java
@@ -1024,7 +1024,37 @@ void setFontDescription (long /*int*/ font) {
}
void setForegroundColor (GdkColor color) {
- if (labelHandle != 0) setForegroundColor (labelHandle, color);
+ if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0) && labelHandle != 0) {
+ GdkRGBA rgba = null;
+ if (color != null) {
+ rgba = display.toGdkRGBA (color);
+ }
+ setForegroundColor (labelHandle, rgba);
+ } else {
+ if (labelHandle != 0) setForegroundColor (labelHandle, color);
+ }
+}
+
+void setForegroundColor (long /*int*/ handle, GdkRGBA rgba) {
+ GdkRGBA toSet = new GdkRGBA();
+ if (rgba != null) {
+ toSet = rgba;
+ } else {
+ GdkColor defaultForeground = display.COLOR_WIDGET_FOREGROUND;
+ toSet = display.toGdkRGBA (defaultForeground);
+ }
+ 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 + ";}";
+
+ // Cache and apply foreground color
+ parent.cssForeground = css;
+ gtk_css_provider_load_from_css(context, css);
+
+ // We need to set the parent ToolBar's background
+ // otherwise setting the foreground will wipe it out.
+ parent.restoreBackground();
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java
index 2915a3d5de..dbbb6e0293 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java
@@ -3162,9 +3162,14 @@ void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba
GdkColor defaultColor = getDisplay().COLOR_LIST_SELECTION;
GdkRGBA selectedBackground = display.toGdkRGBA (defaultColor);
if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
- String css = "GtkTreeView {background-color: " + gtk_rgba_to_css_string(background) + ";}\n"
- + "GtkTreeView:selected {background-color: " + gtk_rgba_to_css_string(selectedBackground) + ";}";
- gtk_css_provider_load_from_css(context, css);
+ String css = "GtkTreeView {background-color: " + display.gtk_rgba_to_css_string(background) + ";}\n"
+ + "GtkTreeView:selected {background-color: " + display.gtk_rgba_to_css_string(selectedBackground) + ";}";
+ // Cache background color
+ cssBackground = css;
+
+ // Apply background color and any foreground color
+ String finalCss = display.gtk_css_create_css_color_string (cssBackground, cssForeground, SWT.BACKGROUND);
+ gtk_css_provider_load_from_css(context, finalCss);
} else {
super.setBackgroundColor(context, handle, rgba);
OS.gtk_widget_override_background_color(handle, OS.GTK_STATE_FLAG_SELECTED, selectedBackground);
@@ -3252,7 +3257,15 @@ void setFontDescription (long /*int*/ font) {
@Override
void setForegroundColor (GdkColor color) {
- setForegroundColor (handle, color, false);
+ if (OS.GTK_VERSION >= OS.VERSION (3, 16, 0)) {
+ GdkRGBA rgba = null;
+ if (color != null) {
+ rgba = display.toGdkRGBA (color);
+ }
+ setForegroundColor (handle, rgba);
+ } else {
+ setForegroundColor (handle, color, false);
+ }
}
/**

Back to the top