The Battle for Wesnoth  1.15.12+dev
password_box.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2018 by Thomas Baumhauer
3  <thomas.baumhauer@NOSPAMgmail.com>
4  Copyright (C) 2009 - 2018 by Mark de Wever <koraq@xs4all.nl>
5  Part of the Battle for Wesnoth Project https://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 #pragma once
18 
19 #include "gui/widgets/text_box.hpp"
20 
21 
22 /**
23  * A class inherited from text_box that displays
24  * its input as stars
25  *
26  * @todo This implementation is quite a hack that
27  * needs to be rewritten cleanly
28  */
29 namespace gui2
30 {
31 namespace implementation
32 {
33  struct builder_password_box;
34 }
35 
36 // ------------ WIDGET -----------{
37 
38 /**
39  * @ingroup GUIWidgetWML
40  *
41  * Key |Type |Default |Description
42  * -------------|------------------------------------|---------|-----------
43  * label | @ref guivartype_t_string "t_string"|"" |The initial text of the password box.
44  */
45 class password_box : public text_box
46 {
47 public:
48  explicit password_box(const implementation::builder_password_box& builder);
49 
50  /** Inherited from text_box_base. */
51  virtual void set_value(const std::string& text) override;
52  std::string get_real_value() const
53  {
54  return real_value_;
55  }
56 
57 
58 protected:
59  void insert_char(const std::string& unicode) override;
60  void paste_selection(const bool mouse) override;
61  void delete_selection() override;
62 
63  // We do not override copy_selection because we
64  // actually want it to copy just the stars
65 
66 private:
67 
68  std::string real_value_;
69 
70 public:
71  /** Static type getter that does not rely on the widget being constructed. */
72  static const std::string& type();
73 
74 private:
75  /** See @ref styled_widget::get_control_type. */
76  virtual const std::string& get_control_type() const override;
77 };
78 
79 // }---------- BUILDER -----------{
80 
81 namespace implementation
82 {
83 
84 // copy & paste from builder_text_box...
85 // does it make more sense to inherit from it?
87 {
88 public:
89  explicit builder_password_box(const config& cfg);
90 
92 
93  virtual widget* build() const override;
94 
95 private:
96  std::string history_;
97 };
98 
99 } // namespace implementation
100 
101 // }------------ END --------------
102 
103 } // namespace gui2
virtual widget * build() const =0
Base class for all widgets.
Definition: widget.hpp:49
Class for a single line text area.
Definition: text_box.hpp:140
Generic file dialog.
Definition: field-fwd.hpp:22
std::string get_real_value() const
std::unique_ptr< window > build(const builder_window::window_resolution &definition)
Builds a window.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.
std::string real_value_
Key Type Default Description label t_string"" The initial text of the password box.