+wxEventLoopBase::wxEventLoopBase()
+{
+ m_isInsideRun = false;
+ m_shouldExit = false;
+
+ m_isInsideYield = false;
+ m_eventsToProcessInsideYield = wxEVT_CATEGORY_ALL;
+}
+
+bool wxEventLoopBase::IsMain() const
+{
+ if (wxTheApp)
+ return wxTheApp->GetMainLoop() == this;
+ return false;
+}
+
+/* static */
+void wxEventLoopBase::SetActive(wxEventLoopBase* loop)
+{
+ ms_activeLoop = loop;
+
+ if (wxTheApp)
+ wxTheApp->OnEventLoopEnter(loop);
+}
+
+int wxEventLoopBase::Run()
+{
+ // event loops are not recursive, you need to create another loop!
+ wxCHECK_MSG( !IsInsideRun(), -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;
+
+ // Set this variable to true for the duration of this method.
+ m_isInsideRun = true;
+ wxON_BLOCK_EXIT_SET(m_isInsideRun, false);
+
+ // Finally really run the loop.
+ return DoRun();
+}
+
+void wxEventLoopBase::Exit(int rc)
+{
+ wxCHECK_RET( IsRunning(), wxS("Use ScheduleExit() on not running loop") );
+
+ ScheduleExit(rc);
+}
+
+void wxEventLoopBase::OnExit()
+{
+ if (wxTheApp)
+ wxTheApp->OnEventLoopExit(this);
+}
+
+void wxEventLoopBase::WakeUpIdle()
+{
+ WakeUp();
+}
+
+bool wxEventLoopBase::ProcessIdle()
+{
+ return wxTheApp && wxTheApp->ProcessIdle();
+}
+
+bool wxEventLoopBase::Yield(bool onlyIfNeeded)
+{
+ if ( m_isInsideYield )
+ {
+ if ( !onlyIfNeeded )
+ {
+ wxFAIL_MSG( wxT("wxYield called recursively" ) );
+ }
+
+ return false;
+ }
+
+ return YieldFor(wxEVT_CATEGORY_ALL);
+}
+
+#if wxUSE_EVENTLOOP_SOURCE
+
+wxEventLoopSource*
+wxEventLoopBase::AddSourceForFD(int fd,
+ wxEventLoopSourceHandler *handler,
+ int flags)
+{
+#if wxUSE_CONSOLE_EVENTLOOP
+ // Delegate to the event loop sources manager defined by it.
+ wxEventLoopSourcesManagerBase* const
+ manager = wxApp::GetValidTraits().GetEventLoopSourcesManager();
+ wxCHECK_MSG( manager, NULL, wxS("Must have wxEventLoopSourcesManager") );
+
+ return manager->AddSourceForFD(fd, handler, flags);
+#else // !wxUSE_CONSOLE_EVENTLOOP
+ return NULL;
+#endif // wxUSE_CONSOLE_EVENTLOOP/!wxUSE_CONSOLE_EVENTLOOP
+}
+
+#endif // wxUSE_EVENTLOOP_SOURCE
+