Wt
3.3.0
|
A WDialog shows a dialog. More...
#include <Wt/WDialog>
Public Types | |
enum | DialogCode { Rejected, Accepted } |
The result of a modal dialog execution. More... | |
Public Member Functions | |
WDialog (WObject *parent=0) | |
Constructs a new dialog. | |
WDialog (const WString &windowTitle, WObject *parent=0) | |
Constructs a dialog with a given window title. | |
~WDialog () | |
Deletes a dialog. | |
void | setWindowTitle (const WString &title) |
Sets the dialog window title. | |
WString | windowTitle () const |
Returns the dialog window title. | |
void | setCaption (const WString &caption) |
Sets the dialog caption (deprecated). | |
WString | caption () 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. | |
WContainerWidget * | titleBar () const |
Returns the dialog title bar container. | |
WContainerWidget * | contents () const |
Returns the dialog contents container. | |
WContainerWidget * | footer () const |
Returns the dialog footer 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. | |
virtual void | setMinimumSize (const WLength &width, const WLength &height) |
Sets a minimum size. | |
virtual void | setMaximumSize (const WLength &width, const WLength &height) |
Sets a maximum size. | |
Protected Member Functions | |
void | render (WFlags< RenderFlag > flags) |
Renders the widget. |
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(false) 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 until exec() returns. A thread that is locked by a recursive event loop cannot be used to process requests from another sessions. When all threads in the threadpool are locked in recursive event loops, the server will be unresponsive to requests from any other session. In practical terms, this means you must not use exec(), unless your application will never be used by more concurrent users than the amount of threads in your threadpool (like on some intranets or extranets).
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 (not recommended):
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());
Usage example, using the asynchronous method (recommended):
void MyClass::showDialog() { dialog_ = new WDialog("Personalia"); new Wt::WText("Enter your name: ", dialog_->contents()); Wt::WLineEdit *edit = new Wt::WLineEdit(dialog_->contents()); new Wt::WBreak(dialog_->contents()); Wt::WPushButton *ok = new Wt::WPushButton("Ok", dialog_->contents()); // these events will accept() the Dialog edit->enterPressed().connect(dialog_, &Wt::WDialog::accept); ok->clicked().connect(dialog_, &Wt::WDialog::accept); dialog_->finished().connect(this, &MyClass::dialogDone); dialog_->show(); } void MyClass::dialogDone(DialogCode code) { if (code == Wt::WDialog::Accepted) setStatus("Welcome, " + edit_->text()); delete dialog_; }
This dialog looks like this (using the default css themes):
![]()
A simple custom dialog (default) | ![]()
A simple custom dialog (polished) |
Wt::WDialog::WDialog | ( | WObject * | parent = 0 | ) |
Constructs a new dialog.
Unlike other widgets, the dialog does not require a parent container since it is a top-level widget. You may however still provide a parent object to let the dialog be deleted together with its parent.
Constructs a dialog with a given window title.
Unlike other widgets, the dialog does not require a parent container since it is a top-level widget. You may however still provide a parent object to let the dialog be deleted together with its parent.
void Wt::WDialog::accept | ( | ) | [virtual] |
Closes the dialog, with result is Accepted.
WString Wt::WDialog::caption | ( | ) | const |
Returns the dialog caption (deprecated).
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.
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 until exec returns, so the entire server will be unresponsive when the thread pool is exhausted.
Signal<DialogCode>& Wt::WDialog::finished | ( | ) |
Signal emitted when the dialog is closed.
WContainerWidget * Wt::WDialog::footer | ( | ) | const |
Returns the dialog footer container.
This is an optional section which is typically used for buttons.
bool Wt::WDialog::isModal | ( | ) | const |
Returns whether the dialog is modal.
bool Wt::WDialog::isTitleBarEnabled | ( | ) | const |
Returns whether the title bar is enabled.
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).
Reimplemented from Wt::WWidget.
void Wt::WDialog::reject | ( | ) | [virtual] |
Closes the dialog, with result is Rejected.
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.
void Wt::WDialog::render | ( | WFlags< RenderFlag > | flags | ) | [protected, virtual] |
Renders the widget.
This function renders the widget (or an update for the widget), after this has been scheduled using scheduleRender().
The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.
Reimplemented from Wt::WPopupWidget.
bool Wt::WDialog::resizable | ( | ) | const |
Returns whether the dialog has a resize handle.
DialogCode Wt::WDialog::result | ( | ) | const |
Returns the result that was set for this dialog.
void Wt::WDialog::setCaption | ( | const WString & | caption | ) |
Sets the dialog caption (deprecated).
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::WPopupWidget.
Sets a maximum size.
Specifies a maximum size for this widget, setting CSS max-width
and max-height
properties.
The default the maximum width and height are WLength::Auto, indicating no maximum size. A WLength::Percentage size should not be used, as this is (in virtually all cases) undefined behaviour.
When the widget is a container widget that contains a layout manager, then setting a maximum size will have the effect of letting the size of the container to reflect the preferred size of the contents (rather than constraining the size of the children based on the size of the container), up to the specified maximum size.
Reimplemented from Wt::WCompositeWidget.
Sets a minimum size.
Specifies a minimum size for this widget, setting CSS min-width
and min-height
properties.
The default minimum width and height is 0. The special value WLength::Auto indicates that the initial width is used as minimum size. A WLength::Percentage size should not be used, as this is (in virtually all cases) undefined behaviour.
When the widget is inserted in a layout manager, then the minimum size will be taken into account.
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.
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.
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.
WString Wt::WDialog::windowTitle | ( | ) | const |
Returns the dialog window title.