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