app.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/app.h
  3. // Purpose: wxAppBase class and macros used for declaration of wxApp
  4. // derived class in the user code
  5. // Author: Julian Smart
  6. // Modified by:
  7. // Created: 01/02/97
  8. // Copyright: (c) Julian Smart
  9. // Licence: wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11. #ifndef _WX_APP_H_BASE_
  12. #define _WX_APP_H_BASE_
  13. // ----------------------------------------------------------------------------
  14. // headers we have to include here
  15. // ----------------------------------------------------------------------------
  16. #include "wx/event.h" // for the base class
  17. #include "wx/eventfilter.h" // (and another one)
  18. #include "wx/build.h"
  19. #include "wx/cmdargs.h" // for wxCmdLineArgsArray used by wxApp::argv
  20. #include "wx/init.h" // we must declare wxEntry()
  21. #include "wx/intl.h" // for wxLayoutDirection
  22. #include "wx/log.h" // for wxDISABLE_DEBUG_LOGGING_IN_RELEASE_BUILD()
  23. class WXDLLIMPEXP_FWD_BASE wxAppConsole;
  24. class WXDLLIMPEXP_FWD_BASE wxAppTraits;
  25. class WXDLLIMPEXP_FWD_BASE wxCmdLineParser;
  26. class WXDLLIMPEXP_FWD_BASE wxEventLoopBase;
  27. class WXDLLIMPEXP_FWD_BASE wxMessageOutput;
  28. #if wxUSE_GUI
  29. struct WXDLLIMPEXP_FWD_CORE wxVideoMode;
  30. class WXDLLIMPEXP_FWD_CORE wxWindow;
  31. #endif
  32. // this macro should be used in any main() or equivalent functions defined in wx
  33. #define wxDISABLE_DEBUG_SUPPORT() \
  34. wxDISABLE_ASSERTS_IN_RELEASE_BUILD(); \
  35. wxDISABLE_DEBUG_LOGGING_IN_RELEASE_BUILD()
  36. // ----------------------------------------------------------------------------
  37. // typedefs
  38. // ----------------------------------------------------------------------------
  39. // the type of the function used to create a wxApp object on program start up
  40. typedef wxAppConsole* (*wxAppInitializerFunction)();
  41. // ----------------------------------------------------------------------------
  42. // constants
  43. // ----------------------------------------------------------------------------
  44. enum
  45. {
  46. wxPRINT_WINDOWS = 1,
  47. wxPRINT_POSTSCRIPT = 2
  48. };
  49. // ----------------------------------------------------------------------------
  50. // global variables
  51. // ----------------------------------------------------------------------------
  52. // use of this list is strongly deprecated, use wxApp ScheduleForDestruction()
  53. // and IsScheduledForDestruction() methods instead of this list directly, it
  54. // is here for compatibility purposes only
  55. extern WXDLLIMPEXP_DATA_BASE(wxList) wxPendingDelete;
  56. // ----------------------------------------------------------------------------
  57. // wxAppConsoleBase: wxApp for non-GUI applications
  58. // ----------------------------------------------------------------------------
  59. class WXDLLIMPEXP_BASE wxAppConsoleBase : public wxEvtHandler,
  60. public wxEventFilter
  61. {
  62. public:
  63. // ctor and dtor
  64. wxAppConsoleBase();
  65. virtual ~wxAppConsoleBase();
  66. // the virtual functions which may/must be overridden in the derived class
  67. // -----------------------------------------------------------------------
  68. // This is the very first function called for a newly created wxApp object,
  69. // it is used by the library to do the global initialization. If, for some
  70. // reason, you must override it (instead of just overriding OnInit(), as
  71. // usual, for app-specific initializations), do not forget to call the base
  72. // class version!
  73. virtual bool Initialize(int& argc, wxChar **argv);
  74. // This gives wxCocoa a chance to call OnInit() with a memory pool in place
  75. virtual bool CallOnInit() { return OnInit(); }
  76. // Called before OnRun(), this is a good place to do initialization -- if
  77. // anything fails, return false from here to prevent the program from
  78. // continuing. The command line is normally parsed here, call the base
  79. // class OnInit() to do it.
  80. virtual bool OnInit();
  81. // This is the replacement for the normal main(): all program work should
  82. // be done here. When OnRun() returns, the programs starts shutting down.
  83. virtual int OnRun();
  84. // Called before the first events are handled, called from within MainLoop()
  85. virtual void OnLaunched();
  86. // This is called by wxEventLoopBase::SetActive(): you should put the code
  87. // which needs an active event loop here.
  88. // Note that this function is called whenever an event loop is activated;
  89. // you may want to use wxEventLoopBase::IsMain() to perform initialization
  90. // specific for the app's main event loop.
  91. virtual void OnEventLoopEnter(wxEventLoopBase* WXUNUSED(loop)) {}
  92. // This is only called if OnInit() returned true so it's a good place to do
  93. // any cleanup matching the initializations done there.
  94. virtual int OnExit();
  95. // This is called by wxEventLoopBase::OnExit() for each event loop which
  96. // is exited.
  97. virtual void OnEventLoopExit(wxEventLoopBase* WXUNUSED(loop)) {}
  98. // This is the very last function called on wxApp object before it is
  99. // destroyed. If you override it (instead of overriding OnExit() as usual)
  100. // do not forget to call the base class version!
  101. virtual void CleanUp();
  102. // Called when a fatal exception occurs, this function should take care not
  103. // to do anything which might provoke a nested exception! It may be
  104. // overridden if you wish to react somehow in non-default way (core dump
  105. // under Unix, application crash under Windows) to fatal program errors,
  106. // however extreme care should be taken if you don't want this function to
  107. // crash.
  108. virtual void OnFatalException() { }
  109. // Called from wxExit() function, should terminate the application a.s.a.p.
  110. virtual void Exit();
  111. // application info: name, description, vendor
  112. // -------------------------------------------
  113. // NB: all these should be set by the application itself, there are no
  114. // reasonable default except for the application name which is taken to
  115. // be argv[0]
  116. // set/get the application name
  117. wxString GetAppName() const;
  118. void SetAppName(const wxString& name) { m_appName = name; }
  119. // set/get the application display name: the display name is the name
  120. // shown to the user in titles, reports, etc while the app name is
  121. // used for paths, config, and other places the user doesn't see
  122. //
  123. // by default the display name is the same as app name or a capitalized
  124. // version of the program if app name was not set neither but it's
  125. // usually better to set it explicitly to something nicer
  126. wxString GetAppDisplayName() const;
  127. void SetAppDisplayName(const wxString& name) { m_appDisplayName = name; }
  128. // set/get the app class name
  129. wxString GetClassName() const { return m_className; }
  130. void SetClassName(const wxString& name) { m_className = name; }
  131. // set/get the vendor name
  132. const wxString& GetVendorName() const { return m_vendorName; }
  133. void SetVendorName(const wxString& name) { m_vendorName = name; }
  134. // set/get the vendor display name: the display name is shown
  135. // in titles/reports/dialogs to the user, while the vendor name
  136. // is used in some areas such as wxConfig, wxStandardPaths, etc
  137. const wxString& GetVendorDisplayName() const
  138. {
  139. return m_vendorDisplayName.empty() ? GetVendorName()
  140. : m_vendorDisplayName;
  141. }
  142. void SetVendorDisplayName(const wxString& name)
  143. {
  144. m_vendorDisplayName = name;
  145. }
  146. // cmd line parsing stuff
  147. // ----------------------
  148. // all of these methods may be overridden in the derived class to
  149. // customize the command line parsing (by default only a few standard
  150. // options are handled)
  151. //
  152. // you also need to call wxApp::OnInit() from YourApp::OnInit() for all
  153. // this to work
  154. #if wxUSE_CMDLINE_PARSER
  155. // this one is called from OnInit() to add all supported options
  156. // to the given parser (don't forget to call the base class version if you
  157. // override it!)
  158. virtual void OnInitCmdLine(wxCmdLineParser& parser);
  159. // called after successfully parsing the command line, return true
  160. // to continue and false to exit (don't forget to call the base class
  161. // version if you override it!)
  162. virtual bool OnCmdLineParsed(wxCmdLineParser& parser);
  163. // called if "--help" option was specified, return true to continue
  164. // and false to exit
  165. virtual bool OnCmdLineHelp(wxCmdLineParser& parser);
  166. // called if incorrect command line options were given, return
  167. // false to abort and true to continue
  168. virtual bool OnCmdLineError(wxCmdLineParser& parser);
  169. #endif // wxUSE_CMDLINE_PARSER
  170. // miscellaneous customization functions
  171. // -------------------------------------
  172. // create the app traits object to which we delegate for everything which
  173. // either should be configurable by the user (then he can change the
  174. // default behaviour simply by overriding CreateTraits() and returning his
  175. // own traits object) or which is GUI/console dependent as then wxAppTraits
  176. // allows us to abstract the differences behind the common facade
  177. wxAppTraits *GetTraits();
  178. // this function provides safer access to traits object than
  179. // wxTheApp->GetTraits() during startup or termination when the global
  180. // application object itself may be unavailable
  181. //
  182. // of course, it still returns NULL in this case and the caller must check
  183. // for it
  184. static wxAppTraits *GetTraitsIfExists();
  185. // Return some valid traits object.
  186. //
  187. // This method checks if we have wxTheApp and returns its traits if it does
  188. // exist and the traits are non-NULL, similarly to GetTraitsIfExists(), but
  189. // falls back to wxConsoleAppTraits to ensure that it always returns
  190. // something valid.
  191. static wxAppTraits& GetValidTraits();
  192. // returns the main event loop instance, i.e. the event loop which is started
  193. // by OnRun() and which dispatches all events sent from the native toolkit
  194. // to the application (except when new event loops are temporarily set-up).
  195. // The returned value maybe NULL. Put initialization code which needs a
  196. // non-NULL main event loop into OnEventLoopEnter().
  197. wxEventLoopBase* GetMainLoop() const
  198. { return m_mainLoop; }
  199. // This function sets the C locale to the default locale for the current
  200. // environment. It is advised to call this to ensure that the underlying
  201. // toolkit uses the locale in which the numbers and monetary amounts are
  202. // shown in the format expected by user and so on.
  203. //
  204. // Notice that this does _not_ change the global C++ locale, you need to do
  205. // it explicitly if you want.
  206. //
  207. // Finally, notice that while this function is virtual, it is not supposed
  208. // to be overridden outside of the library itself.
  209. virtual void SetCLocale();
  210. // event processing functions
  211. // --------------------------
  212. // Implement the inherited wxEventFilter method but just return -1 from it
  213. // to indicate that default processing should take place.
  214. virtual int FilterEvent(wxEvent& event);
  215. // return true if we're running event loop, i.e. if the events can
  216. // (already) be dispatched
  217. static bool IsMainLoopRunning();
  218. #if wxUSE_EXCEPTIONS
  219. // execute the functor to handle the given event
  220. //
  221. // this is a generalization of HandleEvent() below and the base class
  222. // implementation of CallEventHandler() still calls HandleEvent() for
  223. // compatibility for functors which are just wxEventFunctions (i.e. methods
  224. // of wxEvtHandler)
  225. virtual void CallEventHandler(wxEvtHandler *handler,
  226. wxEventFunctor& functor,
  227. wxEvent& event) const;
  228. // call the specified handler on the given object with the given event
  229. //
  230. // this method only exists to allow catching the exceptions thrown by any
  231. // event handler, it would lead to an extra (useless) virtual function call
  232. // if the exceptions were not used, so it doesn't even exist in that case
  233. virtual void HandleEvent(wxEvtHandler *handler,
  234. wxEventFunction func,
  235. wxEvent& event) const;
  236. // Called when an unhandled C++ exception occurs inside OnRun(): note that
  237. // the main event loop has already terminated by now and the program will
  238. // exit, if you need to really handle the exceptions you need to override
  239. // OnExceptionInMainLoop()
  240. virtual void OnUnhandledException();
  241. // Function called if an uncaught exception is caught inside the main
  242. // event loop: it may return true to continue running the event loop or
  243. // false to stop it (in the latter case it may rethrow the exception as
  244. // well)
  245. virtual bool OnExceptionInMainLoop();
  246. #endif // wxUSE_EXCEPTIONS
  247. // pending events
  248. // --------------
  249. // IMPORTANT: all these methods conceptually belong to wxEventLoopBase
  250. // but for many reasons we need to allow queuing of events
  251. // even when there's no event loop (e.g. in wxApp::OnInit);
  252. // this feature is used e.g. to queue events on secondary threads
  253. // or in wxPython to use wx.CallAfter before the GUI is initialized
  254. // process all events in the m_handlersWithPendingEvents list -- it is necessary
  255. // to call this function to process posted events. This happens during each
  256. // event loop iteration in GUI mode but if there is no main loop, it may be
  257. // also called directly.
  258. virtual void ProcessPendingEvents();
  259. // check if there are pending events on global pending event list
  260. bool HasPendingEvents() const;
  261. // temporary suspends processing of the pending events
  262. void SuspendProcessingOfPendingEvents();
  263. // resume processing of the pending events previously stopped because of a
  264. // call to SuspendProcessingOfPendingEvents()
  265. void ResumeProcessingOfPendingEvents();
  266. // called by ~wxEvtHandler to (eventually) remove the handler from the list of
  267. // the handlers with pending events
  268. void RemovePendingEventHandler(wxEvtHandler* toRemove);
  269. // adds an event handler to the list of the handlers with pending events
  270. void AppendPendingEventHandler(wxEvtHandler* toAppend);
  271. // moves the event handler from the list of the handlers with pending events
  272. //to the list of the handlers with _delayed_ pending events
  273. void DelayPendingEventHandler(wxEvtHandler* toDelay);
  274. // deletes the current pending events
  275. void DeletePendingEvents();
  276. // delayed destruction
  277. // -------------------
  278. // If an object may have pending events for it, it shouldn't be deleted
  279. // immediately as this would result in a crash when trying to handle these
  280. // events: instead, it should be scheduled for destruction and really
  281. // destroyed only after processing all pending events.
  282. //
  283. // Notice that this is only possible if we have a running event loop,
  284. // otherwise the object is just deleted directly by ScheduleForDestruction()
  285. // and IsScheduledForDestruction() always returns false.
  286. // schedule the object for destruction in the near future
  287. void ScheduleForDestruction(wxObject *object);
  288. // return true if the object is scheduled for destruction
  289. bool IsScheduledForDestruction(wxObject *object) const;
  290. // wxEventLoop-related methods
  291. // ---------------------------
  292. // all these functions are forwarded to the corresponding methods of the
  293. // currently active event loop -- and do nothing if there is none
  294. virtual bool Pending();
  295. virtual bool Dispatch();
  296. virtual int MainLoop();
  297. virtual void ExitMainLoop();
  298. bool Yield(bool onlyIfNeeded = false);
  299. virtual void WakeUpIdle();
  300. // this method is called by the active event loop when there are no events
  301. // to process
  302. //
  303. // by default it generates the idle events and if you override it in your
  304. // derived class you should call the base class version to ensure that idle
  305. // events are still sent out
  306. virtual bool ProcessIdle();
  307. // this virtual function is overridden in GUI wxApp to always return true
  308. // as GUI applications always have an event loop -- but console ones may
  309. // have it or not, so it simply returns true if already have an event loop
  310. // running but false otherwise
  311. virtual bool UsesEventLoop() const;
  312. // debugging support
  313. // -----------------
  314. // this function is called when an assert failure occurs, the base class
  315. // version does the normal processing (i.e. shows the usual assert failure
  316. // dialog box)
  317. //
  318. // the arguments are the location of the failed assert (func may be empty
  319. // if the compiler doesn't support C99 __FUNCTION__), the text of the
  320. // assert itself and the user-specified message
  321. virtual void OnAssertFailure(const wxChar *file,
  322. int line,
  323. const wxChar *func,
  324. const wxChar *cond,
  325. const wxChar *msg);
  326. // old version of the function without func parameter, for compatibility
  327. // only, override OnAssertFailure() in the new code
  328. virtual void OnAssert(const wxChar *file,
  329. int line,
  330. const wxChar *cond,
  331. const wxChar *msg);
  332. // check that the wxBuildOptions object (constructed in the application
  333. // itself, usually the one from wxIMPLEMENT_APP() macro) matches the build
  334. // options of the library and abort if it doesn't
  335. static bool CheckBuildOptions(const char *optionsSignature,
  336. const char *componentName);
  337. // implementation only from now on
  338. // -------------------------------
  339. // helpers for dynamic wxApp construction
  340. static void SetInitializerFunction(wxAppInitializerFunction fn)
  341. { ms_appInitFn = fn; }
  342. static wxAppInitializerFunction GetInitializerFunction()
  343. { return ms_appInitFn; }
  344. // accessors for ms_appInstance field (external code might wish to modify
  345. // it, this is why we provide a setter here as well, but you should really
  346. // know what you're doing if you call it), wxTheApp is usually used instead
  347. // of GetInstance()
  348. static wxAppConsole *GetInstance() { return ms_appInstance; }
  349. static void SetInstance(wxAppConsole *app) { ms_appInstance = app; }
  350. // command line arguments (public for backwards compatibility)
  351. int argc;
  352. // this object is implicitly convertible to either "char**" (traditional
  353. // type of argv parameter of main()) or to "wchar_t **" (for compatibility
  354. // with Unicode build in previous wx versions and because the command line
  355. // can, in pr
  356. #if wxUSE_UNICODE
  357. wxCmdLineArgsArray argv;
  358. #else
  359. char **argv;
  360. #endif
  361. protected:
  362. // delete all objects in wxPendingDelete list
  363. //
  364. // called from ProcessPendingEvents()
  365. void DeletePendingObjects();
  366. // the function which creates the traits object when GetTraits() needs it
  367. // for the first time
  368. virtual wxAppTraits *CreateTraits();
  369. // function used for dynamic wxApp creation
  370. static wxAppInitializerFunction ms_appInitFn;
  371. // the one and only global application object
  372. static wxAppConsole *ms_appInstance;
  373. // create main loop from AppTraits or return NULL if
  374. // there is no main loop implementation
  375. wxEventLoopBase *CreateMainLoop();
  376. // application info (must be set from the user code)
  377. wxString m_vendorName, // vendor name ("acme")
  378. m_vendorDisplayName, // vendor display name (e.g. "ACME Inc")
  379. m_appName, // app name ("myapp")
  380. m_appDisplayName, // app display name ("My Application")
  381. m_className; // class name
  382. // the class defining the application behaviour, NULL initially and created
  383. // by GetTraits() when first needed
  384. wxAppTraits *m_traits;
  385. // the main event loop of the application (may be NULL if the loop hasn't
  386. // been started yet or has already terminated)
  387. wxEventLoopBase *m_mainLoop;
  388. // pending events management vars:
  389. // the array of the handlers with pending events which needs to be processed
  390. // inside ProcessPendingEvents()
  391. wxEvtHandlerArray m_handlersWithPendingEvents;
  392. // helper array used by ProcessPendingEvents() to store the event handlers
  393. // which have pending events but of these events none can be processed right now
  394. // (because of a call to wxEventLoop::YieldFor() which asked to selectively process
  395. // pending events)
  396. wxEvtHandlerArray m_handlersWithPendingDelayedEvents;
  397. #if wxUSE_THREADS
  398. // this critical section protects both the lists above
  399. wxCriticalSection m_handlersWithPendingEventsLocker;
  400. #endif
  401. // flag modified by Suspend/ResumeProcessingOfPendingEvents()
  402. bool m_bDoPendingEventProcessing;
  403. friend class WXDLLIMPEXP_FWD_BASE wxEvtHandler;
  404. // the application object is a singleton anyhow, there is no sense in
  405. // copying it
  406. wxDECLARE_NO_COPY_CLASS(wxAppConsoleBase);
  407. };
  408. #if defined(__UNIX__) && !defined(__WINDOWS__)
  409. #include "wx/unix/app.h"
  410. #else
  411. // this has to be a class and not a typedef as we forward declare it
  412. class wxAppConsole : public wxAppConsoleBase { };
  413. #endif
  414. // ----------------------------------------------------------------------------
  415. // wxAppBase: the common part of wxApp implementations for all platforms
  416. // ----------------------------------------------------------------------------
  417. #if wxUSE_GUI
  418. class WXDLLIMPEXP_CORE wxAppBase : public wxAppConsole
  419. {
  420. public:
  421. wxAppBase();
  422. virtual ~wxAppBase();
  423. // the virtual functions which may/must be overridden in the derived class
  424. // -----------------------------------------------------------------------
  425. // very first initialization function
  426. //
  427. // Override: very rarely
  428. virtual bool Initialize(int& argc, wxChar **argv);
  429. // a platform-dependent version of OnInit(): the code here is likely to
  430. // depend on the toolkit. default version does nothing.
  431. //
  432. // Override: rarely.
  433. virtual bool OnInitGui();
  434. // called to start program execution - the default version just enters
  435. // the main GUI loop in which events are received and processed until
  436. // the last window is not deleted (if GetExitOnFrameDelete) or
  437. // ExitMainLoop() is called. In console mode programs, the execution
  438. // of the program really starts here
  439. //
  440. // Override: rarely in GUI applications, always in console ones.
  441. virtual int OnRun();
  442. // a matching function for OnInit()
  443. virtual int OnExit();
  444. // very last clean up function
  445. //
  446. // Override: very rarely
  447. virtual void CleanUp();
  448. // the worker functions - usually not used directly by the user code
  449. // -----------------------------------------------------------------
  450. // safer alternatives to Yield(), using wxWindowDisabler
  451. virtual bool SafeYield(wxWindow *win, bool onlyIfNeeded);
  452. virtual bool SafeYieldFor(wxWindow *win, long eventsToProcess);
  453. // this virtual function is called in the GUI mode when the application
  454. // becomes idle and normally just sends wxIdleEvent to all interested
  455. // parties
  456. //
  457. // it should return true if more idle events are needed, false if not
  458. virtual bool ProcessIdle();
  459. // override base class version: GUI apps always use an event loop
  460. virtual bool UsesEventLoop() const { return true; }
  461. // top level window functions
  462. // --------------------------
  463. // return true if our app has focus
  464. virtual bool IsActive() const { return m_isActive; }
  465. // set the "main" top level window
  466. void SetTopWindow(wxWindow *win) { m_topWindow = win; }
  467. // return the "main" top level window (if it hadn't been set previously
  468. // with SetTopWindow(), will return just some top level window and, if
  469. // there are none, will return NULL)
  470. virtual wxWindow *GetTopWindow() const;
  471. // control the exit behaviour: by default, the program will exit the
  472. // main loop (and so, usually, terminate) when the last top-level
  473. // program window is deleted. Beware that if you disable this behaviour
  474. // (with SetExitOnFrameDelete(false)), you'll have to call
  475. // ExitMainLoop() explicitly from somewhere.
  476. void SetExitOnFrameDelete(bool flag)
  477. { m_exitOnFrameDelete = flag ? Yes : No; }
  478. bool GetExitOnFrameDelete() const
  479. { return m_exitOnFrameDelete == Yes; }
  480. // display mode, visual, printing mode, ...
  481. // ------------------------------------------------------------------------
  482. // Get display mode that is used use. This is only used in framebuffer
  483. // wxWin ports such as wxDFB.
  484. virtual wxVideoMode GetDisplayMode() const;
  485. // Set display mode to use. This is only used in framebuffer wxWin
  486. // ports such as wxDFB. This method should be called from
  487. // wxApp::OnInitGui
  488. virtual bool SetDisplayMode(const wxVideoMode& WXUNUSED(info)) { return true; }
  489. // set use of best visual flag (see below)
  490. void SetUseBestVisual( bool flag, bool forceTrueColour = false )
  491. { m_useBestVisual = flag; m_forceTrueColour = forceTrueColour; }
  492. bool GetUseBestVisual() const { return m_useBestVisual; }
  493. // set/get printing mode: see wxPRINT_XXX constants.
  494. //
  495. // default behaviour is the normal one for Unix: always use PostScript
  496. // printing.
  497. virtual void SetPrintMode(int WXUNUSED(mode)) { }
  498. int GetPrintMode() const { return wxPRINT_POSTSCRIPT; }
  499. // Return the layout direction for the current locale or wxLayout_Default
  500. // if it's unknown
  501. virtual wxLayoutDirection GetLayoutDirection() const;
  502. // Change the theme used by the application, return true on success.
  503. virtual bool SetNativeTheme(const wxString& WXUNUSED(theme)) { return false; }
  504. // command line parsing (GUI-specific)
  505. // ------------------------------------------------------------------------
  506. #if wxUSE_CMDLINE_PARSER
  507. virtual bool OnCmdLineParsed(wxCmdLineParser& parser);
  508. virtual void OnInitCmdLine(wxCmdLineParser& parser);
  509. #endif
  510. // miscellaneous other stuff
  511. // ------------------------------------------------------------------------
  512. // called by toolkit-specific code to set the app status: active (we have
  513. // focus) or not and also the last window which had focus before we were
  514. // deactivated
  515. virtual void SetActive(bool isActive, wxWindow *lastFocus);
  516. #if WXWIN_COMPATIBILITY_2_6
  517. // returns true if the program is successfully initialized
  518. wxDEPRECATED_MSG("always returns true now, don't call")
  519. bool Initialized();
  520. #endif // WXWIN_COMPATIBILITY_2_6
  521. protected:
  522. // override base class method to use GUI traits
  523. virtual wxAppTraits *CreateTraits();
  524. // the main top level window (may be NULL)
  525. wxWindow *m_topWindow;
  526. // if Yes, exit the main loop when the last top level window is deleted, if
  527. // No don't do it and if Later -- only do it once we reach our OnRun()
  528. //
  529. // the explanation for using this strange scheme is given in appcmn.cpp
  530. enum
  531. {
  532. Later = -1,
  533. No,
  534. Yes
  535. } m_exitOnFrameDelete;
  536. // true if the app wants to use the best visual on systems where
  537. // more than one are available (Sun, SGI, XFree86 4.0 ?)
  538. bool m_useBestVisual;
  539. // force TrueColour just in case "best" isn't TrueColour
  540. bool m_forceTrueColour;
  541. // does any of our windows have focus?
  542. bool m_isActive;
  543. wxDECLARE_NO_COPY_CLASS(wxAppBase);
  544. };
  545. #if WXWIN_COMPATIBILITY_2_6
  546. inline bool wxAppBase::Initialized() { return true; }
  547. #endif // WXWIN_COMPATIBILITY_2_6
  548. // ----------------------------------------------------------------------------
  549. // now include the declaration of the real class
  550. // ----------------------------------------------------------------------------
  551. #if defined(__WXMSW__)
  552. #include "wx/msw/app.h"
  553. #elif defined(__WXMOTIF__)
  554. #include "wx/motif/app.h"
  555. #elif defined(__WXDFB__)
  556. #include "wx/dfb/app.h"
  557. #elif defined(__WXGTK20__)
  558. #include "wx/gtk/app.h"
  559. #elif defined(__WXGTK__)
  560. #include "wx/gtk1/app.h"
  561. #elif defined(__WXX11__)
  562. #include "wx/x11/app.h"
  563. #elif defined(__WXMAC__)
  564. #include "wx/osx/app.h"
  565. #elif defined(__WXCOCOA__)
  566. #include "wx/cocoa/app.h"
  567. #elif defined(__WXPM__)
  568. #include "wx/os2/app.h"
  569. #endif
  570. #else // !GUI
  571. // wxApp is defined in core and we cannot define another one in wxBase,
  572. // so use the preprocessor to allow using wxApp in console programs too
  573. #define wxApp wxAppConsole
  574. #endif // GUI/!GUI
  575. // ----------------------------------------------------------------------------
  576. // the global data
  577. // ----------------------------------------------------------------------------
  578. // for compatibility, we define this macro to access the global application
  579. // object of type wxApp
  580. //
  581. // note that instead of using of wxTheApp in application code you should
  582. // consider using wxDECLARE_APP() after which you may call wxGetApp() which will
  583. // return the object of the correct type (i.e. MyApp and not wxApp)
  584. //
  585. // the cast is safe as in GUI build we only use wxApp, not wxAppConsole, and in
  586. // console mode it does nothing at all
  587. #define wxTheApp static_cast<wxApp*>(wxApp::GetInstance())
  588. // ----------------------------------------------------------------------------
  589. // global functions
  590. // ----------------------------------------------------------------------------
  591. // event loop related functions only work in GUI programs
  592. // ------------------------------------------------------
  593. // Force an exit from main loop
  594. WXDLLIMPEXP_BASE void wxExit();
  595. // avoid redeclaring this function here if it had been already declared by
  596. // wx/utils.h, this results in warnings from g++ with -Wredundant-decls
  597. #ifndef wx_YIELD_DECLARED
  598. #define wx_YIELD_DECLARED
  599. // Yield to other apps/messages
  600. WXDLLIMPEXP_CORE bool wxYield();
  601. #endif // wx_YIELD_DECLARED
  602. // Yield to other apps/messages
  603. WXDLLIMPEXP_BASE void wxWakeUpIdle();
  604. // ----------------------------------------------------------------------------
  605. // macros for dynamic creation of the application object
  606. // ----------------------------------------------------------------------------
  607. // Having a global instance of this class allows wxApp to be aware of the app
  608. // creator function. wxApp can then call this function to create a new app
  609. // object. Convoluted, but necessary.
  610. class WXDLLIMPEXP_BASE wxAppInitializer
  611. {
  612. public:
  613. wxAppInitializer(wxAppInitializerFunction fn)
  614. { wxApp::SetInitializerFunction(fn); }
  615. };
  616. // the code below defines a wxIMPLEMENT_WXWIN_MAIN macro which you can use if
  617. // your compiler really, really wants main() to be in your main program (e.g.
  618. // hello.cpp). Now wxIMPLEMENT_APP should add this code if required.
  619. // For compilers that support it, prefer to use wmain() as this ensures any
  620. // Unicode strings can be passed as command line parameters and not just those
  621. // representable in the current locale.
  622. #if wxUSE_UNICODE && defined(__VISUALC__)
  623. #define wxIMPLEMENT_WXWIN_MAIN_CONSOLE \
  624. int wmain(int argc, wchar_t **argv) \
  625. { \
  626. wxDISABLE_DEBUG_SUPPORT(); \
  627. \
  628. return wxEntry(argc, argv); \
  629. }
  630. #else // Use standard main()
  631. #define wxIMPLEMENT_WXWIN_MAIN_CONSOLE \
  632. int main(int argc, char **argv) \
  633. { \
  634. wxDISABLE_DEBUG_SUPPORT(); \
  635. \
  636. return wxEntry(argc, argv); \
  637. }
  638. #endif
  639. // port-specific header could have defined it already in some special way
  640. #ifndef wxIMPLEMENT_WXWIN_MAIN
  641. #define wxIMPLEMENT_WXWIN_MAIN wxIMPLEMENT_WXWIN_MAIN_CONSOLE
  642. #endif // defined(wxIMPLEMENT_WXWIN_MAIN)
  643. #ifdef __WXUNIVERSAL__
  644. #include "wx/univ/theme.h"
  645. #ifdef wxUNIV_DEFAULT_THEME
  646. #define wxIMPLEMENT_WX_THEME_SUPPORT \
  647. WX_USE_THEME(wxUNIV_DEFAULT_THEME);
  648. #else
  649. #define wxIMPLEMENT_WX_THEME_SUPPORT
  650. #endif
  651. #else
  652. #define wxIMPLEMENT_WX_THEME_SUPPORT
  653. #endif
  654. // Use this macro if you want to define your own main() or WinMain() function
  655. // and call wxEntry() from there.
  656. #define wxIMPLEMENT_APP_NO_MAIN(appname) \
  657. appname& wxGetApp() { return *static_cast<appname*>(wxApp::GetInstance()); } \
  658. wxAppConsole *wxCreateApp() \
  659. { \
  660. wxAppConsole::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, \
  661. "your program"); \
  662. return new appname; \
  663. } \
  664. wxAppInitializer \
  665. wxTheAppInitializer((wxAppInitializerFunction) wxCreateApp)
  666. // Same as wxIMPLEMENT_APP() normally but doesn't include themes support in
  667. // wxUniversal builds
  668. #define wxIMPLEMENT_APP_NO_THEMES(appname) \
  669. wxIMPLEMENT_WXWIN_MAIN \
  670. wxIMPLEMENT_APP_NO_MAIN(appname)
  671. // Use this macro exactly once, the argument is the name of the wxApp-derived
  672. // class which is the class of your application.
  673. #define wxIMPLEMENT_APP(appname) \
  674. wxIMPLEMENT_WX_THEME_SUPPORT \
  675. wxIMPLEMENT_APP_NO_THEMES(appname)
  676. // Same as IMPLEMENT_APP(), but for console applications.
  677. #define wxIMPLEMENT_APP_CONSOLE(appname) \
  678. wxIMPLEMENT_WXWIN_MAIN_CONSOLE \
  679. wxIMPLEMENT_APP_NO_MAIN(appname)
  680. // this macro can be used multiple times and just allows you to use wxGetApp()
  681. // function
  682. #define wxDECLARE_APP(appname) \
  683. extern appname& wxGetApp()
  684. // declare the stuff defined by wxIMPLEMENT_APP() macro, it's not really needed
  685. // anywhere else but at the very least it suppresses icc warnings about
  686. // defining extern symbols without prior declaration, and it shouldn't do any
  687. // harm
  688. extern wxAppConsole *wxCreateApp();
  689. extern wxAppInitializer wxTheAppInitializer;
  690. // ----------------------------------------------------------------------------
  691. // Compatibility macro aliases
  692. // ----------------------------------------------------------------------------
  693. // deprecated variants _not_ requiring a semicolon after them
  694. // (note that also some wx-prefixed macro do _not_ require a semicolon because
  695. // it's not always possible to force the compire to require it)
  696. #define IMPLEMENT_WXWIN_MAIN_CONSOLE wxIMPLEMENT_WXWIN_MAIN_CONSOLE
  697. #define IMPLEMENT_WXWIN_MAIN wxIMPLEMENT_WXWIN_MAIN
  698. #define IMPLEMENT_WX_THEME_SUPPORT wxIMPLEMENT_WX_THEME_SUPPORT
  699. #define IMPLEMENT_APP_NO_MAIN(app) wxIMPLEMENT_APP_NO_MAIN(app);
  700. #define IMPLEMENT_APP_NO_THEMES(app) wxIMPLEMENT_APP_NO_THEMES(app);
  701. #define IMPLEMENT_APP(app) wxIMPLEMENT_APP(app);
  702. #define IMPLEMENT_APP_CONSOLE(app) wxIMPLEMENT_APP_CONSOLE(app);
  703. #define DECLARE_APP(app) wxDECLARE_APP(app);
  704. #endif // _WX_APP_H_BASE_