X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8907154c1a8a6882c6797d1f16393ddfb23e7f3a..39c0d6d6b6682b1847881d1e2662a4ccdec83ec8:/src/gtk1/evtloop.cpp diff --git a/src/gtk1/evtloop.cpp b/src/gtk1/evtloop.cpp index 7fbde67a58..fa0e6c7f6e 100644 --- a/src/gtk1/evtloop.cpp +++ b/src/gtk1/evtloop.cpp @@ -1,12 +1,11 @@ /////////////////////////////////////////////////////////////////////////////// -// 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 licence +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -25,7 +24,13 @@ #endif #include "wx/evtloop.h" -#include "wx/app.h" +#include "wx/private/eventloopsourcesmanager.h" +#include "wx/apptrait.h" + +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/log.h" +#endif // WX_PRECOMP #include @@ -49,47 +54,70 @@ private: }; // ============================================================================ -// wxEventLoop implementation +// wxGUIEventLoop implementation // ============================================================================ // ---------------------------------------------------------------------------- -// wxEventLoop running and exiting +// wxGUIEventLoop running and exiting // ---------------------------------------------------------------------------- -wxEventLoop *wxEventLoopBase::ms_activeLoop = NULL; - -wxEventLoop::~wxEventLoop() +wxGUIEventLoop::~wxGUIEventLoop() { - wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") ); + wxASSERT_MSG( !m_impl, wxT("should have been deleted in Run()") ); } -int wxEventLoop::Run() +int wxGUIEventLoop::DoRun() { - // event loops are not recursive, you need to create another loop! - wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") ); + m_impl = new wxEventLoopImpl; - wxEventLoop *oldLoop = ms_activeLoop; - ms_activeLoop = this; + guint loopLevel = gtk_main_level(); + + // This is placed inside of a loop to take into account nested + // event loops. For example, inside this event loop, we may recieve + // Exit() for a different event loop (which we are currently inside of) + // That Exit() will cause this gtk_main() to exit so we need to re-enter it. +#if 0 + // changed by JJ + // this code was intended to support nested event loops. However, + // exiting a dialog will result in a application hang (because + // gtk_main_quit is called when closing the dialog????) + // So for the moment this code is disabled and nested event loops + // probably fail for wxGTK1 + while ( !m_shouldExit ) + { +#endif + gtk_main(); +#if 0 + } - m_impl = new wxEventLoopImpl; + // Force the enclosing event loop to also exit to see if it is done + // in case that event loop ended inside of this one. If it is not time + // yet for that event loop to exit, it will be executed again due to + // the while() loop on m_shouldExit(). + // + // This is unnecessary if we are the top level loop, i.e. loop of level 0. + if ( loopLevel ) + { + gtk_main_quit(); + } +#endif - gtk_main(); + OnExit(); int exitcode = m_impl->GetExitCode(); - delete m_impl; - m_impl = NULL; - - ms_activeLoop = oldLoop; + wxDELETE(m_impl); return exitcode; } -void wxEventLoop::Exit(int rc) +void wxGUIEventLoop::ScheduleExit(int rc) { - wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") ); + wxCHECK_RET( IsInsideRun(), wxT("can't call ScheduleExit() if not started") ); m_impl->SetExitCode(rc); + m_shouldExit = true; + gtk_main_quit(); } @@ -97,7 +125,7 @@ void wxEventLoop::Exit(int rc) // wxEventLoop message processing dispatching // ---------------------------------------------------------------------------- -bool wxEventLoop::Pending() const +bool wxGUIEventLoop::Pending() const { if (wxTheApp) { @@ -109,12 +137,81 @@ bool wxEventLoop::Pending() const 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; +} + +class wxGUIEventLoopSourcesManager : public wxEventLoopSourcesManagerBase +{ + public: + wxEventLoopSource * + AddSourceForFD(int WXUNUSED(fd), + wxEventLoopSourceHandler* WXUNUSED(handler), + int WXUNUSED(flags)) + { + wxFAIL_MSG("Monitoring FDs in the main loop is not implemented in wxGTK1"); + + return NULL; + } +}; + +wxEventLoopSourcesManagerBase* wxGUIAppTraits::GetEventLoopSourcesManager() +{ + static wxGUIEventLoopSourcesManager s_eventLoopSourcesManager; + + return &s_eventLoopSourcesManager; +}