]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxEventLoopBase::DoRun().
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 3 Jul 2013 00:25:23 +0000 (00:25 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 3 Jul 2013 00:25:23 +0000 (00:25 +0000)
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

include/wx/cocoa/evtloop.h
include/wx/evtloop.h
include/wx/gtk/evtloop.h
include/wx/osx/core/evtloop.h
src/cocoa/evtloop.mm
src/common/evtloopcmn.cpp
src/gtk/evtloop.cpp
src/gtk1/evtloop.cpp
src/motif/evtloop.cpp
src/osx/core/evtloop_cf.cpp
src/x11/evtloop.cpp

index 7e0d4768090ff44e1e030a58686c7b897d3ffe15..0790014c9ad119dcd847c33fdcf4e736745396ab 100644 (file)
@@ -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);
index 24ea711ece39e20af4719d81b7bde9d2e5dcb6c4..52084d997dec5d5d88bbeabec2e4be5364731651 100644 (file)
@@ -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;
 
index d08356786232838577439ce8d9736ff1e91e6937..d7f5205f37919fc8c082c5b963bde1cecb698a41 100644 (file)
@@ -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;
index 85f2a6c9911fa012a2859d9c921311d386256811..02830f8c40d441d2522ff72584493b49606628f6 100644 (file)
@@ -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);
 
index a017688edc14f6582b417908e83cf73277c4c453..c73a2307d1ab5966cf77a0348c5e0991bcf24739 100644 (file)
 // 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();
index a9f7bfccf4914c230de4ff5184f662cbff351b97..2f922c248ddfb66c167bdf3f52f1767f6946568b 100644 (file)
@@ -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,
index cc118104d55a9dceae266e2a3e1e39f42457ab8f..68f65545e4cdc82aa845d706aded1e61d2129282 100644 (file)
@@ -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();
index d688c36365c12e210546e13dc91b4e5204ed8f26..5f4a91f9959882881f8cef04ca0546434cb8f4bb 100644 (file)
@@ -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();
index f5041784f4c3f60551b97a155bb0d2bb3d8dc8a2..7ec41cd123c6ee438c6401d2b0fd73595d55ad6d 100644 (file)
@@ -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 );
 
index 66178cccb79853b1153ce0ca8987ee2b7aca09f2..5ef10ae43215627e54fa1f4f81984a2fa9c21929 100644 (file)
@@ -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,
index 146fabde1495ee8ff7e83f2f27e7060643011c48..1f988f97620182e4019fa8432e2b3f9937176c5d 100644 (file)
@@ -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 )
     {