X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f24391587ce5794fac9043196bb04c0b4e293403..c437b3f4e47b74715a2f2385d4862972babd7802:/src/common/evtloopcmn.cpp?ds=inline diff --git a/src/common/evtloopcmn.cpp b/src/common/evtloopcmn.cpp index 36ce381b8d..15813725a8 100644 --- a/src/common/evtloopcmn.cpp +++ b/src/common/evtloopcmn.cpp @@ -9,14 +9,6 @@ // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - // for compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -25,16 +17,83 @@ #endif #include "wx/evtloop.h" -#include "wx/app.h" + +#ifndef WX_PRECOMP + #include "wx/app.h" +#endif //WX_PRECOMP // ---------------------------------------------------------------------------- -// globals +// wxEventLoopBase // ---------------------------------------------------------------------------- -wxEventLoop *wxEventLoopBase::ms_activeLoop = NULL; +wxEventLoopBase *wxEventLoopBase::ms_activeLoop = NULL; + +wxEventLoopBase::wxEventLoopBase() +{ + 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); +} + +void wxEventLoopBase::OnExit() +{ + if (wxTheApp) + wxTheApp->OnEventLoopExit(this); +} + +void wxEventLoopBase::WakeUpIdle() +{ + WakeUp(); +} + +bool wxEventLoopBase::ProcessIdle() +{ + if (!wxTheApp) + return false; + + // process pending wx events before sending idle events + wxTheApp->ProcessPendingEvents(); + + // synthetize an idle event and send it to wxApp + wxIdleEvent event; + event.SetEventObject(wxTheApp); + wxTheApp->ProcessEvent(event); + + return event.MoreRequested(); +} + +bool wxEventLoopBase::Yield(bool onlyIfNeeded) +{ + if ( m_isInsideYield ) + { + if ( !onlyIfNeeded ) + { + wxFAIL_MSG( wxT("wxYield called recursively" ) ); + } + + return false; + } + + return YieldFor(wxEVT_CATEGORY_ALL); +} // wxEventLoopManual is unused in the other ports -#if defined(__WXMSW__) || defined(__WXMAC__) +#if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXDFB__) || (defined(__UNIX__) && wxUSE_BASE) // ============================================================================ // wxEventLoopManual implementation @@ -54,7 +113,7 @@ int wxEventLoopManual::Run() // ProcessIdle() and Dispatch() 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(wx_static_cast(wxEventLoop *, this)); + wxEventLoopActivator activate(this); // 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 @@ -149,4 +208,5 @@ void wxEventLoopManual::Exit(int rc) WakeUp(); } -#endif // __WXMSW__ || __WXMAC__ +#endif // __WXMSW__ || __WXMAC__ || __WXDFB__ +