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 CFRunLoopRef
wxGUIEventLoop::CFGetCurrentRunLoop() const
54 return CFRunLoopGetCurrent();
57 void wxGUIEventLoop::DispatchAndReleaseEvent(EventRef theEvent
)
60 wxTheApp
->MacSetCurrentEvent( theEvent
, NULL
);
62 OSStatus status
= SendEventToEventTarget(theEvent
, GetEventDispatcherTarget());
63 if (status
== eventNotHandledErr
&& wxTheApp
)
64 wxTheApp
->MacHandleUnhandledEvent(theEvent
);
66 ReleaseEvent( theEvent
);
69 bool wxGUIEventLoop::Pending() const
73 return ReceiveNextEvent
75 0, // we want any event at all so we don't specify neither
76 NULL
, // the number of event types nor the types themselves
78 false, // don't remove the event from queue
83 bool wxGUIEventLoop::Dispatch()
88 wxMacAutoreleasePool autoreleasepool
;
92 OSStatus status
= ReceiveNextEvent(0, NULL
, m_sleepTime
, true, &theEvent
) ;
96 case eventLoopTimedOutErr
:
97 // process pending wx events before sending idle events
98 wxTheApp
->ProcessPendingEvents();
99 if ( wxTheApp
->ProcessIdle() )
100 m_sleepTime
= kEventDurationNoWait
;
103 m_sleepTime
= kEventDurationSecond
;
112 case eventLoopQuitErr
:
113 // according to QA1061 this may also occur
114 // when a WakeUp Process is executed
118 DispatchAndReleaseEvent(theEvent
);
119 m_sleepTime
= kEventDurationNoWait
;
126 int wxGUIEventLoop::DispatchTimeout(unsigned long timeout
)
129 OSStatus status
= ReceiveNextEvent(0, NULL
, timeout
/1000, true, &event
);
133 wxFAIL_MSG( "unexpected ReceiveNextEvent() error" );
136 case eventLoopTimedOutErr
:
139 case eventLoopQuitErr
:
143 DispatchAndReleaseEvent(event
);
148 bool wxGUIEventLoop::YieldFor(long eventsToProcess
)
151 // Yielding from a non-gui thread needs to bail out, otherwise we end up
152 // possibly sending events in the thread too.
153 if ( !wxThread::IsMain() )
157 #endif // wxUSE_THREADS
159 m_isInsideYield
= true;
160 m_eventsToProcessInsideYield
= eventsToProcess
;
163 // disable log flushing from here because a call to wxYield() shouldn't
164 // normally result in message boxes popping up &c
168 // process all pending events:
172 // it's necessary to call ProcessIdle() to update the frames sizes which
173 // might have been changed (it also will update other things set from
174 // OnUpdateUI() which is a nice (and desired) side effect)
175 while ( ProcessIdle() ) {}
177 // if there are pending events, we must process them.
179 wxTheApp
->ProcessPendingEvents();
184 m_isInsideYield
= false;