1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/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 // ============================================================================
41 wxGUIEventLoop::wxGUIEventLoop()
46 void wxGUIEventLoop::WakeUp()
48 extern void wxMacWakeUp();
53 bool wxGUIEventLoop::Pending() const
55 wxMacAutoreleasePool autoreleasepool;
56 // a pointer to the event is returned if there is one, or nil if not
57 return [[NSApplication sharedApplication]
58 nextEventMatchingMask: NSAnyEventMask
60 inMode: NSDefaultRunLoopMode
64 bool wxGUIEventLoop::Dispatch()
69 wxMacAutoreleasePool autoreleasepool;
71 if(NSEvent *event = [NSApp
72 nextEventMatchingMask:NSAnyEventMask
73 untilDate:[NSDate dateWithTimeIntervalSinceNow: m_sleepTime]
74 inMode:NSDefaultRunLoopMode
78 [NSApp sendEvent: event];
82 if ( wxTheApp->ProcessIdle() )
98 bool wxGUIEventLoop::YieldFor(long eventsToProcess)
101 // Yielding from a non-gui thread needs to bail out, otherwise we end up
102 // possibly sending events in the thread too.
103 if ( !wxThread::IsMain() )
107 #endif // wxUSE_THREADS
109 m_isInsideYield = true;
110 m_eventsToProcessInsideYield = eventsToProcess;
113 // disable log flushing from here because a call to wxYield() shouldn't
114 // normally result in message boxes popping up &c
118 // process all pending events:
122 // it's necessary to call ProcessIdle() to update the frames sizes which
123 // might have been changed (it also will update other things set from
124 // OnUpdateUI() which is a nice (and desired) side effect)
125 while ( ProcessIdle() ) {}
130 m_isInsideYield = false;
135 int wxGUIEventLoop::DispatchTimeout(unsigned long timeout)
137 wxMacAutoreleasePool autoreleasepool;
139 NSEvent *event = [NSApp
140 nextEventMatchingMask:NSAnyEventMask
141 untilDate:[NSDate dateWithTimeIntervalSinceNow: timeout/1000]
142 inMode:NSDefaultRunLoopMode
147 [NSApp sendEvent: event];