share wxEventLoop::IsRunning() implementation between all ports; moved wxEventLoopActivator used by it in wx/evtloop.h instead of duplicating it in 3 different .cpp files (and not using it at all in 3 other ones)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36842 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-01-12 16:56:48 +00:00
parent f29d3d6133
commit 77fb1a02aa
11 changed files with 44 additions and 116 deletions

View File

@@ -41,15 +41,18 @@ public:
// dispatch a single event, return false if we should exit from the loop
virtual bool Dispatch() = 0;
// is the event loop running now?
virtual bool IsRunning() const = 0;
// return currently active (running) event loop, may be NULL
static wxEventLoop *GetActive() { return ms_activeLoop; }
// set currently active (running) event loop
static void SetActive(wxEventLoop* loop) { ms_activeLoop = loop; }
// is this event loop running now?
//
// notice that even if this event loop hasn't terminated yet but has just
// spawned a nested (e.g. modal) event loop, this would return false
bool IsRunning() const;
protected:
// this function should be called before the event loop terminates, whether
// this happens normally (because of Exit() call) or abnormally (because of
@@ -86,7 +89,6 @@ public:
virtual void Exit(int rc = 0);
virtual bool Pending() const;
virtual bool Dispatch();
virtual bool IsRunning() const { return GetActive() == this; }
protected:
// the pointer to the port specific implementation class
@@ -97,6 +99,8 @@ protected:
#endif // __WXMSW__/!__WXMSW__
inline bool wxEventLoopBase::IsRunning() const { return GetActive() == this; }
// ----------------------------------------------------------------------------
// wxModalEventLoop
// ----------------------------------------------------------------------------
@@ -126,4 +130,30 @@ private:
wxWindowDisabler *m_windowDisabler;
};
// ----------------------------------------------------------------------------
// wxEventLoopActivator: helper class for wxEventLoop implementations
// ----------------------------------------------------------------------------
// this object sets the wxEventLoop given to the ctor as the currently active
// one and unsets it in its dtor, this is especially useful in presence of
// exceptions but is more tidy even when we don't use them
class wxEventLoopActivator
{
public:
wxEventLoopActivator(wxEventLoop *evtLoop)
{
m_evtLoopOld = wxEventLoop::GetActive();
wxEventLoop::SetActive(evtLoop);
}
~wxEventLoopActivator()
{
// restore the previously active event loop
wxEventLoop::SetActive(m_evtLoopOld);
}
private:
wxEventLoop *m_evtLoopOld;
};
#endif // _WX_EVTLOOP_H_