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