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