File: Popup.h

package info (click to toggle)
witty 3.3.3%2Bdfsg-4.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 28,228 kB
  • ctags: 26,694
  • sloc: cpp: 147,809; ansic: 77,999; xml: 16,331; sh: 1,303; makefile: 198; java: 86; sql: 14
file content (104 lines) | stat: -rw-r--r-- 2,642 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// This may look like C code, but it's really -*- C++ -*-
/*
 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */
#ifndef POPUP_H_
#define POPUP_H_

#include <Wt/WObject>
#include <Wt/WString>
#include <Wt/WJavaScript>

using namespace Wt;

/**
 * @addtogroup javascript
 */
/*@{*/

/*! \brief 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.
 */
class Popup : public WObject
{
public:
  /*! \brief Create a confirm dialog.
   */
  static Popup *createConfirm(const WString& message, WObject *parent = 0);

  /*! \brief Create a prompt dialog with the given default value
   */
  static Popup *createPrompt(const WString& message,
			     const std::string defaultValue,
			     WObject *parent = 0);

  /*! \brief Create an alert dialog.
   */
  static Popup *createAlert(const WString& message, WObject *parent = 0);

  /*! \brief Change the message
   */
  void setMessage(const WString& message);

  /*! \brief Change the default value for a prompt dialog.
   */
  void setDefaultValue(const std::string defaultValue);

  /*! \brief Get the current message.
   */
  const WString& message() const { return message_; }

  /*! \brief Get the default value for a prompt dialog.
   */
  const std::string& defaultValue() const { return defaultValue_; }

  /*! \brief Show the dialog.
   *
   * Use show.exec() to show the dialog, or connect the slot to an EventSignal
   * to directly show the dialog without a server round trip.
   */
  JSlot show;

  /*! \brief Signal emitted when ok pressed.
   */
  JSignal<std::string>& okPressed() { return okPressed_; }

  /*! \brief Signal emitted when cancel is pressed.
   */
  JSignal<void>&        cancelPressed() { return cancelPressed_; }

private:
  /*! \brief Popup type.
   */
  enum Type { Confirm, Alert, Prompt };

  /*! \brief Popup constructor.
   */
  Popup(Type t, const WString& message, const std::string defaultValue,
	WObject *parent);

  JSignal<std::string> okPressed_;
  JSignal<void>        cancelPressed_;

  Type t_;
  WString message_;
  std::string defaultValue_;

  /*! \brief Update the javascript code.
   */
  void setJavaScript();
};

/*@}*/

#endif // POPUP_H_