X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/489468feaa08b8f504735eecca522fb8d0f825d2..cffda6922a7a7f205389e8002d0b7558ec2d36fb:/src/osx/carbon/evtloop.cpp diff --git a/src/osx/carbon/evtloop.cpp b/src/osx/carbon/evtloop.cpp index 681564bffa..68695943bb 100644 --- a/src/osx/carbon/evtloop.cpp +++ b/src/osx/carbon/evtloop.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/evtloop.cpp +// Name: src/osx/carbon/evtloop.cpp // Purpose: implementation of wxEventLoop for wxMac // Author: Vadim Zeitlin // Modified by: @@ -28,82 +28,116 @@ #ifndef WX_PRECOMP #include "wx/app.h" + #include "wx/log.h" #endif // WX_PRECOMP -#ifdef __DARWIN__ - #include -#else - #include +#if wxUSE_GUI +#include "wx/nonownedwnd.h" #endif + +#include "wx/osx/private.h" + // ============================================================================ // wxEventLoop implementation // ============================================================================ -// ---------------------------------------------------------------------------- -// high level functions for RunApplicationEventLoop() case -// ---------------------------------------------------------------------------- - -#if wxMAC_USE_RUN_APP_EVENT_LOOP - -int wxGUIEventLoop::Run() +wxGUIEventLoop::wxGUIEventLoop() { - wxEventLoopActivator activate(this); - - RunApplicationEventLoop(); - - return m_exitcode; } -void wxGUIEventLoop::Exit(int rc) +static void DispatchAndReleaseEvent(EventRef theEvent) { - m_exitcode = rc; + if ( wxTheApp ) + wxTheApp->MacSetCurrentEvent( theEvent, NULL ); - QuitApplicationEventLoop(); + OSStatus status = SendEventToEventTarget(theEvent, GetEventDispatcherTarget()); + if (status == eventNotHandledErr && wxTheApp) + wxTheApp->MacHandleUnhandledEvent(theEvent); - OnExit(); + ReleaseEvent( theEvent ); } -#else // manual event loop - -// ---------------------------------------------------------------------------- -// functions only used by wxEventLoopManual-based implementation -// ---------------------------------------------------------------------------- - -void wxGUIEventLoop::WakeUp() +int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout) { - extern void wxMacWakeUp(); + wxMacAutoreleasePool autoreleasepool; + + EventRef event; + OSStatus status = ReceiveNextEvent(0, NULL, timeout/1000, true, &event); + switch ( status ) + { + default: + wxFAIL_MSG( "unexpected ReceiveNextEvent() error" ); + // fall through + + case eventLoopTimedOutErr: + return -1; + + case eventLoopQuitErr: + // according to QA1061 this may also occur + // when a WakeUp Process is executed + return 0; + + case noErr: + DispatchAndReleaseEvent(event); + return 1; + } +} - wxMacWakeUp(); +void wxGUIEventLoop::DoRun() +{ + wxMacAutoreleasePool autoreleasepool; + RunApplicationEventLoop(); } -#endif // high/low-level event loop +void wxGUIEventLoop::DoStop() +{ + QuitApplicationEventLoop(); +} -// ---------------------------------------------------------------------------- -// low level functions used in both cases -// ---------------------------------------------------------------------------- +wxModalEventLoop::wxModalEventLoop(wxWindow *winModal) +{ + m_modalWindow = dynamic_cast (winModal); + wxASSERT_MSG( m_modalWindow != NULL, "must pass in a toplevel window for modal event loop" ); +} -bool wxGUIEventLoop::Pending() const +void wxModalEventLoop::DoRun() { - 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; + 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 ); + } + } -bool wxGUIEventLoop::Dispatch() +void wxModalEventLoop::DoStop() { - // TODO: we probably should do the dispatching directly from here but for - // now it's easier to forward to wxApp which has all the code to do - // it - if ( !wxTheApp ) - return false; - - wxTheApp->MacDoOneEvent(); - return true; + wxMacAutoreleasePool autoreleasepool; + WindowRef theWindow = m_modalWindow->GetWXWindow(); + QuitAppModalLoopForWindow(theWindow); } + +