src/macosx/native/sun/osxapp/NSApplicationAWT.m

Print this page




  35 
  36 static BOOL sUsingDefaultNIB = YES;
  37 static NSString *SHARED_FRAMEWORK_BUNDLE = @"/System/Library/Frameworks/JavaVM.framework";
  38 static id <NSApplicationDelegate> applicationDelegate = nil;
  39 static QueuingApplicationDelegate * qad = nil;
  40 
  41 // Flag used to indicate to the Plugin2 event synthesis code to do a postEvent instead of sendEvent
  42 BOOL postEventDuringEventSynthesis = NO;
  43 
  44 @implementation NSApplicationAWT
  45 
  46 - (id) init
  47 {
  48     // Headless: NO
  49     // Embedded: NO
  50     // Multiple Calls: NO
  51     //  Caller: +[NSApplication sharedApplication]
  52 
  53 AWT_ASSERT_APPKIT_THREAD;
  54     fApplicationName = nil;



  55 
  56     // NSApplication will call _RegisterApplication with the application's bundle, but there may not be one.
  57     // So, we need to call it ourselves to ensure the app is set up properly.
  58     [self registerWithProcessManager];
  59 
  60     return [super init];
  61 }
  62 
  63 - (void)dealloc
  64 {
  65     [fApplicationName release];
  66     fApplicationName = nil;
  67 
  68     [super dealloc];
  69 }
  70 //- (void)finalize { [super finalize]; }
  71 
  72 - (void)finishLaunching
  73 {
  74 AWT_ASSERT_APPKIT_THREAD;


 311             [optionsDictionary setValue:[NSApp applicationIconImage] forKey:@"ApplicationIcon"];
 312         }
 313     }
 314 
 315     [super orderFrontStandardAboutPanelWithOptions:optionsDictionary];
 316 }
 317 
 318 #define DRAGMASK (NSMouseMovedMask | NSLeftMouseDraggedMask | NSRightMouseDownMask | NSRightMouseDraggedMask | NSLeftMouseUpMask | NSRightMouseUpMask | NSFlagsChangedMask | NSKeyDownMask)
 319 
 320 - (NSEvent *)nextEventMatchingMask:(NSUInteger)mask untilDate:(NSDate *)expiration inMode:(NSString *)mode dequeue:(BOOL)deqFlag {
 321     if (mask == DRAGMASK && [((NSString *)kCFRunLoopDefaultMode) isEqual:mode]) {
 322         postEventDuringEventSynthesis = YES;
 323     }
 324 
 325     NSEvent *event = [super nextEventMatchingMask:mask untilDate:expiration inMode:mode dequeue: deqFlag];
 326     postEventDuringEventSynthesis = NO;
 327 
 328     return event;
 329 }
 330 







































 331 @end
 332 
 333 
 334 void OSXAPP_SetApplicationDelegate(id <NSApplicationDelegate> delegate)
 335 {
 336 AWT_ASSERT_APPKIT_THREAD;
 337     applicationDelegate = delegate;
 338 
 339     if (NSApp != nil) {
 340         [NSApp setDelegate: applicationDelegate];
 341 
 342         if (applicationDelegate && qad) {
 343             [qad processQueuedEventsWithTargetDelegate: applicationDelegate];
 344             qad = nil;
 345         }
 346     }
 347 }
 348 


  35 
  36 static BOOL sUsingDefaultNIB = YES;
  37 static NSString *SHARED_FRAMEWORK_BUNDLE = @"/System/Library/Frameworks/JavaVM.framework";
  38 static id <NSApplicationDelegate> applicationDelegate = nil;
  39 static QueuingApplicationDelegate * qad = nil;
  40 
  41 // Flag used to indicate to the Plugin2 event synthesis code to do a postEvent instead of sendEvent
  42 BOOL postEventDuringEventSynthesis = NO;
  43 
  44 @implementation NSApplicationAWT
  45 
  46 - (id) init
  47 {
  48     // Headless: NO
  49     // Embedded: NO
  50     // Multiple Calls: NO
  51     //  Caller: +[NSApplication sharedApplication]
  52 
  53 AWT_ASSERT_APPKIT_THREAD;
  54     fApplicationName = nil;
  55     dummyEventTimestamp = 0.0;
  56     seenDummyEventLock = nil;
  57 
  58 
  59     // NSApplication will call _RegisterApplication with the application's bundle, but there may not be one.
  60     // So, we need to call it ourselves to ensure the app is set up properly.
  61     [self registerWithProcessManager];
  62 
  63     return [super init];
  64 }
  65 
  66 - (void)dealloc
  67 {
  68     [fApplicationName release];
  69     fApplicationName = nil;
  70 
  71     [super dealloc];
  72 }
  73 //- (void)finalize { [super finalize]; }
  74 
  75 - (void)finishLaunching
  76 {
  77 AWT_ASSERT_APPKIT_THREAD;


 314             [optionsDictionary setValue:[NSApp applicationIconImage] forKey:@"ApplicationIcon"];
 315         }
 316     }
 317 
 318     [super orderFrontStandardAboutPanelWithOptions:optionsDictionary];
 319 }
 320 
 321 #define DRAGMASK (NSMouseMovedMask | NSLeftMouseDraggedMask | NSRightMouseDownMask | NSRightMouseDraggedMask | NSLeftMouseUpMask | NSRightMouseUpMask | NSFlagsChangedMask | NSKeyDownMask)
 322 
 323 - (NSEvent *)nextEventMatchingMask:(NSUInteger)mask untilDate:(NSDate *)expiration inMode:(NSString *)mode dequeue:(BOOL)deqFlag {
 324     if (mask == DRAGMASK && [((NSString *)kCFRunLoopDefaultMode) isEqual:mode]) {
 325         postEventDuringEventSynthesis = YES;
 326     }
 327 
 328     NSEvent *event = [super nextEventMatchingMask:mask untilDate:expiration inMode:mode dequeue: deqFlag];
 329     postEventDuringEventSynthesis = NO;
 330 
 331     return event;
 332 }
 333 
 334 // NSTimeInterval has microseconds precision
 335 #define TS_EQUAL(ts1, ts2) (fabs((ts1) - (ts2)) < 1e-6)
 336 
 337 - (void)sendEvent:(NSEvent *)event
 338 {
 339     if ([event type] == NSApplicationDefined && TS_EQUAL([event timestamp], dummyEventTimestamp)) {
 340         [seenDummyEventLock lockWhenCondition:NO];
 341         [seenDummyEventLock unlockWithCondition:YES];
 342     } else {
 343         [super sendEvent:event];
 344     }
 345 }
 346 
 347 - (void)postDummyEvent {
 348     seenDummyEventLock = [[NSConditionLock alloc] initWithCondition:NO];
 349     dummyEventTimestamp = [NSProcessInfo processInfo].systemUptime;
 350     
 351     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];    
 352     NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined
 353                                         location: NSMakePoint(0,0)
 354                                    modifierFlags: 0
 355                                        timestamp: dummyEventTimestamp
 356                                     windowNumber: 0
 357                                          context: nil
 358                                          subtype: 0
 359                                            data1: 0
 360                                            data2: 0];
 361     [NSApp postEvent: event atStart: NO];
 362     [pool drain];
 363 }
 364 
 365 - (void)waitForDummyEvent {
 366     [seenDummyEventLock lockWhenCondition:YES];
 367     [seenDummyEventLock unlock];
 368     [seenDummyEventLock release];
 369 
 370     seenDummyEventLock = nil;
 371 }
 372 
 373 @end
 374 
 375 
 376 void OSXAPP_SetApplicationDelegate(id <NSApplicationDelegate> delegate)
 377 {
 378 AWT_ASSERT_APPKIT_THREAD;
 379     applicationDelegate = delegate;
 380 
 381     if (NSApp != nil) {
 382         [NSApp setDelegate: applicationDelegate];
 383 
 384         if (applicationDelegate && qad) {
 385             [qad processQueuedEventsWithTargetDelegate: applicationDelegate];
 386             qad = nil;
 387         }
 388     }
 389 }
 390