]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/evtloop.cpp
fix for gccxml
[wxWidgets.git] / src / osx / carbon / evtloop.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/evtloop.cpp
3 // Purpose: implementation of wxEventLoop for wxMac
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 2006-01-12
7 // RCS-ID: $Id$
8 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #include "wx/evtloop.h"
28
29 #ifndef WX_PRECOMP
30 #include "wx/app.h"
31 #endif // WX_PRECOMP
32
33 #include "wx/osx/private.h"
34
35 // ============================================================================
36 // wxEventLoop implementation
37 // ============================================================================
38
39 wxGUIEventLoop::wxGUIEventLoop()
40 {
41 m_sleepTime = kEventDurationNoWait;
42 }
43
44 void wxGUIEventLoop::WakeUp()
45 {
46 extern void wxMacWakeUp();
47
48 wxMacWakeUp();
49 }
50
51 bool wxGUIEventLoop::Pending() const
52 {
53 EventRef theEvent;
54
55 return ReceiveNextEvent
56 (
57 0, // we want any event at all so we don't specify neither
58 NULL, // the number of event types nor the types themselves
59 kEventDurationNoWait,
60 false, // don't remove the event from queue
61 &theEvent
62 ) == noErr;
63 }
64
65 bool wxGUIEventLoop::Dispatch()
66 {
67 if ( !wxTheApp )
68 return false;
69
70 wxMacAutoreleasePool autoreleasepool;
71
72 EventRef theEvent;
73
74 OSStatus status = ReceiveNextEvent(0, NULL, m_sleepTime, true, &theEvent) ;
75
76 switch (status)
77 {
78 case eventLoopTimedOutErr :
79 if ( wxTheApp->ProcessIdle() )
80 m_sleepTime = kEventDurationNoWait ;
81 else
82 {
83 m_sleepTime = kEventDurationSecond;
84 #if wxUSE_THREADS
85 wxMutexGuiLeave();
86 wxMilliSleep(20);
87 wxMutexGuiEnter();
88 #endif
89 }
90 break;
91
92 case eventLoopQuitErr :
93 // according to QA1061 this may also occur
94 // when a WakeUp Process is executed
95 break;
96
97 default:
98 if ( wxTheApp )
99 wxTheApp->MacSetCurrentEvent( theEvent, NULL );
100
101 OSStatus status = SendEventToEventTarget(theEvent, GetEventDispatcherTarget());
102 if (status == eventNotHandledErr && wxTheApp)
103 wxTheApp->MacHandleUnhandledEvent(theEvent);
104
105 ReleaseEvent( theEvent );
106 m_sleepTime = kEventDurationNoWait ;
107 break;
108 }
109
110 return true;
111 }