// Author: Vadim Zeitlin, Stefan Csomor
// Modified by:
// Created: 2006-01-12
-// RCS-ID: $Id: evtloop.cpp 54845 2008-07-30 14:52:41Z SC $
+// RCS-ID: $Id$
// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
{
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 );
}
//-----------------------------------------------------------------------------
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()
+{
NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined
location:NSMakePoint(0.0, 0.0)
modifierFlags:0
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 )
{
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;
+ }
}
}