Wt  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
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.
void setResizable (bool resizable)
 Adds a resize handle to the dialog.
bool resizable () const
 Returns whether the dialog has a resize handle.
void setClosable (bool closable)
 Adds a close button to the titlebar.
bool closable () const
 Returns whether the dialog can be closed.
virtual void setHidden (bool hidden, const WAnimation &animation=WAnimation())
 Hides or shows the widget.
virtual void positionAt (const WWidget *widget, Orientation orientation=Vertical)
 Positions a widget next to another widget.
- Public Member Functions inherited from Wt::WCompositeWidget
 WCompositeWidget (WContainerWidget *parent=0)
 Creates a WCompositeWidget.
 WCompositeWidget (WWidget *implementation, WContainerWidget *parent)
 Creates a WCompositeWidget with given implementation.
virtual const std::string id () const
 Returns the (unique) identifier for this object.
virtual void setPositionScheme (PositionScheme scheme)
 Sets the CSS position scheme.
virtual PositionScheme positionScheme () const
 Returns the CSS position scheme.
virtual void setOffsets (const WLength &offset, WFlags< Side > sides=All)
 Sets CSS offsets for a non-statically positioned widget.
virtual WLength offset (Side s) const
 Returns a CSS offset.
virtual void resize (const WLength &width, const WLength &height)
 Resizes the widget.
virtual WLength width () const
 Returns the width.
virtual WLength height () const
 Returns the height.
virtual void setMinimumSize (const WLength &width, const WLength &height)
 Sets a minimum size.
virtual WLength minimumWidth () const
 Returns the minimum width.
virtual WLength minimumHeight () const
 Returns the minimum height.
virtual void setMaximumSize (const WLength &width, const WLength &height)
 Sets a maximum size.
virtual WLength maximumWidth () const
 Returns the maximum width.
virtual WLength maximumHeight () const
 Returns the maximum height.
virtual void setLineHeight (const WLength &height)
 Sets the CSS line height for contained text.
virtual WLength lineHeight () const
 Returns the CSS line height for contained text.
virtual void setFloatSide (Side s)
 Specifies a CSS float side.
virtual Side floatSide () const
 Returns the CSS float side.
virtual void setClearSides (WFlags< Side > sides)
 Sets the sides that should be cleared of floats.
virtual WFlags< SideclearSides () const
 Returns the sides that should remain empty.
virtual void setMargin (const WLength &margin, WFlags< Side > sides=All)
 Sets CSS margins around the widget.
virtual WLength margin (Side side) const
 Returns a CSS margin set.
virtual void setHiddenKeepsGeometry (bool enabled)
 Sets whether the widget keeps its geometry when hidden.
virtual bool hiddenKeepsGeometry () const
 Returns whether the widget keeps its geometry when hidden.
virtual bool isHidden () const
 Returns whether the widget is set hidden.
virtual bool isVisible () const
 Returns whether the widget is visible.
virtual void setDisabled (bool disabled)
 Sets whether the widget is disabled.
virtual bool isDisabled () const
 Returns whether the widget is set disabled.
virtual bool isEnabled () const
 Returns whether the widget is enabled.
virtual void setPopup (bool popup)
 Lets the widget overlay over other sibling widgets.
virtual bool isPopup () const
 Returns whether the widget is overlayed.
virtual void setInline (bool isInline)
 Sets whether the widget is displayed inline or as a block.
virtual bool isInline () const
 Returns whether the widget is displayed inline or as block.
virtual void setDecorationStyle (const WCssDecorationStyle &style)
 Sets a CSS decoration style.
virtual WCssDecorationStyledecorationStyle ()
 Returns the decoration style of this widget.
virtual void setStyleClass (const WString &styleClass)
 Sets (one or more) CSS style classes.
virtual WString styleClass () const
 Returns the CSS style class.
virtual void addStyleClass (const WString &styleClass, bool force=false)
 Adds a CSS style class.
virtual void removeStyleClass (const WString &styleClass, bool force=false)
 Removes a CSS style class.
virtual void setVerticalAlignment (AlignmentFlag alignment, const WLength &length=WLength::Auto)
 Sets the vertical alignment.
virtual AlignmentFlag verticalAlignment () const
 Returns the vertical alignment.
virtual WLength verticalAlignmentLength () const
 Returns the fixed vertical alignment that was set.
virtual void setToolTip (const WString &text, TextFormat textFormat=PlainText)
 Sets a tooltip.
virtual WString toolTip () const
 Returns the tooltip.
virtual void refresh ()
 Refresh the widget.
virtual void setAttributeValue (const std::string &name, const WString &value)
 Sets an attribute value.
virtual WString attributeValue (const std::string &name) const
 Returns an attribute value.
virtual void setJavaScriptMember (const std::string &name, const std::string &value)
 Sets a JavaScript member.
virtual std::string javaScriptMember (const std::string &name) const
 Returns the value of a JavaScript member.
virtual void callJavaScriptMember (const std::string &name, const std::string &args)
 Calls a JavaScript member.
virtual void load ()
 Loads content just before the widget is used.
virtual bool loaded () const
 Returns whether this widget has been loaded.
virtual void setTabIndex (int index)
 Sets the tab index.
virtual int tabIndex () const
 Returns the tab index.
virtual void setId (const std::string &id)
 Sets the CSS Id.
virtual WWidgetfind (const std::string &name)
 Finds a descendent widget by name.
