]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/app.tex
* First draft on wxStreamBuffer, wxStream* will follow.
[wxWidgets.git] / docs / latex / wx / app.tex
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
15 file to tell wxWindows how to create an instance of your application class.
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
25 \wxheading{See also}
26
27 \helpref{wxApp overview}{wxappoverview}
28
29 \latexignore{\rtfignore{\wxheading{Members}}}
30
31 \membersection{wxApp::wxApp}
32
33 \func{void}{wxApp}{\void}
34
35 Constructor. Called implicitly with a definition of a wxApp object.
36
37 The argument is a language identifier; this is an experimental
38 feature and will be expanded and documented in future versions.
39
40 \membersection{wxApp::\destruct{wxApp}}
41
42 \func{void}{\destruct{wxApp}}{\void}
43
44 Destructor. Will be called implicitly on program exit if the wxApp
45 object is created on the stack.
46
47 \membersection{wxApp::argc}\label{wxappargc}
48
49 \member{int}{argc}
50
51 Number of command line arguments (after environment-specific processing).
52
53 \membersection{wxApp::argv}\label{wxappargv}
54
55 \member{char **}{argv}
56
57 Command line arguments (after environment-specific processing).
58
59 \membersection{wxApp::CreateLogTarget}\label{wxappcreatelogtarget}
60
61 \func{virtual wxLog*}{CreateLogTarget}{\void}
62
63 Creates a wxLog class for the application to use for logging errors. The default
64 implementation returns a new wxLogGui class.
65
66 \wxheading{See also}
67
68 \helpref{wxLog}{wxlog}
69
70 \membersection{wxApp::Dispatch}\label{wxappdispatch}
71
72 \func{void}{Dispatch}{\void}
73
74 Dispatches the next event in the windowing system event queue.
75
76 This can be used for programming event loops, e.g.
77
78 \begin{verbatim}
79 while (app.Pending())
80 Dispatch();
81 \end{verbatim}
82
83 \wxheading{See also}
84
85 \helpref{wxApp::Pending}{wxapppending}
86
87 \membersection{wxApp::GetAppName}\label{wxappgetappname}
88
89 \constfunc{wxString}{GetAppName}{\void}
90
91 Returns the application name.
92
93 \wxheading{Remarks}
94
95 wxWindows sets this to a reasonable default before
96 calling \helpref{wxApp::OnInit}{wxapponinit}, but the application can reset it at will.
97
98 \membersection{wxApp::GetAuto3D}\label{wxappgetauto3d}
99
100 \constfunc{bool}{GetAuto3D}{\void}
101
102 Returns TRUE if 3D control mode is on, FALSE otherwise.
103
104 \wxheading{See also}
105
106 \helpref{wxApp::SetAuto3D}{wxappsetauto3d}
107
108 \membersection{wxApp::GetClassName}\label{wxappgetclassname}
109
110 \constfunc{wxString}{GetClassName}{\void}
111
112 Gets the class name of the application. The class name may be used in a platform specific
113 manner to refer to the application.
114
115 \wxheading{See also}
116
117 \helpref{wxApp::SetClassName}{wxappsetclassname}
118
119 \membersection{wxApp::GetExitOnDelete}\label{wxappgetexitondelete}
120
121 \constfunc{bool}{GetExitOnDelete}{\void}
122
123 Returns TRUE if the application will exit when the top-level window is deleted, FALSE
124 otherwise.
125
126 \wxheading{See also}
127
128 \helpref{wxApp::SetExitOnDelete}{wxappsetexitondelete}
129
130 \membersection{wxApp::GetPrintMode}\label{wxappgetprintmode}
131
132 \constfunc{bool}{GetPrintMode}{\void}
133
134 Returns the print mode: see \helpref{wxApp::SetPrintMode}{wxappsetprintmode}.
135
136 \membersection{wxApp::GetTopWindow}\label{wxappgettopwindow}
137
138 \constfunc{wxWindow *}{GetTopWindow}{\void}
139
140 Returns a pointer to the top window.
141
142 \wxheading{See also}
143
144 \helpref{wxApp::SetTopWindow}{wxappsettopwindow}
145
146 \membersection{wxApp::ExitMainLoop}\label{wxappexitmainloop}
147
148 \func{void}{ExitMainLoop}{\void}
149
150 Call this to explicitly exit the main message (event) loop.
151 You should normally exit the main loop (and the application) by deleting
152 the top window.
153
154 \membersection{wxApp::Initialized}\label{wxappinitialized}
155
156 \func{bool}{Initialized}{\void}
157
158 Returns TRUE if the application has been initialized (i.e. if\rtfsp
159 \helpref{wxApp::OnInit}{wxapponinit} has returned successfully). This can be useful for error
160 message routines to determine which method of output is best for the
161 current state of the program (some windowing systems may not like
162 dialogs to pop up before the main loop has been entered).
163
164 \membersection{wxApp::MainLoop}\label{wxappmainloop}
165
166 \func{int}{MainLoop}{\void}
167
168 Called by wxWindows on creation of the application. Override this if you wish
169 to provide your own (environment-dependent) main loop.
170
171 \wxheading{Return value}
172
173 Returns 0 under X, and the wParam of the WM\_QUIT message under Windows.
174
175 \membersection{wxApp::OnActivate}\label{wxapponactivate}
176
177 \func{void}{OnActivate}{\param{wxActivateEvent\& }{event}}
178
179 Provide this member function to know whether the application is being
180 activated or deactivated (Windows only).
181
182 \wxheading{See also}
183
184 \helpref{wxWindow::OnActivate}{wxwindowonactivate}, \helpref{wxActivateEvent}{wxactivateevent}
185
186 \membersection{wxApp::OnExit}\label{wxapponexit}
187
188 \func{int}{OnExit}{\void}
189
190 Provide this member function for any processing which needs to be done as
191 the application is about to exit.
192
193 \membersection{wxApp::OnCharHook}\label{wxapponcharhook}
194
195 \func{void}{OnCharHook}{\param{wxKeyEvent\&}{ event}}
196
197 This event handler function is called (under Windows only) to allow the window to intercept keyboard events
198 before they are processed by child windows.
199
200 \wxheading{Parameters}
201
202 \docparam{event}{The keypress event.}
203
204 \wxheading{Remarks}
205
206 Use the wxEVT\_CHAR\_HOOK macro in your event table.
207
208 If you use this member, you can selectively consume keypress events by calling\rtfsp
209 \helpref{wxEvent::Skip}{wxeventskip} for characters the application is not interested in.
210
211 \wxheading{See also}
212
213 \helpref{wxKeyEvent}{wxkeyevent}, \helpref{wxWindow::OnChar}{wxwindowonchar},\rtfsp
214 \helpref{wxWindow::OnCharHook}{wxwindowoncharhook}, \helpref{wxDialog::OnCharHook}{wxdialogoncharhook}
215
216 \membersection{wxApp::OnIdle}\label{wxapponidle}
217
218 \func{void}{OnIdle}{\param{wxIdleEvent\& }{event}}
219
220 Override this member function for any processing which needs to be done
221 when the application is idle. You should call wxApp::OnIdle from your own function,
222 since this forwards OnIdle events to windows and also performs garbage collection for
223 windows whose destruction has been delayed.
224
225 wxWindows' strategy for OnIdle processing is as follows. After pending user interface events for an
226 application have all been processed, wxWindows sends an OnIdle event to the application object. wxApp::OnIdle itself
227 sends an OnIdle event to each application window, allowing windows to do idle processing such as updating
228 their appearance. If either wxApp::OnIdle or a window OnIdle function requested more time, by
229 caling \helpref{wxIdleEvent::ReqestMore}{wxidleeventrequestmore}, wxWindows will send another OnIdle
230 event to the application object. This will occur in a loop until either a user event is found to be
231 pending, or OnIdle requests no more time. Then all pending user events are processed until the system
232 goes idle again, when OnIdle is called, and so on.
233
234 \wxheading{See also}
235
236 \helpref{wxWindow::OnIdle}{wxwindowonidle}, \helpref{wxIdleEvent}{wxidleevent},\rtfsp
237 \helpref{wxWindow::SendIdleEvents}{wxappsendidleevents}
238
239 \membersection{wxApp::OnEndSession}\label{wxapponendsession}
240
241 \func{void}{OnEndSession}{\param{wxCloseEvent\& }{event}}
242
243 This is an event handler function called when the operating system or GUI session is
244 about to close down. The application has a chance to silently save information,
245 and can optionally close itself.
246
247 Use the EVT\_END\_SESSION event table macro to handle query end session events.
248
249 The default handler calls \helpref{wxWindow::Close}{wxwindowclose} with a TRUE argument
250 (forcing the application to close itself silently).
251
252 \wxheading{Remarks}
253
254 Under X, OnEndSession is called in response to the 'die' event.
255
256 Under Windows, OnEndSession is called in response to the WM\_ENDSESSION message.
257
258 \wxheading{See also}
259
260 \helpref{wxWindow::Close}{wxwindowclose},\rtfsp
261 \helpref{wxWindow::OnCloseWindow}{wxwindowonclosewindow},\rtfsp
262 \helpref{wxCloseEvent}{wxcloseevent},\rtfsp
263 \helpref{wxApp::OnQueryEndSession}{wxapponqueryendsession}
264
265 \membersection{wxApp::OnInit}\label{wxapponinit}
266
267 \func{bool}{OnInit}{\void}
268
269 This must be provided by the application, and will usually create the
270 application's main window, calling \helpref{wxApp::SetTopWindow}{wxappsettopwindow}.
271
272 Return TRUE to continue processing, FALSE to exit the application.
273
274 \membersection{wxApp::OnQueryEndSession}\label{wxapponqueryendsession}
275
276 \func{void}{OnQueryEndSession}{\param{wxCloseEvent\& }{event}}
277
278 This is an event handler function called when the operating system or GUI session is
279 about to close down. Typically, an application will try to save unsaved documents
280 at this point.
281
282 If \helpref{wxCloseEvent::CanVeto}{wxcloseeventcanveto} returns TRUE, the application
283 is allowed to veto the shutdown by calling \helpref{wxCloseEvent::Veto}{wxcloseeventveto}.
284 The application might veto the shutdown after prompting for documents to be saved, and the
285 user has cancelled the save.
286
287 Use the EVT\_QUERY\_END\_SESSION event table macro to handle query end session events.
288
289 You should check whether the application is forcing the deletion of the window
290 using \helpref{wxCloseEvent::GetForce}{wxcloseeventgetforce}. If this is TRUE,
291 destroy the window using \helpref{wxWindow::Destroy}{wxwindowdestroy}.
292 If not, it is up to you whether you respond by destroying the window.
293
294 The default handler calls \helpref{wxWindow::Close}{wxwindowclose} on the top-level window,
295 and vetoes the shutdown if Close returns FALSE. This will be sufficient for many applications.
296
297 \wxheading{Remarks}
298
299 Under X, OnQueryEndSession is called in response to the 'save session' event.
300
301 Under Windows, OnQueryEndSession is called in response to the WM\_QUERYENDSESSION message.
302
303 \wxheading{See also}
304
305 \helpref{wxWindow::Close}{wxwindowclose},\rtfsp
306 \helpref{wxWindow::OnCloseWindow}{wxwindowonclosewindow},\rtfsp
307 \helpref{wxCloseEvent}{wxcloseevent},\rtfsp
308 \helpref{wxApp::OnEndSession}{wxapponendsession}
309
310 \membersection{wxWindow::OnScroll}\label{wxwindowonscroll}
311
312 \membersection{wxApp::ProcessMessage}\label{wxappprocessmessage}
313
314 \func{bool}{ProcessMessage}{\param{MSG *}{msg}}
315
316 Windows-only function for processing a message. This function
317 is called from the main message loop, checking for windows that
318 may wish to process it. The function returns TRUE if the message
319 was processed, FALSE otherwise. If you use wxWindows with another class
320 library with its own message loop, you should make sure that this
321 function is called to allow wxWindows to receive messages. For example,
322 to allow co-existance with the Microsoft Foundation Classes, override
323 the PreTranslateMessage function:
324
325 \begin{verbatim}
326 // Provide wxWindows message loop compatibility
327 BOOL CTheApp::PreTranslateMessage(MSG *msg)
328 {
329 if (wxTheApp && wxTheApp->ProcessMessage(msg))
330 return TRUE;
331 else
332 return CWinApp::PreTranslateMessage(msg);
333 }
334 \end{verbatim}
335
336 \membersection{wxApp::Pending}\label{wxapppending}
337
338 \func{bool}{Pending}{\void}
339
340 Returns TRUE if unprocessed events are in the window system event queue
341 (MS Windows and Motif).
342
343 \wxheading{See also}
344
345 \helpref{wxApp::Dispatch}{wxappdispatch}
346
347 \membersection{wxApp::SendIdleEvents}\label{wxappsendidleevents}
348
349 \func{bool}{SendIdleEvents}{\void}
350
351 Sends idle events to all top-level windows.
352
353 \func{bool}{SendIdleEvents}{\param{wxWindow*}{ win}}
354
355 Sends idle events to a window and its children.
356
357 \wxheading{Remarks}
358
359 These functions poll the top-level windows, and their children, for idle event processing.
360 If TRUE is returned, more OnIdle processing is requested by one or more window.
361
362 \wxheading{See also}
363
364 \helpref{wxApp::OnIdle}{wxapponidle}, \helpref{wxWindow::OnIdle}{wxwindowonidle}, \helpref{wxIdleEvent}{wxidleevent}
365
366 \membersection{wxApp::SetAppName}\label{wxappsetappname}
367
368 \func{void}{SetAppName}{\param{const wxString\& }{name}}
369
370 Sets the name of the application. The name may be used in dialogs
371 (for example by the document/view framework). A default name is set by
372 wxWindows.
373
374 \wxheading{See also}
375
376 \helpref{wxApp::GetAppName}{wxappgetappname}
377
378 \membersection{wxApp::SetAuto3D}\label{wxappsetauto3d}
379
380 \func{void}{SetAuto3D}{\param{const bool}{ auto3D}}
381
382 Switches automatic 3D controls on or off.
383
384 \wxheading{Parameters}
385
386 \docparam{auto3D}{If TRUE, all controls will be created with 3D appearances unless
387 overridden for a control or dialog. The default is TRUE}
388
389 \wxheading{Remarks}
390
391 This has an effect on Windows only.
392
393 \wxheading{See also}
394
395 \helpref{wxApp::GetAuto3D}{wxappgetauto3d}
396
397 \membersection{wxApp::SetClassName}\label{wxappsetclassname}
398
399 \func{void}{SetClassName}{\param{const wxString\& }{name}}
400
401 Sets the class name of the application. This may be used in a platform specific
402 manner to refer to the application.
403
404 \wxheading{See also}
405
406 \helpref{wxApp::GetClassName}{wxappgetclassname}
407
408 \membersection{wxApp::SetExitOnDelete}\label{wxappsetexitondelete}
409
410 \func{void}{SetExitOnDelete}{\param{bool}{ flag}}
411
412 Allows the programmer to specify whether the application will exit when the
413 top-level frame is deleted.
414
415 \wxheading{Parameters}
416
417 \docparam{flag}{If TRUE (the default), the application will exit when the top-level frame is
418 deleted. If FALSE, the application will continue to run.}
419
420 \wxheading{Remarks}
421
422 Currently, setting this to FALSE only has an effect under Windows.
423
424 \membersection{wxApp::SetPrintMode}\label{wxappsetprintmode}
425
426 \func{void}{SetPrintMode}{\param{int}{ mode}}
427
428 Sets the print mode determining what printing facilities will be
429 used by the printing framework.
430
431 \wxheading{Parameters}
432
433 \docparam{mode}{This can be one of:
434
435 \begin{twocollist}\itemsep=0pt
436 \twocolitem{{\bf wxPRINT\_WINDOWS}}{Under Windows, use Windows printing (wxPrinterDC). This is the
437 default under Windows.}
438 \twocolitem{{\bf wxPRINT\_POSTSCRIPT}}{Use PostScript printing (wxPostScriptDC). This is the
439 default for non-Windows platforms.}
440 \end{twocollist}
441 }%
442
443 \membersection{wxApp::SetTopWindow}\label{wxappsettopwindow}
444
445 \func{void}{SetTopWindow}{\param{wxWindow* }{window}}
446
447 Sets the `top' window. You should normally call this from within \helpref{wxApp::OnInit}{wxapponinit} to
448 let wxWindows know which is the main window.
449
450 \wxheading{Parameters}
451
452 \docparam{window}{The new top window.}
453
454 \wxheading{See also}
455
456 \helpref{wxApp::GetTopWindow}{wxappgettopwindow}, \helpref{wxApp::OnInit}{wxapponinit}
457