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