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
);
140 bool wxGUIEventLoop::YieldFor(long eventsToProcess
)
143 // Yielding from a non-gui thread needs to bail out, otherwise we end up
144 // possibly sending events in the thread too.
145 if ( !wxThread::IsMain() )
149 #endif // wxUSE_THREADS
151 m_isInsideYield
= true;
152 m_eventsToProcessInsideYield
= eventsToProcess
;
155 // disable log flushing from here because a call to wxYield() shouldn't
156 // normally result in message boxes popping up &c
160 // process all pending events:
164 // it's necessary to call ProcessIdle() to update the frames sizes which
165 // might have been changed (it also will update other things set from
166 // OnUpdateUI() which is a nice (and desired) side effect)
167 while ( ProcessIdle() ) {}
172 m_isInsideYield
= false;