]> git.saurik.com Git - wxWidgets.git/commitdiff
more work on fixing wxEntry() and ANSI/Unicode cmd line args mess
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 30 Jun 2003 20:02:05 +0000 (20:02 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 30 Jun 2003 20:02:05 +0000 (20:02 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21520 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

24 files changed:
include/wx/app.h
include/wx/cocoa/app.h
include/wx/gtk/app.h
include/wx/gtk1/app.h
include/wx/init.h
include/wx/mac/app.h
include/wx/mgl/app.h
include/wx/motif/app.h
include/wx/msw/app.h
include/wx/os2/app.h
include/wx/x11/app.h
src/cocoa/app.mm
src/common/appbase.cpp
src/common/appcmn.cpp
src/common/init.cpp
src/gtk/app.cpp
src/gtk1/app.cpp
src/mac/app.cpp
src/mac/carbon/app.cpp
src/mgl/app.cpp
src/motif/app.cpp
src/msw/app.cpp
src/os2/app.cpp
src/x11/app.cpp

index 5ed82cebefc75afde670663bd462938a131c9ded..22afb2459b943dd14af6b64706529832e0a3da8b 100644 (file)
@@ -95,7 +95,7 @@ public:
     // 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
@@ -314,7 +314,7 @@ public:
         // 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.
index ffb6b3d82c703d34281de4cb65629f4fff570b89..cb9c7d933ebd85c034f98ead5b4c731f34fed624 100644 (file)
@@ -66,7 +66,7 @@ public:
     // 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();
index fea48cf032eb2829df87aa165a316b328a07a54e..1cda1b39eaab122ea7b3fdee7378a2d4ac2b327d 100644 (file)
@@ -58,7 +58,7 @@ public:
     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();
index fea48cf032eb2829df87aa165a316b328a07a54e..1cda1b39eaab122ea7b3fdee7378a2d4ac2b327d 100644 (file)
@@ -58,7 +58,7 @@ public:
     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();
index f973e9b0f36beded2979abfd279e4f0b58cdddf1..5b6672c9a768b5ee079a3d1b0cacdad1aabfc9f8 100644 (file)
@@ -24,8 +24,9 @@
 // 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)
@@ -41,7 +42,7 @@ extern void WXDLLEXPORT wxEntryCleanup();
 // 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);
 
 
 // ----------------------------------------------------------------------------
index 592e797f3f57deacfb708016c74aba203ca7f4c1..99556638d1eeb04640fa3daa1b142fd39996cf71 100644 (file)
@@ -91,7 +91,7 @@ protected:
 public:
 
     // Implementation
-    virtual bool Initialize(int argc, wxChar **argv);
+    virtual bool Initialize(int& argc, wxChar **argv);
     virtual void CleanUp();
     
     bool IsExiting() { return !m_keepGoing ; }
index ea3a377ab6108add13969d676584e80dadc27a89..1142fd2da675b2300691504c2609a8cba995ef10 100644 (file)
@@ -54,7 +54,7 @@ public:
     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);
index 8f8b632ba82f3bcf57d1cab6ddcef49a66da23c7..fef30fbcdc3bd896e47055d409361d85a5c2b774 100644 (file)
@@ -82,7 +82,7 @@ protected:
     
 public:
     // Implementation
-    virtual bool Initialize(int argc, wxChar **argv);
+    virtual bool Initialize(int& argc, wxChar **argv);
     virtual void CleanUp();
     
     // Motif-specific
index 756430f73c2ab452e8a650673d69fc8a8d676fbd..768833038d6cd25c42671679d9415e94d0feac54 100644 (file)
@@ -36,7 +36,7 @@ public:
     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();
index 915e1a12678053a276a9db218db77b9ed698e1e1..9a26ede018e6b0a358a4b2781587bfaebac15218 100644 (file)
@@ -126,7 +126,7 @@ private:
 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);
index d8d709a77a6975db3e16595e1be00ab07f5a6e5c..edbe54182028c89e57b48f928ac4249205b4d842 100644 (file)
@@ -89,7 +89,7 @@ protected:
     
 public:
     // Implementation
-    virtual bool Initialize();
+    virtual bool Initialize(int& argc, wxChar **argv);
     virtual void CleanUp();
     
     void DeletePendingObjects();
index 8532a12f941933b42343f14907fd109d22438faa..58addbd3d75499ea435b2f62b70648dd7a6d4ec9 100644 (file)
@@ -111,99 +111,6 @@ WX_IMPLEMENT_POSER(wxPoserNSApplication);
 // 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();
@@ -229,11 +136,25 @@ END_EVENT_TABLE()
 #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
index 99708fd85e0f7fdd4aaaee8cadfa79d56cfa14a2..f3a5e7460b01f95b87dd74784b34eb739581f4c9 100644 (file)
@@ -121,7 +121,7 @@ wxAppConsole::~wxAppConsole()
 // initilization/cleanup
 // ----------------------------------------------------------------------------
 
-bool wxAppConsole::Initialize(int argc, wxChar **argv)
+bool wxAppConsole::Initialize(int& argc, wxChar **argv)
 {
     // remember the command line arguments
     this->argc = argc;
index 21466c15ecceef29315124ec0677085a9c25b631..78ede412b947a79f9c5afb3f69bb577e3085e26c 100644 (file)
@@ -73,19 +73,11 @@ wxAppBase::wxAppBase()
     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
index e696eacb12421a36b85b3fc96e3e1e828689fd74..ec81ea6ede1ec11c5e609dd7a01ede65ee10cd09 100644 (file)
@@ -87,6 +87,20 @@ public:
     }
 };
 
