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