]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/evtloop.mm
Check index in wxItemContainer methods working with client data.
[wxWidgets.git] / src / osx / cocoa / evtloop.mm
index 4771978ff4c325710c5c818f25dae9ab7568c28a..89957cd2bd7672e073352c8ef469c97c107777e1 100644 (file)
@@ -118,10 +118,16 @@ bool wxGUIEventLoop::Dispatch()
                 inMode:NSDefaultRunLoopMode
                 dequeue: YES])
     {
+        WXEVENTREF formerEvent = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEvent();
+        WXEVENTHANDLERCALLREF formerHandler = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEventHandlerCallRef();
+
         if (wxTheApp)
             wxTheApp->MacSetCurrentEvent(event, NULL);
         m_sleepTime = 0.0;
         [NSApp sendEvent: event];
+
+        if (wxTheApp)
+            wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
     }
     else
     {
@@ -173,8 +179,43 @@ void wxGUIEventLoop::DoRun()
 void wxGUIEventLoop::DoStop()
 {
     [NSApp stop:0];
+    // only calling stop: is not enough when called from a runloop-observer,
+    // therefore add a dummy event, to make sure the runloop gets another round
+    NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined 
+                                        location:NSMakePoint(0.0, 0.0) 
+                                   modifierFlags:0 
+                                       timestamp:0 
+                                    windowNumber:0 
+                                         context:nil
+                                         subtype:0 data1:0 data2:0]; 
+    [NSApp postEvent:event atStart:FALSE];
+}
+
+CFRunLoopRef wxGUIEventLoop::CFGetCurrentRunLoop() const
+{
+    NSRunLoop* nsloop = [NSRunLoop currentRunLoop];
+    return [nsloop getCFRunLoop];
 }
 
+
+// TODO move into a evtloop_osx.cpp
+
+wxModalEventLoop::wxModalEventLoop(wxWindow *modalWindow)
+{
+    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();
+}
+
+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()
 {
     wxMacAutoreleasePool pool;
@@ -191,8 +232,7 @@ void wxModalEventLoop::DoRun()
         }
     }
     
-    NSWindow* theWindow = m_modalWindow->GetWXWindow();
-    [NSApp runModalForWindow:theWindow];
+    [NSApp runModalForWindow:m_modalNativeWindow];
 }
 
 void wxModalEventLoop::DoStop()