]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/evtloop.mm
Correct format specifiers used to show wxIPV4address.
[wxWidgets.git] / src / osx / cocoa / evtloop.mm
index a8a8c561d7a0551747ff1fe093d29fd520b7709d..11e9d211296b72c4fbe181d032fd90410ddfb787 100644 (file)
 
 #ifndef WX_PRECOMP
     #include "wx/app.h"
+    #include "wx/nonownedwnd.h"
 #endif // WX_PRECOMP
 
+#include "wx/log.h"
+
 #include "wx/osx/private.h"
 
 // ============================================================================
 // wxEventLoop implementation
 // ============================================================================
 
-wxGUIEventLoop::wxGUIEventLoop()
+/*
+static int CalculateNSEventMaskFromEventCategory(wxEventCategory cat)
 {
-    m_sleepTime = 0.0;
+       NSLeftMouseDownMask     |
+       NSLeftMouseUpMask |
+       NSRightMouseDownMask |
+       NSRightMouseUpMask              = 1 << NSRightMouseUp,
+       NSMouseMovedMask                = 1 << NSMouseMoved,
+       NSLeftMouseDraggedMask          = 1 << NSLeftMouseDragged,
+       NSRightMouseDraggedMask         = 1 << NSRightMouseDragged,
+       NSMouseEnteredMask              = 1 << NSMouseEntered,
+       NSMouseExitedMask               = 1 << NSMouseExited,
+        NSScrollWheelMask              = 1 << NSScrollWheel,
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+       NSTabletPointMask               = 1 << NSTabletPoint,
+       NSTabletProximityMask           = 1 << NSTabletProximity,
+#endif
+       NSOtherMouseDownMask            = 1 << NSOtherMouseDown,
+       NSOtherMouseUpMask              = 1 << NSOtherMouseUp,
+       NSOtherMouseDraggedMask         = 1 << NSOtherMouseDragged,
+
+
+
+       NSKeyDownMask                   = 1 << NSKeyDown,
+       NSKeyUpMask                     = 1 << NSKeyUp,
+       NSFlagsChangedMask              = 1 << NSFlagsChanged,
+
+       NSAppKitDefinedMask             = 1 << NSAppKitDefined,
+       NSSystemDefinedMask             = 1 << NSSystemDefined,
+       NSApplicationDefinedMask        = 1 << NSApplicationDefined,
+       NSPeriodicMask                  = 1 << NSPeriodic,
+       NSCursorUpdateMask              = 1 << NSCursorUpdate,
+
+       NSAnyEventMask                  = 0xffffffffU
 }
+*/
 
-void wxGUIEventLoop::WakeUp()
+wxGUIEventLoop::wxGUIEventLoop()
 {
-    extern void wxMacWakeUp();
-
-    wxMacWakeUp();
 }
 
+//-----------------------------------------------------------------------------
+// events dispatch and loop handling
+//-----------------------------------------------------------------------------
+
+#if 0
+
 bool wxGUIEventLoop::Pending() const
 {
-    // a pointer to the event is returned if there is one, or nil if not
+#if 0
+    // this code doesn't reliably detect pending events
+    // so better return true and have the dispatch deal with it
+    // as otherwise we end up in a tight loop when idle events are responded
+    // to by RequestMore(true)
+    wxMacAutoreleasePool autoreleasepool;
+  
     return [[NSApplication sharedApplication]
             nextEventMatchingMask: NSAnyEventMask
             untilDate: nil
             inMode: NSDefaultRunLoopMode
-            dequeue: NO];
+            dequeue: NO] != nil;
+#else
+    return true;
+#endif
 }
 
 bool wxGUIEventLoop::Dispatch()
@@ -71,11 +118,22 @@ 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
     {
+        if (wxTheApp)
+            wxTheApp->ProcessPendingEvents();
+        
         if ( wxTheApp->ProcessIdle() )
             m_sleepTime = 0.0 ;
         else
@@ -91,3 +149,84 @@ bool wxGUIEventLoop::Dispatch()
 
     return true;
 }
+
+#endif
+
+int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout)
+{
+    wxMacAutoreleasePool autoreleasepool;
+
+    NSEvent *event = [NSApp
+                nextEventMatchingMask:NSAnyEventMask
+                untilDate:[NSDate dateWithTimeIntervalSinceNow: timeout/1000]
+                inMode:NSDefaultRunLoopMode
+                dequeue: YES];
+    
+    if ( event == nil )
+        return -1;
+
+    [NSApp sendEvent: event];
+
+    return 1;
+}
+
+void wxGUIEventLoop::DoRun()
+{
+    wxMacAutoreleasePool autoreleasepool;
+    [NSApp run];
+}
+
+void wxGUIEventLoop::DoStop()
+{
+    [NSApp stop:0];
+}
+
+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;
+
+    // If the app hasn't started, flush the event queue
+    // If we don't do this, the Dock doesn't get the message that
+    // the app has started so will refuse to activate it.
+    [NSApplication sharedApplication];
+    if (![NSApp isRunning])
+    {
+        while(NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES])
+        {
+            [NSApp sendEvent:event];
+        }
+    }
+    
+    [NSApp runModalForWindow:m_modalNativeWindow];
+}
+
+void wxModalEventLoop::DoStop()
+{
+    [NSApp stopModal];
+}
+