Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Williams2018-01-31 15:27:10 -0500
committerEric Williams2018-02-02 13:37:30 -0500
commit2b94e7b384e944a78a368863074b86d6cfecabcd (patch)
tree81d14727e01633f392f5f44a80dfdde6561a23d1
parent91ec200f79b93eab3648ca4efd9706bd7537135e (diff)
downloadeclipse.platform.swt-2b94e7b384e944a78a368863074b86d6cfecabcd.tar.gz
eclipse.platform.swt-2b94e7b384e944a78a368863074b86d6cfecabcd.tar.xz
eclipse.platform.swt-2b94e7b384e944a78a368863074b86d6cfecabcd.zip
Bug 481485: [GTK3.10+] Paint listener for button/label does not work
On GTK3.10+, Buttons and Labels do not receive the proper draw signals. This is due to them drawing on their SwtFixed parents (fixedHandle), as GtkButton and GtkLabel do not have their own GdkWindows. This patch reverts parts of bug 483791 and fixes this bug by overriding windowProc() in Button and Label. There we check if the incoming handle is the paintHandle, and draw accordingly. Bug snippet is attached in this patch. Change-Id: I7c415985248ca5fda9e38aaf9b0c08ae834d762d Signed-off-by: Eric Williams <ericwill@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java37
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java37
-rw-r--r--tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug481485_ButtonLabelPaintListener.java45
3 files changed, 81 insertions, 38 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java
index a431f6c4c8..f7b67e4c82 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java
@@ -176,25 +176,6 @@ public void addSelectionListener (SelectionListener listener) {
}
@Override
-void connectPaint () {
- /*
- * Feature in GTK3.10+: when attaching a paint listener to a Button
- * widget, re-drawing happens on GtkButton and not the GtkBox.
- * This causes issues when setting a background color, as whatever
- * is drawn on the Button is not re-drawn. See bug 483791.
- */
- if (GTK.GTK_VERSION >= OS.VERSION (3, 9, 0) && boxHandle != 0) {
- int paintMask = GDK.GDK_EXPOSURE_MASK;
- GTK.gtk_widget_add_events (boxHandle, paintMask);
-
- OS.g_signal_connect_closure_by_id (boxHandle, display.signalIds [DRAW], 0, display.getClosure (EXPOSE_EVENT_INVERSE), false);
- OS.g_signal_connect_closure_by_id (boxHandle, display.signalIds [DRAW], 0, display.getClosure (DRAW), true);
- } else {
- super.connectPaint();
- }
-}
-
-@Override
Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
checkWidget ();
if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
@@ -1222,4 +1203,22 @@ int traversalCode (int key, GdkEventKey event) {
return code;
}
+@Override
+long /*int*/ windowProc (long /*int*/ handle, long /*int*/ arg0, long /*int*/ user_data) {
+ /*
+ * For Labels/Buttons, the first widget in the tree with a GdkWindow is SwtFixed.
+ * Unfortunately this fails the check in !GTK_IS_CONTAINER check Widget.windowProc().
+ * Instead lets override windowProc() here and check for paintHandle() compatibility.
+ * Fixes bug 481485 without re-introducing bug 483791.
+ */
+ switch ((int)/*64*/user_data) {
+ case DRAW: {
+ if (GTK.GTK_VERSION >= OS.VERSION(3, 9, 0) && paintHandle() == handle) {
+ return gtk_draw(handle, arg0);
+ }
+ }
+ }
+ return super.windowProc(handle, arg0, user_data);
+}
+
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java
index cda63c4f8d..ea08a3c726 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java
@@ -114,25 +114,6 @@ void addRelation (Control control) {
}
@Override
-void connectPaint () {
- /*
- * Feature in GTK3.10+: when attaching a paint listener to a Label
- * widget, re-drawing happens on GtkEventBox and not the GtkLabel.
- * This causes issues when setting a background color, as whatever
- * is drawn on the Label is not re-drawn. See bug 483791.
- */
- if (GTK.GTK_VERSION >= OS.VERSION (3, 9, 0) && labelHandle != 0) {
- int paintMask = GDK.GDK_EXPOSURE_MASK;
- GTK.gtk_widget_add_events (labelHandle, paintMask);
-
- OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [DRAW], 0, display.getClosure (EXPOSE_EVENT_INVERSE), false);
- OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [DRAW], 0, display.getClosure (DRAW), true);
- } else {
- super.connectPaint();
- }
-}
-
-@Override
Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
checkWidget ();
if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
@@ -736,4 +717,22 @@ long /*int*/ gtk_separator_new (int orientation) {
}
return separator;
}
+
+@Override
+long /*int*/ windowProc (long /*int*/ handle, long /*int*/ arg0, long /*int*/ user_data) {
+ /*
+ * For Labels/Buttons, the first widget in the tree with a GdkWindow is SwtFixed.
+ * Unfortunately this fails the check in !GTK_IS_CONTAINER check Widget.windowProc().
+ * Instead lets override windowProc() here and check for paintHandle() compatibility.
+ * Fixes bug 481485 without re-introducing bug 483791.
+ */
+ switch ((int)/*64*/user_data) {
+ case DRAW: {
+ if (GTK.GTK_VERSION >= OS.VERSION(3, 9, 0) && paintHandle() == handle) {
+ return gtk_draw(handle, arg0);
+ }
+ }
+ }
+ return super.windowProc(handle, arg0, user_data);
+}
}
diff --git a/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug481485_ButtonLabelPaintListener.java b/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug481485_ButtonLabelPaintListener.java
new file mode 100644
index 0000000000..a9800c9f9f
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug481485_ButtonLabelPaintListener.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+public class Bug481485_ButtonLabelPaintListener {
+
+ public static void main(String[] args) {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new GridLayout());
+
+ Button button = new Button(shell, SWT.PUSH);
+// the bug happens with Label as well
+// Label button = new Label(shell, SWT.None);
+ button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ button.addPaintListener(e -> e.gc.drawString("Button", 100, 100, true));
+
+ shell.setSize(300, 300);
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+} \ No newline at end of file

Back to the top