From 914073189107fb2f0f4f78d7c98fbcc37c700d50 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 28 Dec 2008 14:32:49 +0000 Subject: [PATCH] implement DispatchTimeout() for wxOSX/Cocoa git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57621 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- Makefile.in | 1 + build/bakefiles/files.bkl | 1 + include/wx/osx/cocoa/evtloop.h | 31 +++++++++++++++++++++++++++++++ include/wx/osx/evtloop.h | 4 ++-- src/osx/cocoa/evtloop.mm | 17 +++++++++++++++++ 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 include/wx/osx/cocoa/evtloop.h diff --git a/Makefile.in b/Makefile.in index 9cb64789aa..78b0864850 100644 --- a/Makefile.in +++ b/Makefile.in @@ -3070,6 +3070,7 @@ COND_TOOLKIT_OSX_COCOA_GUI_HDR = \ wx/osx/uma.h \ wx/osx/window.h \ wx/osx/cocoa/chkconf.h \ + wx/osx/cocoa/evtloop.h \ wx/osx/cocoa/private.h \ wx/osx/core/colour.h \ wx/osx/carbon/accel.h \ diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 42fd51abb0..d2ea2993c9 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -2522,6 +2522,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! wx/osx/cocoa/chkconf.h + wx/osx/cocoa/evtloop.h wx/osx/cocoa/private.h $(OSX_CARBON_HDR) wx/generic/region.h diff --git a/include/wx/osx/cocoa/evtloop.h b/include/wx/osx/cocoa/evtloop.h new file mode 100644 index 0000000000..ed222c2bcb --- /dev/null +++ b/include/wx/osx/cocoa/evtloop.h @@ -0,0 +1,31 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/osx/cocoa/evtloop.h +// Purpose: declaration of wxGUIEventLoop for wxOSX/Cocoa +// Author: Vadim Zeitlin +// Created: 2008-12-28 +// RCS-ID: $Id$ +// Copyright: (c) 2006 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_OSX_COCOA_EVTLOOP_H_ +#define _WX_OSX_COCOA_EVTLOOP_H_ + +class WXDLLIMPEXP_CORE wxGUIEventLoop : public wxEventLoopManual +{ +public: + wxGUIEventLoop(); + + // implement/override base class pure virtual + virtual bool Pending() const; + virtual bool Dispatch(); + virtual int DispatchTimeout(unsigned long timeout); + + virtual void WakeUp(); + +private: + double m_sleepTime; +}; + +#endif // _WX_OSX_COCOA_EVTLOOP_H_ + diff --git a/include/wx/osx/evtloop.h b/include/wx/osx/evtloop.h index 19410d62d8..7b1b1f5f5d 100644 --- a/include/wx/osx/evtloop.h +++ b/include/wx/osx/evtloop.h @@ -10,8 +10,8 @@ // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// -#ifdef __WXMAC_CLASSIC__ - #error "wxEventLoop is not implemented for Classic build." +#ifdef __WXOSX_COCOA__ + #include "wx/osx/cocoa/evtloop.h" #else #include "wx/osx/carbon/evtloop.h" #endif diff --git a/src/osx/cocoa/evtloop.mm b/src/osx/cocoa/evtloop.mm index d7082f1578..1d607f9eaf 100644 --- a/src/osx/cocoa/evtloop.mm +++ b/src/osx/cocoa/evtloop.mm @@ -92,3 +92,20 @@ bool wxGUIEventLoop::Dispatch() return true; } + +int wxGUIEventLoop::DispatchTimeout(unsigned long timeout) +{ + wxMacAutoreleasePool autoreleasepool; + + NSEvent *event = [NSApp + nextEventMatchingMask:NSAnyEventMask + untilDate:[NSDate dateWithTimeIntervalSinceNow: timeout/1000] + inMode:NSDefaultRunLoopMode + dequeue: YES]; + if ( !event ) + return -1; + + [NSApp sendEvent: event]; + + return true; +} -- 2.45.2