1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxDialog
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 Modes used for wxDialog::SetLayoutAdaptationMode().
12 enum wxDialogLayoutAdaptationMode
14 wxDIALOG_ADAPTATION_MODE_DEFAULT
= 0, ///< Use global adaptation enabled status.
15 wxDIALOG_ADAPTATION_MODE_ENABLED
= 1, ///< Enable this dialog overriding global status.
16 wxDIALOG_ADAPTATION_MODE_DISABLED
= 2 ///< Disable this dialog overriding global status.
19 #define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxSYSTEM_MENU | wxCLOSE_BOX)
24 A dialog box is a window with a title bar and sometimes a system menu,
25 which can be moved around the screen. It can contain controls and other
26 windows and is often used to allow the user to make some choice or to
29 Dialogs can be made scrollable, automatically, for computers with low
30 resolution screens: please see @ref overview_dialog_autoscrolling for
33 Dialogs usually contains either a single button allowing to close the
34 dialog or two buttons, one accepting the changes and the other one
35 discarding them (such button, if present, is automatically activated if the
36 user presses the "Esc" key). By default, buttons with the standard wxID_OK
37 and wxID_CANCEL identifiers behave as expected. Starting with wxWidgets 2.7
38 it is also possible to use a button with a different identifier instead,
39 see SetAffirmativeId() and SetEscapeId().
41 Also notice that the CreateButtonSizer() should be used to create the
42 buttons appropriate for the current platform and positioned correctly
43 (including their order which is platform-dependent).
45 @section dialog_modal Modal and Modeless
47 There are two kinds of dialog, modal and modeless. A modal dialog blocks
48 program flow and user input on other windows until it is dismissed, whereas
49 a modeless dialog behaves more like a frame in that program flow continues,
50 and input in other windows is still possible. To show a modal dialog you
51 should use the ShowModal() method while to show a dialog modelessly you
52 simply use Show(), just as with frames.
54 Note that the modal dialog is one of the very few examples of
55 wxWindow-derived objects which may be created on the stack and not on the
56 heap. In other words, while most windows would be created like this:
61 MyAskDialog *dlg = new MyAskDialog(...);
62 if ( dlg->ShowModal() == wxID_OK )
64 //else: dialog was cancelled or some another button pressed
70 You can achieve the same result with dialogs by using simpler code:
76 if ( dlg.ShowModal() == wxID_OK )
79 // no need to call Destroy() here
83 An application can define a wxCloseEvent handler for the dialog to respond
84 to system close events.
88 Puts a caption on the dialog box.
89 @style{wxDEFAULT_DIALOG_STYLE}
90 Equivalent to a combination of wxCAPTION, wxCLOSE_BOX and
91 wxSYSTEM_MENU (the last one is not used under Unix).
92 @style{wxRESIZE_BORDER}
93 Display a resizable frame around the window.
95 Display a system menu.
97 Displays a close box on the frame.
98 @style{wxMAXIMIZE_BOX}
99 Displays a maximize box on the dialog.
100 @style{wxMINIMIZE_BOX}
101 Displays a minimize box on the dialog.
102 @style{wxTHICK_FRAME}
103 Display a thick frame around the window.
104 @style{wxSTAY_ON_TOP}
105 The dialog stays on top of all other windows.
107 This style is obsolete and doesn't do anything any more, don't use
109 @style{wxDIALOG_NO_PARENT}
110 By default, a dialog created with a @NULL parent window will be
111 given the @ref wxApp::GetTopWindow() "application's top level window"
112 as parent. Use this style to prevent this from happening and create
113 an orphan dialog. This is not recommended for modal dialogs.
114 @style{wxDIALOG_EX_CONTEXTHELP}
115 Under Windows, puts a query button on the caption. When pressed,
116 Windows will go into a context-sensitive help mode and wxWidgets
117 will send a @c wxEVT_HELP event if the user clicked on an application
118 window. Note that this is an extended style and must be set by
119 calling SetExtraStyle() before Create is called (two-step
121 @style{wxDIALOG_EX_METAL}
122 On Mac OS X, frames with this style will be shown with a metallic
123 look. This is an extra style.
126 Under Unix or Linux, MWM (the Motif Window Manager) or other window
127 managers recognizing the MHM hints should be running for any of these
128 styles to have an effect.
131 @beginEventEmissionTable{wxCloseEvent}
132 @event{EVT_CLOSE(func)}
133 The dialog is being closed by the user or programmatically (see wxWindow::Close).
134 The user may generate this event clicking the close button
135 (typically the 'X' on the top-right of the title bar) if it's present
136 (see the @c wxCLOSE_BOX style) or by clicking a button with the
137 @c wxID_CANCEL or @c wxID_OK ids.
138 @event{EVT_INIT_DIALOG(func)}
139 Process a @c wxEVT_INIT_DIALOG event. See wxInitDialogEvent.
145 @see @ref overview_dialog, wxFrame, @ref overview_validator
147 class wxDialog
: public wxTopLevelWindow
158 Can be @NULL, a frame or another dialog box.
160 An identifier for the dialog. A value of -1 is taken to mean a
163 The title of the dialog.
165 The dialog position. The value wxDefaultPosition indicates a
166 default position, chosen by either the windowing system or
167 wxWidgets, depending on platform.
169 The dialog size. The value wxDefaultSize indicates a default size,
170 chosen by either the windowing system or wxWidgets, depending on
175 Used to associate a name with the window, allowing the application
176 user to set Motif resource values for individual dialog boxes.
180 wxDialog(wxWindow
* parent
, wxWindowID id
, const wxString
& title
,
181 const wxPoint
& pos
= wxDefaultPosition
,
182 const wxSize
& size
= wxDefaultSize
,
183 long style
= wxDEFAULT_DIALOG_STYLE
,
184 const wxString
& name
= wxDialogNameStr
);
189 Deletes any child windows before deleting the physical window.
191 See @ref overview_windowdeletion for more info.
196 Adds an identifier to be regarded as a main button for the
197 non-scrolling area of a dialog.
199 @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
201 void AddMainButtonId(wxWindowID id
);
204 Returns @true if this dialog can and should perform layout adaptation
205 using DoLayoutAdaptation(), usually if the dialog is too large to fit
208 @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
210 virtual bool CanDoLayoutAdaptation();
213 Centres the dialog box on the display.
216 May be wxHORIZONTAL, wxVERTICAL or wxBOTH.
218 void Centre(int direction
= wxBOTH
);
221 Used for two-step dialog box construction.
225 bool Create(wxWindow
* parent
, wxWindowID id
, const wxString
& title
,
226 const wxPoint
& pos
= wxDefaultPosition
,
227 const wxSize
& size
= wxDefaultSize
,
228 long style
= wxDEFAULT_DIALOG_STYLE
,
229 const wxString
& name
= wxDialogNameStr
);
232 Creates a sizer with standard buttons. @a flags is a bit list of the
233 following flags: wxOK, wxCANCEL, wxYES, wxNO, wxAPPLY, wxCLOSE, wxHELP,
236 The sizer lays out the buttons in a manner appropriate to the platform.
238 This function uses CreateStdDialogButtonSizer() internally for most
239 platforms but doesn't create the sizer at all for the platforms with
240 hardware buttons (such as smartphones) for which it sets up the
241 hardware buttons appropriately and returns @NULL, so don't forget to
242 test that the return value is valid before using it.
244 wxSizer
* CreateButtonSizer(long flags
);
247 Creates a sizer with standard buttons using CreateButtonSizer()
248 separated from the rest of the dialog contents by a horizontal
251 @note Just like CreateButtonSizer(), this function may return @NULL if
252 no buttons were created.
254 This is a combination of CreateButtonSizer() and
255 CreateSeparatedSizer().
257 wxSizer
* CreateSeparatedButtonSizer(long flags
);
260 Returns the sizer containing the given one with a separating
261 wxStaticLine if necessarily.
263 This function is useful for creating the sizer containing footer-like
264 contents in dialog boxes. It will add a separating static line only if
265 it conforms to the current platform convention (currently it is not
266 added under Mac where the use of static lines for grouping is
267 discouraged and is added elsewhere).
271 @param sizer The sizer to wrap, must be non-@NULL.
272 @return The sizer wrapping the input one or possibly the input sizer
273 itself if no wrapping is necessary.
275 wxSizer
*CreateSeparatedSizer(wxSizer
*sizer
);
278 Creates a wxStdDialogButtonSizer with standard buttons. @a flags is a
279 bit list of the following flags: wxOK, wxCANCEL, wxYES, wxNO, wxAPPLY,
280 wxCLOSE, wxHELP, wxNO_DEFAULT.
282 The sizer lays out the buttons in a manner appropriate to the platform.
284 wxStdDialogButtonSizer
* CreateStdDialogButtonSizer(long flags
);
287 Splits text up at newlines and places the lines into wxStaticText
288 objects in a vertical wxBoxSizer.
290 wxSizer
*CreateTextSizer( const wxString
& message
);
293 Performs layout adaptation, usually if the dialog is too large to fit
296 @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
298 virtual bool DoLayoutAdaptation();
301 This function is called when the titlebar OK button is pressed
302 (PocketPC only). A command event for the identifier returned by
303 GetAffirmativeId() is sent by default. You can override this function.
304 If the function returns @false, wxWidgets will call Close() for the
312 A static function enabling or disabling layout adaptation for all
315 @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
317 static void EnableLayoutAdaptation(bool enable
);
320 Ends a modal dialog, passing a value to be returned from the
321 ShowModal() invocation.
324 The value that should be returned by ShowModal.
326 @see ShowModal(), GetReturnCode(), SetReturnCode()
328 virtual void EndModal(int retCode
);
331 Gets the identifier of the button which works like standard OK button
334 @see SetAffirmativeId()
336 int GetAffirmativeId() const;
339 Override this to return a window containing the main content of the
340 dialog. This is particularly useful when the dialog implements pages,
341 such as wxPropertySheetDialog, and allows the
342 @ref overview_dialog "layout adaptation code" to know that only the
343 pages need to be made scrollable.
345 virtual wxWindow
* GetContentWindow() const;
348 Gets the identifier of the button to map presses of @c ESC button to.
352 int GetEscapeId() const;
355 Returns @true if the dialog has been adapted, usually by making it
356 scrollable to work with a small display.
358 @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
360 bool GetLayoutAdaptationDone() const;
363 Gets a value representing the aggressiveness of search for buttons and
364 sizers to be in the non-scrolling part of a layout-adapted dialog. Zero
365 switches off adaptation, and 3 allows search for standard buttons
366 anywhere in the dialog.
368 @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
370 int GetLayoutAdaptationLevel() const;
373 Gets the adaptation mode, overriding the global adaptation flag.
375 @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
377 wxDialogLayoutAdaptationMode
GetLayoutAdaptationMode() const;
380 A static function getting the current layout adapter object.
382 @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
384 static wxDialogLayoutAdapter
* GetLayoutAdapter();
387 Returns an array of identifiers to be regarded as the main buttons for
388 the non-scrolling area of a dialog.
390 @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
392 wxArrayInt
& GetMainButtonIds();
395 Gets the return code for this window.
397 @remarks A return code is normally associated with a modal dialog,
398 where ShowModal() returns a code to the application.
400 @see SetReturnCode(), ShowModal(), EndModal()
402 int GetReturnCode() const;
405 On PocketPC, a dialog is automatically provided with an empty toolbar.
406 This function allows you to access the toolbar and add tools to it.
407 Removing tools and adding arbitrary controls are not currently
410 This function is not available on any other platform.
414 wxToolBar
* GetToolBar() const;
417 Iconizes or restores the dialog. Windows only.
420 If @true, iconizes the dialog box; if @false, shows and restores it.
422 @remarks Note that in Windows, iconization has no effect since dialog
423 boxes cannot be iconized. However, applications may need to
424 explicitly restore dialog boxes under Motif which have
425 user-iconizable frames, and under Windows calling
426 Iconize(@false) will bring the window to the front, as does
429 virtual void Iconize(bool iconize
= true);
432 Returns @true if the dialog box is iconized. Windows only.
434 @remarks Always returns @false under Windows since dialogs cannot be
437 virtual bool IsIconized() const;
440 A static function returning @true if layout adaptation is enabled for
443 @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
445 static bool IsLayoutAdaptationEnabled();
448 Returns @true if @a id is in the array of identifiers to be regarded as
449 the main buttons for the non-scrolling area of a dialog.
453 @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
455 bool IsMainButtonId(wxWindowID id
) const;
458 Returns @true if the dialog box is modal, @false otherwise.
460 virtual bool IsModal() const;
463 Sets the identifier to be used as OK button. When the button with this
464 identifier is pressed, the dialog calls wxWindow::Validate() and
465 wxWindow::TransferDataFromWindow() and, if they both return @true,
466 closes the dialog with the affirmative id return code.
468 Also, when the user presses a hardware OK button on the devices having
469 one or the special OK button in the PocketPC title bar, an event with
470 this id is generated.
472 By default, the affirmative id is wxID_OK.
474 @see GetAffirmativeId(), SetEscapeId()
476 void SetAffirmativeId(int id
);
479 Sets the identifier of the button which should work like the standard
480 "Cancel" button in this dialog. When the button with this id is
481 clicked, the dialog is closed. Also, when the user presses @c ESC key
482 in the dialog or closes the dialog using the close button in the title
483 bar, this is mapped to the click of the button with the specified id.
485 By default, the escape id is the special value wxID_ANY meaning that
486 wxID_CANCEL button is used if it's present in the dialog and otherwise
487 the button with GetAffirmativeId() is used. Another special value for
488 @a id is wxID_NONE meaning that @c ESC presses should be ignored. If
489 any other value is given, it is interpreted as the id of the button to
490 map the escape key to.
492 void SetEscapeId(int id
);
495 Sets the icon for this dialog.
498 The icon to associate with this dialog.
502 void SetIcon(const wxIcon
& icon
);
505 Sets the icons for this dialog.
508 The icons to associate with this dialog.
512 void SetIcons(const wxIconBundle
& icons
);
515 Marks the dialog as having been adapted, usually by making it
516 scrollable to work with a small display.
518 @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
520 void SetLayoutAdaptationDone(bool done
);
523 Sets the aggressiveness of search for buttons and sizers to be in the
524 non-scrolling part of a layout-adapted dialog. Zero switches off
525 adaptation, and 3 allows search for standard buttons anywhere in the
528 @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
530 void SetLayoutAdaptationLevel(int level
);
533 Sets the adaptation mode, overriding the global adaptation flag.
535 @see wxDialogLayoutAdaptationMode, @ref overview_dialog_autoscrolling
536 (for more on layout adaptation)
538 void SetLayoutAdaptationMode(wxDialogLayoutAdaptationMode mode
);
541 A static function for setting the current layout adapter object,
542 returning the old adapter. If you call this, you should delete the old
545 @see wxDialogLayoutAdapter, @ref overview_dialog_autoscrolling
547 static wxDialogLayoutAdapter
* SetLayoutAdapter(wxDialogLayoutAdapter
* adapter
);
550 @deprecated This function doesn't work for all ports, just use
551 ShowModal() to show a modal dialog instead.
553 Allows the programmer to specify whether the dialog box is modal
554 (Show() blocks control until the dialog is hidden) or modeless (control
555 returns immediately).
558 If @true, the dialog will be modal, otherwise it will be modeless.
560 void SetModal(bool flag
);
563 Sets the return code for this window.
565 A return code is normally associated with a modal dialog, where
566 ShowModal() returns a code to the application. The function EndModal()
567 calls SetReturnCode().
570 The integer return code, usually a control identifier.
572 @see GetReturnCode(), ShowModal(), EndModal()
574 void SetReturnCode(int retCode
);
577 Hides or shows the dialog. The preferred way of dismissing a modal
578 dialog is to use EndModal().
581 If @true, the dialog box is shown and brought to the front,
582 otherwise the box is hidden. If @false and the dialog is modal,
583 control is returned to the calling program.
585 virtual bool Show(bool show
= 1);
588 Shows an application-modal dialog.
590 Program flow does not return until the dialog has been dismissed with
593 Notice that it is possible to call ShowModal() for a dialog which had
594 been previously shown with Show(), this allows to make an existing
595 modeless dialog modal. However ShowModal() can't be called twice
596 without intervening EndModal() calls.
598 Note that this function creates a temporary event loop which takes
599 precedence over the application's main event loop (see wxEventLoopBase)
600 and which is destroyed when the dialog is dismissed.
601 This also results in a call to wxApp::ProcessPendingEvents().
603 @return The value set with SetReturnCode().
605 @see ShowWindowModal(), EndModal(), GetReturnCode(), SetReturnCode()
607 virtual int ShowModal();
610 Shows a dialog modal to the parent top level window only.
612 Unlike ShowModal(), dialogs shown with this function only prevent the
613 user from interacting with their parent frame only but not with the
614 rest of the application. They also don't block the program execution
615 but instead return immediately, as Show(), and generate a
616 wxEVT_WINDOW_MODAL_DIALOG_CLOSED event later when the dialog is closed.
618 Currently this function is only fully implemented in wxOSX ports, under
619 the other platforms it behaves like ShowModal() (but also sends the
620 above mentioned event).
624 void ShowWindowModal();
630 @class wxDialogLayoutAdapter
632 This abstract class is the base for classes that help wxWidgets perform
633 run-time layout adaptation of dialogs. Principally, this is to cater for
634 small displays by making part of the dialog scroll, but the application
635 developer may find other uses for layout adaption.
637 By default, there is one instance of wxStandardDialogLayoutAdapter which
638 can perform adaptation for most custom dialogs and dialogs with book
639 controls such as wxPropertySheetDialog.
644 @see @ref overview_dialog_autoscrolling
646 class wxDialogLayoutAdapter
652 wxDialogLayoutAdapter();
655 Override this to returns @true if adaptation can and should be done.
657 virtual bool CanDoLayoutAdaptation(wxDialog
* dialog
) = 0;
660 Override this to perform layout adaptation, such as making parts of the
661 dialog scroll and resizing the dialog to fit the display. Normally this
662 function will be called just before the dialog is shown.
664 virtual bool DoLayoutAdaptation(wxDialog
* dialog
) = 0;
668 class wxWindowModalDialogEvent
: public wxCommandEvent
671 wxWindowModalDialogEvent (wxEventType commandType
= wxEVT_NULL
, int id
= 0);
673 wxDialog
*GetDialog() const;
674 int GetReturnCode() const;
675 virtual wxEvent
*Clone() const;