The Battle for Wesnoth  1.15.2+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 class password_box : public text_box
39 {
40 public:
41  explicit password_box(const implementation::builder_password_box& builder);
42 
43  /** Inherited from text_box_base. */
44  virtual void set_value(const std::string& text) override;
45  std::string get_real_value() const
46  {
47  return real_value_;
48  }
49 
50 
51 protected:
52  void insert_char(const std::string& unicode) override;
53  void paste_selection(const bool mouse) override;
54  void delete_selection() override;
55 
56  // We do not override copy_selection because we
57  // actually want it to copy just the stars
58 
59 private:
60 
61  std::string real_value_;
62 
63 public:
64  /** Static type getter that does not rely on the widget being constructed. */
65  static const std::string& type();
66 
67 private:
68  /** See @ref styled_widget::get_control_type. */
69  virtual const std::string& get_control_type() const override;
70 };
71 
72 // }---------- BUILDER -----------{
73 
74 namespace implementation
75 {
76 
77 // copy & paste from builder_text_box...
78 // does it make more sense to inherit from it?
80 {
81 public:
82  explicit builder_password_box(const config& cfg);
83 
85 
86  widget* build() const;
87 
88 private:
89  std::string history_;
90 };
91 
92 } // namespace implementation
93 
94 // }------------ END --------------
95 
96 } // namespace gui2
virtual widget * build() const =0
Base class for all widgets.
Definition: widget.hpp:47
Class for a single line text area.
Definition: text_box.hpp:121
Generic file dialog.
Definition: field-fwd.hpp:22
std::string get_real_value() const
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:68
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.
std::string real_value_