]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/dialog.tex
Apply Mart R.'s patch for improved font width
[wxWidgets.git] / docs / latex / wx / dialog.tex
CommitLineData
a660d684
KB
1\section{\class{wxDialog}}\label{wxdialog}
2
1e4709b3
VZ
3A dialog box is a window with a title bar and sometimes a system menu, which
4can be moved around the screen. It can contain controls and other windows and
5is usually used to allow the user to make some choice or to answer a question.
a660d684
KB
6
7\wxheading{Derived from}
8
834ed994 9\helpref{wxTopLevelWindow}{wxtoplevelwindow}\\
a660d684
KB
10\helpref{wxWindow}{wxwindow}\\
11\helpref{wxEvtHandler}{wxevthandler}\\
12\helpref{wxObject}{wxobject}
13
954b8ae6
JS
14\wxheading{Include files}
15
16<wx/dialog.h>
17
a660d684
KB
18\wxheading{Remarks}
19
1e4709b3
VZ
20There are two kinds of dialog -- {\it modal}\ and {\it modeless}. A modal dialog
21blocks program flow and user input on other windows until it is dismissed,
22whereas a modeless dialog behaves more like a frame in that program flow
0032ddbb
JS
23continues, and input in other windows is still possible. To show a modal dialog
24you should use the \helpref{ShowModal}{wxdialogshowmodal} method while to show
25a dialog modelessly you simply use \helpref{Show}{wxdialogshow}, just as with
1e4709b3 26frames.
a660d684 27
0032ddbb 28Note that the modal dialog is one of the very few examples of
1e4709b3 29wxWindow-derived objects which may be created on the stack and not on the heap.
d2c2afc9
JS
30In other words, although this code snippet:
31
1e4709b3
VZ
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
a660d684 39
1e4709b3
VZ
40 dlg->Destroy();
41 }
42\end{verbatim}
d2c2afc9 43
1e4709b3
VZ
44works, you can also achieve the same result by using a simpler code fragment
45below:
d2c2afc9 46
1e4709b3
VZ
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
3980000c 58An application can define a \helpref{wxCloseEvent}{wxcloseevent} handler for
1e4709b3 59the dialog to respond to system close events.
a660d684
KB
60
61\wxheading{Window styles}
62
63\twocolwidtha{5cm}
64\begin{twocollist}\itemsep=0pt
f6bcfd97 65\twocolitem{\windowstyle{wxCAPTION}}{Puts a caption on the dialog box.}
850c6ed4 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)}
f6bcfd97 67\twocolitem{\windowstyle{wxRESIZE\_BORDER}}{Display a resizeable frame around the window.}
bbcdf8bc 68\twocolitem{\windowstyle{wxSYSTEM\_MENU}}{Display a system menu.}
850c6ed4 69\twocolitem{\windowstyle{wxCLOSE\_BOX}}{Displays a close box on the frame.}
0032ddbb
JS
70\twocolitem{\windowstyle{wxMAXIMIZE\_BOX}}{Displays a maximize box on the dialog.}
71\twocolitem{\windowstyle{wxMINIMIZE\_BOX}}{Displays a minimize box on the dialog.}
bbcdf8bc
JS
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).}
a660d684
KB
74\twocolitem{\windowstyle{wxNO\_3D}}{Under Windows, specifies that the child controls
75should not have 3D borders unless specified in the control.}
0032ddbb
JS
76\twocolitem{\windowstyle{wxDIALOG\_NO\_PARENT}}{By default, a dialog created
77with a {\tt NULL} parent window will be given the
78\helpref{application's top level window}{wxappgettopwindow} as parent. Use this
79style to prevent this from happening and create an orphan dialog. This is not recommended for modal dialogs.}
26a80c22 80\twocolitem{\windowstyle{wxDIALOG\_EX\_CONTEXTHELP}}{Under Windows, puts a query button on the
fc2171bd 81caption. When pressed, Windows will go into a context-sensitive help mode and wxWidgets will send
1e4709b3 82a wxEVT\_HELP event if the user clicked on an application window. {\it Note}\ that this is an extended
26a80c22 83style and must be set by calling \helpref{SetExtraStyle}{wxwindowsetextrastyle} before Create is called (two-step construction).}
03d77609 84\twocolitem{\windowstyle{wxDIALOG\_EX\_METAL}}{On Mac OS X, frames with this style will be shown with a metallic look. This is an {\it extra} style.}
a660d684
KB
85\end{twocollist}
86
b3daa5a3 87Under Unix or Linux, MWM (the Motif Window Manager) or other window managers
2edb0bde 88recognizing the MHM hints should be running for any of these styles to have an
b3daa5a3 89effect.
a660d684
KB
90
91See also \helpref{Generic window styles}{windowstyles}.
92
93\wxheading{See also}
94
965b4f87 95\helpref{wxDialog overview}{wxdialogoverview}, \helpref{wxFrame}{wxframe},\rtfsp
a660d684
KB
96\helpref{Validator overview}{validatoroverview}
97
98\latexignore{\rtfignore{\wxheading{Members}}}
99
b236c10f 100\membersection{wxDialog::wxDialog}\label{wxdialogctor}
a660d684
KB
101
102\func{}{wxDialog}{\void}
103
104Default constructor.
105
eaaa6a06 106\func{}{wxDialog}{\param{wxWindow* }{parent}, \param{wxWindowID }{id},\rtfsp
a660d684
KB
107\param{const wxString\& }{title},\rtfsp
108\param{const wxPoint\& }{pos = wxDefaultPosition},\rtfsp
109\param{const wxSize\& }{size = wxDefaultSize},\rtfsp
eaaa6a06 110\param{long}{ style = wxDEFAULT\_DIALOG\_STYLE},\rtfsp
a660d684
KB
111\param{const wxString\& }{name = ``dialogBox"}}
112
113Constructor.
114
115\wxheading{Parameters}
116
117\docparam{parent}{Can be NULL, a frame or another dialog box.}
118
119\docparam{id}{An identifier for the dialog. A value of -1 is taken to mean a default.}
120
121\docparam{title}{The title of the dialog.}
122
123\docparam{pos}{The dialog position. A value of (-1, -1) indicates a default position, chosen by
fc2171bd 124either the windowing system or wxWidgets, depending on platform.}
a660d684
KB
125
126\docparam{size}{The dialog size. A value of (-1, -1) indicates a default size, chosen by
fc2171bd 127either the windowing system or wxWidgets, depending on platform.}
a660d684
KB
128
129\docparam{style}{The window style. See \helpref{wxDialog}{wxdialog}.}
130
131\docparam{name}{Used to associate a name with the window,
132allowing the application user to set Motif resource values for
133individual dialog boxes.}
134
135\wxheading{See also}
136
137\helpref{wxDialog::Create}{wxdialogcreate}
138
b236c10f 139\membersection{wxDialog::\destruct{wxDialog}}\label{wxdialogdtor}
a660d684
KB
140
141\func{}{\destruct{wxDialog}}{\void}
142
143Destructor. Deletes any child windows before deleting the physical window.
144
145\membersection{wxDialog::Centre}\label{wxdialogcentre}
146
eaaa6a06 147\func{void}{Centre}{\param{int}{ direction = wxBOTH}}
a660d684
KB
148
149Centres the dialog box on the display.
150
151\wxheading{Parameters}
152
153\docparam{direction}{May be {\tt wxHORIZONTAL}, {\tt wxVERTICAL} or {\tt wxBOTH}.}
154
155\membersection{wxDialog::Create}\label{wxdialogcreate}
156
eaaa6a06 157\func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID }{id},\rtfsp
a660d684
KB
158\param{const wxString\& }{title},\rtfsp
159\param{const wxPoint\& }{pos = wxDefaultPosition},\rtfsp
160\param{const wxSize\& }{size = wxDefaultSize},\rtfsp
eaaa6a06 161\param{long}{ style = wxDEFAULT\_DIALOG\_STYLE},\rtfsp
a660d684
KB
162\param{const wxString\& }{name = ``dialogBox"}}
163
b236c10f 164Used for two-step dialog box construction. See \helpref{wxDialog::wxDialog}{wxdialogctor}\rtfsp
a660d684
KB
165for details.
166
67edd0c7
JS
167\membersection{wxDialog::CreateButtonSizer}\label{wxdialogcreatebuttonsizer}
168
169\func{wxSizer*}{CreateButtonSizer}{\param{long}{ flags}}
170
171Creates a sizer with standard buttons. {\it flags} is a bit list
172of the following flags: wxOK, wxCANCEL, wxYES, wxNO, wxHELP, wxNO\_DEFAULT.
173
174The sizer lays out the buttons in a manner appropriate to the platform.
175
176This function simply calls \helpref{CreateStdDialogButtonSizer}{wxdialogcreatestddialogbuttonsizer}.
177
178\membersection{wxDialog::CreateStdDialogButtonSizer}\label{wxdialogcreatestddialogbuttonsizer}
179
180\func{wxStdDialogButtonSizer*}{CreateStdDialogButtonSizer}{\param{long}{ flags}}
181
182Creates a \helpref{wxStdDialogButtonSizer}{wxstddialogbuttonsizer} with standard buttons. {\it flags} is a bit list
183of the following flags: wxOK, wxCANCEL, wxYES, wxNO, wxHELP, wxNO\_DEFAULT.
184
185The sizer lays out the buttons in a manner appropriate to the platform.
186
9ceeecb9
JS
187\membersection{wxDialog::DoOK}\label{wxdialogdook}
188
189\func{virtual bool}{DoOK}{\void}
190
191This function is called when the titlebar OK button is pressed (PocketPC only).
192A command event for the identifier returned by GetAffirmativeId is sent by
193default. You can override this function. If the function returns false, wxWidgets
194will call Close() for the dialog.
195
a660d684
KB
196\membersection{wxDialog::EndModal}\label{wxdialogendmodal}
197
198\func{void}{EndModal}{\param{int }{retCode}}
199
200Ends a modal dialog, passing a value to be returned from the \helpref{wxDialog::ShowModal}{wxdialogshowmodal}\rtfsp
201invocation.
202
203\wxheading{Parameters}
204
205\docparam{retCode}{The value that should be returned by {\bf ShowModal}.}
206
207\wxheading{See also}
208
209\helpref{wxDialog::ShowModal}{wxdialogshowmodal},\rtfsp
6453876e
RR
210\helpref{wxDialog::GetReturnCode}{wxdialoggetreturncode},\rtfsp
211\helpref{wxDialog::SetReturnCode}{wxdialogsetreturncode}
212
9ceeecb9
JS
213\membersection{wxDialog::GetAffirmativeId}\label{wxdialoggetaffirmativeid}
214
215\constfunc{int}{GetAffirmativeId}{\void}
216
217Gets the identifier to be used when the user presses an OK button in a PocketPC titlebar.
218
219\wxheading{See also}
220
221\helpref{wxDialog::SetAffirmativeId}{wxdialogsetaffirmativeid}
222
6453876e
RR
223\membersection{wxDialog::GetReturnCode}\label{wxdialoggetreturncode}
224
225\func{int}{GetReturnCode}{\void}
226
227Gets the return code for this window.
228
229\wxheading{Remarks}
230
231A return code is normally associated with a modal dialog, where \helpref{wxDialog::ShowModal}{wxdialogshowmodal} returns
232a code to the application.
233
234\wxheading{See also}
235
236\helpref{wxDialog::SetReturnCode}{wxdialogsetreturncode}, \helpref{wxDialog::ShowModal}{wxdialogshowmodal},\rtfsp
237\helpref{wxDialog::EndModal}{wxdialogendmodal}
a660d684
KB
238
239\membersection{wxDialog::GetTitle}\label{wxdialoggettitle}
240
241\constfunc{wxString}{GetTitle}{\void}
242
243Returns the title of the dialog box.
244
ec5f0c24
JS
245\membersection{wxDialog::GetToolBar}\label{wxdialoggettoolbar}
246
247\constfunc{wxToolBar*}{GetToolBar}{\void}
248
249On PocketPC, a dialog is automatically provided with an empty toolbar. GetToolBar
250allows you to access the toolbar and add tools to it. Removing tools and adding
251arbitrary controls are not currently supported.
252
253This function is not available on any other platform.
254
a660d684
KB
255\membersection{wxDialog::Iconize}\label{wxdialogiconized}
256
257\func{void}{Iconize}{\param{const bool}{ iconize}}
258
6453876e 259Iconizes or restores the dialog. Windows only.
a660d684
KB
260
261\wxheading{Parameters}
262
cc81d32f 263\docparam{iconize}{If true, iconizes the dialog box; if false, shows and restores it.}
a660d684
KB
264
265\wxheading{Remarks}
266
267Note that in Windows, iconization has no effect since dialog boxes cannot be
268iconized. However, applications may need to explicitly restore dialog
269boxes under Motif which have user-iconizable frames, and under Windows
cc81d32f
VS
270calling {\tt Iconize(false)} will bring the window to the front, as does
271\rtfsp{\tt Show(true)}.
a660d684
KB
272
273\membersection{wxDialog::IsIconized}\label{wxdialogisiconized}
274
275\constfunc{bool}{IsIconized}{\void}
276
cc81d32f 277Returns true if the dialog box is iconized. Windows only.
a660d684
KB
278
279\wxheading{Remarks}
280
cc81d32f 281Always returns false under Windows since dialogs cannot be iconized.
a660d684
KB
282
283\membersection{wxDialog::IsModal}\label{wxdialogismodal}
284
285\constfunc{bool}{IsModal}{\void}
286
cc81d32f 287Returns true if the dialog box is modal, false otherwise.
a660d684 288
a660d684
KB
289\membersection{wxDialog::OnApply}\label{wxdialogonapply}
290
291\func{void}{OnApply}{\param{wxCommandEvent\& }{event}}
292
293The default handler for the wxID\_APPLY identifier.
294
295\wxheading{Remarks}
296
297This function calls \helpref{wxWindow::Validate}{wxwindowvalidate} and \helpref{wxWindow::TransferDataToWindow}{wxwindowtransferdatatowindow}.
298
299\wxheading{See also}
300
301\helpref{wxDialog::OnOK}{wxdialogonok}, \helpref{wxDialog::OnCancel}{wxdialogoncancel}
302
303\membersection{wxDialog::OnCancel}\label{wxdialogoncancel}
304
305\func{void}{OnCancel}{\param{wxCommandEvent\& }{event}}
306
307The default handler for the wxID\_CANCEL identifier.
308
309\wxheading{Remarks}
310
311The function either calls {\bf EndModal(wxID\_CANCEL)} if the dialog is modal, or
cc81d32f 312sets the return value to wxID\_CANCEL and calls {\bf Show(false)} if the dialog is modeless.
a660d684
KB
313
314\wxheading{See also}
315
316\helpref{wxDialog::OnOK}{wxdialogonok}, \helpref{wxDialog::OnApply}{wxdialogonapply}
317
318\membersection{wxDialog::OnOK}\label{wxdialogonok}
319
320\func{void}{OnOK}{\param{wxCommandEvent\& }{event}}
321
322The default handler for the wxID\_OK identifier.
323
324\wxheading{Remarks}
325
326The function calls
327\rtfsp\helpref{wxWindow::Validate}{wxwindowvalidate}, then \helpref{wxWindow::TransferDataFromWindow}{wxwindowtransferdatafromwindow}.
cc81d32f
VS
328If this returns true, the function either calls {\bf EndModal(wxID\_OK)} if the dialog is modal, or
329sets the return value to wxID\_OK and calls {\bf Show(false)} if the dialog is modeless.
a660d684
KB
330
331\wxheading{See also}
332
333\helpref{wxDialog::OnCancel}{wxdialogoncancel}, \helpref{wxDialog::OnApply}{wxdialogonapply}
334
335\membersection{wxDialog::OnSysColourChanged}\label{wxdialogonsyscolourchanged}
336
337\func{void}{OnSysColourChanged}{\param{wxSysColourChangedEvent\& }{event}}
338
339The default handler for wxEVT\_SYS\_COLOUR\_CHANGED.
340
341\wxheading{Parameters}
342
343\docparam{event}{The colour change event.}
344
345\wxheading{Remarks}
346
347Changes the dialog's colour to conform to the current settings (Windows only).
348Add an event table entry for your dialog class if you wish the behaviour
349to be different (such as keeping a user-defined
f4fcc291 350background colour). If you do override this function, call wxEvent::Skip to
a660d684
KB
351propagate the notification to child windows and controls.
352
353\wxheading{See also}
354
355\helpref{wxSysColourChangedEvent}{wxsyscolourchangedevent}
356
9ceeecb9
JS
357\membersection{wxDialog::SetAffirmativeId}\label{wxdialogsetaffirmativeid}
358
359\func{void}{SetAffirmativeId}{\param{int }{id}}
360
361Sets the identifier to be used when the user presses an OK button in a PocketPC titlebar.
362By default, this is wxID\_OK.
363
364\wxheading{See also}
365
366\helpref{wxDialog::GetAffirmativeId}{wxdialoggetaffirmativeid}
367
9a6a5530
MB
368\membersection{wxDialog::SetIcon}\label{wxdialogseticon}
369
370\func{void}{SetIcon}{\param{const wxIcon\& }{icon}}
371
372Sets the icon for this dialog.
373
374\wxheading{Parameters}
375
376\docparam{icon}{The icon to associate with this dialog.}
377
378See also \helpref{wxIcon}{wxicon}.
379
380\membersection{wxDialog::SetIcons}\label{wxdialogseticons}
381
382\func{void}{SetIcons}{\param{const wxIconBundle\& }{icons}}
383
384Sets the icons for this dialog.
385
386\wxheading{Parameters}
387
388\docparam{icons}{The icons to associate with this dialog.}
389
390See also \helpref{wxIconBundle}{wxiconbundle}.
391
a660d684
KB
392\membersection{wxDialog::SetModal}\label{wxdialogsetmodal}
393
394\func{void}{SetModal}{\param{const bool}{ flag}}
395
f6bcfd97
BP
396{\bf NB:} This function is deprecated and doesn't work for all ports, just use
397\helpref{ShowModal}{wxdialogshowmodal} to show a modal dialog instead.
398
a660d684
KB
399Allows the programmer to specify whether the dialog box is modal (wxDialog::Show blocks control
400until the dialog is hidden) or modeless (control returns immediately).
401
402\wxheading{Parameters}
403
cc81d32f 404\docparam{flag}{If true, the dialog will be modal, otherwise it will be modeless.}
a660d684 405
6453876e
RR
406\membersection{wxDialog::SetReturnCode}\label{wxdialogsetreturncode}
407
408\func{void}{SetReturnCode}{\param{int }{retCode}}
409
410Sets the return code for this window.
411
412\wxheading{Parameters}
413
414\docparam{retCode}{The integer return code, usually a control identifier.}
415
416\wxheading{Remarks}
417
418A return code is normally associated with a modal dialog, where \helpref{wxDialog::ShowModal}{wxdialogshowmodal} returns
419a code to the application. The function \helpref{wxDialog::EndModal}{wxdialogendmodal} calls {\bf SetReturnCode}.
420
421\wxheading{See also}
422
d7cb14ce 423\helpref{wxDialog::GetReturnCode}{wxdialoggetreturncode}, \helpref{wxDialog::ShowModal}{wxdialogshowmodal},\rtfsp
6453876e
RR
424\helpref{wxDialog::EndModal}{wxdialogendmodal}
425
a660d684
KB
426\membersection{wxDialog::SetTitle}\label{wxdialogsettitle}
427
428\func{void}{SetTitle}{\param{const wxString\& }{ title}}
429
430Sets the title of the dialog box.
431
432\wxheading{Parameters}
433
434\docparam{title}{The dialog box title.}
435
436\membersection{wxDialog::Show}\label{wxdialogshow}
437
438\func{bool}{Show}{\param{const bool}{ show}}
439
440Hides or shows the dialog.
441
442\wxheading{Parameters}
443
cc81d32f
VS
444\docparam{show}{If true, the dialog box is shown and brought to the front;
445otherwise the box is hidden. If false and the dialog is
a660d684
KB
446modal, control is returned to the calling program.}
447
448\wxheading{Remarks}
449
450The preferred way of dismissing a modal dialog is to use \helpref{wxDialog::EndModal}{wxdialogendmodal}.
451
452\membersection{wxDialog::ShowModal}\label{wxdialogshowmodal}
453
454\func{int}{ShowModal}{\void}
455
456Shows a modal dialog. Program flow does not return until the dialog has been dismissed with\rtfsp
457\helpref{wxDialog::EndModal}{wxdialogendmodal}.
458
459\wxheading{Return value}
460
d7cb14ce 461The return value is the value set with \helpref{wxDialog::SetReturnCode}{wxdialogsetreturncode}.
a660d684
KB
462
463\wxheading{See also}
464
465\helpref{wxDialog::EndModal}{wxdialogendmodal},\rtfsp
d7cb14ce
JS
466\helpref{wxDialog:GetReturnCode}{wxdialoggetreturncode},\rtfsp
467\helpref{wxDialog::SetReturnCode}{wxdialogsetreturncode}
a660d684 468