X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/53a2db124c633f80bdb16336084262037d879a2c..6dbf7a375093d1e94aadb61f8d6759e820a9256d:/include/wx/evtloop.h diff --git a/include/wx/evtloop.h b/include/wx/evtloop.h index 6a573d713c..6841c61fd0 100644 --- a/include/wx/evtloop.h +++ b/include/wx/evtloop.h @@ -31,6 +31,7 @@ public: // using it virtual bool IsOk() const { return true; } + // start the event loop, return the exit code when it is finished virtual int Run() = 0; @@ -43,6 +44,12 @@ public: // dispatch a single event, return false if we should exit from the loop virtual bool Dispatch() = 0; + // same as Dispatch() but doesn't wait for longer than the specified (in + // ms) timeout, return true if an event was processed, false if we should + // exit the loop or -1 if timeout expired + virtual int DispatchTimeout(unsigned long timeout) = 0; + + // return currently active (running) event loop, may be NULL static wxEventLoopBase *GetActive() { return ms_activeLoop; } @@ -116,11 +123,17 @@ protected: #elif defined(__WXMSW__) #include "wx/msw/evtloop.h" #elif defined(__WXMAC__) - #include "wx/mac/evtloop.h" + #include "wx/osx/evtloop.h" +#elif defined(__WXCOCOA__) + #include "wx/cocoa/evtloop.h" #elif defined(__WXDFB__) #include "wx/dfb/evtloop.h" +#elif defined(__WXGTK20__) + #include "wx/gtk/evtloop.h" #else // other platform +#include "wx/stopwatch.h" // for wxMilliClock_t + class WXDLLIMPEXP_FWD_CORE wxEventLoopImpl; class WXDLLIMPEXP_CORE wxGUIEventLoop : public wxEventLoopBase @@ -133,6 +146,20 @@ public: virtual void Exit(int rc = 0); virtual bool Pending() const; virtual bool Dispatch(); + virtual int DispatchTimeout(unsigned long timeout) + { + // TODO: this is, of course, horribly inefficient and a proper wait with + // timeout should be implemented for all ports natively... + const wxMilliClock_t timeEnd = wxGetLocalTimeMillis() + timeout; + for ( ;; ) + { + if ( Pending() ) + return Dispatch(); + + if ( wxGetLocalTimeMillis() >= timeEnd ) + return -1; + } + } virtual void WakeUp() { } protected: @@ -156,7 +183,7 @@ protected: #else // !GUI // we can't define wxEventLoop differently in GUI and base libraries so use // a #define to still allow writing wxEventLoop in the user code - #if defined(__WXMSW__) || defined(__UNIX__) + #if wxUSE_CONSOLE_EVENTLOOP && (defined(__WXMSW__) || defined(__UNIX__)) #define wxEventLoop wxConsoleEventLoop #else // we still must define it somehow for the code below... #define wxEventLoop wxEventLoopBase @@ -223,4 +250,34 @@ private: wxEventLoopBase *m_evtLoopOld; }; +#if wxUSE_CONSOLE_EVENTLOOP + +class wxEventLoopGuarantor +{ +public: + wxEventLoopGuarantor() + { + m_evtLoopNew = NULL; + if (!wxEventLoop::GetActive()) + { + m_evtLoopNew = new wxEventLoop; + wxEventLoop::SetActive(m_evtLoopNew); + } + } + + ~wxEventLoopGuarantor() + { + if (m_evtLoopNew) + { + wxEventLoop::SetActive(NULL); + delete m_evtLoopNew; + } + } + +private: + wxEventLoop *m_evtLoopNew; +}; + +#endif // wxUSE_CONSOLE_EVENTLOOP + #endif // _WX_EVTLOOP_H_