app.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: app.h
  3. // Purpose: interface of wxApp
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxAppConsole
  9. This class is essential for writing console-only or hybrid apps without
  10. having to define @c wxUSE_GUI=0.
  11. It is used to:
  12. @li set and get application-wide properties (see wxAppConsole::CreateTraits
  13. and wxAppConsole::SetXXX functions)
  14. @li implement the windowing system message or event loop: events in fact are
  15. supported even in console-mode applications (see wxAppConsole::HandleEvent
  16. and wxAppConsole::ProcessPendingEvents);
  17. @li initiate application processing via wxApp::OnInit;
  18. @li allow default processing of events not handled by other
  19. objects in the application (see wxAppConsole::FilterEvent)
  20. @li implement Apple-specific event handlers (see wxAppConsole::MacXXX functions)
  21. You should use the macro wxIMPLEMENT_APP(appClass) in your application
  22. implementation file to tell wxWidgets how to create an instance of your
  23. application class.
  24. Use wxDECLARE_APP(appClass) in a header file if you want the ::wxGetApp() function
  25. (which returns a reference to your application object) to be visible to other
  26. files.
  27. @library{wxbase}
  28. @category{appmanagement}
  29. @see @ref overview_app, wxApp, wxAppTraits, wxEventLoopBase
  30. */
  31. class wxAppConsole : public wxEvtHandler,
  32. public wxEventFilter
  33. {
  34. protected:
  35. /**
  36. Creates the wxAppTraits object when GetTraits() needs it for the first time.
  37. @see wxAppTraits
  38. */
  39. virtual wxAppTraits* CreateTraits();
  40. public:
  41. /**
  42. Destructor.
  43. */
  44. virtual ~wxAppConsole();
  45. /**
  46. @name Event-handling
  47. Note that you should look at wxEvtLoopBase for more event-processing
  48. documentation.
  49. */
  50. //@{
  51. /**
  52. Called by wxWidgets on creation of the application. Override this if you wish
  53. to provide your own (environment-dependent) main loop.
  54. @return 0 under X, and the wParam of the WM_QUIT message under Windows.
  55. */
  56. virtual int MainLoop();
  57. /**
  58. Call this to explicitly exit the main message (event) loop.
  59. You should normally exit the main loop (and the application) by deleting
  60. the top window.
  61. This function simply calls wxEvtLoopBase::Exit() on the active loop.
  62. */
  63. virtual void ExitMainLoop();
  64. /**
  65. Overridden wxEventFilter method.
  66. This function is called before processing any event and allows the application
  67. to preempt the processing of some events, see wxEventFilter
  68. documentation for more information.
  69. wxApp implementation of this method always return -1 indicating that
  70. the event should be processed normally.
  71. */
  72. virtual int FilterEvent(wxEvent& event);
  73. /**
  74. Returns the main event loop instance, i.e.\ the event loop which is started
  75. by OnRun() and which dispatches all events sent from the native toolkit
  76. to the application (except when new event loops are temporarily set-up).
  77. The returned value maybe @NULL. Put initialization code which needs a
  78. non-@NULL main event loop into OnEventLoopEnter().
  79. */
  80. wxEventLoopBase* GetMainLoop() const;
  81. /**
  82. This function simply invokes the given method @a func of the specified
  83. event handler @a handler with the @a event as parameter. It exists solely
  84. to allow to catch the C++ exceptions which could be thrown by all event
  85. handlers in the application in one place: if you want to do this, override
  86. this function in your wxApp-derived class and add try/catch clause(s) to it.
  87. */
  88. virtual void HandleEvent(wxEvtHandler* handler,
  89. wxEventFunction func,
  90. wxEvent& event) const;
  91. /**
  92. Returns @true if the application is using an event loop.
  93. This function always returns @true for the GUI applications which
  94. must use an event loop but by default only returns @true for the
  95. console programs if an event loop is already running as it can't know
  96. whether one will be created in the future.
  97. Thus, it only makes sense to override it in console applications which
  98. do use an event loop, to return @true instead of checking if there is a
  99. currently active event loop.
  100. */
  101. virtual bool UsesEventLoop() const;
  102. //@}
  103. /**
  104. @name Pending events
  105. Pending events are handled by wxAppConsole rather than wxEventLoopBase
  106. to allow queuing of events even when there's no event loop
  107. (e.g. in wxAppConsole::OnInit).
  108. */
  109. //@{
  110. /**
  111. Process all pending events; it is necessary to call this function to
  112. process events posted with wxEvtHandler::QueueEvent or wxEvtHandler::AddPendingEvent.
  113. This happens during each event loop iteration (see wxEventLoopBase) in GUI mode but
  114. it may be also called directly.
  115. Note that this function does not only process the pending events for the wxApp object
  116. itself (which derives from wxEvtHandler) but also the pending events for @e any
  117. event handler of this application.
  118. This function will immediately return and do nothing if SuspendProcessingOfPendingEvents()
  119. was called.
  120. */
  121. virtual void ProcessPendingEvents();
  122. /**
  123. Deletes the pending events of all wxEvtHandlers of this application.
  124. See wxEvtHandler::DeletePendingEvents() for warnings about deleting the pending
  125. events.
  126. */
  127. void DeletePendingEvents();
  128. /**
  129. Returns @true if there are pending events on the internal pending event list.
  130. Whenever wxEvtHandler::QueueEvent or wxEvtHandler::AddPendingEvent() are
  131. called (not only for wxApp itself, but for any event handler of the application!),
  132. the internal wxApp's list of handlers with pending events is updated and this
  133. function will return true.
  134. */
  135. bool HasPendingEvents() const;
  136. /**
  137. Temporary suspends processing of the pending events.
  138. @see ResumeProcessingOfPendingEvents()
  139. */
  140. void SuspendProcessingOfPendingEvents();
  141. /**
  142. Resume processing of the pending events previously stopped because of a
  143. call to SuspendProcessingOfPendingEvents().
  144. */
  145. void ResumeProcessingOfPendingEvents();
  146. //@}
  147. /**
  148. Delayed objects destruction.
  149. In applications using events it may be unsafe for an event handler to
  150. delete the object which generated the event because more events may be
  151. still pending for the same object. In this case the handler may call
  152. ScheduleForDestruction() instead.
  153. */
  154. //@{
  155. /**
  156. Schedule the object for destruction in the near future.
  157. Notice that if the application is not using an event loop, i.e. if
  158. UsesEventLoop() returns @false, this method will simply delete the
  159. object immediately.
  160. Examples of using this function inside wxWidgets itself include
  161. deleting the top level windows when they are closed and sockets when
  162. they are disconnected.
  163. */
  164. void ScheduleForDestruction(wxObject *object);
  165. /**
  166. Check if the object had been scheduled for destruction with
  167. ScheduleForDestruction().
  168. This function may be useful as an optimization to avoid doing something
  169. with an object which will be soon destroyed in any case.
  170. */
  171. bool IsScheduledForDestruction(wxObject *object) const;
  172. //@}
  173. bool Yield(bool onlyIfNeeded = false);
  174. /**
  175. Allows external code to modify global ::wxTheApp, but you should really
  176. know what you're doing if you call it.
  177. @param app
  178. Replacement for the global application object.
  179. @see GetInstance()
  180. */
  181. static void SetInstance(wxAppConsole* app);
  182. /**
  183. Returns the one and only global application object.
  184. Usually ::wxTheApp is used instead.
  185. @see SetInstance()
  186. */
  187. static wxAppConsole* GetInstance();
  188. /**
  189. Returns @true if the main event loop is currently running, i.e.\ if the
  190. application is inside OnRun().
  191. This can be useful to test whether events can be dispatched. For example,
  192. if this function returns @false, non-blocking sockets cannot be used because
  193. the events from them would never be processed.
  194. */
  195. static bool IsMainLoopRunning();
  196. /**
  197. @name Callbacks for application-wide "events"
  198. */
  199. //@{
  200. /**
  201. This function is called when an assert failure occurs, i.e.\ the condition
  202. specified in wxASSERT() macro evaluated to @false.
  203. It is only called in debug mode (when @c __WXDEBUG__ is defined) as
  204. asserts are not left in the release code at all.
  205. The base class version shows the default assert failure dialog box proposing to
  206. the user to stop the program, continue or ignore all subsequent asserts.
  207. @param file
  208. the name of the source file where the assert occurred
  209. @param line
  210. the line number in this file where the assert occurred
  211. @param func
  212. the name of the function where the assert occurred, may be
  213. empty if the compiler doesn't support C99 __FUNCTION__
  214. @param cond
  215. the condition of the failed assert in text form
  216. @param msg
  217. the message specified as argument to wxASSERT_MSG or wxFAIL_MSG, will
  218. be @NULL if just wxASSERT or wxFAIL was used
  219. */
  220. virtual void OnAssertFailure(const wxChar *file,
  221. int line,
  222. const wxChar *func,
  223. const wxChar *cond,
  224. const wxChar *msg);
  225. /**
  226. Called when command line parsing fails (i.e.\ an incorrect command line option
  227. was specified by the user). The default behaviour is to show the program usage
  228. text and abort the program.
  229. Return @true to continue normal execution or @false to return
  230. @false from OnInit() thus terminating the program.
  231. @see OnInitCmdLine()
  232. */
  233. virtual bool OnCmdLineError(wxCmdLineParser& parser);
  234. /**
  235. Called when the help option (@c --help) was specified on the command line.
  236. The default behaviour is to show the program usage text and abort the program.
  237. Return @true to continue normal execution or @false to return
  238. @false from OnInit() thus terminating the program.
  239. @see OnInitCmdLine()
  240. */
  241. virtual bool OnCmdLineHelp(wxCmdLineParser& parser);
  242. /**
  243. Called after the command line had been successfully parsed. You may override
  244. this method to test for the values of the various parameters which could be
  245. set from the command line.
  246. Don't forget to call the base class version unless you want to suppress
  247. processing of the standard command line options.
  248. Return @true to continue normal execution or @false to return @false from
  249. OnInit() thus terminating the program.
  250. @see OnInitCmdLine()
  251. */
  252. virtual bool OnCmdLineParsed(wxCmdLineParser& parser);
  253. /**
  254. Called by wxEventLoopBase::SetActive(): you can override this function
  255. and put here the code which needs an active event loop.
  256. Note that this function is called whenever an event loop is activated;
  257. you may want to use wxEventLoopBase::IsMain() to perform initialization
  258. specific for the app's main event loop.
  259. @see OnEventLoopExit()
  260. */
  261. virtual void OnEventLoopEnter(wxEventLoopBase* loop);
  262. /**
  263. Called by wxEventLoopBase::OnExit() for each event loop which
  264. is exited.
  265. @see OnEventLoopEnter()
  266. */
  267. virtual void OnEventLoopExit(wxEventLoopBase* loop);
  268. /**
  269. This function is called if an unhandled exception occurs inside the main
  270. application event loop. It can return @true to ignore the exception and to
  271. continue running the loop or @false to exit the loop and terminate the
  272. program. In the latter case it can also use C++ @c throw keyword to
  273. rethrow the current exception.
  274. The default behaviour of this function is the latter in all ports except under
  275. Windows where a dialog is shown to the user which allows him to choose between
  276. the different options. You may override this function in your class to do
  277. something more appropriate.
  278. Finally note that if the exception is rethrown from here, it can be caught in
  279. OnUnhandledException().
  280. */
  281. virtual bool OnExceptionInMainLoop();
  282. /**
  283. Override this member function for any processing which needs to be
  284. done as the application is about to exit. OnExit is called after
  285. destroying all application windows and controls, but before
  286. wxWidgets cleanup. Note that it is not called at all if
  287. OnInit() failed.
  288. The return value of this function is currently ignored, return the same
  289. value as returned by the base class method if you override it.
  290. */
  291. virtual int OnExit();
  292. /**
  293. This function may be called if something fatal happens: an unhandled
  294. exception under Win32 or a fatal signal under Unix, for example. However,
  295. this will not happen by default: you have to explicitly call
  296. wxHandleFatalExceptions() to enable this.
  297. Generally speaking, this function should only show a message to the user and
  298. return. You may attempt to save unsaved data but this is not guaranteed to
  299. work and, in fact, probably won't.
  300. @see wxHandleFatalExceptions()
  301. */
  302. virtual void OnFatalException();
  303. /**
  304. This must be provided by the application, and will usually create the
  305. application's main window, optionally calling SetTopWindow().
  306. You may use OnExit() to clean up anything initialized here, provided
  307. that the function returns @true.
  308. Notice that if you want to use the command line processing provided by
  309. wxWidgets you have to call the base class version in the derived class
  310. OnInit().
  311. Return @true to continue processing, @false to exit the application
  312. immediately.
  313. */
  314. virtual bool OnInit();
  315. /**
  316. Called from OnInit() and may be used to initialize the parser with the
  317. command line options for this application. The base class versions adds
  318. support for a few standard options only.
  319. */
  320. virtual void OnInitCmdLine(wxCmdLineParser& parser);
  321. /**
  322. This virtual function is where the execution of a program written in wxWidgets
  323. starts. The default implementation just enters the main loop and starts
  324. handling the events until it terminates, either because ExitMainLoop() has
  325. been explicitly called or because the last frame has been deleted and
  326. GetExitOnFrameDelete() flag is @true (this is the default).
  327. The return value of this function becomes the exit code of the program, so it
  328. should return 0 in case of successful termination.
  329. */
  330. virtual int OnRun();
  331. /**
  332. This function is called when an unhandled C++ exception occurs in user
  333. code called by wxWidgets.
  334. Any unhandled exceptions thrown from (overridden versions of) OnInit()
  335. and OnExit() methods as well as any exceptions thrown from inside the
  336. main loop and re-thrown by OnUnhandledException() will result in a call
  337. to this function.
  338. By the time this function is called, the program is already about to
  339. exit and the exception can't be handled nor ignored any more, override
  340. OnUnhandledException() or use explicit @c try/catch blocks around
  341. OnInit() body to be able to handle the exception earlier.
  342. The default implementation dumps information about the exception using
  343. wxMessageOutputBest.
  344. */
  345. virtual void OnUnhandledException();
  346. //@}
  347. /**
  348. @name Application information
  349. */
  350. //@{
  351. /**
  352. Returns the user-readable application name.
  353. The difference between this string and the one returned by GetAppName()
  354. is that this one is meant to be shown to the user and so should be used
  355. for the window titles, page headers and so on while the other one
  356. should be only used internally, e.g. for the file names or
  357. configuration file keys.
  358. If the application name for display had been previously set by
  359. SetAppDisplayName(), it will be returned by this function. Otherwise,
  360. if SetAppName() had been called its value will be returned; also as is.
  361. Finally if none was called, this function returns the program name
  362. capitalized using wxString::Capitalize().
  363. @since 2.9.0
  364. */
  365. wxString GetAppDisplayName() const;
  366. /**
  367. Returns the application name.
  368. If SetAppName() had been called, returns the string passed to it.
  369. Otherwise returns the program name, i.e. the value of @c argv[0] passed
  370. to the @c main() function.
  371. @see GetAppDisplayName()
  372. */
  373. wxString GetAppName() const;
  374. /**
  375. Gets the class name of the application. The class name may be used in a
  376. platform specific manner to refer to the application.
  377. @see SetClassName()
  378. */
  379. wxString GetClassName() const;
  380. /**
  381. Returns a pointer to the wxAppTraits object for the application.
  382. If you want to customize the wxAppTraits object, you must override the
  383. CreateTraits() function.
  384. */
  385. wxAppTraits* GetTraits();
  386. /**
  387. Returns the user-readable vendor name. The difference between this string
  388. and the one returned by GetVendorName() is that this one is meant to be shown
  389. to the user and so should be used for the window titles, page headers and so on
  390. while the other one should be only used internally, e.g. for the file names or
  391. configuration file keys.
  392. By default, returns the same string as GetVendorName().
  393. @since 2.9.0
  394. */
  395. const wxString& GetVendorDisplayName() const;
  396. /**
  397. Returns the application's vendor name.
  398. */
  399. const wxString& GetVendorName() const;
  400. /**
  401. Set the application name to be used in the user-visible places such as
  402. window titles.
  403. See GetAppDisplayName() for more about the differences between the
  404. display name and name.
  405. Notice that if this function is called, the name is used as is, without
  406. any capitalization as done by default by GetAppDisplayName().
  407. */
  408. void SetAppDisplayName(const wxString& name);
  409. /**
  410. Sets the name of the application. This name should be used for file names,
  411. configuration file entries and other internal strings. For the user-visible
  412. strings, such as the window titles, the application display name set by
  413. SetAppDisplayName() is used instead.
  414. By default the application name is set to the name of its executable file.
  415. @see GetAppName()
  416. */
  417. void SetAppName(const wxString& name);
  418. /**
  419. Sets the class name of the application. This may be used in a platform specific
  420. manner to refer to the application.
  421. @see GetClassName()
  422. */
  423. void SetClassName(const wxString& name);
  424. /**
  425. Set the vendor name to be used in the user-visible places.
  426. See GetVendorDisplayName() for more about the differences between the
  427. display name and name.
  428. */
  429. void SetVendorDisplayName(const wxString& name);
  430. /**
  431. Sets the name of application's vendor. The name will be used
  432. in registry access. A default name is set by wxWidgets.
  433. @see GetVendorName()
  434. */
  435. void SetVendorName(const wxString& name);
  436. //@}
  437. /**
  438. Sets the C locale to the default locale for the current environment.
  439. It is advised to call this to ensure that the underlying toolkit uses
  440. the locale in which the numbers and monetary amounts are shown in the
  441. format expected by user and so on.
  442. Calling this function is roughly equivalent to calling
  443. @code
  444. setlocale(LC_ALL, "");
  445. @endcode
  446. but performs additional toolkit-specific tasks under some platforms and
  447. so should be used instead of @c setlocale() itself. Alternatively, you
  448. can use wxLocale to change the locale with more control.
  449. Notice that this does @em not change the global C++ locale, you need to
  450. do it explicitly if you want, e.g.
  451. @code
  452. std::locale::global(std::locale(""));
  453. @endcode
  454. but be warned that locale support in C++ standard library can be poor
  455. or worse under some platforms, e.g. the above line results in an
  456. immediate crash under OS X up to the version 10.8.2.
  457. @since 2.9.5
  458. */
  459. void SetCLocale();
  460. /**
  461. Number of command line arguments (after environment-specific processing).
  462. */
  463. int argc;
  464. /**
  465. Command line arguments (after environment-specific processing).
  466. Under Windows and Linux/Unix, you should parse the command line
  467. arguments and check for files to be opened when starting your
  468. application. Under OS X, you need to override MacOpenFiles()
  469. since command line arguments are used differently there.
  470. You may use the wxCmdLineParser to parse command line arguments.
  471. */
  472. wxChar** argv;
  473. };
  474. /**
  475. @class wxApp
  476. The wxApp class represents the application itself when @c wxUSE_GUI=1.
  477. In addition to the features provided by wxAppConsole it keeps track of
  478. the <em>top window</em> (see SetTopWindow()) and adds support for
  479. video modes (see SetVideoMode()).
  480. In general, application-wide settings for GUI-only apps are accessible
  481. from wxApp (or from wxSystemSettings or wxSystemOptions classes).
  482. @beginEventEmissionTable
  483. @event{EVT_QUERY_END_SESSION(func)}
  484. Process a query end session event, supplying the member function.
  485. See wxCloseEvent.
  486. @event{EVT_END_SESSION(func)}
  487. Process an end session event, supplying the member function.
  488. See wxCloseEvent.
  489. @event{EVT_ACTIVATE_APP(func)}
  490. Process a @c wxEVT_ACTIVATE_APP event. See wxActivateEvent.
  491. @event{EVT_HIBERNATE(func)}
  492. Process a hibernate event. See wxActivateEvent.
  493. @event{EVT_DIALUP_CONNECTED(func)}
  494. A connection with the network was established. See wxDialUpEvent.
  495. @event{EVT_DIALUP_DISCONNECTED(func)}
  496. The connection with the network was lost. See wxDialUpEvent.
  497. @event{EVT_IDLE(func)}
  498. Process a @c wxEVT_IDLE event. See wxIdleEvent.
  499. @endEventTable
  500. @library{wxbase}
  501. @category{appmanagement}
  502. @see @ref overview_app, wxAppTraits, wxEventLoopBase, wxSystemSettings
  503. */
  504. class wxApp : public wxAppConsole
  505. {
  506. public:
  507. /**
  508. Constructor. Called implicitly with a definition of a wxApp object.
  509. */
  510. wxApp();
  511. /**
  512. Destructor. Will be called implicitly on program exit if the wxApp
  513. object is created on the stack.
  514. */
  515. virtual ~wxApp();
  516. /**
  517. Get display mode that is used use. This is only used in framebuffer
  518. wxWidgets ports such as wxDFB.
  519. */
  520. virtual wxVideoMode GetDisplayMode() const;
  521. /**
  522. Returns @true if the application will exit when the top-level frame is deleted.
  523. @see SetExitOnFrameDelete()
  524. */
  525. bool GetExitOnFrameDelete() const;
  526. /**
  527. Return the layout direction for the current locale or @c wxLayout_Default
  528. if it's unknown.
  529. */
  530. virtual wxLayoutDirection GetLayoutDirection() const;
  531. /**
  532. Returns @true if the application will use the best visual on systems that support
  533. different visuals, @false otherwise.
  534. @see SetUseBestVisual()
  535. */
  536. bool GetUseBestVisual() const;
  537. /**
  538. Returns a pointer to the top window.
  539. @remarks
  540. If the top window hasn't been set using SetTopWindow(), this function
  541. will find the first top-level window (frame or dialog or instance of
  542. wxTopLevelWindow) from the internal top level window list and return that.
  543. @see SetTopWindow()
  544. */
  545. virtual wxWindow* GetTopWindow() const;
  546. /**
  547. Returns @true if the application is active, i.e.\ if one of its windows is
  548. currently in the foreground.
  549. If this function returns @false and you need to attract users attention to
  550. the application, you may use wxTopLevelWindow::RequestUserAttention to do it.
  551. */
  552. virtual bool IsActive() const;
  553. /**
  554. This function is similar to wxYield(), except that it disables the user
  555. input to all program windows before calling wxAppConsole::Yield and re-enables it
  556. again afterwards. If @a win is not @NULL, this window will remain enabled,
  557. allowing the implementation of some limited user interaction.
  558. Returns the result of the call to wxAppConsole::Yield.
  559. @see wxSafeYield
  560. */
  561. virtual bool SafeYield(wxWindow *win, bool onlyIfNeeded);
  562. /**
  563. Works like SafeYield() with @e onlyIfNeeded == @true except that
  564. it allows the caller to specify a mask of events to be processed.
  565. See wxAppConsole::YieldFor for more info.
  566. */
  567. virtual bool SafeYieldFor(wxWindow *win, long eventsToProcess);
  568. /**
  569. Windows-only function for processing a message. This function is called
  570. from the main message loop, checking for windows that may wish to process it.
  571. The function returns @true if the message was processed, @false otherwise.
  572. If you use wxWidgets with another class library with its own message loop,
  573. you should make sure that this function is called to allow wxWidgets to
  574. receive messages. For example, to allow co-existence with the Microsoft
  575. Foundation Classes, override the PreTranslateMessage function:
  576. @code
  577. // Provide wxWidgets message loop compatibility
  578. BOOL CTheApp::PreTranslateMessage(MSG *msg)
  579. {
  580. if (wxTheApp && wxTheApp->ProcessMessage((WXMSW *)msg))
  581. return true;
  582. else
  583. return CWinApp::PreTranslateMessage(msg);
  584. }
  585. @endcode
  586. @onlyfor{wxmsw}
  587. */
  588. bool ProcessMessage(WXMSG* msg);
  589. /**
  590. Set display mode to use. This is only used in framebuffer wxWidgets
  591. ports such as wxDFB.
  592. */
  593. virtual bool SetDisplayMode(const wxVideoMode& info);
  594. /**
  595. Allows the programmer to specify whether the application will exit when the
  596. top-level frame is deleted.
  597. @param flag
  598. If @true (the default), the application will exit when the top-level frame
  599. is deleted. If @false, the application will continue to run.
  600. @see GetExitOnFrameDelete(), @ref overview_app_shutdown
  601. */
  602. void SetExitOnFrameDelete(bool flag);
  603. /**
  604. Allows runtime switching of the UI environment theme.
  605. Currently implemented for wxGTK2-only.
  606. Return @true if theme was successfully changed.
  607. @param theme
  608. The name of the new theme or an absolute path to a gtkrc-theme-file
  609. */
  610. virtual bool SetNativeTheme(const wxString& theme);
  611. /**
  612. Sets the 'top' window. You can call this from within OnInit() to let wxWidgets
  613. know which is the main window. You don't have to set the top window;
  614. it is only a convenience so that (for example) certain dialogs without parents
  615. can use a specific window as the top window.
  616. If no top window is specified by the application, wxWidgets just uses the
  617. first frame or dialog (or better, any wxTopLevelWindow) in its top-level
  618. window list, when it needs to use the top window.
  619. If you previously called SetTopWindow() and now you need to restore this
  620. automatic behaviour you can call @code wxApp::SetTopWindow(NULL) @endcode.
  621. @param window
  622. The new top window.
  623. @see GetTopWindow(), OnInit()
  624. */
  625. void SetTopWindow(wxWindow* window);
  626. /**
  627. Allows the programmer to specify whether the application will use the best
  628. visual on systems that support several visual on the same display. This is typically
  629. the case under Solaris and IRIX, where the default visual is only 8-bit whereas
  630. certain applications are supposed to run in TrueColour mode.
  631. Note that this function has to be called in the constructor of the wxApp
  632. instance and won't have any effect when called later on.
  633. This function currently only has effect under GTK.
  634. @param flag
  635. If @true, the app will use the best visual.
  636. @param forceTrueColour
  637. If @true then the application will try to force using a TrueColour
  638. visual and abort the app if none is found.
  639. */
  640. void SetUseBestVisual(bool flag, bool forceTrueColour = false);
  641. /**
  642. @name Mac-specific functions
  643. */
  644. //@{
  645. /**
  646. Called in response of an "open-application" Apple event.
  647. Override this to create a new document in your app.
  648. @onlyfor{wxosx}
  649. */
  650. virtual void MacNewFile();
  651. /**
  652. Called in response of an openFiles message with Cocoa, or an
  653. "open-document" Apple event with Carbon.
  654. You need to override this method in order to open one or more document
  655. files after the user double clicked on it or if the files and/or
  656. folders were dropped on either the application in the dock or the
  657. application icon in Finder.
  658. By default this method calls MacOpenFile for each file/folder.
  659. @onlyfor{wxosx}
  660. @since 2.9.3
  661. */
  662. virtual void MacOpenFiles(const wxArrayString& fileNames);
  663. /**
  664. Called in response of an "open-document" Apple event.
  665. @deprecated
  666. This function is kept mostly for backwards compatibility. Please
  667. override wxApp::MacOpenFiles method instead in any new code.
  668. @onlyfor{wxosx}
  669. */
  670. virtual void MacOpenFile(const wxString& fileName);
  671. /**
  672. Called in response of a "get-url" Apple event.
  673. @onlyfor{wxosx}
  674. */
  675. virtual void MacOpenURL(const wxString& url);
  676. /**
  677. Called in response of a "print-document" Apple event.
  678. @onlyfor{wxosx}
  679. */
  680. virtual void MacPrintFile(const wxString& fileName);
  681. /**
  682. Called in response of a "reopen-application" Apple event.
  683. @onlyfor{wxosx}
  684. */
  685. virtual void MacReopenApp();
  686. /**
  687. May be overridden to indicate that the application is not a foreground
  688. GUI application under OS X.
  689. This method is called during the application startup and returns @true
  690. by default. In this case, wxWidgets ensures that the application is ran
  691. as a foreground, GUI application so that the user can interact with it
  692. normally, even if it is not bundled. If this is undesired, i.e. if the
  693. application doesn't need to be brought to the foreground, this method
  694. can be overridden to return @false.
  695. Notice that overriding it doesn't make any difference for the bundled
  696. applications which are always foreground unless @c LSBackgroundOnly key
  697. is specified in the @c Info.plist file.
  698. @onlyfor{wxosx}
  699. @since 3.0.1
  700. */
  701. virtual bool OSXIsGUIApplication();
  702. //@}
  703. };
  704. // ============================================================================
  705. // Global functions/macros
  706. // ============================================================================
  707. /** @addtogroup group_funcmacro_rtti */
  708. //@{
  709. /**
  710. This is used in headers to create a forward declaration of the ::wxGetApp()
  711. function implemented by wxIMPLEMENT_APP().
  712. It creates the declaration <tt>className& wxGetApp()</tt>
  713. (requires a final semicolon).
  714. @header{wx/app.h}
  715. Example:
  716. @code
  717. wxDECLARE_APP(MyApp);
  718. @endcode
  719. */
  720. #define wxDECLARE_APP( className )
  721. /**
  722. This is used in the application class implementation file to make the
  723. application class known to wxWidgets for dynamic construction.
  724. Note that this macro requires a final semicolon.
  725. @header{wx/app.h}
  726. Example:
  727. @code
  728. wxIMPLEMENT_APP(MyApp);
  729. @endcode
  730. @see wxDECLARE_APP()
  731. */
  732. #define wxIMPLEMENT_APP( className )
  733. //@}
  734. /**
  735. The global pointer to the singleton wxApp object.
  736. @see wxApp::GetInstance()
  737. */
  738. wxApp *wxTheApp;
  739. /** @addtogroup group_funcmacro_appinitterm */
  740. //@{
  741. /**
  742. This function doesn't exist in wxWidgets but it is created by using the
  743. wxIMPLEMENT_APP() macro.
  744. Thus, before using it anywhere but in the same module where this macro is
  745. used, you must make it available using wxDECLARE_APP().
  746. The advantage of using this function compared to directly using the global
  747. ::wxTheApp pointer is that the latter is of type wxApp* and so wouldn't
  748. allow you to access the functions specific to your application class but
  749. not present in wxApp while wxGetApp() returns the object of the right type.
  750. @header{wx/app.h}
  751. */
  752. wxAppDerivedClass& wxGetApp();
  753. /**
  754. If @a doIt is @true, the fatal exceptions (also known as general protection
  755. faults under Windows or segmentation violations in the Unix world) will be
  756. caught and passed to wxApp::OnFatalException.
  757. By default, i.e. before this function is called, they will be handled in
  758. the normal way which usually just means that the application will be
  759. terminated. Calling wxHandleFatalExceptions() with @a doIt equal to @false
  760. will restore this default behaviour.
  761. Notice that this function is only available if @c wxUSE_ON_FATAL_EXCEPTION
  762. is 1 and under Windows platform this requires a compiler with support for
  763. SEH (structured exception handling) which currently means only Microsoft
  764. Visual C++ or a recent Borland C++ version.
  765. @header{wx/app.h}
  766. */
  767. bool wxHandleFatalExceptions(bool doIt = true);
  768. /**
  769. This function is used in wxBase only and only if you don't create
  770. wxApp object at all. In this case you must call it from your
  771. @c main() function before calling any other wxWidgets functions.
  772. If the function returns @false the initialization could not be performed,
  773. in this case the library cannot be used and wxUninitialize() shouldn't be
  774. called neither.
  775. This function may be called several times but wxUninitialize() must be
  776. called for each successful call to this function.
  777. @header{wx/app.h}
  778. */
  779. bool wxInitialize();
  780. /**
  781. This function is for use in console (wxBase) programs only. It must be called
  782. once for each previous successful call to wxInitialize().
  783. @header{wx/app.h}
  784. */
  785. void wxUninitialize();
  786. /**
  787. This function wakes up the (internal and platform dependent) idle system,
  788. i.e. it will force the system to send an idle event even if the system
  789. currently @e is idle and thus would not send any idle event until after
  790. some other event would get sent. This is also useful for sending events
  791. between two threads and is used by the corresponding functions
  792. wxPostEvent() and wxEvtHandler::AddPendingEvent().
  793. @header{wx/app.h}
  794. */
  795. void wxWakeUpIdle();
  796. /**
  797. Calls wxAppConsole::Yield.
  798. @deprecated
  799. This function is kept only for backwards compatibility. Please use
  800. the wxAppConsole::Yield method instead in any new code.
  801. @header{wx/app.h}
  802. */
  803. bool wxYield();
  804. /**
  805. Calls wxApp::SafeYield.
  806. @header{wx/app.h}
  807. */
  808. bool wxSafeYield(wxWindow* win = NULL, bool onlyIfNeeded = false);
  809. /**
  810. This function initializes wxWidgets in a platform-dependent way. Use this if you
  811. are not using the default wxWidgets entry code (e.g. main or WinMain).
  812. For example, you can initialize wxWidgets from an Microsoft Foundation Classes
  813. (MFC) application using this function.
  814. @note This overload of wxEntry is available under all platforms.
  815. @see wxEntryStart()
  816. @header{wx/app.h}
  817. */
  818. int wxEntry(int& argc, wxChar** argv);
  819. /**
  820. See wxEntry(int&,wxChar**) for more info about this function.
  821. Notice that under Windows CE platform, and only there, the type of @a pCmdLine
  822. is @c wchar_t *, otherwise it is @c char *, even in Unicode build.
  823. @remarks To clean up wxWidgets, call wxApp::OnExit followed by the static
  824. function wxApp::CleanUp. For example, if exiting from an MFC application
  825. that also uses wxWidgets:
  826. @code
  827. int CTheApp::ExitInstance()
  828. {
  829. // OnExit isn't called by CleanUp so must be called explicitly.
  830. wxTheApp->OnExit();
  831. wxApp::CleanUp();
  832. return CWinApp::ExitInstance();
  833. }
  834. @endcode
  835. @header{wx/app.h}
  836. */
  837. int wxEntry(HINSTANCE hInstance,
  838. HINSTANCE hPrevInstance = NULL,
  839. char* pCmdLine = NULL,
  840. int nCmdShow = SW_SHOWNORMAL);
  841. //@}
  842. /** @addtogroup group_funcmacro_procctrl */
  843. //@{
  844. /**
  845. Exits application after calling wxApp::OnExit.
  846. Should only be used in an emergency: normally the top-level frame
  847. should be deleted (after deleting all other frames) to terminate the
  848. application. See wxCloseEvent and wxApp.
  849. @header{wx/app.h}
  850. */
  851. void wxExit();
  852. //@}
  853. /** @addtogroup group_funcmacro_debug */
  854. //@{
  855. /**
  856. @def wxDISABLE_DEBUG_SUPPORT()
  857. Use this macro to disable all debugging code in release build when not
  858. using wxIMPLEMENT_APP().
  859. Currently this macro disables assert checking and debug and trace level
  860. logging messages in release build (i.e. when @c NDEBUG is defined). It is
  861. used by wxIMPLEMENT_APP() macro so you only need to use it explicitly if you
  862. don't use this macro but initialize wxWidgets directly (e.g. calls
  863. wxEntry() or wxEntryStart() itself).
  864. If you do not want to disable debugging code even in release build of your
  865. application, you can use wxSetDefaultAssertHandler() and
  866. wxLog::SetLogLevel() with @c wxLOG_Max parameter to enable assertions and
  867. debug logging respectively.
  868. @see wxDISABLE_ASSERTS_IN_RELEASE_BUILD(),
  869. wxDISABLE_DEBUG_LOGGING_IN_RELEASE_BUILD(),
  870. @ref overview_debugging
  871. @since 2.9.1
  872. @header{wx/app.h}
  873. */
  874. #define wxDISABLE_DEBUG_SUPPORT() \
  875. wxDISABLE_ASSERTS_IN_RELEASE_BUILD(); \
  876. wxDISABLE_DEBUG_LOGGING_IN_RELEASE_BUILD()
  877. //@}