The Battle for Wesnoth  1.19.0-dev
password_box.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2024
3  by Thomas Baumhauer <thomas.baumhauer@NOSPAMgmail.com>, Mark de Wever <koraq@xs4all.nl>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "gui/widgets/text_box.hpp"
19 
20 
21 /**
22  * A class inherited from text_box that displays
23  * its input as stars
24  *
25  * @todo This implementation is quite a hack that
26  * needs to be rewritten cleanly
27  */
28 namespace gui2
29 {
30 namespace implementation
31 {
32  struct builder_password_box;
33 }
34 
35 // ------------ WIDGET -----------{
36 
37 /**
38  * @ingroup GUIWidgetWML
39  *
40  * Key |Type |Default |Description
41  * -------------|------------------------------------|---------|-----------
42  * label | @ref guivartype_t_string "t_string"|"" |The initial text of the password box.
43  */
44 class password_box : public text_box
45 {
46 public:
47  explicit password_box(const implementation::builder_password_box& builder);
48 
49  /** Inherited from text_box_base. */
50  virtual void set_value(const std::string& text) override;
51  std::string get_real_value() const
52  {
53  return real_value_;
54  }
55 
56 
57 protected:
58  void insert_char(const std::string& unicode) override;
59  void paste_selection(const bool mouse) override;
60  void delete_selection() override;
61 
62  // We do not override copy_selection because we
63  // actually want it to copy just the stars
64 
65 private:
66 
67  std::string real_value_;
68 
69 public:
70  /** Static type getter that does not rely on the widget being constructed. */
71  static const std::string& type();
72 
73 private:
74  /** See @ref styled_widget::get_control_type. */
75  virtual const std::string& get_control_type() const override;
76 };
77 
78 // }---------- BUILDER -----------{
79 
80 namespace implementation
81 {
82 
83 // copy & paste from builder_text_box...
84 // does it make more sense to inherit from it?
86 {
87 public:
88  explicit builder_password_box(const config& cfg);
89 
91 
92  virtual std::unique_ptr<widget> build() const override;
93 
94 private:
95  std::string history_;
96 };
97 
98 } // namespace implementation
99 
100 // }------------ END --------------
101 
102 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
std::string real_value_
void delete_selection() override
Deletes the current selection.
virtual void set_value(const std::string &text) override
Inherited from text_box_base.
virtual const std::string & get_control_type() const override
See styled_widget::get_control_type.
std::string get_real_value() const
password_box(const implementation::builder_password_box &builder)
void paste_selection(const bool mouse) override
Pastes the current selection.
void insert_char(const std::string &unicode) override
Inserts a character at the cursor.
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
const std::string & text() const
Class for a single line text area.
Definition: text_box.hpp:142
Generic file dialog.
Contains the implementation details for lexical_cast and shouldn't be used directly.
virtual std::unique_ptr< widget > build() const override
virtual std::unique_ptr< widget > build() const=0