--- old/src/macosx/native/sun/awt/AWTWindow.m 2013-03-28 18:52:29.000000000 +0400 +++ new/src/macosx/native/sun/awt/AWTWindow.m 2013-03-28 18:52:29.000000000 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -50,6 +50,7 @@ BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY) static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow"); +static JNF_CLASS_CACHE(jc_Dialog, "java/awt/Dialog"); // Cocoa windowDidBecomeKey/windowDidResignKey notifications // doesn't provide information about "opposite" window, so we @@ -536,8 +537,37 @@ - (void) windowDidBecomeKey: (NSNotification *) notification { AWT_ASSERT_APPKIT_THREAD; [AWTToolkit eventCountPlusPlus]; - [CMenuBar activate:self.javaMenuBar modallyDisabled:NO]; + AWTWindow *opposite = [AWTWindow lastKeyWindow]; + + // check if the current window is a Dialog + // if so, check if it's modal + JNIEnv *env = [ThreadUtilities getJNIEnv]; + jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; + if (platformWindow != NULL) { + static JNF_MEMBER_CACHE(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;"); + static JNF_MEMBER_CACHE(jm_isModal, jc_Dialog, "isModal", "()Z"); + jobject awtWindow = JNFGetObjectField(env, platformWindow, jf_target); + if (awtWindow != NULL) { + if (JNFIsInstanceOf(env, awtWindow, &jc_Dialog)) { + if (self.javaMenuBar != NULL) { + [CMenuBar activate:self.javaMenuBar modallyDisabled:NO]; + } else { + if (JNFCallBooleanMethod(env, awtWindow, jm_isModal) == JNI_TRUE) { + [CMenuBar activate:opposite->javaMenuBar modallyDisabled:YES]; + } + } + } else { + [CMenuBar activate:self.javaMenuBar modallyDisabled:NO]; + } + (*env)->DeleteLocalRef(env, awtWindow); + } + (*env)->DeleteLocalRef(env, platformWindow); + } else { + // fallback if something's gone wrong with JNF + [CMenuBar activate:self.javaMenuBar modallyDisabled:NO]; + } + [AWTWindow setLastKeyWindow:nil]; [self _deliverWindowFocusEvent:YES oppositeWindow: opposite];