From: Vadim Zeitlin Date: Fri, 1 Aug 2003 23:00:16 +0000 (+0000) Subject: replaced the old wxApp with wxAppConsole::ms_appInstance of type wxAppConsole; wxTheA... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/7cafd224fe6d2d5b4ea0281783dea4dd244212f9 replaced the old wxApp with wxAppConsole::ms_appInstance of type wxAppConsole; wxTheApp is now a macro for backwards compatibility (this fixes problems with contradictorary wxTheApp definitions in separate build) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22457 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/app.h b/include/wx/app.h index 31f27162cf..1a356a01d8 100644 --- a/include/wx/app.h +++ b/include/wx/app.h @@ -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 diff --git a/src/common/appbase.cpp b/src/common/appbase.cpp index fddde79afd..5971f3962b 100644 --- a/src/common/appbase.cpp +++ b/src/common/appbase.cpp @@ -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(); diff --git a/src/common/init.cpp b/src/common/init.cpp index 32288fd1e3..a797719db4 100644 --- a/src/common/init.cpp +++ b/src/common/init.cpp @@ -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;