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