1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxDialog class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 A dialog box is a window with a title bar and sometimes a system menu, which
14 can be moved around the screen. It can contain controls and other windows and
15 is often used to allow the user to make some choice or to answer a question.
17 Dialogs can be made scrollable, automatically: please see @ref
18 overview_autoscrollingdialogs "Automatic scrolling dialogs" for further details.
22 Puts a caption on the dialog box.
23 @style{wxDEFAULT_DIALOG_STYLE}:
24 Equivalent to a combination of wxCAPTION, wxCLOSE_BOX and
25 wxSYSTEM_MENU (the last one is not used under Unix)
26 @style{wxRESIZE_BORDER}:
27 Display a resizeable frame around the window.
28 @style{wxSYSTEM_MENU}:
29 Display a system menu.
31 Displays a close box on the frame.
32 @style{wxMAXIMIZE_BOX}:
33 Displays a maximize box on the dialog.
34 @style{wxMINIMIZE_BOX}:
35 Displays a minimize box on the dialog.
36 @style{wxTHICK_FRAME}:
37 Display a thick frame around the window.
38 @style{wxSTAY_ON_TOP}:
39 The dialog stays on top of all other windows.
41 Under Windows, specifies that the child controls should not have 3D
42 borders unless specified in the control.
43 @style{wxDIALOG_NO_PARENT}:
44 By default, a dialog created with a @NULL parent window will be
45 given the application's top level window as parent. Use this style
46 to prevent this from happening and create an orphan dialog. This is
47 not recommended for modal dialogs.
48 @style{wxDIALOG_EX_CONTEXTHELP}:
49 Under Windows, puts a query button on the caption. When pressed,
50 Windows will go into a context-sensitive help mode and wxWidgets
51 will send a wxEVT_HELP event if the user clicked on an application
52 window. Note that this is an extended style and must be set by
53 calling SetExtraStyle before Create is called (two-step
55 @style{wxDIALOG_EX_METAL}:
56 On Mac OS X, frames with this style will be shown with a metallic
57 look. This is an extra style.
64 @ref overview_wxdialogoverview "wxDialog overview", wxFrame, @ref
65 overview_validatoroverview "Validator overview"
67 class wxDialog
: public wxTopLevelWindow
75 Can be @NULL, a frame or another dialog box.
78 An identifier for the dialog. A value of -1 is taken to mean a default.
81 The title of the dialog.
84 The dialog position. The value wxDefaultPosition indicates a default position, chosen by
85 either the windowing system or wxWidgets, depending on platform.
88 The dialog size. The value wxDefaultSize indicates a default size, chosen by
89 either the windowing system or wxWidgets, depending on platform.
92 The window style. See wxDialog.
95 Used to associate a name with the window,
96 allowing the application user to set Motif resource values for
97 individual dialog boxes.
102 wxDialog(wxWindow
* parent
, wxWindowID id
,
103 const wxString
& title
,
104 const wxPoint
& pos
= wxDefaultPosition
,
105 const wxSize
& size
= wxDefaultSize
,
106 long style
= wxDEFAULT_DIALOG_STYLE
,
107 const wxString
& name
= "dialogBox");
111 Destructor. Deletes any child windows before deleting the physical window.
116 Adds an identifier to be regarded as a main button for the non-scrolling area
119 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
120 more on layout adaptation.
122 void AddMainButtonId(wxWindowID id
);
125 Returns @true if this dialog can and should perform layout adaptation using
126 DoLayoutAdaptation(), usually if
127 the dialog is too large to fit on the display.
129 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
130 more on layout adaptation.
132 bool CanDoLayoutAdapation();
135 Centres the dialog box on the display.
138 May be wxHORIZONTAL, wxVERTICAL or wxBOTH.
140 void Centre(int direction
= wxBOTH
);
143 Used for two-step dialog box construction. See wxDialog()
146 bool Create(wxWindow
* parent
, wxWindowID id
,
147 const wxString
& title
,
148 const wxPoint
& pos
= wxDefaultPosition
,
149 const wxSize
& size
= wxDefaultSize
,
150 long style
= wxDEFAULT_DIALOG_STYLE
,
151 const wxString
& name
= "dialogBox");
154 Creates a sizer with standard buttons. @e flags is a bit list
155 of the following flags: wxOK, wxCANCEL, wxYES, wxNO, wxAPPLY, wxCLOSE,
156 wxHELP, wxNO_DEFAULT.
158 The sizer lays out the buttons in a manner appropriate to the platform.
160 This function uses CreateStdDialogButtonSizer()
161 internally for most platforms but doesn't create the sizer at all for the
162 platforms with hardware buttons (such as smartphones) for which it sets up the
163 hardware buttons appropriately and returns @NULL, so don't forget to test that
164 the return value is valid before using it.
166 wxSizer
* CreateButtonSizer(long flags
);
169 Creates a sizer with standard buttons using
170 CreateButtonSizer() separated from the rest
171 of the dialog contents by a horizontal wxStaticLine.
173 Please notice that just like CreateButtonSizer() this function may return @c
175 if no buttons were created.
177 wxSizer
* CreateSeparatedButtonSizer(long flags
);
180 Creates a wxStdDialogButtonSizer with standard buttons. @e flags is a bit list
181 of the following flags: wxOK, wxCANCEL, wxYES, wxNO, wxAPPLY, wxCLOSE,
182 wxHELP, wxNO_DEFAULT.
184 The sizer lays out the buttons in a manner appropriate to the platform.
186 wxStdDialogButtonSizer
* CreateStdDialogButtonSizer(long flags
);
189 Performs layout adaptation, usually if the dialog is too large to fit on the
192 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
193 more on layout adaptation.
195 bool DoLayoutAdapation();
198 This function is called when the titlebar OK button is pressed (PocketPC only).
199 A command event for the identifier returned by GetAffirmativeId is sent by
200 default. You can override this function. If the function returns @false,
202 will call Close() for the dialog.
204 #define virtual bool DoOK() /* implementation is private */
207 A static function enabling or disabling layout adaptation for all dialogs.
209 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
210 more on layout adaptation.
212 static void EnableLayoutAdaptation(bool enable
);
215 Ends a modal dialog, passing a value to be returned from the ShowModal()
219 The value that should be returned by ShowModal.
221 @sa ShowModal(), GetReturnCode(), SetReturnCode()
223 void EndModal(int retCode
);
226 Gets the identifier of the button which works like standard OK button in this
229 @sa SetAffirmativeId()
231 int GetAffirmativeId();
234 Override this to return a window containing the main content of the dialog.
236 particularly useful when the dialog implements pages, such as
237 wxPropertySheetDialog,
238 and allows the @ref overview_wxdialogoverview "layout adaptation code" to know
239 that only the pages need to be made scrollable.
241 wxWindow
* GetContentWindow();
244 Gets the identifier of the button to map presses of @c ESC
252 Returns @true if the dialog has been adapted, usually by making it scrollable
253 to work with a small display.
255 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
256 more on layout adaptation.
258 bool GetLayoutAdaptationDone();
261 Gets a value representing the aggressiveness of search for buttons and sizers
262 to be in the non-scrolling part of a layout-adapted dialog.
263 Zero switches off adaptation, and 3 allows search for standard buttons anywhere
266 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
267 more on layout adaptation.
269 int GetLayoutAdaptationLevel();
272 Gets the adaptation mode, overriding the global adaptation flag.
274 See also SetLayoutAdaptationMode() and @ref overview_autoscrollingdialogs
275 "Automatic scrolling dialogs".
277 wxDialogLayoutAdaptationMode
GetLayoutAdaptationMode();
280 A static function getting the current layout adapter object.
282 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
283 more on layout adaptation.
285 static wxDialogLayoutAdapter
* GetLayoutAdapter();
288 Returns an array of identifiers to be regarded as the main buttons for the
289 non-scrolling area of a dialog.
291 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
292 more on layout adaptation.
294 wxArrayInt
GetMainButtonIds();
297 Gets the return code for this window.
299 @remarks A return code is normally associated with a modal dialog, where
300 ShowModal() returns a code to the application.
302 @sa SetReturnCode(), ShowModal(), EndModal()
307 On PocketPC, a dialog is automatically provided with an empty toolbar.
309 allows you to access the toolbar and add tools to it. Removing tools and adding
310 arbitrary controls are not currently supported.
312 This function is not available on any other platform.
314 wxToolBar
* GetToolBar();
317 Iconizes or restores the dialog. Windows only.
320 If @true, iconizes the dialog box; if @false, shows and restores it.
322 @remarks Note that in Windows, iconization has no effect since dialog
323 boxes cannot be iconized. However, applications may
324 need to explicitly restore dialog boxes under Motif
325 which have user-iconizable frames, and under Windows
326 calling Iconize(@false) will bring the window to the
327 front, as does Show(@true).
329 void Iconize(bool iconize
);
332 Returns @true if the dialog box is iconized. Windows only.
334 @remarks Always returns @false under Windows since dialogs cannot be
340 A static function returning @true if layout adaptation is enabled for all
343 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
344 more on layout adaptation.
346 static bool IsLayoutAdaptationEnabled();
349 Returns @true if @e id is in the array of identifiers to be regarded as the
350 main buttons for the non-scrolling area of a dialog.
352 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
353 more on layout adaptation.
355 bool IsMainButton(wxWindowID
& id
);
358 Returns @true if the dialog box is modal, @false otherwise.
363 The default handler for wxEVT_SYS_COLOUR_CHANGED.
366 The colour change event.
368 @remarks Changes the dialog's colour to conform to the current settings
369 (Windows only). Add an event table entry for your
370 dialog class if you wish the behaviour to be
371 different (such as keeping a user-defined background
372 colour). If you do override this function, call
373 wxEvent::Skip to propagate the notification to child
374 windows and controls.
376 @sa wxSysColourChangedEvent
378 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
381 Sets the identifier to be used as OK button. When the button with this
382 identifier is pressed, the dialog calls wxWindow::Validate
383 and wxWindow::TransferDataFromWindow
384 and, if they both return @true, closes the dialog with @c wxID_OK return
387 Also, when the user presses a hardware OK button on the devices having one or
388 the special OK button in the PocketPC title bar, an event with this id is
391 By default, the affirmative id is wxID_OK.
393 @sa GetAffirmativeId(), SetEscapeId()
395 void SetAffirmativeId(int id
);
398 Sets the identifier of the button which should work like the standard
399 @c CANCEL button in this dialog. When the button with this id is
400 clicked, the dialog is closed. Also, when the user presses @c ESC
401 key in the dialog or closes the dialog using the close button in the title bar,
402 this is mapped to the click of the button with the specified id.
404 By default, the escape id is the special value @c wxID_ANY meaning that
405 @c wxID_CANCEL button is used if it's present in the dialog and
406 otherwise the button with GetAffirmativeId()
407 is used. Another special value for @e id is @c wxID_NONE meaning that
408 @c ESC presses should be ignored. If any other value is given, it
409 is interpreted as the id of the button to map the escape key to.
411 void SetEscapeId(int id
);
414 Sets the icon for this dialog.
417 The icon to associate with this dialog.
419 void SetIcon(const wxIcon
& icon
);
422 Sets the icons for this dialog.
425 The icons to associate with this dialog.
427 void SetIcons(const wxIconBundle
& icons
);
430 Marks the dialog as having been adapted, usually by making it scrollable to
431 work with a small display.
433 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
434 more on layout adaptation.
436 void SetLayoutAdaptationDone(bool done
);
439 Sets the aggressiveness of search for buttons and sizers to be in the
440 non-scrolling part of a layout-adapted dialog.
441 Zero switches off adaptation, and 3 allows search for standard buttons anywhere
444 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
445 more on layout adaptation.
447 void SetLayoutAdaptationLevel(int level
);
450 Sets the adaptation mode, overriding the global adaptation flag. @e mode may be
451 one of the following values:
452 See also @ref overview_autoscrollingdialogs "Automatic scrolling dialogs" for
453 more on layout adaptation.
455 void SetLayoutAdaptationMode(wxDialogLayoutAdaptationMode mode
);
458 A static function for setting the current layout adapter object, returning the
459 old adapter. If you call this, you should
460 delete the old adapter object.
462 See also wxDialogLayoutAdapter and @ref overview_autoscrollingdialogs
463 "Automatic scrolling dialogs".
465 static wxDialogLayoutAdapter
* SetLayoutAdapter(wxDialogLayoutAdapter
* adapter
);
468 @b NB: This function is deprecated and doesn't work for all ports, just use
469 ShowModal() to show a modal dialog instead.
471 Allows the programmer to specify whether the dialog box is modal (Show() blocks
473 until the dialog is hidden) or modeless (control returns immediately).
476 If @true, the dialog will be modal, otherwise it will be modeless.
478 void SetModal(bool flag
);
481 Sets the return code for this window.
484 The integer return code, usually a control identifier.
486 @remarks A return code is normally associated with a modal dialog, where
487 ShowModal() returns a code to the
488 application. The function EndModal() calls
491 @sa GetReturnCode(), ShowModal(), EndModal()
493 void SetReturnCode(int retCode
);
496 Hides or shows the dialog.
499 If @true, the dialog box is shown and brought to the front;
500 otherwise the box is hidden. If @false and the dialog is
501 modal, control is returned to the calling program.
503 @remarks The preferred way of dismissing a modal dialog is to use
506 bool Show(bool show
);
509 Shows a modal dialog. Program flow does not return until the dialog has been
513 @returns The return value is the value set with SetReturnCode().
520 @class wxDialogLayoutAdapter
523 This abstract class is the base for classes that help wxWidgets peform run-time
524 layout adaptation of dialogs. Principally,
525 this is to cater for small displays by making part of the dialog scroll, but
526 the application developer may find other
527 uses for layout adaption.
529 By default, there is one instance of wxStandardDialogLayoutAdapter
530 which can perform adaptation for most custom dialogs and dialogs with book
532 such as wxPropertySheetDialog.
538 @ref overview_autoscrollingdialogs "Automatic scrolling dialogs"
540 class wxDialogLayoutAdapter
546 wxDialogLayoutAdapter();
549 Override this to returns @true if adaptation can and should be done.
551 bool CanDoLayoutAdaptation(wxDialog
* dialog
);
554 Override this to perform layout adaptation, such as making parts of the dialog
555 scroll and resizing the dialog to fit the display.
556 Normally this function will be called just before the dialog is shown.
558 bool DoLayoutAdaptation(wxDialog
* dialog
);