]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/carbon/evtloop.cpp
Misc XRC format docs corrections.
[wxWidgets.git] / src / osx / carbon / evtloop.cpp
index abaafd3181f7d4a72946575c58c656aee273ef54..4a8238baa0b73c3ab4dcd317f269d11eeeeeb203 100644 (file)
@@ -4,7 +4,6 @@
 // Author:      Vadim Zeitlin
 // Modified by:
 // Created:     2006-01-12
-// RCS-ID:      $Id$
 // Copyright:   (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
 // Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
     #include "wx/log.h"
 #endif // WX_PRECOMP
 
+#if wxUSE_GUI
+#include "wx/nonownedwnd.h"
+#endif
+
 #include "wx/osx/private.h"
 
 // ============================================================================
@@ -55,6 +58,8 @@ static void DispatchAndReleaseEvent(EventRef theEvent)
 
 int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout)
 {
+    wxMacAutoreleasePool autoreleasepool;
+
     EventRef event;
     OSStatus status = ReceiveNextEvent(0, NULL, timeout/1000, true, &event);
     switch ( status )
@@ -76,3 +81,99 @@ int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout)
             return 1;
     }
 }
+
+void wxGUIEventLoop::WakeUp()
+{
+    OSStatus err = noErr;
+    wxMacCarbonEvent wakeupEvent;
+    wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
+                        kEventAttributeNone );
+    err = PostEventToQueue(GetMainEventQueue(), wakeupEvent,
+                            kEventPriorityHigh );
+}
+
+void wxGUIEventLoop::OSXDoRun()
+{
+    wxMacAutoreleasePool autoreleasepool;
+
+    while (!m_shouldExit)
+    {
+        RunApplicationEventLoop();
+    }
+
+    // Force enclosing event loop to temporarily exit and check
+    // if it should be stopped.
+    QuitApplicationEventLoop();
+}
+
+void wxGUIEventLoop::OSXDoStop()
+{
+    QuitApplicationEventLoop();
+}
+
+CFRunLoopRef wxGUIEventLoop::CFGetCurrentRunLoop() const
+{
+    return wxCFEventLoop::CFGetCurrentRunLoop();
+}
+
+// TODO move into a evtloop_osx.cpp
+
+wxModalEventLoop::wxModalEventLoop(wxWindow *modalWindow)
+{
+    m_modalWindow = wxDynamicCast(modalWindow, wxNonOwnedWindow);
+    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::OSXDoRun()
+{
+    wxWindowDisabler disabler(m_modalWindow);
+    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 );
+    }
+
+}
+
+void wxModalEventLoop::OSXDoStop()
+{
+    wxMacAutoreleasePool autoreleasepool;
+    QuitAppModalLoopForWindow(m_modalNativeWindow);
+}
+
+