diff options
author | Alexander Kurtakov <akurtako@redhat.com> | 2013-03-15 11:01:28 +0200 |
---|---|---|
committer | Alexander Kurtakov <akurtako@redhat.com> | 2013-03-15 11:01:28 +0200 |
commit | 7c1b8eca79b80c0d72e829a1c54df2844c3fbc3c (patch) | |
tree | 04ea9c6bac9692f9587c4024ae06fcf79f4d2da0 | |
parent | 5615da8f551c03efc897817665468fdea1e24c53 (diff) | |
download | eclipse.platform.swt-7c1b8eca79b80c0d72e829a1c54df2844c3fbc3c.tar.gz eclipse.platform.swt-7c1b8eca79b80c0d72e829a1c54df2844c3fbc3c.tar.xz eclipse.platform.swt-7c1b8eca79b80c0d72e829a1c54df2844c3fbc3c.zip |
Fix Control.setBackground on GTK3.
The function used gtk_widget_override_background_color doesn't work on
all themes (see https://bugzilla.gnome.org/show_bug.cgi?id=656461 ). In
order to make it work for all themes CSS needs to be used.
6 files changed, 47 insertions, 11 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 cea1a16e4e..a21ddb96a3 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 @@ -14953,6 +14953,24 @@ fail: } #endif +#ifndef NO__1gtk_1style_1context_1add_1provider +JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1style_1context_1add_1provider) + (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jint arg2) +{ + OS_NATIVE_ENTER(env, that, _1gtk_1style_1context_1add_1provider_FUNC); +/* + gtk_style_context_add_provider(arg0, arg1, (guint)arg2); +*/ + { + OS_LOAD_FUNCTION(fp, gtk_style_context_add_provider) + if (fp) { + ((void (CALLING_CONVENTION*)(jintLong, jintLong, guint))fp)(arg0, arg1, (guint)arg2); + } + } + OS_NATIVE_EXIT(env, that, _1gtk_1style_1context_1add_1provider_FUNC); +} +#endif + #ifndef NO__1gtk_1style_1context_1add_1provider_1for_1screen JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1style_1context_1add_1provider_1for_1screen) (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jint arg2) 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 4c39eb104f..0065a62030 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 @@ -278,6 +278,7 @@ #define gtk_scrolled_window_get_vscrollbar_LIB LIB_GTK #define gtk_scale_new_LIB LIB_GTK #define gtk_style_context_add_provider_for_screen_LIB LIB_GTK +#define gtk_style_context_add_provider_LIB LIB_GTK #define gtk_style_context_restore_LIB LIB_GTK #define gtk_style_context_save_LIB LIB_GTK #define gtk_style_context_set_state_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 41fd5a4966..0acbfdfb7a 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 @@ -1066,6 +1066,7 @@ char * OS_nativeFunctionNames[] = { "_1gtk_1status_1icon_1set_1tooltip", "_1gtk_1status_1icon_1set_1visible", "_1gtk_1style_1context_1add_1class", + "_1gtk_1style_1context_1add_1provider", "_1gtk_1style_1context_1add_1provider_1for_1screen", "_1gtk_1style_1context_1get_1background_1color", "_1gtk_1style_1context_1get_1border", 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 5f3e9a6965..ad883f06bc 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 @@ -1076,6 +1076,7 @@ typedef enum { _1gtk_1status_1icon_1set_1tooltip_FUNC, _1gtk_1status_1icon_1set_1visible_FUNC, _1gtk_1style_1context_1add_1class_FUNC, + _1gtk_1style_1context_1add_1provider_FUNC, _1gtk_1style_1context_1add_1provider_1for_1screen_FUNC, _1gtk_1style_1context_1get_1background_1color_FUNC, _1gtk_1style_1context_1get_1border_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 8b72f41415..4f1688d00a 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 @@ -8498,6 +8498,22 @@ public static final void gtk_style_context_add_provider_for_screen(long /*int*/ lock.unlock(); } } + + +/** +* @method flags=dynamic +* @param priority cast=(guint) +*/ +public static final native void _gtk_style_context_add_provider (long /*int*/ context, long /*int*/ provider, int priority); +public static final void gtk_style_context_add_provider( + long /* int */context, long /* int */provider, int priority) { + lock.lock(); + try { + _gtk_style_context_add_provider(context, provider, priority); + } finally { + lock.unlock(); + } +} /** * @param list_store cast=(GtkListStore *) * @param iter cast=(GtkTreeIter *) 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 c929cf0efd..b09533d78d 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 @@ -3909,24 +3909,23 @@ public void setBackground (Color color) { void setBackgroundColor (long /*int*/ handle, GdkColor color) { if (OS.GTK3) { - GdkRGBA rgba = null; - double alpha = 1; + if (color == null) { if ((state & PARENT_BACKGROUND) != 0) { - alpha = 0; Control control = findBackgroundControl(); if (control == null) control = this; color = control.getBackgroundColor(); } } - if (color != null) { - rgba = new GdkRGBA (); - rgba.alpha = alpha; - rgba.red = (color.red & 0xFFFF) / (float)0xFFFF; - rgba.green = (color.green & 0xFFFF) / (float)0xFFFF; - rgba.blue = (color.blue & 0xFFFF) / (float)0xFFFF; - } - OS.gtk_widget_override_background_color (handle, OS.GTK_STATE_FLAG_NORMAL, rgba); + String css ="GtkWidget {\n" + + " background-color: rgb("+((color.red >> 8) & 0xFF)+","+((color.green >> 8) & 0xFF)+","+((color.blue >> 8) & 0xFF)+");\n" + + "}\n"; + byte[] css_data = Converter.wcsToMbcs (null, css, true); + long /*int*/ context = OS.gtk_widget_get_style_context(handle); + long /*int*/ provider = OS.gtk_css_provider_new (); + OS.gtk_css_provider_load_from_data (provider, css_data, -1, null); + OS.gtk_style_context_add_provider (context, provider, OS.GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + OS.g_object_unref (provider); return; } int index = OS.GTK_STATE_NORMAL; |