X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b503b036c117287b0be2c9383a12a45680d5c81b..50b5e38d3ff57f33b9b3510ab8576123efd670e9:/src/osx/cocoa/evtloop.mm diff --git a/src/osx/cocoa/evtloop.mm b/src/osx/cocoa/evtloop.mm index a8a8c561d7..92f08d178e 100644 --- a/src/osx/cocoa/evtloop.mm +++ b/src/osx/cocoa/evtloop.mm @@ -30,6 +30,8 @@ #include "wx/app.h" #endif // WX_PRECOMP +#include "wx/log.h" + #include "wx/osx/private.h" // ============================================================================ @@ -50,6 +52,7 @@ void wxGUIEventLoop::WakeUp() bool wxGUIEventLoop::Pending() const { + wxMacAutoreleasePool autoreleasepool; // a pointer to the event is returned if there is one, or nil if not return [[NSApplication sharedApplication] nextEventMatchingMask: NSAnyEventMask @@ -91,3 +94,57 @@ bool wxGUIEventLoop::Dispatch() return true; } + +bool wxGUIEventLoop::YieldFor(long eventsToProcess) +{ +#if wxUSE_THREADS + // Yielding from a non-gui thread needs to bail out, otherwise we end up + // possibly sending events in the thread too. + if ( !wxThread::IsMain() ) + { + return true; + } +#endif // wxUSE_THREADS + + m_isInsideYield = true; + m_eventsToProcessInsideYield = eventsToProcess; + +#if wxUSE_LOG + // disable log flushing from here because a call to wxYield() shouldn't + // normally result in message boxes popping up &c + wxLog::Suspend(); +#endif // wxUSE_LOG + + // process all pending events: + while ( Pending() ) + Dispatch(); + + // it's necessary to call ProcessIdle() to update the frames sizes which + // might have been changed (it also will update other things set from + // OnUpdateUI() which is a nice (and desired) side effect) + while ( ProcessIdle() ) {} + +#if wxUSE_LOG + wxLog::Resume(); +#endif // wxUSE_LOG + m_isInsideYield = false; + + return true; +} + +int wxGUIEventLoop::DispatchTimeout(unsigned long timeout) +{ + wxMacAutoreleasePool autoreleasepool; + + NSEvent *event = [NSApp + nextEventMatchingMask:NSAnyEventMask + untilDate:[NSDate dateWithTimeIntervalSinceNow: timeout/1000] + inMode:NSDefaultRunLoopMode + dequeue: YES]; + if ( !event ) + return -1; + + [NSApp sendEvent: event]; + + return true; +}