+void wxApp::OnIdle(wxIdleEvent &event)
+{
+ static bool s_inOnIdle = FALSE;
+
+ /* Avoid recursion (via ProcessEvent default case) */
+ if (s_inOnIdle)
+ return;
+
+ s_inOnIdle = TRUE;
+
+ /* Resend in the main thread events which have been prepared in other
+ threads */
+ ProcessPendingEvents();
+
+ // 'Garbage' collection of windows deleted with Close().
+ DeletePendingObjects();
+
+#if wxUSE_LOG
+ // flush the logged messages if any
+ wxLog::FlushActive();
+#endif // wxUSE_LOG
+
+ // Send OnIdle events to all windows
+ if ( SendIdleEvents() )
+ event.RequestMore(TRUE);
+
+ s_inOnIdle = FALSE;
+}
+
+int wxApp::MainLoop()
+{
+ int rt;
+ m_mainLoop = new wxEventLoop;
+
+ rt = m_mainLoop->Run();
+
+ delete m_mainLoop;
+ m_mainLoop = NULL;
+ return rt;
+}
+
+void wxApp::ExitMainLoop()
+{
+ if ( m_mainLoop )
+ m_mainLoop->Exit(0);
+}
+
+bool wxApp::Initialized()
+{
+ return (wxTopLevelWindows.GetCount() != 0);
+}
+
+bool wxApp::Pending()
+{
+ return wxEventLoop::GetActive()->Pending();
+}
+
+void wxApp::Dispatch()
+{
+ wxEventLoop::GetActive()->Dispatch();
+}
+
+bool wxApp::Initialize(int& argc, wxChar **argv)
+{
+#ifdef __DJGPP__
+ // VS: disable long filenames under DJGPP as the very first thing,
+ // since SciTech MGL doesn't like them much...
+ wxSetEnv(wxT("LFN"), wxT("N"));
+#endif
+
+ // must do it before calling wxAppBase::Initialize(), because fonts are
+ // needed by stock lists which are created there
+ wxTheFontsManager = new wxFontsManager;
+
+ if ( !wxAppBase::Initialize(argc, argv) )
+ return false;
+
+ if ( MGL_init(".", NULL) == 0 )
+ {
+ wxLogError(_("Cannot initialize SciTech MGL!"));
+
+ wxAppBase::CleanUp();
+
+ return false;
+ }
+
+#if wxUSE_INTL
+ wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
+#endif
+
+ return true;
+}
+
+void wxApp::CleanUp()
+{
+ delete gs_rootWindow;
+
+ wxAppBase::CleanUp();
+
+ // must do this after calling base class CleanUp()
+ delete wxTheFontsManager;
+ wxTheFontsManager = (wxFontsManager*) NULL;
+
+ wxDestroyMGL_WM();
+ MGL_exit();
+}
+