]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/dialog.tex
define _HPUX_SOURCE under HP-UX, otherwise many things are not defined in standard...
[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 72\twocolitem{\windowstyle{wxTHICK\_FRAME}}{Display a thick frame around the window.}
3faa8195 73\twocolitem{\windowstyle{wxSTAY\_ON\_TOP}}{The dialog stays on top of all other windows.}
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
c6ece595 100
b236c10f 101\membersection{wxDialog::wxDialog}\label{wxdialogctor}
a660d684
KB
102
103\func{}{wxDialog}{\void}
104
105Default constructor.
106
eaaa6a06 107\func{}{wxDialog}{\param{wxWindow* }{parent}, \param{wxWindowID }{id},\rtfsp
a660d684
KB
108\param{const wxString\& }{title},\rtfsp
109\param{const wxPoint\& }{pos = wxDefaultPosition},\rtfsp
110\param{const wxSize\& }{size = wxDefaultSize},\rtfsp
eaaa6a06 111\param{long}{ style = wxDEFAULT\_DIALOG\_STYLE},\rtfsp
a660d684
KB
112\param{const wxString\& }{name = ``dialogBox"}}
113
114Constructor.
115
116\wxheading{Parameters}
117
118\docparam{parent}{Can be NULL, a frame or another dialog box.}
119
120\docparam{id}{An identifier for the dialog. A value of -1 is taken to mean a default.}
121
122\docparam{title}{The title of the dialog.}
123
124\docparam{pos}{The dialog position. A value of (-1, -1) indicates a default position, chosen by
fc2171bd 125either the windowing system or wxWidgets, depending on platform.}
a660d684
KB
126
127\docparam{size}{The dialog size. A value of (-1, -1) indicates a default size, chosen by
fc2171bd 128either the windowing system or wxWidgets, depending on platform.}
a660d684
KB
129
130\docparam{style}{The window style. See \helpref{wxDialog}{wxdialog}.}
131
132\docparam{name}{Used to associate a name with the window,
133allowing the application user to set Motif resource values for
134individual dialog boxes.}
135
136\wxheading{See also}
137
138\helpref{wxDialog::Create}{wxdialogcreate}
139
c6ece595 140
b236c10f 141\membersection{wxDialog::\destruct{wxDialog}}\label{wxdialogdtor}
a660d684
KB
142
143\func{}{\destruct{wxDialog}}{\void}
144
145Destructor. Deletes any child windows before deleting the physical window.
146
c6ece595 147
a660d684
KB
148\membersection{wxDialog::Centre}\label{wxdialogcentre}
149
eaaa6a06 150\func{void}{Centre}{\param{int}{ direction = wxBOTH}}
a660d684
KB
151
152Centres the dialog box on the display.
153
154\wxheading{Parameters}
155
156\docparam{direction}{May be {\tt wxHORIZONTAL}, {\tt wxVERTICAL} or {\tt wxBOTH}.}
157
c6ece595 158
a660d684
KB
159\membersection{wxDialog::Create}\label{wxdialogcreate}
160
eaaa6a06 161\func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID }{id},\rtfsp
a660d684
KB
162\param{const wxString\& }{title},\rtfsp
163\param{const wxPoint\& }{pos = wxDefaultPosition},\rtfsp
164\param{const wxSize\& }{size = wxDefaultSize},\rtfsp
eaaa6a06 165\param{long}{ style = wxDEFAULT\_DIALOG\_STYLE},\rtfsp
a660d684
KB
166\param{const wxString\& }{name = ``dialogBox"}}
167
b236c10f 168Used for two-step dialog box construction. See \helpref{wxDialog::wxDialog}{wxdialogctor}\rtfsp
a660d684
KB
169for details.
170
c6ece595 171
67edd0c7
JS
172\membersection{wxDialog::CreateButtonSizer}\label{wxdialogcreatebuttonsizer}
173
174\func{wxSizer*}{CreateButtonSizer}{\param{long}{ flags}}
175
176Creates a sizer with standard buttons. {\it flags} is a bit list
177of the following flags: wxOK, wxCANCEL, wxYES, wxNO, wxHELP, wxNO\_DEFAULT.
178
179The sizer lays out the buttons in a manner appropriate to the platform.
180
181This function simply calls \helpref{CreateStdDialogButtonSizer}{wxdialogcreatestddialogbuttonsizer}.
182
c6ece595 183
67edd0c7
JS
184\membersection{wxDialog::CreateStdDialogButtonSizer}\label{wxdialogcreatestddialogbuttonsizer}
185
186\func{wxStdDialogButtonSizer*}{CreateStdDialogButtonSizer}{\param{long}{ flags}}
187
188Creates a \helpref{wxStdDialogButtonSizer}{wxstddialogbuttonsizer} with standard buttons. {\it flags} is a bit list
189of the following flags: wxOK, wxCANCEL, wxYES, wxNO, wxHELP, wxNO\_DEFAULT.
190
191The sizer lays out the buttons in a manner appropriate to the platform.
192
c6ece595 193
9ceeecb9
JS
194\membersection{wxDialog::DoOK}\label{wxdialogdook}
195
196\func{virtual bool}{DoOK}{\void}
197
198This function is called when the titlebar OK button is pressed (PocketPC only).
199A command event for the identifier returned by GetAffirmativeId is sent by
200default. You can override this function. If the function returns false, wxWidgets
201will call Close() for the dialog.
202
c6ece595 203
a660d684
KB
204\membersection{wxDialog::EndModal}\label{wxdialogendmodal}
205
206\func{void}{EndModal}{\param{int }{retCode}}
207
208Ends a modal dialog, passing a value to be returned from the \helpref{wxDialog::ShowModal}{wxdialogshowmodal}\rtfsp
209invocation.
210
211\wxheading{Parameters}
212
213\docparam{retCode}{The value that should be returned by {\bf ShowModal}.}
214
215\wxheading{See also}
216
217\helpref{wxDialog::ShowModal}{wxdialogshowmodal},\rtfsp
6453876e
RR
218\helpref{wxDialog::GetReturnCode}{wxdialoggetreturncode},\rtfsp
219\helpref{wxDialog::SetReturnCode}{wxdialogsetreturncode}
220
c6ece595 221
9ceeecb9
JS
222\membersection{wxDialog::GetAffirmativeId}\label{wxdialoggetaffirmativeid}
223
224\constfunc{int}{GetAffirmativeId}{\void}
225
226Gets the identifier to be used when the user presses an OK button in a PocketPC titlebar.
227
228\wxheading{See also}
229
230\helpref{wxDialog::SetAffirmativeId}{wxdialogsetaffirmativeid}
231
c6ece595
VZ
232
233\membersection{wxDialog::GetEscapeId}\label{wxdialoggetescapeid}
234
235\constfunc{int}{GetEscapeId}{\void}
236
237Gets the identifier of the button to map presses of \texttt{\textsc{ESC}}
238button to.
239
240\wxheading{See also}
241
242\helpref{wxDialog::SetEscapeId}{wxdialogsetescapeid}
243
244
6453876e
RR
245\membersection{wxDialog::GetReturnCode}\label{wxdialoggetreturncode}
246
247\func{int}{GetReturnCode}{\void}
248
249Gets the return code for this window.
250
251\wxheading{Remarks}
252
253A return code is normally associated with a modal dialog, where \helpref{wxDialog::ShowModal}{wxdialogshowmodal} returns
254a code to the application.
255
256\wxheading{See also}
257
258\helpref{wxDialog::SetReturnCode}{wxdialogsetreturncode}, \helpref{wxDialog::ShowModal}{wxdialogshowmodal},\rtfsp
259\helpref{wxDialog::EndModal}{wxdialogendmodal}
a660d684 260
c6ece595 261
a660d684
KB
262\membersection{wxDialog::GetTitle}\label{wxdialoggettitle}
263
264\constfunc{wxString}{GetTitle}{\void}
265
266Returns the title of the dialog box.
267
c6ece595 268
ec5f0c24
JS
269\membersection{wxDialog::GetToolBar}\label{wxdialoggettoolbar}
270
271\constfunc{wxToolBar*}{GetToolBar}{\void}
272
273On PocketPC, a dialog is automatically provided with an empty toolbar. GetToolBar
274allows you to access the toolbar and add tools to it. Removing tools and adding
275arbitrary controls are not currently supported.
276
277This function is not available on any other platform.
278
c6ece595 279
a660d684
KB
280\membersection{wxDialog::Iconize}\label{wxdialogiconized}
281
282\func{void}{Iconize}{\param{const bool}{ iconize}}
283
6453876e 284Iconizes or restores the dialog. Windows only.
a660d684
KB
285
286\wxheading{Parameters}
287
cc81d32f 288\docparam{iconize}{If true, iconizes the dialog box; if false, shows and restores it.}
a660d684
KB
289
290\wxheading{Remarks}
291
292Note that in Windows, iconization has no effect since dialog boxes cannot be
293iconized. However, applications may need to explicitly restore dialog
294boxes under Motif which have user-iconizable frames, and under Windows
cc81d32f
VS
295calling {\tt Iconize(false)} will bring the window to the front, as does
296\rtfsp{\tt Show(true)}.
a660d684 297
c6ece595 298
a660d684
KB
299\membersection{wxDialog::IsIconized}\label{wxdialogisiconized}
300
301\constfunc{bool}{IsIconized}{\void}
302
cc81d32f 303Returns true if the dialog box is iconized. Windows only.
a660d684
KB
304
305\wxheading{Remarks}
306
cc81d32f 307Always returns false under Windows since dialogs cannot be iconized.
a660d684 308
c6ece595 309
a660d684
KB
310\membersection{wxDialog::IsModal}\label{wxdialogismodal}
311
312\constfunc{bool}{IsModal}{\void}
313
cc81d32f 314Returns true if the dialog box is modal, false otherwise.
a660d684 315
c6ece595 316
a660d684
KB
317\membersection{wxDialog::OnApply}\label{wxdialogonapply}
318
319\func{void}{OnApply}{\param{wxCommandEvent\& }{event}}
320
321The default handler for the wxID\_APPLY identifier.
322
323\wxheading{Remarks}
324
325This function calls \helpref{wxWindow::Validate}{wxwindowvalidate} and \helpref{wxWindow::TransferDataToWindow}{wxwindowtransferdatatowindow}.
326
327\wxheading{See also}
328
329\helpref{wxDialog::OnOK}{wxdialogonok}, \helpref{wxDialog::OnCancel}{wxdialogoncancel}
330
c6ece595 331
a660d684
KB
332\membersection{wxDialog::OnCancel}\label{wxdialogoncancel}
333
334\func{void}{OnCancel}{\param{wxCommandEvent\& }{event}}
335
336The default handler for the wxID\_CANCEL identifier.
337
338\wxheading{Remarks}
339
340The function either calls {\bf EndModal(wxID\_CANCEL)} if the dialog is modal, or
cc81d32f 341sets the return value to wxID\_CANCEL and calls {\bf Show(false)} if the dialog is modeless.
a660d684
KB
342
343\wxheading{See also}
344
345\helpref{wxDialog::OnOK}{wxdialogonok}, \helpref{wxDialog::OnApply}{wxdialogonapply}
346
c6ece595 347
a660d684
KB
348\membersection{wxDialog::OnOK}\label{wxdialogonok}
349
350\func{void}{OnOK}{\param{wxCommandEvent\& }{event}}
351
352The default handler for the wxID\_OK identifier.
353
354\wxheading{Remarks}
355
356The function calls
357\rtfsp\helpref{wxWindow::Validate}{wxwindowvalidate}, then \helpref{wxWindow::TransferDataFromWindow}{wxwindowtransferdatafromwindow}.
cc81d32f
VS
358If this returns true, the function either calls {\bf EndModal(wxID\_OK)} if the dialog is modal, or
359sets the return value to wxID\_OK and calls {\bf Show(false)} if the dialog is modeless.
a660d684
KB
360
361\wxheading{See also}
362
363\helpref{wxDialog::OnCancel}{wxdialogoncancel}, \helpref{wxDialog::OnApply}{wxdialogonapply}
364
c6ece595 365
a660d684
KB
366\membersection{wxDialog::OnSysColourChanged}\label{wxdialogonsyscolourchanged}
367
368\func{void}{OnSysColourChanged}{\param{wxSysColourChangedEvent\& }{event}}
369
370The default handler for wxEVT\_SYS\_COLOUR\_CHANGED.
371
372\wxheading{Parameters}
373
374\docparam{event}{The colour change event.}
375
376\wxheading{Remarks}
377
378Changes the dialog's colour to conform to the current settings (Windows only).
379Add an event table entry for your dialog class if you wish the behaviour
380to be different (such as keeping a user-defined
f4fcc291 381background colour). If you do override this function, call wxEvent::Skip to
a660d684
KB
382propagate the notification to child windows and controls.
383
384\wxheading{See also}
385
386\helpref{wxSysColourChangedEvent}{wxsyscolourchangedevent}
387
c6ece595 388
9ceeecb9
JS
389\membersection{wxDialog::SetAffirmativeId}\label{wxdialogsetaffirmativeid}
390
391\func{void}{SetAffirmativeId}{\param{int }{id}}
392
393Sets the identifier to be used when the user presses an OK button in a PocketPC titlebar.
394By default, this is wxID\_OK.
395
396\wxheading{See also}
397
398\helpref{wxDialog::GetAffirmativeId}{wxdialoggetaffirmativeid}
399
c6ece595
VZ
400
401\membersection{wxDialog::SetEscapeId}\label{wxdialogsetescapeid}
402
403\func{void}{SetEscapeId}{\param{int }{id}}
404
405Sets the identifier to be used when the user presses \texttt{\textsc{ESC}}
406button in the dialog. By default, this is \texttt{wxID\_ANY} meaning that
407the first suitable button is used: if there a \texttt{wxID\_CANCEL} button, it
408is activated, otherwise \texttt{wxID\_OK} button is activated if present.
409Another possible special value for \arg{id} is \texttt{wxID\_NONE} meaning that
410\texttt{\textsc{ESC}} presses should be ignored. If another value is given, it
411is interpreted as the id of the button to map the escape key to.
412
413
9a6a5530
MB
414\membersection{wxDialog::SetIcon}\label{wxdialogseticon}
415
416\func{void}{SetIcon}{\param{const wxIcon\& }{icon}}
417
418Sets the icon for this dialog.
419
420\wxheading{Parameters}
421
422\docparam{icon}{The icon to associate with this dialog.}
423
424See also \helpref{wxIcon}{wxicon}.
425
c6ece595 426
9a6a5530
MB
427\membersection{wxDialog::SetIcons}\label{wxdialogseticons}
428
429\func{void}{SetIcons}{\param{const wxIconBundle\& }{icons}}
430
431Sets the icons for this dialog.
432
433\wxheading{Parameters}
434
435\docparam{icons}{The icons to associate with this dialog.}
436
437See also \helpref{wxIconBundle}{wxiconbundle}.
438
c6ece595 439
a660d684
KB
440\membersection{wxDialog::SetModal}\label{wxdialogsetmodal}
441
442\func{void}{SetModal}{\param{const bool}{ flag}}
443
f6bcfd97
BP
444{\bf NB:} This function is deprecated and doesn't work for all ports, just use
445\helpref{ShowModal}{wxdialogshowmodal} to show a modal dialog instead.
446
a660d684
KB
447Allows the programmer to specify whether the dialog box is modal (wxDialog::Show blocks control
448until the dialog is hidden) or modeless (control returns immediately).
449
450\wxheading{Parameters}
451
cc81d32f 452\docparam{flag}{If true, the dialog will be modal, otherwise it will be modeless.}
a660d684 453
c6ece595 454
6453876e
RR
455\membersection{wxDialog::SetReturnCode}\label{wxdialogsetreturncode}
456
457\func{void}{SetReturnCode}{\param{int }{retCode}}
458
459Sets the return code for this window.
460
461\wxheading{Parameters}
462
463\docparam{retCode}{The integer return code, usually a control identifier.}
464
465\wxheading{Remarks}
466
467A return code is normally associated with a modal dialog, where \helpref{wxDialog::ShowModal}{wxdialogshowmodal} returns
468a code to the application. The function \helpref{wxDialog::EndModal}{wxdialogendmodal} calls {\bf SetReturnCode}.
469
470\wxheading{See also}
471
d7cb14ce 472\helpref{wxDialog::GetReturnCode}{wxdialoggetreturncode}, \helpref{wxDialog::ShowModal}{wxdialogshowmodal},\rtfsp
6453876e
RR
473\helpref{wxDialog::EndModal}{wxdialogendmodal}
474
c6ece595 475
a660d684
KB
476\membersection{wxDialog::SetTitle}\label{wxdialogsettitle}
477
478\func{void}{SetTitle}{\param{const wxString\& }{ title}}
479
480Sets the title of the dialog box.
481
482\wxheading{Parameters}
483
484\docparam{title}{The dialog box title.}
485
c6ece595 486
a660d684
KB
487\membersection{wxDialog::Show}\label{wxdialogshow}
488
489\func{bool}{Show}{\param{const bool}{ show}}
490
491Hides or shows the dialog.
492
493\wxheading{Parameters}
494
cc81d32f
VS
495\docparam{show}{If true, the dialog box is shown and brought to the front;
496otherwise the box is hidden. If false and the dialog is
a660d684
KB
497modal, control is returned to the calling program.}
498
499\wxheading{Remarks}
500
501The preferred way of dismissing a modal dialog is to use \helpref{wxDialog::EndModal}{wxdialogendmodal}.
502
c6ece595 503
a660d684
KB
504\membersection{wxDialog::ShowModal}\label{wxdialogshowmodal}
505
506\func{int}{ShowModal}{\void}
507
508Shows a modal dialog. Program flow does not return until the dialog has been dismissed with\rtfsp
509\helpref{wxDialog::EndModal}{wxdialogendmodal}.
510
511\wxheading{Return value}
512
d7cb14ce 513The return value is the value set with \helpref{wxDialog::SetReturnCode}{wxdialogsetreturncode}.
a660d684
KB
514
515\wxheading{See also}
516
517\helpref{wxDialog::EndModal}{wxdialogendmodal},\rtfsp
d7cb14ce
JS
518\helpref{wxDialog:GetReturnCode}{wxdialoggetreturncode},\rtfsp
519\helpref{wxDialog::SetReturnCode}{wxdialogsetreturncode}
a660d684 520