eclipse/eclipse-bug-483096.patch
Roland Grunberg 47041fe349 Backport Neon patches regarding background colour and CPU usage.
- [GTK3.16+] gtk_widget_override_background_color is deprecated.
- [GTK3] Eclipse IDE consumes CPU when idle
- [GTK] Empty repositories view links have white backgrounds
- Resolves: rhbz#1294697, rhbz#1269892
- ebz#483096, ebz#484696, ebz#484729
2016-01-05 11:57:15 -05:00

756 lines
30 KiB
Diff

From 438fdd3ab3d4c36e72b77af7d5db136acd445bc4 Mon Sep 17 00:00:00 2001
From: Eric Williams <ericwill@redhat.com>
Date: Wed, 2 Dec 2015 09:29:36 -0500
Subject: [PATCH] Bug 483096: [GTK3.16+] gtk_widget_override_background_color
is deprecated
As of GTK3.16, gtk_widget_override_background_color() is deprecated. The
preferred GTK method of setting background colors is through the CSS
theme machinery. Unfortunately this also means some calls to
gtk_widget_override_background_color() will fail (i.e. bug 479998). This
patch aims to prevent cases like that happening in the future.
We already apply certain CSS properties to individual widgets in
Control, therefore setting background colors isn't problematic -- this
patch merely builds off of this functionality. In addition, this patch
implements the ability to read and parse GTK CSS, converting properties
like "background-color" and "background" into GdkRGBA/GdkColor objects.
Note, there are a few widgets that override setBackgroundColor() and
therefore need some additional tweaks: Table/Tree, ToolBar, Text, Label,
and Spinner.
Tested on GTK3.18, 3.16, 3.14, and 2.24. AllNonBrowser JUnit tests pass
on GTK2 and GTK3.
Change-Id: I8b5287b30b86766ca154b9f8e581eee69cacd5f6
Signed-off-by: Eric Williams <ericwill@redhat.com>
[Fix missing /*int*/ for 64to32 conversion.]
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
---
.../Eclipse SWT PI/gtk/library/os.c | 67 +++++++++++++++
.../Eclipse SWT PI/gtk/library/os.h | 1 +
.../Eclipse SWT PI/gtk/library/os_custom.c | 1 -
.../Eclipse SWT PI/gtk/library/os_custom.h | 3 +
.../Eclipse SWT PI/gtk/library/os_stats.c | 3 +
.../Eclipse SWT PI/gtk/library/os_stats.h | 3 +
.../gtk/org/eclipse/swt/internal/gtk/OS.java | 38 ++++++++-
.../gtk/org/eclipse/swt/widgets/Control.java | 98 +++++++++++++++++++---
.../gtk/org/eclipse/swt/widgets/Label.java | 8 +-
.../gtk/org/eclipse/swt/widgets/Spinner.java | 22 +++++
.../gtk/org/eclipse/swt/widgets/Table.java | 51 ++++++++---
.../gtk/org/eclipse/swt/widgets/Text.java | 24 +++++-
.../gtk/org/eclipse/swt/widgets/ToolBar.java | 24 ++++++
.../gtk/org/eclipse/swt/widgets/Tree.java | 51 ++++++++---
14 files changed, 355 insertions(+), 39 deletions(-)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
index c748451..55f38fb 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
@@ -7169,6 +7169,33 @@ fail:
}
#endif
+#ifndef NO__1gdk_1rgba_1parse
+JNIEXPORT jintLong JNICALL OS_NATIVE(_1gdk_1rgba_1parse)
+ (JNIEnv *env, jclass that, jobject arg0, jbyteArray arg1)
+{
+ GdkRGBA _arg0, *lparg0=NULL;
+ jbyte *lparg1=NULL;
+ jintLong rc = 0;
+ OS_NATIVE_ENTER(env, that, _1gdk_1rgba_1parse_FUNC);
+ if (arg0) if ((lparg0 = getGdkRGBAFields(env, arg0, &_arg0)) == NULL) goto fail;
+ if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail;
+/*
+ rc = (jintLong)gdk_rgba_parse((GdkRGBA *)lparg0, (const gchar *)lparg1);
+*/
+ {
+ OS_LOAD_FUNCTION(fp, gdk_rgba_parse)
+ if (fp) {
+ rc = (jintLong)((jintLong (CALLING_CONVENTION*)(GdkRGBA *, const gchar *))fp)((GdkRGBA *)lparg0, (const gchar *)lparg1);
+ }
+ }
+fail:
+ if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0);
+ if (arg0 && lparg0) setGdkRGBAFields(env, arg0, lparg0);
+ OS_NATIVE_EXIT(env, that, _1gdk_1rgba_1parse_FUNC);
+ return rc;
+}
+#endif
+
#ifndef NO__1gdk_1rgba_1to_1string
JNIEXPORT jintLong JNICALL OS_NATIVE(_1gdk_1rgba_1to_1string)
(JNIEnv *env, jclass that, jobject arg0)
@@ -10076,6 +10103,26 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1css_1provider_1new)
}
#endif
+#ifndef NO__1gtk_1css_1provider_1to_1string
+JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1css_1provider_1to_1string)
+ (JNIEnv *env, jclass that, jintLong arg0)
+{
+ jintLong rc = 0;
+ OS_NATIVE_ENTER(env, that, _1gtk_1css_1provider_1to_1string_FUNC);
+/*
+ rc = (jintLong)gtk_css_provider_to_string(arg0);
+*/
+ {
+ OS_LOAD_FUNCTION(fp, gtk_css_provider_to_string)
+ if (fp) {
+ rc = (jintLong)((jintLong (CALLING_CONVENTION*)(jintLong))fp)(arg0);
+ }
+ }
+ OS_NATIVE_EXIT(env, that, _1gtk_1css_1provider_1to_1string_FUNC);
+ return rc;
+}
+#endif
+
#ifndef NO__1gtk_1dialog_1add_1button
JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1dialog_1add_1button)
(JNIEnv *env, jclass that, jintLong arg0, jbyteArray arg1, jint arg2)
@@ -18184,6 +18231,26 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1widget_1get_1modifier_1style)
}
#endif
+#ifndef NO__1gtk_1widget_1get_1name
+JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1widget_1get_1name)
+ (JNIEnv *env, jclass that, jintLong arg0)
+{
+ jintLong rc = 0;
+ OS_NATIVE_ENTER(env, that, _1gtk_1widget_1get_1name_FUNC);
+/*
+ rc = (jintLong)gtk_widget_get_name(arg0);
+*/
+ {
+ OS_LOAD_FUNCTION(fp, gtk_widget_get_name)
+ if (fp) {
+ rc = (jintLong)((jintLong (CALLING_CONVENTION*)(jintLong))fp)(arg0);
+ }
+ }
+ OS_NATIVE_EXIT(env, that, _1gtk_1widget_1get_1name_FUNC);
+ return rc;
+}
+#endif
+
#ifndef NO__1gtk_1widget_1get_1pango_1context
JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1widget_1get_1pango_1context)
(JNIEnv *env, jclass that, jintLong arg0)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h
index 90084ea..c9ea289 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h
@@ -188,4 +188,5 @@
#define NO__1gdk_1rgba_1to_1string
+#define NO__1gdk_1rgba_1parse
#define NO__1g_1object_1set__I_3BLorg_eclipse_swt_internal_gtk_GdkRGBA_2I
#define NO__1g_1object_1set__J_3BLorg_eclipse_swt_internal_gtk_GdkRGBA_2J
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c
index 1d3ec0a..8fe1a26 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c
@@ -512,7 +512,6 @@ static void swt_fixed_realize (GtkWidget *widget) {
window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
gtk_widget_set_window (widget, window);
gdk_window_set_user_data (window, widget);
- gtk_style_context_set_background (gtk_widget_get_style_context (widget), window);
}
static void swt_fixed_map (GtkWidget *widget) {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h
index 42e9109..7a27475 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h
@@ -308,6 +308,7 @@
#define gdk_region_polygon_LIB LIB_GDK
#define gdk_region_get_rectangles_LIB LIB_GDK
#define gdk_rgba_to_string_LIB LIB_GDK
+#define gdk_rgba_parse_LIB LIB_GDK
#define gdk_screen_get_default_LIB LIB_GDK
#define gdk_screen_get_monitor_at_point_LIB LIB_GDK
#define gdk_screen_get_monitor_at_window_LIB LIB_GDK
@@ -360,6 +361,7 @@
#define gtk_window_set_skip_taskbar_hint_LIB LIB_GTK
#define gtk_widget_is_composited_LIB LIB_GTK
#define gtk_widget_get_allocation_LIB LIB_GTK
+#define gtk_widget_get_name_LIB LIB_GTK
#define gtk_widget_size_request_LIB LIB_GTK
#define gtk_widget_get_default_style_LIB LIB_GTK
#define gtk_widget_get_preferred_size_LIB LIB_GTK
@@ -527,6 +529,7 @@
#define gtk_cell_renderer_get_preferred_height_for_width_LIB LIB_GTK
#define gtk_css_provider_load_from_data_LIB LIB_GTK
#define gtk_css_provider_new_LIB LIB_GTK
+#define gtk_css_provider_to_string_LIB LIB_GTK
#define gtk_icon_set_render_icon_pixbuf_LIB LIB_GTK
#define gtk_drag_set_icon_surface_LIB LIB_GTK
#define gtk_accel_label_set_accel_LIB LIB_GTK
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
index 64982d3..2439244 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
@@ -553,6 +553,7 @@ char * OS_nativeFunctionNames[] = {
"_1gdk_1region_1subtract",
"_1gdk_1region_1union",
"_1gdk_1region_1union_1with_1rect",
+ "_1gdk_1rgba_1parse",
"_1gdk_1rgba_1to_1string",
"_1gdk_1screen_1get_1default",
"_1gdk_1screen_1get_1monitor_1at_1point",
@@ -735,6 +736,7 @@ char * OS_nativeFunctionNames[] = {
"_1gtk_1container_1set_1border_1width",
"_1gtk_1css_1provider_1load_1from_1data",
"_1gtk_1css_1provider_1new",
+ "_1gtk_1css_1provider_1to_1string",
"_1gtk_1dialog_1add_1button",
"_1gtk_1dialog_1run",
"_1gtk_1drag_1begin",
@@ -1371,6 +1373,7 @@ char * OS_nativeFunctionNames[] = {
"_1gtk_1widget_1get_1has_1window",
"_1gtk_1widget_1get_1mapped",
"_1gtk_1widget_1get_1modifier_1style",
+ "_1gtk_1widget_1get_1name",
"_1gtk_1widget_1get_1pango_1context",
"_1gtk_1widget_1get_1parent",
"_1gtk_1widget_1get_1parent_1window",
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
index 15c9f78..30137be 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
@@ -563,6 +563,7 @@ typedef enum {
_1gdk_1region_1subtract_FUNC,
_1gdk_1region_1union_FUNC,
_1gdk_1region_1union_1with_1rect_FUNC,
+ _1gdk_1rgba_1parse_FUNC,
_1gdk_1rgba_1to_1string_FUNC,
_1gdk_1screen_1get_1default_FUNC,
_1gdk_1screen_1get_1monitor_1at_1point_FUNC,
@@ -745,6 +746,7 @@ typedef enum {
_1gtk_1container_1set_1border_1width_FUNC,
_1gtk_1css_1provider_1load_1from_1data_FUNC,
_1gtk_1css_1provider_1new_FUNC,
+ _1gtk_1css_1provider_1to_1string_FUNC,
_1gtk_1dialog_1add_1button_FUNC,
_1gtk_1dialog_1run_FUNC,
_1gtk_1drag_1begin_FUNC,
@@ -1381,6 +1383,7 @@ typedef enum {
_1gtk_1widget_1get_1has_1window_FUNC,
_1gtk_1widget_1get_1mapped_FUNC,
_1gtk_1widget_1get_1modifier_1style_FUNC,
+ _1gtk_1widget_1get_1name_FUNC,
_1gtk_1widget_1get_1pango_1context_FUNC,
_1gtk_1widget_1get_1parent_FUNC,
_1gtk_1widget_1get_1parent_1window_FUNC,
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
index b47c738..d3e52c3 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
@@ -1795,6 +1795,16 @@ public static final boolean gtk_widget_get_sensitive(long /*int*/ widget) {
lock.unlock();
}
}
+/** @method flags=dynamic */
+public static final native long /*int*/ _gtk_widget_get_name(long /*int*/ widget);
+public static final long /*int*/ gtk_widget_get_name(long /*int*/ widget) {
+ lock.lock();
+ try {
+ return _gtk_widget_get_name(widget);
+ } finally {
+ lock.unlock();
+ }
+}
public static final native void _GTK_WIDGET_SET_FLAGS(long /*int*/ wid, int flag);
public static final void GTK_WIDGET_SET_FLAGS(long /*int*/ wid, int flag) {
lock.lock();
@@ -5491,9 +5501,9 @@ public static final void gdk_region_union_with_rect(long /*int*/ region, GdkRect
lock.unlock();
}
}
-/**
+/**
* @method flags=dynamic
- * @param rgba cast=(GdkRGBA *)
+ * @param rgba cast=(GdkRGBA *)
*/
public static final native long /*int*/ _gdk_rgba_to_string(GdkRGBA rgba);
public static final long /*int*/ gdk_rgba_to_string(GdkRGBA rgba) {
@@ -5504,6 +5514,20 @@ public static final long /*int*/ gdk_rgba_to_string(GdkRGBA rgba) {
lock.unlock();
}
}
+/**
+ * @method flags=dynamic
+ * @param rgba cast=(GdkRGBA *)
+ * @param property cast=(const gchar *)
+ */
+public static final native long /*int*/ _gdk_rgba_parse(GdkRGBA rgba, byte[] property);
+public static final long /*int*/ gdk_rgba_parse(GdkRGBA rgba, byte[] property) {
+ lock.lock();
+ try {
+ return _gdk_rgba_parse(rgba, property);
+ } finally {
+ lock.unlock();
+ }
+}
/** @method flags=dynamic */
public static final native long /*int*/ _gdk_screen_get_default();
public static final long /*int*/ gdk_screen_get_default() {
@@ -9265,6 +9289,16 @@ public static final long /*int*/gtk_css_provider_new() {
lock.unlock();
}
}
+/** @method flags=dynamic */
+public static final native long /*int*/ _gtk_css_provider_to_string(long /*int*/ provider);
+public static final long /*int*/gtk_css_provider_to_string(long /*int*/ provider) {
+ lock.lock();
+ try {
+ return _gtk_css_provider_to_string(provider);
+ } finally {
+ lock.unlock();
+ }
+}
/**
* @method flags=dynamic
* @param screen cast=(GdkScreen *)
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 6ae6636..d7d772c 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
@@ -2610,18 +2610,22 @@ public Image getBackgroundImage () {
GdkColor getContextBackground () {
long /*int*/ fontHandle = fontHandle ();
- long /*int*/ context = OS.gtk_widget_get_style_context (fontHandle);
- int styleState = OS.gtk_widget_get_state_flags(handle);
- GdkRGBA rgba = new GdkRGBA ();
- OS.gtk_style_context_get_background_color (context, styleState, rgba);
- if (rgba.alpha == 0) {
- return display.COLOR_WIDGET_BACKGROUND;
+ if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0) && provider != 0) {
+ return gtk_css_parse_background (provider);
+ } else {
+ long /*int*/ context = OS.gtk_widget_get_style_context (fontHandle);
+ int styleState = OS.gtk_widget_get_state_flags(handle);
+ GdkRGBA rgba = new GdkRGBA ();
+ OS.gtk_style_context_get_background_color (context, styleState, rgba);
+ if (rgba.alpha == 0) {
+ return display.COLOR_WIDGET_BACKGROUND;
+ }
+ GdkColor color = new GdkColor ();
+ color.red = (short)(rgba.red * 0xFFFF);
+ color.green = (short)(rgba.green * 0xFFFF);
+ color.blue = (short)(rgba.blue * 0xFFFF);
+ return color;
}
- GdkColor color = new GdkColor ();
- color.red = (short)(rgba.red * 0xFFFF);
- color.green = (short)(rgba.green * 0xFFFF);
- color.blue = (short)(rgba.blue * 0xFFFF);
- return color;
}
GdkColor getContextColor () {
@@ -4087,7 +4091,22 @@ private void _setBackground (Color color) {
}
void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) {
- OS.gtk_widget_override_background_color (handle, OS.GTK_STATE_FLAG_NORMAL, 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);
+ } else {
+ OS.gtk_widget_override_background_color (handle, OS.GTK_STATE_FLAG_NORMAL, rgba);
+ }
}
void setBackgroundColorGradient (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) {
@@ -4142,6 +4161,61 @@ String gtk_rgba_to_css_string (GdkRGBA rgba) {
return new String (Converter.mbcsToWcs (null, buffer));
}
+GdkColor gtk_css_parse_background (long /*int*/ provider) {
+ String shortOutput;
+ int startIndex;
+ GdkColor color = new GdkColor ();
+ 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 = 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 = gtk_css_property_to_rgba (shortOutput);
+ } else {
+ return display.COLOR_WIDGET_BACKGROUND;
+ }
+ }
+ color.red = (short)(rgba.red * 0xFFFF);
+ color.green = (short)(rgba.green * 0xFFFF);
+ color.blue = (short)(rgba.blue * 0xFFFF);
+ return color;
+}
+
+GdkRGBA gtk_css_property_to_rgba(String property) {
+ /* Here we convert rgb(...) or rgba(...) properties
+ * into GdkRGBA objects using gdk_rgba_parse(). Note
+ * that we still need to remove the ";" character from the
+ * input string.
+ */
+ GdkRGBA rgba = new GdkRGBA ();
+ String [] propertyParsed = new String [1];
+ propertyParsed = property.split (";");
+ OS.gdk_rgba_parse (rgba, Converter.wcsToMbcs (null, propertyParsed[0], true));
+ return rgba;
+}
+
void setBackgroundColor (long /*int*/ handle, GdkColor color) {
if (OS.GTK3) {
GdkRGBA rgba = null;
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 9749576..073c88b 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
@@ -492,9 +492,11 @@ private void gtk_label_set_align (float xalign, float yalign) {
@Override
void setBackgroundColor (GdkColor color) {
super.setBackgroundColor (color);
- setBackgroundColor(fixedHandle, color);
- if (labelHandle != 0) setBackgroundColor(labelHandle, color);
- if (imageHandle != 0) setBackgroundColor(imageHandle, color);
+ if (OS.GTK_VERSION < OS.VERSION(3, 16, 0)) {
+ setBackgroundColor(fixedHandle, color);
+ if (labelHandle != 0) setBackgroundColor(labelHandle, color);
+ if (imageHandle != 0) setBackgroundColor(imageHandle, color);
+ }
}
@Override
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 3bbb886..8930061 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
@@ -65,6 +65,10 @@ public class Spinner extends Composite {
static {
LIMIT = 0x7FFFFFFF;
}
+ /* Spinner uses non-standard CSS to set its background color, so we need
+ * a global variable to keep track of its background color.
+ */
+ GdkRGBA background;
/**
* Constructs a new instance of this class given its parent
@@ -917,7 +921,25 @@ void removeVerifyListener (VerifyListener listener) {
}
@Override
+GdkColor getContextBackground () {
+ if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
+ if (background != null) {
+ GdkColor color = new GdkColor ();
+ color.red = (short)(background.red * 0xFFFF);
+ color.green = (short)(background.green * 0xFFFF);
+ color.blue = (short)(background.blue * 0xFFFF);
+ return color;
+ } else {
+ return display.COLOR_WIDGET_BACKGROUND;
+ }
+ } else {
+ return super.getContextBackground ();
+ }
+}
+
+@Override
void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) {
+ background = rgba;
setBackgroundColorGradient (context, handle, rgba);
}
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 faf6aa5..89bd414 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
@@ -80,6 +80,7 @@ public class Table extends Composite {
boolean firstCustomDraw;
int drawState, drawFlags;
GdkColor drawForeground;
+ GdkRGBA background;
boolean ownerDraw, ignoreSize, ignoreAccessibility;
static final int CHECKED_COLUMN = 0;
@@ -1336,6 +1337,23 @@ public TableColumn [] getColumns () {
return result;
}
+@Override
+GdkColor getContextBackground () {
+ if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
+ if (background != null) {
+ GdkColor color = new GdkColor ();
+ color.red = (short)(background.red * 0xFFFF);
+ color.green = (short)(background.green * 0xFFFF);
+ color.blue = (short)(background.blue * 0xFFFF);
+ return color;
+ } else {
+ return display.COLOR_WIDGET_BACKGROUND;
+ }
+ } else {
+ return super.getContextBackground ();
+ }
+}
+
TableItem getFocusItem () {
long /*int*/ [] path = new long /*int*/ [1];
OS.gtk_tree_view_get_cursor (handle, path, null);
@@ -3102,17 +3120,30 @@ void setBackgroundColor (GdkColor color) {
super.setBackgroundColor (color);
if (!OS.GTK3) {
OS.gtk_widget_modify_base (handle, 0, color);
+ }
+}
+
+@Override
+void setBackgroundColor (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
+ * on GTK3.16+, or by using GtkStateFlags as an argument to
+ * gtk_widget_override_background_color() on versions of GTK3 less than 3.16.
+ */
+ background = rgba;
+ GdkColor defaultColor = getDisplay().COLOR_LIST_SELECTION;
+ GdkRGBA selectedBackground = new GdkRGBA ();
+ selectedBackground.alpha = 1;
+ selectedBackground.red = (defaultColor.red & 0xFFFF) / (float)0xFFFF;
+ selectedBackground.green = (defaultColor.green & 0xFFFF) / (float)0xFFFF;
+ selectedBackground.blue = (defaultColor.blue & 0xFFFF) / (float)0xFFFF;
+ if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
+ String css = "GtkTreeView {background-color: " + gtk_rgba_to_css_string(rgba) + ";}\n"
+ + "GtkTreeView:selected {background-color: " + gtk_rgba_to_css_string(selectedBackground) + ";}";
+ gtk_css_provider_load_from_css(context, css);
} else {
- // Setting the background color overrides the selected background color
- // so we have to reset it the default.
- GdkColor defaultColor = getDisplay().COLOR_LIST_SELECTION;
- GdkRGBA selectedBackground = new GdkRGBA ();
- selectedBackground.alpha = 1;
- selectedBackground.red = (defaultColor.red & 0xFFFF) / (float)0xFFFF;
- selectedBackground.green = (defaultColor.green & 0xFFFF) / (float)0xFFFF;
- selectedBackground.blue = (defaultColor.blue & 0xFFFF) / (float)0xFFFF;
-
- OS.gtk_widget_override_background_color (handle, OS.GTK_STATE_FLAG_SELECTED, selectedBackground);
+ super.setBackgroundColor(context, handle, rgba);
+ OS.gtk_widget_override_background_color(handle, OS.GTK_STATE_FLAG_SELECTED, selectedBackground);
}
}
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 8d5d0ba..12a2e81 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
@@ -98,6 +98,10 @@ public class Text extends Scrollable {
LIMIT = 0x7FFFFFFF;
DELIMITER = "\n";
}
+ /* 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;
/**
* Constructs a new instance of this class given its parent
@@ -598,7 +602,7 @@ public Rectangle computeTrim (int x, int y, int width, int height) {
trim.width += tmp.left + tmp.right;
trim.height += tmp.top + tmp.bottom;
if ((style & SWT.BORDER) != 0) {
- OS.gtk_style_context_get_border (context, OS.GTK_STATE_FLAG_NORMAL, tmp);
+ OS.gtk_style_context_get_border (context, styleState, tmp);
trim.x -= tmp.left;
trim.y -= tmp.top;
trim.width += tmp.left + tmp.right;
@@ -2146,7 +2150,25 @@ void setBackgroundColor (GdkColor color) {
}
@Override
+GdkColor getContextBackground () {
+ if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
+ if (background != null) {
+ GdkColor color = new GdkColor ();
+ color.red = (short)(background.red * 0xFFFF);
+ color.green = (short)(background.green * 0xFFFF);
+ color.blue = (short)(background.blue * 0xFFFF);
+ return color;
+ } else {
+ return display.COLOR_WIDGET_BACKGROUND;
+ }
+ } else {
+ return super.getContextBackground ();
+ }
+}
+
+@Override
void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) {
+ background = rgba;
if ((style & SWT.MULTI) != 0) {
super.setBackgroundColor (context, handle, rgba);
return;
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 86bda76..acc271e 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,12 @@ public class ToolBar extends Composite {
menuItemSelectedFunc = new Callback(ToolBar.class, "MenuItemSelectedProc", 2);
if (menuItemSelectedFunc.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
}
+ /*
+ * We need to keep track of the background color ourselves, otherwise ToolBars will
+ * sometimes have the background color of their parent Composite. Also, ToolBars on
+ * GTK are called GtkToolbar-swt-toolbar-flat which can cause issues with CSS theming.
+ */
+ GdkRGBA background;
/**
* Constructs a new instance of this class given its parent
@@ -260,6 +266,23 @@ boolean forceFocus (long /*int*/ focusHandle) {
return super.forceFocus (focusHandle);
}
+@Override
+GdkColor getContextBackground () {
+ if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
+ if (background != null) {
+ GdkColor color = new GdkColor ();
+ color.red = (short)(background.red * 0xFFFF);
+ color.green = (short)(background.green * 0xFFFF);
+ color.blue = (short)(background.blue * 0xFFFF);
+ return color;
+ } else {
+ return display.COLOR_WIDGET_BACKGROUND;
+ }
+ } else {
+ return super.getContextBackground ();
+ }
+}
+
/**
* Returns the item at the given, zero-relative index in the
* receiver. Throws an exception if the index is out of range.
@@ -588,6 +611,7 @@ 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) {
+ background = 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);
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 32ebf72..f8aaa6a 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
@@ -89,6 +89,7 @@ public class Tree extends Composite {
boolean expandAll;
int drawState, drawFlags;
GdkColor drawForeground;
+ GdkRGBA background;
boolean ownerDraw, ignoreSize, ignoreAccessibility;
static final int ID_COLUMN = 0;
@@ -1333,6 +1334,23 @@ public TreeColumn [] getColumns () {
return result;
}
+@Override
+GdkColor getContextBackground () {
+ if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
+ if (background != null) {
+ GdkColor color = new GdkColor ();
+ color.red = (short)(background.red * 0xFFFF);
+ color.green = (short)(background.green * 0xFFFF);
+ color.blue = (short)(background.blue * 0xFFFF);
+ return color;
+ } else {
+ return display.COLOR_WIDGET_BACKGROUND;
+ }
+ } else {
+ return super.getContextBackground ();
+ }
+}
+
TreeItem getFocusItem () {
long /*int*/ [] path = new long /*int*/ [1];
OS.gtk_tree_view_get_cursor (handle, path, null);
@@ -3087,17 +3105,30 @@ void setBackgroundColor (GdkColor color) {
super.setBackgroundColor (color);
if (!OS.GTK3) {
OS.gtk_widget_modify_base (handle, 0, color);
+ }
+}
+
+@Override
+void setBackgroundColor (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
+ * on GTK3.16+, or by using GtkStateFlags as an argument to
+ * gtk_widget_override_background_color() on versions of GTK3 less than 3.16.
+ */
+ background = rgba;
+ GdkColor defaultColor = getDisplay().COLOR_LIST_SELECTION;
+ GdkRGBA selectedBackground = new GdkRGBA ();
+ selectedBackground.alpha = 1;
+ selectedBackground.red = (defaultColor.red & 0xFFFF) / (float)0xFFFF;
+ selectedBackground.green = (defaultColor.green & 0xFFFF) / (float)0xFFFF;
+ selectedBackground.blue = (defaultColor.blue & 0xFFFF) / (float)0xFFFF;
+ if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
+ String css = "GtkTreeView {background-color: " + gtk_rgba_to_css_string(rgba) + ";}\n"
+ + "GtkTreeView:selected {background-color: " + gtk_rgba_to_css_string(selectedBackground) + ";}";
+ gtk_css_provider_load_from_css(context, css);
} else {
- // Setting the background color overrides the selected background color
- // so we have to reset it the default.
- GdkColor defaultColor = getDisplay().COLOR_LIST_SELECTION;
- GdkRGBA selectedBackground = new GdkRGBA ();
- selectedBackground.alpha = 1;
- selectedBackground.red = (defaultColor.red & 0xFFFF) / (float)0xFFFF;
- selectedBackground.green = (defaultColor.green & 0xFFFF) / (float)0xFFFF;
- selectedBackground.blue = (defaultColor.blue & 0xFFFF) / (float)0xFFFF;
-
- OS.gtk_widget_override_background_color (handle, OS.GTK_STATE_FLAG_SELECTED, selectedBackground);
+ super.setBackgroundColor(context, handle, rgba);
+ OS.gtk_widget_override_background_color(handle, OS.GTK_STATE_FLAG_SELECTED, selectedBackground);
}
}
--
2.5.0