X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/489468feaa08b8f504735eecca522fb8d0f825d2..55410bb4f67febe1ca20654f078ea4fb9a6223ae:/src/osx/carbon/evtloop.cpp diff --git a/src/osx/carbon/evtloop.cpp b/src/osx/carbon/evtloop.cpp index 681564bffa..4278ced196 100644 --- a/src/osx/carbon/evtloop.cpp +++ b/src/osx/carbon/evtloop.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/evtloop.cpp +// Name: src/osx/carbon/evtloop.cpp // Purpose: implementation of wxEventLoop for wxMac // Author: Vadim Zeitlin // Modified by: @@ -28,47 +28,20 @@ #ifndef WX_PRECOMP #include "wx/app.h" + #include "wx/log.h" #endif // WX_PRECOMP -#ifdef __DARWIN__ - #include -#else - #include -#endif +#include "wx/osx/private.h" + // ============================================================================ // wxEventLoop implementation // ============================================================================ -// ---------------------------------------------------------------------------- -// high level functions for RunApplicationEventLoop() case -// ---------------------------------------------------------------------------- - -#if wxMAC_USE_RUN_APP_EVENT_LOOP - -int wxGUIEventLoop::Run() +wxGUIEventLoop::wxGUIEventLoop() { - wxEventLoopActivator activate(this); - - RunApplicationEventLoop(); - - return m_exitcode; + m_sleepTime = kEventDurationNoWait; } -void wxGUIEventLoop::Exit(int rc) -{ - m_exitcode = rc; - - QuitApplicationEventLoop(); - - OnExit(); -} - -#else // manual event loop - -// ---------------------------------------------------------------------------- -// functions only used by wxEventLoopManual-based implementation -// ---------------------------------------------------------------------------- - void wxGUIEventLoop::WakeUp() { extern void wxMacWakeUp(); @@ -76,11 +49,17 @@ void wxGUIEventLoop::WakeUp() wxMacWakeUp(); } -#endif // high/low-level event loop +void wxGUIEventLoop::DispatchAndReleaseEvent(EventRef theEvent) +{ + if ( wxTheApp ) + wxTheApp->MacSetCurrentEvent( theEvent, NULL ); -// ---------------------------------------------------------------------------- -// low level functions used in both cases -// ---------------------------------------------------------------------------- + OSStatus status = SendEventToEventTarget(theEvent, GetEventDispatcherTarget()); + if (status == eventNotHandledErr && wxTheApp) + wxTheApp->MacHandleUnhandledEvent(theEvent); + + ReleaseEvent( theEvent ); +} bool wxGUIEventLoop::Pending() const { @@ -98,12 +77,100 @@ bool wxGUIEventLoop::Pending() const bool wxGUIEventLoop::Dispatch() { - // TODO: we probably should do the dispatching directly from here but for - // now it's easier to forward to wxApp which has all the code to do - // it if ( !wxTheApp ) return false; - wxTheApp->MacDoOneEvent(); + wxMacAutoreleasePool autoreleasepool; + + EventRef theEvent; + + OSStatus status = ReceiveNextEvent(0, NULL, m_sleepTime, true, &theEvent) ; + + switch (status) + { + case eventLoopTimedOutErr : + if ( wxTheApp->ProcessIdle() ) + m_sleepTime = kEventDurationNoWait ; + else + { + m_sleepTime = kEventDurationSecond; +#if wxUSE_THREADS + wxMutexGuiLeave(); + wxMilliSleep(20); + wxMutexGuiEnter(); +#endif + } + break; + + case eventLoopQuitErr : + // according to QA1061 this may also occur + // when a WakeUp Process is executed + break; + + default: + 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; }