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())
 Construct a WDialog with a given window title.
 ~WDialog ()
 Destruct a WDialog.
void setCaption (const WString &caption)
 Set the dialog caption (deprecated).
const WStringcaption () const
 Get the dialog caption (deprecated).
void setWindowTitle (const WString &title)
 Set the dialog window title.
const WStringwindowTitle () const
 Get the dialog window title.
void setTitleBarEnabled (bool enabled)
 Enable or disable the title bar.
bool isTitleBarEnabled () const
 Returns whether the title bar is enabled.
WContainerWidgetcontents () const
 Get the dialog contents container.
DialogCode exec ()
 Execute the dialog in a recursive event loop.
virtual void done (DialogCode r)
 Stop the dialog.
virtual void accept ()
 Close the dialog, with result is Accepted.
virtual void reject ()
 Close the dialog, with result is Rejected.
Signal< DialogCode > & finished ()
 Signal emitted when the dialog is closed.
DialogCode result () const
 Get the result that was set for this dialog.
void setModal (bool modal)
 Set whether the dialog is modal.
bool isModal () const
 Returns whether the dialog is modal.
virtual void setHidden (bool hidden)
 Sets whether the widget must be hidden.
virtual void resize (const WLength &width, const WLength &height)
 Resizes 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.

The easiest way to display a modal dialog is using the exec() method: after creating a WDialog 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 durring the exec() method) locks a thread. Therefore it is only suitable for software to be deployed on an intranet.

A WDialog can be used as any other widget. In this case, the WDialog is created with the proper content, and for example an OK button is connected to a method which deletes the dialog. Unlike other widgets, a dialog is hidden by default. You must use the method show() or setHidden(true) to show the dialog.

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. Multiple non-modal dialogs may be open at the same time.

Widgets may be added to the dialog, by adding to the contents() ContainerWidget.

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(SLOT(&dialog, Wt::WDialog::accept));
 ok.clicked().connect(SLOT(&dialog, Wt::WDialog::accept));
  
 if (dialog.exec() == Wt::WDialog::Accepted)
   setStatus("Welcome, " + edit.text());

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

WDialog-1.png

A simple custom dialog

Note:
Currently only one modal dialog can be shown at a time, but you can show as many non-modal dialogs as you want.

For the dialog to render properly in IE, the "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()  ) 

Construct 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::setCaption ( const WString caption  ) 

Set the dialog caption (deprecated).

Deprecated:
Use setWindowTitle() instead.

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

Get the dialog caption (deprecated).

Deprecated:
Use windowTitle() instead.

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

Set the dialog window title.

The window title is displayed in the title bar.

See also:
setTitleBarEnabled()

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

Get the dialog window title.

See also:
setWindowTitle()

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

Enable or disable the title bar.

The titlebar is enabled by default.

bool Wt::WDialog::isTitleBarEnabled (  )  const [inline]

Returns whether the title bar is enabled.

See also:
setTitleBarEnabled()

WContainerWidget* Wt::WDialog::contents (  )  const [inline]

Get the dialog contents container.

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

WDialog::DialogCode Wt::WDialog::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()

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

Stop 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()

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

Close the dialog, with result is Accepted.

See also:
done(DialogCode r), reject()

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

Close the dialog, with result is Rejected.

See also:
done(DialogCode r), accept()

Signal<DialogCode>& Wt::WDialog::finished (  )  [inline]

Signal emitted when the dialog is closed.

See also:
done(DialogCode r), accept(), reject()

DialogCode Wt::WDialog::result (  )  const [inline]

Get the result that was set for this dialog.

See also:
done(DialogCode r)

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

Set whether the dialog is modal.

A modal dialog will block the underlying user interface.

By default a dialog is modal.

bool Wt::WDialog::isModal (  )  const [inline]

Returns whether the dialog is modal.

See also:
setModal()

void Wt::WDialog::setHidden ( bool  hidden  )  [virtual]

Sets whether the widget must be hidden.

Hide or show the widget (including all its descendant widgets). setHidden(false) will show this widget and all child widgets that are not hidden.

See also:
hide(), show()

Reimplemented from Wt::WCompositeWidget.

void Wt::WDialog::resize ( const WLength width,
const WLength height 
) [virtual]

Resizes the widget.

Specify a new size for this widget, by specifying width and height. By default a widget has automatic width and height, see WLength::isAuto().

This applies to CSS-based layout.

See also:
width(), height()

Reimplemented from Wt::WCompositeWidget.


Generated on Tue Sep 1 17:51:15 2009 for Wt by doxygen 1.5.6