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