Wt 3.1.10
Public Types | Public Member Functions
Wt::WDialog Class Reference

A WDialog shows a dialog. More...

#include <Wt/WDialog>

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

List of all members.

Public Types

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

Public Member Functions

 WDialog (const WString &windowTitle=WString())
 Constructs a WDialog with a given window title.
 ~WDialog ()
 Destructs a WDialog.
void setWindowTitle (const WString &title)
 Sets the dialog window title.
const WStringwindowTitle () const
 Returns the dialog window title.
void setCaption (const WString &caption)
 Sets the dialog caption (deprecated).
const WStringcaption () const
 Returns the dialog caption (deprecated).
void setTitleBarEnabled (bool enabled)
 Enables or disables the title bar.
bool isTitleBarEnabled () const
 Returns whether the title bar is enabled.
WContainerWidgettitleBar () const
 Returns the dialog title bar container.
WContainerWidgetcontents () const
 Returns the dialog contents container.
DialogCode exec (const WAnimation &animation=WAnimation())
 Executes the dialog in a recursive event loop.
virtual void done (DialogCode r)
 Stops the dialog.
virtual void accept ()
 Closes the dialog, with result is Accepted.
virtual void reject ()
 Closes the dialog, with result is Rejected.
void rejectWhenEscapePressed ()
 Lets pressing the escape key reject the dialog.
Signal< DialogCode > & finished ()
 Signal emitted when the dialog is closed.
DialogCode result () const
 Returns the result that was set for this dialog.
void setModal (bool modal)
 Sets whether the dialog is modal.
bool isModal () const
 Returns whether the dialog is modal.
virtual void setHidden (bool hidden, const WAnimation &animation=WAnimation())
 Hides or shows the widget.

Detailed Description

A WDialog shows a dialog.

By default, the dialog is modal. 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 (this is enforced at the server side, so you may rely on this behavior).

There are two distinct ways for using a WDialog window.

A WDialog can be used as any other widget. In this case, the WDialog is simply instantiated 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 does not need to be added to a parent widget, but is hidden by default. You must use the method show() or setHidden(true) to show the dialog.

The easiest way to display a modal dialog is using exec(): after creating a WDialog window, a call to exec() will block (suspend the thread) until the dialog window is closed, and return the dialog result. Typically, an OK button will be connected to accept(), and in some cases a Cancel button to reject(). This solution has the drawback that it is not scalable to many concurrent sessions, since for every session with a recursive event loop (which is running durring the exec() method), a thread is locked. In practical terms, this means it is only suitable for software with restricted access or deployed on an intranet or extranet.

Use setModal(false) to create a non-modal dialog. A non-modal dialog does not block the underlying user interface: the user must not first deal with the dialog before interacting with the rest of the user interface.

Contents for the dialog is defined by adding it to the contents() widget.

Usage example, using the exec() method:

 Wt::WDialog dialog("Personalia");
  
 new Wt::WText("Enter your name: ", dialog.contents());
 Wt::WLineEdit edit(dialog.contents());
 new Wt::WBreak(dialog.contents());
  
 Wt::WPushButton ok("Ok", dialog.contents());

 // these events will accept() the Dialog
 edit.enterPressed().connect(&dialog, &Wt::WDialog::accept);
 ok.clicked().connect(&dialog, &Wt::WDialog::accept);
  
 if (dialog.exec() == Wt::WDialog::Accepted)
   setStatus("Welcome, " + edit.text());

This dialog looks like this (using the standard look):

WDialog-default-1.png
A simple custom dialog (default)
WDialog-polished-1.png
A simple custom dialog (polished)

CSS

A dialog has the Wt-dialog and Wt-outset style classes. The look can be overridden using the following style class selectors:

 .Wt-dialog .titlebar : The title bar
 .Wt-dialog .body     : The body (requires vertical padding 4px).
 
Note:
For the dialog (or rather, the silkscreen covering the user interface below) to render properly in IE, the "html body" margin is set to 0 (if it wasn't already).

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::WDialog::WDialog ( const WString windowTitle = WString())

Constructs a WDialog with a given window title.

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


Member Function Documentation

void Wt::WDialog::accept ( ) [virtual]

Closes the dialog, with result is Accepted.

See also:
done(DialogCode r), reject()
const WString & Wt::WDialog::caption ( ) const

Returns the dialog caption (deprecated).

Deprecated:
Use windowTitle() instead.
WContainerWidget* Wt::WDialog::contents ( ) const

Returns the dialog contents container.

Content to the dialog window may be added to this container widget.

void Wt::WDialog::done ( DialogCode  r) [virtual]

Stops the dialog.

Sets the dialog result, and emits the finished() signal.

If a recursive event loop was started using the exec() method, it is ended.

See also:
finished(), result()
WDialog::DialogCode Wt::WDialog::exec ( const WAnimation animation = WAnimation())

Executes 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::WDialog::finished ( )

Signal emitted when the dialog is closed.

See also:
done(DialogCode r), accept(), reject()
bool Wt::WDialog::isModal ( ) const

Returns whether the dialog is modal.

See also:
setModal()
bool Wt::WDialog::isTitleBarEnabled ( ) const

Returns whether the title bar is enabled.

See also:
setTitleBarEnabled()
void Wt::WDialog::reject ( ) [virtual]

Closes the dialog, with result is Rejected.

See also:
done(DialogCode r), accept()
void Wt::WDialog::rejectWhenEscapePressed ( )

Lets pressing the escape key reject the dialog.

Before Wt 3.1.5, pressing escape automatically rejected the dialog. Since 3.1.4 this behaviour is no longer the default since it may interfere with other functionality in the dialog. Use this method to enable this behaviour.

See also:
reject()
DialogCode Wt::WDialog::result ( ) const

Returns the result that was set for this dialog.

See also:
done(DialogCode r)
void Wt::WDialog::setCaption ( const WString caption)

Sets the dialog caption (deprecated).

Deprecated:
Use setWindowTitle() instead.
void Wt::WDialog::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::WCompositeWidget.

void Wt::WDialog::setModal ( bool  modal)

Sets whether the dialog is modal.

A modal dialog will block the underlying user interface.

By default a dialog is modal.

void Wt::WDialog::setTitleBarEnabled ( bool  enabled)

Enables or disables the title bar.

The titlebar is enabled by default.

void Wt::WDialog::setWindowTitle ( const WString title)

Sets the dialog window title.

The window title is displayed in the title bar.

See also:
setTitleBarEnabled()
WContainerWidget* Wt::WDialog::titleBar ( ) const

Returns the dialog title bar container.

The title bar contains a single text that contains the caption. You may customize the title bar by for example adding other content.

const WString & Wt::WDialog::windowTitle ( ) const

Returns the dialog window title.

See also:
setWindowTitle()
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator

Generated on Mon Nov 14 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.4