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

Print this page

        

@@ -56,10 +56,11 @@
 @synthesize javaPlatformWindow;
 @synthesize javaMenuBar;
 @synthesize javaMinSize;
 @synthesize javaMaxSize;
 @synthesize styleBits;
+@synthesize isModallyBlocked;
 
 - (void) updateMinMaxSize:(BOOL)resizable {
     if (resizable) {
         [self setMinSize:self.javaMinSize];
         [self setMaxSize:self.javaMaxSize];

@@ -155,10 +156,11 @@
                               backing:NSBackingStoreBuffered
                                 defer:NO];
 
     if (self == nil) return nil; // no hope
 
+    self.isModallyBlocked = NO;
     self.javaPlatformWindow = platformWindow;
     self.styleBits = bits;
     [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
 
     [self setDelegate:self];

@@ -177,20 +179,19 @@
     [self.javaPlatformWindow setJObject:nil withEnv:env];
 
     [super dealloc];
 }
 
-
 // NSWindow overrides
 - (BOOL) canBecomeKeyWindow {
 AWT_ASSERT_APPKIT_THREAD;
-    return IS(self.styleBits, SHOULD_BECOME_KEY);
+    return !self.isModallyBlocked && IS(self.styleBits, SHOULD_BECOME_KEY);
 }
 
 - (BOOL) canBecomeMainWindow {
 AWT_ASSERT_APPKIT_THREAD;
-    return IS(self.styleBits, SHOULD_BECOME_MAIN);
+    return !self.isModallyBlocked && IS(self.styleBits, SHOULD_BECOME_MAIN);
 }
 
 - (BOOL) worksWhenModal {
 AWT_ASSERT_APPKIT_THREAD;
     return IS(self.styleBits, MODAL_EXCLUDED);

@@ -971,5 +972,56 @@
 
 JNF_COCOA_EXIT(env);
 
     return underMouse;
 }
+
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeModallyBlocked
+(JNIEnv *env, jclass clazz, jlong windowPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    AWTWindow *window = OBJC(windowPtr);
+    if (IS(window.styleBits, MODAL_EXCLUDED)) {
+        return;
+    }
+
+    window.isModallyBlocked = YES;
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [[window standardWindowButton:NSWindowCloseButton] setEnabled: NO];
+        [[window standardWindowButton:NSWindowMiniaturizeButton] setEnabled: NO];
+        [[window standardWindowButton:NSWindowZoomButton] setEnabled: NO];
+
+        [window updateMinMaxSize:NO];
+        [window setShowsResizeIndicator:NO];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeModallyUnblocked
+(JNIEnv *env, jclass clazz, jlong windowPtr)
+{
+JNF_COCOA_ENTER(env);
+
+    AWTWindow *window = OBJC(windowPtr);
+    if (IS(window.styleBits, MODAL_EXCLUDED)) {
+        return;
+    }
+
+    window.isModallyBlocked = NO;
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [[window standardWindowButton:NSWindowCloseButton] setEnabled: IS(window.styleBits, CLOSEABLE)];
+        [[window standardWindowButton:NSWindowMiniaturizeButton] setEnabled: IS(window.styleBits, MINIMIZABLE)];
+        [[window standardWindowButton:NSWindowZoomButton] setEnabled: IS(window.styleBits, ZOOMABLE)];
+
+        if (IS(window.styleBits, RESIZABLE)) {
+            [window updateMinMaxSize:YES];
+            [window setShowsResizeIndicator:YES];
+        }
+
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+
+