< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.m

Print this page


   1 /*
   2  * Copyright (c) 2011, 2014, 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


 353         
 354         // Signal so that JNI_OnLoad can proceed.
 355         if (!wasOnMainThread) [AWTStarter appKitIsRunning:nil];
 356         
 357         // Proceed to exit this call as there is no reason to run the NSApplication event loop.
 358     }
 359     
 360     [pool drain];
 361 }
 362 
 363 @end
 364 
 365 /*
 366  * Class:     sun_lwawt_macosx_LWCToolkit
 367  * Method:    nativeSyncQueue
 368  * Signature: (J)Z
 369  */
 370 JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_nativeSyncQueue
 371 (JNIEnv *env, jobject self, jlong timeout)
 372 {
 373     int currentEventNum = [AWTToolkit getEventCount];
 374 
 375     NSApplication* sharedApp = [NSApplication sharedApplication];
 376     if ([sharedApp isKindOfClass:[NSApplicationAWT class]]) {
 377         NSApplicationAWT* theApp = (NSApplicationAWT*)sharedApp;
 378         [theApp postDummyEvent];
 379         [theApp waitForDummyEvent:timeout];










 380     } else {
 381         // could happen if we are embedded inside SWT application,
 382         // in this case just spin a single empty block through 
 383         // the event loop to give it a chance to process pending events
 384         [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){}];
 385     }
 386     
 387     if (([AWTToolkit getEventCount] - currentEventNum) != 0) {
 388         return JNI_TRUE;
 389     }
 390         
 391     return JNI_FALSE;
 392 }
 393 
 394 /*
 395  * Class:     sun_lwawt_macosx_LWCToolkit
 396  * Method:    flushNativeSelectors
 397  * Signature: ()J
 398  */
 399 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_flushNativeSelectors


   1 /*
   2  * Copyright (c) 2011, 2015, 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


 353 
 354         // Signal so that JNI_OnLoad can proceed.
 355         if (!wasOnMainThread) [AWTStarter appKitIsRunning:nil];
 356 
 357         // Proceed to exit this call as there is no reason to run the NSApplication event loop.
 358     }
 359 
 360     [pool drain];
 361 }
 362 
 363 @end
 364 
 365 /*
 366  * Class:     sun_lwawt_macosx_LWCToolkit
 367  * Method:    nativeSyncQueue
 368  * Signature: (J)Z
 369  */
 370 JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_nativeSyncQueue
 371 (JNIEnv *env, jobject self, jlong timeout)
 372 {
 373     long currentEventNum = [AWTToolkit getEventCount];
 374 
 375     NSApplication* sharedApp = [NSApplication sharedApplication];
 376     if ([sharedApp isKindOfClass:[NSApplicationAWT class]]) {
 377         NSApplicationAWT* theApp = (NSApplicationAWT*)sharedApp;
 378         // We use two different API to post events to the application,
 379         //  - [NSApplication postEvent]
 380         //  - CGEventPost(), see CRobot.m
 381         // It was found that if we post an event via CGEventPost in robot and
 382         // immediately after this we will post the second event via
 383         // [NSApp postEvent] then sometimes the second event will be handled
 384         // first. The opposite isn't proved, but we use both here to be safer.
 385         [theApp postDummyEvent:false];
 386         [theApp waitForDummyEvent:timeout / 2.0];
 387         [theApp postDummyEvent:true];
 388         [theApp waitForDummyEvent:timeout / 2.0];
 389 
 390     } else {
 391         // could happen if we are embedded inside SWT application,
 392         // in this case just spin a single empty block through
 393         // the event loop to give it a chance to process pending events
 394         [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){}];
 395     }
 396 
 397     if (([AWTToolkit getEventCount] - currentEventNum) != 0) {
 398         return JNI_TRUE;
 399     }
 400 
 401     return JNI_FALSE;
 402 }
 403 
 404 /*
 405  * Class:     sun_lwawt_macosx_LWCToolkit
 406  * Method:    flushNativeSelectors
 407  * Signature: ()J
 408  */
 409 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_flushNativeSelectors


< prev index next >