]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/frame.tex
6e7287870a24fe8813d4b273d252559e5e7a9719
[wxWidgets.git] / docs / latex / wx / frame.tex
1 \section{\class{wxFrame}}\label{wxframe}
2
3 A frame is a window whose size and position can (usually) be changed by the user. It usually has
4 thick borders and a title bar, and can optionally contain a menu bar, toolbar and
5 status bar. A frame can contain any window that is not a frame or dialog.
6
7 A frame that has a status bar and toolbar created via the CreateStatusBar/CreateToolBar functions
8 manages these windows, and adjusts the value returned by GetClientSize to reflect
9 the remaining size available to application windows.
10
11 \wxheading{Derived from}
12
13 \helpref{wxWindow}{wxwindow}\\
14 \helpref{wxEvtHandler}{wxevthandler}\\
15 \helpref{wxObject}{wxobject}
16
17 \wxheading{Window styles}
18
19 \twocolwidtha{5cm}
20 \begin{twocollist}\itemsep=0pt
21 \twocolitem{\windowstyle{wxICONIZE}}{Display the frame iconized (minimized) (Windows only).}
22 \twocolitem{\windowstyle{wxCAPTION}}{Puts a caption on the frame.}
23 \twocolitem{\windowstyle{wxDEFAULT\_FRAME\_STYLE}}{Defined as {\bf wxMINIMIZE\_BOX \pipe wxMAXIMIZE\_BOX \pipe wxTHICK\_FRAME \pipe wxSYSTEM\_MENU \pipe wxCAPTION}.}
24 \twocolitem{\windowstyle{wxMINIMIZE}}{Identical to {\bf wxICONIZE}.}
25 \twocolitem{\windowstyle{wxMINIMIZE\_BOX}}{Displays a minimize box on the frame (Windows and Motif only).}
26 \twocolitem{\windowstyle{wxMAXIMIZE}}{Displays the frame maximized (Windows only).}
27 \twocolitem{\windowstyle{wxMAXIMIZE\_BOX}}{Displays a maximize box on the frame (Windows and Motif only).}
28 \twocolitem{\windowstyle{wxSTAY\_ON\_TOP}}{Stay on top of other windows (Windows only).}
29 \twocolitem{\windowstyle{wxSYSTEM\_MENU}}{Displays a system menu (Windows and Motif only).}
30 \twocolitem{\windowstyle{wxTHICK\_FRAME}}{Displays a thick frame around the window (Windows and Motif only).}
31 \twocolitem{\windowstyle{wxRESIZE\_BORDER}}{Displays a resizeable border around the window (Motif only).}
32 \end{twocollist}
33
34 See also \helpref{window styles overview}{windowstyles}. Currently the GTK port of wxWindows
35 ignores all the window styles listed above as there is no standard way (yet) to inform the
36 window manager about such options. Therefore, the only relevant window style flag which
37 the GTK port recognizes is \windowstyle{wxSIMPLE\_BORDER} which brings up a frame without
38 any window decorations. This can be used for a splash screen or specialized tooltip etc.
39
40 \wxheading{Remarks}
41
42 An application should normally define an \helpref{OnCloseWindow}{wxwindowonclosewindow} handler for the
43 frame to respond to system close events, for example so that related data and subwindows can be cleaned up.
44
45 \wxheading{See also}
46
47 \helpref{wxMDIParentFrame}{wxmdiparentframe}, \helpref{wxMDIChildFrame}{wxmdichildframe},\rtfsp
48 \helpref{wxMiniFrame}{wxminiframe}, \helpref{wxDialog}{wxdialog}
49
50 \latexignore{\rtfignore{\wxheading{Members}}}
51
52 \membersection{wxFrame::wxFrame}\label{wxframeconstr}
53
54 \func{}{wxFrame}{\void}
55
56 Default constructor.
57
58 \func{}{wxFrame}{\param{wxWindow* }{parent}, \param{wxWindowID }{id},\rtfsp
59 \param{const wxString\& }{title}, \param{const wxPoint\&}{ pos = wxDefaultPosition},\rtfsp
60 \param{const wxSize\&}{ size = wxDefaultSize}, \param{long}{ style = wxDEFAULT\_FRAME\_STYLE},\rtfsp
61 \param{const wxString\& }{name = ``frame"}}
62
63 Constructor, creating the window.
64
65 \wxheading{Parameters}
66
67 \docparam{parent}{The window parent. This may be NULL. If it is non-NULL, the frame will
68 always be displayed on top of the parent window on Windows.}
69
70 \docparam{id}{The window identifier. It may take a value of -1 to indicate a default value.}
71
72 \docparam{title}{The caption to be displayed on the frame's title bar.}
73
74 \docparam{pos}{The window position. A value of (-1, -1) indicates a default position, chosen by
75 either the windowing system or wxWindows, depending on platform.}
76
77 \docparam{size}{The window size. A value of (-1, -1) indicates a default size, chosen by
78 either the windowing system or wxWindows, depending on platform.}
79
80 \docparam{style}{The window style. See \helpref{wxFrame}{wxframe}.}
81
82 \docparam{name}{The name of the window. This parameter is used to associate a name with the item,
83 allowing the application user to set Motif resource values for
84 individual windows.}
85
86 \wxheading{Remarks}
87
88 For Motif, MWM (the Motif Window Manager) should be running for any window styles to work
89 (otherwise all styles take effect).
90
91 \wxheading{See also}
92
93 \helpref{wxFrame::Create}{wxframecreate}
94
95 \membersection{wxFrame::\destruct{wxFrame}}
96
97 \func{void}{\destruct{wxFrame}}{\void}
98
99 Destructor. Destroys all child windows and menu bar if present.
100
101 \membersection{wxFrame::Centre}\label{wxframecentre}
102
103 \func{void}{Centre}{\param{int}{ direction = wxBOTH}}
104
105 Centres the frame on the display.
106
107 \wxheading{Parameters}
108
109 \docparam{direction}{The parameter may be {\tt wxHORIZONTAL}, {\tt wxVERTICAL} or {\tt wxBOTH}.}
110
111 \membersection{wxFrame::Command}\label{wxframecommand}
112
113 \func{void}{Command}{\param{int }{id}}
114
115 Simulate a menu command.
116
117 \wxheading{Parameters}
118
119 \docparam{id}{The identifier for a menu item.}
120
121 \membersection{wxFrame::Create}\label{wxframecreate}
122
123 \func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID }{id},\rtfsp
124 \param{const wxString\& }{title}, \param{const wxPoint\&}{ pos = wxDefaultPosition},\rtfsp
125 \param{const wxSize\&}{ size = wxDefaultSize}, \param{long}{ style = wxDEFAULT\_FRAME\_STYLE},\rtfsp
126 \param{const wxString\& }{name = ``frame"}}
127
128 Used in two-step frame construction. See \helpref{wxFrame::wxFrame}{wxframeconstr}\rtfsp
129 for further details.
130
131 \membersection{wxFrame::CreateStatusBar}\label{wxframecreatestatusbar}
132
133 \func{virtual wxStatusBar*}{CreateStatusBar}{\param{int}{ number = 1},
134 \param{long}{ style = 0},
135 \param{wxWindowID}{ id = -1}, \param{const wxString\&}{ name = "statusBar"}}
136
137 Creates a status bar at the bottom of the frame.
138
139 \wxheading{Parameters}
140
141 \docparam{number}{The number of fields to create. Specify a
142 value greater than 1 to create a multi-field status bar.}
143
144 \docparam{style}{The status bar style. See \helpref{wxStatusBar}{wxstatusbar} for a list
145 of valid styles.}
146
147 \docparam{id}{The status bar window identifier. If -1, an identifier will be chosen by
148 wxWindows.}
149
150 \docparam{name}{The status bar window name.}
151
152 \wxheading{Return value}
153
154 A pointer to the the status bar if it was created successfully, NULL otherwise.
155
156 \wxheading{Remarks}
157
158 The width of the status bar is the whole width of the frame (adjusted automatically when
159 resizing), and the height and text size are chosen by the host windowing system.
160
161 By default, the status bar is an instance of wxStatusBar. To use a different class,
162 override \helpref{wxFrame::OnCreateStatusBar}{wxframeoncreatestatusbar}.
163
164 Note that you can put controls and other windows on the status bar if you wish.
165
166 \wxheading{See also}
167
168 \helpref{wxFrame::SetStatusText}{wxframesetstatustext},\rtfsp
169 \helpref{wxFrame::OnCreateStatusBar}{wxframeoncreatestatusbar},\rtfsp
170 \helpref{wxFrame::GetStatusBar}{wxframegetstatusbar}
171
172 \membersection{wxFrame::CreateToolBar}\label{wxframecreatetoolbar}
173
174 \func{virtual wxToolBar*}{CreateToolBar}{\param{long}{ style = wxNO\_BORDER \pipe wxTB\_HORIZONTAL},
175 \param{wxWindowID}{ id = -1}, \param{const wxString\&}{ name = "toolBar"}}
176
177 Creates a toolbar at the top or left of the frame.
178
179 \wxheading{Parameters}
180
181 \docparam{style}{The toolbar style. See \helpref{wxToolBar}{wxtoolbar} for a list
182 of valid styles.}
183
184 \docparam{id}{The toolbar window identifier. If -1, an identifier will be chosen by
185 wxWindows.}
186
187 \docparam{name}{The toolbar window name.}
188
189 \wxheading{Return value}
190
191 A pointer to the the toolbar if it was created successfully, NULL otherwise.
192
193 \wxheading{Remarks}
194
195 By default, the toolbar is an instance of wxToolBar (which is defined to be
196 a suitable toolbar class on each platform, such as wxToolBar95). To use a different class,
197 override \helpref{wxFrame::OnCreateToolBar}{wxframeoncreatetoolbar}.
198
199 When a toolbar has been created with this function, or made known to the frame
200 with \helpref{wxFrame::SetToolBar}{wxframesettoolbar}, the frame will manage the toolbar
201 position and adjust the return value from \helpref{wxWindow::GetClientSize}{wxwindowgetclientsize} to
202 reflect the available space for application windows.
203
204 \wxheading{See also}
205
206 \helpref{wxFrame::CreateStatusBar}{wxframecreatestatusbar},\rtfsp
207 \helpref{wxFrame::OnCreateToolBar}{wxframeoncreatetoolbar},\rtfsp
208 \helpref{wxFrame::SetToolBar}{wxframesettoolbar},\rtfsp
209 \helpref{wxFrame::GetToolBar}{wxframegettoolbar}
210
211 \membersection{wxFrame::GetMenuBar}\label{wxframegetmenubar}
212
213 \constfunc{wxMenuBar*}{GetMenuBar}{\void}
214
215 Returns a pointer to the menubar currently associated with the frame (if any).
216
217 \wxheading{See also}
218
219 \helpref{wxFrame::SetMenuBar}{wxframesetmenubar}, \helpref{wxMenuBar}{wxmenubar}, \helpref{wxMenu}{wxmenu}
220
221 \membersection{wxFrame::GetStatusBar}\label{wxframegetstatusbar}
222
223 \func{wxStatusBar*}{GetStatusBar}{\void}
224
225 Returns a pointer to the status bar currently associated with the frame (if any).
226
227 \wxheading{See also}
228
229 \helpref{wxFrame::CreateStatusBar}{wxframecreatestatusbar}, \helpref{wxStatusBar}{wxstatusbar}
230
231 \membersection{wxFrame::GetTitle}\label{wxframegettitle}
232
233 \func{wxString\&}{GetTitle}{\void}
234
235 Gets a temporary pointer to the frame title. See
236 \helpref{wxFrame::SetTitle}{wxframesettitle}.
237
238 \membersection{wxFrame::GetToolBar}\label{wxframegettoolbar}
239
240 \func{wxToolBar*}{GetToolBar}{\void}
241
242 Returns a pointer to the toolbar currently associated with the frame (if any).
243
244 \wxheading{See also}
245
246 \helpref{wxFrame::CreateToolBar}{wxframecreatetoolbar}, \helpref{wxToolBar}{wxtoolbar},\rtfsp
247 \helpref{wxFrame::SetToolBar}{wxframesettoolbar}
248
249 \membersection{wxFrame::Iconize}\label{wxframeiconize}
250
251 \func{void}{Iconize}{\param{const bool}{ iconize}}
252
253 Iconizes or restores the frame.
254
255 \wxheading{Parameters}
256
257 \docparam{izonize}{If TRUE, iconizes the frame; if FALSE, shows and restores it.}
258
259 \wxheading{See also}
260
261 \helpref{wxFrame::IsIconized}{wxframeisiconized}, \helpref{wxFrame::Maximize}{wxframemaximize}.
262
263 \membersection{wxFrame::IsIconized}\label{wxframeisiconized}
264
265 \constfunc{bool}{IsIconized}{\void}
266
267 Returns TRUE if the frame is iconized.
268
269 \membersection{wxFrame::IsMaximized}\label{wxframeismaximized}
270
271 \constfunc{bool}{IsMaximized}{\void}
272
273 Returns TRUE if the frame is maximized.
274
275 \membersection{wxFrame::LoadAccelerators}\label{wxframeloadaccelerators}
276
277 \func{void}{LoadAccelerators}{\param{const wxString\& }{table}}
278
279 Loads a keyboard accelerator table for this frame.
280
281 \wxheading{Parameters}
282
283 \docparam{table}{Accelerator table to load.}
284
285 \wxheading{Return value}
286
287 TRUE if the operation was successful, FALSE otherwise.
288
289 \wxheading{Remarks}
290
291 Accelerator tables map keystrokes onto control and menu identifiers, so the
292 programmer does not have to explicitly program this correspondence.
293
294 See the hello demo ({\tt hello.cpp} and {\tt hello.rc}) for
295 an example of accelerator usage. This is a fragment from {\tt hello.rc}:
296
297 \begin{verbatim}
298 #define HELLO_LOAD_FILE 111
299
300 menus_accel ACCELERATORS
301 {
302
303 "^L", HELLO_LOAD_FILE
304
305 }
306 \end{verbatim}
307
308 This function only works under Windows.
309
310 % huh? If you call LoadAccelerators, you need to override wxFrame::OnActivate to do nothing.
311
312 \membersection{wxFrame::Maximize}\label{wxframemaximize}
313
314 \func{void}{Maximize}{\param{const bool }{maximize}}
315
316 Maximizes or restores the frame.
317
318 \wxheading{Parameters}
319
320 \docparam{maximize}{If TRUE, maximizes the frame, otherwise it restores it}.
321
322 \wxheading{Remarks}
323
324 This function only works under Windows.
325
326 \wxheading{See also}
327
328 \helpref{wxFrame::Iconize}{wxframeiconize}
329
330 \membersection{wxFrame::OnActivate}
331
332 \func{void}{OnActivate}{\param{bool}{ active}}
333
334 Called when a window is activated or deactivated (MS Windows
335 only). If the window is being activated, {\it active} is TRUE, else it
336 is FALSE.
337
338 If you call wxFrame::LoadAccelerators, you need to override this function e.g.
339
340 \begin{verbatim}
341 void OnActivate(bool) {};
342 \end{verbatim}
343
344 \membersection{wxFrame::OnCreateStatusBar}\label{wxframeoncreatestatusbar}
345
346 \func{virtual wxStatusBar*}{OnCreateStatusBar}{\param{int }{number}
347 \param{long}{ style},
348 \param{wxWindowID}{ id}, \param{const wxString\&}{ name}}
349
350 Virtual function called when a status bar is requested by \helpref{wxFrame::CreateStatusBar}{wxframecreatestatusbar}.
351
352 \wxheading{Parameters}
353
354 \docparam{number}{The number of fields to create.}
355
356 \docparam{style}{The window style. See \helpref{wxStatusBar}{wxstatusbar} for a list
357 of valid styles.}
358
359 \docparam{id}{The window identifier. If -1, an identifier will be chosen by
360 wxWindows.}
361
362 \docparam{name}{The window name.}
363
364 \wxheading{Return value}
365
366 A status bar object.
367
368 \wxheading{Remarks}
369
370 An application can override this function to return a different kind of status bar. The default
371 implementation returns an instance of \helpref{wxStatusBar}{wxstatusbar}.
372
373 \wxheading{See also}
374
375 \helpref{wxFrame::CreateStatusBar}{wxframecreatestatusbar}, \helpref{wxStatusBar}{wxstatusbar}.
376
377 \membersection{wxFrame::OnCreateToolBar}\label{wxframeoncreatetoolbar}
378
379 \func{virtual wxToolBar*}{OnCreateToolBar}{\param{long}{ style},
380 \param{wxWindowID}{ id}, \param{const wxString\&}{ name}}
381
382 Virtual function called when a toolbar is requested by \helpref{wxFrame::CreateToolBar}{wxframecreatetoolbar}.
383
384 \wxheading{Parameters}
385
386 \docparam{style}{The toolbar style. See \helpref{wxToolBar}{wxtoolbar} for a list
387 of valid styles.}
388
389 \docparam{id}{The toolbar window identifier. If -1, an identifier will be chosen by
390 wxWindows.}
391
392 \docparam{name}{The toolbar window name.}
393
394 \wxheading{Return value}
395
396 A toolbar object.
397
398 \wxheading{Remarks}
399
400 An application can override this function to return a different kind of toolbar. The default
401 implementation returns an instance of \helpref{wxToolBar}{wxtoolbar}.
402
403 \wxheading{See also}
404
405 \helpref{wxFrame::CreateToolBar}{wxframecreatetoolbar}, \helpref{wxToolBar}{wxtoolbar}.
406
407 \membersection{wxFrame::OnMenuCommand}\label{wxframeonmenucommand}
408
409 \func{void}{OnMenuCommand}{\param{wxCommandEvent\&}{ event}}
410
411 See \helpref{wxWindow::OnMenuCommand}{wxwindowonmenucommand}.
412
413 \membersection{wxFrame::OnMenuHighlight}\label{wxframeonmenuhighlight}
414
415 \func{void}{OnMenuHighlight}{\param{wxMenuEvent\&}{ event}}
416
417 See \helpref{wxWindow::OnMenuHighlight}{wxwindowonmenuhighlight}.
418
419 \membersection{wxFrame::OnSize}\label{wxframeonsize}
420
421 \func{void}{OnSize}{\param{wxSizeEvent\& }{event}}
422
423 See \helpref{wxWindow::OnSize}{wxwindowonsize}.
424
425 The default {\bf wxFrame::OnSize} implementation looks for a single subwindow,
426 and if one is found, resizes it to fit
427 inside the frame. Override this member if more complex behaviour
428 is required (for example, if there are several subwindows).
429
430 \membersection{wxFrame::SetIcon}\label{wxframeseticon}
431
432 \func{void}{SetIcon}{\param{const wxIcon\& }{icon}}
433
434 Sets the icon for this frame.
435
436 \wxheading{Parameters}
437
438 \docparam{icon}{The icon to associate with this frame.}
439
440 \wxheading{Remarks}
441
442 The frame takes a `copy' of {\it icon}, but since it uses reference
443 counting, the copy is very quick. It is safe to delete {\it icon} after
444 calling this function.
445
446 Under Windows, instead of using {\bf SetIcon}, you can add the
447 following lines to your MS Windows resource file:
448
449 \begin{verbatim}
450 wxSTD_MDIPARENTFRAME ICON icon1.ico
451 wxSTD_MDICHILDFRAME ICON icon2.ico
452 wxSTD_FRAME ICON icon3.ico
453 \end{verbatim}
454
455 where icon1.ico will be used for the MDI parent frame, icon2.ico
456 will be used for MDI child frames, and icon3.ico will be used for
457 non-MDI frames.
458
459 If these icons are not supplied, and {\bf SetIcon} is not called either,
460 then the following defaults apply if you have included wx.rc.
461
462 \begin{verbatim}
463 wxDEFAULT_FRAME ICON std.ico
464 wxDEFAULT_MDIPARENTFRAME ICON mdi.ico
465 wxDEFAULT_MDICHILDFRAME ICON child.ico
466 \end{verbatim}
467
468 You can replace std.ico, mdi.ico and child.ico with your own defaults
469 for all your wxWindows application. Currently they show the same icon.
470
471 {\it Note:} a wxWindows application linked with subsystem equal to 4.0
472 (i.e. marked as a Windows 95 application) doesn't respond properly
473 to wxFrame::SetIcon. To work around this until a solution is found,
474 mark your program as a 3.5 application. This will also ensure
475 that Windows provides small icons for the application automatically.
476
477 See also \helpref{wxIcon}{wxicon}.
478
479 \membersection{wxFrame::SetMenuBar}\label{wxframesetmenubar}
480
481 \func{void}{SetMenuBar}{\param{wxMenuBar* }{menuBar}}
482
483 Tells the frame to show the given menu bar.
484
485 \wxheading{Parameters}
486
487 \docparam{menuBar}{The menu bar to associate with the frame.}
488
489 \wxheading{Remarks}
490
491 If the frame is destroyed, the
492 menu bar and its menus will be destroyed also, so do not delete the menu
493 bar explicitly (except by resetting the frame's menu bar to another
494 frame or NULL).
495
496 Under Windows, a call to \helpref{wxFrame::OnSize}{wxframeonsize} is generated, so be sure to initialize
497 data members properly before calling {\bf SetMenuBar}.
498
499 Note that it is not possible to call this function twice for the same frame object.
500
501 \wxheading{See also}
502
503 \helpref{wxFrame::GetMenuBar}{wxframegetmenubar}, \helpref{wxMenuBar}{wxmenubar}, \helpref{wxMenu}{wxmenu}.
504
505 \membersection{wxFrame::SetStatusBar}\label{wxframesetstatusbar}
506
507 \func{void}{SetStatusBar}{\param{wxStatusBar*}{ statusBar}}
508
509 Associates a status bar with the frame.
510
511 \wxheading{See also}
512
513 \helpref{wxFrame::CreateStatusBar}{wxframecreatestatusbar}, \helpref{wxStatusBar}{wxstatusbar},\rtfsp
514 \helpref{wxFrame::GetStatusBar}{wxframegetstatusbar}
515
516 \membersection{wxFrame::SetStatusText}\label{wxframesetstatustext}
517
518 \func{virtual void}{SetStatusText}{\param{const wxString\& }{ text}, \param{int}{ number = 0}}
519
520 Sets the status bar text and redraws the status bar.
521
522 \wxheading{Parameters}
523
524 \docparam{text}{The text for the status field.}
525
526 \docparam{number}{The status field (starting from zero).}
527
528 \wxheading{Remarks}
529
530 Use an empty string to clear the status bar.
531
532 \wxheading{See also}
533
534 \helpref{wxFrame::CreateStatusBar}{wxframecreatestatusbar}, \helpref{wxStatusBar}{wxstatusbar}
535
536 \membersection{wxFrame::SetStatusWidths}\label{wxframesetstatuswidths}
537
538 \func{virtual void}{SetStatusWidths}{\param{int}{ n}, \param{int *}{widths}}
539
540 Sets the widths of the fields in the status bar.
541
542 \wxheading{Parameters}
543
544 \wxheading{n}{The number of fields in the status bar. It must be the
545 same used in \helpref{CreateStatusBar}{wxframecreatestatusbar}.}
546
547 \docparam{widths}{Must contain an array of {\it n} integers, each of which is a status field width
548 in pixels. A value of -1 indicates that the field is variable width; at least one
549 field must be -1. You should delete this array after calling {\bf SetStatusWidths}.}
550
551 \wxheading{Remarks}
552
553 The widths of the variable fields are calculated from the total width of all fields,
554 minus the sum of widths of the non-variable fields, divided by the number of
555 variable fields.
556
557 \membersection{wxFrame::SetToolBar}\label{wxframesettoolbar}
558
559 \func{void}{SetToolBar}{\param{wxToolBar*}{ toolBar}}
560
561 Associates a toolbar with the frame.
562
563 \wxheading{See also}
564
565 \helpref{wxFrame::CreateToolBar}{wxframecreatetoolbar}, \helpref{wxToolBar}{wxtoolbar},\rtfsp
566 \helpref{wxFrame::GetToolBar}{wxframegettoolbar}
567
568 \membersection{wxFrame::SetTitle}\label{wxframesettitle}
569
570 \func{virtual void}{SetTitle}{\param{const wxString\& }{ title}}
571
572 Sets the frame title.
573
574 \wxheading{Parameters}
575
576 \docparam{title}{The frame title.}
577
578 \wxheading{See also}
579
580 \helpref{wxFrame::GetTitle}{wxframegettitle}
581