412 } 413 414 + (NSNumber *) getNSWindowDisplayID_AppKitThread:(NSWindow *)window { 415 AWT_ASSERT_APPKIT_THREAD; 416 NSScreen *screen = [window screen]; 417 NSDictionary *deviceDescription = [screen deviceDescription]; 418 return [deviceDescription objectForKey:@"NSScreenNumber"]; 419 } 420 421 - (void) dealloc { 422 AWT_ASSERT_APPKIT_THREAD; 423 424 JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; 425 [self.javaPlatformWindow setJObject:nil withEnv:env]; 426 427 self.nsWindow = nil; 428 self.ownerWindow = nil; 429 [super dealloc]; 430 } 431 432 // Tests wheather the corresponding Java paltform window is visible or not 433 + (BOOL) isJavaPlatformWindowVisible:(NSWindow *)window { 434 BOOL isVisible = NO; 435 436 if ([AWTWindow isAWTWindow:window] && [window delegate] != nil) { 437 AWTWindow *awtWindow = (AWTWindow *)[window delegate]; 438 [AWTToolkit eventCountPlusPlus]; 439 440 JNIEnv *env = [ThreadUtilities getJNIEnv]; 441 jobject platformWindow = [awtWindow.javaPlatformWindow jObjectWithEnv:env]; 442 if (platformWindow != NULL) { 443 static JNF_MEMBER_CACHE(jm_isVisible, jc_CPlatformWindow, "isVisible", "()Z"); 444 isVisible = JNFCallBooleanMethod(env, platformWindow, jm_isVisible) == JNI_TRUE ? YES : NO; 445 (*env)->DeleteLocalRef(env, platformWindow); 446 447 } 448 } 449 return isVisible; 450 } 451 452 // Orders window's childs based on the current focus state 453 - (void) orderChildWindows:(BOOL)focus { 454 AWT_ASSERT_APPKIT_THREAD; 455 456 if (self.isMinimizing) { 457 // Do not perform any ordering, if iconify is in progress 458 return; 459 } 460 461 NSEnumerator *windowEnumerator = [[NSApp windows]objectEnumerator]; 462 NSWindow *window; 463 while ((window = [windowEnumerator nextObject]) != nil) { 464 if ([AWTWindow isJavaPlatformWindowVisible:window]) { 465 AWTWindow *awtWindow = (AWTWindow *)[window delegate]; 466 AWTWindow *owner = awtWindow.ownerWindow; 467 if (IS(awtWindow.styleBits, ALWAYS_ON_TOP)) { 468 // Do not order 'always on top' windows 469 continue; 470 } 471 while (awtWindow.ownerWindow != nil) { 472 if (awtWindow.ownerWindow == self) { 473 if (focus) { 474 // Move the childWindow to floating level 475 // so it will appear in front of its 476 // parent which owns the focus 477 [window setLevel:NSFloatingWindowLevel]; 783 JNFCallVoidMethod(env, platformWindow, jm_windowWillExitFullScreen); 784 [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_WILL_EXIT withEnv:env]; 785 (*env)->DeleteLocalRef(env, platformWindow); 786 } 787 } 788 789 - (void)windowDidExitFullScreen:(NSNotification *)notification { 790 static JNF_MEMBER_CACHE(jm_windowDidExitFullScreen, jc_CPlatformWindow, "windowDidExitFullScreen", "()V"); 791 JNIEnv *env = [ThreadUtilities getJNIEnv]; 792 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 793 if (platformWindow != NULL) { 794 JNFCallVoidMethod(env, platformWindow, jm_windowDidExitFullScreen); 795 [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_DID_EXIT withEnv:env]; 796 (*env)->DeleteLocalRef(env, platformWindow); 797 } 798 [AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows]; 799 } 800 801 - (void)sendEvent:(NSEvent *)event { 802 if ([event type] == NSLeftMouseDown || [event type] == NSRightMouseDown || [event type] == NSOtherMouseDown) { 803 // Move parent windows to front and make sure that a child window is displayed 804 // in front of its nearest parent. 805 if (self.ownerWindow != nil) { 806 JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; 807 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 808 if (platformWindow != NULL) { 809 static JNF_MEMBER_CACHE(jm_orderAboveSiblings, jc_CPlatformWindow, "orderAboveSiblings", "()V"); 810 JNFCallVoidMethod(env,platformWindow, jm_orderAboveSiblings); 811 (*env)->DeleteLocalRef(env, platformWindow); 812 } 813 } 814 [self orderChildWindows:YES]; 815 816 NSPoint p = [NSEvent mouseLocation]; 817 NSRect frame = [self.nsWindow frame]; 818 NSRect contentRect = [self.nsWindow contentRectForFrameRect:frame]; 819 820 // Check if the click happened in the non-client area (title bar) 821 if (p.y >= (frame.origin.y + contentRect.size.height)) { 822 JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; 823 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 824 if (platformWindow != NULL) { 825 // Currently, no need to deliver the whole NSEvent. 826 static JNF_MEMBER_CACHE(jm_deliverNCMouseDown, jc_CPlatformWindow, "deliverNCMouseDown", "()V"); 827 JNFCallVoidMethod(env, platformWindow, jm_deliverNCMouseDown); 828 (*env)->DeleteLocalRef(env, platformWindow); 829 } 830 } 831 } 832 } 833 834 - (void)constrainSize:(NSSize*)size { | 412 } 413 414 + (NSNumber *) getNSWindowDisplayID_AppKitThread:(NSWindow *)window { 415 AWT_ASSERT_APPKIT_THREAD; 416 NSScreen *screen = [window screen]; 417 NSDictionary *deviceDescription = [screen deviceDescription]; 418 return [deviceDescription objectForKey:@"NSScreenNumber"]; 419 } 420 421 - (void) dealloc { 422 AWT_ASSERT_APPKIT_THREAD; 423 424 JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; 425 [self.javaPlatformWindow setJObject:nil withEnv:env]; 426 427 self.nsWindow = nil; 428 self.ownerWindow = nil; 429 [super dealloc]; 430 } 431 432 // Tests whether window is blocked by modal dialog/window 433 - (BOOL) isBlocked { 434 BOOL isBlocked = NO; 435 436 JNIEnv *env = [ThreadUtilities getJNIEnv]; 437 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 438 if (platformWindow != NULL) { 439 static JNF_MEMBER_CACHE(jm_isBlocked, jc_CPlatformWindow, "isBlocked", "()Z"); 440 isBlocked = JNFCallBooleanMethod(env, platformWindow, jm_isBlocked) == JNI_TRUE ? YES : NO; 441 (*env)->DeleteLocalRef(env, platformWindow); 442 } 443 444 return isBlocked; 445 } 446 447 // Tests whether the corresponding Java platform window is visible or not 448 + (BOOL) isJavaPlatformWindowVisible:(NSWindow *)window { 449 BOOL isVisible = NO; 450 451 if ([AWTWindow isAWTWindow:window] && [window delegate] != nil) { 452 AWTWindow *awtWindow = (AWTWindow *)[window delegate]; 453 [AWTToolkit eventCountPlusPlus]; 454 455 JNIEnv *env = [ThreadUtilities getJNIEnv]; 456 jobject platformWindow = [awtWindow.javaPlatformWindow jObjectWithEnv:env]; 457 if (platformWindow != NULL) { 458 static JNF_MEMBER_CACHE(jm_isVisible, jc_CPlatformWindow, "isVisible", "()Z"); 459 isVisible = JNFCallBooleanMethod(env, platformWindow, jm_isVisible) == JNI_TRUE ? YES : NO; 460 (*env)->DeleteLocalRef(env, platformWindow); 461 462 } 463 } 464 return isVisible; 465 } 466 467 // Orders window's childs based on the current focus state 468 - (void) orderChildWindows:(BOOL)focus { 469 AWT_ASSERT_APPKIT_THREAD; 470 471 if (self.isMinimizing || [self isBlocked]) { 472 // Do not perform any ordering, if iconify is in progress 473 // or the window is blocked by a modal window 474 return; 475 } 476 477 NSEnumerator *windowEnumerator = [[NSApp windows]objectEnumerator]; 478 NSWindow *window; 479 while ((window = [windowEnumerator nextObject]) != nil) { 480 if ([AWTWindow isJavaPlatformWindowVisible:window]) { 481 AWTWindow *awtWindow = (AWTWindow *)[window delegate]; 482 AWTWindow *owner = awtWindow.ownerWindow; 483 if (IS(awtWindow.styleBits, ALWAYS_ON_TOP)) { 484 // Do not order 'always on top' windows 485 continue; 486 } 487 while (awtWindow.ownerWindow != nil) { 488 if (awtWindow.ownerWindow == self) { 489 if (focus) { 490 // Move the childWindow to floating level 491 // so it will appear in front of its 492 // parent which owns the focus 493 [window setLevel:NSFloatingWindowLevel]; 799 JNFCallVoidMethod(env, platformWindow, jm_windowWillExitFullScreen); 800 [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_WILL_EXIT withEnv:env]; 801 (*env)->DeleteLocalRef(env, platformWindow); 802 } 803 } 804 805 - (void)windowDidExitFullScreen:(NSNotification *)notification { 806 static JNF_MEMBER_CACHE(jm_windowDidExitFullScreen, jc_CPlatformWindow, "windowDidExitFullScreen", "()V"); 807 JNIEnv *env = [ThreadUtilities getJNIEnv]; 808 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 809 if (platformWindow != NULL) { 810 JNFCallVoidMethod(env, platformWindow, jm_windowDidExitFullScreen); 811 [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_DID_EXIT withEnv:env]; 812 (*env)->DeleteLocalRef(env, platformWindow); 813 } 814 [AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows]; 815 } 816 817 - (void)sendEvent:(NSEvent *)event { 818 if ([event type] == NSLeftMouseDown || [event type] == NSRightMouseDown || [event type] == NSOtherMouseDown) { 819 if ([self isBlocked]) { 820 // Move parent windows to front and make sure that a child window is displayed 821 // in front of its nearest parent. 822 if (self.ownerWindow != nil) { 823 JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; 824 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 825 if (platformWindow != NULL) { 826 static JNF_MEMBER_CACHE(jm_orderAboveSiblings, jc_CPlatformWindow, "orderAboveSiblings", "()V"); 827 JNFCallVoidMethod(env,platformWindow, jm_orderAboveSiblings); 828 (*env)->DeleteLocalRef(env, platformWindow); 829 } 830 } 831 [self orderChildWindows:YES]; 832 } 833 834 NSPoint p = [NSEvent mouseLocation]; 835 NSRect frame = [self.nsWindow frame]; 836 NSRect contentRect = [self.nsWindow contentRectForFrameRect:frame]; 837 838 // Check if the click happened in the non-client area (title bar) 839 if (p.y >= (frame.origin.y + contentRect.size.height)) { 840 JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; 841 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; 842 if (platformWindow != NULL) { 843 // Currently, no need to deliver the whole NSEvent. 844 static JNF_MEMBER_CACHE(jm_deliverNCMouseDown, jc_CPlatformWindow, "deliverNCMouseDown", "()V"); 845 JNFCallVoidMethod(env, platformWindow, jm_deliverNCMouseDown); 846 (*env)->DeleteLocalRef(env, platformWindow); 847 } 848 } 849 } 850 } 851 852 - (void)constrainSize:(NSSize*)size { |