2a679db
From 3dc220718412431322c00e1f820c9ce0168892f5 Mon Sep 17 00:00:00 2001
2a679db
From: Eric Williams
2a679db
Date: Mon, 23 Nov 2015 10:37:11 -0500
2a679db
Subject: Bug 481122: [GTK3.18+] some set/get Background/Foreground color
2a679db
 methods have no effect
2a679db
2a679db
With changes in GTK3.18 and onward, gtk_style_context_get_color()
2a679db
behaves differently. In order to correctly fetch the color we must first
2a679db
save the GtkStyleContext, set its state, fetch the color, and then
2a679db
restore the GtkStyleContext. Failure to do this on GTK3.18+ leads to
2a679db
failures in the getForegroundColor() method.
2a679db
2a679db
The convenience method styleContextGetColor() in Display takes care of
2a679db
the process.
2a679db
2a679db
Tested on GTK 3.18, 3.16, 3.14, 3.8, and 2.24. All foreground color
2a679db
related tests on GTK3 now pass. GTK2 behaviour remains unchanged.
2a679db
2a679db
Change-Id: I6423edab5038dc0ef54afc6dd826f19fc936f987
2a679db
Signed-off-by: Eric Williams <ericwill@redhat.com>
2a679db
---
2a679db
 .../gtk/org/eclipse/swt/widgets/Control.java       |  2 +-
2a679db
 .../gtk/org/eclipse/swt/widgets/Display.java       | 36 ++++++++++++++--------
2a679db
 .../gtk/org/eclipse/swt/widgets/Text.java          |  2 +-
2a679db
 3 files changed, 26 insertions(+), 14 deletions(-)
