]>
Commit | Line | Data |
---|---|---|
489468fe SC |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/mac/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 | ||
b2680ced | 33 | #if wxOSX_USE_CARBON |
489468fe SC |
34 | #include <Carbon/Carbon.h> |
35 | #else | |
b2680ced | 36 | #include <CoreFoundation/CoreFoundation.h> |
489468fe SC |
37 | #endif |
38 | // ============================================================================ | |
39 | // wxEventLoop implementation | |
40 | // ============================================================================ | |
41 | ||
42 | // ---------------------------------------------------------------------------- | |
43 | // high level functions for RunApplicationEventLoop() case | |
44 | // ---------------------------------------------------------------------------- | |
45 | ||
b2680ced SC |
46 | |
47 | ||
489468fe SC |
48 | #if wxMAC_USE_RUN_APP_EVENT_LOOP |
49 | ||
50 | int wxGUIEventLoop::Run() | |
51 | { | |
52 | wxEventLoopActivator activate(this); | |
53 | ||
54 | RunApplicationEventLoop(); | |
55 | ||
56 | return m_exitcode; | |
57 | } | |
58 | ||
59 | void wxGUIEventLoop::Exit(int rc) | |
60 | { | |
61 | m_exitcode = rc; | |
62 | ||
63 | QuitApplicationEventLoop(); | |
64 | ||
65 | OnExit(); | |
66 | } | |
67 | ||
68 | #else // manual event loop | |
69 | ||
70 | // ---------------------------------------------------------------------------- | |
71 | // functions only used by wxEventLoopManual-based implementation | |
72 | // ---------------------------------------------------------------------------- | |
73 | ||
74 | void wxGUIEventLoop::WakeUp() | |
75 | { | |
76 | extern void wxMacWakeUp(); | |
77 | ||
78 | wxMacWakeUp(); | |
79 | } | |
80 | ||
81 | #endif // high/low-level event loop | |
82 | ||
83 | // ---------------------------------------------------------------------------- | |
84 | // low level functions used in both cases | |
85 | // ---------------------------------------------------------------------------- | |
86 | ||
87 | bool wxGUIEventLoop::Pending() const | |
88 | { | |
b2680ced | 89 | #if wxOSX_USE_CARBON |
489468fe SC |
90 | EventRef theEvent; |
91 | ||
92 | return ReceiveNextEvent | |
93 | ( | |
94 | 0, // we want any event at all so we don't specify neither | |
95 | NULL, // the number of event types nor the types themselves | |
96 | kEventDurationNoWait, | |
97 | false, // don't remove the event from queue | |
98 | &theEvent | |
99 | ) == noErr; | |
b2680ced SC |
100 | #else |
101 | return true; // TODO | |
102 | #endif | |
489468fe SC |
103 | } |
104 | ||
105 | bool wxGUIEventLoop::Dispatch() | |
106 | { | |
489468fe SC |
107 | if ( !wxTheApp ) |
108 | return false; | |
109 | ||
b2680ced SC |
110 | #if wxOSX_USE_CARBON |
111 | // TODO: we probably should do the dispatching directly from here but for | |
112 | // now it's easier to forward to wxApp which has all the code to do | |
113 | // it | |
489468fe | 114 | wxTheApp->MacDoOneEvent(); |
b2680ced SC |
115 | #else |
116 | CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, 0); | |
117 | #endif | |
489468fe SC |
118 | return true; |
119 | } |