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