///////////////////////////////////////////////////////////////////////////////
-// Name: src/mac/carbon/evtloop.cpp
+// Name: src/osx/carbon/evtloop.cpp
// Purpose: implementation of wxEventLoop for wxMac
// Author: Vadim Zeitlin
// Modified by:
#include "wx/app.h"
#endif // WX_PRECOMP
-#ifdef __DARWIN__
- #include <Carbon/Carbon.h>
-#else
- #include <Carbon.h>
-#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();
wxMacWakeUp();
}
-#endif // high/low-level event loop
-
-// ----------------------------------------------------------------------------
-// low level functions used in both cases
-// ----------------------------------------------------------------------------
-
bool wxGUIEventLoop::Pending() const
{
EventRef theEvent;
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:
+ 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;
}