]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/dialog.tex
* Implemented BestSize cache
[wxWidgets.git] / docs / latex / wx / dialog.tex
1 \section{\class{wxDialog}}\label{wxdialog}
2
3 A dialog box is a window with a title bar and sometimes a system menu, which
4 can be moved around the screen. It can contain controls and other windows and
5 is usually used to allow the user to make some choice or to answer a question.
6
7 \wxheading{Derived from}
8
9 \helpref{wxWindow}{wxwindow}\\
10 \helpref{wxEvtHandler}{wxevthandler}\\
11 \helpref{wxObject}{wxobject}
12
13 \wxheading{Include files}
14
15 <wx/dialog.h>
16
17 \wxheading{Remarks}
18
19 There are two kinds of dialog -- {\it modal}\ and {\it modeless}. A modal dialog
20 blocks program flow and user input on other windows until it is dismissed,
21 whereas a modeless dialog behaves more like a frame in that program flow
22 continues, and input in other windows is still possible. To show a modal dialog
23 you should use the \helpref{ShowModal}{wxdialogshowmodal} method while to show
24 a dialog modelessly you simply use \helpref{Show}{wxdialogshow}, just as with
25 frames.
26
27 Note that the modal dialog is one of the very few examples of
28 wxWindow-derived objects which may be created on the stack and not on the heap.
29 In other words, although this code snippet:
30
31 \begin{verbatim}
32 void AskUser()
33 {
34 MyAskDialog *dlg = new MyAskDialog(...);
35 if ( dlg->ShowModal() == wxID_OK )
36 ...
37 //else: dialog was cancelled or some another button pressed
38
39 dlg->Destroy();
40 }
41 \end{verbatim}
42
43 works, you can also achieve the same result by using a simpler code fragment
44 below:
45
46 \begin{verbatim}
47 void AskUser()
48 {
49 MyAskDialog dlg(...);
50 if ( dlg.ShowModal() == wxID_OK )
51 ...
52
53 // no need to call Destroy() here
54 }
55 \end{verbatim}
56
57 An application can define an \helpref{wxCloseEvent}{wxcloseevent} handler for
58 the dialog to respond to system close events.
59
60 \wxheading{Window styles}
61
62 \twocolwidtha{5cm}
63 \begin{twocollist}\itemsep=0pt
64 \twocolitem{\windowstyle{wxCAPTION}}{Puts a caption on the dialog box.}
65 \twocolitem{\windowstyle{wxDEFAULT\_DIALOG\_STYLE}}{Equivalent to a combination of wxCAPTION, wxCLOSE\_BOX and wxSYSTEM\_MENU (the last one is not used under Unix)}
66 \twocolitem{\windowstyle{wxRESIZE\_BORDER}}{Display a resizeable frame around the window.}
67 \twocolitem{\windowstyle{wxSYSTEM\_MENU}}{Display a system menu.}
68 \twocolitem{\windowstyle{wxCLOSE\_BOX}}{Displays a close box on the frame.}
69 \twocolitem{\windowstyle{wxMAXIMIZE\_BOX}}{Displays a maximize box on the dialog.}
70 \twocolitem{\windowstyle{wxMINIMIZE\_BOX}}{Displays a minimize box on the dialog.}
71 \twocolitem{\windowstyle{wxTHICK\_FRAME}}{Display a thick frame around the window.}
72 \twocolitem{\windowstyle{wxSTAY\_ON\_TOP}}{The dialog stays on top of all other windows (Windows only).}
73 \twocolitem{\windowstyle{wxNO\_3D}}{Under Windows, specifies that the child controls
74 should not have 3D borders unless specified in the control.}
75 \twocolitem{\windowstyle{wxDIALOG\_NO\_PARENT}}{By default, a dialog created
76 with a {\tt NULL} parent window will be given the
77 \helpref{application's top level window}{wxappgettopwindow} as parent. Use this
78 style to prevent this from happening and create an orphan dialog. This is not recommended for modal dialogs.}
79 \twocolitem{\windowstyle{wxDIALOG\_EX\_CONTEXTHELP}}{Under Windows, puts a query button on the
80 caption. When pressed, Windows will go into a context-sensitive help mode and wxWidgets will send
81 a wxEVT\_HELP event if the user clicked on an application window. {\it Note}\ that this is an extended
82 style and must be set by calling \helpref{SetExtraStyle}{wxwindowsetextrastyle} before Create is called (two-step construction).}
83 \end{twocollist}
84
85 Under Unix or Linux, MWM (the Motif Window Manager) or other window managers
86 recognizing the MHM hints should be running for any of these styles to have an
87 effect.
88
89 See also \helpref{Generic window styles}{windowstyles}.
90
91 \wxheading{See also}
92
93 \helpref{wxDialog overview}{wxdialogoverview}, \helpref{wxFrame}{wxframe},\rtfsp
94 \helpref{Validator overview}{validatoroverview}
95
96 \latexignore{\rtfignore{\wxheading{Members}}}
97
98 \membersection{wxDialog::wxDialog}\label{wxdialogconstr}
99
100 \func{}{wxDialog}{\void}
101
102 Default constructor.
103
104 \func{}{wxDialog}{\param{wxWindow* }{parent}, \param{wxWindowID }{id},\rtfsp
105 \param{const wxString\& }{title},\rtfsp
106 \param{const wxPoint\& }{pos = wxDefaultPosition},\rtfsp
107 \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
108 \param{long}{ style = wxDEFAULT\_DIALOG\_STYLE},\rtfsp
109 \param{const wxString\& }{name = ``dialogBox"}}
110
111 Constructor.
112
113 \wxheading{Parameters}
114
115 \docparam{parent}{Can be NULL, a frame or another dialog box.}
116
117 \docparam{id}{An identifier for the dialog. A value of -1 is taken to mean a default.}
118
119 \docparam{title}{The title of the dialog.}
120
121 \docparam{pos}{The dialog position. A value of (-1, -1) indicates a default position, chosen by
122 either the windowing system or wxWidgets, depending on platform.}
123
124 \docparam{size}{The dialog size. A value of (-1, -1) indicates a default size, chosen by
125 either the windowing system or wxWidgets, depending on platform.}
126
127 \docparam{style}{The window style. See \helpref{wxDialog}{wxdialog}.}
128
129 \docparam{name}{Used to associate a name with the window,
130 allowing the application user to set Motif resource values for
131 individual dialog boxes.}
132
133 \wxheading{See also}
134
135 \helpref{wxDialog::Create}{wxdialogcreate}
136
137 \membersection{wxDialog::\destruct{wxDialog}}
138
139 \func{}{\destruct{wxDialog}}{\void}
140
141 Destructor. Deletes any child windows before deleting the physical window.
142
143 \membersection{wxDialog::Centre}\label{wxdialogcentre}
144
145 \func{void}{Centre}{\param{int}{ direction = wxBOTH}}
146
147 Centres the dialog box on the display.
148
149 \wxheading{Parameters}
150
151 \docparam{direction}{May be {\tt wxHORIZONTAL}, {\tt wxVERTICAL} or {\tt wxBOTH}.}
152
153 \membersection{wxDialog::Create}\label{wxdialogcreate}
154
155 \func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID }{id},\rtfsp
156 \param{const wxString\& }{title},\rtfsp
157 \param{const wxPoint\& }{pos = wxDefaultPosition},\rtfsp
158 \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
159 \param{long}{ style = wxDEFAULT\_DIALOG\_STYLE},\rtfsp
160 \param{const wxString\& }{name = ``dialogBox"}}
161
162 Used for two-step dialog box construction. See \helpref{wxDialog::wxDialog}{wxdialogconstr}\rtfsp
163 for details.
164
165 \membersection{wxDialog::EndModal}\label{wxdialogendmodal}
166
167 \func{void}{EndModal}{\param{int }{retCode}}
168
169 Ends a modal dialog, passing a value to be returned from the \helpref{wxDialog::ShowModal}{wxdialogshowmodal}\rtfsp
170 invocation.
171
172 \wxheading{Parameters}
173
174 \docparam{retCode}{The value that should be returned by {\bf ShowModal}.}
175
176 \wxheading{See also}
177
178 \helpref{wxDialog::ShowModal}{wxdialogshowmodal},\rtfsp
179 \helpref{wxDialog::GetReturnCode}{wxdialoggetreturncode},\rtfsp
180 \helpref{wxDialog::SetReturnCode}{wxdialogsetreturncode}
181
182 \membersection{wxDialog::GetReturnCode}\label{wxdialoggetreturncode}
183
184 \func{int}{GetReturnCode}{\void}
185
186 Gets the return code for this window.
187
188 \wxheading{Remarks}
189
190 A return code is normally associated with a modal dialog, where \helpref{wxDialog::ShowModal}{wxdialogshowmodal} returns
191 a code to the application.
192
193 \wxheading{See also}
194
195 \helpref{wxDialog::SetReturnCode}{wxdialogsetreturncode}, \helpref{wxDialog::ShowModal}{wxdialogshowmodal},\rtfsp
196 \helpref{wxDialog::EndModal}{wxdialogendmodal}
197
198 \membersection{wxDialog::GetTitle}\label{wxdialoggettitle}
199
200 \constfunc{wxString}{GetTitle}{\void}
201
202 Returns the title of the dialog box.
203
204 \membersection{wxDialog::Iconize}\label{wxdialogiconized}
205
206 \func{void}{Iconize}{\param{const bool}{ iconize}}
207
208 Iconizes or restores the dialog. Windows only.
209
210 \wxheading{Parameters}
211
212 \docparam{iconize}{If true, iconizes the dialog box; if false, shows and restores it.}
213
214 \wxheading{Remarks}
215
216 Note that in Windows, iconization has no effect since dialog boxes cannot be
217 iconized. However, applications may need to explicitly restore dialog
218 boxes under Motif which have user-iconizable frames, and under Windows
219 calling {\tt Iconize(false)} will bring the window to the front, as does
220 \rtfsp{\tt Show(true)}.
221
222 \membersection{wxDialog::IsIconized}\label{wxdialogisiconized}
223
224 \constfunc{bool}{IsIconized}{\void}
225
226 Returns true if the dialog box is iconized. Windows only.
227
228 \wxheading{Remarks}
229
230 Always returns false under Windows since dialogs cannot be iconized.
231
232 \membersection{wxDialog::IsModal}\label{wxdialogismodal}
233
234 \constfunc{bool}{IsModal}{\void}
235
236 Returns true if the dialog box is modal, false otherwise.
237
238 \membersection{wxDialog::OnCharHook}\label{wxdialogoncharhook}
239
240 \func{void}{OnCharHook}{\param{wxKeyEvent\&}{ event}}
241
242 This member is called to allow the window to intercept keyboard events
243 before they are processed by child windows.
244
245 %For more information, see \helpref{wxWindow::OnCharHook}{wxwindowoncharhook}
246
247 \wxheading{Remarks}
248
249 wxDialog implements this handler to fake a cancel command if the escape key has been
250 pressed. This will dismiss the dialog.
251
252 \membersection{wxDialog::OnApply}\label{wxdialogonapply}
253
254 \func{void}{OnApply}{\param{wxCommandEvent\& }{event}}
255
256 The default handler for the wxID\_APPLY identifier.
257
258 \wxheading{Remarks}
259
260 This function calls \helpref{wxWindow::Validate}{wxwindowvalidate} and \helpref{wxWindow::TransferDataToWindow}{wxwindowtransferdatatowindow}.
261
262 \wxheading{See also}
263
264 \helpref{wxDialog::OnOK}{wxdialogonok}, \helpref{wxDialog::OnCancel}{wxdialogoncancel}
265
266 \membersection{wxDialog::OnCancel}\label{wxdialogoncancel}
267
268 \func{void}{OnCancel}{\param{wxCommandEvent\& }{event}}
269
270 The default handler for the wxID\_CANCEL identifier.
271
272 \wxheading{Remarks}
273
274 The function either calls {\bf EndModal(wxID\_CANCEL)} if the dialog is modal, or
275 sets the return value to wxID\_CANCEL and calls {\bf Show(false)} if the dialog is modeless.
276
277 \wxheading{See also}
278
279 \helpref{wxDialog::OnOK}{wxdialogonok}, \helpref{wxDialog::OnApply}{wxdialogonapply}
280
281 \membersection{wxDialog::OnOK}\label{wxdialogonok}
282
283 \func{void}{OnOK}{\param{wxCommandEvent\& }{event}}
284
285 The default handler for the wxID\_OK identifier.
286
287 \wxheading{Remarks}
288
289 The function calls
290 \rtfsp\helpref{wxWindow::Validate}{wxwindowvalidate}, then \helpref{wxWindow::TransferDataFromWindow}{wxwindowtransferdatafromwindow}.
291 If this returns true, the function either calls {\bf EndModal(wxID\_OK)} if the dialog is modal, or
292 sets the return value to wxID\_OK and calls {\bf Show(false)} if the dialog is modeless.
293
294 \wxheading{See also}
295
296 \helpref{wxDialog::OnCancel}{wxdialogoncancel}, \helpref{wxDialog::OnApply}{wxdialogonapply}
297
298 \membersection{wxDialog::OnSysColourChanged}\label{wxdialogonsyscolourchanged}
299
300 \func{void}{OnSysColourChanged}{\param{wxSysColourChangedEvent\& }{event}}
301
302 The default handler for wxEVT\_SYS\_COLOUR\_CHANGED.
303
304 \wxheading{Parameters}
305
306 \docparam{event}{The colour change event.}
307
308 \wxheading{Remarks}
309
310 Changes the dialog's colour to conform to the current settings (Windows only).
311 Add an event table entry for your dialog class if you wish the behaviour
312 to be different (such as keeping a user-defined
313 background colour). If you do override this function, call wxEvent::Skip to
314 propagate the notification to child windows and controls.
315
316 \wxheading{See also}
317
318 \helpref{wxSysColourChangedEvent}{wxsyscolourchangedevent}
319
320 \membersection{wxDialog::SetIcon}\label{wxdialogseticon}
321
322 \func{void}{SetIcon}{\param{const wxIcon\& }{icon}}
323
324 Sets the icon for this dialog.
325
326 \wxheading{Parameters}
327
328 \docparam{icon}{The icon to associate with this dialog.}
329
330 See also \helpref{wxIcon}{wxicon}.
331
332 \membersection{wxDialog::SetIcons}\label{wxdialogseticons}
333
334 \func{void}{SetIcons}{\param{const wxIconBundle\& }{icons}}
335
336 Sets the icons for this dialog.
337
338 \wxheading{Parameters}
339
340 \docparam{icons}{The icons to associate with this dialog.}
341
342 See also \helpref{wxIconBundle}{wxiconbundle}.
343
344 \membersection{wxDialog::SetModal}\label{wxdialogsetmodal}
345
346 \func{void}{SetModal}{\param{const bool}{ flag}}
347
348 {\bf NB:} This function is deprecated and doesn't work for all ports, just use
349 \helpref{ShowModal}{wxdialogshowmodal} to show a modal dialog instead.
350
351 Allows the programmer to specify whether the dialog box is modal (wxDialog::Show blocks control
352 until the dialog is hidden) or modeless (control returns immediately).
353
354 \wxheading{Parameters}
355
356 \docparam{flag}{If true, the dialog will be modal, otherwise it will be modeless.}
357
358 \membersection{wxDialog::SetReturnCode}\label{wxdialogsetreturncode}
359
360 \func{void}{SetReturnCode}{\param{int }{retCode}}
361
362 Sets the return code for this window.
363
364 \wxheading{Parameters}
365
366 \docparam{retCode}{The integer return code, usually a control identifier.}
367
368 \wxheading{Remarks}
369
370 A return code is normally associated with a modal dialog, where \helpref{wxDialog::ShowModal}{wxdialogshowmodal} returns
371 a code to the application. The function \helpref{wxDialog::EndModal}{wxdialogendmodal} calls {\bf SetReturnCode}.
372
373 \wxheading{See also}
374
375 \helpref{wxDialog::GetReturnCode}{wxdialoggetreturncode}, \helpref{wxDialog::ShowModal}{wxdialogshowmodal},\rtfsp
376 \helpref{wxDialog::EndModal}{wxdialogendmodal}
377
378 \membersection{wxDialog::SetTitle}\label{wxdialogsettitle}
379
380 \func{void}{SetTitle}{\param{const wxString\& }{ title}}
381
382 Sets the title of the dialog box.
383
384 \wxheading{Parameters}
385
386 \docparam{title}{The dialog box title.}
387
388 \membersection{wxDialog::Show}\label{wxdialogshow}
389
390 \func{bool}{Show}{\param{const bool}{ show}}
391
392 Hides or shows the dialog.
393
394 \wxheading{Parameters}
395
396 \docparam{show}{If true, the dialog box is shown and brought to the front;
397 otherwise the box is hidden. If false and the dialog is
398 modal, control is returned to the calling program.}
399
400 \wxheading{Remarks}
401
402 The preferred way of dismissing a modal dialog is to use \helpref{wxDialog::EndModal}{wxdialogendmodal}.
403
404 \membersection{wxDialog::ShowModal}\label{wxdialogshowmodal}
405
406 \func{int}{ShowModal}{\void}
407
408 Shows a modal dialog. Program flow does not return until the dialog has been dismissed with\rtfsp
409 \helpref{wxDialog::EndModal}{wxdialogendmodal}.
410
411 \wxheading{Return value}
412
413 The return value is the value set with \helpref{wxDialog::SetReturnCode}{wxdialogsetreturncode}.
414
415 \wxheading{See also}
416
417 \helpref{wxDialog::EndModal}{wxdialogendmodal},\rtfsp
418 \helpref{wxDialog:GetReturnCode}{wxdialoggetreturncode},\rtfsp
419 \helpref{wxDialog::SetReturnCode}{wxdialogsetreturncode}
420