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

Print this page




  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
  23  * questions.
  24  */
  25 
  26 #import <Cocoa/Cocoa.h>
  27 #import <JavaNativeFoundation/JavaNativeFoundation.h>
  28 #import <JavaRuntimeSupport/JavaRuntimeSupport.h>
  29 
  30 #import "sun_lwawt_macosx_CPlatformWindow.h"
  31 #import "com_apple_eawt_event_GestureHandler.h"
  32 #import "com_apple_eawt_FullScreenHandler.h"

  33 
  34 #import "AWTWindow.h"
  35 #import "AWTView.h"
  36 #import "CMenu.h"
  37 #import "CMenuBar.h"
  38 #import "LWCToolkit.h"
  39 #import "GeomUtilities.h"
  40 #import "ThreadUtilities.h"
  41 #import "OSVersion.h"
  42 
  43 #define MASK(KEY) \
  44     (sun_lwawt_macosx_CPlatformWindow_ ## KEY)
  45 
  46 #define IS(BITS, KEY) \
  47     ((BITS & MASK(KEY)) != 0)
  48 
  49 #define SET(BITS, KEY, VALUE) \
  50     BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY)
  51 
  52 static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow");


 531         jobject oppositeWindow = [opposite.javaPlatformWindow jObjectWithEnv:env];
 532 
 533         static JNF_MEMBER_CACHE(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(ZLsun/lwawt/macosx/CPlatformWindow;)V");
 534         JNFCallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused, oppositeWindow);
 535         (*env)->DeleteLocalRef(env, platformWindow);
 536         (*env)->DeleteLocalRef(env, oppositeWindow);
 537     }
 538 }
 539 
 540 
 541 - (void) windowDidBecomeKey: (NSNotification *) notification {
 542 AWT_ASSERT_APPKIT_THREAD;
 543     [AWTToolkit eventCountPlusPlus];
 544     AWTWindow *opposite = [AWTWindow lastKeyWindow];
 545     
 546     // Finds appropriate menubar in our hierarchy,
 547     AWTWindow *awtWindow = self;
 548     while (awtWindow.ownerWindow != nil) {
 549         awtWindow = awtWindow.ownerWindow;
 550     }

 551     CMenuBar *menuBar = nil;

 552     if ([awtWindow.nsWindow isVisible]){
 553         menuBar = awtWindow.javaMenuBar;






 554     }
 555     [CMenuBar activate:menuBar modallyDisabled:!awtWindow.isEnabled];

 556 
 557     [AWTWindow setLastKeyWindow:nil];
 558 
 559     [self _deliverWindowFocusEvent:YES oppositeWindow: opposite];
 560 }
 561 
 562 - (void) windowDidResignKey: (NSNotification *) notification {
 563     // TODO: check why sometimes at start is invoked *not* on AppKit main thread.
 564 AWT_ASSERT_APPKIT_THREAD;
 565     [AWTToolkit eventCountPlusPlus];
 566     [self.javaMenuBar deactivate];
 567 








 568     // the new key window
 569     NSWindow *keyWindow = [NSApp keyWindow];
 570     AWTWindow *opposite = nil;
 571     if ([AWTWindow isAWTWindow: keyWindow]) {
 572         opposite = (AWTWindow *)[keyWindow delegate];
 573         [AWTWindow setLastKeyWindow: self];
 574     } else {
 575         [AWTWindow setLastKeyWindow: nil];
 576     }
 577 
 578     [self _deliverWindowFocusEvent:NO oppositeWindow: opposite];
 579 }
 580 
 581 - (void) windowDidBecomeMain: (NSNotification *) notification {
 582 AWT_ASSERT_APPKIT_THREAD;
 583     [AWTToolkit eventCountPlusPlus];
 584 
 585     JNIEnv *env = [ThreadUtilities getJNIEnv];
 586     jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
 587     if (platformWindow != NULL) {


 812 
 813 JNF_COCOA_EXIT(env);
 814 }
 815 
 816 /*
 817  * Class:     sun_lwawt_macosx_CPlatformWindow
 818  * Method:    nativeSetNSWindowMenuBar
 819  * Signature: (JJ)V
 820  */
 821 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMenuBar
 822 (JNIEnv *env, jclass clazz, jlong windowPtr, jlong menuBarPtr)
 823 {
 824 JNF_COCOA_ENTER(env);
 825 
 826     NSWindow *nsWindow = OBJC(windowPtr);
 827     CMenuBar *menuBar = OBJC(menuBarPtr);
 828     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
 829 
 830         AWTWindow *window = (AWTWindow*)[nsWindow delegate];
 831 
 832         if ([nsWindow isKeyWindow]) [window.javaMenuBar deactivate];



 833         window.javaMenuBar = menuBar;
 834 





 835         if ([nsWindow isKeyWindow]) {
 836             [CMenuBar activate:window.javaMenuBar modallyDisabled:NO];
 837         }
 838     }];
 839 
 840 JNF_COCOA_EXIT(env);
 841 }
 842 
 843 /*
 844  * Class:     sun_lwawt_macosx_CPlatformWindow
 845  * Method:    nativeGetNSWindowInsets
 846  * Signature: (J)Ljava/awt/Insets;
 847  */
 848 JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetNSWindowInsets
 849 (JNIEnv *env, jclass clazz, jlong windowPtr)
 850 {
 851     jobject ret = NULL;
 852 
 853 JNF_COCOA_ENTER(env);
 854 
 855     NSWindow *nsWindow = OBJC(windowPtr);
 856     __block NSRect contentRect = NSZeroRect;




  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
  23  * questions.
  24  */
  25 
  26 #import <Cocoa/Cocoa.h>
  27 #import <JavaNativeFoundation/JavaNativeFoundation.h>
  28 #import <JavaRuntimeSupport/JavaRuntimeSupport.h>
  29 
  30 #import "sun_lwawt_macosx_CPlatformWindow.h"
  31 #import "com_apple_eawt_event_GestureHandler.h"
  32 #import "com_apple_eawt_FullScreenHandler.h"
  33 #import "ApplicationDelegate.h"
  34 
  35 #import "AWTWindow.h"
  36 #import "AWTView.h"
  37 #import "CMenu.h"
  38 #import "CMenuBar.h"
  39 #import "LWCToolkit.h"
  40 #import "GeomUtilities.h"
  41 #import "ThreadUtilities.h"
  42 #import "OSVersion.h"
  43 
  44 #define MASK(KEY) \
  45     (sun_lwawt_macosx_CPlatformWindow_ ## KEY)
  46 
  47 #define IS(BITS, KEY) \
  48     ((BITS & MASK(KEY)) != 0)
  49 
  50 #define SET(BITS, KEY, VALUE) \
  51     BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY)
  52 
  53 static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow");


 532         jobject oppositeWindow = [opposite.javaPlatformWindow jObjectWithEnv:env];
 533 
 534         static JNF_MEMBER_CACHE(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(ZLsun/lwawt/macosx/CPlatformWindow;)V");
 535         JNFCallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused, oppositeWindow);
 536         (*env)->DeleteLocalRef(env, platformWindow);
 537         (*env)->DeleteLocalRef(env, oppositeWindow);
 538     }
 539 }
 540 
 541 
 542 - (void) windowDidBecomeKey: (NSNotification *) notification {
 543 AWT_ASSERT_APPKIT_THREAD;
 544     [AWTToolkit eventCountPlusPlus];
 545     AWTWindow *opposite = [AWTWindow lastKeyWindow];
 546 
 547     // Finds appropriate menubar in our hierarchy,
 548     AWTWindow *awtWindow = self;
 549     while (awtWindow.ownerWindow != nil) {
 550         awtWindow = awtWindow.ownerWindow;
 551     }
 552 
 553     CMenuBar *menuBar = nil;
 554     BOOL isDisabled = NO;
 555     if ([awtWindow.nsWindow isVisible]){
 556         menuBar = awtWindow.javaMenuBar;
 557         isDisabled = !awtWindow.isEnabled;
 558     }
 559 
 560     if (menuBar == nil) {
 561         menuBar = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
 562         isDisabled = NO;
 563     }
 564 
 565     [CMenuBar activate:menuBar modallyDisabled:isDisabled];
 566 
 567     [AWTWindow setLastKeyWindow:nil];
 568 
 569     [self _deliverWindowFocusEvent:YES oppositeWindow: opposite];
 570 }
 571 
 572 - (void) windowDidResignKey: (NSNotification *) notification {
 573     // TODO: check why sometimes at start is invoked *not* on AppKit main thread.
 574 AWT_ASSERT_APPKIT_THREAD;
 575     [AWTToolkit eventCountPlusPlus];
 576     [self.javaMenuBar deactivate];
 577 
 578     // In theory, this might cause flickering if the window gaining focus
 579     // has its own menu. However, I couldn't reproduce it on practice, so
 580     // perhaps this is a non issue.
 581     CMenuBar* defaultMenu = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
 582     if (defaultMenu != nil) {
 583         [CMenuBar activate:defaultMenu modallyDisabled:NO];
 584     }
 585 
 586     // the new key window
 587     NSWindow *keyWindow = [NSApp keyWindow];
 588     AWTWindow *opposite = nil;
 589     if ([AWTWindow isAWTWindow: keyWindow]) {
 590         opposite = (AWTWindow *)[keyWindow delegate];
 591         [AWTWindow setLastKeyWindow: self];
 592     } else {
 593         [AWTWindow setLastKeyWindow: nil];
 594     }
 595 
 596     [self _deliverWindowFocusEvent:NO oppositeWindow: opposite];
 597 }
 598 
 599 - (void) windowDidBecomeMain: (NSNotification *) notification {
 600 AWT_ASSERT_APPKIT_THREAD;
 601     [AWTToolkit eventCountPlusPlus];
 602 
 603     JNIEnv *env = [ThreadUtilities getJNIEnv];
 604     jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
 605     if (platformWindow != NULL) {


 830 
 831 JNF_COCOA_EXIT(env);
 832 }
 833 
 834 /*
 835  * Class:     sun_lwawt_macosx_CPlatformWindow
 836  * Method:    nativeSetNSWindowMenuBar
 837  * Signature: (JJ)V
 838  */
 839 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMenuBar
 840 (JNIEnv *env, jclass clazz, jlong windowPtr, jlong menuBarPtr)
 841 {
 842 JNF_COCOA_ENTER(env);
 843 
 844     NSWindow *nsWindow = OBJC(windowPtr);
 845     CMenuBar *menuBar = OBJC(menuBarPtr);
 846     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
 847 
 848         AWTWindow *window = (AWTWindow*)[nsWindow delegate];
 849 
 850         if ([nsWindow isKeyWindow]) {
 851             [window.javaMenuBar deactivate];
 852         }
 853 
 854         window.javaMenuBar = menuBar;
 855 
 856         CMenuBar* actualMenuBar = menuBar;
 857         if (actualMenuBar == nil) {
 858             actualMenuBar = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
 859         }
 860 
 861         if ([nsWindow isKeyWindow]) {
 862             [CMenuBar activate:actualMenuBar modallyDisabled:NO];
 863         }
 864     }];
 865 
 866 JNF_COCOA_EXIT(env);
 867 }
 868 
 869 /*
 870  * Class:     sun_lwawt_macosx_CPlatformWindow
 871  * Method:    nativeGetNSWindowInsets
 872  * Signature: (J)Ljava/awt/Insets;
 873  */
 874 JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetNSWindowInsets
 875 (JNIEnv *env, jclass clazz, jlong windowPtr)
 876 {
 877     jobject ret = NULL;
 878 
 879 JNF_COCOA_ENTER(env);
 880 
 881     NSWindow *nsWindow = OBJC(windowPtr);
 882     __block NSRect contentRect = NSZeroRect;