+
+void wxGUIEventLoop::EndModalSession()
+{
+ wxASSERT_MSG(m_modalSession != NULL, "no modal session active");
+
+ wxASSERT_MSG(m_modalNestedLevel > 0, "incorrect modal nesting level");
+
+ if ( --m_modalNestedLevel == 0 )
+ {
+ [NSApp endModalSession:(NSModalSession)m_modalSession];
+ m_modalSession = nil;
+ if ( m_dummyWindow )
+ {
+ [m_dummyWindow release];
+ m_dummyWindow = nil;
+ }
+ }
+}
+
+//
+//
+//
+
+wxWindowDisabler::wxWindowDisabler(bool disable)
+{
+ m_modalEventLoop = NULL;
+ m_disabled = disable;
+ if ( disable )
+ DoDisable();
+}
+
+wxWindowDisabler::wxWindowDisabler(wxWindow *winToSkip)
+{
+ m_disabled = true;
+ DoDisable(winToSkip);
+}
+
+void wxWindowDisabler::DoDisable(wxWindow *winToSkip)
+{
+ // remember the top level windows which were already disabled, so that we
+ // don't reenable them later
+ m_winDisabled = NULL;
+
+ wxWindowList::compatibility_iterator node;
+ for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() )
+ {
+ wxWindow *winTop = node->GetData();
+ if ( winTop == winToSkip )
+ continue;
+
+ // we don't need to disable the hidden or already disabled windows
+ if ( winTop->IsEnabled() && winTop->IsShown() )
+ {
+ winTop->Disable();
+ }
+ else
+ {
+ if ( !m_winDisabled )
+ {
+ m_winDisabled = new wxWindowList;
+ }
+
+ m_winDisabled->Append(winTop);
+ }
+ }
+
+ m_modalEventLoop = (wxEventLoop*)wxEventLoopBase::GetActive();
+ if (m_modalEventLoop)
+ m_modalEventLoop->BeginModalSession(winToSkip);
+}
+
+wxWindowDisabler::~wxWindowDisabler()
+{
+ if ( !m_disabled )
+ return;
+
+ if (m_modalEventLoop)
+ m_modalEventLoop->EndModalSession();
+
+ wxWindowList::compatibility_iterator node;
+ for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() )
+ {
+ wxWindow *winTop = node->GetData();
+ if ( !m_winDisabled || !m_winDisabled->Find(winTop) )
+ {
+ winTop->Enable();
+ }
+ //else: had been already disabled, don't reenable
+ }
+
+ delete m_winDisabled;
+}
\ No newline at end of file