- gtk_set_locale();
-
- gtk_init( &argc, &argv );
-
- if (!wxApp::Initialize())
- return -1;
-
- if (!wxTheApp)
- {
- wxCHECK_MSG( wxApp::GetInitializerFunction(), -1,
- "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
-
- wxAppInitializerFunction app_ini = wxApp::GetInitializerFunction();
-
- wxObject *test_app = app_ini();
-
- wxTheApp = (wxApp*) test_app;
- }
-
- wxCHECK_MSG( wxTheApp, -1, "wxWindows error: no application object" );
-
- wxTheApp->argc = argc;
- wxTheApp->argv = argv;
-
- char name[200];
- strcpy( name, argv[0] );
- strcpy( name, wxFileNameFromPath(name) );
- wxStripExtension( name );
- wxTheApp->SetAppName( name );
-
- if (!wxTheApp->OnInitGui())
- return 0;
-
- /* Here frames insert themselves automatically
- * into wxTopLevelWindows by getting created
- * in OnInit(). */
-
- if (!wxTheApp->OnInit())
- return 0;
-
- wxTheApp->m_initialized = wxTopLevelWindows.GetCount() != 0;
-
- int retValue = 0;
-
- if (wxTheApp->Initialized())
- retValue = wxTheApp->OnRun();
-
- wxWindow *topWindow = wxTheApp->GetTopWindow();
- if (topWindow)
- {
- // Forcibly delete the window.
- if (topWindow->IsKindOf(CLASSINFO(wxFrame)) ||
- topWindow->IsKindOf(CLASSINFO(wxDialog)) )
- {
- topWindow->Close( TRUE );
- wxTheApp->DeletePendingObjects();
- }
- else
- {
- delete topWindow;
- wxTheApp->SetTopWindow( (wxWindow*) NULL );
- }
- }
-
- wxTheApp->OnExit();
-
- // flush the logged messages if any
- wxLog *log = wxLog::GetActiveTarget();
- if (log != NULL && log->HasPendingMessages())
- log->Flush();
-
- // 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;
-
- wxApp::CleanUp();