2a679db
2a679db
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
2a679db
index ffd9d11..7061084 100644
2a679db
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java	
2a679db
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java	
2a679db
@@ -2626,7 +2626,7 @@ GdkColor getContextColor () {
2a679db
 	long /*int*/ fontHandle = fontHandle ();
2a679db
 	long /*int*/ context = OS.gtk_widget_get_style_context (fontHandle);
2a679db
 	GdkRGBA rgba = new GdkRGBA ();
2a679db
-	OS.gtk_style_context_get_color (context, OS.GTK_STATE_FLAG_NORMAL, rgba);
2a679db
+	rgba = display.styleContextGetColor (context, OS.GTK_STATE_FLAG_NORMAL, rgba);
2a679db
 	GdkColor color = new GdkColor ();
2a679db
 	color.red = (short)(rgba.red * 0xFFFF);
2a679db
 	color.green = (short)(rgba.green * 0xFFFF);
2a679db
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
2a679db
index 0119882..d7e670c 100644
2a679db
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java	
2a679db
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java	
2a679db
@@ -2373,8 +2373,7 @@ void initializeSystemColors () {
2a679db
 		OS.gtk_style_context_add_class (context, OS.GTK_STYLE_CLASS_TOOLTIP);
2a679db
 		OS.gtk_style_context_invalidate(context);
2a679db
 		GdkRGBA rgba = new GdkRGBA();
2a679db
-		OS.gtk_style_context_get_color (context, OS.GTK_STATE_FLAG_NORMAL, rgba);
2a679db
-		COLOR_INFO_FOREGROUND = toGdkColor (rgba);
2a679db
+		COLOR_INFO_FOREGROUND = toGdkColor (styleContextGetColor (context, OS.GTK_STATE_FLAG_NORMAL, rgba));
2a679db
 		getBackgroundColor (context, OS.GTK_STATE_FLAG_NORMAL, rgba);
2a679db
 		COLOR_INFO_BACKGROUND = toGdkColor (rgba);
2a679db
 		OS.gtk_widget_destroy (tooltipShellHandle);
2a679db
@@ -2387,8 +2386,7 @@ void initializeSystemColors () {
2a679db
 		COLOR_WIDGET_NORMAL_SHADOW = toGdkColor (rgba, 0.7);
2a679db
 		COLOR_WIDGET_HIGHLIGHT_SHADOW = toGdkColor (rgba, 1.3);
2a679db
 
2a679db
-		OS.gtk_style_context_get_color (context, OS.GTK_STATE_FLAG_NORMAL, rgba);
2a679db
-		COLOR_WIDGET_FOREGROUND = toGdkColor (rgba);
2a679db
+		COLOR_WIDGET_FOREGROUND = toGdkColor (styleContextGetColor (context, OS.GTK_STATE_FLAG_NORMAL, rgba));
2a679db
 		OS.gtk_style_context_get_background_color (context, OS.GTK_STATE_FLAG_NORMAL, rgba);
2a679db
 		COLOR_WIDGET_BACKGROUND = toGdkColor (rgba);
2a679db
 
2a679db
@@ -2396,17 +2394,14 @@ void initializeSystemColors () {
2a679db
 		OS.gtk_style_context_add_class(context, OS.GTK_STYLE_CLASS_VIEW);
2a679db
 		OS.gtk_style_context_add_class(context, OS.GTK_STYLE_CLASS_CELL);
2a679db
 		OS.gtk_style_context_invalidate(context);
2a679db
-		OS.gtk_style_context_get_color (context, OS.GTK_STATE_FLAG_NORMAL, rgba);
2a679db
-		COLOR_LIST_FOREGROUND = toGdkColor (rgba);
2a679db
+		COLOR_LIST_FOREGROUND = toGdkColor (styleContextGetColor (context, OS.GTK_STATE_FLAG_NORMAL, rgba));
2a679db
 		OS.gtk_style_context_get_background_color (context, OS.GTK_STATE_FLAG_NORMAL, rgba);
2a679db
 		COLOR_LIST_BACKGROUND = toGdkColor (rgba);
2a679db
 		OS.gtk_style_context_restore (context);
2a679db
-		OS.gtk_style_context_get_color (context, OS.GTK_STATE_FLAG_SELECTED, rgba);
2a679db
-		COLOR_LIST_SELECTION_TEXT = toGdkColor (rgba);
2a679db
+		COLOR_LIST_SELECTION_TEXT = toGdkColor (styleContextGetColor (context, OS.GTK_STATE_FLAG_SELECTED, rgba));
2a679db
 		OS.gtk_style_context_get_background_color (context, OS.GTK_STATE_FLAG_SELECTED, rgba);
2a679db
 		COLOR_LIST_SELECTION = toGdkColor (rgba);
2a679db
-		OS.gtk_style_context_get_color (context, OS.GTK_STATE_FLAG_ACTIVE, rgba);
2a679db
-		COLOR_LIST_SELECTION_TEXT_INACTIVE = toGdkColor (rgba);
2a679db
+		COLOR_LIST_SELECTION_TEXT_INACTIVE = toGdkColor (styleContextGetColor (context, OS.GTK_STATE_FLAG_ACTIVE, rgba));
2a679db
 		OS.gtk_style_context_get_background_color (context, OS.GTK_STATE_FLAG_ACTIVE, rgba);
2a679db
 		COLOR_LIST_SELECTION_INACTIVE = toGdkColor (rgba);
2a679db
 
2a679db
@@ -2415,8 +2410,7 @@ void initializeSystemColors () {
2a679db
 		OS.gtk_style_context_get_background_color (context, OS.GTK_STATE_FLAG_SELECTED, rgba);
2a679db
 		COLOR_TITLE_BACKGROUND_GRADIENT = toGdkColor (rgba, 1.3);
2a679db
 
2a679db
-		OS.gtk_style_context_get_color (context, OS.GTK_STATE_FLAG_INSENSITIVE, rgba);
2a679db
-		COLOR_TITLE_INACTIVE_FOREGROUND = toGdkColor (rgba);
2a679db
+		COLOR_TITLE_INACTIVE_FOREGROUND = toGdkColor (styleContextGetColor (context, OS.GTK_STATE_FLAG_INSENSITIVE, rgba));
2a679db
 		OS.gtk_style_context_get_background_color (context, OS.GTK_STATE_FLAG_INSENSITIVE, rgba);
2a679db
 		COLOR_TITLE_INACTIVE_BACKGROUND = toGdkColor (rgba);
2a679db
 		COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT = toGdkColor (rgba, 1.3);
2a679db
@@ -2497,6 +2491,24 @@ void initializeSystemColors () {
2a679db
 	COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT = gdkColor;
2a679db
 }
2a679db
 
2a679db
+GdkRGBA styleContextGetColor(long /*int*/ context, int flag, GdkRGBA rgba) {
2a679db
+	/*
2a679db
+	* Feature in GTK: we need to handle calls to gtk_style_context_get_color()
2a679db
+	* differently due to changes in GTK3.18+. This solves failing test cases
2a679db
+	* which started failing after GTK3.16. See Bug 481122 for more info.
2a679db
+	* Reference: https://blogs.gnome.org/mclasen/2015/11/20/a-gtk-update/
2a679db
+	*/
2a679db
+	if (OS.GTK_VERSION >= OS.VERSION(3, 18, 0)) {
2a679db
+		OS.gtk_style_context_save(context);
2a679db
+		OS.gtk_style_context_set_state(context, flag);
2a679db
+		OS.gtk_style_context_get_color (context, flag, rgba);
2a679db
+		OS.gtk_style_context_restore(context);
2a679db
+	} else {
2a679db
+		OS.gtk_style_context_get_color (context, flag, rgba);
2a679db
+	}
2a679db
+	return rgba;
2a679db
+}
2a679db
+
2a679db
 /**
2a679db
  * Returns the single instance of the system taskBar or null
2a679db
  * when there is no system taskBar available for the platform.
2a679db
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
2a679db
index 2865cd5..6b68b6a 100644
2a679db
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java	
2a679db
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java	
2a679db
@@ -1664,7 +1664,7 @@ void drawMessage (long /*int*/ cr) {
2a679db
 			if (OS.GTK3) {
2a679db
 				long /*int*/ styleContext = OS.gtk_widget_get_style_context (handle);
2a679db
 				GdkRGBA rgba = new GdkRGBA ();
2a679db
-				OS.gtk_style_context_get_color (styleContext, OS.GTK_STATE_FLAG_INSENSITIVE, rgba);
2a679db
+				rgba = display.styleContextGetColor (styleContext, OS.GTK_STATE_FLAG_INSENSITIVE, rgba);
2a679db
 				textColor.red = (short)(rgba.red * 0xFFFF);
2a679db
 				textColor.green = (short)(rgba.green * 0xFFFF);
2a679db
 				textColor.blue = (short)(rgba.blue * 0xFFFF);
2a679db
-- 
2a679db
cgit v0.11.2-4-g4a35
2a679db
2a679db