X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/524c47aa3adf2af11a3069fd5da035a604f08f66..b90817de2b4543762b308f15f7010a19e941991e:/src/osx/carbon/evtloop.cpp?ds=sidebyside diff --git a/src/osx/carbon/evtloop.cpp b/src/osx/carbon/evtloop.cpp index ec51ee972b..4278ced196 100644 --- a/src/osx/carbon/evtloop.cpp +++ b/src/osx/carbon/evtloop.cpp @@ -28,6 +28,7 @@ #ifndef WX_PRECOMP #include "wx/app.h" + #include "wx/log.h" #endif // WX_PRECOMP #include "wx/osx/private.h" @@ -48,6 +49,18 @@ void wxGUIEventLoop::WakeUp() wxMacWakeUp(); } +void wxGUIEventLoop::DispatchAndReleaseEvent(EventRef theEvent) +{ + if ( wxTheApp ) + wxTheApp->MacSetCurrentEvent( theEvent, NULL ); + + OSStatus status = SendEventToEventTarget(theEvent, GetEventDispatcherTarget()); + if (status == eventNotHandledErr && wxTheApp) + wxTheApp->MacHandleUnhandledEvent(theEvent); + + ReleaseEvent( theEvent ); +} + bool wxGUIEventLoop::Pending() const { EventRef theEvent; @@ -95,17 +108,69 @@ bool wxGUIEventLoop::Dispatch() break; default: - if ( wxTheApp ) - wxTheApp->MacSetCurrentEvent( theEvent, NULL ); - - OSStatus status = SendEventToEventTarget(theEvent, GetEventDispatcherTarget()); - if (status == eventNotHandledErr && wxTheApp) - wxTheApp->MacHandleUnhandledEvent(theEvent); - - ReleaseEvent( theEvent ); + DispatchAndReleaseEvent(theEvent); m_sleepTime = kEventDurationNoWait ; break; } return true; } + +int wxGUIEventLoop::DispatchTimeout(unsigned long timeout) +{ + 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: + return 0; + + case noErr: + DispatchAndReleaseEvent(event); + return 1; + } +} + +bool wxGUIEventLoop::YieldFor(long eventsToProcess) +{ +#if wxUSE_THREADS + // Yielding from a non-gui thread needs to bail out, otherwise we end up + // possibly sending events in the thread too. + if ( !wxThread::IsMain() ) + { + return true; + } +#endif // wxUSE_THREADS + + m_isInsideYield = true; + m_eventsToProcessInsideYield = eventsToProcess; + +#if wxUSE_LOG + // disable log flushing from here because a call to wxYield() shouldn't + // normally result in message boxes popping up &c + wxLog::Suspend(); +#endif // wxUSE_LOG + + // process all pending events: + while ( Pending() ) + Dispatch(); + + // it's necessary to call ProcessIdle() to update the frames sizes which + // might have been changed (it also will update other things set from + // OnUpdateUI() which is a nice (and desired) side effect) + while ( ProcessIdle() ) {} + +#if wxUSE_LOG + wxLog::Resume(); +#endif // wxUSE_LOG + m_isInsideYield = false; + + return true; +}