]>
Commit | Line | Data |
---|---|---|
581c5049 SC |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/osx/iphone/evtloop.mm | |
3 | // Purpose: implementation of wxEventLoop for OS X | |
4 | // Author: Vadim Zeitlin, Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 2006-01-12 | |
7 | // RCS-ID: $Id: evtloop.cpp 54845 2008-07-30 14:52:41Z SC $ | |
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/log.h" | |
34 | ||
35 | #include "wx/osx/private.h" | |
36 | ||
37 | // ============================================================================ | |
38 | // wxEventLoop implementation | |
39 | // ============================================================================ | |
40 | ||
41 | /* | |
42 | static int CalculateUIEventMaskFromEventCategory(wxEventCategory cat) | |
43 | { | |
44 | NSLeftMouseDownMask | | |
45 | NSLeftMouseUpMask | | |
46 | NSRightMouseDownMask | | |
47 | NSRightMouseUpMask = 1 << NSRightMouseUp, | |
48 | NSMouseMovedMask = 1 << NSMouseMoved, | |
49 | NSLeftMouseDraggedMask = 1 << NSLeftMouseDragged, | |
50 | NSRightMouseDraggedMask = 1 << NSRightMouseDragged, | |
51 | NSMouseEnteredMask = 1 << NSMouseEntered, | |
52 | NSMouseExitedMask = 1 << NSMouseExited, | |
53 | NSScrollWheelMask = 1 << NSScrollWheel, | |
54 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 | |
55 | NSTabletPointMask = 1 << NSTabletPoint, | |
56 | NSTabletProximityMask = 1 << NSTabletProximity, | |
57 | #endif | |
58 | NSOtherMouseDownMask = 1 << NSOtherMouseDown, | |
59 | NSOtherMouseUpMask = 1 << NSOtherMouseUp, | |
60 | NSOtherMouseDraggedMask = 1 << NSOtherMouseDragged, | |
61 | ||
62 | ||
63 | ||
64 | NSKeyDownMask = 1 << NSKeyDown, | |
65 | NSKeyUpMask = 1 << NSKeyUp, | |
66 | NSFlagsChangedMask = 1 << NSFlagsChanged, | |
67 | ||
68 | NSAppKitDefinedMask = 1 << NSAppKitDefined, | |
69 | NSSystemDefinedMask = 1 << NSSystemDefined, | |
70 | UIApplicationDefinedMask = 1 << UIApplicationDefined, | |
71 | NSPeriodicMask = 1 << NSPeriodic, | |
72 | NSCursorUpdateMask = 1 << NSCursorUpdate, | |
73 | ||
74 | NSAnyEventMask = 0xffffffffU | |
75 | } | |
76 | */ | |
77 | ||
78 | wxGUIEventLoop::wxGUIEventLoop() | |
79 | { | |
80 | m_sleepTime = 0.0; | |
81 | } | |
82 | ||
83 | void wxGUIEventLoop::WakeUp() | |
84 | { | |
85 | extern void wxMacWakeUp(); | |
86 | ||
87 | wxMacWakeUp(); | |
88 | } | |
89 | ||
90 | bool wxGUIEventLoop::Pending() const | |
91 | { | |
92 | wxMacAutoreleasePool autoreleasepool; | |
93 | // a pointer to the event is returned if there is one, or nil if not | |
94 | /* | |
95 | return [[UIApplication sharedApplication] | |
96 | nextEventMatchingMask: NSAnyEventMask | |
97 | untilDate: nil | |
98 | inMode: NSDefaultRunLoopMode | |
99 | dequeue: NO]; | |
100 | */ | |
101 | return false; | |
102 | } | |
103 | ||
104 | bool wxGUIEventLoop::Dispatch() | |
105 | { | |
106 | if ( !wxTheApp ) | |
107 | return false; | |
108 | ||
109 | wxMacAutoreleasePool autoreleasepool; | |
110 | ||
111 | /* | |
112 | if(UIEvent *event = [[UIApplication sharedApplication] | |
113 | nextEventMatchingMask:NSAnyEventMask | |
114 | untilDate:[NSDate dateWithTimeIntervalSinceNow: m_sleepTime] | |
115 | inMode:NSDefaultRunLoopMode | |
116 | dequeue: YES]) | |
117 | { | |
118 | m_sleepTime = 0.0; | |
119 | [[UIApplication sharedApplication] sendEvent: event]; | |
120 | } | |
121 | else | |
122 | */ | |
123 | { | |
124 | if ( wxTheApp->ProcessIdle() ) | |
125 | m_sleepTime = 0.0 ; | |
126 | else | |
127 | { | |
128 | m_sleepTime = 1.0; | |
129 | #if wxUSE_THREADS | |
130 | wxMutexGuiLeave(); | |
131 | wxMilliSleep(20); | |
132 | wxMutexGuiEnter(); | |
133 | #endif | |
134 | } | |
135 | } | |
136 | ||
137 | return true; | |
138 | } | |
139 | ||
140 | bool wxGUIEventLoop::YieldFor(long eventsToProcess) | |
141 | { | |
142 | #if wxUSE_THREADS | |
143 | // Yielding from a non-gui thread needs to bail out, otherwise we end up | |
144 | // possibly sending events in the thread too. | |
145 | if ( !wxThread::IsMain() ) | |
146 | { | |
147 | return true; | |
148 | } | |
149 | #endif // wxUSE_THREADS | |
150 | ||
151 | m_isInsideYield = true; | |
152 | m_eventsToProcessInsideYield = eventsToProcess; | |
153 | ||
154 | #if wxUSE_LOG | |
155 | // disable log flushing from here because a call to wxYield() shouldn't | |
156 | // normally result in message boxes popping up &c | |
157 | wxLog::Suspend(); | |
158 | #endif // wxUSE_LOG | |
159 | ||
160 | // process all pending events: | |
161 | while ( Pending() ) | |
162 | Dispatch(); | |
163 | ||
164 | // it's necessary to call ProcessIdle() to update the frames sizes which | |
165 | // might have been changed (it also will update other things set from | |
166 | // OnUpdateUI() which is a nice (and desired) side effect) | |
167 | while ( ProcessIdle() ) {} | |
168 | ||
169 | #if wxUSE_LOG | |
170 | wxLog::Resume(); | |
171 | #endif // wxUSE_LOG | |
172 | m_isInsideYield = false; | |
173 | ||
174 | return true; | |
175 | } | |
176 | ||
177 | int wxGUIEventLoop::DispatchTimeout(unsigned long timeout) | |
178 | { | |
179 | wxMacAutoreleasePool autoreleasepool; | |
180 | /* | |
181 | UIEvent *event = [[UIApplication sharedApplication] | |
182 | nextEventMatchingMask:NSAnyEventMask | |
183 | untilDate:[NSDate dateWithTimeIntervalSinceNow: timeout/1000] | |
184 | inMode:NSDefaultRunLoopMode | |
185 | dequeue: YES]; | |
186 | if ( !event ) | |
187 | return -1; | |
188 | ||
189 | [NSApp sendEvent: event]; | |
190 | */ | |
191 | return true; | |
192 | } |