From: Vadim Zeitlin Date: Wed, 28 Jul 2010 18:22:20 +0000 (+0000) Subject: Allow non-modal windows shown from modal dialogs to work in wxOSX. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/40c4350f96527e54bd51e789ccbc79baf4eb9f26?ds=inline Allow non-modal windows shown from modal dialogs to work in wxOSX. 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 --- diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index c08eb11bae..35e7553229 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -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];