A JavaScript based popup window, encapsulating the Javascript functions alert(), confirm(), and prompt(). More...
#include <Popup.h>
Inherits Wt::WObject.
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.
Definition at line 32 of file Popup.h.
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.
00014 : WObject(parent), 00015 okPressed_(this, "ok"), 00016 cancelPressed_(this, "cancel"), 00017 t_(t), 00018 message_(message), 00019 defaultValue_(defaultValue) 00020 { 00021 setJavaScript(); 00022 }
JSignal<void>& Popup::cancelPressed | ( | ) | [inline] |
Signal emitted when cancel is pressed.
Definition at line 78 of file Popup.h.
00078 { 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.
00084 { 00085 return new Popup(Prompt, message, defaultValue, parent); 00086 }
const std::string& Popup::defaultValue | ( | ) | const [inline] |
Get the default value for a prompt dialog.
Definition at line 63 of file Popup.h.
00063 { 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.
00067 { 00068 defaultValue_ = defaultValue; 00069 setJavaScript(); 00070 }
void Popup::setJavaScript | ( | ) | [private] |
Update the javascript code.
Definition at line 24 of file Popup.C.
00025 { 00026 /* 00027 * Sets the JavaScript code. 00028 * 00029 * Notice how Wt.emit() is used to emit the okPressed or cancelPressed 00030 * signal, and how arguments may be passed to it, matching the number and 00031 * type of arguments in the JSignal definition. 00032 */ 00033 switch (t_) { 00034 case Confirm: 00035 show.setJavaScript 00036 ("function(){ if (confirm('" + message_.narrow() + "')) {" 00037 + okPressed_.createCall("''") + 00038 "} else {" 00039 + cancelPressed_.createCall() + 00040 "}}"); 00041 break; 00042 case Alert: 00043 show.setJavaScript 00044 ("function(){ alert('" + message_.narrow() + "');" 00045 + okPressed_.createCall("''") + 00046 "}"); 00047 break; 00048 case Prompt: 00049 show.setJavaScript 00050 ("function(){var n = prompt('" + message_.narrow() + "', '" 00051 + defaultValue_ + "');" 00052 "if (n != null) {" 00053 + okPressed_.createCall("n") + 00054 "} else {" 00055 + cancelPressed_.createCall() + 00056 "}}"); 00057 } 00058 }
void Popup::setMessage | ( | const WString & | message | ) |
Change the message.
Definition at line 60 of file Popup.C.
00061 { 00062 message_ = message; 00063 setJavaScript(); 00064 }
JSignal<void> Popup::cancelPressed_ [private] |
std::string Popup::defaultValue_ [private] |
WString Popup::message_ [private] |
JSignal<std::string> Popup::okPressed_ [private] |