X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e2478fde622a16d25c66690af353dfdc37e7b582..2d9c0e97c580cff977d75760dc0d82c5852eec2c:/include/wx/app.h?ds=sidebyside diff --git a/include/wx/app.h b/include/wx/app.h index 2a653d9560..35d9b5d06e 100644 --- a/include/wx/app.h +++ b/include/wx/app.h @@ -13,10 +13,6 @@ #ifndef _WX_APP_H_BASE_ #define _WX_APP_H_BASE_ -#if defined(__GNUG__) && !defined(__APPLE__) - #pragma interface "appbase.h" -#endif - // ---------------------------------------------------------------------------- // headers we have to include here // ---------------------------------------------------------------------------- @@ -28,12 +24,13 @@ #endif // wxUSE_GUI #include "wx/build.h" +#include "wx/init.h" // we must declare wxEntry() -class WXDLLEXPORT wxApp; -class WXDLLEXPORT wxAppTraits; -class WXDLLEXPORT wxCmdLineParser; -class WXDLLEXPORT wxLog; -class WXDLLEXPORT wxMessageOutput; +class WXDLLIMPEXP_CORE wxApp; +class WXDLLIMPEXP_BASE wxAppTraits; +class WXDLLIMPEXP_BASE wxCmdLineParser; +class WXDLLIMPEXP_BASE wxLog; +class WXDLLIMPEXP_BASE wxMessageOutput; // ---------------------------------------------------------------------------- // typedefs @@ -60,7 +57,7 @@ enum // VS: Fullscreen/framebuffer application needs to choose display mode prior // to wxWindows initialization. This class holds information about display // mode. It is used by wxApp::Set/GetDisplayMode. -class WXDLLEXPORT wxDisplayModeInfo +class WXDLLIMPEXP_CORE wxDisplayModeInfo { public: wxDisplayModeInfo() : m_ok(FALSE) {} @@ -82,7 +79,7 @@ private: // wxAppConsole: wxApp for non-GUI applications // ---------------------------------------------------------------------------- -class WXDLLEXPORT wxAppConsole : public wxEvtHandler +class WXDLLIMPEXP_BASE wxAppConsole : public wxEvtHandler { public: // ctor and dtor @@ -93,12 +90,25 @@ public: // the virtual functions which may/must be overridden in the derived class // ----------------------------------------------------------------------- + // This is the very first function called for a newly created wxApp object, + // it is used by the library to do the global initialization. If, for some + // reason, you must override it (instead of just overriding OnInit(), as + // usual, for app-specific initializations), do not forget to call the base + // class version! + virtual bool Initialize(int& argc, wxChar **argv); + + // This gives wxCocoa a chance to call OnInit() with a memory pool in place + virtual bool CallOnInit() { return OnInit(); } + // Called before OnRun(), this is a good place to do initialization -- if // anything fails, return false from here to prevent the program from // continuing. The command line is normally parsed here, call the base // class OnInit() to do it. virtual bool OnInit(); + // this is here only temproary hopefully (FIXME) + virtual bool OnInitGui() { return true; } + // This is the replacement for the normal main(): all program work should // be done here. When OnRun() returns, the programs starts shutting down. virtual int OnRun() = 0; @@ -107,6 +117,11 @@ public: // any cleanup matching the initializations done there. virtual int OnExit(); + // This is the very last function called on wxApp object before it is + // destroyed. If you override it (instead of overriding OnExit() as usual) + // do not forget to call the base class version! + virtual void CleanUp(); + // Called when a fatal exception occurs, this function should take care not // to do anything which might provoke a nested exception! It may be // overridden if you wish to react somehow in non-default way (core dump @@ -290,7 +305,7 @@ protected: #if wxUSE_GUI -class WXDLLEXPORT wxAppBase : public wxAppConsole +class WXDLLIMPEXP_CORE wxAppBase : public wxAppConsole { public: wxAppBase(); @@ -299,6 +314,11 @@ public: // the virtual functions which may/must be overridden in the derived class // ----------------------------------------------------------------------- + // very first initialization function + // + // Override: very rarely + virtual bool Initialize(int& argc, wxChar **argv); + // a platform-dependent version of OnInit(): the code here is likely to // depend on the toolkit. default version does nothing. // @@ -314,8 +334,10 @@ public: // Override: rarely in GUI applications, always in console ones. virtual int OnRun(); - // exit the main loop thus terminating the application - virtual void Exit(); + // very last clean up function + // + // Override: very rarely + virtual void CleanUp(); // the worker functions - usually not used directly by the user code @@ -324,6 +346,9 @@ public: // execute the main GUI loop, the function returns when the loop ends virtual int MainLoop() = 0; + // exit the main loop thus terminating the application + virtual void Exit(); + // exit the main GUI loop during the next iteration (i.e. it does not // stop the program immediately!) virtual void ExitMainLoop() = 0; @@ -354,7 +379,14 @@ public: // parties // // it should return TRUE if more idle events are needed, FALSE if not - virtual bool ProcessIdle() = 0; + virtual bool ProcessIdle() ; + + // Send idle event to window and all subwindows + // Returns TRUE if more idle time is requested. + virtual bool SendIdleEvents(wxWindow* win, wxIdleEvent& event); + + // Perform standard OnIdle behaviour: call from port's OnIdle + void OnIdle(wxIdleEvent& event); // top level window functions @@ -423,6 +455,9 @@ public: protected: + // delete all objects in wxPendingDelete list + void DeletePendingObjects(); + // override base class method to use GUI traits virtual wxAppTraits *CreateTraits(); @@ -478,7 +513,7 @@ protected: #endif #else // !GUI // can't use typedef because wxApp forward declared as a class - class WXDLLEXPORT wxApp : public wxAppConsole + class WXDLLIMPEXP_BASE wxApp : public wxAppConsole { }; #endif // GUI/!GUI @@ -491,7 +526,7 @@ protected: // 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) -WXDLLEXPORT_DATA(extern wxApp*) wxTheApp; +WXDLLIMPEXP_DATA_BASE(extern wxApp*) wxTheApp; // ---------------------------------------------------------------------------- // global functions @@ -501,51 +536,13 @@ WXDLLEXPORT_DATA(extern wxApp*) wxTheApp; // ------------------------------------------------------ // Force an exit from main loop -extern void WXDLLEXPORT wxExit(); +extern void WXDLLIMPEXP_BASE wxExit(); // Yield to other apps/messages -extern bool WXDLLEXPORT wxYield(); +extern bool WXDLLIMPEXP_BASE wxYield(); // Yield to other apps/messages -extern void WXDLLEXPORT wxWakeUpIdle(); - - -// console applications may avoid using DECLARE_APP and IMPLEMENT_APP macros -// and call these functions instead at the program startup and termination -// ------------------------------------------------------------------------- - -#if !wxUSE_GUI - -// initialize the library (may be called as many times as needed, but each -// call to wxInitialize() must be matched by wxUninitialize()) -extern bool WXDLLEXPORT wxInitialize(); - -// clean up - the library can't be used any more after the last call to -// wxUninitialize() -extern void WXDLLEXPORT wxUninitialize(); - -// create an object of this class on stack to initialize/cleanup thel ibrary -// automatically -class WXDLLEXPORT wxInitializer -{ -public: - // initialize the library - wxInitializer() { m_ok = wxInitialize(); } - - // has the initialization been successful? (explicit test) - bool IsOk() const { return m_ok; } - - // has the initialization been successful? (implicit test) - operator bool() const { return m_ok; } - - // dtor only does clean up if we initialized the library properly - ~wxInitializer() { if ( m_ok ) wxUninitialize(); } - -private: - bool m_ok; -}; - -#endif // !wxUSE_GUI +extern void WXDLLIMPEXP_BASE wxWakeUpIdle(); // ---------------------------------------------------------------------------- // macros for dynamic creation of the application object @@ -555,7 +552,7 @@ private: // creator function. wxApp can then call this function to create a new app // object. Convoluted, but necessary. -class WXDLLEXPORT wxAppInitializer +class WXDLLIMPEXP_BASE wxAppInitializer { public: wxAppInitializer(wxAppInitializerFunction fn) @@ -566,32 +563,25 @@ public: // be in your main program (e.g. hello.cpp). Now IMPLEMENT_APP should add this // code if required. -#if !wxUSE_GUI || defined(__WXMOTIF__) || defined(__WXGTK__) || defined(__WXPM__) || defined(__WXMGL__) || defined(__WXCOCOA__) - #define IMPLEMENT_WXWIN_MAIN \ - extern int wxEntry( int argc, char **argv ); \ - int main(int argc, char **argv) { return wxEntry(argc, argv); } -#elif defined(__WXMAC__) - // wxMac seems to have a specific wxEntry prototype - #define IMPLEMENT_WXWIN_MAIN \ - extern int wxEntry( int argc, char **argv, bool enterLoop = TRUE ); \ +#if !wxUSE_GUI || !defined(__WXMSW__) + #define IMPLEMENT_WXWIN_MAIN \ int main(int argc, char **argv) { return wxEntry(argc, argv); } #elif defined(__WXMSW__) && defined(WXUSINGDLL) - // NT defines APIENTRY, 3.x not - #if !defined(WXAPIENTRY) - #define WXAPIENTRY WXFAR wxSTDCALL - #endif - + // we need HINSTANCE declaration to define WinMain() #include #include "wx/msw/winundef.h" #define IMPLEMENT_WXWIN_MAIN \ - extern "C" int WXAPIENTRY WinMain(HINSTANCE hInstance,\ - HINSTANCE hPrevInstance,\ - LPSTR m_lpCmdLine, int nCmdShow)\ - {\ - return wxEntry((WXHINSTANCE) hInstance,\ - (WXHINSTANCE) hPrevInstance,\ - m_lpCmdLine, nCmdShow);\ + extern int wxEntry(HINSTANCE hInstance, \ + HINSTANCE hPrevInstance = NULL, \ + char *pCmdLine = NULL, \ + int nCmdShow = SW_NORMAL); \ + extern "C" int WINAPI WinMain(HINSTANCE hInstance, \ + HINSTANCE hPrevInstance, \ + char *lpCmdLine, \ + int nCmdShow) \ + { \ + return wxEntry(hInstance, hPrevInstance, lpCmdLine, nCmdShow); \ } #else #define IMPLEMENT_WXWIN_MAIN @@ -609,13 +599,14 @@ 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() \ - { \ - wxApp::CheckBuildOptions(wxBuildOptions()); \ - return new appname; \ - } \ - wxAppInitializer wxTheAppInitializer((wxAppInitializerFunction) wxCreateApp); \ +#define IMPLEMENT_APP_NO_MAIN(appname) \ + wxApp *wxCreateApp() \ + { \ + wxApp::CheckBuildOptions(wxBuildOptions()); \ + return new appname; \ + } \ + wxAppInitializer \ + wxTheAppInitializer((wxAppInitializerFunction) wxCreateApp); \ appname& wxGetApp() { return *(appname *)wxTheApp; } // Same as IMPLEMENT_APP() normally but doesn't include themes support in @@ -634,5 +625,5 @@ public: // function #define DECLARE_APP(appname) extern appname& wxGetApp(); -#endif - // _WX_APP_H_BASE_ +#endif // _WX_APP_H_BASE_ +