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:
@@ -41,15 +41,18 @@ public:
|
|||||||
// dispatch a single event, return false if we should exit from the loop
|
// dispatch a single event, return false if we should exit from the loop
|
||||||
virtual bool Dispatch() = 0;
|
virtual bool Dispatch() = 0;
|
||||||
|
|
||||||
// is the event loop running now?
|
|
||||||
virtual bool IsRunning() const = 0;
|
|
||||||
|
|
||||||
// return currently active (running) event loop, may be NULL
|
// return currently active (running) event loop, may be NULL
|
||||||
static wxEventLoop *GetActive() { return ms_activeLoop; }
|
static wxEventLoop *GetActive() { return ms_activeLoop; }
|
||||||
|
|
||||||
// set currently active (running) event loop
|
// set currently active (running) event loop
|
||||||
static void SetActive(wxEventLoop* loop) { ms_activeLoop = 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:
|
protected:
|
||||||
// this function should be called before the event loop terminates, whether
|
// this function should be called before the event loop terminates, whether
|
||||||
// this happens normally (because of Exit() call) or abnormally (because of
|
// this happens normally (because of Exit() call) or abnormally (because of
|
||||||
@@ -86,7 +89,6 @@ public:
|
|||||||
virtual void Exit(int rc = 0);
|
virtual void Exit(int rc = 0);
|
||||||
virtual bool Pending() const;
|
virtual bool Pending() const;
|
||||||
virtual bool Dispatch();
|
virtual bool Dispatch();
|
||||||
virtual bool IsRunning() const { return GetActive() == this; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// the pointer to the port specific implementation class
|
// the pointer to the port specific implementation class
|
||||||
@@ -97,6 +99,8 @@ protected:
|
|||||||
|
|
||||||
#endif // __WXMSW__/!__WXMSW__
|
#endif // __WXMSW__/!__WXMSW__
|
||||||
|
|
||||||
|
inline bool wxEventLoopBase::IsRunning() const { return GetActive() == this; }
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxModalEventLoop
|
// wxModalEventLoop
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -126,4 +130,30 @@ private:
|
|||||||
wxWindowDisabler *m_windowDisabler;
|
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_
|
#endif // _WX_EVTLOOP_H_
|
||||||
|
@@ -26,7 +26,6 @@ public:
|
|||||||
virtual void Exit(int rc = 0);
|
virtual void Exit(int rc = 0);
|
||||||
virtual bool Pending() const;
|
virtual bool Pending() const;
|
||||||
virtual bool Dispatch();
|
virtual bool Dispatch();
|
||||||
virtual bool IsRunning() const;
|
|
||||||
|
|
||||||
// MSW-specific methods
|
// MSW-specific methods
|
||||||
// --------------------
|
// --------------------
|
||||||
|
@@ -60,8 +60,7 @@ int wxEventLoop::Run()
|
|||||||
// event loops are not recursive, you need to create another loop!
|
// event loops are not recursive, you need to create another loop!
|
||||||
wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
|
wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
|
||||||
|
|
||||||
wxEventLoop *oldLoop = ms_activeLoop;
|
wxEventLoopActivator activate(this);
|
||||||
ms_activeLoop = this;
|
|
||||||
|
|
||||||
m_impl = new wxEventLoopImpl;
|
m_impl = new wxEventLoopImpl;
|
||||||
|
|
||||||
@@ -71,8 +70,6 @@ int wxEventLoop::Run()
|
|||||||
delete m_impl;
|
delete m_impl;
|
||||||
m_impl = NULL;
|
m_impl = NULL;
|
||||||
|
|
||||||
ms_activeLoop = oldLoop;
|
|
||||||
|
|
||||||
return exitcode;
|
return exitcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -68,8 +68,7 @@ int wxEventLoop::Run()
|
|||||||
// event loops are not recursive, you need to create another loop!
|
// event loops are not recursive, you need to create another loop!
|
||||||
wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
|
wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
|
||||||
|
|
||||||
wxEventLoop *oldLoop = ms_activeLoop;
|
wxEventLoopActivator activate(this);
|
||||||
ms_activeLoop = this;
|
|
||||||
|
|
||||||
m_impl = new wxEventLoopImpl;
|
m_impl = new wxEventLoopImpl;
|
||||||
|
|
||||||
@@ -79,8 +78,6 @@ int wxEventLoop::Run()
|
|||||||
delete m_impl;
|
delete m_impl;
|
||||||
m_impl = NULL;
|
m_impl = NULL;
|
||||||
|
|
||||||
ms_activeLoop = oldLoop;
|
|
||||||
|
|
||||||
return exitcode;
|
return exitcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -68,8 +68,7 @@ int wxEventLoop::Run()
|
|||||||
// event loops are not recursive, you need to create another loop!
|
// event loops are not recursive, you need to create another loop!
|
||||||
wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
|
wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
|
||||||
|
|
||||||
wxEventLoop *oldLoop = ms_activeLoop;
|
wxEventLoopActivator activate(this);
|
||||||
ms_activeLoop = this;
|
|
||||||
|
|
||||||
m_impl = new wxEventLoopImpl;
|
m_impl = new wxEventLoopImpl;
|
||||||
|
|
||||||
@@ -79,8 +78,6 @@ int wxEventLoop::Run()
|
|||||||
delete m_impl;
|
delete m_impl;
|
||||||
m_impl = NULL;
|
m_impl = NULL;
|
||||||
|
|
||||||
ms_activeLoop = oldLoop;
|
|
||||||
|
|
||||||
return exitcode;
|
return exitcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -118,8 +118,7 @@ int wxEventLoop::Run()
|
|||||||
|
|
||||||
m_impl = new wxEventLoopImpl;
|
m_impl = new wxEventLoopImpl;
|
||||||
|
|
||||||
wxEventLoop *oldLoop = ms_activeLoop;
|
wxEventLoopActivator activate(this);
|
||||||
ms_activeLoop = this;
|
|
||||||
|
|
||||||
for ( ;; )
|
for ( ;; )
|
||||||
{
|
{
|
||||||
@@ -144,8 +143,6 @@ int wxEventLoop::Run()
|
|||||||
delete m_impl;
|
delete m_impl;
|
||||||
m_impl = NULL;
|
m_impl = NULL;
|
||||||
|
|
||||||
ms_activeLoop = oldLoop;
|
|
||||||
|
|
||||||
return exitcode;
|
return exitcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -108,8 +108,7 @@ int wxEventLoop::Run()
|
|||||||
// event loops are not recursive, you need to create another loop!
|
// event loops are not recursive, you need to create another loop!
|
||||||
wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
|
wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
|
||||||
|
|
||||||
wxEventLoop *oldLoop = ms_activeLoop;
|
wxEventLoopActivator activate(this);
|
||||||
ms_activeLoop = this;
|
|
||||||
|
|
||||||
m_impl = new wxEventLoopImpl;
|
m_impl = new wxEventLoopImpl;
|
||||||
m_impl->SetKeepGoing( true );
|
m_impl->SetKeepGoing( true );
|
||||||
@@ -124,8 +123,6 @@ int wxEventLoop::Run()
|
|||||||
delete m_impl;
|
delete m_impl;
|
||||||
m_impl = NULL;
|
m_impl = NULL;
|
||||||
|
|
||||||
ms_activeLoop = oldLoop;
|
|
||||||
|
|
||||||
return exitcode;
|
return exitcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -48,34 +48,6 @@
|
|||||||
WX_DEFINE_LIST(wxMsgList)
|
WX_DEFINE_LIST(wxMsgList)
|
||||||
#endif // wxUSE_THREADS
|
#endif // wxUSE_THREADS
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// helper class
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// this object sets the wxEventLoop given to the ctor as the currently active
|
|
||||||
// one and unsets it in its dtor
|
|
||||||
class wxEventLoopActivator
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
wxEventLoopActivator(wxEventLoop **pActive,
|
|
||||||
wxEventLoop *evtLoop)
|
|
||||||
{
|
|
||||||
m_pActive = pActive;
|
|
||||||
m_evtLoopOld = *pActive;
|
|
||||||
*pActive = evtLoop;
|
|
||||||
}
|
|
||||||
|
|
||||||
~wxEventLoopActivator()
|
|
||||||
{
|
|
||||||
// restore the previously active event loop
|
|
||||||
*m_pActive = m_evtLoopOld;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
wxEventLoop *m_evtLoopOld;
|
|
||||||
wxEventLoop **m_pActive;
|
|
||||||
};
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// wxEventLoop implementation
|
// wxEventLoop implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -223,11 +195,6 @@ bool wxEventLoop::PreProcessMessage(WXMSG *msg)
|
|||||||
// wxEventLoop running and exiting
|
// wxEventLoop running and exiting
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool wxEventLoop::IsRunning() const
|
|
||||||
{
|
|
||||||
return ms_activeLoop == this;
|
|
||||||
}
|
|
||||||
|
|
||||||
int wxEventLoop::Run()
|
int wxEventLoop::Run()
|
||||||
{
|
{
|
||||||
// event loops are not recursive, you need to create another loop!
|
// event loops are not recursive, you need to create another loop!
|
||||||
@@ -236,7 +203,7 @@ int wxEventLoop::Run()
|
|||||||
// ProcessIdle() and Dispatch() below may throw so the code here should
|
// ProcessIdle() and Dispatch() below may throw so the code here should
|
||||||
// be exception-safe, hence we must use local objects for all actions we
|
// be exception-safe, hence we must use local objects for all actions we
|
||||||
// should undo
|
// should undo
|
||||||
wxEventLoopActivator activate(&ms_activeLoop, this);
|
wxEventLoopActivator activate(this);
|
||||||
|
|
||||||
// we must ensure that OnExit() is called even if an exception is thrown
|
// we must ensure that OnExit() is called even if an exception is thrown
|
||||||
// from inside Dispatch() but we must call it from Exit() in normal
|
// from inside Dispatch() but we must call it from Exit() in normal
|
||||||
|
@@ -83,30 +83,6 @@ private:
|
|||||||
|
|
||||||
wxDEFINE_TIED_SCOPED_PTR_TYPE(wxEventLoopImpl);
|
wxDEFINE_TIED_SCOPED_PTR_TYPE(wxEventLoopImpl);
|
||||||
|
|
||||||
// this object sets the wxEventLoop given to the ctor as the currently active
|
|
||||||
// one and unsets it in its dtor
|
|
||||||
class wxEventLoopActivator
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
wxEventLoopActivator(wxEventLoop **pActive,
|
|
||||||
wxEventLoop *evtLoop)
|
|
||||||
{
|
|
||||||
m_pActive = pActive;
|
|
||||||
m_evtLoopOld = *pActive;
|
|
||||||
*pActive = evtLoop;
|
|
||||||
}
|
|
||||||
|
|
||||||
~wxEventLoopActivator()
|
|
||||||
{
|
|
||||||
// restore the previously active event loop
|
|
||||||
*m_pActive = m_evtLoopOld;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
wxEventLoop *m_evtLoopOld;
|
|
||||||
wxEventLoop **m_pActive;
|
|
||||||
};
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// wxEventLoopImpl implementation
|
// wxEventLoopImpl implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -271,7 +247,7 @@ int wxEventLoop::Run()
|
|||||||
// SendIdleMessage() and Dispatch() below may throw so the code here should
|
// SendIdleMessage() and Dispatch() below may throw so the code here should
|
||||||
// be exception-safe, hence we must use local objects for all actions we
|
// be exception-safe, hence we must use local objects for all actions we
|
||||||
// should undo
|
// should undo
|
||||||
wxEventLoopActivator activate(&ms_activeLoop, this);
|
wxEventLoopActivator activate(this);
|
||||||
wxEventLoopImplTiedPtr impl(&m_impl, new wxEventLoopImpl);
|
wxEventLoopImplTiedPtr impl(&m_impl, new wxEventLoopImpl);
|
||||||
|
|
||||||
CallEventLoopMethod callOnExit(this, &wxEventLoop::OnExit);
|
CallEventLoopMethod callOnExit(this, &wxEventLoop::OnExit);
|
||||||
|
@@ -51,34 +51,6 @@
|
|||||||
#include <Menu.h>
|
#include <Menu.h>
|
||||||
#include <Form.h>
|
#include <Form.h>
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// helper class
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// this object sets the wxEventLoop given to the ctor as the currently active
|
|
||||||
// one and unsets it in its dtor
|
|
||||||
class wxEventLoopActivator
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
wxEventLoopActivator(wxEventLoop **pActive,
|
|
||||||
wxEventLoop *evtLoop)
|
|
||||||
{
|
|
||||||
m_pActive = pActive;
|
|
||||||
m_evtLoopOld = *pActive;
|
|
||||||
*pActive = evtLoop;
|
|
||||||
}
|
|
||||||
|
|
||||||
~wxEventLoopActivator()
|
|
||||||
{
|
|
||||||
// restore the previously active event loop
|
|
||||||
*m_pActive = m_evtLoopOld;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
wxEventLoop *m_evtLoopOld;
|
|
||||||
wxEventLoop **m_pActive;
|
|
||||||
};
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// wxEventLoop implementation
|
// wxEventLoop implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -122,6 +94,8 @@ int wxEventLoop::Run()
|
|||||||
status_t error;
|
status_t error;
|
||||||
EventType event;
|
EventType event;
|
||||||
|
|
||||||
|
wxEventLoopActivator activate(this);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
wxTheApp && wxTheApp->ProcessIdle();
|
wxTheApp && wxTheApp->ProcessIdle();
|
||||||
|
|
||||||
|
@@ -357,8 +357,7 @@ int wxEventLoop::Run()
|
|||||||
|
|
||||||
m_impl = new wxEventLoopImpl;
|
m_impl = new wxEventLoopImpl;
|
||||||
|
|
||||||
wxEventLoop *oldLoop = ms_activeLoop;
|
wxEventLoopActivator activate(this);
|
||||||
ms_activeLoop = this;
|
|
||||||
|
|
||||||
m_impl->m_keepGoing = TRUE;
|
m_impl->m_keepGoing = TRUE;
|
||||||
while ( m_impl->m_keepGoing )
|
while ( m_impl->m_keepGoing )
|
||||||
@@ -400,8 +399,6 @@ int wxEventLoop::Run()
|
|||||||
delete m_impl;
|
delete m_impl;
|
||||||
m_impl = NULL;
|
m_impl = NULL;
|
||||||
|
|
||||||
ms_activeLoop = oldLoop;
|
|
||||||
|
|
||||||
return exitcode;
|
return exitcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user