src/macosx/native/sun/awt/CRobot.m

Print this page




 118         gsButtonEventNumber = (int*)malloc(sizeof(int) * gNumberOfButtons);
 119         if (gsButtonEventNumber == NULL) {
 120             JNU_ThrowOutOfMemoryError(env, NULL);
 121             return;
 122         }
 123 
 124         for (i = 0; i < gNumberOfButtons; ++i) {
 125             gsButtonEventNumber[i] = ROBOT_EVENT_NUMBER_START;
 126         }
 127     }
 128 }
 129 
 130 /*
 131  * Class:     sun_lwawt_macosx_CRobot
 132  * Method:    mouseEvent
 133  * Signature: (IIIIZZ)V
 134  */
 135 JNIEXPORT void JNICALL
 136 Java_sun_lwawt_macosx_CRobot_mouseEvent
 137 (JNIEnv *env, jobject peer,
 138  jint screenIndex, jint mouseLastX, jint mouseLastY, jint buttonsState,
 139  jboolean isButtonsDownState, jboolean isMouseMove)
 140 {
 141     JNF_COCOA_ENTER(env);
 142 
 143     // This is the native method called when Robot mouse events occur.
 144     // The CRobot tracks the mouse position, and which button was
 145     // pressed. If the mouse position is unknown it is obtained from
 146     // CGEvents. The peer also tracks the mouse button desired state,
 147     // the appropriate key modifier state, and whether the mouse action
 148     // is simply a mouse move with no mouse button state changes.
 149 
 150     CGError err = kCGErrorSuccess;
 151 
 152     CGDirectDisplayID displayID =
 153     FindCGDirectDisplayIDForScreenIndex(screenIndex);
 154     CGRect globalDeviceBounds = CGDisplayBounds(displayID);
 155 
 156     // Set unknown mouse location, if needed.
 157     if ((mouseLastX == sun_lwawt_macosx_CRobot_MOUSE_LOCATION_UNKNOWN) ||
 158         (mouseLastY == sun_lwawt_macosx_CRobot_MOUSE_LOCATION_UNKNOWN))
 159     {
 160         CGEventRef event = CGEventCreate(NULL);
 161         if (event == NULL) {
 162             return;
 163         }
 164 
 165         CGPoint globalPos = CGEventGetLocation(event);
 166         CFRelease(event);
 167 
 168         // Normalize the coords within this display device, as
 169         // per Robot rules.
 170         if (globalPos.x < CGRectGetMinX(globalDeviceBounds)) {
 171             globalPos.x = CGRectGetMinX(globalDeviceBounds);
 172         }
 173         else if (globalPos.x > CGRectGetMaxX(globalDeviceBounds)) {




 118         gsButtonEventNumber = (int*)malloc(sizeof(int) * gNumberOfButtons);
 119         if (gsButtonEventNumber == NULL) {
 120             JNU_ThrowOutOfMemoryError(env, NULL);
 121             return;
 122         }
 123 
 124         for (i = 0; i < gNumberOfButtons; ++i) {
 125             gsButtonEventNumber[i] = ROBOT_EVENT_NUMBER_START;
 126         }
 127     }
 128 }
 129 
 130 /*
 131  * Class:     sun_lwawt_macosx_CRobot
 132  * Method:    mouseEvent
 133  * Signature: (IIIIZZ)V
 134  */
 135 JNIEXPORT void JNICALL
 136 Java_sun_lwawt_macosx_CRobot_mouseEvent
 137 (JNIEnv *env, jobject peer,
 138  jint displayID, jint mouseLastX, jint mouseLastY, jint buttonsState,
 139  jboolean isButtonsDownState, jboolean isMouseMove)
 140 {
 141     JNF_COCOA_ENTER(env);
 142 
 143     // This is the native method called when Robot mouse events occur.
 144     // The CRobot tracks the mouse position, and which button was
 145     // pressed. If the mouse position is unknown it is obtained from
 146     // CGEvents. The peer also tracks the mouse button desired state,
 147     // the appropriate key modifier state, and whether the mouse action
 148     // is simply a mouse move with no mouse button state changes.
 149 
 150     CGError err = kCGErrorSuccess;
 151 


 152     CGRect globalDeviceBounds = CGDisplayBounds(displayID);
 153 
 154     // Set unknown mouse location, if needed.
 155     if ((mouseLastX == sun_lwawt_macosx_CRobot_MOUSE_LOCATION_UNKNOWN) ||
 156         (mouseLastY == sun_lwawt_macosx_CRobot_MOUSE_LOCATION_UNKNOWN))
 157     {
 158         CGEventRef event = CGEventCreate(NULL);
 159         if (event == NULL) {
 160             return;
 161         }
 162 
 163         CGPoint globalPos = CGEventGetLocation(event);
 164         CFRelease(event);
 165 
 166         // Normalize the coords within this display device, as
 167         // per Robot rules.
 168         if (globalPos.x < CGRectGetMinX(globalDeviceBounds)) {
 169             globalPos.x = CGRectGetMinX(globalDeviceBounds);
 170         }
 171         else if (globalPos.x > CGRectGetMaxX(globalDeviceBounds)) {