]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/init.cpp
Added wxGUIAppTraits::GetOSVersion() implementation.
[wxWidgets.git] / src / common / init.cpp
index 78576fb3c545eec7e749a34308f1eb430f41bf6f..b3cd9aa66df9f2d0b3c8a681d90d283a394457d3 100644 (file)
     #include "wx/app.h"
     #include "wx/debug.h"
     #include "wx/filefn.h"
+    #include "wx/log.h"
 #endif
 
 #include "wx/module.h"
 
-// ----------------------------------------------------------------------------
-// global vars
-// ----------------------------------------------------------------------------
-
-wxApp * WXDLLEXPORT wxTheApp = NULL;
-
-wxAppInitializerFunction
-    wxAppBase::m_appInitFn = (wxAppInitializerFunction)NULL;
-
 // ----------------------------------------------------------------------------
 // private classes
 // ----------------------------------------------------------------------------
 
-class /* no WXDLLEXPORT */ wxConsoleApp : public wxApp
+// we need a dummy app object if the user doesn't want to create a real one
+class wxDummyConsoleApp : public wxApp
 {
 public:
-    virtual int OnRun() { wxFAIL_MSG(wxT("unreachable")); return 0; }
+    virtual int OnRun() { wxFAIL_MSG( _T("unreachable code") ); return 0; }
 };
 
 // ----------------------------------------------------------------------------
@@ -67,28 +60,6 @@ static size_t gs_nInitCount = 0;
 // implementation
 // ============================================================================
 
-// ----------------------------------------------------------------------------
-// stubs for some GUI functions
-// ----------------------------------------------------------------------------
-
-void WXDLLEXPORT wxExit()
-{
-    abort();
-}
-
-// Yield to other apps/messages
-bool WXDLLEXPORT wxYield()
-{
-    // do nothing
-    return TRUE;
-}
-
-// Yield to other apps/messages
-void WXDLLEXPORT wxWakeUpIdle()
-{
-    // do nothing
-}
-
 // ----------------------------------------------------------------------------
 // wxBase-specific functions
 // ----------------------------------------------------------------------------
@@ -109,7 +80,7 @@ bool WXDLLEXPORT wxInitialize()
         return FALSE;
     }
 
-    wxTheApp = new wxConsoleApp;
+    wxTheApp = new wxDummyConsoleApp;
 
     if ( !wxTheApp )
     {
@@ -155,18 +126,16 @@ int wxEntry(int argc, char **argv)
 
 #if wxUSE_UNICODE
     wxTheApp->argv = new wxChar*[argc+1];
-    int mb_argc = 0;
-    while (mb_argc < argc)
+    for ( int mb_argc = 0; mb_argc < argc; mb_argc++ )
     {
-        wxTheApp->argv[mb_argc] = wxStrdup(wxConvLibc.cMB2WX(argv[mb_argc]));
-        mb_argc++;
+        wxTheApp->argv[mb_argc] = wxStrdup(wxConvLocal.cMB2WX(argv[mb_argc]));
     }
     wxTheApp->argv[mb_argc] = (wxChar *)NULL;
 #else
     wxTheApp->argv = argv;
 #endif
 
-    wxString name = wxFileNameFromPath(argv[0]);
+    wxString name = wxFileNameFromPath(wxTheApp->argv[0]);
     wxStripExtension(name);
     wxTheApp->SetAppName(name);
 
@@ -219,16 +188,29 @@ static void DoCleanUp()
     // continuing to use user defined log target is unsafe from now on because
     // some resources may be already unavailable, so replace it by something
     // more safe
-    wxLog *oldlog = wxLog::SetActiveTarget(new wxLogStderr);
-    if ( oldlog )
-        delete oldlog;
+    wxLog::DontCreateOnDemand();
+    delete wxLog::SetActiveTarget(new wxLogStderr);
 #endif // wxUSE_LOG
 
     wxModule::CleanUpModules();
 
     wxClassInfo::CleanUpClasses();
 
+    // TODO: this should really be done in ~wxApp
+#if wxUSE_UNICODE
+    for ( int mb_argc = 0; mb_argc < wxTheApp->argc; mb_argc++ )
+    {
+        free(wxTheApp->argv[mb_argc]);
+    }
+#endif // wxUSE_UNICODE
+
     // delete the application object
     delete wxTheApp;
     wxTheApp = (wxApp *)NULL;
+
+#if wxUSE_LOG
+    // and now delete the last logger as well
+    delete wxLog::SetActiveTarget(NULL);
+#endif // wxUSE_LOG
 }
+