The Battle for Wesnoth
1.13.4+dev
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
gui
widgets
password_box.hpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2009 - 2016 by Thomas Baumhauer
3
<
[email protected]
>
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
:
57
tpassword_box
() :
ttext_box
(),
real_value_
()
58
{
59
}
60
61
/** Inherited from ttext_. */
62
virtual
void
set_value
(
const
std::string
&
text
);
63
std::string
get_real_value
()
const
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
85
std::string
real_value_
;
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?
98
struct
tbuilder_password_box
:
public
tbuilder_control
99
{
100
public
:
101
explicit
tbuilder_password_box
(
const
config
& cfg);
102
103
using
tbuilder_control::build
;
104
105
twidget
*
build
()
const
;
106
107
private
:
108
std::string
history_
;
109
};
110
111
}
// namespace implementation
112
113
// }------------ END --------------
114
115
}
// namespace gui2
116
117
#endif
gui2::tpassword_box::handle_key_delete
void handle_key_delete(SDLMod modifier, bool &handled)
Delete key pressed.
Definition:
password_box.cpp:87
SDLMod
#define SDLMod
Definition:
compat.hpp:30
gui2::tpassword_box::post_function
void post_function()
Definition:
password_box.cpp:126
gui2::ttext_box
Class for a single line text area.
Definition:
text_box.hpp:118
gui2::tpassword_box::pre_function
void pre_function()
Definition:
password_box.cpp:111
gui2::implementation::tbuilder_password_box::build
twidget * build() const
Definition:
password_box.cpp:177
gui2
A class inherited from ttext_box that displays its input as stars.
Definition:
field-fwd.hpp:23
gui2::tpassword_box
Definition:
password_box.hpp:35
gui2::tpassword_box::delete_char
void delete_char(const bool before_cursor)
Deletes the character.
Definition:
password_box.cpp:63
gui2::tbuilder_widget::build
virtual twidget * build() const =0
gui2::tpassword_box::tpassword_box
tpassword_box()
Definition:
password_box.hpp:57
gui2::tpassword_box::handle_key_backspace
void handle_key_backspace(SDLMod modifier, bool &handled)
Backspace key pressed.
Definition:
password_box.cpp:70
gui2::implementation::tbuilder_password_box
Definition:
password_box.hpp:98
gui2::tpassword_box::set_value
virtual void set_value(const std::string &text)
Inherited from ttext_.
Definition:
password_box.cpp:49
gui2::tpassword_box::get_real_value
std::string get_real_value() const
Definition:
password_box.hpp:63
gui2::tpassword_box::get_control_type
virtual const std::string & get_control_type() const override
See tcontrol::get_control_type.
Definition:
password_box.cpp:146
gui2::tpassword_box::insert_char
void insert_char(const utf8::string &unicode)
Inserts a character at the cursor.
Definition:
password_box.cpp:56
gui2::tpassword_box::real_value_
std::string real_value_
Definition:
password_box.hpp:85
gui2::twidget
Base class for all widgets.
Definition:
widget.hpp:49
gui2::implementation::tbuilder_password_box::tbuilder_password_box
tbuilder_password_box(const config &cfg)
Definition:
password_box.cpp:172
gui2::ttext_::text
const std::string & text() const
Definition:
text.hpp:81
config
A config object defines a single node in a WML file, with access to child nodes.
Definition:
config.hpp:83
gui2::tpassword_box::paste_selection
void paste_selection(const bool mouse)
Pastes the current selection.
Definition:
password_box.cpp:104
string
GLsizei const GLcharARB ** string
Definition:
glew.h:4503
gui2::implementation::tbuilder_password_box::history_
std::string history_
Definition:
password_box.hpp:108
implementation
Contains the implementation details for lexical_cast and shouldn't be used directly.
gui2::implementation::tbuilder_control
Definition:
control.hpp:517
text_box.hpp
utf8::string
std::string string
Definition:
unicode_types.hpp:30
Generated by
1.8.8