A dialog box is a window with a title bar and sometimes a system menu, which can be moved around the screen. It can contain controls and other windows and is usually used to allow the user to make some choice or to answer a question.
Many common interactions such as choosing a file or entering a password are encapsulated in subclasses of Wx::Dialog, and will be displayed using native dialogs.
The dialog usually contains either a single button allowing to close the
dialog or two buttons, one accepting the changes and the other one
discarding them (such button, if present, is automatically activated if
the user presses the
"Esc" key). By default, buttons with the standard
ID_CANCEL identifiers behave as expected. It is also
possible to use a button with a different identifier nstead, see
Also notice that the create_button_sizer should be used to create the buttons appropriate for the current platform and positioned correctly (including their order which is platform-dependent).
There are two kinds of dialog—modal and modeless. A modal dialog blocks program flow and user input on other windows until it is dismissed, whereas a modeless dialog behaves more like a frame in that program flow continues, and input in other windows is still possible. To show a modal dialog you should use the show_modal method while to show a dialog modelessly you simply use show, just as with frames.
These methods return a value representing the user’s choice from the dialog, such as ‘OK’ or ‘Cancel’. To test these, do:
dlg = MyAskDialog.new(...) case dlg.show_modal when Wx::ID_OK # user clicked ok ... when Wx::ID_CANCEL # user clicked cancel or closed the dialog ... end
As well as handling the ending of dialogs this way, an application can
also define a CloseEvent handler for the dialog to
respond to system close events, by calling
||Puts a caption on the dialog box.|
||Equivalent to a combination of CAPTION, CLOSE_BOX and SYSTEM_MENU (the last one is not used under Unix)|
||Display a resizeable frame around the window.|
||Display a system menu.|
||Displays a close box on the frame.|
||Displays a maximize box on the dialog.|
||Displays a minimize box on the dialog.|
||Display a thick frame around the window.|
||The dialog stays on top of all other windows.|
||Under Windows, specifies that the child controlsshould not have 3D borders unless specified in the control.|
||By default, a dialog created with a
||Under Windows, puts a query button on thecaption. When pressed, Windows will go into a context-sensitive help mode and Widgets will senda EVT_HELP event if the user clicked on an application window. Note that this is an extendedstyle and must be set by calling set_extra_style before Create is called (two-step construction).|
||On Mac OS X, frames with this style will be shown with a metallic look. This is an extra style.|
Under Unix or Linux, MWM (the Motif Window Manager) or other window managers recognizing the MHM hints should be running for any of these styles to have an effect.
See also Generic window styles.
Dialog overview, Frame, Validator overview
Dialog.new(Window parent, Integer id, String title, Point pos = DEFAULT_POSITION, Size size = DEFAULT_SIZE, Integer style = DEFAULT_DIALOG_STYLE, String name = "dialogBox")
Constructors. A Dialog may be attached to a particular parent frame, in
which case it will be automatically destroyed when that parent is
closed. However, the parent argument may be
nil – indeed it is
possible to create an application that consists only of Dialogs. If a
Dialog is created with a
nil parent, you must be sure to call
destroy on the dialog once it is no longer being
used. Otherwise, your application may hang when it exits because there
is a window still remaining in use, even if it is not visible.
The zero-argument form is only useful when loading dialog subclasses using XRC.
Destructor. Deletes any child windows before deleting the physical window.
centre(Integer direction = BOTH)
Centres the dialog box on the display.
Boolean create(Window parent, Integer id, String title, Point pos = DEFAULT_POSITION, Size size = DEFAULT_SIZE, Integer style = DEFAULT_DIALOG_STYLE, String name = "dialogBox")
Used for two-step dialog box construction. See Dialog.new for details.
Sizer create_button_sizer(Integer flags)
Creates a sizer with standard buttons. flags is a bit list of the following flags: OK, CANCEL, YES, NO, HELP, NO_DEFAULT.
The sizer lays out the buttons in a manner appropriate to the platform.
This function uses create_std_dialog_button_sizer internally for most platforms but doesn’t create the sizer at all for the platforms with hardware buttons (such as smartphones) for which it sets up the hardware buttons appropriately and returns , so don’t forget to test that the return value is valid before using it.
Sizer create_separated_button_sizer(Integer flags)
Creates a sizer with standard buttons using create_button_sizer separated from the rest of the dialog contents by a horizontal StaticLine.
Please notice that just like CreateButtonSizer() this function may return if no buttons were created.
StdDialogButtonSizer create_std_dialog_button_sizer(Integer flags)
Creates a StdDialogButtonSizer with standard buttons. flags is a bit list of the following flags: OK, CANCEL, YES, NO, HELP, NO_DEFAULT.
The sizer lays out the buttons in a manner appropriate to the platform.
Tells wxRuby that this Dialog can be disposed of. This is normally only required if the Dialog was created with no parent frame (see new). Dialogs that are associated with a parent frame will be automatically destroyed by wxRuby when the frame is closed.
This function is called when the titlebar OK button is pressed (PocketPC only). A command event for the identifier returned by get_affirmative_id is sent by default. You can override this function. If the function returns false, Widgets will call close for the dialog.
Ends a modal dialog, passing a value to be returned from the Dialog#show_modal invocation.
Dialog#show_modal, Dialog#get_return_code, Dialog#set_return_code
Gets the identifier of the button which works like standard OK button in this dialog.
Gets the identifier of the button to map presses of
Gets the return code for this window.
A return code is normally associated with a modal dialog, where Dialog#show_modal returns a code to the application.
Dialog#set_return_code, Dialog#show_modal, Dialog#end_modal
On PocketPC, a dialog is automatically provided with an empty toolbar. get_tool_bar allows you to access the toolbar and add tools to it. Removing tools and adding arbitrary controls are not currently supported.
This function is not available on any other platform.
Iconizes or restores the dialog. Windows only.
Note that in Windows, iconization has no effect since dialog boxes cannot be
iconized. However, applications may need to explicitly restore dialog
boxes under Motif which have user-iconizable frames, and under Windows
iconize(false) will bring the window to the front, as does
Returns true if the dialog box is iconized. Windows only.
Always returns false under Windows since dialogs cannot be iconized.
Returns true if the dialog box is modal, false otherwise.
The default handler for EVT_SYS_COLOUR_CHANGED.
Changes the dialog’s colour to conform to the current settings (Windows only). Add an event table entry for your dialog class if you wish the behaviour to be different (such as keeping a user-defined background colour). If you do override this function, call Event::skip to propagate the notification to child windows and controls.
Sets the identifier to be used as OK button. When the button with this identifier is pressed, the dialog calls validate and Window::transfer_data_from_window and, if they both return true, closes the dialog with ID_OK return code.
Also, when the user presses a hardware OK button on the devices having one or the special OK button in the PocketPC title bar, an event with this id is generated.
By default, the affirmative id is ID_OK.
Sets the identifier of the button which should work like the standard CANCEL button in this dialog. When the button with this id is clicked, the dialog is closed. Also, when the user presses ESC key in the dialog or closes the dialog using the close button in the title bar, this is mapped to the click of the button with the specified id.
By default, the escape id is the special value ID_ANY meaning that ID_CANCEL button is used if it’s present in the dialog and otherwise the button with get_affirmative_id is used. Another special value for id is ID_NONE meaning that ESC presses should be ignored. If any other value is given, it is interpreted as the id of the button to map the escape key to.
Sets the icon for this dialog.
Sets the icons for this dialog.
NB: This function is deprecated and doesn’t work for all ports, just use show_modal to show a modal dialog instead.
Allows the programmer to specify whether the dialog box is modal (Dialog::show blocks control until the dialog is hidden) or modeless (control returns immediately).
A return code is normally associated with a modal dialog, where Dialog::show_modal returns a code to the application. The function Dialog::end_modal calls set_return_code.
Dialog::get_return_code, Dialog::show_modal, Dialog::end_modal
Boolean show(Boolean show)
Hides or shows the dialog.
The preferred way of dismissing a modal dialog is to use Dialog::end_modal.
Shows a modal dialog. Program flow does not return until the dialog has been dismissed with Dialog::end_modal.
The return value is the value set with Dialog::set_return_code.
Dialog::end_modal, Dialog::get_return_code, Dialog::set_return_code
[This page automatically generated from the Textile source at Wed Sep 09 02:21:05 +0100 2009]