Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Williams2017-07-20 14:47:04 +0000
committerEric Williams2017-07-20 14:55:18 +0000
commit511aa0454b2843c23c65b83a67b3012babdde383 (patch)
tree990c8b637730b5cb487066aa5224c84058db5b73
parent610c36f36bcbc8509c1a53a463ec4671f7976118 (diff)
downloadeclipse.platform.swt-511aa0454b2843c23c65b83a67b3012babdde383.tar.gz
eclipse.platform.swt-511aa0454b2843c23c65b83a67b3012babdde383.tar.xz
eclipse.platform.swt-511aa0454b2843c23c65b83a67b3012babdde383.zip
Bug 519576: [GTK3] Use GTK CSS for background/foreground colors on
GTK3.14 and below This fix reverts some changes in Table and Tree that were not necessary to begin with. They were causing failing test cases in Platform UI and are not integral to the actual bug. Change-Id: I94e61737e2a39bb21dc5846097a83264d72f6d1e Signed-off-by: Eric Williams <ericwill@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java3
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java45
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java45
3 files changed, 89 insertions, 4 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 46e4cea20f..70c11d9d45 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
@@ -4474,8 +4474,7 @@ void setBackgroundGdkRGBA (long /*int*/ context, long /*int*/ handle, GdkRGBA rg
// Form background string
String name = OS.GTK_VERSION >= OS.VERSION(3, 20, 0) ? display.gtk_widget_class_get_css_name(handle)
: display.gtk_widget_get_name(handle);
- String selection = OS.GTK_VERSION >= OS.VERSION(3, 20, 0) &&
- !name.contains("treeview") ? " selection" : ":selected";
+ String selection = OS.GTK_VERSION >= OS.VERSION(3, 20, 0) ? " selection" : ":selected";
String css = name + " {background-color: " + display.gtk_rgba_to_css_string(rgba) + ";}\n"
+ name + selection + " {background-color: " + display.gtk_rgba_to_css_string(selectedBackground) + ";}";
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 45d03c992e..bef8da39f1 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
@@ -82,7 +82,7 @@ public class Table extends Composite {
boolean firstCustomDraw;
int drawState, drawFlags;
GdkColor drawForeground;
- GdkRGBA foreground, drawForegroundRGBA;
+ GdkRGBA background, foreground, drawForegroundRGBA;
Color headerBackground, headerForeground;
String headerCSSBackground, headerCSSForeground;
boolean ownerDraw, ignoreSize, ignoreAccessibility, pixbufSizeSet;
@@ -1421,6 +1421,18 @@ public TableColumn [] getColumns () {
}
@Override
+GdkRGBA getContextBackgroundGdkRGBA () {
+ assert OS.GTK3 : "GTK3 code was run by GTK2";
+ if (background != null) {
+ return background;
+ } else {
+ // For Tables and Trees, the default background is
+ // COLOR_LIST_BACKGROUND instead of COLOR_WIDGET_BACKGROUND.
+ return display.COLOR_LIST_BACKGROUND_RGBA;
+ }
+}
+
+@Override
GdkRGBA getContextColorGdkRGBA () {
assert OS.GTK3 : "GTK3 code was run by GTK2";
if (OS.GTK_VERSION >= OS.VERSION(3, 14, 0)) {
@@ -3349,6 +3361,37 @@ void setBackgroundGdkColor (GdkColor color) {
}
@Override
+void setBackgroundGdkRGBA (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) {
+ assert OS.GTK3 : "GTK3 code was run by GTK2";
+ /* 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.14+, or by using GtkStateFlags as an argument to
+ * gtk_widget_override_background_color() on versions of GTK3 less than 3.16.
+ */
+ if (rgba == null) {
+ background = display.COLOR_LIST_BACKGROUND_RGBA;
+ } else {
+ background = rgba;
+ }
+ GdkRGBA selectedBackground = display.getSystemColor(SWT.COLOR_LIST_SELECTION).handleRGBA;
+ if (OS.GTK_VERSION >= OS.VERSION(3, 14, 0)) {
+ String name = OS.GTK_VERSION >= OS.VERSION(3, 20, 0) ? "treeview" : "GtkTreeView";
+ String css = name + " {background-color: " + display.gtk_rgba_to_css_string(background) + ";}\n"
+ + name + ":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.setBackgroundGdkRGBA(context, handle, rgba);
+ OS.gtk_widget_override_background_color(handle, OS.GTK_STATE_FLAG_SELECTED, selectedBackground);
+ }
+}
+
+@Override
void setBackgroundPixmap (Image image) {
ownerDraw = true;
recreateRenderers ();
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 e4f041449a..ce38d7a6ba 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
@@ -90,7 +90,7 @@ public class Tree extends Composite {
boolean expandAll;
int drawState, drawFlags;
GdkColor drawForeground;
- GdkRGBA foreground, drawForegroundRGBA;
+ GdkRGBA background, foreground, drawForegroundRGBA;
boolean ownerDraw, ignoreSize, ignoreAccessibility, pixbufSizeSet;
int pixbufHeight, pixbufWidth;
TreeItem topItem;
@@ -1414,6 +1414,18 @@ public TreeColumn [] getColumns () {
}
@Override
+GdkRGBA getContextBackgroundGdkRGBA () {
+ assert OS.GTK3 : "GTK3 code was run by GTK2";
+ if (background != null) {
+ return background;
+ } else {
+ // For Tables and Trees, the default background is
+ // COLOR_LIST_BACKGROUND instead of COLOR_WIDGET_BACKGROUND.
+ return display.COLOR_LIST_BACKGROUND_RGBA;
+ }
+}
+
+@Override
GdkRGBA getContextColorGdkRGBA () {
if (OS.GTK_VERSION >= OS.VERSION(3, 14, 0)) {
if (foreground != null) {
@@ -3378,6 +3390,37 @@ void setBackgroundGdkColor (GdkColor color) {
}
@Override
+void setBackgroundGdkRGBA (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) {
+ assert OS.GTK3 : "GTK3 code was run by GTK2";
+ /* 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.14+, or by using GtkStateFlags as an argument to
+ * gtk_widget_override_background_color() on versions of GTK3 less than 3.16.
+ */
+ if (rgba == null) {
+ background = display.COLOR_LIST_BACKGROUND_RGBA;
+ } else {
+ background = rgba;
+ }
+ GdkRGBA selectedBackground = display.getSystemColor(SWT.COLOR_LIST_SELECTION).handleRGBA;
+ if (OS.GTK_VERSION >= OS.VERSION(3, 14, 0)) {
+ String name = OS.GTK_VERSION >= OS.VERSION(3, 20, 0) ? "treeview" : "GtkTreeView";
+ String css = name + " {background-color: " + display.gtk_rgba_to_css_string(background) + ";}\n"
+ + name + ":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.setBackgroundGdkRGBA(context, handle, rgba);
+ OS.gtk_widget_override_background_color(handle, OS.GTK_STATE_FLAG_SELECTED, selectedBackground);
+ }
+}
+
+@Override
void setBackgroundPixmap (Image image) {
ownerDraw = true;
recreateRenderers ();

Back to the top