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