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