9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.embed.swt;
27
28 import org.eclipse.swt.SWT;
29 //import org.eclipse.swt.events.MouseEvent;
30
31 import java.lang.reflect.Method;
32
33 //import com.sun.glass.events.KeyEvent;
34 import com.sun.javafx.embed.AbstractEvents;
35 import org.eclipse.swt.widgets.Event;
36
37 import java.lang.reflect.InvocationTargetException;
38
39 /**
40 * An utility class to translate event types between embedded
41 * application and SWT.
42 *
43 */
44 class SWTEvents {
45
46 /*
47 static int mouseIDToEmbedMouseType(int id) {
48 switch (id) {
49 case MouseEvent.MOUSE_PRESSED:
50 return AbstractEvents.MOUSEEVENT_PRESSED;
51 case MouseEvent.MOUSE_RELEASED:
52 return AbstractEvents.MOUSEEVENT_RELEASED;
53 case MouseEvent.MOUSE_CLICKED:
54 return AbstractEvents.MOUSEEVENT_CLICKED;
55 case MouseEvent.MOUSE_MOVED:
56 return AbstractEvents.MOUSEEVENT_MOVED;
57 case MouseEvent.MOUSE_DRAGGED:
58 return AbstractEvents.MOUSEEVENT_DRAGGED;
59 case MouseEvent.MOUSE_ENTERED:
60 return AbstractEvents.MOUSEEVENT_ENTERED;
61 case MouseEvent.MOUSE_EXITED:
62 return AbstractEvents.MOUSEEVENT_EXITED;
63 }
64 return 0;
65 }
66 */
67 static int mouseButtonToEmbedMouseButton(int button, int extModifiers) {
68 switch (button) {
69 case 1: return AbstractEvents.MOUSEEVENT_PRIMARY_BUTTON;
70 case 2: return AbstractEvents.MOUSEEVENT_MIDDLE_BUTTON;
71 case 3: return AbstractEvents.MOUSEEVENT_SECONDARY_BUTTON;
72 }
73 return AbstractEvents.MOUSEEVENT_NONE_BUTTON;
74 }
75
76 static double getWheelRotation(Event e) {
77 int divisor = 1;
78 if ("win32".equals(SWT.getPlatform()) && e.type == SWT.MouseVerticalWheel) {
79 int [] linesToScroll = new int [1];
80 //OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, linesToScroll, 0);
81 try {
82 Class clazz = Class.forName("org.eclipse.swt.internal.win32.OS");
83 Method method = clazz.getDeclaredMethod("SystemParametersInfo", new Class []{int.class, int.class, int [].class, int.class});
84 method.invoke(clazz, 104 /*SPI_GETWHEELSCROLLLINES*/, 0, linesToScroll, 0);
85 } catch (IllegalAccessException iae) {
86 } catch (InvocationTargetException ite) {
87 } catch (NoSuchMethodException nme) {
88 } catch (ClassNotFoundException cfe) {
89 //Fail silently
90 }
91 if (linesToScroll [0] != -1 /*OS.WHEEL_PAGESCROLL*/) {
92 divisor = linesToScroll [0];
93 }
94 } else if ("gtk".equals(SWT.getPlatform())) {
95 divisor = 3;
96 }
97 else if ("cocoa".equals(SWT.getPlatform())) {
98 divisor = Math.abs(e.count);
99 }
100 return e.count / (double) Math.max(1, divisor);
101 }
102
103 static int keyIDToEmbedKeyType(int id) {
104 switch (id) {
105 case SWT.KeyDown:
106 return AbstractEvents.KEYEVENT_PRESSED;
107 case SWT.KeyUp:
108 return AbstractEvents.KEYEVENT_RELEASED;
109 // case KeyEvent.KEY_TYPED:
110 // return AbstractEvents.KEYEVENT_TYPED;
111 }
112 return 0;
113 }
114
115 static final int [] [] KeyTable = {
116
117 {0x0 /*KeyEvent.VK_UNDEFINED*/, SWT.NULL},
118
119 // SWT only
120 {'\n' /*KeyEvent.VK_?????*/, SWT.CR},
121
122 // Misc
123 {'\n' /*KeyEvent.VK_ENTER*/, SWT.LF},
124 {'\b' /*KeyEvent.VK_BACKSPACE*/, SWT.BS},
125 {'\t' /*KeyEvent.VK_TAB*/, SWT.TAB},
126 // {KeyEvent.VK_CANCEL SWT.???},
127 // {KeyEvent.VK_CLEAR SWT.???},
128 // {KeyEvent.VK_PAUSE SWT.???},
129 {0x1B /*KeyEvent.VK_ESCAPE*/, SWT.ESC},
130 {0x20 /*KeyEvent.VK_SPACE*/, 0x20},
131 {0x7F /*KeyEvent.VK_DELETE*/, SWT.DEL},
132 // {KeyEvent.VK_PRINTSCREEN SWT.???;
133 {0x9B /*KeyEvent.VK_INSERT*/, SWT.INSERT},
134 {0x9C /*KeyEvent.VK_HELP*/, SWT.HELP},
266 {0x7A /*KeyEvent.VK_F11*/, SWT.F11},
267 {0x7B /*KeyEvent.VK_F12*/, SWT.F12},
268 };
269
270 // RT-27940: map these to Fx keys
271 // /* Numeric Keypad Keys */
272 // {KeyEvent.VK_MULTIPLY, SWT.KEYPAD_MULTIPLY},
273 // {KeyEvent.VK_ADD, SWT.KEYPAD_ADD},
274 // {KeyEvent.VK_RETURN, SWT.KEYPAD_CR},
275 // {KeyEvent.VK_SUBTRACT, SWT.KEYPAD_SUBTRACT},
276 // {KeyEvent.VK_DECIMAL, SWT.KEYPAD_DECIMAL},
277 // {KeyEvent.VK_DIVIDE, SWT.KEYPAD_DIVIDE},
278 //// {KeyEvent.VK_????, SWT.KEYPAD_EQUAL},
279
280 static int keyCodeToEmbedKeyCode(int keyCode) {
281 for (int i=0; i<KeyTable.length; i++) {
282 if (KeyTable [i] [1] == keyCode) return KeyTable [i] [0];
283 }
284 return 0;
285 }
286
287 static int keyModifiersToEmbedKeyModifiers(int extModifiers) {
288 int embedModifiers = 0;
289 if ((extModifiers & SWT.SHIFT) != 0) {
290 embedModifiers |= AbstractEvents.MODIFIER_SHIFT;
291 }
292 if ((extModifiers & SWT.CTRL) != 0) {
293 embedModifiers |= AbstractEvents.MODIFIER_CONTROL;
294 }
295 if ((extModifiers & SWT.ALT) != 0) {
296 embedModifiers |= AbstractEvents.MODIFIER_ALT;
297 }
298 // NOTE: can't get Windows key from SWT
299 if ((extModifiers & SWT.COMMAND) != 0) {
300 embedModifiers |= AbstractEvents.MODIFIER_META;
301 }
302 return embedModifiers;
303 }
304 }
|
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.embed.swt;
27
28 import org.eclipse.swt.SWT;
29
30 import java.lang.reflect.Method;
31
32 import org.eclipse.swt.widgets.Event;
33
34 import java.lang.reflect.InvocationTargetException;
35
36 /**
37 * An utility class to translate event types between embedded
38 * application and SWT.
39 *
40 */
41 class SWTEvents {
42
43 static double getWheelRotation(Event e) {
44 int divisor = 1;
45 if ("win32".equals(SWT.getPlatform()) && e.type == SWT.MouseVerticalWheel) {
46 int [] linesToScroll = new int [1];
47 //OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, linesToScroll, 0);
48 try {
49 Class clazz = Class.forName("org.eclipse.swt.internal.win32.OS");
50 Method method = clazz.getDeclaredMethod("SystemParametersInfo", new Class []{int.class, int.class, int [].class, int.class});
51 method.invoke(clazz, 104 /*SPI_GETWHEELSCROLLLINES*/, 0, linesToScroll, 0);
52 } catch (IllegalAccessException iae) {
53 } catch (InvocationTargetException ite) {
54 } catch (NoSuchMethodException nme) {
55 } catch (ClassNotFoundException cfe) {
56 //Fail silently
57 }
58 if (linesToScroll [0] != -1 /*OS.WHEEL_PAGESCROLL*/) {
59 divisor = linesToScroll [0];
60 }
61 } else if ("gtk".equals(SWT.getPlatform())) {
62 divisor = 3;
63 }
64 else if ("cocoa".equals(SWT.getPlatform())) {
65 divisor = Math.abs(e.count);
66 }
67 return e.count / (double) Math.max(1, divisor);
68 }
69
70 static final int [] [] KeyTable = {
71
72 {0x0 /*KeyEvent.VK_UNDEFINED*/, SWT.NULL},
73
74 // SWT only
75 {'\n' /*KeyEvent.VK_?????*/, SWT.CR},
76
77 // Misc
78 {'\n' /*KeyEvent.VK_ENTER*/, SWT.LF},
79 {'\b' /*KeyEvent.VK_BACKSPACE*/, SWT.BS},
80 {'\t' /*KeyEvent.VK_TAB*/, SWT.TAB},
81 // {KeyEvent.VK_CANCEL SWT.???},
82 // {KeyEvent.VK_CLEAR SWT.???},
83 // {KeyEvent.VK_PAUSE SWT.???},
84 {0x1B /*KeyEvent.VK_ESCAPE*/, SWT.ESC},
85 {0x20 /*KeyEvent.VK_SPACE*/, 0x20},
86 {0x7F /*KeyEvent.VK_DELETE*/, SWT.DEL},
87 // {KeyEvent.VK_PRINTSCREEN SWT.???;
88 {0x9B /*KeyEvent.VK_INSERT*/, SWT.INSERT},
89 {0x9C /*KeyEvent.VK_HELP*/, SWT.HELP},
221 {0x7A /*KeyEvent.VK_F11*/, SWT.F11},
222 {0x7B /*KeyEvent.VK_F12*/, SWT.F12},
223 };
224
225 // RT-27940: map these to Fx keys
226 // /* Numeric Keypad Keys */
227 // {KeyEvent.VK_MULTIPLY, SWT.KEYPAD_MULTIPLY},
228 // {KeyEvent.VK_ADD, SWT.KEYPAD_ADD},
229 // {KeyEvent.VK_RETURN, SWT.KEYPAD_CR},
230 // {KeyEvent.VK_SUBTRACT, SWT.KEYPAD_SUBTRACT},
231 // {KeyEvent.VK_DECIMAL, SWT.KEYPAD_DECIMAL},
232 // {KeyEvent.VK_DIVIDE, SWT.KEYPAD_DIVIDE},
233 //// {KeyEvent.VK_????, SWT.KEYPAD_EQUAL},
234
235 static int keyCodeToEmbedKeyCode(int keyCode) {
236 for (int i=0; i<KeyTable.length; i++) {
237 if (KeyTable [i] [1] == keyCode) return KeyTable [i] [0];
238 }
239 return 0;
240 }
241 }
|