]> git.saurik.com Git - wxWidgets.git/commitdiff
Implement Pending and Dispatch
authorDavid Elliott <dfe@tgwbd.org>
Wed, 8 Oct 2003 15:51:40 +0000 (15:51 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Wed, 8 Oct 2003 15:51:40 +0000 (15:51 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24125 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/cocoa/evtloop.mm

index bd1611587bf2d4bc245266f4e67d6b409252f968..d7870baa9adc0eff06552fde406ea4487c6a9b51 100644 (file)
@@ -17,6 +17,8 @@
 #include "wx/evtloop.h"
 
 #import <AppKit/NSApplication.h>
+#import <AppKit/NSEvent.h>
+#import <Foundation/NSRunLoop.h>
 
 // ========================================================================
 // wxEventLoopImpl
@@ -95,12 +97,30 @@ void wxEventLoop::Exit(int rc)
 
 bool wxEventLoop::Pending() const
 {
-    return 0;
+    // a pointer to the event is returned if there is one, or nil if not
+    return [[NSApplication sharedApplication]
+            nextEventMatchingMask: NSAnyEventMask
+            untilDate: nil /* Equivalent to [NSDate distantPast] */
+            inMode: NSDefaultRunLoopMode
+            dequeue: NO];
 }
 
 bool wxEventLoop::Dispatch()
 {
+    // This check is required by wxGTK but probably not really for wxCocoa
+    // Keep it here to encourage developers to write cross-platform code
     wxCHECK_MSG( IsRunning(), false, _T("can't call Dispatch() if not running") );
+    NSApplication *cocoaApp = [NSApplication sharedApplication];
+    // Block to retrieve an event then send it
+    if(NSEvent *event = [cocoaApp
+                nextEventMatchingMask:NSAnyEventMask
+                untilDate:[NSDate distantFuture]
+                inMode:NSDefaultRunLoopMode
+                dequeue: YES])
+    {
+        [cocoaApp sendEvent: event];
+        return true;
+    }
     return false;
 }