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");


 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");


 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     CMenuBar *menuBar = nil;
 553     if ([awtWindow.nsWindow isVisible]){
 554         menuBar = awtWindow.javaMenuBar;
 555     }
 556 
 557     if (menuBar == nil) {
 558         menuBar = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
 559     }
 560 
 561     [CMenuBar activate:menuBar modallyDisabled:!awtWindow.isEnabled];
 562 
 563     [AWTWindow setLastKeyWindow:nil];
 564 
 565     [self _deliverWindowFocusEvent:YES oppositeWindow: opposite];
 566 }
 567 
 568 - (void) windowDidResignKey: (NSNotification *) notification {
 569     // TODO: check why sometimes at start is invoked *not* on AppKit main thread.
 570 AWT_ASSERT_APPKIT_THREAD;
 571     [AWTToolkit eventCountPlusPlus];
 572     [self.javaMenuBar deactivate];
 573 
 574     CMenuBar* defaultMenu = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
 575     if (defaultMenu != nil) {
 576         [CMenuBar activate:defaultMenu modallyDisabled:NO];
 577     }
 578 
 579     // the new key window
 580     NSWindow *keyWindow = [NSApp keyWindow];
 581     AWTWindow *opposite = nil;
 582     if ([AWTWindow isAWTWindow: keyWindow]) {
 583         opposite = (AWTWindow *)[keyWindow delegate];
 584         [AWTWindow setLastKeyWindow: self];
 585     } else {
 586         [AWTWindow setLastKeyWindow: nil];
 587     }
 588 
 589     [self _deliverWindowFocusEvent:NO oppositeWindow: opposite];
 590 }
 591 
 592 - (void) windowDidBecomeMain: (NSNotification *) notification {
 593 AWT_ASSERT_APPKIT_THREAD;
 594     [AWTToolkit eventCountPlusPlus];
 595 
 596     JNIEnv *env = [ThreadUtilities getJNIEnv];
 597     jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
 598     if (platformWindow != NULL) {


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