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 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
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:
34 MyAskDialog *dlg = new MyAskDialog(...);
35 if ( dlg->ShowModal() == wxID_OK )
37 //else: dialog was cancelled or some another button pressed
43 works, you can also achieve the same result by using a simpler code fragment
50 if ( dlg.ShowModal() == wxID_OK )
53 // no need to call Destroy() here
57 An application can define an
\helpref{wxCloseEvent
}{wxcloseevent
} handler for
58 the dialog to respond to system close events.
60 \wxheading{Window styles
}
63 \begin{twocollist
}\itemsep=
0pt
64 \twocolitem{\windowstyle{wxCAPTION
}}{Puts a caption on the dialog box.
}
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)
}
66 \twocolitem{\windowstyle{wxRESIZE
\_BORDER}}{Display a resizeable frame around the window.
}
67 \twocolitem{\windowstyle{wxSYSTEM
\_MENU}}{Display a system menu.
}
68 \twocolitem{\windowstyle{wxCLOSE
\_BOX}}{Displays a close box on the frame.
}
69 \twocolitem{\windowstyle{wxMAXIMIZE
\_BOX}}{Displays a maximize box on the dialog.
}
70 \twocolitem{\windowstyle{wxMINIMIZE
\_BOX}}{Displays a minimize box on the dialog.
}
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).
}
73 \twocolitem{\windowstyle{wxNO
\_3D}}{Under Windows, specifies that the child controls
74 should not have
3D borders unless specified in the control.
}
75 \twocolitem{\windowstyle{wxDIALOG
\_NO\_PARENT}}{By default, a dialog created
76 with a
{\tt NULL
} parent window will be given the
77 \helpref{application's top level window
}{wxappgettopwindow
} as parent. Use this
78 style to prevent this from happening and create an orphan dialog. This is not recommended for modal dialogs.
}
79 \twocolitem{\windowstyle{wxDIALOG
\_EX\_CONTEXTHELP}}{Under Windows, puts a query button on the
80 caption. When pressed, Windows will go into a context-sensitive help mode and wxWidgets will send
81 a wxEVT
\_HELP event if the user clicked on an application window.
{\it Note
}\ that this is an extended
82 style and must be set by calling
\helpref{SetExtraStyle
}{wxwindowsetextrastyle
} before Create is called (two-step construction).
}
85 Under Unix or Linux, MWM (the Motif Window Manager) or other window managers
86 recognizing the MHM hints should be running for any of these styles to have an
89 See also
\helpref{Generic window styles
}{windowstyles
}.
93 \helpref{wxDialog overview
}{wxdialogoverview
},
\helpref{wxFrame
}{wxframe
},
\rtfsp
94 \helpref{Validator overview
}{validatoroverview
}
96 \latexignore{\rtfignore{\wxheading{Members
}}}
98 \membersection{wxDialog::wxDialog
}\label{wxdialogconstr
}
100 \func{}{wxDialog
}{\void}
104 \func{}{wxDialog
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{id
},
\rtfsp
105 \param{const wxString\&
}{title
},
\rtfsp
106 \param{const wxPoint\&
}{pos = wxDefaultPosition
},
\rtfsp
107 \param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
108 \param{long
}{ style = wxDEFAULT
\_DIALOG\_STYLE},
\rtfsp
109 \param{const wxString\&
}{name = ``dialogBox"
}}
113 \wxheading{Parameters
}
115 \docparam{parent
}{Can be NULL, a frame or another dialog box.
}
117 \docparam{id
}{An identifier for the dialog. A value of -
1 is taken to mean a default.
}
119 \docparam{title
}{The title of the dialog.
}
121 \docparam{pos
}{The dialog position. A value of (-
1, -
1) indicates a default position, chosen by
122 either the windowing system or wxWidgets, depending on platform.
}
124 \docparam{size
}{The dialog size. A value of (-
1, -
1) indicates a default size, chosen by
125 either the windowing system or wxWidgets, depending on platform.
}
127 \docparam{style
}{The window style. See
\helpref{wxDialog
}{wxdialog
}.
}
129 \docparam{name
}{Used to associate a name with the window,
130 allowing the application user to set Motif resource values for
131 individual dialog boxes.
}
135 \helpref{wxDialog::Create
}{wxdialogcreate
}
137 \membersection{wxDialog::
\destruct{wxDialog
}}
139 \func{}{\destruct{wxDialog
}}{\void}
141 Destructor. Deletes any child windows before deleting the physical window.
143 \membersection{wxDialog::Centre
}\label{wxdialogcentre
}
145 \func{void
}{Centre
}{\param{int
}{ direction = wxBOTH
}}
147 Centres the dialog box on the display.
149 \wxheading{Parameters
}
151 \docparam{direction
}{May be
{\tt wxHORIZONTAL
},
{\tt wxVERTICAL
} or
{\tt wxBOTH
}.
}
153 \membersection{wxDialog::Create
}\label{wxdialogcreate
}
155 \func{bool
}{Create
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{id
},
\rtfsp
156 \param{const wxString\&
}{title
},
\rtfsp
157 \param{const wxPoint\&
}{pos = wxDefaultPosition
},
\rtfsp
158 \param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
159 \param{long
}{ style = wxDEFAULT
\_DIALOG\_STYLE},
\rtfsp
160 \param{const wxString\&
}{name = ``dialogBox"
}}
162 Used for two-step dialog box construction. See
\helpref{wxDialog::wxDialog
}{wxdialogconstr
}\rtfsp
165 \membersection{wxDialog::EndModal
}\label{wxdialogendmodal
}
167 \func{void
}{EndModal
}{\param{int
}{retCode
}}
169 Ends a modal dialog, passing a value to be returned from the
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
}\rtfsp
172 \wxheading{Parameters
}
174 \docparam{retCode
}{The value that should be returned by
{\bf ShowModal
}.
}
178 \helpref{wxDialog::ShowModal
}{wxdialogshowmodal
},
\rtfsp
179 \helpref{wxDialog::GetReturnCode
}{wxdialoggetreturncode
},
\rtfsp
180 \helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
}
182 \membersection{wxDialog::GetReturnCode
}\label{wxdialoggetreturncode
}
184 \func{int
}{GetReturnCode
}{\void}
186 Gets the return code for this window.
190 A return code is normally associated with a modal dialog, where
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
} returns
191 a code to the application.
195 \helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
},
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
},
\rtfsp
196 \helpref{wxDialog::EndModal
}{wxdialogendmodal
}
198 \membersection{wxDialog::GetTitle
}\label{wxdialoggettitle
}
200 \constfunc{wxString
}{GetTitle
}{\void}
202 Returns the title of the dialog box.
204 \membersection{wxDialog::Iconize
}\label{wxdialogiconized
}
206 \func{void
}{Iconize
}{\param{const bool
}{ iconize
}}
208 Iconizes or restores the dialog. Windows only.
210 \wxheading{Parameters
}
212 \docparam{iconize
}{If true, iconizes the dialog box; if false, shows and restores it.
}
216 Note that in Windows, iconization has no effect since dialog boxes cannot be
217 iconized. However, applications may need to explicitly restore dialog
218 boxes under Motif which have user-iconizable frames, and under Windows
219 calling
{\tt Iconize(false)
} will bring the window to the front, as does
220 \rtfsp{\tt Show(true)
}.
222 \membersection{wxDialog::IsIconized
}\label{wxdialogisiconized
}
224 \constfunc{bool
}{IsIconized
}{\void}
226 Returns true if the dialog box is iconized. Windows only.
230 Always returns false under Windows since dialogs cannot be iconized.
232 \membersection{wxDialog::IsModal
}\label{wxdialogismodal
}
234 \constfunc{bool
}{IsModal
}{\void}
236 Returns true if the dialog box is modal, false otherwise.
238 \membersection{wxDialog::OnCharHook
}\label{wxdialogoncharhook
}
240 \func{void
}{OnCharHook
}{\param{wxKeyEvent\&
}{ event
}}
242 This member is called to allow the window to intercept keyboard events
243 before they are processed by child windows.
245 %For more information, see \helpref{wxWindow::OnCharHook}{wxwindowoncharhook}
249 wxDialog implements this handler to fake a cancel command if the escape key has been
250 pressed. This will dismiss the dialog.
252 \membersection{wxDialog::OnApply
}\label{wxdialogonapply
}
254 \func{void
}{OnApply
}{\param{wxCommandEvent\&
}{event
}}
256 The default handler for the wxID
\_APPLY identifier.
260 This function calls
\helpref{wxWindow::Validate
}{wxwindowvalidate
} and
\helpref{wxWindow::TransferDataToWindow
}{wxwindowtransferdatatowindow
}.
264 \helpref{wxDialog::OnOK
}{wxdialogonok
},
\helpref{wxDialog::OnCancel
}{wxdialogoncancel
}
266 \membersection{wxDialog::OnCancel
}\label{wxdialogoncancel
}
268 \func{void
}{OnCancel
}{\param{wxCommandEvent\&
}{event
}}
270 The default handler for the wxID
\_CANCEL identifier.
274 The function either calls
{\bf EndModal(wxID
\_CANCEL)
} if the dialog is modal, or
275 sets the return value to wxID
\_CANCEL and calls
{\bf Show(false)
} if the dialog is modeless.
279 \helpref{wxDialog::OnOK
}{wxdialogonok
},
\helpref{wxDialog::OnApply
}{wxdialogonapply
}
281 \membersection{wxDialog::OnOK
}\label{wxdialogonok
}
283 \func{void
}{OnOK
}{\param{wxCommandEvent\&
}{event
}}
285 The default handler for the wxID
\_OK identifier.
290 \rtfsp\helpref{wxWindow::Validate
}{wxwindowvalidate
}, then
\helpref{wxWindow::TransferDataFromWindow
}{wxwindowtransferdatafromwindow
}.
291 If this returns true, the function either calls
{\bf EndModal(wxID
\_OK)
} if the dialog is modal, or
292 sets the return value to wxID
\_OK and calls
{\bf Show(false)
} if the dialog is modeless.
296 \helpref{wxDialog::OnCancel
}{wxdialogoncancel
},
\helpref{wxDialog::OnApply
}{wxdialogonapply
}
298 \membersection{wxDialog::OnSysColourChanged
}\label{wxdialogonsyscolourchanged
}
300 \func{void
}{OnSysColourChanged
}{\param{wxSysColourChangedEvent\&
}{event
}}
302 The default handler for wxEVT
\_SYS\_COLOUR\_CHANGED.
304 \wxheading{Parameters
}
306 \docparam{event
}{The colour change event.
}
310 Changes the dialog's colour to conform to the current settings (Windows only).
311 Add an event table entry for your dialog class if you wish the behaviour
312 to be different (such as keeping a user-defined
313 background colour). If you do override this function, call wxEvent::Skip to
314 propagate the notification to child windows and controls.
318 \helpref{wxSysColourChangedEvent
}{wxsyscolourchangedevent
}
320 \membersection{wxDialog::SetIcon
}\label{wxdialogseticon
}
322 \func{void
}{SetIcon
}{\param{const wxIcon\&
}{icon
}}
324 Sets the icon for this dialog.
326 \wxheading{Parameters
}
328 \docparam{icon
}{The icon to associate with this dialog.
}
330 See also
\helpref{wxIcon
}{wxicon
}.
332 \membersection{wxDialog::SetIcons
}\label{wxdialogseticons
}
334 \func{void
}{SetIcons
}{\param{const wxIconBundle\&
}{icons
}}
336 Sets the icons for this dialog.
338 \wxheading{Parameters
}
340 \docparam{icons
}{The icons to associate with this dialog.
}
342 See also
\helpref{wxIconBundle
}{wxiconbundle
}.
344 \membersection{wxDialog::SetModal
}\label{wxdialogsetmodal
}
346 \func{void
}{SetModal
}{\param{const bool
}{ flag
}}
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.
351 Allows the programmer to specify whether the dialog box is modal (wxDialog::Show blocks control
352 until the dialog is hidden) or modeless (control returns immediately).
354 \wxheading{Parameters
}
356 \docparam{flag
}{If true, the dialog will be modal, otherwise it will be modeless.
}
358 \membersection{wxDialog::SetReturnCode
}\label{wxdialogsetreturncode
}
360 \func{void
}{SetReturnCode
}{\param{int
}{retCode
}}
362 Sets the return code for this window.
364 \wxheading{Parameters
}
366 \docparam{retCode
}{The integer return code, usually a control identifier.
}
370 A return code is normally associated with a modal dialog, where
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
} returns
371 a code to the application. The function
\helpref{wxDialog::EndModal
}{wxdialogendmodal
} calls
{\bf SetReturnCode
}.
375 \helpref{wxDialog::GetReturnCode
}{wxdialoggetreturncode
},
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
},
\rtfsp
376 \helpref{wxDialog::EndModal
}{wxdialogendmodal
}
378 \membersection{wxDialog::SetTitle
}\label{wxdialogsettitle
}
380 \func{void
}{SetTitle
}{\param{const wxString\&
}{ title
}}
382 Sets the title of the dialog box.
384 \wxheading{Parameters
}
386 \docparam{title
}{The dialog box title.
}
388 \membersection{wxDialog::Show
}\label{wxdialogshow
}
390 \func{bool
}{Show
}{\param{const bool
}{ show
}}
392 Hides or shows the dialog.
394 \wxheading{Parameters
}
396 \docparam{show
}{If true, the dialog box is shown and brought to the front;
397 otherwise the box is hidden. If false and the dialog is
398 modal, control is returned to the calling program.
}
402 The preferred way of dismissing a modal dialog is to use
\helpref{wxDialog::EndModal
}{wxdialogendmodal
}.
404 \membersection{wxDialog::ShowModal
}\label{wxdialogshowmodal
}
406 \func{int
}{ShowModal
}{\void}
408 Shows a modal dialog. Program flow does not return until the dialog has been dismissed with
\rtfsp
409 \helpref{wxDialog::EndModal
}{wxdialogendmodal
}.
411 \wxheading{Return value
}
413 The return value is the value set with
\helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
}.
417 \helpref{wxDialog::EndModal
}{wxdialogendmodal
},
\rtfsp
418 \helpref{wxDialog:GetReturnCode
}{wxdialoggetreturncode
},
\rtfsp
419 \helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
}