#include "wx/utils.h"
-class WXDLLEXPORT wxEventLoop;
-
// ----------------------------------------------------------------------------
// wxEventLoopBase: interface for wxEventLoop
// ----------------------------------------------------------------------------
// using it
virtual bool IsOk() const { return true; }
+
// start the event loop, return the exit code when it is finished
virtual int Run() = 0;
// 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 wxEventLoop *GetActive() { return ms_activeLoop; }
+ static wxEventLoopBase *GetActive() { return ms_activeLoop; }
// set currently active (running) event loop
- static void SetActive(wxEventLoop* loop) { ms_activeLoop = loop; }
+ static void SetActive(wxEventLoopBase* loop) { ms_activeLoop = loop; }
// is this event loop running now?
//
// the pointer to currently active loop
- static wxEventLoop *ms_activeLoop;
+ static wxEventLoopBase *ms_activeLoop;
DECLARE_NO_COPY_CLASS(wxEventLoopBase)
};
#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
-class WXDLLEXPORT wxEventLoopImpl;
+#include "wx/stopwatch.h" // for wxMilliClock_t
+
+class WXDLLIMPEXP_FWD_CORE wxEventLoopImpl;
-class WXDLLEXPORT wxGUIEventLoop : public wxEventLoopBase
+class WXDLLIMPEXP_CORE wxGUIEventLoop : public wxEventLoopBase
{
public:
wxGUIEventLoop() { m_impl = NULL; }
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:
#include "wx/unix/evtloop.h"
#endif
-// cannot use typedef because wxEventLoop is forward-declared in many places
+// we use a class rather than a typedef because wxEventLoop is forward-declared
+// in many places
#if wxUSE_GUI
-class wxEventLoop : public wxGUIEventLoop { };
-#elif defined(__WXMSW__) || defined(__UNIX__)
-class wxEventLoop : public wxConsoleEventLoop { };
-#else // we still must define it somehow for the code below...
-class wxEventLoop : public wxEventLoopBase { };
+ class wxEventLoop : public wxGUIEventLoop { };
+#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 wxUSE_CONSOLE_EVENTLOOP && (defined(__WXMSW__) || defined(__UNIX__))
+ #define wxEventLoop wxConsoleEventLoop
+ #else // we still must define it somehow for the code below...
+ #define wxEventLoop wxEventLoopBase
+ #endif
#endif
inline bool wxEventLoopBase::IsRunning() const { return GetActive() == this; }
// implement modality, we will surely need platform-specific implementations
// too, this generic implementation is here only temporarily to see how it
// works
-class WXDLLEXPORT wxModalEventLoop : public wxGUIEventLoop
+class WXDLLIMPEXP_CORE wxModalEventLoop : public wxGUIEventLoop
{
public:
wxModalEventLoop(wxWindow *winModal)
wxEventLoopActivator(wxEventLoopBase *evtLoop)
{
m_evtLoopOld = wxEventLoopBase::GetActive();
- wxEventLoopBase::SetActive(wx_static_cast(wxEventLoop *, evtLoop));
+ wxEventLoopBase::SetActive(evtLoop);
}
~wxEventLoopActivator()
}
private:
- wxEventLoop *m_evtLoopOld;
+ 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_