X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/292e5e1f17af67a5885f1fdaa8c45a8a5a2a3ca5..472137baebae6c011ad7d70285de454b9ce7796d:/src/osx/carbon/evtloop.cpp diff --git a/src/osx/carbon/evtloop.cpp b/src/osx/carbon/evtloop.cpp index 48fcf2f110..ec51ee972b 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: @@ -30,47 +30,17 @@ #include "wx/app.h" #endif // WX_PRECOMP -#if wxOSX_USE_CARBON - #include -#else - #include -#endif +#include "wx/osx/private.h" + // ============================================================================ // wxEventLoop implementation // ============================================================================ -// ---------------------------------------------------------------------------- -// high level functions for RunApplicationEventLoop() case -// ---------------------------------------------------------------------------- - - - -#if wxOSX_USE_RUN_APP_EVENT_LOOP - -int wxGUIEventLoop::Run() +wxGUIEventLoop::wxGUIEventLoop() { - wxEventLoopActivator activate(this); - - RunApplicationEventLoop(); - - return m_exitcode; -} - -void wxGUIEventLoop::Exit(int rc) -{ - m_exitcode = rc; - - QuitApplicationEventLoop(); - - OnExit(); + m_sleepTime = kEventDurationNoWait; } -#else // manual event loop - -// ---------------------------------------------------------------------------- -// functions only used by wxEventLoopManual-based implementation -// ---------------------------------------------------------------------------- - void wxGUIEventLoop::WakeUp() { extern void wxMacWakeUp(); @@ -78,15 +48,8 @@ void wxGUIEventLoop::WakeUp() wxMacWakeUp(); } -#endif // high/low-level event loop - -// ---------------------------------------------------------------------------- -// low level functions used in both cases -// ---------------------------------------------------------------------------- - bool wxGUIEventLoop::Pending() const { -#if wxOSX_USE_CARBON EventRef theEvent; return ReceiveNextEvent @@ -97,9 +60,6 @@ bool wxGUIEventLoop::Pending() const false, // don't remove the event from queue &theEvent ) == noErr; -#else - return true; // TODO -#endif } bool wxGUIEventLoop::Dispatch() @@ -107,13 +67,45 @@ bool wxGUIEventLoop::Dispatch() if ( !wxTheApp ) return false; -#if wxOSX_USE_CARBON - // 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 - wxTheApp->MacDoOneEvent(); -#else - CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, 0); + 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: + if ( wxTheApp ) + wxTheApp->MacSetCurrentEvent( theEvent, NULL ); + + OSStatus status = SendEventToEventTarget(theEvent, GetEventDispatcherTarget()); + if (status == eventNotHandledErr && wxTheApp) + wxTheApp->MacHandleUnhandledEvent(theEvent); + + ReleaseEvent( theEvent ); + m_sleepTime = kEventDurationNoWait ; + break; + } + return true; }