]> git.saurik.com Git - wxWidgets.git/commitdiff
osx-cocoa event loop
authorStefan Csomor <csomor@advancedconcepts.ch>
Fri, 22 Aug 2008 06:47:58 +0000 (06:47 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Fri, 22 Aug 2008 06:47:58 +0000 (06:47 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55166 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/osx/cocoa/evtloop.mm [new file with mode: 0644]

diff --git a/src/osx/cocoa/evtloop.mm b/src/osx/cocoa/evtloop.mm
new file mode 100644 (file)
index 0000000..a8a8c56
--- /dev/null
@@ -0,0 +1,93 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        src/osx/cocoa/evtloop.mm
+// Purpose:     implementation of wxEventLoop for OS X
+// Author:      Vadim Zeitlin, Stefan Csomor
+// Modified by:
+// Created:     2006-01-12
+// RCS-ID:      $Id: evtloop.cpp 54845 2008-07-30 14:52:41Z SC $
+// Copyright:   (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
+// Licence:     wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+// for compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+#include "wx/evtloop.h"
+
+#ifndef WX_PRECOMP
+    #include "wx/app.h"
+#endif // WX_PRECOMP
+
+#include "wx/osx/private.h"
+
+// ============================================================================
+// wxEventLoop implementation
+// ============================================================================
+
+wxGUIEventLoop::wxGUIEventLoop()
+{
+    m_sleepTime = 0.0;
+}
+
+void wxGUIEventLoop::WakeUp()
+{
+    extern void wxMacWakeUp();
+
+    wxMacWakeUp();
+}
+
+bool wxGUIEventLoop::Pending() const
+{
+    // a pointer to the event is returned if there is one, or nil if not
+    return [[NSApplication sharedApplication]
+            nextEventMatchingMask: NSAnyEventMask
+            untilDate: nil
+            inMode: NSDefaultRunLoopMode
+            dequeue: NO];
+}
+
+bool wxGUIEventLoop::Dispatch()
+{
+    if ( !wxTheApp )
+        return false;
+
+    wxMacAutoreleasePool autoreleasepool;
+
+    if(NSEvent *event = [NSApp
+                nextEventMatchingMask:NSAnyEventMask
+                untilDate:[NSDate dateWithTimeIntervalSinceNow: m_sleepTime]
+                inMode:NSDefaultRunLoopMode
+                dequeue: YES])
+    {
+        m_sleepTime = 0.0;
+        [NSApp sendEvent: event];
+    }
+    else
+    {
+        if ( wxTheApp->ProcessIdle() )
+            m_sleepTime = 0.0 ;
+        else
+        {
+            m_sleepTime = 1.0;
+#if wxUSE_THREADS
+            wxMutexGuiLeave();
+            wxMilliSleep(20);
+            wxMutexGuiEnter();
+#endif
+        }
+    }
+
+    return true;
+}