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
}
49 \helpref{wxCore
}{librarieslist
}
51 \wxheading{Modal and modeless dialogs
}
53 There are two kinds of dialog --
{\it modal
}\ and
{\it modeless
}. A modal dialog
54 blocks program flow and user input on other windows until it is dismissed,
55 whereas a modeless dialog behaves more like a frame in that program flow
56 continues, and input in other windows is still possible. To show a modal dialog
57 you should use the
\helpref{ShowModal
}{wxdialogshowmodal
} method while to show
58 a dialog modelessly you simply use
\helpref{Show
}{wxdialogshow
}, just as with
61 Note that the modal dialog is one of the very few examples of
62 wxWindow-derived objects which may be created on the stack and not on the heap.
63 In other words, although this code snippet:
68 MyAskDialog *dlg = new MyAskDialog(...);
69 if ( dlg->ShowModal() == wxID_OK )
71 //else: dialog was cancelled or some another button pressed
77 works, you can also achieve the same result by using a simpler code fragment
84 if ( dlg.ShowModal() == wxID_OK )
87 // no need to call Destroy() here
91 An application can define a
\helpref{wxCloseEvent
}{wxcloseevent
} handler for
92 the dialog to respond to system close events.
94 \wxheading{Window styles
}
97 \begin{twocollist
}\itemsep=
0pt
98 \twocolitem{\windowstyle{wxCAPTION
}}{Puts a caption on the dialog box.
}
99 \twocolitem{\windowstyle{wxDEFAULT
\_DIALOG\_STYLE}}{Equivalent to a combination of wxCAPTION, wxCLOSE
\_BOX and wxSYSTEM
\_MENU (the last one is not used under Unix)
}
100 \twocolitem{\windowstyle{wxRESIZE
\_BORDER}}{Display a resizeable frame around the window.
}
101 \twocolitem{\windowstyle{wxSYSTEM
\_MENU}}{Display a system menu.
}
102 \twocolitem{\windowstyle{wxCLOSE
\_BOX}}{Displays a close box on the frame.
}
103 \twocolitem{\windowstyle{wxMAXIMIZE
\_BOX}}{Displays a maximize box on the dialog.
}
104 \twocolitem{\windowstyle{wxMINIMIZE
\_BOX}}{Displays a minimize box on the dialog.
}
105 \twocolitem{\windowstyle{wxTHICK
\_FRAME}}{Display a thick frame around the window.
}
106 \twocolitem{\windowstyle{wxSTAY
\_ON\_TOP}}{The dialog stays on top of all other windows.
}
107 \twocolitem{\windowstyle{wxNO
\_3D}}{Under Windows, specifies that the child controls
108 should not have
3D borders unless specified in the control.
}
109 \twocolitem{\windowstyle{wxDIALOG
\_NO\_PARENT}}{By default, a dialog created
110 with a
{\tt NULL
} parent window will be given the
111 \helpref{application's top level window
}{wxappgettopwindow
} as parent. Use this
112 style to prevent this from happening and create an orphan dialog. This is not recommended for modal dialogs.
}
113 \twocolitem{\windowstyle{wxDIALOG
\_EX\_CONTEXTHELP}}{Under Windows, puts a query button on the
114 caption. When pressed, Windows will go into a context-sensitive help mode and wxWidgets will send
115 a wxEVT
\_HELP event if the user clicked on an application window.
{\it Note
}\ that this is an extended
116 style and must be set by calling
\helpref{SetExtraStyle
}{wxwindowsetextrastyle
} before Create is called (two-step construction).
}
117 \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.
}
120 Under Unix or Linux, MWM (the Motif Window Manager) or other window managers
121 recognizing the MHM hints should be running for any of these styles to have an
124 See also
\helpref{Generic window styles
}{windowstyles
}.
128 \helpref{wxDialog overview
}{wxdialogoverview
},
\helpref{wxFrame
}{wxframe
},
\rtfsp
129 \helpref{Validator overview
}{validatoroverview
}
131 \latexignore{\rtfignore{\wxheading{Members
}}}
134 \membersection{wxDialog::wxDialog
}\label{wxdialogctor
}
136 \func{}{wxDialog
}{\void}
140 \func{}{wxDialog
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{id
},
\rtfsp
141 \param{const wxString\&
}{title
},
\rtfsp
142 \param{const wxPoint\&
}{pos = wxDefaultPosition
},
\rtfsp
143 \param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
144 \param{long
}{ style = wxDEFAULT
\_DIALOG\_STYLE},
\rtfsp
145 \param{const wxString\&
}{name = ``dialogBox"
}}
149 \wxheading{Parameters
}
151 \docparam{parent
}{Can be NULL, a frame or another dialog box.
}
153 \docparam{id
}{An identifier for the dialog. A value of -
1 is taken to mean a default.
}
155 \docparam{title
}{The title of the dialog.
}
157 \docparam{pos
}{The dialog position. A value of (-
1, -
1) indicates a default position, chosen by
158 either the windowing system or wxWidgets, depending on platform.
}
160 \docparam{size
}{The dialog size. A value of (-
1, -
1) indicates a default size, chosen by
161 either the windowing system or wxWidgets, depending on platform.
}
163 \docparam{style
}{The window style. See
\helpref{wxDialog
}{wxdialog
}.
}
165 \docparam{name
}{Used to associate a name with the window,
166 allowing the application user to set Motif resource values for
167 individual dialog boxes.
}
171 \helpref{wxDialog::Create
}{wxdialogcreate
}
174 \membersection{wxDialog::
\destruct{wxDialog
}}\label{wxdialogdtor
}
176 \func{}{\destruct{wxDialog
}}{\void}
178 Destructor. Deletes any child windows before deleting the physical window.
181 \membersection{wxDialog::Centre
}\label{wxdialogcentre
}
183 \func{void
}{Centre
}{\param{int
}{ direction = wxBOTH
}}
185 Centres the dialog box on the display.
187 \wxheading{Parameters
}
189 \docparam{direction
}{May be
{\tt wxHORIZONTAL
},
{\tt wxVERTICAL
} or
{\tt wxBOTH
}.
}
192 \membersection{wxDialog::Create
}\label{wxdialogcreate
}
194 \func{bool
}{Create
}{\param{wxWindow*
}{parent
},
\param{wxWindowID
}{id
},
\rtfsp
195 \param{const wxString\&
}{title
},
\rtfsp
196 \param{const wxPoint\&
}{pos = wxDefaultPosition
},
\rtfsp
197 \param{const wxSize\&
}{size = wxDefaultSize
},
\rtfsp
198 \param{long
}{ style = wxDEFAULT
\_DIALOG\_STYLE},
\rtfsp
199 \param{const wxString\&
}{name = ``dialogBox"
}}
201 Used for two-step dialog box construction. See
\helpref{wxDialog::wxDialog
}{wxdialogctor
}\rtfsp
205 \membersection{wxDialog::CreateButtonSizer
}\label{wxdialogcreatebuttonsizer
}
207 \func{wxSizer*
}{CreateButtonSizer
}{\param{long
}{ flags
}}
209 Creates a sizer with standard buttons.
{\it flags
} is a bit list
210 of the following flags: wxOK, wxCANCEL, wxYES, wxNO, wxAPPLY, wxCLOSE,
211 wxHELP, wxNO
\_DEFAULT.
213 The sizer lays out the buttons in a manner appropriate to the platform.
215 This function uses
\helpref{CreateStdDialogButtonSizer
}{wxdialogcreatestddialogbuttonsizer
}
216 internally for most platforms but doesn't create the sizer at all for the
217 platforms with hardware buttons (such as smartphones) for which it sets up the
218 hardware buttons appropriately and returns
\NULL, so don't forget to test that
219 the return value is valid before using it.
222 \membersection{wxDialog::CreateSeparatedButtonSizer
}\label{wxdialogcreateseparatedbuttonsizer
}
224 \func{wxSizer*
}{CreateSeparatedButtonSizer
}{\param{long
}{ flags
}}
226 Creates a sizer with standard buttons using
227 \helpref{CreateButtonSizer
}{wxdialogcreatebuttonsizer
} separated from the rest
228 of the dialog contents by a horizontal
\helpref{wxStaticLine
}{wxstaticline
}.
230 Please notice that just like CreateButtonSizer() this function may return
\NULL
231 if no buttons were created.
234 \membersection{wxDialog::CreateStdDialogButtonSizer
}\label{wxdialogcreatestddialogbuttonsizer
}
236 \func{wxStdDialogButtonSizer*
}{CreateStdDialogButtonSizer
}{\param{long
}{ flags
}}
238 Creates a
\helpref{wxStdDialogButtonSizer
}{wxstddialogbuttonsizer
} with standard buttons.
{\it flags
} is a bit list
239 of the following flags: wxOK, wxCANCEL, wxYES, wxNO, wxAPPLY, wxCLOSE,
240 wxHELP, wxNO
\_DEFAULT.
242 The sizer lays out the buttons in a manner appropriate to the platform.
245 \membersection{wxDialog::DoOK
}\label{wxdialogdook
}
247 \func{virtual bool
}{DoOK
}{\void}
249 This function is called when the titlebar OK button is pressed (PocketPC only).
250 A command event for the identifier returned by GetAffirmativeId is sent by
251 default. You can override this function. If the function returns false, wxWidgets
252 will call Close() for the dialog.
255 \membersection{wxDialog::EndModal
}\label{wxdialogendmodal
}
257 \func{void
}{EndModal
}{\param{int
}{retCode
}}
259 Ends a modal dialog, passing a value to be returned from the
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
}\rtfsp
262 \wxheading{Parameters
}
264 \docparam{retCode
}{The value that should be returned by
{\bf ShowModal
}.
}
268 \helpref{wxDialog::ShowModal
}{wxdialogshowmodal
},
\rtfsp
269 \helpref{wxDialog::GetReturnCode
}{wxdialoggetreturncode
},
\rtfsp
270 \helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
}
273 \membersection{wxDialog::GetAffirmativeId
}\label{wxdialoggetaffirmativeid
}
275 \constfunc{int
}{GetAffirmativeId
}{\void}
277 Gets the identifier of the button which works like standard OK button in this
282 \helpref{wxDialog::SetAffirmativeId
}{wxdialogsetaffirmativeid
}
285 \membersection{wxDialog::GetEscapeId
}\label{wxdialoggetescapeid
}
287 \constfunc{int
}{GetEscapeId
}{\void}
289 Gets the identifier of the button to map presses of
\texttt{\textsc{ESC
}}
294 \helpref{wxDialog::SetEscapeId
}{wxdialogsetescapeid
}
297 \membersection{wxDialog::GetReturnCode
}\label{wxdialoggetreturncode
}
299 \func{int
}{GetReturnCode
}{\void}
301 Gets the return code for this window.
305 A return code is normally associated with a modal dialog, where
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
} returns
306 a code to the application.
310 \helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
},
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
},
\rtfsp
311 \helpref{wxDialog::EndModal
}{wxdialogendmodal
}
314 \membersection{wxDialog::GetToolBar
}\label{wxdialoggettoolbar
}
316 \constfunc{wxToolBar*
}{GetToolBar
}{\void}
318 On PocketPC, a dialog is automatically provided with an empty toolbar. GetToolBar
319 allows you to access the toolbar and add tools to it. Removing tools and adding
320 arbitrary controls are not currently supported.
322 This function is not available on any other platform.
325 \membersection{wxDialog::Iconize
}\label{wxdialogiconized
}
327 \func{void
}{Iconize
}{\param{bool
}{ iconize
}}
329 Iconizes or restores the dialog. Windows only.
331 \wxheading{Parameters
}
333 \docparam{iconize
}{If true, iconizes the dialog box; if false, shows and restores it.
}
337 Note that in Windows, iconization has no effect since dialog boxes cannot be
338 iconized. However, applications may need to explicitly restore dialog
339 boxes under Motif which have user-iconizable frames, and under Windows
340 calling
{\tt Iconize(false)
} will bring the window to the front, as does
341 \rtfsp{\tt Show(true)
}.
344 \membersection{wxDialog::IsIconized
}\label{wxdialogisiconized
}
346 \constfunc{bool
}{IsIconized
}{\void}
348 Returns true if the dialog box is iconized. Windows only.
352 Always returns false under Windows since dialogs cannot be iconized.
355 \membersection{wxDialog::IsModal
}\label{wxdialogismodal
}
357 \constfunc{bool
}{IsModal
}{\void}
359 Returns true if the dialog box is modal, false otherwise.
363 \membersection{wxDialog::OnSysColourChanged
}\label{wxdialogonsyscolourchanged
}
365 \func{void
}{OnSysColourChanged
}{\param{wxSysColourChangedEvent\&
}{event
}}
367 The default handler for wxEVT
\_SYS\_COLOUR\_CHANGED.
369 \wxheading{Parameters
}
371 \docparam{event
}{The colour change event.
}
375 Changes the dialog's colour to conform to the current settings (Windows only).
376 Add an event table entry for your dialog class if you wish the behaviour
377 to be different (such as keeping a user-defined
378 background colour). If you do override this function, call wxEvent::Skip to
379 propagate the notification to child windows and controls.
383 \helpref{wxSysColourChangedEvent
}{wxsyscolourchangedevent
}
386 \membersection{wxDialog::SetAffirmativeId
}\label{wxdialogsetaffirmativeid
}
388 \func{void
}{SetAffirmativeId
}{\param{int
}{id
}}
390 Sets the identifier to be used as OK button. When the button with this
391 identifier is pressed, the dialog calls
\helpref{Validate
}{wxwindowvalidate
}
392 and
\helpref{wxWindow::TransferDataFromWindow
}{wxwindowtransferdatafromwindow
}
393 and, if they both return
\true, closes the dialog with
\texttt{wxID
\_OK} return
396 Also, when the user presses a hardware OK button on the devices having one or
397 the special OK button in the PocketPC title bar, an event with this id is
400 By default, the affirmative id is wxID
\_OK.
404 \helpref{wxDialog::GetAffirmativeId
}{wxdialoggetaffirmativeid
},
\helpref{wxDialog::SetEscapeId
}{wxdialogsetescapeid
}
407 \membersection{wxDialog::SetEscapeId
}\label{wxdialogsetescapeid
}
409 \func{void
}{SetEscapeId
}{\param{int
}{id
}}
411 Sets the identifier of the button which should work like the standard
412 \texttt{\textsc{Cancel
}} button in this dialog. When the button with this id is
413 clicked, the dialog is closed. Also, when the user presses
\texttt{\textsc{ESC
}}
414 key in the dialog or closes the dialog using the close button in the title bar,
415 this is mapped to the click of the button with the specified id.
417 By default, the escape id is the special value
\texttt{wxID
\_ANY} meaning that
418 \texttt{wxID
\_CANCEL} button is used if it's present in the dialog and
419 otherwise the button with
\helpref{GetAffirmativeId()
}{wxdialoggetaffirmativeid
}
420 is used. Another special value for
\arg{id
} is
\texttt{wxID
\_NONE} meaning that
421 \texttt{\textsc{ESC
}} presses should be ignored. If any other value is given, it
422 is interpreted as the id of the button to map the escape key to.
425 \membersection{wxDialog::SetIcon
}\label{wxdialogseticon
}
427 \func{void
}{SetIcon
}{\param{const wxIcon\&
}{icon
}}
429 Sets the icon for this dialog.
431 \wxheading{Parameters
}
433 \docparam{icon
}{The icon to associate with this dialog.
}
435 See also
\helpref{wxIcon
}{wxicon
}.
438 \membersection{wxDialog::SetIcons
}\label{wxdialogseticons
}
440 \func{void
}{SetIcons
}{\param{const wxIconBundle\&
}{icons
}}
442 Sets the icons for this dialog.
444 \wxheading{Parameters
}
446 \docparam{icons
}{The icons to associate with this dialog.
}
448 See also
\helpref{wxIconBundle
}{wxiconbundle
}.
451 \membersection{wxDialog::SetModal
}\label{wxdialogsetmodal
}
453 \func{void
}{SetModal
}{\param{bool
}{ flag
}}
455 {\bf NB:
} This function is deprecated and doesn't work for all ports, just use
456 \helpref{ShowModal
}{wxdialogshowmodal
} to show a modal dialog instead.
458 Allows the programmer to specify whether the dialog box is modal (wxDialog::Show blocks control
459 until the dialog is hidden) or modeless (control returns immediately).
461 \wxheading{Parameters
}
463 \docparam{flag
}{If true, the dialog will be modal, otherwise it will be modeless.
}
466 \membersection{wxDialog::SetReturnCode
}\label{wxdialogsetreturncode
}
468 \func{void
}{SetReturnCode
}{\param{int
}{retCode
}}
470 Sets the return code for this window.
472 \wxheading{Parameters
}
474 \docparam{retCode
}{The integer return code, usually a control identifier.
}
478 A return code is normally associated with a modal dialog, where
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
} returns
479 a code to the application. The function
\helpref{wxDialog::EndModal
}{wxdialogendmodal
} calls
{\bf SetReturnCode
}.
483 \helpref{wxDialog::GetReturnCode
}{wxdialoggetreturncode
},
\helpref{wxDialog::ShowModal
}{wxdialogshowmodal
},
\rtfsp
484 \helpref{wxDialog::EndModal
}{wxdialogendmodal
}
487 \membersection{wxDialog::Show
}\label{wxdialogshow
}
489 \func{bool
}{Show
}{\param{bool
}{ show
}}
491 Hides or shows the dialog.
493 \wxheading{Parameters
}
495 \docparam{show
}{If true, the dialog box is shown and brought to the front;
496 otherwise the box is hidden. If false and the dialog is
497 modal, control is returned to the calling program.
}
501 The preferred way of dismissing a modal dialog is to use
\helpref{wxDialog::EndModal
}{wxdialogendmodal
}.
504 \membersection{wxDialog::ShowModal
}\label{wxdialogshowmodal
}
506 \func{int
}{ShowModal
}{\void}
508 Shows a modal dialog. Program flow does not return until the dialog has been dismissed with
\rtfsp
509 \helpref{wxDialog::EndModal
}{wxdialogendmodal
}.
511 \wxheading{Return value
}
513 The return value is the value set with
\helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
}.
517 \helpref{wxDialog::EndModal
}{wxdialogendmodal
},
\rtfsp
518 \helpref{wxDialog:GetReturnCode
}{wxdialoggetreturncode
},
\rtfsp
519 \helpref{wxDialog::SetReturnCode
}{wxdialogsetreturncode
}