Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Williams2016-07-05 20:57:38 +0000
committerEric Williams2016-07-11 20:18:26 +0000
commit7b2bf7652c8c744510eba4e87f9cd6926e02f2cd (patch)
treeb08e26f682bd8bcb6feda0be5835fcc0ff14106a
parent7ffde511cb3edaee8bda414c32aca9610ae6e58b (diff)
downloadeclipse.platform.swt-7b2bf7652c8c744510eba4e87f9cd6926e02f2cd.tar.gz
eclipse.platform.swt-7b2bf7652c8c744510eba4e87f9cd6926e02f2cd.tar.xz
eclipse.platform.swt-7b2bf7652c8c744510eba4e87f9cd6926e02f2cd.zip
Bug 497707: [GTK3] Replace deprecated gtk_window_get/set_opacity()
Replace the deprecated function gtk_window_set_opacity() with gtk_widget_set_opacity(). Tested on all versions of GTK3 and GTK2.24. No additional AllNonBrowser JUnit test cases fail on GTK3 or GTK2. Change-Id: I82de5596ab7e956339d104efd367cdaac927229a Signed-off-by: Eric Williams <ericwill@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c38
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java26
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java18
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Shell.java33
8 files changed, 108 insertions, 15 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 fbf6860c3d..c894731cfe 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
@@ -18731,6 +18731,26 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1widget_1get_1name)
}
#endif
+#ifndef NO__1gtk_1widget_1get_1opacity
+JNIEXPORT jdouble JNICALL OS_NATIVE(_1gtk_1widget_1get_1opacity)
+ (JNIEnv *env, jclass that, jintLong arg0)
+{
+ jdouble rc = 0;
+ OS_NATIVE_ENTER(env, that, _1gtk_1widget_1get_1opacity_FUNC);
+/*
+ rc = (jdouble)gtk_widget_get_opacity((GtkWidget *)arg0);
+*/
+ {
+ OS_LOAD_FUNCTION(fp, gtk_widget_get_opacity)
+ if (fp) {
+ rc = (jdouble)((jdouble (CALLING_CONVENTION*)(GtkWidget *))fp)((GtkWidget *)arg0);
+ }
+ }
+ OS_NATIVE_EXIT(env, that, _1gtk_1widget_1get_1opacity_FUNC);
+ return rc;
+}
+#endif
+
#ifndef NO__1gtk_1widget_1get_1pango_1context
JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1widget_1get_1pango_1context)
(JNIEnv *env, jclass that, jintLong arg0)
@@ -19558,6 +19578,24 @@ fail:
}
#endif
+#ifndef NO__1gtk_1widget_1set_1opacity
+JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1widget_1set_1opacity)
+ (JNIEnv *env, jclass that, jintLong arg0, jdouble arg1)
+{
+ OS_NATIVE_ENTER(env, that, _1gtk_1widget_1set_1opacity_FUNC);
+/*
+ gtk_widget_set_opacity((GtkWidget *)arg0, arg1);
+*/
+ {
+ OS_LOAD_FUNCTION(fp, gtk_widget_set_opacity)
+ if (fp) {
+ ((void (CALLING_CONVENTION*)(GtkWidget *, jdouble))fp)((GtkWidget *)arg0, arg1);
+ }
+ }
+ OS_NATIVE_EXIT(env, that, _1gtk_1widget_1set_1opacity_FUNC);
+}
+#endif
+
#ifndef NO__1gtk_1widget_1set_1parent_1window
JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1widget_1set_1parent_1window)
(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h
index a4f40497f5..23fd7e824b 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h
@@ -190,6 +190,8 @@
#define NO__1gdk_1rgba_1to_1string
#define NO__1gdk_1rgba_1parse
#define NO__1gtk_1scrollable_1get_1vadjustment
+#define NO__1gtk_1widget_1set_1opacity
+#define NO__1gtk_1widget_1get_1opacity
#define NO__1g_1object_1set__I_3BLorg_eclipse_swt_internal_gtk_GdkRGBA_2I
#define NO__1g_1object_1set__J_3BLorg_eclipse_swt_internal_gtk_GdkRGBA_2J
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 8bbc233da8..f590863e3a 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
@@ -117,6 +117,8 @@
#define g_variant_new_uint64_LIB LIB_GIO
#define g_variant_n_children_LIB LIB_GIO
#define gtk_widget_set_allocation_LIB LIB_GTK
+#define gtk_widget_set_opacity_LIB LIB_GTK
+#define gtk_widget_get_opacity_LIB LIB_GTK
#define gtk_adjustment_configure_LIB LIB_GTK
#define gtk_adjustment_get_lower_LIB LIB_GTK
#define gtk_adjustment_get_page_increment_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 27d4353863..b686351946 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
@@ -1395,6 +1395,7 @@ char * OS_nativeFunctionNames[] = {
"_1gtk_1widget_1get_1mapped",
"_1gtk_1widget_1get_1modifier_1style",
"_1gtk_1widget_1get_1name",
+ "_1gtk_1widget_1get_1opacity",
"_1gtk_1widget_1get_1pango_1context",
"_1gtk_1widget_1get_1parent",
"_1gtk_1widget_1get_1parent_1window",
@@ -1445,6 +1446,7 @@ char * OS_nativeFunctionNames[] = {
"_1gtk_1widget_1set_1has_1window",
"_1gtk_1widget_1set_1mapped",
"_1gtk_1widget_1set_1name",
+ "_1gtk_1widget_1set_1opacity",
"_1gtk_1widget_1set_1parent_1window",
"_1gtk_1widget_1set_1receives_1default",
"_1gtk_1widget_1set_1redraw_1on_1allocate",
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 47ec1d6f8a..bbe3647672 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
@@ -1405,6 +1405,7 @@ typedef enum {
_1gtk_1widget_1get_1mapped_FUNC,
_1gtk_1widget_1get_1modifier_1style_FUNC,
_1gtk_1widget_1get_1name_FUNC,
+ _1gtk_1widget_1get_1opacity_FUNC,
_1gtk_1widget_1get_1pango_1context_FUNC,
_1gtk_1widget_1get_1parent_FUNC,
_1gtk_1widget_1get_1parent_1window_FUNC,
@@ -1455,6 +1456,7 @@ typedef enum {
_1gtk_1widget_1set_1has_1window_FUNC,
_1gtk_1widget_1set_1mapped_FUNC,
_1gtk_1widget_1set_1name_FUNC,
+ _1gtk_1widget_1set_1opacity_FUNC,
_1gtk_1widget_1set_1parent_1window_FUNC,
_1gtk_1widget_1set_1receives_1default_FUNC,
_1gtk_1widget_1set_1redraw_1on_1allocate_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 9d8a8f3840..7686bedad7 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
@@ -15027,6 +15027,32 @@ public static final void gtk_widget_set_name(long /*int*/ widget, byte[] name) {
}
}
/**
+ * @method flags=dynamic
+ * @param widget cast=(GtkWidget *)
+ */
+public static final native void _gtk_widget_set_opacity(long /*int*/ widget, double opacity);
+public static final void gtk_widget_set_opacity(long /*int*/ widget, double opacity) {
+ lock.lock();
+ try {
+ _gtk_widget_set_opacity(widget, opacity);
+ } finally {
+ lock.unlock();
+ }
+}
+/**
+ * @method flags=dynamic
+ * @param widget cast=(GtkWidget *)
+ */
+public static final native double _gtk_widget_get_opacity(long /*int*/ widget);
+public static final double gtk_widget_get_opacity(long /*int*/ widget) {
+ lock.lock();
+ try {
+ return _gtk_widget_get_opacity(widget);
+ } finally {
+ lock.unlock();
+ }
+}
+/**
* @param widget cast=(GtkWidget *)
* @param redraw cast=(gboolean)
*/
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
index 823de0a1b0..6dc94bb5af 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
@@ -1011,7 +1011,11 @@ void forceResize (int width, int height) {
public int getAlpha () {
checkWidget ();
if (OS.gtk_widget_is_composited (shellHandle)) {
- return (int) (OS.gtk_window_get_opacity (shellHandle) * 255);
+ /*
+ * Feature in GTK: gtk_window_get_opacity() is deprecated on GTK3.8
+ * onward. Use gtk_widget_get_opacity() instead.
+ */
+ return (int) (OS.GTK_VERSION > OS.VERSION (3, 8, 0) ? OS.gtk_widget_get_opacity(shellHandle) * 255 : OS.gtk_window_get_opacity (shellHandle) * 255);
}
return 255;
}
@@ -1839,8 +1843,16 @@ void setActiveControl (Control control, int type) {
public void setAlpha (int alpha) {
checkWidget ();
if (OS.gtk_widget_is_composited (shellHandle)) {
- alpha &= 0xFF;
- OS.gtk_window_set_opacity (shellHandle, alpha / 255f);
+ /*
+ * Feature in GTK: gtk_window_set_opacity() is deprecated on GTK3.8
+ * onward. Use gtk_widget_set_opacity() instead.
+ */
+ if (OS.GTK_VERSION > OS.VERSION (3, 8, 0)) {
+ OS.gtk_widget_set_opacity (shellHandle, (double) alpha / 255);
+ } else {
+ alpha &= 0xFF;
+ OS.gtk_window_set_opacity (shellHandle, alpha / 255f);
+ }
}
}
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Shell.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Shell.java
index 8a61c9bafa..64d9b62067 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Shell.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Shell.java
@@ -63,7 +63,7 @@ public void test_Constructor() {
@Test
public void test_ConstructorI() {
/* this should test various combinations of STYLE bits, for now just test individual bits */
- int[] cases = {SWT.NO_TRIM, SWT.RESIZE, SWT.TITLE, SWT.CLOSE, SWT.MENU, SWT.MIN, SWT.BORDER,
+ int[] cases = {SWT.NO_TRIM, SWT.RESIZE, SWT.TITLE, SWT.CLOSE, SWT.MENU, SWT.MIN, SWT.BORDER,
SWT.CLIP_CHILDREN, SWT.CLIP_SIBLINGS, SWT.ON_TOP, SWT.FLAT, SWT.SMOOTH};
Shell newShell;
for (int i = 0; i < cases.length; i++) {
@@ -83,7 +83,7 @@ public void test_ConstructorLorg_eclipse_swt_widgets_Display() {
@Test
public void test_ConstructorLorg_eclipse_swt_widgets_DisplayI() {
- int[] cases = {SWT.NO_TRIM, SWT.RESIZE, SWT.TITLE, SWT.CLOSE, SWT.MENU, SWT.MIN, SWT.BORDER,
+ int[] cases = {SWT.NO_TRIM, SWT.RESIZE, SWT.TITLE, SWT.CLOSE, SWT.MENU, SWT.MIN, SWT.BORDER,
SWT.CLIP_CHILDREN, SWT.CLIP_SIBLINGS, SWT.ON_TOP, SWT.FLAT, SWT.SMOOTH};
Shell newShell;
Display display = shell.getDisplay();
@@ -104,7 +104,7 @@ public void test_ConstructorLorg_eclipse_swt_widgets_Shell() {
@Test
public void test_ConstructorLorg_eclipse_swt_widgets_ShellI() {
/* this should test various combinations of STYLE bits, for now just test individual bits */
- int[] cases = {SWT.NO_TRIM, SWT.RESIZE, SWT.TITLE, SWT.CLOSE, SWT.MENU, SWT.MIN, SWT.BORDER,
+ int[] cases = {SWT.NO_TRIM, SWT.RESIZE, SWT.TITLE, SWT.CLOSE, SWT.MENU, SWT.MIN, SWT.BORDER,
SWT.CLIP_CHILDREN, SWT.CLIP_SIBLINGS, SWT.ON_TOP, SWT.FLAT, SWT.SMOOTH};
Shell newShell;
for (int i = 0; i < cases.length; i++) {
@@ -148,7 +148,7 @@ public void test_addShellListenerLorg_eclipse_swt_events_ShellListener() {
shell.forceActive();
/* can't assume listener is synchronously called when forceActive returned */
/* assertTrue(":a:", listenerCalled == true); */
-
+
listenerCalled = false;
shell.removeShellListener(listener);
shell.forceActive();
@@ -264,18 +264,18 @@ public void test_setActive() {
/* Create shell2 and make it active. */
Shell shell2 = new Shell();
shell2.open();
-
+
/* Test setActive for visible shell. */
shell.setVisible(true);
shell.setActive();
assertTrue("visible shell was not made active", shell.getDisplay().getActiveShell() == shell);
-
+
/* Test setActive for visible dialog shell. */
shell2.setActive();
testShell.setVisible(true);
testShell.setActive();
assertTrue("visible dialog shell was not made active", testShell.getDisplay().getActiveShell() == testShell);
-
+
/* Test setActive for non-visible shell. */
shell2.setActive();
shell.setVisible(false);
@@ -287,7 +287,7 @@ public void test_setActive() {
testShell.setVisible(false);
testShell.setActive();
assertTrue("non-visible dialog shell was made active", testShell.getDisplay().getActiveShell() != testShell);
-
+
shell2.dispose();
}
@@ -472,7 +472,7 @@ public void test_setSizeII() {
newSize.y -= 100;
}
}
-
+
}
@Override
@@ -509,7 +509,7 @@ private void createShell() {
testShell.setText("Shell");
testShell.setLayout(new FillLayout());
setWidget(testShell);
-
+
}
@Test
@@ -533,11 +533,11 @@ public void test_consistency_Open() {
}
});
}}.start();
-
+
while(!shell.isDisposed()) {
if(!display.readAndDispatch()) display.sleep();
}
- setUp();
+ setUp();
String[] results = events.toArray(new String[events.size()]);
assertArrayEquals(getTestName() + " event ordering", temp, results);
}
@@ -576,4 +576,13 @@ public void test_consistency_Dispose() {
consistencyEvent(pt.x, pt.y, 1, 0, ConsistencyUtility.MOUSE_CLICK, events);
createShell();
}
+
+@Test
+public void test_setAlpha() {
+ createShell();
+ testShell.setAlpha(128);
+ assertEquals(128, testShell.getAlpha());
+ testShell.setAlpha(255);
+ assertEquals(255, testShell.getAlpha());
+}
}

Back to the top