Add wxEventLoop::ScheduleExit().
This method allows to request exiting from the given event loop even if it's not the currently active one, unlike Exit() which would assert in this case. With it, it becomes possible to ask the loop to terminate as soon as possible even if a nested loop is currently running. See #10258. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74335 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -52,19 +52,41 @@ wxGUIEventLoop::wxGUIEventLoop()
|
||||
|
||||
int wxGUIEventLoop::DoRun()
|
||||
{
|
||||
gtk_main();
|
||||
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 receive
|
||||
// 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();
|
||||
}
|
||||
|
||||
// Force the enclosing event loop to also exit to see if it is done in case
|
||||
// that event loop had Exit() called inside of the just ended loop. 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();
|
||||
|
||||
return m_exitcode;
|
||||
}
|
||||
|
||||
void wxGUIEventLoop::Exit(int rc)
|
||||
void wxGUIEventLoop::ScheduleExit(int rc)
|
||||
{
|
||||
wxCHECK_RET( IsRunning(), "can't call Exit() if not running" );
|
||||
wxCHECK_RET( IsInsideRun(), wxT("can't call ScheduleExit() if not started") );
|
||||
|
||||
m_exitcode = rc;
|
||||
|
||||
m_shouldExit = true;
|
||||
|
||||
gtk_main_quit();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user