Wt  3.3.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
Public Member Functions | Static Public Member Functions
Wt::WMessageBox Class Reference

A standard dialog for confirmation or to get simple user input. More...

#include <Wt/WMessageBox>

Inheritance diagram for Wt::WMessageBox:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 WMessageBox (WObject *parent=0)
 Creates an empty message box.
 WMessageBox (const WString &caption, const WString &text, Icon icon, WFlags< StandardButton > buttons, WObject *parent=0)
 Creates a message box with given caption, text, icon, and buttons.
void setText (const WString &text)
 Sets the text for the message box.
const WStringtext () const
 Returns the message box text.
WTexttextWidget () const
 Returns the text widget.
void setIcon (Icon icon)
 Sets the icon.
Icon icon () const
 Returns the icon.
void addButton (WPushButton *button, StandardButton result)
 Adds a custom button.
WPushButtonaddButton (const WString &text, StandardButton result)
 Adds a custom button with given text.
WPushButtonaddButton (StandardButton result)
 Adds a standard button.
void setButtons (WFlags< StandardButton > buttons)
 Sets standard buttons for the message box (deprecated).
void setStandardButtons (WFlags< StandardButton > buttons)
 Sets standard buttons for the message box.
WFlags< StandardButtonstandardButtons () const
 Returns the standard buttons.
std::vector< WPushButton * > buttons () const
 Returns the buttons.
WPushButtonbutton (StandardButton button)
 Returns the button widget for the given standard button.
void setDefaultButton (WPushButton *button)
 Sets the button as the default button.
void setDefaultButton (StandardButton button)
 Sets the button as the default button.
WPushButtondefaultButton () const
 Returns the default button.
void setEscapeButton (WPushButton *button)
 Sets the escape button.
void setEscapeButton (StandardButton button)
 Sets the escape button.
WPushButtonescapeButton () const
 Returns the escape button.
StandardButton buttonResult ()
 Returns the result of this message box.
Signal< StandardButton > & buttonClicked ()
 Signal emitted when a button is clicked.
virtual void setHidden (bool hidden, const WAnimation &animation=WAnimation())
 Hides or shows the widget.

Static Public Member Functions

static StandardButton show (const WString &caption, const WString &text, WFlags< StandardButton > buttons, const WAnimation &animation=WAnimation())
 Convenience method to show a message box, blocking the current thread.

Detailed Description

A standard dialog for confirmation or to get simple user input.

The messagebox shows a message in a dialog window, with a number of buttons. These buttons may be standard buttons, or customized.

A messagebox is (usually) modal, and can be instantiated synchronously or asynchronously.

When using a messagebox asynchronously, there is no API call that waits for the messagebox to be processed. Instead, the usage is similar to instantiating a WDialog (or any other widget). You need to connect to the buttonClicked() signal to interpret the result and delete the message box.

The synchronous use of a messagebox involves the use of the static show() method, which blocks the current thread until the user has processed the messabebox. Since this uses the WDialog::exec(), it suffers from the same scalability issues as well as limitations. See documentation of WDialog for more details.

Example code (using the exec() method, not recommended):

 StandardButton
   result = WMessageBox::show("Confirm", "About to wreak havoc... Continue ?",
                              Ok | Cancel);

This will show a message box that looks like this:

WMessageBox-default-1.png
Example of a WMessageBox (default)
WMessageBox-polished-1.png
Example of a WMessageBox (polished)

i18n

The strings used in the WMessageBox buttons can be translated by overriding the default values for the following localization keys:


Member Function Documentation

void Wt::WMessageBox::addButton ( WPushButton button,
StandardButton  result 
)

Adds a custom button.

When the button is clicked, the associated result will be returned.

Adds a custom button with given text.

When the button is clicked, the associated result will be returned.

Returns the button widget for the given standard button.

Returns 0 if the button isn't in the message box.

This may be useful to customize the style or layout of the button.

Returns the result of this message box.

This value is only defined after the dialog is finished.

std::vector< WPushButton * > Wt::WMessageBox::buttons ( ) const

Returns the buttons.

Note:
buttons() returning WFlags<StandardButton> has been renamed to standardButtons() in Wt 3.3.1

Returns the default button.

See also:
setDefaultButton()

Returns the escape button.

See also:
setEscapeButton()
void Wt::WMessageBox::setButtons ( WFlags< StandardButton buttons)

Sets standard buttons for the message box (deprecated).

Deprecated:
this method has been renamed to setStandardButtons().

Sets the button as the default button.

The default button is pressed when the user presses enter. Only one button can be the default button.

If no default button is set, Wt will take a button that is associated with a Wt::Ok or Wt::Yes result.

Sets the button as the default button.

The default button is pressed when the user presses enter. Only one button can be the default button.

The default value is 0 (no default button).

Sets the escape button.

The escape button is pressed when the user presses escapes.

If no escape button is set, Wt will take a button that is associated with a Wt::Cancel or Wt::No result.

Sets the escape button.

The escape button is pressed when the user presses escapes.

If no escape button is set, Wt will take a button that is associated with a Wt::Cancel or Wt::No result.

void Wt::WMessageBox::setHidden ( bool  hidden,
const WAnimation animation = WAnimation() 
) [virtual]

Hides or shows the widget.

Hides or show the widget (including all its descendant widgets). When setting hidden = false, this widget and all descendant widgets that are not hidden will be shown. A widget is only visible if it and all its ancestors in the widget tree are visible, which may be checked using isVisible().

Reimplemented from Wt::WDialog.

StandardButton Wt::WMessageBox::show ( const WString caption,
const WString text,
WFlags< StandardButton buttons,
const WAnimation animation = WAnimation() 
) [static]

Convenience method to show a message box, blocking the current thread.

Show a message box, blocking the current thread until the message box is closed, and return the result. The use of this method is not recommended since it uses WDialog::exec(). See documentation of WDialog for detailed information.

Returns the standard buttons.

See also:
setStandardButtons(), addButton()

Returns the text widget.

This may be useful to customize the style or layout of the displayed text.

 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator

Generated on Tue Mar 22 2016 for the C++ Web Toolkit (Wt) by doxygen 1.7.6.1