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
// 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
#include "wx/os2/app.h"
#endif
#else // !GUI
+ // allow using just wxApp (instead of wxAppConsole) in console programs
typedef wxAppConsole wxApp;
#endif // GUI/!GUI
// 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
// global vars
// ----------------------------------------------------------------------------
-wxApp *wxTheApp = NULL;
+wxAppConsole *wxAppConsole::ms_appInstance = NULL;
wxAppInitializerFunction wxAppConsole::ms_appInitFn = NULL;
{
m_traits = NULL;
- wxTheApp = (wxApp *)this;
+ ms_appInstance = this;
#ifdef __WXDEBUG__
SetTraceMasks();
};
// 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);
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)());
}
}
{
// 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;