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 // process pending wx events before sending idle events
93 wxTheApp
->ProcessPendingEvents();
94 if ( wxTheApp
->ProcessIdle() )
95 m_sleepTime
= kEventDurationNoWait
;
98 m_sleepTime
= kEventDurationSecond
;
107 case eventLoopQuitErr
:
108 // according to QA1061 this may also occur
109 // when a WakeUp Process is executed
113 DispatchAndReleaseEvent(theEvent
);
114 m_sleepTime
= kEventDurationNoWait
;
121 int wxGUIEventLoop::DispatchTimeout(unsigned long timeout
)
124 OSStatus status
= ReceiveNextEvent(0, NULL
, timeout
/1000, true, &event
);
128 wxFAIL_MSG( "unexpected ReceiveNextEvent() error" );
131 case eventLoopTimedOutErr
:
134 case eventLoopQuitErr
:
138 DispatchAndReleaseEvent(event
);
143 bool wxGUIEventLoop::YieldFor(long eventsToProcess
)
146 // Yielding from a non-gui thread needs to bail out, otherwise we end up
147 // possibly sending events in the thread too.
148 if ( !wxThread::IsMain() )
152 #endif // wxUSE_THREADS
154 m_isInsideYield
= true;
155 m_eventsToProcessInsideYield
= eventsToProcess
;
158 // disable log flushing from here because a call to wxYield() shouldn't
159 // normally result in message boxes popping up &c
163 // process all pending events:
167 // it's necessary to call ProcessIdle() to update the frames sizes which
168 // might have been changed (it also will update other things set from
169 // OnUpdateUI() which is a nice (and desired) side effect)
170 while ( ProcessIdle() ) {}
172 // if there are pending events, we must process them.
174 wxTheApp
->ProcessPendingEvents();
179 m_isInsideYield
= false;