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
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 An application can define an
\helpref{wxCloseEvent
}{wxcloseevent
} handler for
55 the dialog to respond to system close events.
57 \wxheading{Window styles
}
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).
}
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
86 See also
\helpref{Generic window styles
}{windowstyles
}.
90 \helpref{wxDialog overview
}{wxdialogoverview
},
\helpref{wxFrame
}{wxframe
},
\rtfsp
91 \helpref{Validator overview
}{validatoroverview
}
93 \latexignore{\rtfignore{\wxheading{Members
}}}
95 \membersection{wxDialog::wxDialog
}\label{wxdialogconstr
}
97 \func{}{wxDialog
}{\void}
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"
}}
110 \wxheading{Parameters
}
112 \docparam{parent
}{Can be NULL, a frame or another dialog box.
}
114 \docparam{id
}{An identifier for the dialog. A value of -
1 is taken to mean a default.
}
116 \docparam{title
}{The title of the dialog.
}
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.
}
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.
}
124 \docparam{style
}{The window style. See
\helpref{wxDialog
}{wxdialog
}.
}
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.
}
132 \helpref{wxDialog::Create
}{wxdialogcreate
}
134 \membersection{wxDialog::
\destruct{wxDialog
}}
136 \func{}{\destruct{wxDialog
}}{\void}
138 Destructor. Deletes any child windows before deleting the physical window.
140 \membersection{wxDialog::Centre
}\label{wxdialogcentre
}
142 \func{void
}{Centre
}{\param{int
}{ direction = wxBOTH
}}
144 Centres the dialog box on the display.
146 \wxheading{Parameters
}
148 \docparam{direction
}{May be
{\tt wxHORIZONTAL
},
{\tt wxVERTICAL
} or
{\tt wxBOTH
}.
}
150 \membersection{wxDialog::Create
}\label{wxdialogcreate
}
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"
}}
159 Used for two-step dialog box construction. See
\helpref{wxDialog::wxDialog
}{wxdialogconstr
}\rtfsp
162 \membersection{wxDialog::EndModal
}\label{wxdialogendmodal
}
164 \func{void
}{EndModal
}{\param{int
}{retCode
}}
166 Ends a modal dialog, passing a value to be returned from the
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
}\rtfsp
169 \wxheading{Parameters
}
171 \docparam{retCode
}{The value that should be returned by
{\bf ShowModal
}.
}
175 \helpref{wxDialog::ShowModal
}{wxdialogshowmodal
},
\rtfsp
176 \helpref{wxDialog::GetReturnCode
}{wxdialoggetreturncode
},
\rtfsp
177 \helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
}
179 \membersection{wxDialog::GetReturnCode
}\label{wxdialoggetreturncode
}
181 \func{int
}{GetReturnCode
}{\void}
183 Gets the return code for this window.
187 A return code is normally associated with a modal dialog, where
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
} returns
188 a code to the application.
192 \helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
},
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
},
\rtfsp
193 \helpref{wxDialog::EndModal
}{wxdialogendmodal
}
195 \membersection{wxDialog::GetTitle
}\label{wxdialoggettitle
}
197 \constfunc{wxString
}{GetTitle
}{\void}
199 Returns the title of the dialog box.
201 \membersection{wxDialog::Iconize
}\label{wxdialogiconized
}
203 \func{void
}{Iconize
}{\param{const bool
}{ iconize
}}
205 Iconizes or restores the dialog. Windows only.
207 \wxheading{Parameters
}
209 \docparam{iconize
}{If true, iconizes the dialog box; if false, shows and restores it.
}
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)
}.
219 \membersection{wxDialog::IsIconized
}\label{wxdialogisiconized
}
221 \constfunc{bool
}{IsIconized
}{\void}
223 Returns true if the dialog box is iconized. Windows only.
227 Always returns false under Windows since dialogs cannot be iconized.
229 \membersection{wxDialog::IsModal
}\label{wxdialogismodal
}
231 \constfunc{bool
}{IsModal
}{\void}
233 Returns true if the dialog box is modal, false otherwise.
235 \membersection{wxDialog::OnCharHook
}\label{wxdialogoncharhook
}
237 \func{void
}{OnCharHook
}{\param{wxKeyEvent\&
}{ event
}}
239 This member is called to allow the window to intercept keyboard events
240 before they are processed by child windows.
242 %For more information, see \helpref{wxWindow::OnCharHook}{wxwindowoncharhook}
246 wxDialog implements this handler to fake a cancel command if the escape key has been
247 pressed. This will dismiss the dialog.
249 \membersection{wxDialog::OnApply
}\label{wxdialogonapply
}
251 \func{void
}{OnApply
}{\param{wxCommandEvent\&
}{event
}}
253 The default handler for the wxID
\_APPLY identifier.
257 This function calls
\helpref{wxWindow::Validate
}{wxwindowvalidate
} and
\helpref{wxWindow::TransferDataToWindow
}{wxwindowtransferdatatowindow
}.
261 \helpref{wxDialog::OnOK
}{wxdialogonok
},
\helpref{wxDialog::OnCancel
}{wxdialogoncancel
}
263 \membersection{wxDialog::OnCancel
}\label{wxdialogoncancel
}
265 \func{void
}{OnCancel
}{\param{wxCommandEvent\&
}{event
}}
267 The default handler for the wxID
\_CANCEL identifier.
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.
276 \helpref{wxDialog::OnOK
}{wxdialogonok
},
\helpref{wxDialog::OnApply
}{wxdialogonapply
}
278 \membersection{wxDialog::OnOK
}\label{wxdialogonok
}
280 \func{void
}{OnOK
}{\param{wxCommandEvent\&
}{event
}}
282 The default handler for the wxID
\_OK identifier.
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.
293 \helpref{wxDialog::OnCancel
}{wxdialogoncancel
},
\helpref{wxDialog::OnApply
}{wxdialogonapply
}
295 \membersection{wxDialog::OnSysColourChanged
}\label{wxdialogonsyscolourchanged
}
297 \func{void
}{OnSysColourChanged
}{\param{wxSysColourChangedEvent\&
}{event
}}
299 The default handler for wxEVT
\_SYS\_COLOUR\_CHANGED.
301 \wxheading{Parameters
}
303 \docparam{event
}{The colour change event.
}
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.
315 \helpref{wxSysColourChangedEvent
}{wxsyscolourchangedevent
}
317 \membersection{wxDialog::SetIcon
}\label{wxdialogseticon
}
319 \func{void
}{SetIcon
}{\param{const wxIcon\&
}{icon
}}
321 Sets the icon for this dialog.
323 \wxheading{Parameters
}
325 \docparam{icon
}{The icon to associate with this dialog.
}
327 See also
\helpref{wxIcon
}{wxicon
}.
329 \membersection{wxDialog::SetIcons
}\label{wxdialogseticons
}
331 \func{void
}{SetIcons
}{\param{const wxIconBundle\&
}{icons
}}
333 Sets the icons for this dialog.
335 \wxheading{Parameters
}
337 \docparam{icons
}{The icons to associate with this dialog.
}
339 See also
\helpref{wxIconBundle
}{wxiconbundle
}.
341 \membersection{wxDialog::SetModal
}\label{wxdialogsetmodal
}
343 \func{void
}{SetModal
}{\param{const bool
}{ flag
}}
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.
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).
351 \wxheading{Parameters
}
353 \docparam{flag
}{If true, the dialog will be modal, otherwise it will be modeless.
}
355 \membersection{wxDialog::SetReturnCode
}\label{wxdialogsetreturncode
}
357 \func{void
}{SetReturnCode
}{\param{int
}{retCode
}}
359 Sets the return code for this window.
361 \wxheading{Parameters
}
363 \docparam{retCode
}{The integer return code, usually a control identifier.
}
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
}.
372 \helpref{wxDialog::GetReturnCode
}{wxdialoggetreturncode
},
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
},
\rtfsp
373 \helpref{wxDialog::EndModal
}{wxdialogendmodal
}
375 \membersection{wxDialog::SetTitle
}\label{wxdialogsettitle
}
377 \func{void
}{SetTitle
}{\param{const wxString\&
}{ title
}}
379 Sets the title of the dialog box.
381 \wxheading{Parameters
}
383 \docparam{title
}{The dialog box title.
}
385 \membersection{wxDialog::Show
}\label{wxdialogshow
}
387 \func{bool
}{Show
}{\param{const bool
}{ show
}}
389 Hides or shows the dialog.
391 \wxheading{Parameters
}
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.
}
399 The preferred way of dismissing a modal dialog is to use
\helpref{wxDialog::EndModal
}{wxdialogendmodal
}.
401 \membersection{wxDialog::ShowModal
}\label{wxdialogshowmodal
}
403 \func{int
}{ShowModal
}{\void}
405 Shows a modal dialog. Program flow does not return until the dialog has been dismissed with
\rtfsp
406 \helpref{wxDialog::EndModal
}{wxdialogendmodal
}.
408 \wxheading{Return value
}
410 The return value is the value set with
\helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
}.
414 \helpref{wxDialog::EndModal
}{wxdialogendmodal
},
\rtfsp
415 \helpref{wxDialog:GetReturnCode
}{wxdialoggetreturncode
},
\rtfsp
416 \helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
}