]> git.saurik.com Git - wxWidgets.git/blame - src/osx/iphone/evtloop.mm
A call to wxPopupWindow::Show shouldn't automatically cause the popup window to steal...
[wxWidgets.git] / src / osx / iphone / evtloop.mm
CommitLineData
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/*
42static 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
78wxGUIEventLoop::wxGUIEventLoop()
79{
80 m_sleepTime = 0.0;
81}
82
83void wxGUIEventLoop::WakeUp()
84{
85 extern void wxMacWakeUp();
86
87 wxMacWakeUp();
88}
89
c200f9a3
SC
90CFRunLoopRef wxGUIEventLoop::CFGetCurrentRunLoop() const
91{
92 return CFRunLoopGetCurrent();
93}
94
581c5049
SC
95bool wxGUIEventLoop::Pending() const
96{
97 wxMacAutoreleasePool autoreleasepool;
98 // a pointer to the event is returned if there is one, or nil if not
99 /*
100 return [[UIApplication sharedApplication]
101 nextEventMatchingMask: NSAnyEventMask
102 untilDate: nil
103 inMode: NSDefaultRunLoopMode
104 dequeue: NO];
105 */
106 return false;
107}
108
109bool wxGUIEventLoop::Dispatch()
110{
111 if ( !wxTheApp )
112 return false;
113
114 wxMacAutoreleasePool autoreleasepool;
115
116/*
117 if(UIEvent *event = [[UIApplication sharedApplication]
118 nextEventMatchingMask:NSAnyEventMask
119 untilDate:[NSDate dateWithTimeIntervalSinceNow: m_sleepTime]
120 inMode:NSDefaultRunLoopMode
121 dequeue: YES])
122 {
123 m_sleepTime = 0.0;
124 [[UIApplication sharedApplication] sendEvent: event];
125 }
126 else
127*/
128 {
129 if ( wxTheApp->ProcessIdle() )
130 m_sleepTime = 0.0 ;
131 else
132 {
133 m_sleepTime = 1.0;
134#if wxUSE_THREADS
135 wxMutexGuiLeave();
136 wxMilliSleep(20);
137 wxMutexGuiEnter();
138#endif
139 }
140 }
141
142 return true;
143}
144
145bool wxGUIEventLoop::YieldFor(long eventsToProcess)
146{
147#if wxUSE_THREADS
148 // Yielding from a non-gui thread needs to bail out, otherwise we end up
149 // possibly sending events in the thread too.
150 if ( !wxThread::IsMain() )
151 {
152 return true;
153 }
154#endif // wxUSE_THREADS
155
156 m_isInsideYield = true;
157 m_eventsToProcessInsideYield = eventsToProcess;
158
159#if wxUSE_LOG
160 // disable log flushing from here because a call to wxYield() shouldn't
161 // normally result in message boxes popping up &c
162 wxLog::Suspend();
163#endif // wxUSE_LOG
164
165 // process all pending events:
166 while ( Pending() )
167 Dispatch();
168
169 // it's necessary to call ProcessIdle() to update the frames sizes which
170 // might have been changed (it also will update other things set from
171 // OnUpdateUI() which is a nice (and desired) side effect)
172 while ( ProcessIdle() ) {}
173
174#if wxUSE_LOG
175 wxLog::Resume();
176#endif // wxUSE_LOG
177 m_isInsideYield = false;
178
179 return true;
180}
181
182int wxGUIEventLoop::DispatchTimeout(unsigned long timeout)
183{
184 wxMacAutoreleasePool autoreleasepool;
185/*
186 UIEvent *event = [[UIApplication sharedApplication]
187 nextEventMatchingMask:NSAnyEventMask
188 untilDate:[NSDate dateWithTimeIntervalSinceNow: timeout/1000]
189 inMode:NSDefaultRunLoopMode
190 dequeue: YES];
191 if ( !event )
192 return -1;
193
194 [NSApp sendEvent: event];
195*/
196 return true;
197}