// Author: Vadim Zeitlin
// Modified by:
// Created: 10.07.01
-// RCS-ID: $Id$
// Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
-// License: wxWindows licence
+// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
#ifndef WX_PRECOMP
#include "wx/app.h"
+ #include "wx/log.h"
#endif // WX_PRECOMP
#include <gtk/gtk.h>
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 wxGUIEventLoop::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;
- wxEventLoopActivator activate(this);
+ guint loopLevel = gtk_main_level();
- m_impl = new wxEventLoopImpl;
+ // 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.
+ while ( !m_shouldExit )
+ {
+ gtk_main();
+ }
- gtk_main();
+ // 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();
+ }
OnExit();
int exitcode = m_impl->GetExitCode();
- delete m_impl;
- m_impl = NULL;
+ wxDELETE(m_impl);
return exitcode;
}
-void wxGUIEventLoop::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();
}
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();