+ return 1;
+ }
+}
+
+void wxGUIEventLoop::DoRun()
+{
+ wxMacAutoreleasePool autoreleasepool;
+ [NSApp run];
+}
+
+void wxGUIEventLoop::DoStop()
+{
+ // 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* cevent = [NSApp currentEvent];
+ // NSString* mode = [[NSRunLoop mainRunLoop] currentMode];
+
+ // when already in a mouse event handler, don't add higher level event
+ // if ( cevent != nil && [cevent type] <= NSMouseMoved && )
+ if ( m_osxLowLevelWakeUp /* [NSEventTrackingRunLoopMode isEqualToString:mode] */ )
+ {
+ // NSLog(@"event for wakeup %@ in mode %@",cevent,mode);
+ wxCFEventLoop::WakeUp();
+ }
+ else
+ {
+ wxMacAutoreleasePool autoreleasepool;
+ NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined
+ location:NSMakePoint(0.0, 0.0)
+ modifierFlags:0
+ timestamp:0
+ windowNumber:0
+ context:nil
+ subtype:0 data1:0 data2:0];
+ [NSApp postEvent:event atStart:FALSE];
+ }
+}
+
+CFRunLoopRef wxGUIEventLoop::CFGetCurrentRunLoop() const
+{
+ NSRunLoop* nsloop = [NSRunLoop currentRunLoop];
+ return [nsloop getCFRunLoop];
+}
+
+
+// TODO move into a evtloop_osx.cpp
+
+wxModalEventLoop::wxModalEventLoop(wxWindow *modalWindow)
+{
+ m_modalWindow = dynamic_cast<wxNonOwnedWindow*> (modalWindow);
+ wxASSERT_MSG( m_modalWindow != NULL, "must pass in a toplevel window for modal event loop" );
+ m_modalNativeWindow = m_modalWindow->GetWXWindow();
+}
+
+wxModalEventLoop::wxModalEventLoop(WXWindow modalNativeWindow)
+{
+ m_modalWindow = NULL;
+ wxASSERT_MSG( modalNativeWindow != NULL, "must pass in a toplevel window for modal event loop" );
+ m_modalNativeWindow = modalNativeWindow;
+}
+
+// END move into a evtloop_osx.cpp
+
+void wxModalEventLoop::DoRun()
+{
+ wxMacAutoreleasePool pool;
+
+ // If the app hasn't started, flush the event queue
+ // If we don't do this, the Dock doesn't get the message that
+ // the app has started so will refuse to activate it.
+ [NSApplication sharedApplication];
+ if (![NSApp isRunning])
+ {
+ while(NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES])
+ {
+ [NSApp sendEvent:event];
+ }
+ }
+
+ [NSApp runModalForWindow:m_modalNativeWindow];
+}
+
+void wxModalEventLoop::DoStop()
+{
+ [NSApp abortModal];
+}
+
+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 )
+ {
+ // 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];
+ wxASSERT_MSG(m_modalSession != NULL, "modal session couldn't be started");