1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/iphone/evtloop.mm
3 // Purpose: implementation of wxEventLoop for OS X
4 // Author: Vadim Zeitlin, Stefan Csomor
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 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/evtloop.h"
35 #include "wx/osx/private.h"
37 // ============================================================================
38 // wxEventLoop implementation
39 // ============================================================================
42 static int CalculateUIEventMaskFromEventCategory(wxEventCategory cat)
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,
58 NSOtherMouseDownMask = 1 << NSOtherMouseDown,
59 NSOtherMouseUpMask = 1 << NSOtherMouseUp,
60 NSOtherMouseDraggedMask = 1 << NSOtherMouseDragged,
64 NSKeyDownMask = 1 << NSKeyDown,
65 NSKeyUpMask = 1 << NSKeyUp,
66 NSFlagsChangedMask = 1 << NSFlagsChanged,
68 NSAppKitDefinedMask = 1 << NSAppKitDefined,
69 NSSystemDefinedMask = 1 << NSSystemDefined,
70 UIApplicationDefinedMask = 1 << UIApplicationDefined,
71 NSPeriodicMask = 1 << NSPeriodic,
72 NSCursorUpdateMask = 1 << NSCursorUpdate,
74 NSAnyEventMask = 0xffffffffU
78 wxGUIEventLoop::wxGUIEventLoop()
83 void wxGUIEventLoop::WakeUp()
85 extern void wxMacWakeUp();
90 CFRunLoopRef wxGUIEventLoop::CFGetCurrentRunLoop() const
92 return CFRunLoopGetCurrent();
95 bool wxGUIEventLoop::Pending() const
97 wxMacAutoreleasePool autoreleasepool;
98 // a pointer to the event is returned if there is one, or nil if not
100 return [[UIApplication sharedApplication]
101 nextEventMatchingMask: NSAnyEventMask
103 inMode: NSDefaultRunLoopMode
109 bool wxGUIEventLoop::Dispatch()
114 wxMacAutoreleasePool autoreleasepool;
117 if(UIEvent *event = [[UIApplication sharedApplication]
118 nextEventMatchingMask:NSAnyEventMask
119 untilDate:[NSDate dateWithTimeIntervalSinceNow: m_sleepTime]
120 inMode:NSDefaultRunLoopMode
124 [[UIApplication sharedApplication] sendEvent: event];
129 if ( wxTheApp->ProcessIdle() )
145 bool wxGUIEventLoop::YieldFor(long eventsToProcess)
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() )
154 #endif // wxUSE_THREADS
156 m_isInsideYield = true;
157 m_eventsToProcessInsideYield = eventsToProcess;
160 // disable log flushing from here because a call to wxYield() shouldn't
161 // normally result in message boxes popping up &c
165 // process all pending events:
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() ) {}
177 m_isInsideYield = false;
182 int wxGUIEventLoop::DispatchTimeout(unsigned long timeout)
184 wxMacAutoreleasePool autoreleasepool;
186 UIEvent *event = [[UIApplication sharedApplication]
187 nextEventMatchingMask:NSAnyEventMask
188 untilDate:[NSDate dateWithTimeIntervalSinceNow: timeout/1000]
189 inMode:NSDefaultRunLoopMode
194 [NSApp sendEvent: event];