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