1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/evtloop.cpp
3 // Purpose: implementation of wxEventLoop for wxMac
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/evtloop.h"
33 #include "wx/osx/private.h"
35 // ============================================================================
36 // wxEventLoop implementation
37 // ============================================================================
39 wxGUIEventLoop::wxGUIEventLoop()
41 m_sleepTime
= kEventDurationNoWait
;
44 void wxGUIEventLoop::WakeUp()
46 extern void wxMacWakeUp();
51 void wxGUIEventLoop::DispatchAndReleaseEvent(EventRef theEvent
)
54 wxTheApp
->MacSetCurrentEvent( theEvent
, NULL
);
56 OSStatus status
= SendEventToEventTarget(theEvent
, GetEventDispatcherTarget());
57 if (status
== eventNotHandledErr
&& wxTheApp
)
58 wxTheApp
->MacHandleUnhandledEvent(theEvent
);
60 ReleaseEvent( theEvent
);
63 bool wxGUIEventLoop::Pending() const
67 return ReceiveNextEvent
69 0, // we want any event at all so we don't specify neither
70 NULL
, // the number of event types nor the types themselves
72 false, // don't remove the event from queue
77 bool wxGUIEventLoop::Dispatch()
82 wxMacAutoreleasePool autoreleasepool
;
86 OSStatus status
= ReceiveNextEvent(0, NULL
, m_sleepTime
, true, &theEvent
) ;
90 case eventLoopTimedOutErr
:
91 if ( wxTheApp
->ProcessIdle() )
92 m_sleepTime
= kEventDurationNoWait
;
95 m_sleepTime
= kEventDurationSecond
;
104 case eventLoopQuitErr
:
105 // according to QA1061 this may also occur
106 // when a WakeUp Process is executed
110 DispatchAndReleaseEvent(theEvent
);
111 m_sleepTime
= kEventDurationNoWait
;
118 int wxGUIEventLoop::DispatchTimeout(unsigned long timeout
)
121 OSStatus status
= ReceiveNextEvent(0, NULL
, timeout
/1000, true, &event
);
125 wxFAIL_MSG( "unexpected ReceiveNextEvent() error" );
128 case eventLoopTimedOutErr
:
131 case eventLoopQuitErr
:
135 DispatchAndReleaseEvent(event
);