The Battle for Wesnoth  1.19.5+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 class password_box : public text_box
38 {
39 public:
40  explicit password_box(const implementation::builder_password_box& builder);
41 
42  /** Inherited from text_box_base. */
43  virtual void set_value(const std::string& text) override;
44  std::string get_real_value() const
45  {
46  return real_value_;
47  }
48 
49 
50 protected:
51  void insert_char(const std::string& unicode) override;
52  void paste_selection() override;
53  void delete_selection() override;
54 
55  // We do not override copy_selection because we
56  // actually want it to copy just the stars
57 
58 private:
59 
60  std::string real_value_;
61 
62 public:
63  /** Static type getter that does not rely on the widget being constructed. */
64  static const std::string& type();
65 
66 private:
67  /** See @ref styled_widget::get_control_type. */
68  virtual const std::string& get_control_type() const override;
69 };
70 
71 // }---------- BUILDER -----------{
72 
73 namespace implementation
74 {
75 
76 // copy & paste from builder_text_box...
77 // does it make more sense to inherit from it?
79 {
80 public:
81  explicit builder_password_box(const config& cfg);
82 
84 
85  virtual std::unique_ptr<widget> build() const override;
86 
87 private:
88  std::string history_;
89 };
90 
91 } // namespace implementation
92 
93 // }------------ END --------------
94 
95 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
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.
void paste_selection() override
Pastes the current selection.
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 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
A widget that allows the user to input text in single line.
Definition: text_box.hpp:125
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