]> git.saurik.com Git - wxWidgets.git/commitdiff
replaced the old wxApp with wxAppConsole::ms_appInstance of type wxAppConsole; wxTheA...
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 1 Aug 2003 23:00:16 +0000 (23:00 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 1 Aug 2003 23:00:16 +0000 (23:00 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22457 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/app.h
src/common/appbase.cpp
src/common/init.cpp

index 31f27162cf2883d29d7217b377c9d6e260c91c05..1a356a01d8db1599210634a147145b40352b1c2a 100644 (file)
@@ -275,6 +275,10 @@ public:
     int      argc;
     wxChar **argv;
 
+    // the one and only global application object (must be public for backwards
+    // compatibility as assigning to wxTheApp should work)
+    static wxAppConsole *ms_appInstance;
+
 protected:
     // the function which creates the traits object when GetTraits() needs it
     // for the first time
@@ -284,6 +288,7 @@ protected:
     // function used for dynamic wxApp creation
     static wxAppInitializerFunction ms_appInitFn;
 
+
     // application info (must be set from the user code)
     wxString m_vendorName,      // vendor name (ACME Inc)
              m_appName,         // app name
@@ -512,6 +517,7 @@ protected:
         #include "wx/os2/app.h"
     #endif
 #else // !GUI
+    // allow using just wxApp (instead of wxAppConsole) in console programs
     typedef wxAppConsole wxApp;
 #endif // GUI/!GUI
 
@@ -519,11 +525,16 @@ protected:
 // the global data
 // ----------------------------------------------------------------------------
 
-// the one and only application object - use of wxTheApp in application code
-// is discouraged, consider using DECLARE_APP() after which you may call
-// wxGetApp() which will return the object of the correct type (i.e. MyApp and
-// not wxApp)
-WXDLLIMPEXP_DATA_BASE(extern wxApp*) wxTheApp;
+// for compatibility, we define this macro to access the global application
+// object of type wxApp
+//
+// note that instead of using of wxTheApp in application code you should
+// consider using DECLARE_APP() after which you may call wxGetApp() which will
+// return the object of the correct type (i.e. MyApp and not wxApp)
+//
+// the cast is safe as in GUI build we only use wxApp, not wxAppConsole, and in
+// console mode it does nothing at all
+#define wxTheApp ((wxApp *)wxApp::ms_appInstance)
 
 // ----------------------------------------------------------------------------
 // global functions
index fddde79afd73b2d9287b2f99786571c1ae34399a..5971f3962be89936ba65cdcd2a4c18853c296d03 100644 (file)
@@ -89,7 +89,7 @@
 // global vars
 // ----------------------------------------------------------------------------
 
-wxApp *wxTheApp = NULL;
+wxAppConsole *wxAppConsole::ms_appInstance = NULL;
 
 wxAppInitializerFunction wxAppConsole::ms_appInitFn = NULL;
 
@@ -105,7 +105,7 @@ wxAppConsole::wxAppConsole()
 {
     m_traits = NULL;
 
-    wxTheApp = (wxApp *)this;
+    ms_appInstance = this;
 
 #ifdef __WXDEBUG__
     SetTraceMasks();
index 32288fd1e325fbcbc58fedcf72626754ff81d450..a797719db46546ef9d9d89a9398c238cb7af66f7 100644 (file)
@@ -67,7 +67,7 @@ public:
 };
 
 // we need a special kind of auto pointer to wxApp which not only deletes the
-// pointer it holds in its dtor but also resets wxTheApp
+// pointer it holds in its dtor but also resets the global application pointer
 wxDECLARE_SCOPED_PTR(wxApp, wxAppPtrBase);
 wxDEFINE_SCOPED_PTR(wxApp, wxAppPtrBase);
 
@@ -245,11 +245,7 @@ bool wxEntryStart(int& argc, wxChar **argv)
         if ( fnCreate )
         {
             // he did, try to create the custom wxApp object
-            // 
-            // NB: cast is needed because for the backwards-compatibility
-            //     reasons wxTheApp is really a wxApp and not just 
-            //     wxAppConsole...
-            app.Set((wxApp*)(*fnCreate)());
+            app.Set((*fnCreate)());
         }
     }
 
@@ -257,25 +253,22 @@ bool wxEntryStart(int& argc, wxChar **argv)
     {
         // either IMPLEMENT_APP() was not used at all or it failed -- in any
         // case we still need something
-        //
-        // NB: cast is needed because for the backwards-compatibility reasons
-        //     wxTheApp is really a wxApp and not just wxAppConsole...
-        app.Set((wxApp *)new wxDummyConsoleApp);
+        app.Set(new wxDummyConsoleApp);
     }
 
 
     // wxApp initialization: this can be customized
     // --------------------------------------------
 
-    if ( !wxTheApp->Initialize(argc, argv) )
+    if ( !app->Initialize(argc, argv) )
     {
         return false;
     }
 
-    wxCallAppCleanup callAppCleanup(wxTheApp);
+    wxCallAppCleanup callAppCleanup(app.get());
 
     // for compatibility call the old initialization function too
-    if ( !wxTheApp->OnInitGui() )
+    if ( !app->OnInitGui() )
         return false;