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

Print this page




 315 
 316     AWTRunLoopObject *o = nil;
 317 
 318     // We double retain because this object is owned by both main thread and "other" thread
 319     // We release in both doAWTRunLoop and stopAWTRunLoop
 320     o = [[AWTRunLoopObject alloc] init];
 321     if (o) {
 322         CFRetain(o); // GC
 323         CFRetain(o); // GC
 324         [o release];
 325     }
 326     return ptr_to_jlong(o);
 327 }
 328 
 329 /*
 330  * Class:     sun_lwawt_macosx_LWCToolkit
 331  * Method:    doAWTRunLoop
 332  * Signature: (JZZ)V
 333  */
 334 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_doAWTRunLoop
 335 (JNIEnv *env, jclass clz, jlong mediator, jboolean awtMode, jboolean detectDeadlocks)
 336 {
 337 AWT_ASSERT_APPKIT_THREAD;
 338 JNF_COCOA_ENTER(env);
 339 
 340     AWTRunLoopObject* mediatorObject = (AWTRunLoopObject*)jlong_to_ptr(mediator);
 341 
 342     if (mediatorObject == nil) return;
 343 
 344     if (!sInPerformFromJava || !detectDeadlocks) {
 345 
 346         NSRunLoop *currentRunLoop = [NSRunLoop currentRunLoop];
 347         NSDate *distantFuture = [NSDate distantFuture];
 348         NSString *mode = (awtMode) ? [JNFRunLoop javaRunLoopMode] : NSDefaultRunLoopMode;
 349 
 350         BOOL isRunning = YES;
 351         while (isRunning && ![mediatorObject shouldEndRunLoop]) {
 352             // Don't use acceptInputForMode because that doesn't setup autorelease pools properly
 353             isRunning = [currentRunLoop runMode:mode beforeDate:distantFuture];











 354         }
 355 
 356     }
 357 #ifndef PRODUCT_BUILD
 358     if (sInPerformFromJava) {
 359         NSLog(@"Apple AWT: Short-circuiting CToolkit.invokeAndWait trampoline deadlock!!!!!");
 360         NSLog(@"\tPlease file a bug report with this message and a reproducible test case.");
 361     }
 362 #endif
 363 
 364     CFRelease(mediatorObject);
 365 
 366 JNF_COCOA_EXIT(env);
 367 }
 368 
 369 /*
 370  * Class:     sun_lwawt_macosx_LWCToolkit
 371  * Method:    stopAWTRunLoop
 372  * Signature: (J)V
 373  */
 374 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_stopAWTRunLoop
 375 (JNIEnv *env, jclass clz, jlong mediator)
 376 {
 377 AWT_ASSERT_NOT_APPKIT_THREAD;
 378 JNF_COCOA_ENTER(env);
 379 
 380     AWTRunLoopObject* mediatorObject = (AWTRunLoopObject*)jlong_to_ptr(mediator);
 381 
 382     [ThreadUtilities performOnMainThread:@selector(endRunLoop) onObject:mediatorObject withObject:nil waitUntilDone:NO awtMode:YES];
 383 
 384     CFRelease(mediatorObject);
 385 
 386 JNF_COCOA_EXIT(env);
 387 }
 388 
 389 /*
 390  * Class:     sun_lwawt_macosx_LWCToolkit
 391  * Method:    isCapsLockOn
 392  * Signature: ()Z
 393  */
 394 JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_isCapsLockOn
 395 (JNIEnv *env, jobject self)
 396 {
 397     __block jboolean isOn = JNI_FALSE;
 398     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 399         NSUInteger modifiers = [NSEvent modifierFlags];
 400         isOn = (modifiers & NSAlphaShiftKeyMask) != 0;
 401     }];
 402 


 446 
 447 // TODO: definitely doesn't belong here (copied from fontpath.c in the
 448 // solaris tree)...
 449 
 450 JNIEXPORT jstring JNICALL
 451 Java_sun_font_FontManager_getFontPath
 452 (JNIEnv *env, jclass obj, jboolean noType1)
 453 {
 454     return JNFNSToJavaString(env, @"/Library/Fonts");
 455 }
 456 
 457 // This isn't yet used on unix, the implementation is added since shared
 458 // code calls this method in preparation for future use.
 459 JNIEXPORT void JNICALL
 460 Java_sun_font_FontManager_populateFontFileNameMap
 461 (JNIEnv *env, jclass obj, jobject fontToFileMap, jobject fontToFamilyMap, jobject familyToFontListMap, jobject locale)
 462 {
 463 
 464 }
 465 
 466 /*
 467  * Class:     sun_lwawt_macosx_LWCToolkit
 468  * Method:    startNativeNestedEventLoop
 469  * Signature: ()V
 470  */
 471 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_startNativeNestedEventLoop
 472 (JNIEnv *env, jclass cls)
 473 {
 474     // Simply get the next event in native loop and pass it to execution
 475     // We'll be called repeatedly so there's no need to block here
 476     NSRunLoop *theRL = [NSRunLoop currentRunLoop];
 477     NSApplication * app = [NSApplication sharedApplication];
 478     NSEvent * event = [app nextEventMatchingMask: 0xFFFFFFFF untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];
 479     if (event != nil) {
 480         [app sendEvent: event];
 481     }
 482 }
 483 
 484 /*
 485  * Class:     sun_lwawt_macosx_LWCToolkit
 486  * Method:    stopNativeNestedEventLoop
 487  * Signature: ()V
 488  */
 489 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_stopNativeNestedEventLoop
 490 (JNIEnv *env, jclass cls)
 491 {
 492 //    At this moment it seems that this method should be no-op
 493 }


 315 
 316     AWTRunLoopObject *o = nil;
 317 
 318     // We double retain because this object is owned by both main thread and "other" thread
 319     // We release in both doAWTRunLoop and stopAWTRunLoop
 320     o = [[AWTRunLoopObject alloc] init];
 321     if (o) {
 322         CFRetain(o); // GC
 323         CFRetain(o); // GC
 324         [o release];
 325     }
 326     return ptr_to_jlong(o);
 327 }
 328 
 329 /*
 330  * Class:     sun_lwawt_macosx_LWCToolkit
 331  * Method:    doAWTRunLoop
 332  * Signature: (JZZ)V
 333  */
 334 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_doAWTRunLoop
 335 (JNIEnv *env, jclass clz, jlong mediator, jboolean processEvents)
 336 {
 337 AWT_ASSERT_APPKIT_THREAD;
 338 JNF_COCOA_ENTER(env);
 339 
 340     AWTRunLoopObject* mediatorObject = (AWTRunLoopObject*)jlong_to_ptr(mediator);
 341 
 342     if (mediatorObject == nil) return;
 343 








 344     // Don't use acceptInputForMode because that doesn't setup autorelease pools properly
 345     BOOL isRunning = true;
 346     while (![mediatorObject shouldEndRunLoop] && isRunning) {
 347         isRunning = [[NSRunLoop currentRunLoop] runMode:[JNFRunLoop javaRunLoopMode]
 348                                              beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.010]];
 349         if (processEvents) {
 350             //We do not spin a runloop here as date is nil, so does not matter which mode to use
 351             NSEvent *event;
 352             if ((event = [NSApp nextEventMatchingMask:NSAnyEventMask
 353                                            untilDate:nil
 354                                               inMode:NSDefaultRunLoopMode
 355                                              dequeue:YES]) != nil) {
 356                 [NSApp sendEvent:event];
 357             }
 358 
 359         }




 360     }
 361 
 362    
 363     CFRelease(mediatorObject);
 364 
 365 JNF_COCOA_EXIT(env);
 366 }
 367 
 368 /*
 369  * Class:     sun_lwawt_macosx_LWCToolkit
 370  * Method:    stopAWTRunLoop
 371  * Signature: (J)V
 372  */
 373 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_stopAWTRunLoop
 374 (JNIEnv *env, jclass clz, jlong mediator)
 375 {
 376 AWT_ASSERT_NOT_APPKIT_THREAD;
 377 JNF_COCOA_ENTER(env);
 378 
 379     AWTRunLoopObject* mediatorObject = (AWTRunLoopObject*)jlong_to_ptr(mediator);
 380 
 381     [ThreadUtilities performOnMainThread:@selector(endRunLoop) on:mediatorObject withObject:nil waitUntilDone:NO];
 382 
 383     CFRelease(mediatorObject);
 384 
 385 JNF_COCOA_EXIT(env);
 386 }
 387 
 388 /*
 389  * Class:     sun_lwawt_macosx_LWCToolkit
 390  * Method:    isCapsLockOn
 391  * Signature: ()Z
 392  */
 393 JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_isCapsLockOn
 394 (JNIEnv *env, jobject self)
 395 {
 396     __block jboolean isOn = JNI_FALSE;
 397     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 398         NSUInteger modifiers = [NSEvent modifierFlags];
 399         isOn = (modifiers & NSAlphaShiftKeyMask) != 0;
 400     }];
 401 


 445 
 446 // TODO: definitely doesn't belong here (copied from fontpath.c in the
 447 // solaris tree)...
 448 
 449 JNIEXPORT jstring JNICALL
 450 Java_sun_font_FontManager_getFontPath
 451 (JNIEnv *env, jclass obj, jboolean noType1)
 452 {
 453     return JNFNSToJavaString(env, @"/Library/Fonts");
 454 }
 455 
 456 // This isn't yet used on unix, the implementation is added since shared
 457 // code calls this method in preparation for future use.
 458 JNIEXPORT void JNICALL
 459 Java_sun_font_FontManager_populateFontFileNameMap
 460 (JNIEnv *env, jclass obj, jobject fontToFileMap, jobject fontToFamilyMap, jobject familyToFontListMap, jobject locale)
 461 {
 462 
 463 }
 464 

















 465