changeset 4978:6bf2990ade5d

7124376: [macosx] Modal dialog lost focus Reviewed-by: kizune
author leonidr
date Sat, 05 May 2012 14:17:09 +0400
parents 8888021b9bae
children 996fd01472ee 42162f9c522b
files src/macosx/classes/sun/lwawt/LWWindowPeer.java src/macosx/classes/sun/lwawt/PlatformWindow.java src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java src/macosx/native/sun/awt/AWTView.m src/macosx/native/sun/awt/AWTWindow.h src/macosx/native/sun/awt/AWTWindow.m
diffstat 7 files changed, 69 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/LWWindowPeer.java	Fri May 04 19:33:59 2012 +0400
+++ b/src/macosx/classes/sun/lwawt/LWWindowPeer.java	Sat May 05 14:17:09 2012 +0400
@@ -427,6 +427,8 @@
                 this.blocker = null;
             }
         }
+
+        platformWindow.setModalBlocked(blocked);
     }
 
     @Override
--- a/src/macosx/classes/sun/lwawt/PlatformWindow.java	Fri May 04 19:33:59 2012 +0400
+++ b/src/macosx/classes/sun/lwawt/PlatformWindow.java	Sat May 05 14:17:09 2012 +0400
@@ -108,6 +108,8 @@
     public void flip(int x1, int y1, int x2, int y2,
                      BufferCapabilities.FlipContents flipAction);
 
+    public void setModalBlocked(boolean blocked);
+
     public void toFront();
 
     public void toBack();
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java	Fri May 04 19:33:59 2012 +0400
+++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java	Sat May 05 14:17:09 2012 +0400
@@ -205,4 +205,7 @@
 
     @Override
     public void setWindowState(int windowState) {}
+
+    @Override
+    public void setModalBlocked(boolean blocked) {}
 }
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Fri May 04 19:33:59 2012 +0400
+++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Sat May 05 14:17:09 2012 +0400
@@ -61,6 +61,7 @@
     private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
     private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
     private static native void nativeSetNSWindowSecurityWarningPositioning(long nsWindowPtr, double x, double y, float biasX, float biasY);
+    private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
 
     private static native int nativeGetScreenNSWindowIsOn_AppKitThread(long nsWindowPtr);
 
@@ -797,6 +798,16 @@
         //       value when the native notification comes to us
     }
 
+    @Override
+    public void setModalBlocked(boolean blocked) {
+        if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
+            return;
+        }
+
+        nativeSetEnabled(getNSWindowPtr(), !blocked);
+    }
+
+
     // ----------------------------------------------------------------------
     //                          UTILITY METHODS
     // ----------------------------------------------------------------------
--- a/src/macosx/native/sun/awt/AWTView.m	Fri May 04 19:33:59 2012 +0400
+++ b/src/macosx/native/sun/awt/AWTView.m	Sat May 05 14:17:09 2012 +0400
@@ -298,6 +298,16 @@
  */
 
 -(void) deliverJavaMouseEvent: (NSEvent *) event {
+    BOOL isEnabled = YES;
+    NSWindow* window = [self window];
+    if ([window isKindOfClass: [AWTWindow class]]) {
+        isEnabled = [(AWTWindow*)window isEnabled];
+    }
+
+    if (!isEnabled) {
+        return;
+    }
+
     [AWTToolkit eventCountPlusPlus];
 
     JNIEnv *env = [ThreadUtilities getJNIEnv];
--- a/src/macosx/native/sun/awt/AWTWindow.h	Fri May 04 19:33:59 2012 +0400
+++ b/src/macosx/native/sun/awt/AWTWindow.h	Sat May 05 14:17:09 2012 +0400
@@ -43,6 +43,7 @@
     NSSize javaMinSize;
     NSSize javaMaxSize;
     jint styleBits;
+    BOOL isEnabled;
 }
 
 @property (nonatomic, retain) JNFWeakJObjectWrapper *javaPlatformWindow;
@@ -51,6 +52,7 @@
 @property (nonatomic) NSSize javaMinSize;
 @property (nonatomic) NSSize javaMaxSize;
 @property (nonatomic) jint styleBits;
+@property (nonatomic) BOOL isEnabled;
 
 - (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)javaPlatformWindow
                     styleBits:(jint)styleBits
--- a/src/macosx/native/sun/awt/AWTWindow.m	Fri May 04 19:33:59 2012 +0400
+++ b/src/macosx/native/sun/awt/AWTWindow.m	Sat May 05 14:17:09 2012 +0400
@@ -78,6 +78,7 @@
 @synthesize javaMinSize;
 @synthesize javaMaxSize;
 @synthesize styleBits;
+@synthesize isEnabled;
 
 - (void) updateMinMaxSize:(BOOL)resizable {
     if (resizable) {
@@ -195,6 +196,7 @@
 
     if (self == nil) return nil; // no hope
 
+    self.isEnabled = YES;
     self.javaPlatformWindow = platformWindow;
     self.styleBits = bits;
     [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
@@ -240,16 +242,15 @@
     [super dealloc];
 }
 
-
 // NSWindow overrides
 - (BOOL) canBecomeKeyWindow {
 AWT_ASSERT_APPKIT_THREAD;
-    return IS(self.styleBits, SHOULD_BECOME_KEY);
+    return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_KEY);
 }
 
 - (BOOL) canBecomeMainWindow {
 AWT_ASSERT_APPKIT_THREAD;
-    return IS(self.styleBits, SHOULD_BECOME_MAIN);
+    return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_MAIN);
 }
 
 - (BOOL) worksWhenModal {
@@ -578,6 +579,27 @@
     size->height = MAX(size->height, minHeight);
 }
 
+- (void) setEnabled: (BOOL)flag {
+    self.isEnabled = flag;
+
+    if (IS(self.styleBits, CLOSEABLE)) {
+        [[self standardWindowButton:NSWindowCloseButton] setEnabled: flag];
+    }
+
+    if (IS(self.styleBits, MINIMIZABLE)) {        
+        [[self standardWindowButton:NSWindowMiniaturizeButton] setEnabled: flag];
+    }
+
+    if (IS(self.styleBits, ZOOMABLE)) {
+        [[self standardWindowButton:NSWindowZoomButton] setEnabled: flag];
+    }
+
+    if (IS(self.styleBits, RESIZABLE)) {
+        [self updateMinMaxSize:flag];
+        [self setShowsResizeIndicator:flag];
+    }
+}
+
 @end // AWTWindow
 
 
@@ -1050,3 +1072,17 @@
 
     return underMouse;
 }
+
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetEnabled
+(JNIEnv *env, jclass clazz, jlong windowPtr, jboolean isEnabled)
+{
+JNF_COCOA_ENTER(env);
+
+    AWTWindow *window = OBJC(windowPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [window setEnabled: isEnabled];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+