/////////////////////////////////////////////////////////////////////////////
-// Name: app.cpp
+// Name: src/mgl/app.cpp
// Author: Vaclav Slavik
// based on GTK and MSW implementations
// Id: $Id$
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
- #pragma implementation "app.h"
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#pragma hdrstop
#endif
+#include "wx/app.h"
#ifndef WX_PRECOMP
#include "wx/settings.h"
- #include "wx/module.h"
#include "wx/frame.h"
#include "wx/dialog.h"
#include "wx/log.h"
#include "wx/intl.h"
+ #include "wx/module.h"
#endif
-#include "wx/app.h"
#include "wx/evtloop.h"
#include "wx/fontutil.h"
#include "wx/univ/theme.h"
#include "wx/univ/colschem.h"
#include "wx/sysopt.h"
#include "wx/mgl/private.h"
+#include "wx/private/fontmgr.h"
//-----------------------------------------------------------------------------
// wxApp::Exit()
wxLog::Suspend();
- if ( wxEventLoop::GetActive() )
+ wxEventLoopBase * const eventLoop = wxEventLoop::GetActive();
+ if ( eventLoop )
{
- while (wxEventLoop::GetActive()->Pending())
- wxEventLoop::GetActive()->Dispatch();
+ while (eventLoop->Pending())
+ eventLoop->Dispatch();
}
/* it's necessary to call ProcessIdle() to update the frames sizes which
SetMGLwindow_t(MGL_wmGetRootWindow(g_winMng));
SetBackgroundColour(wxTHEME_COLOUR(DESKTOP));
}
- ~wxRootWindow()
+ virtual ~wxRootWindow()
{
// we don't want to delete MGL_WM's rootWnd
m_wnd = NULL;
IMPLEMENT_DYNAMIC_CLASS(wxApp,wxEvtHandler)
-BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
- EVT_IDLE(wxAppBase::OnIdle)
-END_EVENT_TABLE()
-
-
wxApp::wxApp()
{
}
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;
-
+ // intialize MGL before creating wxFontsManager since it uses MGL funcs
if ( MGL_init(".", NULL) == 0 )
{
wxLogError(_("Cannot initialize SciTech MGL!"));
+ return false;
+ }
- wxAppBase::CleanUp();
-
+ if ( !wxAppBase::Initialize(argc, argv) )
+ {
+ MGL_exit();
return false;
}
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();
- // must do this after calling base class CleanUp()
- delete wxTheFontsManager;
- wxTheFontsManager = (wxFontsManager*) NULL;
-
- wxDestroyMGL_WM();
- MGL_exit();
+ wxModule::RegisterModule(new wxMGLFinalCleanup);
}
-