The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
password_box.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Thomas Baumhauer
4  Copyright (C) 2009 - 2016 by Mark de Wever <[email protected]>
5  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY.
13 
14  See the COPYING file for more details.
15 */
16 
17 #ifndef GUI_WIDGETS_PASSWORD_BOX_HPP_INCLUDED
18 #define GUI_WIDGETS_PASSWORD_BOX_HPP_INCLUDED
19 
20 #include "gui/widgets/text_box.hpp"
21 
22 
23 /**
24  * A class inherited from ttext_box that displays
25  * its input as stars
26  *
27  * @todo This implementation is quite a hack that
28  * needs to be rewritten cleanly
29  */
30 namespace gui2
31 {
32 
33 // ------------ WIDGET -----------{
34 
35 class tpassword_box : public ttext_box
36 {
37 
38  // The hack works like this: we add the member real_value_
39  // that holds the actual user input.
40  // Overridden functions now simply
41  // - call set_value() from ttext_box with real_value_,
42  // which is done in prefunction()
43  // - call ttext_box::overridden_function()
44  // - set real_value_ to get_value() from ttext_box and
45  // call set_value() from ttext_box with real_value_
46  // turned into stars, which is done in post_function()
47  //
48  // and overridden function should therefore look like this:
49  //
50  // overridden_function(some parameter) {
51  // pre_function();
52  // ttext_box::overridden_function(some parameter);
53  // post_function();
54  // }
55 
56 public:
58  {
59  }
60 
61  /** Inherited from ttext_. */
62  virtual void set_value(const std::string& text);
64  {
65  return real_value_;
66  }
67 
68 
69 protected:
70  void insert_char(const utf8::string& unicode);
71  void delete_char(const bool before_cursor);
72 
73  void paste_selection(const bool mouse);
74 
75  // We do not override copy_selection because we
76  // actually want it to copy just the stars
77 
78 private:
79  void handle_key_backspace(SDLMod modifier, bool& handled);
80  void handle_key_delete(SDLMod modifier, bool& handled);
81 
82  void pre_function();
83  void post_function();
84 
86 
87  /** See @ref tcontrol::get_control_type. */
88  virtual const std::string& get_control_type() const override;
89 };
90 
91 // }---------- BUILDER -----------{
92 
93 namespace implementation
94 {
95 
96 // copy & paste from tbuilder_text_box...
97 // does it make more sense to inherit from it?
99 {
100 public:
101  explicit tbuilder_password_box(const config& cfg);
102 
104 
105  twidget* build() const;
106 
107 private:
109 };
110 
111 } // namespace implementation
112 
113 // }------------ END --------------
114 
115 } // namespace gui2
116 
117 #endif
void handle_key_delete(SDLMod modifier, bool &handled)
Delete key pressed.
#define SDLMod
Definition: compat.hpp:30
Class for a single line text area.
Definition: text_box.hpp:118
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
void delete_char(const bool before_cursor)
Deletes the character.
virtual twidget * build() const =0
void handle_key_backspace(SDLMod modifier, bool &handled)
Backspace key pressed.
virtual void set_value(const std::string &text)
Inherited from ttext_.
std::string get_real_value() const
virtual const std::string & get_control_type() const override
See tcontrol::get_control_type.
void insert_char(const utf8::string &unicode)
Inserts a character at the cursor.
std::string real_value_
Base class for all widgets.
Definition: widget.hpp:49
const std::string & text() const
Definition: text.hpp:81
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
void paste_selection(const bool mouse)
Pastes the current selection.
GLsizei const GLcharARB ** string
Definition: glew.h:4503
Contains the implementation details for lexical_cast and shouldn't be used directly.
std::string string