Wt examples 3.1.10
|
A JavaScript based popup window, encapsulating the Javascript functions alert(), confirm(), and prompt(). More...
#include <Popup.h>
Public Member Functions | |
void | setMessage (const WString &message) |
Change the message. | |
void | setDefaultValue (const std::string defaultValue) |
Change the default value for a prompt dialog. | |
const WString & | message () const |
Get the current message. | |
const std::string & | defaultValue () const |
Get the default value for a prompt dialog. | |
JSignal< std::string > & | okPressed () |
Signal emitted when ok pressed. | |
JSignal< void > & | cancelPressed () |
Signal emitted when cancel is pressed. | |
Static Public Member Functions | |
static Popup * | createConfirm (const WString &message, WObject *parent=0) |
Create a confirm dialog. | |
static Popup * | createPrompt (const WString &message, const std::string defaultValue, WObject *parent=0) |
Create a prompt dialog with the given default value. | |
static Popup * | createAlert (const WString &message, WObject *parent=0) |
Create an alert dialog. | |
Public Attributes | |
JSlot | show |
Show the dialog. | |
Private Types | |
enum | Type { Confirm, Alert, Prompt } |
Popup type. More... | |
Private Member Functions | |
Popup (Type t, const WString &message, const std::string defaultValue, WObject *parent) | |
Popup constructor. | |
void | setJavaScript () |
Update the javascript code. | |
Private Attributes | |
JSignal< std::string > | okPressed_ |
JSignal< void > | cancelPressed_ |
Type | t_ |
WString | message_ |
std::string | defaultValue_ |
A JavaScript based popup window, encapsulating the Javascript functions alert(), confirm(), and prompt().
Use one of the create static methods to create a popup. This will not display the popup, until either the show slot is triggered from an event handler, or is executed using it's exec() method.
When the user closes the popup, either the okPressed or cancelPressed signal is emitted. For a prompt dialog, the value is passed as a parameter to the okPressed signal.
enum Popup::Type [private] |
Popup::Popup | ( | Type | t, |
const WString & | message, | ||
const std::string | defaultValue, | ||
WObject * | parent | ||
) | [private] |
Popup constructor.
Definition at line 12 of file Popup.C.
: WObject(parent), okPressed_(this, "ok"), cancelPressed_(this, "cancel"), t_(t), message_(message), defaultValue_(defaultValue) { setJavaScript(); }
JSignal<void>& Popup::cancelPressed | ( | ) | [inline] |
Signal emitted when cancel is pressed.
Definition at line 78 of file Popup.h.
{ return cancelPressed_; }
Popup * Popup::createPrompt | ( | const WString & | message, |
const std::string | defaultValue, | ||
WObject * | parent = 0 |
||
) | [static] |
Create a prompt dialog with the given default value.
Definition at line 82 of file Popup.C.
{ return new Popup(Prompt, message, defaultValue, parent); }
const std::string& Popup::defaultValue | ( | ) | const [inline] |
Get the default value for a prompt dialog.
Definition at line 63 of file Popup.h.
{ return defaultValue_; }
const WString& Popup::message | ( | ) | const [inline] |
JSignal<std::string>& Popup::okPressed | ( | ) | [inline] |
void Popup::setDefaultValue | ( | const std::string | defaultValue | ) |
Change the default value for a prompt dialog.
Definition at line 66 of file Popup.C.
{ defaultValue_ = defaultValue; setJavaScript(); }
void Popup::setJavaScript | ( | ) | [private] |
Update the javascript code.
Definition at line 24 of file Popup.C.
{ /* * Sets the JavaScript code. * * Notice how Wt.emit() is used to emit the okPressed or cancelPressed * signal, and how arguments may be passed to it, matching the number and * type of arguments in the JSignal definition. */ switch (t_) { case Confirm: show.setJavaScript ("function(){ if (confirm('" + message_.narrow() + "')) {" + okPressed_.createCall("''") + "} else {" + cancelPressed_.createCall() + "}}"); break; case Alert: show.setJavaScript ("function(){ alert('" + message_.narrow() + "');" + okPressed_.createCall("''") + "}"); break; case Prompt: show.setJavaScript ("function(){var n = prompt('" + message_.narrow() + "', '" + defaultValue_ + "');" "if (n != null) {" + okPressed_.createCall("n") + "} else {" + cancelPressed_.createCall() + "}}"); } }
void Popup::setMessage | ( | const WString & | message | ) |
JSignal<void> Popup::cancelPressed_ [private] |
std::string Popup::defaultValue_ [private] |
WString Popup::message_ [private] |
JSignal<std::string> Popup::okPressed_ [private] |