+ wxMacAutoreleasePool autoreleasepool;
+
+ if ( m_modalSession )
+ {
+ NSInteger response = [NSApp runModalSession:(NSModalSession)m_modalSession];
+
+ switch (response)
+ {
+ case NSRunContinuesResponse:
+ {
+ if ( [[NSApplication sharedApplication]
+ nextEventMatchingMask: NSAnyEventMask
+ untilDate: nil
+ inMode: NSDefaultRunLoopMode
+ dequeue: NO] != nil )
+ return 1;
+
+ return -1;
+ }
+
+ case NSRunStoppedResponse:
+ case NSRunAbortedResponse:
+ return -1;
+ default:
+ wxFAIL_MSG("unknown response code");
+ break;
+ }
+ return -1;
+ }
+ else
+ {
+ NSEvent *event = [NSApp
+ nextEventMatchingMask:NSAnyEventMask
+ untilDate:[NSDate dateWithTimeIntervalSinceNow: timeout/1000]
+ inMode:NSDefaultRunLoopMode
+ dequeue: YES];
+
+ if ( event == nil )
+ return -1;
+
+ [NSApp sendEvent: event];
+
+ 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