X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e39af974ef7846e26686ae39d74e4696c1fef0c3..f46f68d9f1f0bb4126fc85ba68013b3df40435ea:/include/wx/app.h diff --git a/include/wx/app.h b/include/wx/app.h index c479f17df7..3698f65a09 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 // ---------------------------------------------------------------------------- @@ -169,11 +170,13 @@ public: #if wxUSE_CMDLINE_PARSER // this one is called from OnInit() to add all supported options - // to the given parser + // to the given parser (don't forget to call the base class version if you + // override it!) virtual void OnInitCmdLine(wxCmdLineParser& parser); // called after successfully parsing the command line, return TRUE - // to continue and FALSE to exit + // to continue and FALSE to exit (don't forget to call the base class + // version if you override it!) virtual bool OnCmdLineParsed(wxCmdLineParser& parser); // called if "--help" option was specified, return TRUE to continue @@ -254,12 +257,12 @@ public: const wxChar *cond, const wxChar *msg); #endif // __WXDEBUG__ - + // check that the wxBuildOptions object (constructed in the application // itself, usually the one from IMPLEMENT_APP() macro) matches the build // options of the library and abort if it doesn't - static bool CheckBuildOptions(const wxBuildOptions& buildOptions); - + static bool CheckBuildOptions(const char *optionsSignature, + const char *componentName); // implementation only from now on // ------------------------------- @@ -270,6 +273,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 +294,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 @@ -334,6 +348,9 @@ public: // Override: rarely in GUI applications, always in console ones. virtual int OnRun(); + // a matching function for OnInit() + virtual int OnExit(); + // very last clean up function // // Override: very rarely @@ -381,13 +398,12 @@ public: // it should return TRUE if more idle events are needed, FALSE if not virtual bool ProcessIdle() ; - // Send idle event to all top-level windows. - // Returns TRUE if more idle time is requested. - virtual bool SendIdleEvents(); - // Send idle event to window and all subwindows // Returns TRUE if more idle time is requested. - virtual bool SendIdleEvents(wxWindow* win); + virtual bool SendIdleEvents(wxWindow* win, wxIdleEvent& event); + + // Perform standard OnIdle behaviour: call from port's OnIdle + void OnIdle(wxIdleEvent& event); // top level window functions @@ -446,6 +462,13 @@ public: int GetPrintMode() const { return wxPRINT_POSTSCRIPT; } + // command line parsing (GUI-specific) + // ------------------------------------------------------------------------ + + virtual bool OnCmdLineParsed(wxCmdLineParser& parser); + virtual void OnInitCmdLine(wxCmdLineParser& parser); + + // miscellaneous other stuff // ------------------------------------------------------------------------ @@ -513,21 +536,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 @@ -569,8 +595,7 @@ public: int main(int argc, char **argv) { return wxEntry(argc, argv); } #elif defined(__WXMSW__) && defined(WXUSINGDLL) // we need HINSTANCE declaration to define WinMain() - #include - #include "wx/msw/winundef.h" + #include "wx/msw/wrapwin.h" #define IMPLEMENT_WXWIN_MAIN \ extern int wxEntry(HINSTANCE hInstance, \ @@ -601,9 +626,10 @@ 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(WX_BUILD_OPTIONS_SIGNATURE, \ + "your program"); \ return new appname; \ } \ wxAppInitializer \