From cfab2206da1885f1b6b364408c68076600951dfd Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sun, 26 Aug 2018 16:52:40 +0200 Subject: [PATCH] Supporting deeper nesting levels of modal dialogs on macOS In order to make sure a parent NSPanel cannot be activated, turn off its worksWhenModal flag while the child has its turn see #18204 --- src/osx/cocoa/evtloop.mm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/osx/cocoa/evtloop.mm b/src/osx/cocoa/evtloop.mm index 976a973507..5c7b86c471 100644 --- a/src/osx/cocoa/evtloop.mm +++ b/src/osx/cocoa/evtloop.mm @@ -435,9 +435,26 @@ void wxModalEventLoop::OSXDoRun() #if OSX_USE_MODAL_SESSION if ( m_modalWindow ) { + bool restoreWorksWhenModal = false; + wxDialog* const parentDialog = wxDynamicCast(wxGetTopLevelParent(m_modalWindow->GetParent()), wxDialog); + NSWindow* parentWindow = parentDialog && parentDialog->IsModal() ? parentDialog->GetWXWindow() : nil; + if ( parentWindow != nil ) + { + if ( [parentWindow isKindOfClass:[NSPanel class]] && [(NSPanel*)parentWindow worksWhenModal] == YES ) + { + [(NSPanel*)parentWindow setWorksWhenModal:NO]; + restoreWorksWhenModal = true; + } + } + BeginModalSession(m_modalWindow); wxCFEventLoop::OSXDoRun(); EndModalSession(); + + if ( restoreWorksWhenModal ) + { + [(NSPanel*)parentWindow setWorksWhenModal:YES]; + } } else #endif