X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b9f246f7d99d2a2bc18d1d074940e5ab7b7bf601..6bcc1145fea1fbe4f4fd492199d1482f95fac5fd:/src/gtk1/evtloop.cpp?ds=sidebyside diff --git a/src/gtk1/evtloop.cpp b/src/gtk1/evtloop.cpp index 361fa3ab92..194e553bed 100644 --- a/src/gtk1/evtloop.cpp +++ b/src/gtk1/evtloop.cpp @@ -1,12 +1,12 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: gtk/evtloop.cpp +// Name: src/gtk1/evtloop.cpp // Purpose: implements wxEventLoop for GTK+ // Author: Vadim Zeitlin // Modified by: // Created: 10.07.01 // RCS-ID: $Id$ // Copyright: (c) 2001 Vadim Zeitlin -// License: wxWindows license +// License: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ - #pragma implementation "evtloop.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -28,11 +24,13 @@ #pragma hdrstop #endif -#ifndef WX_PRECOMP -#endif //WX_PRECOMP - #include "wx/evtloop.h" +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/log.h" +#endif // WX_PRECOMP + #include // ---------------------------------------------------------------------------- @@ -55,49 +53,41 @@ private: }; // ============================================================================ -// wxEventLoop implementation +// wxGUIEventLoop implementation // ============================================================================ // ---------------------------------------------------------------------------- -// wxEventLoop running and exiting +// wxGUIEventLoop running and exiting // ---------------------------------------------------------------------------- -wxEventLoop *wxEventLoop::ms_activeLoop = NULL; - -wxEventLoop::~wxEventLoop() -{ - wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") ); -} - -bool wxEventLoop::IsRunning() const +wxGUIEventLoop::~wxGUIEventLoop() { - return m_impl != NULL; + wxASSERT_MSG( !m_impl, wxT("should have been deleted in Run()") ); } -int wxEventLoop::Run() +int wxGUIEventLoop::Run() { // event loops are not recursive, you need to create another loop! - wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") ); + wxCHECK_MSG( !IsRunning(), -1, wxT("can't reenter a message loop") ); - wxEventLoop *oldLoop = ms_activeLoop; - ms_activeLoop = this; + wxEventLoopActivator activate(this); m_impl = new wxEventLoopImpl; gtk_main(); + OnExit(); + int exitcode = m_impl->GetExitCode(); delete m_impl; m_impl = NULL; - ms_activeLoop = oldLoop; - return exitcode; } -void wxEventLoop::Exit(int rc) +void wxGUIEventLoop::Exit(int rc) { - wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") ); + wxCHECK_RET( IsRunning(), wxT("can't call Exit() if not running") ); m_impl->SetExitCode(rc); @@ -108,17 +98,72 @@ void wxEventLoop::Exit(int rc) // wxEventLoop message processing dispatching // ---------------------------------------------------------------------------- -bool wxEventLoop::Pending() const +bool wxGUIEventLoop::Pending() const { - return gtk_events_pending() > 0; + if (wxTheApp) + { + // We need to remove idle callbacks or gtk_events_pending will + // never return false. + wxTheApp->RemoveIdleTag(); + } + + return gtk_events_pending(); } -bool wxEventLoop::Dispatch() +bool wxGUIEventLoop::Dispatch() { - wxCHECK_MSG( IsRunning(), FALSE, _T("can't call Dispatch() if not running") ); + wxCHECK_MSG( IsRunning(), false, wxT("can't call Dispatch() if not running") ); gtk_main_iteration(); - return TRUE; + return true; } +//----------------------------------------------------------------------------- +// wxYield +//----------------------------------------------------------------------------- + +bool wxGUIEventLoop::YieldFor(long eventsToProcess) +{ +#if wxUSE_THREADS + if ( !wxThread::IsMain() ) + { + // can't call gtk_main_iteration() from other threads like this + return true; + } +#endif // wxUSE_THREADS + + m_isInsideYield = true; + m_eventsToProcessInsideYield = eventsToProcess; + + // We need to remove idle callbacks or the loop will + // never finish. + wxTheApp->RemoveIdleTag(); + +#if wxUSE_LOG + // disable log flushing from here because a call to wxYield() shouldn't + // normally result in message boxes popping up &c + wxLog::Suspend(); +#endif + + // TODO: implement event filtering using the eventsToProcess mask + while (gtk_events_pending()) + gtk_main_iteration(); + + // It's necessary to call ProcessIdle() to update the frames sizes which + // might have been changed (it also will update other things set from + // OnUpdateUI() which is a nice (and desired) side effect). But we + // call ProcessIdle() only once since this is not meant for longish + // background jobs (controlled by wxIdleEvent::RequestMore() and the + // return value of Processidle(). + ProcessIdle(); + +#if wxUSE_LOG + // let the logs be flashed again + wxLog::Resume(); +#endif + + m_isInsideYield = false; + + return true; +}