summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorAlexander Kurtakov2013-03-15 05:01:28 (EDT)
committer Carolyn MacLeod2013-04-09 10:56:36 (EDT)
commit8825ceaa1b095d23277370c1e050acda3f25b234 (patch)
treed07f2af9a9f8c783a3d303ed161e83eabd4fd90e
parent487f4aadb5e235a458028cadba4bc2196973e38e (diff)
downloadeclipse.platform.swt-8825ceaa1b095d23277370c1e050acda3f25b234.zip
eclipse.platform.swt-8825ceaa1b095d23277370c1e050acda3f25b234.tar.gz
eclipse.platform.swt-8825ceaa1b095d23277370c1e050acda3f25b234.tar.bz2
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.
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c18
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java16
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java21
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 cea1a16..a21ddb9 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 4c39eb1..0065a62 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 41fd5a4..0acbfdf 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 5f3e9a6..ad883f0 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 8b72f41..4f1688d 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 c929cf0..b09533d 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;