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