Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLeo Ufimtsev2018-01-29 20:17:07 +0000
committerAlexander Kurtakov2018-02-01 08:59:15 +0000
commit99f1cc70e851d747f5b2b5de343eacb7bc4cce6a (patch)
tree20885dcf664e422feb3feae675b59c8cfa774cd4 /tests
parentceaf821b793f81ec993f2661de5a37693bc0cd05 (diff)
downloadeclipse.platform.swt-99f1cc70e851d747f5b2b5de343eacb7bc4cce6a.tar.gz
eclipse.platform.swt-99f1cc70e851d747f5b2b5de343eacb7bc4cce6a.tar.xz
eclipse.platform.swt-99f1cc70e851d747f5b2b5de343eacb7bc4cce6a.zip
Bug 529151 [Gtk] Move gtk function from OS.java to GTK.java
Benefits: - Adding dynamic functions doesn't require one to manually link the function in os_custom.h anymore. This makes prototyping much faster and SWT development more user friendly. - NativeStats tool generates a separate category for gtk functions (from OS.java once). Technical details: - SWT Tools generates <CLASS_NAME>_LOAD_FUNCTION with GTK.java, we get GTK_LOAD_FUNCTION - we hard-code GTK_LOAD_FUNCTION to link to gtk lib (see os.h). - All native code is still put into os.(c|h) - I manually Updated a few special OS_LOAD_FUNCTION calls and removed old bindings in os_custom.h Verified with child eclipse. Fedora 27, Gtk3.22. Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=529151 Change-Id: I6446ee5cca090022a8d984a1f92969c26e5e2f24 Signed-off-by: Leo Ufimtsev <lufimtse@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug526083_MenuGetBounds.java263
1 files changed, 132 insertions, 131 deletions
diff --git a/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug526083_MenuGetBounds.java b/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug526083_MenuGetBounds.java
index 4dff95e40d..034f03f86b 100644
--- a/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug526083_MenuGetBounds.java
+++ b/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug526083_MenuGetBounds.java
@@ -1,131 +1,132 @@
-package org.eclipse.swt.tests.gtk.snippets;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.internal.gtk.GtkAllocation;
-import org.eclipse.swt.internal.gtk.OS;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.MenuItem;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Widget;
-
-
-/*
- * Title: Bug 526083 - [GTK3] Menu.getBounds() returns wrong x & y coordinate
- * How to run: launch snippet, right click in the boxes, observe messages printed in the console
- * Bug description: The "getBounds" line has incorrect values
- * Expected results: The "getBounds" line should have the same values as the "correct bounds" line
- * GTK Version(s): GTK3
- */
-public class Bug526083_MenuGetBounds {
-
- public static void main(String[] args) {
- final Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new GridLayout(2, false));
- Composite c1 = new Composite(shell, SWT.BORDER);
- c1.setLayoutData(new GridData(100, 100));
- Composite c2 = new Composite(shell, SWT.BORDER);
- c2.setLayoutData(new GridData(100, 100));
- final Menu menu = new Menu(shell, SWT.POP_UP);
- MenuItem item = new MenuItem(menu, SWT.PUSH);
- item.setText("Popup");
- menu.addListener(SWT.Show, event -> display.asyncExec(() -> {
- try {
- // menu.getBounds call
- System.err.println("getBounds: " + invoke(menu, "getBounds"));
- System.err.println("-----------------------------------------");
- // menu.getBounds implementation
-// long /*int*/ window = gtk_widget_get_window (menu.handle);
- long /*int*/ window = ((Long)invoke(Widget.class, "gtk_widget_get_window", true, menu, new Object[] { Long.valueOf(menu.handle) })).longValue();
- int [] origin_x = new int [1], origin_y = new int [1];
- OS.gdk_window_get_origin (window, origin_x, origin_y);
- GtkAllocation allocation = new GtkAllocation ();
- OS.gtk_widget_get_allocation (menu.handle, allocation);
- System.err.println(origin_x[0] + " " + origin_y[0] + " " + allocation.x + " " + allocation.y + " " + allocation.width + " " + allocation.height);
- int x = origin_x [0] + allocation.x;
- int y = origin_y [0] + allocation.y;
- int width = allocation.width;
- int height = allocation.height;
- Rectangle bounds = new Rectangle (x, y, width, height);
- System.err.println("allocation: " + allocation.x + " " + allocation.y + " " + allocation.width + " " + allocation.height);
- System.err.println("bounds: " + bounds);
- System.err.println("-----------------------------------------");
- // correct bounds (without allocation)
- x = origin_x [0];
- y = origin_y [0];
- bounds = new Rectangle (x, y, width, height);
- System.err.println("correct bounds: " + bounds);
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }));
- c1.setMenu(menu);
- c2.setMenu(menu);
- shell.setMenu(menu);
- shell.setSize(300, 300);
- shell.setLocation(100, 100);
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
- display.dispose();
- }
-
- public final static Object invoke(final String clazzName, final String methodName, final Object... args)
- throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
- return invoke(clazzName, methodName, false, args);
- }
-
- public final static Object invoke(final String clazzName, final String methodName, final Class<?>[] params, final Object... args)
- throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
- return invoke(Class.forName(clazzName), methodName, false, null, params, args);
- }
-
- public final static Object invoke(final String clazzName, final String methodName, final boolean declaredMethod, final Object... args)
- throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
- return invoke(Class.forName(clazzName), methodName, declaredMethod, null, args);
- }
-
- public final static Object invoke(final Object obj, final String methodName, final Object... args)
- throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
- return invoke(obj.getClass(), methodName, true, obj, args);
- }
-
- public final static Object invoke(final Class<?> clazz, final String methodName, final boolean declaredMethod, final Object obj, final Object... args)
- throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
- Class<?>[] params = new Class[args.length];
- for (int i = 0; i < args.length; i++) {
- Class<?> argClazz = args[i].getClass();
- try {
- Field typeField = argClazz.getField("TYPE"); //$NON-NLS-1$
- params[i] = (Class<?>) typeField.get(null);
- } catch (NoSuchFieldException e) {
- params[i] = argClazz;
- }
- }
- return invoke(clazz, methodName, declaredMethod, obj, params, args);
- }
-
- public final static Object invoke(final Class<?> clazz, final String methodName, final boolean declaredMethod, final Object obj, final Class<?>[] params, final Object... args)
- throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
- Method method;
- if (declaredMethod) {
- method = clazz.getDeclaredMethod(methodName, params);
- method.setAccessible(true);
- } else {
- method = clazz.getMethod(methodName, params);
- }
- return method.invoke(obj, args);
- }
-
-} \ No newline at end of file
+//package org.eclipse.swt.tests.gtk.snippets;
+//
+//import java.lang.reflect.Field;
+//import java.lang.reflect.InvocationTargetException;
+//import java.lang.reflect.Method;
+//
+//import org.eclipse.swt.SWT;
+//import org.eclipse.swt.graphics.Rectangle;
+//import org.eclipse.swt.internal.gtk.GTK;
+//import org.eclipse.swt.internal.gtk.GtkAllocation;
+//import org.eclipse.swt.internal.gtk.OS;
+//import org.eclipse.swt.layout.GridData;
+//import org.eclipse.swt.layout.GridLayout;
+//import org.eclipse.swt.widgets.Composite;
+//import org.eclipse.swt.widgets.Display;
+//import org.eclipse.swt.widgets.Menu;
+//import org.eclipse.swt.widgets.MenuItem;
+//import org.eclipse.swt.widgets.Shell;
+//import org.eclipse.swt.widgets.Widget;
+//
+//
+///*
+// * Title: Bug 526083 - [GTK3] Menu.getBounds() returns wrong x & y coordinate
+// * How to run: launch snippet, right click in the boxes, observe messages printed in the console
+// * Bug description: The "getBounds" line has incorrect values
+// * Expected results: The "getBounds" line should have the same values as the "correct bounds" line
+// * GTK Version(s): GTK3
+// */
+//public class Bug526083_MenuGetBounds {
+//
+// public static void main(String[] args) {
+// final Display display = new Display();
+// Shell shell = new Shell(display);
+// shell.setLayout(new GridLayout(2, false));
+// Composite c1 = new Composite(shell, SWT.BORDER);
+// c1.setLayoutData(new GridData(100, 100));
+// Composite c2 = new Composite(shell, SWT.BORDER);
+// c2.setLayoutData(new GridData(100, 100));
+// final Menu menu = new Menu(shell, SWT.POP_UP);
+// MenuItem item = new MenuItem(menu, SWT.PUSH);
+// item.setText("Popup");
+// menu.addListener(SWT.Show, event -> display.asyncExec(() -> {
+// try {
+// // menu.getBounds call
+// System.err.println("getBounds: " + invoke(menu, "getBounds"));
+// System.err.println("-----------------------------------------");
+// // menu.getBounds implementation
+//// long /*int*/ window = gtk_widget_get_window (menu.handle);
+// long /*int*/ window = ((Long)invoke(Widget.class, "gtk_widget_get_window", true, menu, new Object[] { Long.valueOf(menu.handle) })).longValue();
+// int [] origin_x = new int [1], origin_y = new int [1];
+// OS.gdk_window_get_origin (window, origin_x, origin_y);
+// GtkAllocation allocation = new GtkAllocation ();
+// GTK.gtk_widget_get_allocation (menu.handle, allocation);
+// System.err.println(origin_x[0] + " " + origin_y[0] + " " + allocation.x + " " + allocation.y + " " + allocation.width + " " + allocation.height);
+// int x = origin_x [0] + allocation.x;
+// int y = origin_y [0] + allocation.y;
+// int width = allocation.width;
+// int height = allocation.height;
+// Rectangle bounds = new Rectangle (x, y, width, height);
+// System.err.println("allocation: " + allocation.x + " " + allocation.y + " " + allocation.width + " " + allocation.height);
+// System.err.println("bounds: " + bounds);
+// System.err.println("-----------------------------------------");
+// // correct bounds (without allocation)
+// x = origin_x [0];
+// y = origin_y [0];
+// bounds = new Rectangle (x, y, width, height);
+// System.err.println("correct bounds: " + bounds);
+// } catch (Throwable t) {
+// t.printStackTrace();
+// }
+// }));
+// c1.setMenu(menu);
+// c2.setMenu(menu);
+// shell.setMenu(menu);
+// shell.setSize(300, 300);
+// shell.setLocation(100, 100);
+// shell.open();
+// while (!shell.isDisposed()) {
+// if (!display.readAndDispatch())
+// display.sleep();
+// }
+// display.dispose();
+// }
+//
+// public final static Object invoke(final String clazzName, final String methodName, final Object... args)
+// throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
+// return invoke(clazzName, methodName, false, args);
+// }
+//
+// public final static Object invoke(final String clazzName, final String methodName, final Class<?>[] params, final Object... args)
+// throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
+// return invoke(Class.forName(clazzName), methodName, false, null, params, args);
+// }
+//
+// public final static Object invoke(final String clazzName, final String methodName, final boolean declaredMethod, final Object... args)
+// throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
+// return invoke(Class.forName(clazzName), methodName, declaredMethod, null, args);
+// }
+//
+// public final static Object invoke(final Object obj, final String methodName, final Object... args)
+// throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
+// return invoke(obj.getClass(), methodName, true, obj, args);
+// }
+//
+// public final static Object invoke(final Class<?> clazz, final String methodName, final boolean declaredMethod, final Object obj, final Object... args)
+// throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
+// Class<?>[] params = new Class[args.length];
+// for (int i = 0; i < args.length; i++) {
+// Class<?> argClazz = args[i].getClass();
+// try {
+// Field typeField = argClazz.getField("TYPE"); //$NON-NLS-1$
+// params[i] = (Class<?>) typeField.get(null);
+// } catch (NoSuchFieldException e) {
+// params[i] = argClazz;
+// }
+// }
+// return invoke(clazz, methodName, declaredMethod, obj, params, args);
+// }
+//
+// public final static Object invoke(final Class<?> clazz, final String methodName, final boolean declaredMethod, final Object obj, final Class<?>[] params, final Object... args)
+// throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
+// Method method;
+// if (declaredMethod) {
+// method = clazz.getDeclaredMethod(methodName, params);
+// method.setAccessible(true);
+// } else {
+// method = clazz.getMethod(methodName, params);
+// }
+// return method.invoke(obj, args);
+// }
+//
+//} \ No newline at end of file

Back to the top