+// 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
@@ -180,7 +194,7 @@ static bool DoCommonPostInit()
     return wxModule::InitializeModules();
 }
 
-bool wxEntryStart(int argc, wxChar **argv)
+bool wxEntryStart(int& argc, wxChar **argv)
 {
     // do minimal, always necessary, initialization
     // --------------------------------------------
@@ -229,26 +243,33 @@ bool wxEntryStart(int argc, wxChar **argv)
         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);
 
@@ -339,7 +360,7 @@ void wxEntryCleanup()
     #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) )
index a062fd79bf70d437ad7b9027e6c0d2463cbf72e3..66f2b9a39514657876d4daebb683e4c0e58711c8 100644 (file)
@@ -676,25 +676,6 @@ bool wxApp::Initialize(int argc, wxChar **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) &&
@@ -707,162 +688,85 @@ int wxEntryStart( int& argc, char *argv[] )
     {
         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__
index a062fd79bf70d437ad7b9027e6c0d2463cbf72e3..66f2b9a39514657876d4daebb683e4c0e58711c8 100644 (file)
@@ -676,25 +676,6 @@ bool wxApp::Initialize(int argc, wxChar **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) &&
@@ -707,162 +688,85 @@ int wxEntryStart( int& argc, char *argv[] )
     {
         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__
index 9c3502089d0985bc5f8b76432ac8b0bb2baae516..9fd758b3a02e193d048ce1ce423d66fdbbf0dfe1 100644 (file)
@@ -447,7 +447,7 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler )
 WXIMPORT char std::__throws_bad_alloc ;
 #endif
 
-bool wxApp::Initialize(int argc, wxChar **argv)
+bool wxApp::Initialize(int& argc, wxChar **argv)
 {
     int error = 0 ;
 
@@ -535,6 +535,20 @@ bool wxApp::Initialize(int argc, wxChar **argv)
 
     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;
 
@@ -634,7 +648,7 @@ void wxApp::CleanUp()
 }
 
 //----------------------------------------------------------------------
-// wxEntry
+// misc initialization stuff
 //----------------------------------------------------------------------
 
 // extern variable for shared library resource id
@@ -813,126 +827,6 @@ pascal void __wxterminate(void)
 
 #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)
index 9c3502089d0985bc5f8b76432ac8b0bb2baae516..9fd758b3a02e193d048ce1ce423d66fdbbf0dfe1 100644 (file)
@@ -447,7 +447,7 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler )
 WXIMPORT char std::__throws_bad_alloc ;
 #endif
 
-bool wxApp::Initialize(int argc, wxChar **argv)
+bool wxApp::Initialize(int& argc, wxChar **argv)
 {
     int error = 0 ;
 
@@ -535,6 +535,20 @@ bool wxApp::Initialize(int argc, wxChar **argv)
 
     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;
 
@@ -634,7 +648,7 @@ void wxApp::CleanUp()
 }
 
 //----------------------------------------------------------------------
-// wxEntry
+// misc initialization stuff
 //----------------------------------------------------------------------
 
 // extern variable for shared library resource id
@@ -813,126 +827,6 @@ pascal void __wxterminate(void)
 
 #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)
index f21c6a862a3fdccc7c330aa85ca00650dcd47895..2e85732f90a20108672462b4b5fa928469c6f5cc 100644 (file)
@@ -383,8 +383,14 @@ void wxApp::Dispatch()
     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;
@@ -422,129 +428,3 @@ void wxApp::CleanUp()
     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;
-}
index a2e569037cffca52c77e7560f2690e0542cc46bb..0185173142f40a4dded1568394669283a62b2eb0 100644 (file)
@@ -86,7 +86,7 @@ END_EVENT_TABLE()
     }
 #endif // __WXDEBUG__
 
-bool wxApp::Initialize(int argc, wxChar **argv)
+bool wxApp::Initialize(int& argc, wxChar **argv)
 {
     if ( !wxAppBase::Initialize(argc, argv) )
         return false;
@@ -112,109 +112,9 @@ void wxApp::Exit()
 }
 
 // ============================================================================
-// 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;
index d0adf0525b0ae806dbdb1242ad3c188468046a93..904f0aaed73e3f20431bb33b1677012e29a464ef 100644 (file)
@@ -258,7 +258,7 @@ private:
 };
 
 //// Initialize
-bool wxApp::Initialize(int argc, wxChar **argv)
+bool wxApp::Initialize(int& argc, wxChar **argv)
 {
     if ( !wxAppBase::Initialize(argc, argv) )
         return false;
index bde40f8e18498da049ef933a12a1d545b26ee9b2..fc5d9650093aca9a139f8a050390702a08bcf1ec 100644 (file)
@@ -226,7 +226,7 @@ void wxApp::HandleSockets()
 //
 // Initialize
 //
-bool wxApp::Initialize(int argc, wxChar **argv)
+bool wxApp::Initialize(int& argc, wxChar **argv)
 {
     if ( !wxAppBase::Initialize(argc, argv) )
         return false;
@@ -470,104 +470,6 @@ void wxApp::CleanUp()
     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;
index b24c11fbabaf5092a5c64678d1a1c4066e060273..4a6aca507eeb3d7f267e68142b50aef914a686ed 100644 (file)
@@ -49,8 +49,6 @@ extern wxList wxPendingDelete;
 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;
 
@@ -93,99 +91,99 @@ BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
     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
-    Displayxdisplay = 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);
 
@@ -197,118 +195,25 @@ int wxEntryStart( int& argc, char *argv[] )
     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()
 {