///////////////////////////////////////////////////////////////////////////////
-// Name: src/mac/carbon/evtloop.cpp
+// Name: src/osx/carbon/evtloop.cpp
// Purpose: implementation of wxEventLoop for wxMac
// Author: Vadim Zeitlin
// Modified by:
#ifndef WX_PRECOMP
#include "wx/app.h"
+ #include "wx/log.h"
#endif // WX_PRECOMP
-#ifdef __DARWIN__
- #include <Carbon/Carbon.h>
-#else
- #include <Carbon.h>
+#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
+wxGUIEventLoop::wxGUIEventLoop()
+{
+}
-int wxGUIEventLoop::Run()
+static void DispatchAndReleaseEvent(EventRef theEvent)
{
- wxEventLoopActivator activate(this);
+ if ( wxTheApp )
+ wxTheApp->MacSetCurrentEvent( theEvent, NULL );
- RunApplicationEventLoop();
+ OSStatus status = SendEventToEventTarget(theEvent, GetEventDispatcherTarget());
+ if (status == eventNotHandledErr && wxTheApp)
+ wxTheApp->MacHandleUnhandledEvent(theEvent);
- return m_exitcode;
+ ReleaseEvent( theEvent );
}
-void wxGUIEventLoop::Exit(int rc)
+int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout)
{
- m_exitcode = rc;
-
- QuitApplicationEventLoop();
+ 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;
+ }
+}
- OnExit();
+void wxGUIEventLoop::DoRun()
+{
+ wxMacAutoreleasePool autoreleasepool;
+ RunApplicationEventLoop();
}
-#else // manual event loop
+void wxGUIEventLoop::DoStop()
+{
+ QuitApplicationEventLoop();
+}
-// ----------------------------------------------------------------------------
-// functions only used by wxEventLoopManual-based implementation
-// ----------------------------------------------------------------------------
+// TODO move into a evtloop_osx.cpp
-void wxGUIEventLoop::WakeUp()
+wxModalEventLoop::wxModalEventLoop(wxWindow *modalWindow)
{
- extern void wxMacWakeUp();
-
- wxMacWakeUp();
+ m_modalWindow = dynamic_cast<wxNonOwnedWindow*> (modalWindow);
+ wxASSERT_MSG( m_modalWindow != NULL, "must pass in a toplevel window for modal event loop" );
+ m_modalNativeWindow = m_modalWindow->GetWXWindow();
}
-#endif // high/low-level event loop
+wxModalEventLoop::wxModalEventLoop(WXWindow modalNativeWindow)
+{
+ m_modalWindow = NULL;
+ wxASSERT_MSG( modalNativeWindow != NULL, "must pass in a toplevel window for modal event loop" );
+ m_modalNativeWindow = modalNativeWindow;
+}
-// ----------------------------------------------------------------------------
-// low level functions used in both cases
-// ----------------------------------------------------------------------------
+// END move into a evtloop_osx.cpp
-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;
+
+ 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 )
+ {
+ if ( m_modalWindow->GetParent() == NULL )
+ {
+ windowGroup = GetWindowGroup(m_modalNativeWindow) ;
+ if ( windowGroup != GetWindowGroupOfClass( kMovableModalWindowClass ) )
+ {
+ formerParentGroup = GetWindowGroupParent( windowGroup );
+ SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
+ resetGroupParent = true;
+ }
+ }
+ }
+
+ m_modalWindow->SetFocus();
+
+ RunAppModalLoopForWindow(m_modalNativeWindow);
+
+ 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;
+ QuitAppModalLoopForWindow(m_modalNativeWindow);
}
+
+