]>
Commit | Line | Data |
---|---|---|
a660d684 KB |
1 | \section{\class{wxApp}}\label{wxapp} |
2 | ||
3 | The {\bf wxApp} class represents the application itself. It is used | |
4 | to: | |
5 | ||
6 | \begin{itemize}\itemsep=0pt | |
7 | \item set and get application-wide properties; | |
8 | \item implement the windowing system message or event loop; | |
9 | \item initiate application processing via \helpref{wxApp::OnInit}{wxapponinit}; | |
10 | \item allow default processing of events not handled by other | |
11 | objects in the application. | |
12 | \end{itemize} | |
13 | ||
14 | You should use the macro IMPLEMENT\_APP(appClass) in your application implementation | |
fc2171bd | 15 | file to tell wxWidgets how to create an instance of your application class. |
a660d684 KB |
16 | |
17 | Use DECLARE\_APP(appClass) in a header file if you want the wxGetApp function (which returns | |
18 | a reference to your application object) to be visible to other files. | |
19 | ||
20 | \wxheading{Derived from} | |
21 | ||
22 | \helpref{wxEvtHandler}{wxevthandler}\\ | |
23 | \helpref{wxObject}{wxobject} | |
24 | ||
954b8ae6 JS |
25 | \wxheading{Include files} |
26 | ||
27 | <wx/app.h> | |
28 | ||
a7af285d VZ |
29 | \wxheading{Library} |
30 | ||
31 | \helpref{wxBase}{librarieslist} | |
32 | ||
a660d684 KB |
33 | \wxheading{See also} |
34 | ||
35 | \helpref{wxApp overview}{wxappoverview} | |
36 | ||
37 | \latexignore{\rtfignore{\wxheading{Members}}} | |
38 | ||
bc37bb43 | 39 | |
f510b7b2 | 40 | \membersection{wxApp::wxApp}\label{wxappctor} |
a660d684 | 41 | |
0e10e38d | 42 | \func{}{wxApp}{\void} |
a660d684 KB |
43 | |
44 | Constructor. Called implicitly with a definition of a wxApp object. | |
45 | ||
4c39aa3a | 46 | |
f510b7b2 | 47 | \membersection{wxApp::\destruct{wxApp}}\label{wxappdtor} |
a660d684 | 48 | |
3f39c254 | 49 | \func{virtual}{\destruct{wxApp}}{\void} |
a660d684 KB |
50 | |
51 | Destructor. Will be called implicitly on program exit if the wxApp | |
52 | object is created on the stack. | |
53 | ||
4c39aa3a | 54 | |
a660d684 KB |
55 | \membersection{wxApp::argc}\label{wxappargc} |
56 | ||
57 | \member{int}{argc} | |
58 | ||
59 | Number of command line arguments (after environment-specific processing). | |
60 | ||
4c39aa3a | 61 | |
a660d684 KB |
62 | \membersection{wxApp::argv}\label{wxappargv} |
63 | ||
749a05ee | 64 | \member{wxChar **}{argv} |
a660d684 KB |
65 | |
66 | Command line arguments (after environment-specific processing). | |
67 | ||
4c39aa3a | 68 | |
a660d684 KB |
69 | \membersection{wxApp::CreateLogTarget}\label{wxappcreatelogtarget} |
70 | ||
71 | \func{virtual wxLog*}{CreateLogTarget}{\void} | |
72 | ||
73 | Creates a wxLog class for the application to use for logging errors. The default | |
74 | implementation returns a new wxLogGui class. | |
75 | ||
76 | \wxheading{See also} | |
77 | ||
78 | \helpref{wxLog}{wxlog} | |
79 | ||
4c39aa3a | 80 | |
afdf936c VZ |
81 | \membersection{wxApp::CreateTraits}\label{wxappcreatetraits} |
82 | ||
83 | \func{virtual wxAppTraits *}{CreateTraits}{\void} | |
84 | ||
85 | Creates the \helpref{wxAppTraits}{wxapptraits} object when \helpref{GetTraits}{wxappgettraits} | |
86 | needs it for the first time. | |
87 | ||
88 | \wxheading{See also} | |
89 | ||
90 | \helpref{wxAppTraits}{wxapptraits} | |
91 | ||
92 | ||
a660d684 KB |
93 | \membersection{wxApp::Dispatch}\label{wxappdispatch} |
94 | ||
c805f6c3 | 95 | \func{virtual void}{Dispatch}{\void} |
a660d684 KB |
96 | |
97 | Dispatches the next event in the windowing system event queue. | |
98 | ||
99 | This can be used for programming event loops, e.g. | |
100 | ||
101 | \begin{verbatim} | |
102 | while (app.Pending()) | |
103 | Dispatch(); | |
104 | \end{verbatim} | |
105 | ||
106 | \wxheading{See also} | |
107 | ||
108 | \helpref{wxApp::Pending}{wxapppending} | |
109 | ||
4c39aa3a | 110 | |
82ce8b17 WS |
111 | \membersection{wxApp::ExitMainLoop}\label{wxappexitmainloop} |
112 | ||
113 | \func{virtual void}{ExitMainLoop}{\void} | |
114 | ||
115 | Call this to explicitly exit the main message (event) loop. | |
116 | You should normally exit the main loop (and the application) by deleting | |
117 | the top window. | |
118 | ||
119 | ||
9154d8cf VZ |
120 | \membersection{wxApp::FilterEvent}\label{wxappfilterevent} |
121 | ||
122 | \func{int}{FilterEvent}{\param{wxEvent\& }{event}} | |
123 | ||
124 | This function is called before processing any event and allows the application | |
125 | to preempt the processing of some events. If this method returns $-1$ the event | |
cc81d32f | 126 | is processed normally, otherwise either {\tt true} or {\tt false} should be |
9154d8cf VZ |
127 | returned and the event processing stops immediately considering that the event |
128 | had been already processed (for the former return value) or that it is not | |
129 | going to be processed at all (for the latter one). | |
130 | ||
4c39aa3a | 131 | |
d2175f3e VZ |
132 | \membersection{wxApp::GetAppDisplayName}\label{wxappgetappdisplayname} |
133 | ||
134 | \constfunc{wxString}{GetAppDisplayName}{\void} | |
135 | ||
136 | Returns the user-readable application name. The difference between this string | |
137 | and the one returned by \helpref{GetAppName}{wxappgetappname} is that this one | |
138 | is meant to be shown to the user and so should be used for the window titles, | |
139 | page headers and so on while the other one should be only used internally, e.g. | |
140 | for the file names or configuration file keys. | |
141 | ||
f07024ee | 142 | By default, returns the same string as \helpref{GetAppName}{wxappgetappname}. |
d2175f3e VZ |
143 | |
144 | \newsince{3.0} | |
145 | ||
146 | ||
a660d684 KB |
147 | \membersection{wxApp::GetAppName}\label{wxappgetappname} |
148 | ||
149 | \constfunc{wxString}{GetAppName}{\void} | |
150 | ||
151 | Returns the application name. | |
152 | ||
153 | \wxheading{Remarks} | |
154 | ||
fc2171bd | 155 | wxWidgets sets this to a reasonable default before |
a660d684 KB |
156 | calling \helpref{wxApp::OnInit}{wxapponinit}, but the application can reset it at will. |
157 | ||
d2175f3e VZ |
158 | \wxheading{See also} |
159 | ||
160 | \helpref{GetAppDisplayName}{wxappgetappdisplayname} | |
161 | ||
4c39aa3a | 162 | |
a660d684 KB |
163 | \membersection{wxApp::GetClassName}\label{wxappgetclassname} |
164 | ||
165 | \constfunc{wxString}{GetClassName}{\void} | |
166 | ||
167 | Gets the class name of the application. The class name may be used in a platform specific | |
168 | manner to refer to the application. | |
169 | ||
170 | \wxheading{See also} | |
171 | ||
172 | \helpref{wxApp::SetClassName}{wxappsetclassname} | |
173 | ||
4c39aa3a | 174 | |
f59d80ca | 175 | \membersection{wxApp::GetExitOnFrameDelete}\label{wxappgetexitonframedelete} |
a660d684 | 176 | |
dab73021 | 177 | \constfunc{bool}{GetExitOnFrameDelete}{\void} |
a660d684 | 178 | |
cc81d32f | 179 | Returns true if the application will exit when the top-level window is deleted, false |
a660d684 KB |
180 | otherwise. |
181 | ||
182 | \wxheading{See also} | |
183 | ||
1cbee0b4 VZ |
184 | \helpref{wxApp::SetExitOnFrameDelete}{wxappsetexitonframedelete},\\ |
185 | \helpref{wxApp shutdown overview}{wxappshutdownoverview} | |
a660d684 | 186 | |
4c39aa3a | 187 | |
82ce8b17 WS |
188 | \membersection{wxApp::GetInstance}\label{wxappgetinstance} |
189 | ||
190 | \func{static wxAppConsole *}{GetInstance}{\void} | |
191 | ||
192 | Returns the one and only global application object. | |
193 | Usually \texttt{wxTheApp} is usead instead. | |
194 | ||
195 | \wxheading{See also} | |
196 | ||
197 | \helpref{wxApp::SetInstance}{wxappsetinstance} | |
198 | ||
199 | ||
a660d684 KB |
200 | \membersection{wxApp::GetTopWindow}\label{wxappgettopwindow} |
201 | ||
83a5b533 | 202 | \constfunc{virtual wxWindow *}{GetTopWindow}{\void} |
a660d684 KB |
203 | |
204 | Returns a pointer to the top window. | |
205 | ||
2a47d3c1 JS |
206 | \wxheading{Remarks} |
207 | ||
208 | If the top window hasn't been set using \helpref{wxApp::SetTopWindow}{wxappsettopwindow}, this | |
209 | function will find the first top-level window (frame or dialog) and return that. | |
210 | ||
a660d684 KB |
211 | \wxheading{See also} |
212 | ||
8480b297 RR |
213 | \helpref{SetTopWindow}{wxappsettopwindow} |
214 | ||
4c39aa3a | 215 | |
afdf936c VZ |
216 | |
217 | \membersection{wxApp::GetTraits}\label{wxappgettraits} | |
218 | ||
219 | \func{wxAppTraits *}{GetTraits}{\void} | |
220 | ||
221 | Returns a pointer to the \helpref{wxAppTraits}{wxapptraits} object for the application. | |
222 | If you want to customize the \helpref{wxAppTraits}{wxapptraits} object, you must override the | |
223 | \helpref{CreateTraits}{wxappcreatetraits} function. | |
224 | ||
225 | ||
226 | ||
8480b297 RR |
227 | \membersection{wxApp::GetUseBestVisual}\label{wxappgetusebestvisual} |
228 | ||
229 | \constfunc{bool}{GetUseBestVisual}{\void} | |
230 | ||
cc81d32f VS |
231 | Returns true if the application will use the best visual on systems that support |
232 | different visuals, false otherwise. | |
8480b297 RR |
233 | |
234 | \wxheading{See also} | |
235 | ||
236 | \helpref{SetUseBestVisual}{wxappsetusebestvisual} | |
a660d684 | 237 | |
4c39aa3a | 238 | |
180b5b48 VZ |
239 | \membersection{wxApp::GetVendorDisplayName}\label{wxappgetvendordisplayname} |
240 | ||
241 | \constfunc{wxString}{GetVendorDisplayName}{\void} | |
242 | ||
243 | Returns the user-readable vendor name. The difference between this string | |
244 | and the one returned by \helpref{GetVendorName}{wxappgetvendorname} is that this one | |
245 | is meant to be shown to the user and so should be used for the window titles, | |
246 | page headers and so on while the other one should be only used internally, e.g. | |
247 | for the file names or configuration file keys. | |
248 | ||
249 | By default, returns the same string as \helpref{GetVendorName}{wxappgetvendorname}. | |
250 | ||
251 | \newsince{2.9.0} | |
252 | ||
253 | ||
e06b9569 | 254 | \membersection{wxApp::GetVendorName}\label{wxappgetvendorname} |
2aa59ef4 VS |
255 | |
256 | \constfunc{wxString}{GetVendorName}{\void} | |
257 | ||
258 | Returns the application's vendor name. | |
259 | ||
4c39aa3a | 260 | |
2fd47df6 | 261 | \membersection{wxApp::IsActive}\label{wxappisactive} |
a660d684 | 262 | |
2fd47df6 | 263 | \constfunc{bool}{IsActive}{\void} |
a660d684 | 264 | |
2fd47df6 VZ |
265 | Returns \true if the application is active, i.e. if one of its windows is |
266 | currently in the foreground. If this function returns \false and you need to | |
267 | attract users attention to the application, you may use | |
268 | \helpref{wxTopLevelWindow::RequestUserAttention}{wxtoplevelwindowrequestuserattention} | |
269 | to do it. | |
a660d684 | 270 | |
4c39aa3a | 271 | |
5f4f5b58 VZ |
272 | \membersection{wxApp::IsMainLoopRunning}\label{wxappismainlooprunning} |
273 | ||
9b0db452 | 274 | \func{static bool}{IsMainLoopRunning}{\void} |
5f4f5b58 VZ |
275 | |
276 | Returns \true if the main event loop is currently running, i.e. if the | |
277 | application is inside \helpref{OnRun}{wxapponrun}. | |
278 | ||
fab86f26 | 279 | This can be useful to test whether events can be dispatched. For example, |
5f4f5b58 VZ |
280 | if this function returns \false, non-blocking sockets cannot be used because |
281 | the events from them would never be processed. | |
282 | ||
283 | ||
a660d684 KB |
284 | \membersection{wxApp::MainLoop}\label{wxappmainloop} |
285 | ||
c805f6c3 | 286 | \func{virtual int}{MainLoop}{\void} |
a660d684 | 287 | |
fc2171bd | 288 | Called by wxWidgets on creation of the application. Override this if you wish |
a660d684 KB |
289 | to provide your own (environment-dependent) main loop. |
290 | ||
291 | \wxheading{Return value} | |
292 | ||
293 | Returns 0 under X, and the wParam of the WM\_QUIT message under Windows. | |
294 | ||
a5f1fd3e VZ |
295 | %% VZ: OnXXX() functions should *not* be documented |
296 | %% | |
297 | %%\membersection{wxApp::OnActivate}\label{wxapponactivate} | |
298 | %% | |
299 | %%\func{void}{OnActivate}{\param{wxActivateEvent\& }{event}} | |
300 | %% | |
301 | %%Provide this member function to know whether the application is being | |
302 | %%activated or deactivated (Windows only). | |
303 | %% | |
304 | %%\wxheading{See also} | |
305 | %% | |
306 | %%\helpref{wxWindow::OnActivate}{wxwindowonactivate}, \helpref{wxActivateEvent}{wxactivateevent} | |
307 | %% | |
308 | %%\membersection{wxApp::OnCharHook}\label{wxapponcharhook} | |
309 | %% | |
310 | %%\func{void}{OnCharHook}{\param{wxKeyEvent\&}{ event}} | |
311 | %% | |
312 | %%This event handler function is called (under Windows only) to allow the window to intercept keyboard events | |
313 | %%before they are processed by child windows. | |
314 | %% | |
315 | %%\wxheading{Parameters} | |
316 | %% | |
317 | %%\docparam{event}{The keypress event.} | |
318 | %% | |
319 | %%\wxheading{Remarks} | |
320 | %% | |
321 | %%Use the wxEVT\_CHAR\_HOOK macro in your event table. | |
322 | %% | |
323 | %%If you use this member, you can selectively consume keypress events by calling\rtfsp | |
324 | %%\helpref{wxEvent::Skip}{wxeventskip} for characters the application is not interested in. | |
325 | %% | |
326 | %%\wxheading{See also} | |
327 | %% | |
328 | %%\helpref{wxKeyEvent}{wxkeyevent}, \helpref{wxWindow::OnChar}{wxwindowonchar},\rtfsp | |
329 | %%\helpref{wxWindow::OnCharHook}{wxwindowoncharhook}, \helpref{wxDialog::OnCharHook}{wxdialogoncharhook} | |
330 | ||
4c39aa3a | 331 | |
3ec4a23f | 332 | \membersection{wxApp::OnAssertFailure}\label{wxapponassertfailure} |
a5f1fd3e | 333 | |
3ec4a23f | 334 | \func{void}{OnAssertFailure}{\param{const wxChar }{*file}, \param{int }{line}, \param{const wxChar }{*func}, \param{const wxChar }{*cond}, \param{const wxChar }{*msg}} |
a5f1fd3e VZ |
335 | |
336 | This function is called when an assert failure occurs, i.e. the condition | |
cc81d32f | 337 | specified in \helpref{wxASSERT}{wxassert} macro evaluated to {\tt false}. |
1156efc1 | 338 | It is only called in debug mode (when {\tt \_\_WXDEBUG\_\_} is defined) as |
a5f1fd3e VZ |
339 | asserts are not left in the release code at all. |
340 | ||
3ec4a23f | 341 | The base class version shows the default assert failure dialog box proposing to |
a5f1fd3e | 342 | the user to stop the program, continue or ignore all subsequent asserts. |
a660d684 | 343 | |
a5f1fd3e | 344 | \wxheading{Parameters} |
a660d684 | 345 | |
43e8916f | 346 | \docparam{file}{the name of the source file where the assert occurred} |
a660d684 | 347 | |
43e8916f | 348 | \docparam{line}{the line number in this file where the assert occurred} |
a660d684 | 349 | |
3ec4a23f VZ |
350 | \docparam{func}{the name of the function where the assert occurred, may be |
351 | empty if the compiler doesn't support C99 \texttt{\_\_FUNCTION\_\_}} | |
352 | ||
353 | \docparam{cond}{the condition of the failed assert in text form} | |
aad65f13 | 354 | |
a5f1fd3e VZ |
355 | \docparam{msg}{the message specified as argument to |
356 | \helpref{wxASSERT\_MSG}{wxassertmsg} or \helpref{wxFAIL\_MSG}{wxfailmsg}, will | |
357 | be {\tt NULL} if just \helpref{wxASSERT}{wxassert} or \helpref{wxFAIL}{wxfail} | |
358 | was used} | |
a660d684 | 359 | |
a660d684 | 360 | |
bf188f1a | 361 | \membersection{wxApp::OnCmdLineError}\label{wxapponcmdlineerror} |
a37a5a73 | 362 | |
bf188f1a | 363 | \func{bool}{OnCmdLineError}{\param{wxCmdLineParser\& }{parser}} |
a37a5a73 | 364 | |
bf188f1a VZ |
365 | Called when command line parsing fails (i.e. an incorrect command line option |
366 | was specified by the user). The default behaviour is to show the program usage | |
367 | text and abort the program. | |
a37a5a73 | 368 | |
cc81d32f VS |
369 | Return {\tt true} to continue normal execution or {\tt false} to return |
370 | {\tt false} from \helpref{OnInit}{wxapponinit} thus terminating the program. | |
a37a5a73 VZ |
371 | |
372 | \wxheading{See also} | |
373 | ||
bf188f1a | 374 | \helpref{OnInitCmdLine}{wxapponinitcmdline} |
a37a5a73 | 375 | |
4c39aa3a | 376 | |
bf188f1a | 377 | \membersection{wxApp::OnCmdLineHelp}\label{wxapponcmdlinehelp} |
a660d684 | 378 | |
bf188f1a | 379 | \func{bool}{OnCmdLineHelp}{\param{wxCmdLineParser\& }{parser}} |
a660d684 | 380 | |
bf188f1a VZ |
381 | Called when the help option ({\tt --help}) was specified on the command line. |
382 | The default behaviour is to show the program usage text and abort the program. | |
a660d684 | 383 | |
cc81d32f VS |
384 | Return {\tt true} to continue normal execution or {\tt false} to return |
385 | {\tt false} from \helpref{OnInit}{wxapponinit} thus terminating the program. | |
a660d684 KB |
386 | |
387 | \wxheading{See also} | |
388 | ||
bf188f1a | 389 | \helpref{OnInitCmdLine}{wxapponinitcmdline} |
a660d684 | 390 | |
4c39aa3a | 391 | |
bf188f1a | 392 | \membersection{wxApp::OnCmdLineParsed}\label{wxapponcmdlineparsed} |
387a3b02 | 393 | |
bf188f1a | 394 | \func{bool}{OnCmdLineParsed}{\param{wxCmdLineParser\& }{parser}} |
387a3b02 | 395 | |
bf188f1a VZ |
396 | Called after the command line had been successfully parsed. You may override |
397 | this method to test for the values of the various parameters which could be | |
398 | set from the command line. | |
387a3b02 | 399 | |
bf188f1a VZ |
400 | Don't forget to call the base class version unless you want to suppress |
401 | processing of the standard command line options. | |
387a3b02 | 402 | |
cc81d32f VS |
403 | Return {\tt true} to continue normal execution or {\tt false} to return |
404 | {\tt false} from \helpref{OnInit}{wxapponinit} thus terminating the program. | |
387a3b02 | 405 | |
bf188f1a VZ |
406 | \wxheading{See also} |
407 | ||
408 | \helpref{OnInitCmdLine}{wxapponinitcmdline} | |
409 | ||
4c39aa3a | 410 | |
f510b7b2 | 411 | \membersection{wxApp::OnExceptionInMainLoop}\label{wxapponexceptioninmainloop} |
b76f0023 VZ |
412 | |
413 | \func{virtual bool}{OnExceptionInMainLoop}{\void} | |
414 | ||
415 | This function is called if an unhandled exception occurs inside the main | |
416 | application event loop. It can return \true to ignore the exception and to | |
417 | continue running the loop or \false to exit the loop and terminate the | |
418 | program. In the latter case it can also use C++ \texttt{throw} keyword to | |
419 | rethrow the current exception. | |
420 | ||
421 | The default behaviour of this function is the latter in all ports except under | |
422 | Windows where a dialog is shown to the user which allows him to choose between | |
423 | the different options. You may override this function in your class to do | |
424 | something more appropriate. | |
425 | ||
426 | Finally note that if the exception is rethrown from here, it can be caught in | |
427 | \helpref{OnUnhandledException}{wxapponunhandledexception}. | |
428 | ||
429 | ||
4c39aa3a VZ |
430 | \membersection{wxApp::OnExit}\label{wxapponexit} |
431 | ||
bc37bb43 | 432 | \func{virtual int}{OnExit}{\void} |
4c39aa3a | 433 | |
bc37bb43 | 434 | Override this member function for any processing which needs to be |
4c39aa3a VZ |
435 | done as the application is about to exit. OnExit is called after |
436 | destroying all application windows and controls, but before | |
fc2171bd | 437 | wxWidgets cleanup. Note that it is not called at all if |
bc37bb43 VZ |
438 | \helpref{OnInit}{wxapponinit} failed. |
439 | ||
440 | The return value of this function is currently ignored, return the same value | |
441 | as returned by the base class method if you override it. | |
4c39aa3a VZ |
442 | |
443 | ||
bf188f1a VZ |
444 | \membersection{wxApp::OnFatalException}\label{wxapponfatalexception} |
445 | ||
446 | \func{void}{OnFatalException}{\void} | |
387a3b02 | 447 | |
bf188f1a VZ |
448 | This function may be called if something fatal happens: an unhandled |
449 | exception under Win32 or a a fatal signal under Unix, for example. However, | |
450 | this will not happen by default: you have to explicitly call | |
451 | \helpref{wxHandleFatalExceptions}{wxhandlefatalexceptions} to enable this. | |
387a3b02 | 452 | |
bf188f1a VZ |
453 | Generally speaking, this function should only show a message to the user and |
454 | return. You may attempt to save unsaved data but this is not guaranteed to | |
455 | work and, in fact, probably won't. | |
387a3b02 JS |
456 | |
457 | \wxheading{See also} | |
458 | ||
d2c2afc9 | 459 | \helpref{wxHandleFatalExceptions}{wxhandlefatalexceptions} |
bf188f1a VZ |
460 | |
461 | %% VZ: the wxApp event handler are private and should not be documented here! | |
462 | %% | |
463 | %%\membersection{wxApp::OnIdle}\label{wxapponidle} | |
464 | %% | |
465 | %%\func{void}{OnIdle}{\param{wxIdleEvent\& }{event}} | |
466 | %% | |
467 | %%Override this member function for any processing which needs to be done | |
468 | %%when the application is idle. You should call wxApp::OnIdle from your own function, | |
469 | %%since this forwards OnIdle events to windows and also performs garbage collection for | |
470 | %%windows whose destruction has been delayed. | |
471 | %% | |
fc2171bd JS |
472 | %%wxWidgets' strategy for OnIdle processing is as follows. After pending user interface events for an |
473 | %%application have all been processed, wxWidgets sends an OnIdle event to the application object. wxApp::OnIdle itself | |
bf188f1a VZ |
474 | %%sends an OnIdle event to each application window, allowing windows to do idle processing such as updating |
475 | %%their appearance. If either wxApp::OnIdle or a window OnIdle function requested more time, by | |
fc2171bd | 476 | %%calling \helpref{wxIdleEvent::RequestMore}{wxidleeventrequestmore}, wxWidgets will send another OnIdle |
bf188f1a VZ |
477 | %%event to the application object. This will occur in a loop until either a user event is found to be |
478 | %%pending, or OnIdle requests no more time. Then all pending user events are processed until the system | |
479 | %%goes idle again, when OnIdle is called, and so on. | |
480 | %% | |
481 | %%\wxheading{See also} | |
482 | %% | |
483 | %%\helpref{wxWindow::OnIdle}{wxwindowonidle}, \helpref{wxIdleEvent}{wxidleevent},\rtfsp | |
484 | %%\helpref{wxWindow::SendIdleEvents}{wxappsendidleevents} | |
485 | %% | |
486 | %%\membersection{wxApp::OnEndSession}\label{wxapponendsession} | |
487 | %% | |
488 | %%\func{void}{OnEndSession}{\param{wxCloseEvent\& }{event}} | |
489 | %% | |
490 | %%This is an event handler function called when the operating system or GUI session is | |
491 | %%about to close down. The application has a chance to silently save information, | |
492 | %%and can optionally close itself. | |
493 | %% | |
494 | %%Use the EVT\_END\_SESSION event table macro to handle query end session events. | |
495 | %% | |
cc81d32f | 496 | %%The default handler calls \helpref{wxWindow::Close}{wxwindowclose} with a true argument |
bf188f1a VZ |
497 | %%(forcing the application to close itself silently). |
498 | %% | |
499 | %%\wxheading{Remarks} | |
500 | %% | |
501 | %%Under X, OnEndSession is called in response to the `die' event. | |
502 | %% | |
503 | %%Under Windows, OnEndSession is called in response to the WM\_ENDSESSION message. | |
504 | %% | |
505 | %%\wxheading{See also} | |
506 | %% | |
507 | %%\helpref{wxWindow::Close}{wxwindowclose},\rtfsp | |
508 | %%\helpref{wxWindow::OnCloseWindow}{wxwindowonclosewindow},\rtfsp | |
509 | %%\helpref{wxCloseEvent}{wxcloseevent},\rtfsp | |
387a3b02 | 510 | |
4c39aa3a | 511 | |
a660d684 KB |
512 | \membersection{wxApp::OnInit}\label{wxapponinit} |
513 | ||
514 | \func{bool}{OnInit}{\void} | |
515 | ||
516 | This must be provided by the application, and will usually create the | |
bf188f1a | 517 | application's main window, optionally calling |
bc37bb43 VZ |
518 | \helpref{wxApp::SetTopWindow}{wxappsettopwindow}. You may use |
519 | \helpref{OnExit}{wxapponexit} to clean up anything initialized here, provided | |
520 | that the function returns \true. | |
bf188f1a VZ |
521 | |
522 | Notice that if you want to to use the command line processing provided by | |
fc2171bd | 523 | wxWidgets you have to call the base class version in the derived class |
bf188f1a | 524 | OnInit(). |
a660d684 | 525 | |
bc37bb43 VZ |
526 | Return \true to continue processing, \false to exit the application |
527 | immediately. | |
a660d684 | 528 | |
4c39aa3a | 529 | |
bf188f1a VZ |
530 | \membersection{wxApp::OnInitCmdLine}\label{wxapponinitcmdline} |
531 | ||
532 | \func{void}{OnInitCmdLine}{\param{wxCmdLineParser\& }{parser}} | |
533 | ||
534 | Called from \helpref{OnInit}{wxapponinit} and may be used to initialize the | |
535 | parser with the command line options for this application. The base class | |
536 | versions adds support for a few standard options only. | |
537 | ||
4c39aa3a VZ |
538 | \membersection{wxApp::OnRun}\label{wxapponrun} |
539 | ||
540 | \func{virtual int}{OnRun}{\void} | |
541 | ||
fc2171bd | 542 | This virtual function is where the execution of a program written in wxWidgets |
4c39aa3a VZ |
543 | starts. The default implementation just enters the main loop and starts |
544 | handling the events until it terminates, either because | |
545 | \helpref{ExitMainLoop}{wxappexitmainloop} has been explicitly called or because | |
546 | the last frame has been deleted and | |
547 | \helpref{GetExitOnFrameDelete}{wxappgetexitonframedelete} flag is \true (this | |
548 | is the default). | |
549 | ||
bc37bb43 VZ |
550 | The return value of this function becomes the exit code of the program, so it |
551 | should return $0$ in case of successful termination. | |
552 | ||
553 | ||
e490e267 | 554 | \membersection{wxApp::OnUnhandledException}\label{wxapponunhandledexception} |
4c39aa3a VZ |
555 | |
556 | \func{virtual void}{OnUnhandledException}{\void} | |
557 | ||
558 | This function is called when an unhandled C++ exception occurs inside | |
559 | \helpref{OnRun()}{wxapponrun} (the exceptions which occur during the program | |
1663c655 VZ |
560 | startup and shutdown might not be caught at all). Notice that by now the main |
561 | event loop has been terminated and the program will exit, if you want to | |
562 | prevent this from happening (i.e. continue running after catching an exception) | |
563 | you need to override \helpref{OnExceptionInMainLoop}{wxapponexceptioninmainloop}. | |
564 | ||
565 | The default implementation shows information about the exception in debug build | |
566 | but does nothing in the release build. | |
4c39aa3a | 567 | |
bc37bb43 | 568 | |
a660d684 KB |
569 | \membersection{wxApp::ProcessMessage}\label{wxappprocessmessage} |
570 | ||
da25d3ab | 571 | \func{bool}{ProcessMessage}{\param{WXMSG *}{msg}} |
a660d684 KB |
572 | |
573 | Windows-only function for processing a message. This function | |
574 | is called from the main message loop, checking for windows that | |
cc81d32f | 575 | may wish to process it. The function returns true if the message |
fc2171bd | 576 | was processed, false otherwise. If you use wxWidgets with another class |
a660d684 | 577 | library with its own message loop, you should make sure that this |
fc2171bd | 578 | function is called to allow wxWidgets to receive messages. For example, |
2edb0bde | 579 | to allow co-existence with the Microsoft Foundation Classes, override |
a660d684 KB |
580 | the PreTranslateMessage function: |
581 | ||
582 | \begin{verbatim} | |
fc2171bd | 583 | // Provide wxWidgets message loop compatibility |
a660d684 KB |
584 | BOOL CTheApp::PreTranslateMessage(MSG *msg) |
585 | { | |
da25d3ab | 586 | if (wxTheApp && wxTheApp->ProcessMessage((WXMSW *)msg)) |
cc81d32f | 587 | return true; |
a660d684 KB |
588 | else |
589 | return CWinApp::PreTranslateMessage(msg); | |
590 | } | |
591 | \end{verbatim} | |
592 | ||
4c39aa3a | 593 | |
387a3b02 JS |
594 | \membersection{wxApp::Pending}\label{wxapppending} |
595 | ||
c805f6c3 | 596 | \func{virtual bool}{Pending}{\void} |
387a3b02 | 597 | |
cc81d32f | 598 | Returns true if unprocessed events are in the window system event queue. |
387a3b02 JS |
599 | |
600 | \wxheading{See also} | |
601 | ||
602 | \helpref{wxApp::Dispatch}{wxappdispatch} | |
603 | ||
4c39aa3a | 604 | |
a660d684 KB |
605 | \membersection{wxApp::SendIdleEvents}\label{wxappsendidleevents} |
606 | ||
dfcb9d7c | 607 | \func{bool}{SendIdleEvents}{\param{wxWindow*}{ win}, \param{wxIdleEvent\& }{event}} |
a660d684 KB |
608 | |
609 | Sends idle events to a window and its children. | |
610 | ||
fc2171bd | 611 | Please note that this function is internal to wxWidgets and shouldn't be used |
dfcb9d7c VZ |
612 | by user code. |
613 | ||
a660d684 KB |
614 | \wxheading{Remarks} |
615 | ||
616 | These functions poll the top-level windows, and their children, for idle event processing. | |
cc81d32f | 617 | If true is returned, more OnIdle processing is requested by one or more window. |
a660d684 KB |
618 | |
619 | \wxheading{See also} | |
620 | ||
4d5a0f67 | 621 | \helpref{wxIdleEvent}{wxidleevent} |
a660d684 | 622 | |
4c39aa3a | 623 | |
d2175f3e VZ |
624 | \membersection{wxApp::SetAppDisplayName}\label{wxappsetappdisplayname} |
625 | ||
626 | \func{void}{SetAppDisplayName}{\param{const wxString\& }{name}} | |
627 | ||
628 | Set the application name to be used in the user-visible places such as window | |
629 | titles. See \helpref{GetAppDisplayName}{wxappgetappdisplayname} for more about | |
630 | the differences between the display name and name. | |
631 | ||
632 | ||
a660d684 KB |
633 | \membersection{wxApp::SetAppName}\label{wxappsetappname} |
634 | ||
635 | \func{void}{SetAppName}{\param{const wxString\& }{name}} | |
636 | ||
d2175f3e VZ |
637 | Sets the name of the application. This name should be used for file names, |
638 | configuration file entries and other internal strings. For the user-visible | |
639 | strings, such as the window titles, the application display name set by | |
640 | \helpref{SetAppDisplayName}{wxappsetappdisplayname} is used instead. | |
641 | ||
642 | By default the application name is set to the name of its executable file. | |
a660d684 KB |
643 | |
644 | \wxheading{See also} | |
645 | ||
646 | \helpref{wxApp::GetAppName}{wxappgetappname} | |
647 | ||
4c39aa3a | 648 | |
a660d684 KB |
649 | \membersection{wxApp::SetClassName}\label{wxappsetclassname} |
650 | ||
651 | \func{void}{SetClassName}{\param{const wxString\& }{name}} | |
652 | ||
653 | Sets the class name of the application. This may be used in a platform specific | |
654 | manner to refer to the application. | |
655 | ||
656 | \wxheading{See also} | |
657 | ||
658 | \helpref{wxApp::GetClassName}{wxappgetclassname} | |
659 | ||
4c39aa3a | 660 | |
f59d80ca | 661 | \membersection{wxApp::SetExitOnFrameDelete}\label{wxappsetexitonframedelete} |
a660d684 | 662 | |
f59d80ca | 663 | \func{void}{SetExitOnFrameDelete}{\param{bool}{ flag}} |
a660d684 KB |
664 | |
665 | Allows the programmer to specify whether the application will exit when the | |
666 | top-level frame is deleted. | |
667 | ||
668 | \wxheading{Parameters} | |
669 | ||
cc81d32f VS |
670 | \docparam{flag}{If true (the default), the application will exit when the top-level frame is |
671 | deleted. If false, the application will continue to run.} | |
a660d684 | 672 | |
1cbee0b4 VZ |
673 | \wxheading{See also} |
674 | ||
675 | \helpref{wxApp::GetExitOnFrameDelete}{wxappgetexitonframedelete},\\ | |
676 | \helpref{wxApp shutdown overview}{wxappshutdownoverview} | |
677 | ||
4c39aa3a | 678 | |
82ce8b17 WS |
679 | \membersection{wxApp::SetInstance}\label{wxappsetinstance} |
680 | ||
681 | \func{static void}{SetInstance}{\param{wxAppConsole* }{app}} | |
682 | ||
683 | Allows external code to modify global \texttt{wxTheApp}, but you should really | |
684 | know what you're doing if you call it. | |
685 | ||
686 | \wxheading{Parameters} | |
687 | ||
688 | \docparam{app}{Replacement for the global application object.} | |
689 | ||
690 | \wxheading{See also} | |
691 | ||
692 | \helpref{wxApp::GetInstance}{wxappgetinstance} | |
693 | ||
694 | ||
a660d684 KB |
695 | \membersection{wxApp::SetTopWindow}\label{wxappsettopwindow} |
696 | ||
697 | \func{void}{SetTopWindow}{\param{wxWindow* }{window}} | |
698 | ||
2a47d3c1 | 699 | Sets the `top' window. You can call this from within \helpref{wxApp::OnInit}{wxapponinit} to |
fc2171bd | 700 | let wxWidgets know which is the main window. You don't have to set the top window; |
f6bcfd97 | 701 | it is only a convenience so that (for example) certain dialogs without parents can use a |
2a47d3c1 | 702 | specific window as the top window. If no top window is specified by the application, |
fc2171bd | 703 | wxWidgets just uses the first frame or dialog in its top-level window list, when it |
2a47d3c1 | 704 | needs to use the top window. |
a660d684 KB |
705 | |
706 | \wxheading{Parameters} | |
707 | ||
708 | \docparam{window}{The new top window.} | |
709 | ||
710 | \wxheading{See also} | |
711 | ||
712 | \helpref{wxApp::GetTopWindow}{wxappgettopwindow}, \helpref{wxApp::OnInit}{wxapponinit} | |
713 | ||
2aa59ef4 | 714 | |
180b5b48 VZ |
715 | \membersection{wxApp::SetVendorDisplayName}\label{wxappsetvendordisplayname} |
716 | ||
717 | \func{void}{SetVendorDisplayName}{\param{const wxString\& }{name}} | |
718 | ||
719 | Set the vendor name to be used in the user-visible places. See | |
720 | \helpref{GetVendorDisplayName}{wxappgetvendordisplayname} for more about | |
721 | the differences between the display name and name. | |
722 | ||
4c39aa3a | 723 | |
2aa59ef4 VS |
724 | \membersection{wxApp::SetVendorName}\label{wxappsetvendorname} |
725 | ||
726 | \func{void}{SetVendorName}{\param{const wxString\& }{name}} | |
727 | ||
728 | Sets the name of application's vendor. The name will be used | |
729 | in registry access. A default name is set by | |
fc2171bd | 730 | wxWidgets. |
2aa59ef4 VS |
731 | |
732 | \wxheading{See also} | |
733 | ||
734 | \helpref{wxApp::GetVendorName}{wxappgetvendorname} | |
735 | ||
4c39aa3a | 736 | |
8480b297 RR |
737 | \membersection{wxApp::SetUseBestVisual}\label{wxappsetusebestvisual} |
738 | ||
515a31bf | 739 | \func{void}{SetUseBestVisual}{\param{bool}{ flag}, \param{bool}{ forceTrueColour = false}} |
8480b297 RR |
740 | |
741 | Allows the programmer to specify whether the application will use the best visual | |
103aab26 RR |
742 | on systems that support several visual on the same display. This is typically the |
743 | case under Solaris and IRIX, where the default visual is only 8-bit whereas certain | |
2edb0bde | 744 | applications are supposed to run in TrueColour mode. |
8480b297 | 745 | |
515a31bf RR |
746 | If \arg{forceTrueColour} is true then the application will try to force |
747 | using a TrueColour visual and abort the app if none is found. | |
748 | ||
fa482912 | 749 | Note that this function has to be called in the constructor of the {\tt wxApp} |
8480b297 RR |
750 | instance and won't have any effect when called later on. |
751 | ||
752 | This function currently only has effect under GTK. | |
753 | ||
754 | \wxheading{Parameters} | |
755 | ||
cc81d32f | 756 | \docparam{flag}{If true, the app will use the best visual.} |
e06b9569 | 757 | |
763b3301 VS |
758 | |
759 | \membersection{wxApp::HandleEvent}\label{wxapphandleevent} | |
760 | ||
761 | \constfunc{virtual void}{HandleEvent}{\param{wxEvtHandler}{ *handler}, \param{wxEventFunction}{ func}, \param{wxEvent\& }{event}} | |
762 | ||
763 | This function simply invokes the given method \arg{func} of the specified | |
764 | event handler \arg{handler} with the \arg{event} as parameter. It exists solely | |
765 | to allow to catch the C++ exceptions which could be thrown by all event | |
766 | handlers in the application in one place: if you want to do this, override this | |
767 | function in your wxApp-derived class and add try/catch clause(s) to it. | |
768 | ||
769 | ||
5638d705 | 770 | \membersection{wxApp::Yield}\label{wxappyield} |
8461e4c2 | 771 | |
cc81d32f | 772 | \func{bool}{Yield}{\param{bool}{ onlyIfNeeded = false}} |
8461e4c2 VZ |
773 | |
774 | Yields control to pending messages in the windowing system. This can be useful, for example, when a | |
775 | time-consuming process writes to a text window. Without an occasional | |
776 | yield, the text window will not be updated properly, and on systems with | |
777 | cooperative multitasking, such as Windows 3.1 other processes will not respond. | |
778 | ||
779 | Caution should be exercised, however, since yielding may allow the | |
780 | user to perform actions which are not compatible with the current task. | |
781 | Disabling menu items or whole menus during processing can avoid unwanted | |
782 | reentrance of code: see \helpref{::wxSafeYield}{wxsafeyield} for a better | |
783 | function. | |
784 | ||
785 | Note that Yield() will not flush the message logs. This is intentional as | |
786 | calling Yield() is usually done to quickly update the screen and popping up a | |
787 | message box dialog may be undesirable. If you do wish to flush the log | |
788 | messages immediately (otherwise it will be done during the next idle loop | |
789 | iteration), call \helpref{wxLog::FlushActive}{wxlogflushactive}. | |
790 | ||
791 | Calling Yield() recursively is normally an error and an assert failure is | |
43e8916f | 792 | raised in debug build if such situation is detected. However if the |
cc81d32f VS |
793 | {\it onlyIfNeeded} parameter is {\tt true}, the method will just silently |
794 | return {\tt false} instead. | |
f010ad48 | 795 |