Wt::WDialog Class Reference

A WDialog emulates a modal window. 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.
const WStringcaption () const
 Get the dialog caption.
void setWindowTitle (const WString &title)
 Set the dialog window title.
const WStringwindowTitle () const
 Get the dialog window title.
WContainerWidgetcontents () const
 Get 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 is Accepted.
virtual void reject ()
 Stop a recursive event loop with result is Rejected.
DialogCode result () const
 Get the result that was set for this dialog.
virtual void setHidden (bool hidden)
 Set whether the widget must be hidden.

Public Attributes

Signal< DialogCodefinished
 Signal emitted when the recursive event loop is ended.


Detailed Description

A WDialog emulates a modal window.

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 distinct ways for using a WDialog window.

The easiest way 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 second way is by treating the WDialog as another 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.

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

Only one WDialog window may exist at any time in a single application. An attempt to instantiate a second dialog will result in an exception that terminates the session.

Example code for displaying a dialog and running it using the exec() method:

  // ...

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

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

  // ...

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

WDialog-1.png

A simple custom dialog


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: use setWindowTitle instead

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

Get the dialog caption.

deprecated: use windowTitle instead

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 a recursive event loop.

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

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

Stop a recursive event loop with result is Accepted.

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

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

Stop a recursive event loop with result is Rejected.

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

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

Get the result that was set for this dialog.

See also:
done(DialogCode r)

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

Set 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.


Member Data Documentation

Signal emitted when the recursive event loop is ended.

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


Generated on Mon Nov 3 15:00:59 2008 for Wt by doxygen 1.5.6