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