+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
+
+ // intialize MGL before creating wxFontsManager since it uses MGL funcs
+ if ( MGL_init(".", NULL) == 0 )
+ {
+ wxLogError(_("Cannot initialize SciTech MGL!"));
+ return false;
+ }
+
+ if ( !wxAppBase::Initialize(argc, argv) )
+ {
+ MGL_exit();
+ return false;
+ }
+
+#if wxUSE_INTL
+ wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
+#endif
+
+ return true;
+}
+
+// Modules are cleaned up after wxApp::CleanUp(), and some modules may
+// require MGL to still be alive, e.g. the stock fonts need the fonts
+// manager. So append this module last minute in wxApp::CleanUp() to close
+// down MGL after all the other modules have been cleaned up.
+//
+struct wxMGLFinalCleanup: public wxModule
+{
+ bool OnInit() { return true; }
+
+ void OnExit()
+ {
+ wxFontsManager::CleanUp();
+
+ wxDestroyMGL_WM();
+ MGL_exit();
+ }
+};
+
+void wxApp::CleanUp()
+{
+ delete gs_rootWindow;
+
+ wxAppBase::CleanUp();
+
+ wxModule::RegisterModule(new wxMGLFinalCleanup);
+}