1 /* 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 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 #include "input/LensInput.h" 27 #include "wm/LensWindowManager.h" 28 #include "com_sun_glass_events_WindowEvent.h" 29 #include "com_sun_glass_events_KeyEvent.h" 30 #include "com_sun_glass_events_MouseEvent.h" 31 #include "com_sun_glass_ui_Robot.h" 32 33 jboolean glass_robot_postKeyEvent(JNIEnv *env, 34 jint keyEventType, 35 jint jfxKeyCode) { 36 37 NativeWindow window; 38 39 window = glass_window_getFocusedWindow(); 40 41 if (window == NULL) { 42 GLASS_LOG_WARNING("Can't post event (window is NULL)"); 43 return JNI_FALSE; 44 } 45 46 GLASS_LOG_FINE("Sending keyEvent %d, keyCode %d", keyEventType, jfxKeyCode); 47 glass_application_notifyKeyEvent(env, window, 48 keyEventType, 49 jfxKeyCode, 50 JNI_FALSE/*not a repeat event*/); 51 52 53 return JNI_TRUE; 54 } 55 56 57 jboolean glass_robot_postScrollEvent(JNIEnv *env, 58 jint wheelAmt ){ 59 60 jboolean result = JNI_FALSE; 61 int x, y; 62 63 lens_wm_getPointerPosition(&x, &y); 64 lens_wm_notifyScrollEvent(env, x, y, wheelAmt); 65 66 result = JNI_TRUE; 67 68 return result; 69 } 70 71 72 73 jboolean glass_robot_postMouseEvent(JNIEnv *env, 74 jint mouseEventType, jint x, jint y, 75 jint buttons) { 76 77 NativeWindow window = NULL; 78 jboolean result = JNI_FALSE; 79 jint glassMouseButton; 80 81 switch (buttons) { 82 case com_sun_glass_ui_Robot_MOUSE_LEFT_BTN : 83 glassMouseButton = com_sun_glass_events_MouseEvent_BUTTON_LEFT; 84 break; 85 case com_sun_glass_ui_Robot_MOUSE_RIGHT_BTN : 86 glassMouseButton = com_sun_glass_events_MouseEvent_BUTTON_RIGHT; 87 break; 88 case com_sun_glass_ui_Robot_MOUSE_MIDDLE_BTN : 89 glassMouseButton = com_sun_glass_events_MouseEvent_BUTTON_OTHER; 90 break; 91 default: 92 glassMouseButton = com_sun_glass_events_MouseEvent_BUTTON_NONE; 93 break; 94 } 95 96 switch (mouseEventType) { 97 case com_sun_glass_events_MouseEvent_DOWN: 98 case com_sun_glass_events_MouseEvent_UP: { 99 if (mouseEventType == com_sun_glass_events_MouseEvent_DOWN) { 100 GLASS_LOG_FINE("Posting mouse event: press"); 101 } else { 102 GLASS_LOG_FINE("Posting mouse event: release"); 103 } 104 int mousePosX, mousePosY; 105 lens_wm_getPointerPosition(&mousePosX, &mousePosY); 106 jboolean isPressed = 107 mouseEventType == com_sun_glass_events_MouseEvent_DOWN; 108 lens_wm_notifyButtonEvent(env, isPressed, glassMouseButton, 109 mousePosX, mousePosY); 110 result = JNI_TRUE; 111 } 112 break; 113 case com_sun_glass_events_MouseEvent_MOVE: 114 115 GLASS_LOG_FINER("Posting mouse event: Move"); 116 lens_wm_setPointerPosition(x, y); 117 lens_wm_notifyMotionEvent(env, x, y); 118 result = JNI_TRUE; 119 break; 120 case com_sun_glass_events_MouseEvent_DRAG: 121 case com_sun_glass_events_MouseEvent_ENTER: 122 case com_sun_glass_events_MouseEvent_EXIT: 123 case com_sun_glass_events_MouseEvent_CLICK: 124 case com_sun_glass_events_MouseEvent_WHEEL: 125 default: 126 break; 127 } 128 129 return result; 130 } 131 132 jboolean glass_robot_getMouseLocation(jint *pX, jint *pY) { 133 134 lens_wm_getPointerPosition(pX, pY); 135 return JNI_TRUE; 136 } 137