Wt  3.2.2
Public Types | Public Member Functions
Wt::Ext::Dialog Class Reference

A dialog emulates a modal window that blocks the user-interface. More...

#include <Wt/Ext/Dialog>

Inheritance diagram for Wt::Ext::Dialog:
Inheritance graph
[legend]

List of all members.

Public Types

enum  DialogCode { Rejected, Accepted }
 The result of a modal dialog execution. More...

Public Member Functions

 Dialog (const WString &windowTitle=WString())
 Construct a Dialog with a given window title.
 ~Dialog ()
 Destruct a Dialog.
void setWindowTitle (const WString &windowTitle)
 Set the dialog window title.
const WStringwindowTitle () const
 Return the dialog window title.
WContainerWidgetcontents () const
 Return the dialog contents container.
DialogCode exec ()
 Execute the dialog in a recursive event loop.
virtual void done (DialogCode r)
 Stop a recursive event loop.
virtual void accept ()
 Stop a recursive event loop with result Accepted.
virtual void reject ()
 Stop a recursive event loop with result Rejected.
Signal< DialogCode > & finished ()
 Signal emitted when the recursive event loop is ended.
DialogCode result () const
 Return the result that was set for this dialog.
virtual void setHidden (bool hidden, const WAnimation &animation=WAnimation())
 Hides or shows the widget.
void addButton (Button *button)
 Add a button at the bottom of this dialog.
void removeButton (Button *button)
 Remove a button from the bottom of this dialog.
const std::vector< Button * > & buttons () const
 Return the list of buttons at the bottom of this dialog.
void setDefaultButton (Button *button)
 Configure a default button for this dialog.
ButtondefaultButton () const
 Return the default button for this dialog.
void setSizeGripEnabled (bool enabled)
 Configure a size grip to allow the user to resize this dialog.
bool isSizeGripEnabled () const
 Return if the size grip is enabled.

Detailed Description

A dialog emulates a modal window that blocks the user-interface.

A modal window blocks the user interface, and does not allow the user to interact with any other part of the user interface until the dialog is closed.

There are two ways for using a Dialog window.

The easiest way is using the exec() method: after creating a Dialog window, call the exec() method which blocks until the dialog window is closed, and returns the dialog result. Typically, an OK button will be connected to the accept() slot, and a Cancel button to the reject() slot. This solution has the drawback that it is not scalable to many concurrent sessions, since every recursive event loop (which is running during the exec() method) locks a thread. Therefore it is only suitable for software that doesn't need to scale (to thousands of users).

A second way is by treating the Dialog as another widget. The dialog may be closed by calling accept(), reject() or done() (or connecting a signal to one of these methods). This will hide the dialog and emit the finished() signal, which you then can listen for to process the dialog result and delete the dialog. Unlike other widgets, a dialog is hidden by default. You must use the method show() or setHidden(true) to show the dialog.

Since Dialog is a Panel, the dialog contents may be layed out inside the dialog using layout managers. To be compatible with WDialog howevere, a contents() method is provided which creates a WFitLayout that fits a single WContainerWidget widget inside the dialog.

Only one Dialog window may exist at any time in a single application. An attempt to instantiate a second dialog will result in undefined behaviour.

The API is a superset of the WDialog API:

ExtDialog-1.png
An example Dialog using BorderLayouts

Member Enumeration Documentation

The result of a modal dialog execution.

Enumerator:
Rejected 

Dialog closed with reject()

Accepted 

Dialog closed with accept()


Constructor & Destructor Documentation

Wt::Ext::Dialog::Dialog ( const WString windowTitle = WString())

Construct a Dialog with a given window title.

Only a single Dialog may be constructed at any time. Unlike other widgets, a dialog should not need be added to a container widget to be displayed.


Member Function Documentation

void Wt::Ext::Dialog::accept ( ) [virtual]

Stop a recursive event loop with result Accepted.

See also:
done(DialogCode), reject()
void Wt::Ext::Dialog::addButton ( Button button)

Add a button at the bottom of this dialog.

Is the same as Panel::addFooterButton()

const std::vector<Button *>& Wt::Ext::Dialog::buttons ( ) const

Return the list of buttons at the bottom of this dialog.

Is the same as Panel::footerButtons()

Reimplemented in Wt::Ext::MessageBox.

WContainerWidget * Wt::Ext::Dialog::contents ( ) const

Return the dialog contents container.

The first invocation to this method creates a single WContainerWidget that is fitted in the panel content area, like this:

 WContainerWidget *contents = new WContainerWidget();
 dialog->setLayout(new WFitLayout());
 dialog->layout()->addWidget(contents);
Button * Wt::Ext::Dialog::defaultButton ( ) const

Return the default button for this dialog.

See also:
setDefaultButton(), Button::isDefault()

Reimplemented from Wt::Ext::Panel.

void Wt::Ext::Dialog::done ( DialogCode  r) [virtual]

Stop a recursive event loop.

Sets the dialog result, and ends a recursive event loop that was started using the exec() method.

Dialog::DialogCode Wt::Ext::Dialog::exec ( )

Execute the dialog in a recursive event loop.

Executes the dialog. This blocks the current thread of execution until one of done(DialogCode), accept() or reject() is called.

Warning: using exec() does not scale to many concurrent sessions, since the thread is locked.

See also:
done(DialogCode r), accept(), reject()
Signal<DialogCode>& Wt::Ext::Dialog::finished ( )

Signal emitted when the recursive event loop is ended.

See also:
done(DialogCode), accept(), reject()
bool Wt::Ext::Dialog::isSizeGripEnabled ( ) const

Return if the size grip is enabled.

See also:
setSizeGripEnabled()
void Wt::Ext::Dialog::reject ( ) [virtual]

Stop a recursive event loop with result Rejected.

See also:
done(DialogCode), accept()
void Wt::Ext::Dialog::removeButton ( Button button)

Remove a button from the bottom of this dialog.

The button must have been previously added using addButton(). Is the same as Panel::removeFooterButton()

DialogCode Wt::Ext::Dialog::result ( ) const

Return the result that was set for this dialog.

See also:
done(DialogCode)
void Wt::Ext::Dialog::setDefaultButton ( Button button)

Configure a default button for this dialog.

The button must have been previously added using addButton(). A default button is activated when the user presses Return in the dialog.

See also:
Button::setDefault()

Reimplemented from Wt::Ext::Panel.

void Wt::Ext::Dialog::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::Ext::Widget.

Reimplemented in Wt::Ext::MessageBox.

void Wt::Ext::Dialog::setSizeGripEnabled ( bool  enabled)

Configure a size grip to allow the user to resize this dialog.

When a size grip is enabled, then the user may resize the dialog window.

The default is true.

void Wt::Ext::Dialog::setWindowTitle ( const WString windowTitle)

Set the dialog window title.

Is the same as Panel::setTitle(const WString&)

const WString& Wt::Ext::Dialog::windowTitle ( ) const

Return the dialog window title.

Is the same as Panel::title()

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator

Generated on Fri Jul 27 2012 for the C++ Web Toolkit (Wt) by doxygen 1.7.5.1