virtual void setSelectable (bool selectable)
 Sets as selectable.
virtual void doJavaScript (const std::string &js)
 Executes the given JavaScript statements when the widget is rendered or updated.
virtual void propagateSetEnabled (bool enabled)
 Propagates that a widget was enabled or disabled through children.
- Public Member Functions inherited from Wt::WWidget
virtual ~WWidget ()
 Destructor.
WWidgetparent () const
 Returns the parent widget.
void setWidth (const WLength &width)
 Sets the width.
void setHeight (const WLength &height)
 Sets the height.
std::string jsRef () const
 Returns a JavaScript expression to the corresponding DOM node.
virtual void acceptDrops (const std::string &mimeType, const WString &hoverStyleClass=WString())
 Sets a mime type to be accepted for dropping.
virtual void stopAcceptDrops (const std::string &mimeType)
 Indicates that a mime type is no longer accepted for dropping.
virtual void htmlText (std::ostream &out)
 Streams the (X)HTML representation.
bool isRendered () const
 Returns whether the widget is rendered.
void hide ()
 Hides the widget.
void animateHide (const WAnimation &animation)
 Hides the widget using an animation.
void show ()
 Shows the widget.
void animateShow (const WAnimation &animation)
 Shows the widget using an animation.
void enable ()
 Enables the widget.
void disable ()
 Disable thes widget.
bool layoutSizeAware () const
 Returns whether the widget is layout size aware.
- Public Member Functions inherited from Wt::WObject
 WObject (WObject *parent=0)
 Create a WObject with a given parent object.
virtual ~WObject ()
 Destructor.
void setObjectName (const std::string &name)
 Sets an object name.
virtual std::string objectName () const
 Returns the object name.
void resetLearnedSlots ()
 Resets learned stateless slot implementations.
template<class T >
void resetLearnedSlot (void(T::*method)())
 Resets a learned stateless slot implementation.
template<class T >
WStatelessSlot * implementStateless (void(T::*method)())
 Declares a slot to be stateless and learn client-side behaviour on first invocation.
template<class T >
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
 Declares a slot to be stateless and learn client-side behaviour in advance.
template<class T >
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 Provides a JavaScript implementation for a method.
void addChild (WObject *child)
 Adds a child object.
virtual void removeChild (WObject *child)
 Removes a child object.
const std::vector< WObject * > & children () const
 Returns the children.

Additional Inherited Members

- Protected Member Functions inherited from Wt::WCompositeWidget
virtual void enableAjax ()
 Progresses to an Ajax-enabled widget.
void setImplementation (WWidget *widget)
 Set the implementation widget.
WWidgetimplementation ()
 Get the implementation widget.
virtual int boxPadding (Orientation orientation) const
 Returns the widget's built-in padding.
virtual int boxBorder (Orientation orientation) const
 Returns the widget's built-in border width.
- Protected Member Functions inherited from Wt::WWidget
void setLayoutSizeAware (bool sizeAware)
 Sets the widget to be aware of its size set by a layout manager.
virtual void layoutSizeChanged (int width, int height)
 Virtual method that indicates a size change.
 WWidget (WContainerWidget *parent=0)
 Creates a widget.
virtual void dropEvent (WDropEvent dropEvent)
 Handles a drop event.
virtual WStatelessSlot * getStateless (Method method)
 On-demand stateless slot implementation.

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

A modal dialog can be instantiated synchronously or asynchronously. A non-modal dialog can only be instantiated asynchronously.

When using a dialog asynchronously, there is no API call that waits for the dialog to be closed. Then, the usage is similar to instantiating any other 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 synchronous use of a dialog involves a call to exec() which will block (suspend the thread) until the dialog window is closed, and return the dialog result. Events within dialog are handled using a so-called recursive event loop. 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, 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
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 synchronously. 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::positionAt ( const WWidget widget,
Orientation  orientation = Vertical 
)
virtual

Positions a widget next to another widget.

Positions this absolutely positioned widget next to another widget. Both widgets must be visible.

When orientation = Wt::Vertical, the widget is displayed below the other widget (or above in case there is not enough room below). It is aligned so that the left edges align (or the right edges if there is not enough room to the right).

Conversely, when orientation = Wt::Horizontal, the widget is displayed to the right of the other widget (or to the left in case there is not enough room to the right). It is aligned so that the top edges align (or the bottom edges if there is not enough room below).

Note:
This only works if JavaScript is available.

Reimplemented from Wt::WWidget.

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()
bool Wt::WDialog::resizable ( ) const

Returns whether the dialog has a resize handle.

See also:
setResizable()
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::setClosable ( bool  closable)

Adds a close button to the titlebar.

The close button is shown in the title bar. Clicking the close button will reject the dialog.

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. A modal dialog can be shown synchronously or asynchronously. A non-modal dialog can only be shown asynchronously.

By default a dialog is modal.

void Wt::WDialog::setResizable ( bool  resizable)

Adds a resize handle to the dialog.

The resize handle is shown in the bottom right corner of the dialog, and allows the user to resize the dialog (but not smaller than the content allows).

This also sets the minimum width and height to WLength::Auto to use the initial width and height as minimum sizes. You may want to provide other values for minimum width and height to allow the dialog to be reduced in size.

See also:
setMinimumSize(), setMaximumSize()
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()

Generated on Sun May 27 2012 for the C++ Web Toolkit (Wt) by doxygen 1.8.1