+void wxGUIEventLoop::BeginModalSession( wxWindow* modalWindow )
+{
+ WXWindow nsnow = nil;
+
+ if ( modalWindow )
+ {
+ // we must show now, otherwise beginModalSessionForWindow does it but it
+ // also would do a centering of the window before overriding all our position
+ if ( !modalWindow->IsShownOnScreen() )
+ modalWindow->Show();
+
+ wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (modalWindow);
+ wxASSERT_MSG( now != NULL, "must pass in a toplevel window for modal event loop" );
+ nsnow = now ? now->GetWXWindow() : nil;
+ }
+ else
+ {
+ NSRect r = NSMakeRect(10, 10, 0, 0);
+ nsnow = [NSPanel alloc];
+ [nsnow initWithContentRect:r
+ styleMask:NSBorderlessWindowMask
+ backing:NSBackingStoreBuffered
+ defer:YES
+ ];
+ [nsnow orderOut:nil];
+ m_dummyWindow = nsnow;
+ }
+ m_modalSession = [NSApp beginModalSessionForWindow:nsnow];
+}
+
+void wxGUIEventLoop::EndModalSession()
+{
+ wxASSERT_MSG(m_modalSession != NULL, "no modal session active");
+ [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();
+ m_modalEventLoop->BeginModalSession(winToSkip);