Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXi Yan2018-09-11 17:38:45 +0000
committerEric Williams2018-09-12 20:06:22 +0000
commita6c44f4c7093b8b2c9d629a75604a6d650b09686 (patch)
tree243838ef47291576aa090536349667a613c42081 /bundles/org.eclipse.swt
parent872a22b373752d88298a555447667414b513ee64 (diff)
downloadeclipse.platform.swt-a6c44f4c7093b8b2c9d629a75604a6d650b09686.tar.gz
eclipse.platform.swt-a6c44f4c7093b8b2c9d629a75604a6d650b09686.tar.xz
eclipse.platform.swt-a6c44f4c7093b8b2c9d629a75604a6d650b09686.zip
Bug 464228 - [Gtk3] Combo box styling differences
Button on non-readonly Combo is not styled, so the background color of the button on combo is dependent on OS theme. GtkEntry and GtkToggleButton in Combo needs to be themed separately using different css providers. Added provider instance for button to load the background CSS to both entry and button instead of the entry only. Tested in child Eclipse in dark theme. On Ubuntu, Combo button is now dark instead of white. On Fedora, Combo button now has same background as entry. Change-Id: I77fbe01361c84309aadc9ab187ebaf80f560850c Signed-off-by: Xi Yan <xixiyan@redhat.com>
Diffstat (limited to 'bundles/org.eclipse.swt')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java57
1 files changed, 53 insertions, 4 deletions
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 f16bd0a2ef..06ed4fff62 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
@@ -68,7 +68,9 @@ public class Combo extends Composite {
int fixStart = -1, fixEnd = -1;
String [] items = new String [0];
int indexSelected;
- GdkRGBA background;
+ GdkRGBA background, buttonBackground;
+ String cssButtonBackground, cssButtonForeground = " ";
+ long /*int*/ buttonProvider;
boolean firstDraw = true;
/**
* the operating system limit for the number of characters
@@ -612,6 +614,10 @@ GdkRGBA defaultBackground () {
return display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).handleRGBA;
}
+GdkRGBA defaultButtonBackground () {
+ return display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND).handleRGBA;
+}
+
@Override
void deregister () {
super.deregister ();
@@ -2027,6 +2033,45 @@ public void select (int index) {
}
}
+void setButtonBackgroundGdkRGBA (GdkRGBA rgba) {
+ if (rgba == null) {
+ buttonBackground = defaultButtonBackground();
+ } else {
+ buttonBackground = rgba;
+ }
+ String color = display.gtk_rgba_to_css_string (buttonBackground);
+ String css = "* {background: " + color + ";}\n";
+ cssButtonBackground = css;
+ String finalCss = display.gtk_css_create_css_color_string (cssButtonBackground, cssButtonForeground, SWT.BACKGROUND);
+ long /*int*/ buttonContext = GTK.gtk_widget_get_style_context(buttonHandle);
+ if (buttonProvider == 0) {
+ buttonProvider = GTK.gtk_css_provider_new();
+ GTK.gtk_style_context_add_provider(buttonContext, buttonProvider, GTK.GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ OS.g_object_unref(buttonProvider);
+ }
+ GTK.gtk_css_provider_load_from_data (buttonProvider, Converter.wcsToMbcs(finalCss, true), -1, null);
+}
+
+void setButtonForegroundGdkRGBA (GdkRGBA rgba) {
+ assert GTK.GTK3 : "GTK3 code was run by GTK2";
+ GdkRGBA toSet;
+ if (rgba != null) {
+ toSet = rgba;
+ } else {
+ toSet = display.COLOR_WIDGET_FOREGROUND_RGBA;
+ }
+ String color = display.gtk_rgba_to_css_string(toSet);
+ String css = "* {color: " + color + ";}\n";
+ cssButtonForeground = css;
+ String finalCss = display.gtk_css_create_css_color_string(cssButtonBackground, cssButtonForeground, SWT.FOREGROUND);
+ long /*int*/ buttonContext = GTK.gtk_widget_get_style_context(buttonHandle);
+ if (buttonProvider == 0) {
+ buttonProvider = GTK.gtk_css_provider_new();
+ GTK.gtk_style_context_add_provider(buttonContext, buttonProvider, GTK.GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ OS.g_object_unref(buttonProvider);
+ }
+ GTK.gtk_css_provider_load_from_data (buttonProvider, Converter.wcsToMbcs(finalCss, true), -1, null);
+}
@Override
void setBackgroundGdkRGBA (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) {
@@ -2066,8 +2111,10 @@ void setBackgroundGdkRGBA (long /*int*/ context, long /*int*/ handle, GdkRGBA rg
gtk_css_provider_load_from_css (GTK.gtk_widget_get_style_context(buttonHandle), finalCss);
} else {
if (GTK.GTK_VERSION >= OS.VERSION(3, 14, 0)) {
- // For GTK3.14+, only the GtkEntry needs to be themed.
- gtk_css_provider_load_from_css (GTK.gtk_widget_get_style_context(entryHandle), finalCss);
+ // GtkEntry and GtkToggleButton needs to be themed separately with different
+ // providers for coherent background. Similar to Tree/Table headers.
+ gtk_css_provider_load_from_css (GTK._gtk_widget_get_style_context(entryHandle), finalCss);
+ setButtonBackgroundGdkRGBA (rgba);
} else {
// Maintain GTK3.12- functionality
setBackgroundGradientGdkRGBA (GTK.gtk_widget_get_style_context (entryHandle), handle, rgba);
@@ -2146,11 +2193,13 @@ void setForegroundGdkRGBA (GdkRGBA rgba) {
if (entryHandle != 0) {
setForegroundGdkRGBA (entryHandle, rgba);
}
+ if ((style & SWT.READ_ONLY) == 0 && buttonHandle != 0) {
+ setButtonForegroundGdkRGBA (rgba);
+ }
OS.g_object_set (textRenderer, OS.foreground_rgba, rgba, 0);
super.setForegroundGdkRGBA(rgba);
}
-
/**
* Sets the text of the item in the receiver's list at the given
* zero-relative index to the string argument.

Back to the top