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"
34 #include "wx/osx/private.h"
36 // ============================================================================
37 // wxEventLoop implementation
38 // ============================================================================
40 wxGUIEventLoop::wxGUIEventLoop()
42 m_sleepTime
= kEventDurationNoWait
;
45 void wxGUIEventLoop::WakeUp()
47 extern void wxMacWakeUp();
52 void wxGUIEventLoop::DispatchAndReleaseEvent(EventRef theEvent
)
55 wxTheApp
->MacSetCurrentEvent( theEvent
, NULL
);
57 OSStatus status
= SendEventToEventTarget(theEvent
, GetEventDispatcherTarget());
58 if (status
== eventNotHandledErr
&& wxTheApp
)
59 wxTheApp
->MacHandleUnhandledEvent(theEvent
);
61 ReleaseEvent( theEvent
);
64 bool wxGUIEventLoop::Pending() const
68 return ReceiveNextEvent
70 0, // we want any event at all so we don't specify neither
71 NULL
, // the number of event types nor the types themselves
73 false, // don't remove the event from queue
78 bool wxGUIEventLoop::Dispatch()
83 wxMacAutoreleasePool autoreleasepool
;
87 OSStatus status
= ReceiveNextEvent(0, NULL
, m_sleepTime
, true, &theEvent
) ;
91 case eventLoopTimedOutErr
:
92 if ( wxTheApp
->ProcessIdle() )
93 m_sleepTime
= kEventDurationNoWait
;
96 m_sleepTime
= kEventDurationSecond
;
105 case eventLoopQuitErr
:
106 // according to QA1061 this may also occur
107 // when a WakeUp Process is executed
111 DispatchAndReleaseEvent(theEvent
);
112 m_sleepTime
= kEventDurationNoWait
;
119 int wxGUIEventLoop::DispatchTimeout(unsigned long timeout
)
122 OSStatus status
= ReceiveNextEvent(0, NULL
, timeout
/1000, true, &event
);
126 wxFAIL_MSG( "unexpected ReceiveNextEvent() error" );
129 case eventLoopTimedOutErr
:
132 case eventLoopQuitErr
:
136 DispatchAndReleaseEvent(event
);
141 bool wxGUIEventLoop::YieldFor(long eventsToProcess
)
144 // Yielding from a non-gui thread needs to bail out, otherwise we end up
145 // possibly sending events in the thread too.
146 if ( !wxThread::IsMain() )
150 #endif // wxUSE_THREADS
152 m_isInsideYield
= true;
153 m_eventsToProcessInsideYield
= eventsToProcess
;
156 // disable log flushing from here because a call to wxYield() shouldn't
157 // normally result in message boxes popping up &c
161 // process all pending events:
165 // it's necessary to call ProcessIdle() to update the frames sizes which
166 // might have been changed (it also will update other things set from
167 // OnUpdateUI() which is a nice (and desired) side effect)
168 while ( ProcessIdle() ) {}
173 m_isInsideYield
= false;