Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 034f03f86b80d31dcfab8320f864cb4068d823c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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.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);
//	}
//
//}

Back to the top