From 0aff141c5114ae93c373a3ab350dcff69d05591c Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Mon, 6 Jun 2011 16:32:41 +0000 Subject: [PATCH] supporting nested window disablers on the same window git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67866 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/cocoa/evtloop.h | 5 +++++ src/osx/cocoa/evtloop.mm | 29 ++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/include/wx/osx/cocoa/evtloop.h b/include/wx/osx/cocoa/evtloop.h index c8b5d9e666..e38cf92c38 100644 --- a/include/wx/osx/cocoa/evtloop.h +++ b/include/wx/osx/cocoa/evtloop.h @@ -31,7 +31,12 @@ protected: virtual CFRunLoopRef CFGetCurrentRunLoop() const; void* m_modalSession; + + wxWindow* m_modalWindow; + WXWindow m_dummyWindow; + + int m_modalNestedLevel; }; #endif // _WX_OSX_COCOA_EVTLOOP_H_ diff --git a/src/osx/cocoa/evtloop.mm b/src/osx/cocoa/evtloop.mm index c9ac5ee75d..4814425583 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 ); } //----------------------------------------------------------------------------- @@ -308,6 +311,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 ) { @@ -339,12 +352,18 @@ void wxGUIEventLoop::BeginModalSession( wxWindow* modalWindow ) 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; + } } } -- 2.45.2