X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a9a4f2295344414e2ee4e3ec27fa5292918dff27..60372b0d54379701d62edf5595a7dc25c48330e1:/src/osx/cocoa/evtloop.mm diff --git a/src/osx/cocoa/evtloop.mm b/src/osx/cocoa/evtloop.mm index 91df515ef9..3a8568b33d 100644 --- a/src/osx/cocoa/evtloop.mm +++ b/src/osx/cocoa/evtloop.mm @@ -107,12 +107,15 @@ wxGUIEventLoop::wxGUIEventLoop() { m_modalSession = nil; m_dummyWindow = nil; + m_modalNestedLevel = 0; + m_modalWindow = NULL; } wxGUIEventLoop::~wxGUIEventLoop() { wxASSERT( m_modalSession == nil ); wxASSERT( m_dummyWindow == nil ); + wxASSERT( m_modalNestedLevel == 0 ); } //----------------------------------------------------------------------------- @@ -243,9 +246,15 @@ void wxGUIEventLoop::DoRun() void wxGUIEventLoop::DoStop() { - [NSApp stop:0]; // only calling stop: is not enough when called from a runloop-observer, // therefore add a dummy event, to make sure the runloop gets another round + [NSApp stop:0]; + WakeUp(); +} + +void wxGUIEventLoop::WakeUp() +{ + wxMacAutoreleasePool autoreleasepool; NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined location:NSMakePoint(0.0, 0.0) modifierFlags:0 @@ -308,6 +317,16 @@ void wxModalEventLoop::DoStop() void wxGUIEventLoop::BeginModalSession( wxWindow* modalWindow ) { WXWindow nsnow = nil; + + if ( m_modalNestedLevel > 0 ) + { + wxASSERT_MSG( m_modalWindow == modalWindow, "Nested Modal Sessions must be based on same window"); + m_modalNestedLevel++; + return; + } + + m_modalWindow = modalWindow; + m_modalNestedLevel = 1; if ( modalWindow ) { @@ -333,17 +352,24 @@ void wxGUIEventLoop::BeginModalSession( wxWindow* modalWindow ) m_dummyWindow = nsnow; } m_modalSession = [NSApp beginModalSessionForWindow:nsnow]; + wxASSERT_MSG(m_modalSession != NULL, "modal session couldn't be started"); } void wxGUIEventLoop::EndModalSession() { wxASSERT_MSG(m_modalSession != NULL, "no modal session active"); - [NSApp endModalSession:(NSModalSession)m_modalSession]; - m_modalSession = nil; - if ( m_dummyWindow ) + + wxASSERT_MSG(m_modalNestedLevel > 0, "incorrect modal nesting level"); + + if ( --m_modalNestedLevel == 0 ) { - [m_dummyWindow release]; - m_dummyWindow = nil; + [NSApp endModalSession:(NSModalSession)m_modalSession]; + m_modalSession = nil; + if ( m_dummyWindow ) + { + [m_dummyWindow release]; + m_dummyWindow = nil; + } } } @@ -395,7 +421,8 @@ void wxWindowDisabler::DoDisable(wxWindow *winToSkip) } m_modalEventLoop = (wxEventLoop*)wxEventLoopBase::GetActive(); - m_modalEventLoop->BeginModalSession(winToSkip); + if (m_modalEventLoop) + m_modalEventLoop->BeginModalSession(winToSkip); } wxWindowDisabler::~wxWindowDisabler() @@ -403,7 +430,8 @@ wxWindowDisabler::~wxWindowDisabler() if ( !m_disabled ) return; - m_modalEventLoop->EndModalSession(); + if (m_modalEventLoop) + m_modalEventLoop->EndModalSession(); wxWindowList::compatibility_iterator node; for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() )