]> git.saurik.com Git - wxWidgets.git/commitdiff
Allow non-modal windows shown from modal dialogs to work in wxOSX.
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 28 Jul 2010 18:22:20 +0000 (18:22 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 28 Jul 2010 18:22:20 +0000 (18:22 +0000)
Use kCGUtilityWindowLevel for such windows instead of kCGFloatingWindowLevel
and also call setWorksWhenModal:YES.

Closes #12187.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65130 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/osx/cocoa/nonownedwnd.mm

index c08eb11bae07fb72e04a3a1594a1e763e86d9829..35e755322965b1080d4b9b1e0a3d378192df575c 100644 (file)
@@ -14,6 +14,7 @@
     #include "wx/nonownedwnd.h"
     #include "wx/frame.h"
     #include "wx/app.h"
+    #include "wx/dialog.h"
 #endif
 
 #include "wx/osx/private.h"
@@ -408,7 +409,7 @@ void wxNonOwnedWindowCocoaImpl::WillBeDestroyed()
     }
 }
 
-void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), const wxPoint& pos, const wxSize& size,
+void wxNonOwnedWindowCocoaImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
 long style, long extraStyle, const wxString& WXUNUSED(name) )
 {
     static wxNonOwnedWindowController* controller = NULL;
@@ -516,6 +517,29 @@ long style, long extraStyle, const wxString& WXUNUSED(name) )
         defer:NO
         ];
 
+    // If the parent is modal, windows with wxFRAME_FLOAT_ON_PARENT style need
+    // to be in kCGUtilityWindowLevel and not kCGFloatingWindowLevel to stay
+    // above the parent.
+    wxDialog * const parentDialog = wxDynamicCast(parent, wxDialog);
+    if (parentDialog && parentDialog->IsModal())
+    {
+        if (level == kCGFloatingWindowLevel)
+        {
+            level = kCGUtilityWindowLevel;
+        }
+
+        // Cocoa's modal loop does not process other windows by default, but
+        // don't call this on normal window levels so nested modal dialogs will
+        // still behave modally.
+        if (level != kCGNormalWindowLevel)
+        {
+            if ([m_macWindow isKindOfClass:[NSPanel class]])
+            {
+                [(NSPanel*)m_macWindow setWorksWhenModal:YES];
+            }
+        }
+    }
+
     [m_macWindow setLevel:level];
 
     [m_macWindow setDelegate:controller];