int retValue = 0;
- if ( wxTheApp->OnInit() )
+ // it is common to create a modal dialog in OnInit() (to ask/notify the
+ // user about something) but it wouldn't work if we don't change the
+ // "exit on delete last frame" flag here as when this dialog is
+ // deleted, the app would terminate (it was the last top level window
+ // as the main frame wasn't created yet!), so disable this behaviour
+ // temproarily
+ bool exitOnLastFrameDelete = wxTheApp->GetExitOnFrameDelete();
+ wxTheApp->SetExitOnFrameDelete(FALSE);
+
+ // init the app
+ retValue = wxTheApp->OnInit() ? 0 : -1;
+
+ // restore the old flag value
+ wxTheApp->SetExitOnFrameDelete(exitOnLastFrameDelete);
+
+ if ( retValue == 0 )
{
if ( enterLoop )
{
+ // run the main loop
retValue = wxTheApp->OnRun();
}
else
- // We want to initialize, but not run or exit immediately.
+ {
+ // we want to initialize, but not run or exit immediately.
return 1;
+ }
}
//else: app initialization failed, so we skipped OnRun()
}
// Yield to incoming messages
+
+static bool gs_inYield = FALSE;
+
bool wxYield()
{
// disable log flushing from here because a call to wxYield() shouldn't
// normally result in message boxes popping up &c
wxLog::Suspend();
+#ifdef __WXDEBUG__
+ if (gs_inYield)
+ wxFAIL_MSG( wxT("wxYield called recursively" ) );
+#endif
+
+ gs_inYield = TRUE;
+
// we don't want to process WM_QUIT from here - it should be processed in
// the main event loop in order to stop it
MSG msg;
// let the logs be flashed again
wxLog::Resume();
+ gs_inYield = FALSE;
+
return TRUE;
}
+// Yield to incoming messages; but fail silently if recursion is detected.
+bool wxYieldIfNeeded()
+{
+ if (gs_inYield)
+ return FALSE;
+
+ return wxYield();
+}
+
bool wxHandleFatalExceptions(bool doit)
{
#if wxUSE_ON_FATAL_EXCEPTION