Add wxEventLoopBase::DoRun().
Call it from public Run() after setting the loop as active and resetting m_shouldExit flag. No real changes, just cut down on the code duplication among the ports and make it easier to implement the upcoming changes. see #10258. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74333 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -20,7 +20,6 @@ class WXDLLIMPEXP_CORE wxGUIEventLoop : public wxEventLoopBase
|
||||
public:
|
||||
wxGUIEventLoop() { m_exitcode = 0; }
|
||||
|
||||
virtual int Run();
|
||||
virtual void Exit(int rc = 0);
|
||||
virtual bool Pending() const;
|
||||
virtual bool Dispatch();
|
||||
@@ -29,6 +28,8 @@ public:
|
||||
virtual bool YieldFor(long eventsToProcess);
|
||||
|
||||
protected:
|
||||
virtual int DoRun();
|
||||
|
||||
int m_exitcode;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxGUIEventLoop);
|
||||
|
@@ -88,7 +88,10 @@ public:
|
||||
// -------------------
|
||||
|
||||
// start the event loop, return the exit code when it is finished
|
||||
virtual int Run() = 0;
|
||||
//
|
||||
// notice that wx ports should override DoRun(), this method is virtual
|
||||
// only to allow overriding it in the user code for custom event loops
|
||||
virtual int Run();
|
||||
|
||||
// is this event loop running now?
|
||||
//
|
||||
@@ -169,6 +172,9 @@ public:
|
||||
|
||||
|
||||
protected:
|
||||
// real implementation of Run()
|
||||
virtual int DoRun() = 0;
|
||||
|
||||
// this function should be called before the event loop terminates, whether
|
||||
// this happens normally (because of Exit() call) or abnormally (because of
|
||||
// an exception thrown from inside the loop)
|
||||
@@ -198,15 +204,15 @@ class WXDLLIMPEXP_BASE wxEventLoopManual : public wxEventLoopBase
|
||||
public:
|
||||
wxEventLoopManual();
|
||||
|
||||
// enters a loop calling OnNextIteration(), Pending() and Dispatch() and
|
||||
// terminating when Exit() is called
|
||||
virtual int Run();
|
||||
|
||||
// sets the "should exit" flag and wakes up the loop so that it terminates
|
||||
// soon
|
||||
virtual void Exit(int rc = 0);
|
||||
|
||||
protected:
|
||||
// enters a loop calling OnNextIteration(), Pending() and Dispatch() and
|
||||
// terminating when Exit() is called
|
||||
virtual int DoRun();
|
||||
|
||||
// may be overridden to perform some action at the start of each new event
|
||||
// loop iteration
|
||||
virtual void OnNextIteration() { }
|
||||
@@ -285,7 +291,6 @@ public:
|
||||
}
|
||||
#endif // wxUSE_EVENTLOOP_SOURCE
|
||||
|
||||
virtual int Run();
|
||||
virtual void Exit(int rc = 0);
|
||||
virtual bool Pending() const;
|
||||
virtual bool Dispatch();
|
||||
@@ -307,6 +312,8 @@ public:
|
||||
virtual bool YieldFor(long eventsToProcess);
|
||||
|
||||
protected:
|
||||
virtual int DoRun();
|
||||
|
||||
// the pointer to the port specific implementation class
|
||||
wxEventLoopImpl *m_impl;
|
||||
|
||||
|
@@ -22,7 +22,6 @@ class WXDLLIMPEXP_CORE wxGUIEventLoop : public wxEventLoopBase
|
||||
public:
|
||||
wxGUIEventLoop();
|
||||
|
||||
virtual int Run();
|
||||
virtual void Exit(int rc = 0);
|
||||
virtual bool Pending() const;
|
||||
virtual bool Dispatch();
|
||||
@@ -38,6 +37,9 @@ public:
|
||||
void StoreGdkEventForLaterProcessing(GdkEvent* ev)
|
||||
{ m_arrGdkEvents.Add(ev); }
|
||||
|
||||
protected:
|
||||
virtual int DoRun();
|
||||
|
||||
private:
|
||||
// the exit code of this event loop
|
||||
int m_exitcode;
|
||||
|
@@ -24,10 +24,6 @@ public:
|
||||
wxCFEventLoop();
|
||||
virtual ~wxCFEventLoop();
|
||||
|
||||
// enters a loop calling OnNextIteration(), Pending() and Dispatch() and
|
||||
// terminating when Exit() is called
|
||||
virtual int Run();
|
||||
|
||||
// sets the "should exit" flag and wakes up the loop so that it terminates
|
||||
// soon
|
||||
virtual void Exit(int rc = 0);
|
||||
@@ -63,6 +59,10 @@ public:
|
||||
void SetShouldWaitForEvent(bool should) { m_shouldWaitForEvent = should; }
|
||||
#endif
|
||||
protected:
|
||||
// enters a loop calling OnNextIteration(), Pending() and Dispatch() and
|
||||
// terminating when Exit() is called
|
||||
virtual int DoRun();
|
||||
|
||||
void CommonModeObserverCallBack(CFRunLoopObserverRef observer, int activity);
|
||||
void DefaultModeObserverCallBack(CFRunLoopObserverRef observer, int activity);
|
||||
|
||||
|
@@ -30,13 +30,8 @@
|
||||
// wxGUIEventLoop running and exiting
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int wxGUIEventLoop::Run()
|
||||
int wxGUIEventLoop::DoRun()
|
||||
{
|
||||
// event loops are not recursive, you need to create another loop!
|
||||
wxCHECK_MSG( !IsRunning(), -1, wxT("can't reenter a message loop") );
|
||||
|
||||
wxEventLoopActivator activate(this);
|
||||
|
||||
[[NSApplication sharedApplication] run];
|
||||
|
||||
OnExit();
|
||||
|
@@ -52,6 +52,24 @@ void wxEventLoopBase::SetActive(wxEventLoopBase* loop)
|
||||
wxTheApp->OnEventLoopEnter(loop);
|
||||
}
|
||||
|
||||
int wxEventLoopBase::Run()
|
||||
{
|
||||
// event loops are not recursive, you need to create another loop!
|
||||
wxCHECK_MSG( !IsRunning(), -1, wxT("can't reenter a message loop") );
|
||||
|
||||
// ProcessIdle() and ProcessEvents() below may throw so the code here should
|
||||
// be exception-safe, hence we must use local objects for all actions we
|
||||
// should undo
|
||||
wxEventLoopActivator activate(this);
|
||||
|
||||
// We might be called again, after a previous call to ScheduleExit(), so
|
||||
// reset this flag.
|
||||
m_shouldExit = false;
|
||||
|
||||
// Finally really run the loop.
|
||||
return DoRun();
|
||||
}
|
||||
|
||||
void wxEventLoopBase::OnExit()
|
||||
{
|
||||
if (wxTheApp)
|
||||
@@ -118,16 +136,8 @@ bool wxEventLoopManual::ProcessEvents()
|
||||
return Dispatch();
|
||||
}
|
||||
|
||||
int wxEventLoopManual::Run()
|
||||
int wxEventLoopManual::DoRun()
|
||||
{
|
||||
// event loops are not recursive, you need to create another loop!
|
||||
wxCHECK_MSG( !IsRunning(), -1, wxT("can't reenter a message loop") );
|
||||
|
||||
// ProcessIdle() and ProcessEvents() below may throw so the code here should
|
||||
// be exception-safe, hence we must use local objects for all actions we
|
||||
// should undo
|
||||
wxEventLoopActivator activate(this);
|
||||
|
||||
// we must ensure that OnExit() is called even if an exception is thrown
|
||||
// from inside ProcessEvents() but we must call it from Exit() in normal
|
||||
// situations because it is supposed to be called synchronously,
|
||||
|
@@ -50,13 +50,8 @@ wxGUIEventLoop::wxGUIEventLoop()
|
||||
m_exitcode = 0;
|
||||
}
|
||||
|
||||
int wxGUIEventLoop::Run()
|
||||
int wxGUIEventLoop::DoRun()
|
||||
{
|
||||
// event loops are not recursive, you need to create another loop!
|
||||
wxCHECK_MSG( !IsRunning(), -1, "can't reenter a message loop" );
|
||||
|
||||
wxEventLoopActivator activate(this);
|
||||
|
||||
gtk_main();
|
||||
|
||||
OnExit();
|
||||
|
@@ -65,13 +65,8 @@ wxGUIEventLoop::~wxGUIEventLoop()
|
||||
wxASSERT_MSG( !m_impl, wxT("should have been deleted in Run()") );
|
||||
}
|
||||
|
||||
int wxGUIEventLoop::Run()
|
||||
int wxGUIEventLoop::DoRun()
|
||||
{
|
||||
// event loops are not recursive, you need to create another loop!
|
||||
wxCHECK_MSG( !IsRunning(), -1, wxT("can't reenter a message loop") );
|
||||
|
||||
wxEventLoopActivator activate(this);
|
||||
|
||||
m_impl = new wxEventLoopImpl;
|
||||
|
||||
gtk_main();
|
||||
|
@@ -102,13 +102,8 @@ wxGUIEventLoop::~wxGUIEventLoop()
|
||||
wxASSERT_MSG( !m_impl, wxT("should have been deleted in Run()") );
|
||||
}
|
||||
|
||||
int wxGUIEventLoop::Run()
|
||||
int wxGUIEventLoop::DoRun()
|
||||
{
|
||||
// event loops are not recursive, you need to create another loop!
|
||||
wxCHECK_MSG( !IsRunning(), -1, wxT("can't reenter a message loop") );
|
||||
|
||||
wxEventLoopActivator activate(this);
|
||||
|
||||
m_impl = new wxEventLoopImpl;
|
||||
m_impl->SetKeepGoing( true );
|
||||
|
||||
|
@@ -392,16 +392,8 @@ void wxCFEventLoop::OSXDoStop()
|
||||
|
||||
// enters a loop calling OnNextIteration(), Pending() and Dispatch() and
|
||||
// terminating when Exit() is called
|
||||
int wxCFEventLoop::Run()
|
||||
int wxCFEventLoop::DoRun()
|
||||
{
|
||||
// event loops are not recursive, you need to create another loop!
|
||||
wxCHECK_MSG( !IsRunning(), -1, wxT("can't reenter a message loop") );
|
||||
|
||||
// ProcessIdle() and ProcessEvents() below may throw so the code here should
|
||||
// be exception-safe, hence we must use local objects for all actions we
|
||||
// should undo
|
||||
wxEventLoopActivator activate(this);
|
||||
|
||||
// we must ensure that OnExit() is called even if an exception is thrown
|
||||
// from inside ProcessEvents() but we must call it from Exit() in normal
|
||||
// situations because it is supposed to be called synchronously,
|
||||
|
@@ -125,15 +125,10 @@ wxGUIEventLoop::~wxGUIEventLoop()
|
||||
wxASSERT_MSG( !m_impl, wxT("should have been deleted in Run()") );
|
||||
}
|
||||
|
||||
int wxGUIEventLoop::Run()
|
||||
int wxGUIEventLoop::DoRun()
|
||||
{
|
||||
// event loops are not recursive, you need to create another loop!
|
||||
wxCHECK_MSG( !m_impl, -1, wxT("can't reenter a message loop") );
|
||||
|
||||
m_impl = new wxEventLoopImpl;
|
||||
|
||||
wxEventLoopActivator activate(this);
|
||||
|
||||
m_impl->m_keepGoing = true;
|
||||
while ( m_impl->m_keepGoing )
|
||||
{
|
||||
|
Reference in New Issue
Block a user