// reason, you must override it (instead of just overriding OnInit(), as
// usual, for app-specific initializations), do not forget to call the base
// class version!
- virtual bool Initialize(int argc, wxChar **argv);
+ virtual bool Initialize(int& argc, wxChar **argv);
// Called before OnRun(), this is a good place to do initialization -- if
// anything fails, return false from here to prevent the program from
// very first initialization function
//
// Override: very rarely
- virtual bool Initialize(int argc, wxChar **argv);
+ virtual bool Initialize(int& argc, wxChar **argv);
// a platform-dependent version of OnInit(): the code here is likely to
// depend on the toolkit. default version does nothing.
// Returns TRUE if more idle time is requested.
bool SendIdleEvents(wxWindowCocoa* win);
- virtual bool Initialize(int argc, wxChar **argv);
+ virtual bool Initialize(int& argc, wxChar **argv);
virtual void CleanUp();
virtual bool OnInit();
bool SendIdleEvents();
bool SendIdleEvents( wxWindow* win );
- virtual bool Initialize(int argc, wxChar **argv);
+ virtual bool Initialize(int& argc, wxChar **argv);
virtual void CleanUp();
static bool InitialzeVisual();
bool SendIdleEvents();
bool SendIdleEvents( wxWindow* win );
- virtual bool Initialize(int argc, wxChar **argv);
+ virtual bool Initialize(int& argc, wxChar **argv);
virtual void CleanUp();
static bool InitialzeVisual();
// this function also creates wxTheApp as a side effect, if IMPLEMENT_APP
// hadn't been used a dummy default application object is created
//
-// note that the parameters may be modified
-extern bool WXDLLEXPORT wxEntryStart(int argc, wxChar **argv);
+// note that the parameters may be modified, this is why we pass them by
+// reference!
+extern bool WXDLLEXPORT wxEntryStart(int& argc, wxChar **argv);
// free the resources allocated by the library in wxEntryStart() and shut it
// down (wxEntryStart() may be called again afterwards if necessary)
// but this one always exists under all platforms
//
// returns the program exit code
-extern int WXDLLEXPORT wxEntry(int argc, wxChar **argv);
+extern int WXDLLEXPORT wxEntry(int& argc, wxChar **argv);
// ----------------------------------------------------------------------------
public:
// Implementation
- virtual bool Initialize(int argc, wxChar **argv);
+ virtual bool Initialize(int& argc, wxChar **argv);
virtual void CleanUp();
bool IsExiting() { return !m_keepGoing ; }
bool SendIdleEvents();
bool SendIdleEvents(wxWindow* win);
- virtual bool Initialize(int argc, wxChar **argv);
+ virtual bool Initialize(int& argc, wxChar **argv);
virtual void CleanUp();
virtual bool Yield(bool onlyIfNeeded = FALSE);
public:
// Implementation
- virtual bool Initialize(int argc, wxChar **argv);
+ virtual bool Initialize(int& argc, wxChar **argv);
virtual void CleanUp();
// Motif-specific
virtual ~wxApp();
// override base class (pure) virtuals
- virtual bool Initialize(int argc, wxChar **argv);
+ virtual bool Initialize(int& argc, wxChar **argv);
virtual void CleanUp();
virtual int MainLoop();
public:
// Implementation
- virtual bool Initialize(int argc, wxChar **argv);
+ virtual bool Initialize(int& argc, wxChar **argv);
virtual void CleanUp(void);
static bool RegisterWindowClasses(HAB vHab);
public:
// Implementation
- virtual bool Initialize();
+ virtual bool Initialize(int& argc, wxChar **argv);
virtual void CleanUp();
void DeletePendingObjects();
// functions
// ============================================================================
-//----------------------------------------------------------------------
-// wxEntry
-//----------------------------------------------------------------------
-
-int WXDLLEXPORT wxEntryStart( int WXUNUSED(argc), char *WXUNUSED(argv)[] )
-{
- return wxApp::Initialize();
-}
-
-int WXDLLEXPORT wxEntryInitGui()
-{
- return wxTheApp->OnInitGui();
-}
-
-void WXDLLEXPORT wxEntryCleanup()
-{
- wxApp::CleanUp();
-}
-
-int wxEntry( int argc, char *argv[])
-{
- if (!wxEntryStart(argc, argv)) {
- return 0;
- }
- wxLogDebug("Creating application");
- // create the application object or ensure that one already exists
- if (!wxTheApp)
- {
- // The app may have declared a global application object, but we recommend
- // the IMPLEMENT_APP macro is used instead, which sets an initializer
- // function for delayed, dynamic app object construction.
- wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
- wxT("No initializer - use IMPLEMENT_APP macro.") );
-
- wxTheApp = (wxApp*) (*wxApp::GetInitializerFunction()) ();
- }
-
- wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
-
- // Mac OS X passes a process serial number command line argument when
- // the application is launched from the Finder. This argument must be
- // removed from the command line arguments before being handled by the
- // application (otherwise applications would need to handle it)
-
- if (argc > 1) {
- char theArg[6] = "";
- strncpy(theArg, argv[1], 5);
-
- if (strcmp(theArg, "-psn_") == 0) {
- // assume the argument is always the only one and remove it
- --argc;
- }
- }
-
- wxTheApp->argc = argc;
- wxTheApp->argv = argv;
-
- wxLogDebug("initializing gui");
- // GUI-specific initialization, such as creating an app context.
- wxEntryInitGui();
-
- // Here frames insert themselves automatically
- // into wxTopLevelWindows by getting created
- // in OnInit().
-
- int retValue = 0;
-
- wxLogDebug("Time to run");
- 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);
- }
- else
- {
- delete topWindow;
- wxTheApp->SetTopWindow(NULL);
- }
- }
-
- wxTheApp->OnExit();
-
- wxEntryCleanup();
-
- return retValue;
-}
-
void wxApp::Exit()
{
wxApp::CleanUp();
#endif
// ----------------------------------------------------------------------------
-// wxApp static functions
+// wxApp initialization/cleanup
// ----------------------------------------------------------------------------
-bool wxApp::Initialize(int argc, wxChar **argv)
+bool wxApp::Initialize(int& argc, wxChar **argv)
{
+ // Mac OS X passes a process serial number command line argument when
+ // the application is launched from the Finder. This argument must be
+ // removed from the command line arguments before being handled by the
+ // application (otherwise applications would need to handle it)
+ if ( argc > 1 )
+ {
+ static const wxChar *ARG_PSN = _T("-psn_");
+ if ( wxStrncmp(argv[1], ARG_PSN, sizeof(ARG_PSN) - 1) == 0 )
+ {
+ // remove this argument
+ memmove(argv, argv + 1, argc--);
+ }
+ }
+
// VZ: apparently this needs to be done a.s.a.p., right? it is done after
// wxClassInfo::InitializeClasses() now but usd to be done before, I
// hope it's not a problem -- if it is, please let me know, David (if
// initilization/cleanup
// ----------------------------------------------------------------------------
-bool wxAppConsole::Initialize(int argc, wxChar **argv)
+bool wxAppConsole::Initialize(int& argc, wxChar **argv)
{
// remember the command line arguments
this->argc = argc;
m_exitOnFrameDelete = Later;
}
-bool wxAppBase::Initialize(int argc, wxChar **argv)
+bool wxAppBase::Initialize(int& argc, wxChar **argv)
{
if ( !wxAppConsole::Initialize(argc, argv) )
return false;
- // for compatibility call the old initialization function too
- if ( !OnInitGui() )
- {
- wxAppConsole::CleanUp();
-
- return false;
- }
-
#if wxUSE_THREADS
wxPendingEventsLocker = new wxCriticalSection;
#endif
}
};
+// class to ensure that wxAppBase::CleanUp() is called if our Initialize()
+// fails
+class wxCallAppCleanup
+{
+public:
+ wxCallAppCleanup(wxApp *app) : m_app(app) { }
+ ~wxCallAppCleanup() { if ( m_app ) m_app->CleanUp(); }
+
+ void Dismiss() { m_app = NULL; }
+
+private:
+ wxApp *m_app;
+};
+
// another tiny class which simply exists to ensure that wxEntryCleanup is
// always called
class wxCleanupOnExit
return wxModule::InitializeModules();
}
-bool wxEntryStart(int argc, wxChar **argv)
+bool wxEntryStart(int& argc, wxChar **argv)
{
// do minimal, always necessary, initialization
// --------------------------------------------
return false;
}
+ wxCallAppCleanup callAppCleanup(wxTheApp);
+
+ // for compatibility call the old initialization function too
+ if ( !wxTheApp->OnInitGui() )
+ return false;
+
// common initialization after wxTheApp creation
// ---------------------------------------------
if ( !DoCommonPostInit() )
- {
return false;
- }
// prevent the smart pointer from destroying its contents
app.release();
+ // and the cleanup object from doing cleanup
+ callAppCleanup.Dismiss();
+
return true;
}
#if wxUSE_UNICODE
// we provide a wxEntryStart() wrapper taking "char *" pointer too
-bool wxEntryStart(int argc, char **argv)
+bool wxEntryStart(int& argc, char **argv)
{
ConvertArgsToUnicode(argc, argv);
#define wxEntryReal wxEntry
#endif // !(__WXMSW__ && wxUSE_ON_FATAL_EXCEPTION)
-int wxEntryReal(int argc, wxChar **argv)
+int wxEntryReal(int& argc, wxChar **argv)
{
// library initialization
if ( !wxEntryStart(argc, argv) )
if ( !wxAppBase::Initialize(argc, argv) )
return false;
-#if wxUSE_INTL
- wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
-#endif
-
- return true;
-}
-
-void wxApp::CleanUp()
-{
- wxAppBase::CleanUp();
-}
-
-//-----------------------------------------------------------------------------
-// wxEntry
-//-----------------------------------------------------------------------------
-
-// NB: argc and argv may be changed here, pass by reference!
-int wxEntryStart( int& argc, char *argv[] )
-{
#if wxUSE_THREADS
// GTK 1.2 up to version 1.2.3 has broken threads
if ((gtk_major_version == 1) &&
{
g_thread_init(NULL);
}
-#endif
+#endif // wxUSE_THREADS
gtk_set_locale();
// We should have the wxUSE_WCHAR_T test on the _outside_
#if wxUSE_WCHAR_T
-#if defined(__WXGTK20__)
- // gtk+ 2.0 supports Unicode through UTF-8 strings
- wxConvCurrent = &wxConvUTF8;
-#else
- if (!wxOKlibc()) wxConvCurrent = &wxConvLocal;
-#endif
-#else
- if (!wxOKlibc()) wxConvCurrent = (wxMBConv*) NULL;
-#endif
+ #if defined(__WXGTK20__)
+ // gtk+ 2.0 supports Unicode through UTF-8 strings
+ wxConvCurrent = &wxConvUTF8;
+ #else // GTK 1.x
+ if (!wxOKlibc())
+ wxConvCurrent = &wxConvLocal;
+ #endif
+#else // !wxUSE_WCHAR_T
+ if (!wxOKlibc())
+ wxConvCurrent = (wxMBConv*) NULL;
+#endif // wxUSE_WCHAR_T/!wxUSE_WCHAR_T
- gtk_init( &argc, &argv );
-
- /* we can not enter threads before gtk_init is done */
- gdk_threads_enter();
-
- wxSetDetectableAutoRepeat( TRUE );
-
- if (!wxApp::Initialize())
+#if wxUSE_UNICODE
+ // gtk_init() wants UTF-8, not wchar_t, so convert
+ int i;
+ char *argvGTK = new char *[argc + 1];
+ for ( i = 0; i < argc; i++ )
{
- gdk_threads_leave();
- return -1;
+ argvGTK[i] = wxStrdupA(wxConvUTF8.cWX2MB(argv[i]));
}
- return 0;
-}
-
-
-int wxEntryInitGui()
-{
- int retValue = 0;
-
- if ( !wxTheApp->OnInitGui() )
- retValue = -1;
-
- wxGetRootWindow();
-
- return retValue;
-}
-
-
-void wxEntryCleanup()
-{
-#if wxUSE_LOG
- // 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;
-#endif // wxUSE_LOG
+ argvGTK[argc] = NULL;
- wxApp::CleanUp();
+ int argcGTK = argc;
+ gtk_init( &argcGTK, &argvGTK );
- gdk_threads_leave();
-}
-
-
-int wxEntry( int argc, char *argv[] )
-{
-#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
- // This seems to be necessary since there are 'rogue'
- // objects present at this point (perhaps global objects?)
- // Setting a checkpoint will ignore them as far as the
- // memory checking facility is concerned.
- // Of course you may argue that memory allocated in globals should be
- // checked, but this is a reasonable compromise.
- wxDebugContext::SetCheckpoint();
-#endif
- int err = wxEntryStart(argc, argv);
- if (err)
- return err;
-
- if (!wxTheApp)
- {
- wxCHECK_MSG( wxApp::GetInitializerFunction(), -1,
- wxT("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, wxT("wxWindows error: no application object") );
-
- wxTheApp->argc = argc;
-#if wxUSE_UNICODE
- wxTheApp->argv = new wxChar*[argc+1];
- int mb_argc = 0;
- while (mb_argc < argc)
+ if ( argcGTK != argc )
{
- wxTheApp->argv[mb_argc] = wxStrdup(wxConvLibc.cMB2WX(argv[mb_argc]));
- mb_argc++;
- }
- wxTheApp->argv[mb_argc] = (wxChar *)NULL;
-#else
- wxTheApp->argv = argv;
-#endif
+ // we have to drop the parameters which were consumed by GTK+
+ for ( i = 0; i < argcGTK; i++ )
+ {
+ while ( wxStrcmp(wxConvUTF8.cWX2MB(argv[i]), argvGTK[i]) != 0 )
+ {
+ memmove(argv + i, argv + i + 1, argc - i);
+ }
+ }
- if (wxTheApp->argc > 0)
- {
- wxFileName fname( wxTheApp->argv[0] );
- wxTheApp->SetAppName( fname.GetName() );
+ argc = argcGTK;
}
+ //else: gtk_init() didn't modify our parameters
- int retValue;
- retValue = wxEntryInitGui();
-
- // Here frames insert themselves automatically into wxTopLevelWindows by
- // getting created in OnInit().
- if ( retValue == 0 )
+ // free our copy
+ for ( i = 0; i < argcGTK; i++ )
{
- if ( !wxTheApp->OnInit() )
- retValue = -1;
+ free(argvGTK[i]);
}
- if ( retValue == 0 )
- {
- // Delete pending toplevel windows
- wxTheApp->DeletePendingObjects();
-
- // When is the app not initialized ?
- wxTheApp->m_initialized = TRUE;
+ delete [] argvGTK;
+#else // !wxUSE_UNICODE
+ // gtk_init() shouldn't actually change argv itself (just its contents) so
+ // it's ok to pass pointer to it
+ gtk_init( &argc, &argv );
+#endif // wxUSE_UNICODE/!wxUSE_UNICODE
- if (wxTheApp->Initialized())
- {
- wxTheApp->OnRun();
+ // we can not enter threads before gtk_init is done
+ gdk_threads_enter();
- wxWindow *topWindow = wxTheApp->GetTopWindow();
+ wxSetDetectableAutoRepeat( TRUE );
- // Delete all pending windows if any
- wxTheApp->DeletePendingObjects();
+#if wxUSE_INTL
+ wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
+#endif
- // Reset top window
- if (topWindow)
- wxTheApp->SetTopWindow( (wxWindow*) NULL );
+ wxGetRootWindow();
- retValue = wxTheApp->OnExit();
- }
- }
+ return true;
+}
- wxEntryCleanup();
+void wxApp::CleanUp()
+{
+ wxAppBase::CleanUp();
- return retValue;
+ gdk_threads_leave();
}
#ifdef __WXDEBUG__
if ( !wxAppBase::Initialize(argc, argv) )
return false;
-#if wxUSE_INTL
- wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
-#endif
-
- return true;
-}
-
-void wxApp::CleanUp()
-{
- wxAppBase::CleanUp();
-}
-
-//-----------------------------------------------------------------------------
-// wxEntry
-//-----------------------------------------------------------------------------
-
-// NB: argc and argv may be changed here, pass by reference!
-int wxEntryStart( int& argc, char *argv[] )
-{
#if wxUSE_THREADS
// GTK 1.2 up to version 1.2.3 has broken threads
if ((gtk_major_version == 1) &&
{
g_thread_init(NULL);
}
-#endif
+#endif // wxUSE_THREADS
gtk_set_locale();
// We should have the wxUSE_WCHAR_T test on the _outside_
#if wxUSE_WCHAR_T
-#if defined(__WXGTK20__)
- // gtk+ 2.0 supports Unicode through UTF-8 strings
- wxConvCurrent = &wxConvUTF8;
-#else
- if (!wxOKlibc()) wxConvCurrent = &wxConvLocal;
-#endif
-#else
- if (!wxOKlibc()) wxConvCurrent = (wxMBConv*) NULL;
-#endif
+ #if defined(__WXGTK20__)
+ // gtk+ 2.0 supports Unicode through UTF-8 strings
+ wxConvCurrent = &wxConvUTF8;
+ #else // GTK 1.x
+ if (!wxOKlibc())
+ wxConvCurrent = &wxConvLocal;
+ #endif
+#else // !wxUSE_WCHAR_T
+ if (!wxOKlibc())
+ wxConvCurrent = (wxMBConv*) NULL;
+#endif // wxUSE_WCHAR_T/!wxUSE_WCHAR_T
- gtk_init( &argc, &argv );
-
- /* we can not enter threads before gtk_init is done */
- gdk_threads_enter();
-
- wxSetDetectableAutoRepeat( TRUE );
-
- if (!wxApp::Initialize())
+#if wxUSE_UNICODE
+ // gtk_init() wants UTF-8, not wchar_t, so convert
+ int i;
+ char *argvGTK = new char *[argc + 1];
+ for ( i = 0; i < argc; i++ )
{
- gdk_threads_leave();
- return -1;
+ argvGTK[i] = wxStrdupA(wxConvUTF8.cWX2MB(argv[i]));
}
- return 0;
-}
-
-
-int wxEntryInitGui()
-{
- int retValue = 0;
-
- if ( !wxTheApp->OnInitGui() )
- retValue = -1;
-
- wxGetRootWindow();
-
- return retValue;
-}
-
-
-void wxEntryCleanup()
-{
-#if wxUSE_LOG
- // 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;
-#endif // wxUSE_LOG
+ argvGTK[argc] = NULL;
- wxApp::CleanUp();
+ int argcGTK = argc;
+ gtk_init( &argcGTK, &argvGTK );
- gdk_threads_leave();
-}
-
-
-int wxEntry( int argc, char *argv[] )
-{
-#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
- // This seems to be necessary since there are 'rogue'
- // objects present at this point (perhaps global objects?)
- // Setting a checkpoint will ignore them as far as the
- // memory checking facility is concerned.
- // Of course you may argue that memory allocated in globals should be
- // checked, but this is a reasonable compromise.
- wxDebugContext::SetCheckpoint();
-#endif
- int err = wxEntryStart(argc, argv);
- if (err)
- return err;
-
- if (!wxTheApp)
- {
- wxCHECK_MSG( wxApp::GetInitializerFunction(), -1,
- wxT("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, wxT("wxWindows error: no application object") );
-
- wxTheApp->argc = argc;
-#if wxUSE_UNICODE
- wxTheApp->argv = new wxChar*[argc+1];
- int mb_argc = 0;
- while (mb_argc < argc)
+ if ( argcGTK != argc )
{
- wxTheApp->argv[mb_argc] = wxStrdup(wxConvLibc.cMB2WX(argv[mb_argc]));
- mb_argc++;
- }
- wxTheApp->argv[mb_argc] = (wxChar *)NULL;
-#else
- wxTheApp->argv = argv;
-#endif
+ // we have to drop the parameters which were consumed by GTK+
+ for ( i = 0; i < argcGTK; i++ )
+ {
+ while ( wxStrcmp(wxConvUTF8.cWX2MB(argv[i]), argvGTK[i]) != 0 )
+ {
+ memmove(argv + i, argv + i + 1, argc - i);
+ }
+ }
- if (wxTheApp->argc > 0)
- {
- wxFileName fname( wxTheApp->argv[0] );
- wxTheApp->SetAppName( fname.GetName() );
+ argc = argcGTK;
}
+ //else: gtk_init() didn't modify our parameters
- int retValue;
- retValue = wxEntryInitGui();
-
- // Here frames insert themselves automatically into wxTopLevelWindows by
- // getting created in OnInit().
- if ( retValue == 0 )
+ // free our copy
+ for ( i = 0; i < argcGTK; i++ )
{
- if ( !wxTheApp->OnInit() )
- retValue = -1;
+ free(argvGTK[i]);
}
- if ( retValue == 0 )
- {
- // Delete pending toplevel windows
- wxTheApp->DeletePendingObjects();
-
- // When is the app not initialized ?
- wxTheApp->m_initialized = TRUE;
+ delete [] argvGTK;
+#else // !wxUSE_UNICODE
+ // gtk_init() shouldn't actually change argv itself (just its contents) so
+ // it's ok to pass pointer to it
+ gtk_init( &argc, &argv );
+#endif // wxUSE_UNICODE/!wxUSE_UNICODE
- if (wxTheApp->Initialized())
- {
- wxTheApp->OnRun();
+ // we can not enter threads before gtk_init is done
+ gdk_threads_enter();
- wxWindow *topWindow = wxTheApp->GetTopWindow();
+ wxSetDetectableAutoRepeat( TRUE );
- // Delete all pending windows if any
- wxTheApp->DeletePendingObjects();
+#if wxUSE_INTL
+ wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
+#endif
- // Reset top window
- if (topWindow)
- wxTheApp->SetTopWindow( (wxWindow*) NULL );
+ wxGetRootWindow();
- retValue = wxTheApp->OnExit();
- }
- }
+ return true;
+}
- wxEntryCleanup();
+void wxApp::CleanUp()
+{
+ wxAppBase::CleanUp();
- return retValue;
+ gdk_threads_leave();
}
#ifdef __WXDEBUG__
WXIMPORT char std::__throws_bad_alloc ;
#endif
-bool wxApp::Initialize(int argc, wxChar **argv)
+bool wxApp::Initialize(int& argc, wxChar **argv)
{
int error = 0 ;
s_macCursorRgn = ::NewRgn() ;
+ // Mac OS X passes a process serial number command line argument when
+ // the application is launched from the Finder. This argument must be
+ // removed from the command line arguments before being handled by the
+ // application (otherwise applications would need to handle it)
+ if ( argc > 1 )
+ {
+ static const wxChar *ARG_PSN = _T("-psn_");
+ if ( wxStrncmp(argv[1], ARG_PSN, sizeof(ARG_PSN) - 1) == 0 )
+ {
+ // remove this argument
+ memmove(argv, argv + 1, argc--);
+ }
+ }
+
if ( !wxAppBase::Initialize(argc, argv) )
return false;
}
//----------------------------------------------------------------------
-// wxEntry
+// misc initialization stuff
//----------------------------------------------------------------------
// extern variable for shared library resource id
#endif /* WXMAKINGDLL && !__DARWIN__ */
-int WXDLLEXPORT wxEntryStart( int WXUNUSED(argc), char *WXUNUSED(argv)[] )
-{
- return wxApp::Initialize();
-}
-
-int WXDLLEXPORT wxEntryInitGui()
-{
- return wxTheApp->OnInitGui();
-}
-
-void WXDLLEXPORT wxEntryCleanup()
-{
- wxApp::CleanUp();
-}
-
-int wxEntry( int argc, char *argv[] , bool enterLoop )
-{
-#ifdef __MWERKS__
-#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
- // This seems to be necessary since there are 'rogue'
- // objects present at this point (perhaps global objects?)
- // Setting a checkpoint will ignore them as far as the
- // memory checking facility is concerned.
- // Of course you may argue that memory allocated in globals should be
- // checked, but this is a reasonable compromise.
- wxDebugContext::SetCheckpoint();
-#endif
-#endif
- if (!wxEntryStart(argc, argv)) {
- return 0;
- }
- // create the application object or ensure that one already exists
- if (!wxTheApp)
- {
- // The app may have declared a global application object, but we recommend
- // the IMPLEMENT_APP macro is used instead, which sets an initializer
- // function for delayed, dynamic app object construction.
- wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
- wxT("No initializer - use IMPLEMENT_APP macro.") );
-
- wxTheApp = (wxApp*) (*wxApp::GetInitializerFunction()) ();
- }
-
- wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
-
-#ifdef __DARWIN__
- // Mac OS X passes a process serial number command line argument when
- // the application is launched from the Finder. This argument must be
- // removed from the command line arguments before being handled by the
- // application (otherwise applications would need to handle it)
-
- if (argc > 1) {
- if (strncmp(argv[1], "-psn_", 5) == 0) {
- // assume the argument is always the only one and remove it
- --argc;
- }
- }
-#else
- argc = 0 ; // currently we don't support files as parameters
-#endif
- // we could try to get the open apple events here to adjust argc and argv better
-
- wxTheApp->argc = argc;
-#if wxUSE_UNICODE
- wxTheApp->argv = new wxChar*[argc+1];
- int mb_argc ;
- for ( mb_argc = 0; mb_argc < argc; mb_argc++ )
- {
- wxTheApp->argv[mb_argc] = wxStrdup(wxConvLocal.cMB2WX(argv[mb_argc]));
- }
- wxTheApp->argv[mb_argc] = (wxChar *)NULL;
-#else
- wxTheApp->argv = argv;
-#endif
-
- // GUI-specific initialization, such as creating an app context.
- wxEntryInitGui();
-
- // Here frames insert themselves automatically
- // into wxTopLevelWindows by getting created
- // in OnInit().
-
- int retValue = 0;
-
- if ( wxTheApp->OnInit() )
- {
- if ( enterLoop )
- {
- retValue = wxTheApp->OnRun();
- }
- else
- // We want to initialize, but not run or exit immediately.
- return 1;
- }
- //else: app initialization failed, so we skipped 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(NULL);
- }
- }
-
- wxTheApp->OnExit();
-
- wxEntryCleanup();
-
- return retValue;
-}
-
#if TARGET_CARBON
bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec)
WXIMPORT char std::__throws_bad_alloc ;
#endif
-bool wxApp::Initialize(int argc, wxChar **argv)
+bool wxApp::Initialize(int& argc, wxChar **argv)
{
int error = 0 ;
s_macCursorRgn = ::NewRgn() ;
+ // Mac OS X passes a process serial number command line argument when
+ // the application is launched from the Finder. This argument must be
+ // removed from the command line arguments before being handled by the
+ // application (otherwise applications would need to handle it)
+ if ( argc > 1 )
+ {
+ static const wxChar *ARG_PSN = _T("-psn_");
+ if ( wxStrncmp(argv[1], ARG_PSN, sizeof(ARG_PSN) - 1) == 0 )
+ {
+ // remove this argument
+ memmove(argv, argv + 1, argc--);
+ }
+ }
+
if ( !wxAppBase::Initialize(argc, argv) )
return false;
}
//----------------------------------------------------------------------
-// wxEntry
+// misc initialization stuff
//----------------------------------------------------------------------
// extern variable for shared library resource id
#endif /* WXMAKINGDLL && !__DARWIN__ */
-int WXDLLEXPORT wxEntryStart( int WXUNUSED(argc), char *WXUNUSED(argv)[] )
-{
- return wxApp::Initialize();
-}
-
-int WXDLLEXPORT wxEntryInitGui()
-{
- return wxTheApp->OnInitGui();
-}
-
-void WXDLLEXPORT wxEntryCleanup()
-{
- wxApp::CleanUp();
-}
-
-int wxEntry( int argc, char *argv[] , bool enterLoop )
-{
-#ifdef __MWERKS__
-#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
- // This seems to be necessary since there are 'rogue'
- // objects present at this point (perhaps global objects?)
- // Setting a checkpoint will ignore them as far as the
- // memory checking facility is concerned.
- // Of course you may argue that memory allocated in globals should be
- // checked, but this is a reasonable compromise.
- wxDebugContext::SetCheckpoint();
-#endif
-#endif
- if (!wxEntryStart(argc, argv)) {
- return 0;
- }
- // create the application object or ensure that one already exists
- if (!wxTheApp)
- {
- // The app may have declared a global application object, but we recommend
- // the IMPLEMENT_APP macro is used instead, which sets an initializer
- // function for delayed, dynamic app object construction.
- wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
- wxT("No initializer - use IMPLEMENT_APP macro.") );
-
- wxTheApp = (wxApp*) (*wxApp::GetInitializerFunction()) ();
- }
-
- wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
-
-#ifdef __DARWIN__
- // Mac OS X passes a process serial number command line argument when
- // the application is launched from the Finder. This argument must be
- // removed from the command line arguments before being handled by the
- // application (otherwise applications would need to handle it)
-
- if (argc > 1) {
- if (strncmp(argv[1], "-psn_", 5) == 0) {
- // assume the argument is always the only one and remove it
- --argc;
- }
- }
-#else
- argc = 0 ; // currently we don't support files as parameters
-#endif
- // we could try to get the open apple events here to adjust argc and argv better
-
- wxTheApp->argc = argc;
-#if wxUSE_UNICODE
- wxTheApp->argv = new wxChar*[argc+1];
- int mb_argc ;
- for ( mb_argc = 0; mb_argc < argc; mb_argc++ )
- {
- wxTheApp->argv[mb_argc] = wxStrdup(wxConvLocal.cMB2WX(argv[mb_argc]));
- }
- wxTheApp->argv[mb_argc] = (wxChar *)NULL;
-#else
- wxTheApp->argv = argv;
-#endif
-
- // GUI-specific initialization, such as creating an app context.
- wxEntryInitGui();
-
- // Here frames insert themselves automatically
- // into wxTopLevelWindows by getting created
- // in OnInit().
-
- int retValue = 0;
-
- if ( wxTheApp->OnInit() )
- {
- if ( enterLoop )
- {
- retValue = wxTheApp->OnRun();
- }
- else
- // We want to initialize, but not run or exit immediately.
- return 1;
- }
- //else: app initialization failed, so we skipped 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(NULL);
- }
- }
-
- wxTheApp->OnExit();
-
- wxEntryCleanup();
-
- return retValue;
-}
-
#if TARGET_CARBON
bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec)
wxEventLoop::GetActive()->Dispatch();
}
-bool wxApp::Initialize(int argc, wxChar **argv)
+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;
MGL_exit();
}
-
-int wxEntryStart(int argc, char *argv[])
-{
- return wxApp::Initialize() ? 0 : -1;
-}
-
-
-int wxEntryInitGui()
-{
- return wxTheApp->OnInitGui() ? 0 : -1;
-}
-
-
-void wxEntryCleanup()
-{
- wxApp::CleanUp();
-}
-
-
-
-int wxEntry(int argc, char *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
-
-#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
- // This seems to be necessary since there are 'rogue'
- // objects present at this point (perhaps global objects?)
- // Setting a checkpoint will ignore them as far as the
- // memory checking facility is concerned.
- // Of course you may argue that memory allocated in globals should be
- // checked, but this is a reasonable compromise.
- wxDebugContext::SetCheckpoint();
-#endif
- int err = wxEntryStart(argc, argv);
- if ( err )
- return err;
-
- if ( !wxTheApp )
- {
- wxCHECK_MSG( wxApp::GetInitializerFunction(), -1,
- wxT("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, wxT("wxWindows error: no application object") );
-
- wxTheApp->argc = argc;
-#if wxUSE_UNICODE
- wxTheApp->argv = new wxChar*[argc+1];
- int mb_argc = 0;
- while (mb_argc < argc)
- {
- wxTheApp->argv[mb_argc] = wxStrdup(wxConvLibc.cMB2WX(argv[mb_argc]));
- mb_argc++;
- }
- wxTheApp->argv[mb_argc] = (wxChar *)NULL;
-#else
- wxTheApp->argv = argv;
-#endif
-
- wxString name(wxFileNameFromPath(argv[0]));
- wxStripExtension(name);
- wxTheApp->SetAppName(name);
-
- int retValue;
- retValue = wxEntryInitGui();
-
- // Here frames insert themselves automatically into wxTopLevelWindows by
- // getting created in OnInit().
- if ( retValue == 0 )
- {
- if ( !wxTheApp->OnInit() )
- retValue = -1;
- }
-
- if ( retValue == 0 )
- {
- /* delete pending toplevel windows (typically a single
- dialog) so that, if there isn't any left, we don't
- call OnRun() */
- wxTheApp->DeletePendingObjects();
-
- if ( wxTheApp->Initialized() )
- {
- 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);
- }
- }
-
-#if wxUSE_LOG
- // flush the logged messages if any
- wxLog *log = wxLog::GetActiveTarget();
- if (log != NULL && log->HasPendingMessages())
- log->Flush();
-#endif // wxUSE_LOG
- retValue = wxTheApp->OnExit();
- }
- }
-
- wxEntryCleanup();
-
- return retValue;
-}
}
#endif // __WXDEBUG__
-bool wxApp::Initialize(int argc, wxChar **argv)
+bool wxApp::Initialize(int& argc, wxChar **argv)
{
if ( !wxAppBase::Initialize(argc, argv) )
return false;
}
// ============================================================================
-// wxEntry*
+// wxApp
// ============================================================================
-int wxEntryStart( int argc, char* argv[] )
-{
-#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
- // This seems to be necessary since there are 'rogue'
- // objects present at this point (perhaps global objects?)
- // Setting a checkpoint will ignore them as far as the
- // memory checking facility is concerned.
- // Of course you may argue that memory allocated in globals should be
- // checked, but this is a reasonable compromise.
- wxDebugContext::SetCheckpoint();
-#endif
-
- if (!wxApp::Initialize())
- return -1;
-
- return 0;
-}
-
-int wxEntryInitGui()
-{
- int retValue = 0;
-
- // GUI-specific initialization, such as creating an app context.
- if (!wxTheApp->OnInitGui())
- retValue = -1;
-
- return retValue;
-}
-
-void wxEntryCleanup()
-{
- // So dialog boxes aren't used for further messages
- delete wxLog::SetActiveTarget(new wxLogStderr);
-
- // flush the logged messages if any
- wxLog *pLog = wxLog::GetActiveTarget();
- if ( pLog != NULL && pLog->HasPendingMessages() )
- pLog->Flush();
-
- wxApp::CleanUp();
-}
-
-int wxEntry( int argc, char *argv[] )
-{
- int retValue = 0;
-
- retValue = wxEntryStart( argc, argv );
- if (retValue) return retValue;
-
- if (!wxTheApp)
- {
- if (!wxApp::GetInitializerFunction())
- {
- printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
- return 0;
- };
-
- wxTheApp = (wxApp*) (* wxApp::GetInitializerFunction()) ();
- };
-
- if (!wxTheApp)
- {
- printf( "wxWindows error: wxTheApp == NULL\n" );
- return 0;
- };
-
- wxTheApp->SetClassName(wxFileNameFromPath(argv[0]));
- wxTheApp->SetAppName(wxFileNameFromPath(argv[0]));
-
- wxTheApp->argc = argc;
- wxTheApp->argv = argv;
-
- // GUI-specific initialization, such as creating an app context.
- retValue = wxEntryInitGui();
- if (retValue) return retValue;
-
- // Here frames insert themselves automatically into wxTopLevelWindows by
- // getting created in OnInit().
-
- if (wxTheApp->OnInit())
- {
- if (wxTheApp->Initialized())
- wxTheApp->OnRun();
- }
-
- if (wxTheApp->GetTopWindow())
- {
- delete wxTheApp->GetTopWindow();
- wxTheApp->SetTopWindow(NULL);
- }
-
- wxTheApp->DeletePendingObjects();
-
- retValue = wxTheApp->OnExit();
-
- wxEntryCleanup();
-
- return retValue;
-}
-
wxApp::wxApp()
{
argc = 0;
};
//// Initialize
-bool wxApp::Initialize(int argc, wxChar **argv)
+bool wxApp::Initialize(int& argc, wxChar **argv)
{
if ( !wxAppBase::Initialize(argc, argv) )
return false;
//
// Initialize
//
-bool wxApp::Initialize(int argc, wxChar **argv)
+bool wxApp::Initialize(int& argc, wxChar **argv)
{
if ( !wxAppBase::Initialize(argc, argv) )
return false;
wxAppBase::CleanUp();
} // end of wxApp::CleanUp
-//----------------------------------------------------------------------
-// Main wxWindows entry point
-//----------------------------------------------------------------------
-int wxEntry(
- int argc
-, char* argv[]
-)
-{
- HAB vHab = 0;
-
- if (!wxApp::Initialize(vHab))
- return 0;
-
- //
- // create the application object or ensure that one already exists
- //
- if (!wxTheApp)
- {
- // The app may have declared a global application object, but we recommend
- // the IMPLEMENT_APP macro is used instead, which sets an initializer
- // function for delayed, dynamic app object construction.
- wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
- wxT("No initializer - use IMPLEMENT_APP macro.") );
- wxTheApp = (*wxApp::GetInitializerFunction()) ();
- }
- wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
- wxTheApp->argc = argc;
-
-#if wxUSE_UNICODE
- wxTheApp->argv = new wxChar*[argc+1];
-
- int nArgc = 0;
-
- while (nArgc < argc)
- {
- wxTheApp->argv[nArgc] = wxStrdup(wxConvLibc.cMB2WX(argv[nArgc]));
- nArgc++;
- }
- wxTheApp->argv[nArgc] = (wxChar *)NULL;
-#else
- wxTheApp->argv = argv;
-#endif
-
- wxString sName(wxFileNameFromPath(argv[0]));
-
- wxStripExtension(sName);
- wxTheApp->SetAppName(sName);
-
- int nRetValue = 0;
-
- if (!wxTheApp->OnInitGui())
- nRetValue = -1;
-
- if (nRetValue == 0)
- {
- if (wxTheApp->OnInit())
- {
- wxTheApp->OnRun();
- }
- // Normal exit
- wxWindow* pTopWindow = wxTheApp->GetTopWindow();
- if (pTopWindow)
- {
- // Forcibly delete the window.
- if (pTopWindow->IsKindOf(CLASSINFO(wxFrame)) ||
- pTopWindow->IsKindOf(CLASSINFO(wxDialog)) )
- {
- pTopWindow->Close(TRUE);
- wxTheApp->DeletePendingObjects();
- }
- else
- {
- delete pTopWindow;
- wxTheApp->SetTopWindow(NULL);
- }
- }
- }
- else // app initialization failed
- {
- wxLogLastError(" Gui initialization failed, exitting");
- }
-#if wxUSE_CONSOLEDEBUG
- printf("wxTheApp->OnExit ");
- fflush(stdout);
-#endif
- nRetValue = wxTheApp->OnExit();
-#if wxUSE_CONSOLEDEBUG
- printf("wxApp::CleanUp ");
- fflush(stdout);
-#endif
- wxApp::CleanUp();
-#if wxUSE_CONSOLEDEBUG
- printf("return %i ", nRetValue);
- fflush(stdout);
-#endif
- return(nRetValue);
-} // end of wxEntry
-
bool wxApp::OnInitGui()
{
ERRORID vError;
wxHashTable *wxWidgetHashTable = NULL;
wxHashTable *wxClientWidgetHashTable = NULL;
-// This is set within wxEntryStart -- too early on
-// to put these in wxTheApp
static bool g_showIconic = FALSE;
static wxSize g_initialSize = wxDefaultSize;
EVT_IDLE(wxApp::OnIdle)
END_EVENT_TABLE()
-bool wxApp::Initialize(int argc, wxChar **argv)
+bool wxApp::Initialize(int& argc, wxChar **argv)
{
- if ( !wxAppBase::Initialize(argc, argv) )
- return false;
-
-#if wxUSE_INTL
- wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
-#endif
-
- wxWidgetHashTable = new wxHashTable(wxKEY_INTEGER);
- wxClientWidgetHashTable = new wxHashTable(wxKEY_INTEGER);
-
- return true;
-}
-
-void wxApp::CleanUp()
-{
- delete wxWidgetHashTable;
- wxWidgetHashTable = NULL;
- delete wxClientWidgetHashTable;
- wxClientWidgetHashTable = NULL;
-
- wxAppBase::CleanUp();
-}
-
-// NB: argc and argv may be changed here, pass by reference!
-int wxEntryStart( int& argc, char *argv[] )
-{
-#ifdef __WXDEBUG__
-#if !wxUSE_NANOX
+#if defined(__WXDEBUG__) && !wxUSE_NANOX
// install the X error handler
gs_pfnXErrorHandler = XSetErrorHandler( wxXErrorHandler );
-#endif
#endif // __WXDEBUG__
char *displayName = NULL;
bool syncDisplay = FALSE;
- int i;
- for (i = 0; i < argc; i++)
+ int argcOrig = argc;
+ for ( int i = 0; i < argcOrig; i++ )
{
- if (strcmp( argv[i], "-display") == 0)
+ if (wxStrcmp( argv[i], _T("-display") ) == 0)
{
if (i < (argc - 1))
{
- i ++;
+ argv[i++] = NULL;
+
displayName = argv[i];
- continue;
+
+ argv[i] = NULL;
+ argc -= 2;
}
}
- else if (strcmp( argv[i], "-geometry") == 0)
+ else if (wxStrcmp( argv[i], _T("-geometry") ) == 0)
{
if (i < (argc - 1))
{
- i ++;
+ argv[i++] = NULL;
+
int w, h;
- if (sscanf(argv[i], "%dx%d", &w, &h) != 2)
+ if (wxSscanf(argv[i], _T("%dx%d"), &w, &h) != 2)
{
- wxLogError( _("Invalid geometry specification '%s'"), wxString::FromAscii(argv[i]).c_str() );
+ wxLogError( _("Invalid geometry specification '%s'"),
+ wxString::FromAscii(argv[i]).c_str() );
}
else
{
g_initialSize = wxSize(w, h);
}
- continue;
+
+ argv[i] = NULL;
+ argc -= 2;
}
}
- else if (strcmp( argv[i], "-sync") == 0)
+ else if (wxStrcmp( argv[i], _T("-sync") ) == 0)
{
syncDisplay = TRUE;
- continue;
+
+ argv[i] = NULL;
+ argc--;
}
- else if (strcmp( argv[i], "-iconic") == 0)
+ else if (wxStrcmp( argv[i], _T("-iconic") ) == 0)
{
g_showIconic = TRUE;
- continue;
+ argv[i] = NULL;
+ argc--;
}
+ }
+ if ( argc != argcOrig )
+ {
+ // remove the argumens we consumed
+ for ( int i = 0; i < argc; i++ )
+ {
+ while ( !argv[i] )
+ {
+ memmove(argv + i, argv + i + 1, argcOrig - i);
+ }
+ }
}
// X11 display stuff
- Display* xdisplay = XOpenDisplay( displayName );
+ Display *xdisplay = XOpenDisplay( displayName );
if (!xdisplay)
{
wxLogError( _("wxWindows could not open display. Exiting.") );
- return -1;
+ return false;
+ }
+
+ if ( !wxAppBase::Initialize(argc, argv) )
+ {
+ XCloseDisplay(xdisplay);
+
+ return false;
}
if (syncDisplay)
XSynchronize(xdisplay, True);
- wxApp::ms_display = (WXDisplay*) xdisplay;
+ ms_display = (WXDisplay*) xdisplay;
XSelectInput( xdisplay, XDefaultRootWindow(xdisplay), PropertyChangeMask);
g_type_init();
#endif
- if (!wxApp::Initialize())
- return -1;
-
- return 0;
-}
-
-int wxEntryInitGui()
-{
- int retValue = 0;
+#if wxUSE_INTL
+ wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
+#endif
- if ( !wxTheApp->OnInitGui() )
- retValue = -1;
+ wxWidgetHashTable = new wxHashTable(wxKEY_INTEGER);
+ wxClientWidgetHashTable = new wxHashTable(wxKEY_INTEGER);
- return retValue;
+ return true;
}
-
-int wxEntry( int argc, char *argv[] )
+void wxApp::CleanUp()
{
-#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
- // This seems to be necessary since there are 'rogue'
- // objects present at this point (perhaps global objects?)
- // Setting a checkpoint will ignore them as far as the
- // memory checking facility is concerned.
- // Of course you may argue that memory allocated in globals should be
- // checked, but this is a reasonable compromise.
- wxDebugContext::SetCheckpoint();
-#endif
- int err = wxEntryStart(argc, argv);
- if (err)
- return err;
-
- if (!wxTheApp)
- {
- if (!wxApp::GetInitializerFunction())
- {
- printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
- return 0;
- }
-
- wxTheApp = (wxApp*) (* wxApp::GetInitializerFunction()) ();
- }
-
- if (!wxTheApp)
- {
- printf( "wxWindows error: wxTheApp == NULL\n" );
- return 0;
- }
-
- // Command line argument stuff
- wxTheApp->argc = argc;
-#if wxUSE_UNICODE
- wxTheApp->argv = new wxChar*[argc+1];
- int mb_argc = 0;
- while (mb_argc < argc)
- {
- wxString tmp = wxString::FromAscii( argv[mb_argc] );
- wxTheApp->argv[mb_argc] = wxStrdup( tmp.c_str() );
- mb_argc++;
- }
- wxTheApp->argv[mb_argc] = (wxChar *)NULL;
-#else
- wxTheApp->argv = argv;
-#endif
-
- if (wxTheApp->argc > 0)
- {
- wxFileName fname( wxTheApp->argv[0] );
- wxTheApp->SetAppName( fname.GetName() );
- }
-
- wxTheApp->m_showIconic = g_showIconic;
- wxTheApp->m_initialSize = g_initialSize;
-
- int retValue;
- retValue = wxEntryInitGui();
-
- // Here frames insert themselves automatically into wxTopLevelWindows by
- // getting created in OnInit().
- if ( retValue == 0 )
- {
- if ( !wxTheApp->OnInit() )
- retValue = -1;
- }
-
- if ( retValue == 0 )
- {
- if (wxTheApp->Initialized()) retValue = wxTheApp->OnRun();
- }
-
- // flush the logged messages if any
- wxLog *pLog = wxLog::GetActiveTarget();
- if ( pLog != NULL && pLog->HasPendingMessages() )
- pLog->Flush();
-
- delete wxLog::SetActiveTarget(new wxLogStderr); // So dialog boxes aren't used
- // for further messages
-
- if (wxTheApp->GetTopWindow())
- {
- delete wxTheApp->GetTopWindow();
- wxTheApp->SetTopWindow(NULL);
- }
-
- wxTheApp->DeletePendingObjects();
-
- wxTheApp->OnExit();
-
- wxApp::CleanUp();
+ delete wxWidgetHashTable;
+ wxWidgetHashTable = NULL;
+ delete wxClientWidgetHashTable;
+ wxClientWidgetHashTable = NULL;
- return retValue;
-};
+ wxAppBase::CleanUp();
+}
wxApp::wxApp()
{