+}
+
+static void DispatchAndReleaseEvent(EventRef theEvent)
+{
+ if ( wxTheApp )
+ wxTheApp->MacSetCurrentEvent( theEvent, NULL );
+
+ OSStatus status = SendEventToEventTarget(theEvent, GetEventDispatcherTarget());
+ if (status == eventNotHandledErr && wxTheApp)
+ wxTheApp->MacHandleUnhandledEvent(theEvent);
+
+ ReleaseEvent( theEvent );
+}
+
+int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout)
+{
+ wxMacAutoreleasePool autoreleasepool;
+
+ EventRef event;
+ OSStatus status = ReceiveNextEvent(0, NULL, timeout/1000, true, &event);
+ switch ( status )
+ {
+ default:
+ wxFAIL_MSG( "unexpected ReceiveNextEvent() error" );
+ // fall through
+
+ case eventLoopTimedOutErr:
+ return -1;
+
+ case eventLoopQuitErr:
+ // according to QA1061 this may also occur
+ // when a WakeUp Process is executed
+ return 0;
+
+ case noErr:
+ DispatchAndReleaseEvent(event);
+ return 1;
+ }