#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;
// ----------------------------------------------------------------------------
// the type of the function used to create a wxApp object on program start up
-typedef wxApp* (*wxAppInitializerFunction)();
+typedef wxAppConsole* (*wxAppInitializerFunction)();
// ----------------------------------------------------------------------------
// constants
};
#endif // wxUSE_GUI
+
// ----------------------------------------------------------------------------
// wxAppConsole: wxApp for non-GUI applications
// ----------------------------------------------------------------------------
#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
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
// -------------------------------
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;
// 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
// 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
// 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
int GetPrintMode() const { return wxPRINT_POSTSCRIPT; }
+ // command line parsing (GUI-specific)
+ // ------------------------------------------------------------------------
+
+ virtual bool OnCmdLineParsed(wxCmdLineParser& parser);
+ virtual void OnInitCmdLine(wxCmdLineParser& parser);
+
+
// miscellaneous other stuff
// ------------------------------------------------------------------------
#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
int main(int argc, char **argv) { return wxEntry(argc, argv); }
#elif defined(__WXMSW__) && defined(WXUSINGDLL)
// we need HINSTANCE declaration to define WinMain()
- #include <windows.h>
- #include "wx/msw/winundef.h"
+ #include "wx/msw/wrapwin.h"
#define IMPLEMENT_WXWIN_MAIN \
extern int wxEntry(HINSTANCE hInstance, \
// 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 \