1 \section{\class{wxDialog
}}\label{wxdialog
}
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.
7 \wxheading{Derived from
}
9 \helpref{wxWindow
}{wxwindow
}\\
10 \helpref{wxEvtHandler
}{wxevthandler
}\\
11 \helpref{wxObject
}{wxobject
}
13 \wxheading{Include files
}
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 on other windows is still possible. To show a modal dialog
23 you should use
\helpref{ShowModal
}{wxdialogshowmodal
} method while to show
24 dialog modelessly you simply use
\helpref{Show
}{wxdialogshow
}, just as with the
27 Note that the modal dialogs are 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
33 MyAskDialog *dlg = new MyAskDialog(...);
34 if ( dlg->ShowModal() == wxID_OK )
36 //else: dialog was cancelled or some another button pressed
41 works, you can also achieve the same result by using a simpler code fragment
47 if ( dlg.ShowModal() == wxID_OK )
50 // no need to call Destroy() here
54 A dialog may be loaded from a wxWindows resource file (extension
{\tt wxr
}),
55 which may itself be created by Dialog Editor. For details, see
56 \helpref{The wxWindows resource system
}{resourceformats
},
57 \helpref{wxWindows resource functions
}{resourcefuncs
}
58 and the resource sample.
60 An application can define an
\helpref{wxCloseEvent
}{wxcloseevent
} handler for
61 the dialog to respond to system close events.
63 \wxheading{Window styles
}
66 \begin{twocollist
}\itemsep=
0pt
67 \twocolitem{\windowstyle{wxCAPTION
}}{Puts a caption on the dialog box.
}
68 \twocolitem{\windowstyle{wxDEFAULT
\_DIALOG\_STYLE}}{Equivalent to a combination of wxCAPTION, wxCLOSE
\_BOX and wxSYSTEM
\_MENU (the last one is not used under Unix)
}
69 \twocolitem{\windowstyle{wxRESIZE
\_BORDER}}{Display a resizeable frame around the window.
}
70 \twocolitem{\windowstyle{wxSYSTEM
\_MENU}}{Display a system menu.
}
71 \twocolitem{\windowstyle{wxCLOSE
\_BOX}}{Displays a close box on the frame.
}
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).
}
74 \twocolitem{\windowstyle{wxNO
\_3D}}{Under Windows, specifies that the child controls
75 should not have
3D borders unless specified in the control.
}
76 \twocolitem{\windowstyle{wxDIALOG
\_NO\_PARENT}}{By default, the dialogs created
77 with
{\tt NULL
} parent window will be given the
78 \helpref{applications top level window
}{wxappgettopwindow
} as parent. Use this
79 style to prevent this from happening and create a really orphan dialog (note
80 that this is not recommended for modal dialogs).
}
81 \twocolitem{\windowstyle{wxDIALOG
\_EX\_CONTEXTHELP}}{Under Windows, puts a query button on the
82 caption. When pressed, Windows will go into a context-sensitive help mode and wxWindows will send
83 a wxEVT
\_HELP event if the user clicked on an application window.
{\it Note
}\ that this is an extended
84 style and must be set by calling
\helpref{SetExtraStyle
}{wxwindowsetextrastyle
} before Create is called (two-step construction).
}
87 Under Unix or Linux, MWM (the Motif Window Manager) or other window managers
88 recognizing the MHM hints should be running for any of these styles to have an
91 See also
\helpref{Generic window styles
}{windowstyles
}.
95 \helpref{wxDialog overview
}{wxdialogoverview
},
\helpref{wxFrame
}{wxframe
},
\helpref{Resources
}{resources
},
\rtfsp
96 \helpref{Validator overview
}{validatoroverview
}
98 \latexignore{\rtfignore{\wxheading{Members
}}}
100 \membersection{wxDialog::wxDialog
}\label{wxdialogconstr
}
102 \func{}{wxDialog
}{\void}
106 \func{}{wxDialog
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{id
},
\rtfsp
107 \param{const wxString\&
}{title
},
\rtfsp
108 \param{const wxPoint\&
}{pos = wxDefaultPosition
},
\rtfsp
109 \param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
110 \param{long
}{ style = wxDEFAULT
\_DIALOG\_STYLE},
\rtfsp
111 \param{const wxString\&
}{name = ``dialogBox"
}}
115 \wxheading{Parameters
}
117 \docparam{parent
}{Can be NULL, a frame or another dialog box.
}
119 \docparam{id
}{An identifier for the dialog. A value of -
1 is taken to mean a default.
}
121 \docparam{title
}{The title of the dialog.
}
123 \docparam{pos
}{The dialog position. A value of (-
1, -
1) indicates a default position, chosen by
124 either the windowing system or wxWindows, depending on platform.
}
126 \docparam{size
}{The dialog size. A value of (-
1, -
1) indicates a default size, chosen by
127 either the windowing system or wxWindows, depending on platform.
}
129 \docparam{style
}{The window style. See
\helpref{wxDialog
}{wxdialog
}.
}
131 \docparam{name
}{Used to associate a name with the window,
132 allowing the application user to set Motif resource values for
133 individual dialog boxes.
}
137 \helpref{wxDialog::Create
}{wxdialogcreate
}
139 \membersection{wxDialog::
\destruct{wxDialog
}}
141 \func{}{\destruct{wxDialog
}}{\void}
143 Destructor. Deletes any child windows before deleting the physical window.
145 \membersection{wxDialog::Centre
}\label{wxdialogcentre
}
147 \func{void
}{Centre
}{\param{int
}{ direction = wxBOTH
}}
149 Centres the dialog box on the display.
151 \wxheading{Parameters
}
153 \docparam{direction
}{May be
{\tt wxHORIZONTAL
},
{\tt wxVERTICAL
} or
{\tt wxBOTH
}.
}
155 \membersection{wxDialog::Create
}\label{wxdialogcreate
}
157 \func{bool
}{Create
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{id
},
\rtfsp
158 \param{const wxString\&
}{title
},
\rtfsp
159 \param{const wxPoint\&
}{pos = wxDefaultPosition
},
\rtfsp
160 \param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
161 \param{long
}{ style = wxDEFAULT
\_DIALOG\_STYLE},
\rtfsp
162 \param{const wxString\&
}{name = ``dialogBox"
}}
164 Used for two-step dialog box construction. See
\helpref{wxDialog::wxDialog
}{wxdialogconstr
}\rtfsp
167 \membersection{wxDialog::EndModal
}\label{wxdialogendmodal
}
169 \func{void
}{EndModal
}{\param{int
}{retCode
}}
171 Ends a modal dialog, passing a value to be returned from the
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
}\rtfsp
174 \wxheading{Parameters
}
176 \docparam{retCode
}{The value that should be returned by
{\bf ShowModal
}.
}
180 \helpref{wxDialog::ShowModal
}{wxdialogshowmodal
},
\rtfsp
181 \helpref{wxDialog::GetReturnCode
}{wxdialoggetreturncode
},
\rtfsp
182 \helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
}
184 \membersection{wxDialog::GetReturnCode
}\label{wxdialoggetreturncode
}
186 \func{int
}{GetReturnCode
}{\void}
188 Gets the return code for this window.
192 A return code is normally associated with a modal dialog, where
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
} returns
193 a code to the application.
197 \helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
},
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
},
\rtfsp
198 \helpref{wxDialog::EndModal
}{wxdialogendmodal
}
200 \membersection{wxDialog::GetTitle
}\label{wxdialoggettitle
}
202 \constfunc{wxString
}{GetTitle
}{\void}
204 Returns the title of the dialog box.
206 \membersection{wxDialog::Iconize
}\label{wxdialogiconized
}
208 \func{void
}{Iconize
}{\param{const bool
}{ iconize
}}
210 Iconizes or restores the dialog. Windows only.
212 \wxheading{Parameters
}
214 \docparam{iconize
}{If true, iconizes the dialog box; if false, shows and restores it.
}
218 Note that in Windows, iconization has no effect since dialog boxes cannot be
219 iconized. However, applications may need to explicitly restore dialog
220 boxes under Motif which have user-iconizable frames, and under Windows
221 calling
{\tt Iconize(false)
} will bring the window to the front, as does
222 \rtfsp{\tt Show(true)
}.
224 \membersection{wxDialog::IsIconized
}\label{wxdialogisiconized
}
226 \constfunc{bool
}{IsIconized
}{\void}
228 Returns true if the dialog box is iconized. Windows only.
232 Always returns false under Windows since dialogs cannot be iconized.
234 \membersection{wxDialog::IsModal
}\label{wxdialogismodal
}
236 \constfunc{bool
}{IsModal
}{\void}
238 Returns true if the dialog box is modal, false otherwise.
240 \membersection{wxDialog::OnCharHook
}\label{wxdialogoncharhook
}
242 \func{void
}{OnCharHook
}{\param{wxKeyEvent\&
}{ event
}}
244 This member is called to allow the window to intercept keyboard events
245 before they are processed by child windows.
247 %For more information, see \helpref{wxWindow::OnCharHook}{wxwindowoncharhook}
251 wxDialog implements this handler to fake a cancel command if the escape key has been
252 pressed. This will dismiss the dialog.
254 \membersection{wxDialog::OnApply
}\label{wxdialogonapply
}
256 \func{void
}{OnApply
}{\param{wxCommandEvent\&
}{event
}}
258 The default handler for the wxID
\_APPLY identifier.
262 This function calls
\helpref{wxWindow::Validate
}{wxwindowvalidate
} and
\helpref{wxWindow::TransferDataToWindow
}{wxwindowtransferdatatowindow
}.
266 \helpref{wxDialog::OnOK
}{wxdialogonok
},
\helpref{wxDialog::OnCancel
}{wxdialogoncancel
}
268 \membersection{wxDialog::OnCancel
}\label{wxdialogoncancel
}
270 \func{void
}{OnCancel
}{\param{wxCommandEvent\&
}{event
}}
272 The default handler for the wxID
\_CANCEL identifier.
276 The function either calls
{\bf EndModal(wxID
\_CANCEL)
} if the dialog is modal, or
277 sets the return value to wxID
\_CANCEL and calls
{\bf Show(false)
} if the dialog is modeless.
281 \helpref{wxDialog::OnOK
}{wxdialogonok
},
\helpref{wxDialog::OnApply
}{wxdialogonapply
}
283 \membersection{wxDialog::OnOK
}\label{wxdialogonok
}
285 \func{void
}{OnOK
}{\param{wxCommandEvent\&
}{event
}}
287 The default handler for the wxID
\_OK identifier.
292 \rtfsp\helpref{wxWindow::Validate
}{wxwindowvalidate
}, then
\helpref{wxWindow::TransferDataFromWindow
}{wxwindowtransferdatafromwindow
}.
293 If this returns true, the function either calls
{\bf EndModal(wxID
\_OK)
} if the dialog is modal, or
294 sets the return value to wxID
\_OK and calls
{\bf Show(false)
} if the dialog is modeless.
298 \helpref{wxDialog::OnCancel
}{wxdialogoncancel
},
\helpref{wxDialog::OnApply
}{wxdialogonapply
}
300 \membersection{wxDialog::OnSysColourChanged
}\label{wxdialogonsyscolourchanged
}
302 \func{void
}{OnSysColourChanged
}{\param{wxSysColourChangedEvent\&
}{event
}}
304 The default handler for wxEVT
\_SYS\_COLOUR\_CHANGED.
306 \wxheading{Parameters
}
308 \docparam{event
}{The colour change event.
}
312 Changes the dialog's colour to conform to the current settings (Windows only).
313 Add an event table entry for your dialog class if you wish the behaviour
314 to be different (such as keeping a user-defined
315 background colour). If you do override this function, call wxEvent::Skip to
316 propagate the notification to child windows and controls.
320 \helpref{wxSysColourChangedEvent
}{wxsyscolourchangedevent
}
322 \membersection{wxDialog::SetIcon
}\label{wxdialogseticon
}
324 \func{void
}{SetIcon
}{\param{const wxIcon\&
}{icon
}}
326 Sets the icon for this dialog.
328 \wxheading{Parameters
}
330 \docparam{icon
}{The icon to associate with this dialog.
}
332 See also
\helpref{wxIcon
}{wxicon
}.
334 \membersection{wxDialog::SetIcons
}\label{wxdialogseticons
}
336 \func{void
}{SetIcons
}{\param{const wxIconBundle\&
}{icons
}}
338 Sets the icons for this dialog.
340 \wxheading{Parameters
}
342 \docparam{icons
}{The icons to associate with this dialog.
}
344 See also
\helpref{wxIconBundle
}{wxiconbundle
}.
346 \membersection{wxDialog::SetModal
}\label{wxdialogsetmodal
}
348 \func{void
}{SetModal
}{\param{const bool
}{ flag
}}
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.
353 Allows the programmer to specify whether the dialog box is modal (wxDialog::Show blocks control
354 until the dialog is hidden) or modeless (control returns immediately).
356 \wxheading{Parameters
}
358 \docparam{flag
}{If true, the dialog will be modal, otherwise it will be modeless.
}
360 \membersection{wxDialog::SetReturnCode
}\label{wxdialogsetreturncode
}
362 \func{void
}{SetReturnCode
}{\param{int
}{retCode
}}
364 Sets the return code for this window.
366 \wxheading{Parameters
}
368 \docparam{retCode
}{The integer return code, usually a control identifier.
}
372 A return code is normally associated with a modal dialog, where
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
} returns
373 a code to the application. The function
\helpref{wxDialog::EndModal
}{wxdialogendmodal
} calls
{\bf SetReturnCode
}.
377 \helpref{wxDialog::GetReturnCode
}{wxdialoggetreturncode
},
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
},
\rtfsp
378 \helpref{wxDialog::EndModal
}{wxdialogendmodal
}
380 \membersection{wxDialog::SetTitle
}\label{wxdialogsettitle
}
382 \func{void
}{SetTitle
}{\param{const wxString\&
}{ title
}}
384 Sets the title of the dialog box.
386 \wxheading{Parameters
}
388 \docparam{title
}{The dialog box title.
}
390 \membersection{wxDialog::Show
}\label{wxdialogshow
}
392 \func{bool
}{Show
}{\param{const bool
}{ show
}}
394 Hides or shows the dialog.
396 \wxheading{Parameters
}
398 \docparam{show
}{If true, the dialog box is shown and brought to the front;
399 otherwise the box is hidden. If false and the dialog is
400 modal, control is returned to the calling program.
}
404 The preferred way of dismissing a modal dialog is to use
\helpref{wxDialog::EndModal
}{wxdialogendmodal
}.
406 \membersection{wxDialog::ShowModal
}\label{wxdialogshowmodal
}
408 \func{int
}{ShowModal
}{\void}
410 Shows a modal dialog. Program flow does not return until the dialog has been dismissed with
\rtfsp
411 \helpref{wxDialog::EndModal
}{wxdialogendmodal
}.
413 \wxheading{Return value
}
415 The return value is the value set with
\helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
}.
419 \helpref{wxDialog::EndModal
}{wxdialogendmodal
},
\rtfsp
420 \helpref{wxDialog:GetReturnCode
}{wxdialoggetreturncode
},
\rtfsp
421 \helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
}