X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/11fed901d1744019e2a4279714d172829a3c0699..0f1c3d30d4a699817340ce56e752b61b78cccb1c:/src/osx/cocoa/evtloop.mm diff --git a/src/osx/cocoa/evtloop.mm b/src/osx/cocoa/evtloop.mm index 795a05f9b7..69c550b6d0 100644 --- a/src/osx/cocoa/evtloop.mm +++ b/src/osx/cocoa/evtloop.mm @@ -77,25 +77,31 @@ static int CalculateNSEventMaskFromEventCategory(wxEventCategory cat) wxGUIEventLoop::wxGUIEventLoop() { - m_sleepTime = 0.0; } -void wxGUIEventLoop::WakeUp() -{ - extern void wxMacWakeUp(); +//----------------------------------------------------------------------------- +// events dispatch and loop handling +//----------------------------------------------------------------------------- - wxMacWakeUp(); -} +#if 0 bool wxGUIEventLoop::Pending() const { +#if 0 + // this code doesn't reliably detect pending events + // so better return true and have the dispatch deal with it + // as otherwise we end up in a tight loop when idle events are responded + // to by RequestMore(true) wxMacAutoreleasePool autoreleasepool; - // a pointer to the event is returned if there is one, or nil if not + return [[NSApplication sharedApplication] nextEventMatchingMask: NSAnyEventMask untilDate: nil inMode: NSDefaultRunLoopMode - dequeue: NO]; + dequeue: NO] != nil; +#else + return true; +#endif } bool wxGUIEventLoop::Dispatch() @@ -111,11 +117,16 @@ bool wxGUIEventLoop::Dispatch() inMode:NSDefaultRunLoopMode dequeue: YES]) { + if (wxTheApp) + wxTheApp->MacSetCurrentEvent(event, NULL); m_sleepTime = 0.0; [NSApp sendEvent: event]; } else { + if (wxTheApp) + wxTheApp->ProcessPendingEvents(); + if ( wxTheApp->ProcessIdle() ) m_sleepTime = 0.0 ; else @@ -132,44 +143,9 @@ 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; -} +#endif -int wxGUIEventLoop::DispatchTimeout(unsigned long timeout) +int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout) { wxMacAutoreleasePool autoreleasepool; @@ -178,10 +154,11 @@ int wxGUIEventLoop::DispatchTimeout(unsigned long timeout) untilDate:[NSDate dateWithTimeIntervalSinceNow: timeout/1000] inMode:NSDefaultRunLoopMode dequeue: YES]; - if ( !event ) + + if ( event == nil ) return -1; [NSApp sendEvent: event]; - return true; + return 1; }