Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java57
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualNativeCTests/BugSnippets/Bug_464228_ComboBox.c57
2 files changed, 110 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.
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualNativeCTests/BugSnippets/Bug_464228_ComboBox.c b/tests/org.eclipse.swt.tests.gtk/ManualNativeCTests/BugSnippets/Bug_464228_ComboBox.c
new file mode 100644
index 0000000000..c49d5870b3
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/ManualNativeCTests/BugSnippets/Bug_464228_ComboBox.c
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Red Hat and others. All rights reserved.
+ * The contents of this file are made available under the terms
+ * of the GNU Lesser General Public License (LGPL) Version 2.1 that
+ * accompanies this distribution (lgpl-v21.txt). The LGPL is also
+ * available at http://www.gnu.org/licenses/lgpl.html. If the version
+ * of the LGPL at http://www.gnu.org is different to the version of
+ * the LGPL accompanying this distribution and there is any conflict
+ * between the two license versions, the terms of the LGPL accompanying
+ * this distribution shall govern.
+ *
+ * Contributors:
+ * Red Hat - initial API and implementation
+ *******************************************************************************/
+
+#include <gtk/gtk.h>
+
+/*
+ * GtkInspector: combobox {background: rgb(75, 75, 75); color: white;}
+ */
+
+static gboolean delete_event(GtkWidget*, GdkEvent*, gpointer);
+
+int main(int argc, char *argv[]) {
+ GtkWidget *window;
+ GtkWidget *combobox;
+ GtkWidget *main_vbox;
+ gtk_init(&argc, &argv);
+
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ g_signal_connect(window, "delete_event", G_CALLBACK(delete_event), NULL);
+ gtk_window_resize((GtkWindow *) window, 600, 600);
+
+ combobox = gtk_combo_box_text_new_with_entry();
+ gtk_widget_set_size_request (combobox, -1, 40);
+
+ gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(combobox), NULL, "ITEM 1");
+ gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(combobox), NULL, "ITEM 2");
+
+ main_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+ gtk_container_add(GTK_CONTAINER(window), main_vbox);
+
+ gtk_box_pack_start(GTK_BOX(main_vbox), combobox, FALSE, FALSE, 0);
+
+
+ gtk_widget_show_all(window);
+
+ gtk_main();
+
+ return 0;
+}
+
+static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data) {
+ gtk_main_quit();
+
+ return FALSE;
+}

Back to the top