X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bcf79477d17935e28d263373d6afe8e4d8ec53d0..ad05cdb74c4a1e632b6e9c5e56f463c6d798457b:/src/osx/carbon/evtloop.cpp?ds=sidebyside diff --git a/src/osx/carbon/evtloop.cpp b/src/osx/carbon/evtloop.cpp index 4278ced196..4ca136ca90 100644 --- a/src/osx/carbon/evtloop.cpp +++ b/src/osx/carbon/evtloop.cpp @@ -31,6 +31,10 @@ #include "wx/log.h" #endif // WX_PRECOMP +#if wxUSE_GUI +#include "wx/nonownedwnd.h" +#endif + #include "wx/osx/private.h" // ============================================================================ @@ -39,17 +43,9 @@ wxGUIEventLoop::wxGUIEventLoop() { - m_sleepTime = kEventDurationNoWait; } -void wxGUIEventLoop::WakeUp() -{ - extern void wxMacWakeUp(); - - wxMacWakeUp(); -} - -void wxGUIEventLoop::DispatchAndReleaseEvent(EventRef theEvent) +static void DispatchAndReleaseEvent(EventRef theEvent) { if ( wxTheApp ) wxTheApp->MacSetCurrentEvent( theEvent, NULL ); @@ -61,63 +57,10 @@ void wxGUIEventLoop::DispatchAndReleaseEvent(EventRef theEvent) ReleaseEvent( theEvent ); } -bool wxGUIEventLoop::Pending() const -{ - EventRef theEvent; - - return ReceiveNextEvent - ( - 0, // we want any event at all so we don't specify neither - NULL, // the number of event types nor the types themselves - kEventDurationNoWait, - false, // don't remove the event from queue - &theEvent - ) == noErr; -} - -bool wxGUIEventLoop::Dispatch() +int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout) { - if ( !wxTheApp ) - return false; - wxMacAutoreleasePool autoreleasepool; - - EventRef theEvent; - - OSStatus status = ReceiveNextEvent(0, NULL, m_sleepTime, true, &theEvent) ; - - switch (status) - { - case eventLoopTimedOutErr : - if ( wxTheApp->ProcessIdle() ) - m_sleepTime = kEventDurationNoWait ; - else - { - m_sleepTime = kEventDurationSecond; -#if wxUSE_THREADS - wxMutexGuiLeave(); - wxMilliSleep(20); - wxMutexGuiEnter(); -#endif - } - break; - - case eventLoopQuitErr : - // according to QA1061 this may also occur - // when a WakeUp Process is executed - break; - - default: - DispatchAndReleaseEvent(theEvent); - m_sleepTime = kEventDurationNoWait ; - break; - } - - return true; -} - -int wxGUIEventLoop::DispatchTimeout(unsigned long timeout) -{ + EventRef event; OSStatus status = ReceiveNextEvent(0, NULL, timeout/1000, true, &event); switch ( status ) @@ -130,6 +73,8 @@ int wxGUIEventLoop::DispatchTimeout(unsigned long timeout) return -1; case eventLoopQuitErr: + // according to QA1061 this may also occur + // when a WakeUp Process is executed return 0; case noErr: @@ -138,39 +83,74 @@ int wxGUIEventLoop::DispatchTimeout(unsigned long timeout) } } -bool wxGUIEventLoop::YieldFor(long eventsToProcess) +void wxGUIEventLoop::DoRun() +{ + wxMacAutoreleasePool autoreleasepool; + RunApplicationEventLoop(); +} + +void wxGUIEventLoop::DoStop() +{ + QuitApplicationEventLoop(); +} + +// TODO move into a evtloop_osx.cpp + +wxModalEventLoop::wxModalEventLoop(wxWindow *modalWindow) +{ + m_modalWindow = dynamic_cast (modalWindow); + wxASSERT_MSG( m_modalWindow != NULL, "must pass in a toplevel window for modal event loop" ); + m_modalNativeWindow = m_modalWindow->GetWXWindow(); +} + +wxModalEventLoop::wxModalEventLoop(WXWindow modalNativeWindow) +{ + m_modalWindow = NULL; + wxASSERT_MSG( modalNativeWindow != NULL, "must pass in a toplevel window for modal event loop" ); + m_modalNativeWindow = modalNativeWindow; +} + +// END move into a evtloop_osx.cpp + +void wxModalEventLoop::DoRun() { -#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() ) + wxMacAutoreleasePool autoreleasepool; + + bool resetGroupParent = false; + + WindowGroupRef windowGroup = NULL; + WindowGroupRef formerParentGroup = NULL; + + // make sure modal dialogs are in the right layer so that they are not covered + if ( m_modalWindow != NULL ) { - return true; + if ( m_modalWindow->GetParent() == NULL ) + { + windowGroup = GetWindowGroup(m_modalNativeWindow) ; + if ( windowGroup != GetWindowGroupOfClass( kMovableModalWindowClass ) ) + { + formerParentGroup = GetWindowGroupParent( windowGroup ); + SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) ); + resetGroupParent = true; + } + } } -#endif // wxUSE_THREADS - m_isInsideYield = true; - m_eventsToProcessInsideYield = eventsToProcess; + m_modalWindow->SetFocus(); + + RunAppModalLoopForWindow(m_modalNativeWindow); -#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 + if ( resetGroupParent ) + { + SetWindowGroupParent( windowGroup , formerParentGroup ); + } - // 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() ) {} +void wxModalEventLoop::DoStop() +{ + wxMacAutoreleasePool autoreleasepool; + QuitAppModalLoopForWindow(m_modalNativeWindow); +} -#if wxUSE_LOG - wxLog::Resume(); -#endif // wxUSE_LOG - m_isInsideYield = false; - return true; -}