X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/955a919785b76a1826e6b8d55f696a0dfb62a318..3d1f1919657af3ccd160b88b83d3748d0335f319:/include/wx/app.h diff --git a/include/wx/app.h b/include/wx/app.h index 35d9b5d06e..c95c47751c 100644 --- a/include/wx/app.h +++ b/include/wx/app.h @@ -26,7 +26,7 @@ #include "wx/build.h" #include "wx/init.h" // we must declare wxEntry() -class WXDLLIMPEXP_CORE wxApp; +class WXDLLIMPEXP_BASE wxAppConsole; class WXDLLIMPEXP_BASE wxAppTraits; class WXDLLIMPEXP_BASE wxCmdLineParser; class WXDLLIMPEXP_BASE wxLog; @@ -37,7 +37,7 @@ class WXDLLIMPEXP_BASE wxMessageOutput; // ---------------------------------------------------------------------------- // the type of the function used to create a wxApp object on program start up -typedef wxApp* (*wxAppInitializerFunction)(); +typedef wxAppConsole* (*wxAppInitializerFunction)(); // ---------------------------------------------------------------------------- // constants @@ -75,6 +75,7 @@ private: }; #endif // wxUSE_GUI + // ---------------------------------------------------------------------------- // wxAppConsole: wxApp for non-GUI applications // ---------------------------------------------------------------------------- @@ -270,6 +271,13 @@ public: static wxAppInitializerFunction GetInitializerFunction() { return ms_appInitFn; } + // accessors for ms_appInstance field (external code might wish to modify + // it, this is why we provide a setter here as well, but you should really + // know what you're doing if you call it), wxTheApp is usually used instead + // of GetInstance() + static wxAppConsole *GetInstance() { return ms_appInstance; } + static void SetInstance(wxAppConsole *app) { ms_appInstance = app; } + // command line arguments (public for backwards compatibility) int argc; @@ -284,6 +292,10 @@ protected: // function used for dynamic wxApp creation static wxAppInitializerFunction ms_appInitFn; + // the one and only global application object + static wxAppConsole *ms_appInstance; + + // application info (must be set from the user code) wxString m_vendorName, // vendor name (ACME Inc) m_appName, // app name @@ -512,21 +524,24 @@ protected: #include "wx/os2/app.h" #endif #else // !GUI - // can't use typedef because wxApp forward declared as a class - class WXDLLIMPEXP_BASE wxApp : public wxAppConsole - { - }; + // 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::GetInstance()) // ---------------------------------------------------------------------------- // global functions @@ -600,9 +615,9 @@ public: // Use this macro if you want to define your own main() or WinMain() function // and call wxEntry() from there. #define IMPLEMENT_APP_NO_MAIN(appname) \ - wxApp *wxCreateApp() \ + wxAppConsole *wxCreateApp() \ { \ - wxApp::CheckBuildOptions(wxBuildOptions()); \ + wxAppConsole::CheckBuildOptions(wxBuildOptions()); \ return new appname; \ } \ wxAppInitializer \