public:
wxGUIEventLoop() { m_exitcode = 0; }
- virtual int Run();
virtual void Exit(int rc = 0);
virtual bool Pending() const;
virtual bool Dispatch();
virtual bool YieldFor(long eventsToProcess);
protected:
+ virtual int DoRun();
+
int m_exitcode;
wxDECLARE_NO_COPY_CLASS(wxGUIEventLoop);
// -------------------
// 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?
//
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)
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() { }
}
#endif // wxUSE_EVENTLOOP_SOURCE
- virtual int Run();
virtual void Exit(int rc = 0);
virtual bool Pending() const;
virtual bool Dispatch();
virtual bool YieldFor(long eventsToProcess);
protected:
+ virtual int DoRun();
+
// the pointer to the port specific implementation class
wxEventLoopImpl *m_impl;
public:
wxGUIEventLoop();
- virtual int Run();
virtual void Exit(int rc = 0);
virtual bool Pending() const;
virtual bool Dispatch();
void StoreGdkEventForLaterProcessing(GdkEvent* ev)
{ m_arrGdkEvents.Add(ev); }
+protected:
+ virtual int DoRun();
+
private:
// the exit code of this event loop
int m_exitcode;
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);
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);
// 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();
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)
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,
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();
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();
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 );
// 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,
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 )
{