1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% Purpose: wxDialog documentation
4 %% Author: wxWidgets Team
8 %% Copyright: (c) wxWidgets Team
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 \section{\class{wxDialog
}}\label{wxdialog
}
14 A dialog box is a window with a title bar and sometimes a system menu, which
15 can be moved around the screen. It can contain controls and other windows and
16 is often used to allow the user to make some choice or to answer a question.
19 \wxheading{Dialog Buttons
}
21 The dialog usually contains either a single button allowing to close the
22 dialog or two buttons, one accepting the changes and the other one discarding
23 them (such button, if present, is automatically activated if the user presses
24 the
\texttt{"Esc"
} key). By default, buttons with the standard
\texttt{wxID
\_OK}
25 and
\texttt{wxID
\_CANCEL} identifiers behave as expected. Starting with
26 wxWidgets
2.7 it is also possible to use a button with a different identifier
27 instead, see
\helpref{SetAffirmativeId
}{wxdialogsetaffirmativeid
} and
28 \helpref{SetEscapeId
}{wxdialogsetescapeid
}.
30 Also notice that the
\helpref{CreateButtonSizer()
}{wxdialogcreatebuttonsizer
}
31 should be used to create the buttons appropriate for the current platform and
32 positioned correctly (including their order which is platform-dependent).
36 \wxheading{Derived from
}
38 \helpref{wxTopLevelWindow
}{wxtoplevelwindow
}\\
39 \helpref{wxWindow
}{wxwindow
}\\
40 \helpref{wxEvtHandler
}{wxevthandler
}\\
41 \helpref{wxObject
}{wxobject
}
43 \wxheading{Include files
}
47 \wxheading{Modal and modeless dialogs
}
49 There are two kinds of dialog --
{\it modal
}\ and
{\it modeless
}. A modal dialog
50 blocks program flow and user input on other windows until it is dismissed,
51 whereas a modeless dialog behaves more like a frame in that program flow
52 continues, and input in other windows is still possible. To show a modal dialog
53 you should use the
\helpref{ShowModal
}{wxdialogshowmodal
} method while to show
54 a dialog modelessly you simply use
\helpref{Show
}{wxdialogshow
}, just as with
57 Note that the modal dialog is one of the very few examples of
58 wxWindow-derived objects which may be created on the stack and not on the heap.
59 In other words, although this code snippet:
64 MyAskDialog *dlg = new MyAskDialog(...);
65 if ( dlg->ShowModal() == wxID_OK )
67 //else: dialog was cancelled or some another button pressed
73 works, you can also achieve the same result by using a simpler code fragment
80 if ( dlg.ShowModal() == wxID_OK )
83 // no need to call Destroy() here
87 An application can define a
\helpref{wxCloseEvent
}{wxcloseevent
} handler for
88 the dialog to respond to system close events.
90 \wxheading{Window styles
}
93 \begin{twocollist
}\itemsep=
0pt
94 \twocolitem{\windowstyle{wxCAPTION
}}{Puts a caption on the dialog box.
}
95 \twocolitem{\windowstyle{wxDEFAULT
\_DIALOG\_STYLE}}{Equivalent to a combination of wxCAPTION, wxCLOSE
\_BOX and wxSYSTEM
\_MENU (the last one is not used under Unix)
}
96 \twocolitem{\windowstyle{wxRESIZE
\_BORDER}}{Display a resizeable frame around the window.
}
97 \twocolitem{\windowstyle{wxSYSTEM
\_MENU}}{Display a system menu.
}
98 \twocolitem{\windowstyle{wxCLOSE
\_BOX}}{Displays a close box on the frame.
}
99 \twocolitem{\windowstyle{wxMAXIMIZE
\_BOX}}{Displays a maximize box on the dialog.
}
100 \twocolitem{\windowstyle{wxMINIMIZE
\_BOX}}{Displays a minimize box on the dialog.
}
101 \twocolitem{\windowstyle{wxTHICK
\_FRAME}}{Display a thick frame around the window.
}
102 \twocolitem{\windowstyle{wxSTAY
\_ON\_TOP}}{The dialog stays on top of all other windows.
}
103 \twocolitem{\windowstyle{wxNO
\_3D}}{Under Windows, specifies that the child controls
104 should not have
3D borders unless specified in the control.
}
105 \twocolitem{\windowstyle{wxDIALOG
\_NO\_PARENT}}{By default, a dialog created
106 with a
{\tt NULL
} parent window will be given the
107 \helpref{application's top level window
}{wxappgettopwindow
} as parent. Use this
108 style to prevent this from happening and create an orphan dialog. This is not recommended for modal dialogs.
}
109 \twocolitem{\windowstyle{wxDIALOG
\_EX\_CONTEXTHELP}}{Under Windows, puts a query button on the
110 caption. When pressed, Windows will go into a context-sensitive help mode and wxWidgets will send
111 a wxEVT
\_HELP event if the user clicked on an application window.
{\it Note
}\ that this is an extended
112 style and must be set by calling
\helpref{SetExtraStyle
}{wxwindowsetextrastyle
} before Create is called (two-step construction).
}
113 \twocolitem{\windowstyle{wxDIALOG
\_EX\_METAL}}{On Mac OS X, frames with this style will be shown with a metallic look. This is an
{\it extra
} style.
}
116 Under Unix or Linux, MWM (the Motif Window Manager) or other window managers
117 recognizing the MHM hints should be running for any of these styles to have an
120 See also
\helpref{Generic window styles
}{windowstyles
}.
124 \helpref{wxDialog overview
}{wxdialogoverview
},
\helpref{wxFrame
}{wxframe
},
\rtfsp
125 \helpref{Validator overview
}{validatoroverview
}
127 \latexignore{\rtfignore{\wxheading{Members
}}}
130 \membersection{wxDialog::wxDialog
}\label{wxdialogctor
}
132 \func{}{wxDialog
}{\void}
136 \func{}{wxDialog
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{id
},
\rtfsp
137 \param{const wxString\&
}{title
},
\rtfsp
138 \param{const wxPoint\&
}{pos = wxDefaultPosition
},
\rtfsp
139 \param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
140 \param{long
}{ style = wxDEFAULT
\_DIALOG\_STYLE},
\rtfsp
141 \param{const wxString\&
}{name = ``dialogBox"
}}
145 \wxheading{Parameters
}
147 \docparam{parent
}{Can be NULL, a frame or another dialog box.
}
149 \docparam{id
}{An identifier for the dialog. A value of -
1 is taken to mean a default.
}
151 \docparam{title
}{The title of the dialog.
}
153 \docparam{pos
}{The dialog position. A value of (-
1, -
1) indicates a default position, chosen by
154 either the windowing system or wxWidgets, depending on platform.
}
156 \docparam{size
}{The dialog size. A value of (-
1, -
1) indicates a default size, chosen by
157 either the windowing system or wxWidgets, depending on platform.
}
159 \docparam{style
}{The window style. See
\helpref{wxDialog
}{wxdialog
}.
}
161 \docparam{name
}{Used to associate a name with the window,
162 allowing the application user to set Motif resource values for
163 individual dialog boxes.
}
167 \helpref{wxDialog::Create
}{wxdialogcreate
}
170 \membersection{wxDialog::
\destruct{wxDialog
}}\label{wxdialogdtor
}
172 \func{}{\destruct{wxDialog
}}{\void}
174 Destructor. Deletes any child windows before deleting the physical window.
177 \membersection{wxDialog::Centre
}\label{wxdialogcentre
}
179 \func{void
}{Centre
}{\param{int
}{ direction = wxBOTH
}}
181 Centres the dialog box on the display.
183 \wxheading{Parameters
}
185 \docparam{direction
}{May be
{\tt wxHORIZONTAL
},
{\tt wxVERTICAL
} or
{\tt wxBOTH
}.
}
188 \membersection{wxDialog::Create
}\label{wxdialogcreate
}
190 \func{bool
}{Create
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{id
},
\rtfsp
191 \param{const wxString\&
}{title
},
\rtfsp
192 \param{const wxPoint\&
}{pos = wxDefaultPosition
},
\rtfsp
193 \param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
194 \param{long
}{ style = wxDEFAULT
\_DIALOG\_STYLE},
\rtfsp
195 \param{const wxString\&
}{name = ``dialogBox"
}}
197 Used for two-step dialog box construction. See
\helpref{wxDialog::wxDialog
}{wxdialogctor
}\rtfsp
201 \membersection{wxDialog::CreateButtonSizer
}\label{wxdialogcreatebuttonsizer
}
203 \func{wxSizer*
}{CreateButtonSizer
}{\param{long
}{ flags
}}
205 Creates a sizer with standard buttons.
{\it flags
} is a bit list
206 of the following flags: wxOK, wxCANCEL, wxYES, wxNO, wxAPPLY, wxCLOSE,
207 wxHELP, wxNO
\_DEFAULT.
209 The sizer lays out the buttons in a manner appropriate to the platform.
211 This function uses
\helpref{CreateStdDialogButtonSizer
}{wxdialogcreatestddialogbuttonsizer
}
212 internally for most platforms but doesn't create the sizer at all for the
213 platforms with hardware buttons (such as smartphones) for which it sets up the
214 hardware buttons appropriately and returns
\NULL, so don't forget to test that
215 the return value is valid before using it.
218 \membersection{wxDialog::CreateSeparatedButtonSizer
}\label{wxdialogcreateseparatedbuttonsizer
}
220 \func{wxSizer*
}{CreateSeparatedButtonSizer
}{\param{long
}{ flags
}}
222 Creates a sizer with standard buttons using
223 \helpref{CreateButtonSizer
}{wxdialogcreatebuttonsizer
} separated from the rest
224 of the dialog contents by a horizontal
\helpref{wxStaticLine
}{wxstaticline
}.
226 Please notice that just like CreateButtonSizer() this function may return
\NULL
227 if no buttons were created.
230 \membersection{wxDialog::CreateStdDialogButtonSizer
}\label{wxdialogcreatestddialogbuttonsizer
}
232 \func{wxStdDialogButtonSizer*
}{CreateStdDialogButtonSizer
}{\param{long
}{ flags
}}
234 Creates a
\helpref{wxStdDialogButtonSizer
}{wxstddialogbuttonsizer
} with standard buttons.
{\it flags
} is a bit list
235 of the following flags: wxOK, wxCANCEL, wxYES, wxNO, wxAPPLY, wxCLOSE,
236 wxHELP, wxNO
\_DEFAULT.
238 The sizer lays out the buttons in a manner appropriate to the platform.
241 \membersection{wxDialog::DoOK
}\label{wxdialogdook
}
243 \func{virtual bool
}{DoOK
}{\void}
245 This function is called when the titlebar OK button is pressed (PocketPC only).
246 A command event for the identifier returned by GetAffirmativeId is sent by
247 default. You can override this function. If the function returns false, wxWidgets
248 will call Close() for the dialog.
251 \membersection{wxDialog::EndModal
}\label{wxdialogendmodal
}
253 \func{void
}{EndModal
}{\param{int
}{retCode
}}
255 Ends a modal dialog, passing a value to be returned from the
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
}\rtfsp
258 \wxheading{Parameters
}
260 \docparam{retCode
}{The value that should be returned by
{\bf ShowModal
}.
}
264 \helpref{wxDialog::ShowModal
}{wxdialogshowmodal
},
\rtfsp
265 \helpref{wxDialog::GetReturnCode
}{wxdialoggetreturncode
},
\rtfsp
266 \helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
}
269 \membersection{wxDialog::GetAffirmativeId
}\label{wxdialoggetaffirmativeid
}
271 \constfunc{int
}{GetAffirmativeId
}{\void}
273 Gets the identifier of the button which works like standard OK button in this
278 \helpref{wxDialog::SetAffirmativeId
}{wxdialogsetaffirmativeid
}
281 \membersection{wxDialog::GetEscapeId
}\label{wxdialoggetescapeid
}
283 \constfunc{int
}{GetEscapeId
}{\void}
285 Gets the identifier of the button to map presses of
\texttt{\textsc{ESC
}}
290 \helpref{wxDialog::SetEscapeId
}{wxdialogsetescapeid
}
293 \membersection{wxDialog::GetReturnCode
}\label{wxdialoggetreturncode
}
295 \func{int
}{GetReturnCode
}{\void}
297 Gets the return code for this window.
301 A return code is normally associated with a modal dialog, where
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
} returns
302 a code to the application.
306 \helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
},
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
},
\rtfsp
307 \helpref{wxDialog::EndModal
}{wxdialogendmodal
}
310 \membersection{wxDialog::GetToolBar
}\label{wxdialoggettoolbar
}
312 \constfunc{wxToolBar*
}{GetToolBar
}{\void}
314 On PocketPC, a dialog is automatically provided with an empty toolbar. GetToolBar
315 allows you to access the toolbar and add tools to it. Removing tools and adding
316 arbitrary controls are not currently supported.
318 This function is not available on any other platform.
321 \membersection{wxDialog::Iconize
}\label{wxdialogiconized
}
323 \func{void
}{Iconize
}{\param{bool
}{ iconize
}}
325 Iconizes or restores the dialog. Windows only.
327 \wxheading{Parameters
}
329 \docparam{iconize
}{If true, iconizes the dialog box; if false, shows and restores it.
}
333 Note that in Windows, iconization has no effect since dialog boxes cannot be
334 iconized. However, applications may need to explicitly restore dialog
335 boxes under Motif which have user-iconizable frames, and under Windows
336 calling
{\tt Iconize(false)
} will bring the window to the front, as does
337 \rtfsp{\tt Show(true)
}.
340 \membersection{wxDialog::IsIconized
}\label{wxdialogisiconized
}
342 \constfunc{bool
}{IsIconized
}{\void}
344 Returns true if the dialog box is iconized. Windows only.
348 Always returns false under Windows since dialogs cannot be iconized.
351 \membersection{wxDialog::IsModal
}\label{wxdialogismodal
}
353 \constfunc{bool
}{IsModal
}{\void}
355 Returns true if the dialog box is modal, false otherwise.
359 \membersection{wxDialog::OnSysColourChanged
}\label{wxdialogonsyscolourchanged
}
361 \func{void
}{OnSysColourChanged
}{\param{wxSysColourChangedEvent\&
}{event
}}
363 The default handler for wxEVT
\_SYS\_COLOUR\_CHANGED.
365 \wxheading{Parameters
}
367 \docparam{event
}{The colour change event.
}
371 Changes the dialog's colour to conform to the current settings (Windows only).
372 Add an event table entry for your dialog class if you wish the behaviour
373 to be different (such as keeping a user-defined
374 background colour). If you do override this function, call wxEvent::Skip to
375 propagate the notification to child windows and controls.
379 \helpref{wxSysColourChangedEvent
}{wxsyscolourchangedevent
}
382 \membersection{wxDialog::SetAffirmativeId
}\label{wxdialogsetaffirmativeid
}
384 \func{void
}{SetAffirmativeId
}{\param{int
}{id
}}
386 Sets the identifier to be used as OK button. When the button with this
387 identifier is pressed, the dialog calls
\helpref{Validate
}{wxwindowvalidate
}
388 and
\helpref{wxWindow::TransferDataFromWindow
}{wxwindowtransferdatafromwindow
}
389 and, if they both return
\true, closes the dialog with
\texttt{wxID
\_OK} return
392 Also, when the user presses a hardware OK button on the devices having one or
393 the special OK button in the PocketPC title bar, an event with this id is
396 By default, the affirmative id is wxID
\_OK.
400 \helpref{wxDialog::GetAffirmativeId
}{wxdialoggetaffirmativeid
},
\helpref{wxDialog::SetEscapeId
}{wxdialogsetescapeid
}
403 \membersection{wxDialog::SetEscapeId
}\label{wxdialogsetescapeid
}
405 \func{void
}{SetEscapeId
}{\param{int
}{id
}}
407 Sets the identifier of the button which should work like the standard
408 \texttt{\textsc{Cancel
}} button in this dialog. When the button with this id is
409 clicked, the dialog is closed. Also, when the user presses
\texttt{\textsc{ESC
}}
410 key in the dialog or closes the dialog using the close button in the title bar,
411 this is mapped to the click of the button with the specified id.
413 By default, the escape id is the special value
\texttt{wxID
\_ANY} meaning that
414 \texttt{wxID
\_CANCEL} button is used if it's present in the dialog and
415 otherwise the button with
\helpref{GetAffirmativeId()
}{wxdialoggetaffirmativeid
}
416 is used. Another special value for
\arg{id
} is
\texttt{wxID
\_NONE} meaning that
417 \texttt{\textsc{ESC
}} presses should be ignored. If any other value is given, it
418 is interpreted as the id of the button to map the escape key to.
421 \membersection{wxDialog::SetIcon
}\label{wxdialogseticon
}
423 \func{void
}{SetIcon
}{\param{const wxIcon\&
}{icon
}}
425 Sets the icon for this dialog.
427 \wxheading{Parameters
}
429 \docparam{icon
}{The icon to associate with this dialog.
}
431 See also
\helpref{wxIcon
}{wxicon
}.
434 \membersection{wxDialog::SetIcons
}\label{wxdialogseticons
}
436 \func{void
}{SetIcons
}{\param{const wxIconBundle\&
}{icons
}}
438 Sets the icons for this dialog.
440 \wxheading{Parameters
}
442 \docparam{icons
}{The icons to associate with this dialog.
}
444 See also
\helpref{wxIconBundle
}{wxiconbundle
}.
447 \membersection{wxDialog::SetModal
}\label{wxdialogsetmodal
}
449 \func{void
}{SetModal
}{\param{bool
}{ flag
}}
451 {\bf NB:
} This function is deprecated and doesn't work for all ports, just use
452 \helpref{ShowModal
}{wxdialogshowmodal
} to show a modal dialog instead.
454 Allows the programmer to specify whether the dialog box is modal (wxDialog::Show blocks control
455 until the dialog is hidden) or modeless (control returns immediately).
457 \wxheading{Parameters
}
459 \docparam{flag
}{If true, the dialog will be modal, otherwise it will be modeless.
}
462 \membersection{wxDialog::SetReturnCode
}\label{wxdialogsetreturncode
}
464 \func{void
}{SetReturnCode
}{\param{int
}{retCode
}}
466 Sets the return code for this window.
468 \wxheading{Parameters
}
470 \docparam{retCode
}{The integer return code, usually a control identifier.
}
474 A return code is normally associated with a modal dialog, where
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
} returns
475 a code to the application. The function
\helpref{wxDialog::EndModal
}{wxdialogendmodal
} calls
{\bf SetReturnCode
}.
479 \helpref{wxDialog::GetReturnCode
}{wxdialoggetreturncode
},
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
},
\rtfsp
480 \helpref{wxDialog::EndModal
}{wxdialogendmodal
}
483 \membersection{wxDialog::Show
}\label{wxdialogshow
}
485 \func{bool
}{Show
}{\param{bool
}{ show
}}
487 Hides or shows the dialog.
489 \wxheading{Parameters
}
491 \docparam{show
}{If true, the dialog box is shown and brought to the front;
492 otherwise the box is hidden. If false and the dialog is
493 modal, control is returned to the calling program.
}
497 The preferred way of dismissing a modal dialog is to use
\helpref{wxDialog::EndModal
}{wxdialogendmodal
}.
500 \membersection{wxDialog::ShowModal
}\label{wxdialogshowmodal
}
502 \func{int
}{ShowModal
}{\void}
504 Shows a modal dialog. Program flow does not return until the dialog has been dismissed with
\rtfsp
505 \helpref{wxDialog::EndModal
}{wxdialogendmodal
}.
507 \wxheading{Return value
}
509 The return value is the value set with
\helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
}.
513 \helpref{wxDialog::EndModal
}{wxdialogendmodal
},
\rtfsp
514 \helpref{wxDialog:GetReturnCode
}{wxdialoggetreturncode
},
\rtfsp
515 \helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
}