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

Print this page




  38 #import "ThreadUtilities.h"
  39 #import "AWT_debug.h"
  40 #import "CSystemColors.h"
  41 #import  "NSApplicationAWT.h"
  42 #import "PropertiesUtilities.h"
  43 #import "ApplicationDelegate.h"
  44 
  45 #import "sun_lwawt_macosx_LWCToolkit.h"
  46 
  47 #import "sizecalc.h"
  48 
  49 int gNumberOfButtons;
  50 jint* gButtonDownMasks;
  51 
  52 // Indicates that the app has been started with -XstartOnFirstThread
  53 // (directly or via WebStart settings), and AWT should not run its
  54 // own event loop in this mode. Even if a loop isn't running yet,
  55 // we expect an embedder (e.g. SWT) to start it some time later.
  56 static BOOL forceEmbeddedMode = NO;
  57 



  58 // This is the data necessary to have JNI_OnLoad wait for AppKit to start.
  59 static BOOL sAppKitStarted = NO;
  60 static pthread_mutex_t sAppKitStarted_mutex = PTHREAD_MUTEX_INITIALIZER;
  61 static pthread_cond_t sAppKitStarted_cv = PTHREAD_COND_INITIALIZER;
  62 
  63 @implementation AWTToolkit
  64 
  65 static long eventCount;
  66 
  67 + (long) getEventCount{
  68     return eventCount;
  69 }
  70 
  71 + (void) eventCountPlusPlus{    
  72     eventCount++;
  73 }
  74 
  75 @end
  76 
  77 


 308             setUpAWTAppKit(false);
 309         }
 310         [AWTStarter markAppAsDaemon];
 311         return;
 312     }
 313 
 314     if (forceEmbeddedMode) {
 315         AWT_STARTUP_LOG(@"in SWT or SWT/WebStart mode");
 316 
 317         // Init a default NSApplication instance instead of the NSApplicationAWT.
 318         // Note that [NSApp isRunning] will return YES after that, though
 319         // this behavior isn't specified anywhere. We rely on that.
 320         NSApplicationLoad();
 321     }
 322 
 323     // This will create a NSApplicationAWT for standalone AWT programs, unless there is
 324     //  already a NSApplication instance. If there is already a NSApplication instance,
 325     //  and -[NSApplication isRunning] returns YES, AWT is embedded inside another
 326     //  AppKit Application.
 327     NSApplication *app = [NSApplicationAWT sharedApplication];
 328     BOOL isEmbedded = ![NSApp isKindOfClass:[NSApplicationAWT class]];
 329     [ThreadUtilities setAWTEmbedded:isEmbedded];
 330 
 331     if (!isEmbedded) {
 332         // Install run loop observers and set the AppKit Java thread name
 333         setUpAWTAppKit(true);
 334     }
 335 
 336     // AWT gets to this point BEFORE NSApplicationDidFinishLaunchingNotification is sent.
 337     if (![app isRunning]) {
 338         AWT_STARTUP_LOG(@"+[AWTStarter startAWT]: ![app isRunning]");
 339         // This is where the AWT AppKit thread parks itself to process events.
 340         [NSApplicationAWT runAWTLoopWithApp: app];
 341     } else {
 342         // We're either embedded, or showing a splash screen
 343         if (isEmbedded) {
 344             AWT_STARTUP_LOG(@"running embedded");
 345             
 346             // We don't track if the runloop is busy, so set it free to let AWT finish when it needs
 347             setBusy(NO);
 348         } else {
 349             AWT_STARTUP_LOG(@"running after showing a splash screen");


 706     if (isSWTInWebStart(env)) {
 707         forceEmbeddedMode = YES;
 708     }
 709 
 710     [AWTStarter start:headless ? YES : NO];
 711 
 712     JNF_COCOA_EXIT(env)
 713 }
 714 
 715 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
 716     OSXAPP_SetJavaVM(vm);
 717 
 718     // We need to let Foundation know that this is a multithreaded application, if it isn't already.
 719     if (![NSThread isMultiThreaded]) {
 720         [NSThread detachNewThreadSelector:nil toTarget:nil withObject:nil];
 721     }
 722 
 723     return JNI_VERSION_1_4;
 724 }
 725 













  38 #import "ThreadUtilities.h"
  39 #import "AWT_debug.h"
  40 #import "CSystemColors.h"
  41 #import  "NSApplicationAWT.h"
  42 #import "PropertiesUtilities.h"
  43 #import "ApplicationDelegate.h"
  44 
  45 #import "sun_lwawt_macosx_LWCToolkit.h"
  46 
  47 #import "sizecalc.h"
  48 
  49 int gNumberOfButtons;
  50 jint* gButtonDownMasks;
  51 
  52 // Indicates that the app has been started with -XstartOnFirstThread
  53 // (directly or via WebStart settings), and AWT should not run its
  54 // own event loop in this mode. Even if a loop isn't running yet,
  55 // we expect an embedder (e.g. SWT) to start it some time later.
  56 static BOOL forceEmbeddedMode = NO;
  57 
  58 // Indicates if awt toolkit is embedded into another UI toolkit
  59 static BOOL isEmbedded = NO;
  60 
  61 // This is the data necessary to have JNI_OnLoad wait for AppKit to start.
  62 static BOOL sAppKitStarted = NO;
  63 static pthread_mutex_t sAppKitStarted_mutex = PTHREAD_MUTEX_INITIALIZER;
  64 static pthread_cond_t sAppKitStarted_cv = PTHREAD_COND_INITIALIZER;
  65 
  66 @implementation AWTToolkit
  67 
  68 static long eventCount;
  69 
  70 + (long) getEventCount{
  71     return eventCount;
  72 }
  73 
  74 + (void) eventCountPlusPlus{    
  75     eventCount++;
  76 }
  77 
  78 @end
  79 
  80 


 311             setUpAWTAppKit(false);
 312         }
 313         [AWTStarter markAppAsDaemon];
 314         return;
 315     }
 316 
 317     if (forceEmbeddedMode) {
 318         AWT_STARTUP_LOG(@"in SWT or SWT/WebStart mode");
 319 
 320         // Init a default NSApplication instance instead of the NSApplicationAWT.
 321         // Note that [NSApp isRunning] will return YES after that, though
 322         // this behavior isn't specified anywhere. We rely on that.
 323         NSApplicationLoad();
 324     }
 325 
 326     // This will create a NSApplicationAWT for standalone AWT programs, unless there is
 327     //  already a NSApplication instance. If there is already a NSApplication instance,
 328     //  and -[NSApplication isRunning] returns YES, AWT is embedded inside another
 329     //  AppKit Application.
 330     NSApplication *app = [NSApplicationAWT sharedApplication];
 331     isEmbedded = ![NSApp isKindOfClass:[NSApplicationAWT class]];

 332 
 333     if (!isEmbedded) {
 334         // Install run loop observers and set the AppKit Java thread name
 335         setUpAWTAppKit(true);
 336     }
 337 
 338     // AWT gets to this point BEFORE NSApplicationDidFinishLaunchingNotification is sent.
 339     if (![app isRunning]) {
 340         AWT_STARTUP_LOG(@"+[AWTStarter startAWT]: ![app isRunning]");
 341         // This is where the AWT AppKit thread parks itself to process events.
 342         [NSApplicationAWT runAWTLoopWithApp: app];
 343     } else {
 344         // We're either embedded, or showing a splash screen
 345         if (isEmbedded) {
 346             AWT_STARTUP_LOG(@"running embedded");
 347             
 348             // We don't track if the runloop is busy, so set it free to let AWT finish when it needs
 349             setBusy(NO);
 350         } else {
 351             AWT_STARTUP_LOG(@"running after showing a splash screen");


 708     if (isSWTInWebStart(env)) {
 709         forceEmbeddedMode = YES;
 710     }
 711 
 712     [AWTStarter start:headless ? YES : NO];
 713 
 714     JNF_COCOA_EXIT(env)
 715 }
 716 
 717 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
 718     OSXAPP_SetJavaVM(vm);
 719 
 720     // We need to let Foundation know that this is a multithreaded application, if it isn't already.
 721     if (![NSThread isMultiThreaded]) {
 722         [NSThread detachNewThreadSelector:nil toTarget:nil withObject:nil];
 723     }
 724 
 725     return JNI_VERSION_1_4;
 726 }
 727 
 728 /*
 729  * Class:     sun_lwawt_macosx_LWCToolkit
 730  * Method:    isEmbedded
 731  * Signature: ()Z
 732  */
 733 JNIEXPORT jboolean JNICALL
 734 Java_sun_lwawt_macosx_LWCToolkit_isEmbedded
 735 (JNIEnv *env, jclass klass) {
 736     return isEmbedded ? JNI_TRUE : JNI_FALSE;
 737 }
 738