X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9af42efda6c78093872a67180d43d5eeba261fee..cffda6922a7a7f205389e8002d0b7558ec2d36fb:/src/osx/carbon/evtloop.cpp diff --git a/src/osx/carbon/evtloop.cpp b/src/osx/carbon/evtloop.cpp index 45aad41e25..68695943bb 100644 --- a/src/osx/carbon/evtloop.cpp +++ b/src/osx/carbon/evtloop.cpp @@ -28,8 +28,13 @@ #ifndef WX_PRECOMP #include "wx/app.h" + #include "wx/log.h" #endif // WX_PRECOMP +#if wxUSE_GUI +#include "wx/nonownedwnd.h" +#endif + #include "wx/osx/private.h" // ============================================================================ @@ -38,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 ); @@ -60,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 ) @@ -129,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: @@ -137,3 +83,61 @@ int wxGUIEventLoop::DispatchTimeout(unsigned long timeout) } } +void wxGUIEventLoop::DoRun() +{ + wxMacAutoreleasePool autoreleasepool; + RunApplicationEventLoop(); +} + +void wxGUIEventLoop::DoStop() +{ + QuitApplicationEventLoop(); +} + +wxModalEventLoop::wxModalEventLoop(wxWindow *winModal) +{ + m_modalWindow = dynamic_cast (winModal); + wxASSERT_MSG( m_modalWindow != NULL, "must pass in a toplevel window for modal event loop" ); +} + +void wxModalEventLoop::DoRun() +{ + wxMacAutoreleasePool autoreleasepool; + WindowRef windowRef = m_modalWindow->GetWXWindow(); + + WindowGroupRef windowGroup = NULL; + WindowGroupRef formerParentGroup = NULL; + bool resetGroupParent = false; + + // make sure modal dialogs are in the right layer so that they are not covered + + if ( m_modalWindow->GetParent() == NULL ) + { + windowGroup = GetWindowGroup(windowRef) ; + if ( windowGroup != GetWindowGroupOfClass( kMovableModalWindowClass ) ) + { + formerParentGroup = GetWindowGroupParent( windowGroup ); + SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) ); + resetGroupParent = true; + } + } + + m_modalWindow->SetFocus(); + + RunAppModalLoopForWindow(windowRef); + + if ( resetGroupParent ) + { + SetWindowGroupParent( windowGroup , formerParentGroup ); + } + +} + +void wxModalEventLoop::DoStop() +{ + wxMacAutoreleasePool autoreleasepool; + WindowRef theWindow = m_modalWindow->GetWXWindow(); + QuitAppModalLoopForWindow(theWindow); +} + +