1 /***************************************************************************
2  *   Copyright (c) 2017-2019 by the fifechan team                               *
3  *   https://github.com/fifengine/fifechan                                 *
4  *   This file is part of fifechan.                                        *
5  *                                                                         *
6  *   fifechan is free software; you can redistribute it and/or             *
7  *   modify it under the terms of the GNU Lesser General Public            *
8  *   License as published by the Free Software Foundation; either          *
9  *   version 2.1 of the License, or (at your option) any later version.    *
10  *                                                                         *
11  *   This library is distributed in the hope that it will be useful,       *
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
14  *   Lesser General Public License for more details.                       *
15  *                                                                         *
16  *   You should have received a copy of the GNU Lesser General Public      *
17  *   License along with this library; if not, write to the                 *
18  *   Free Software Foundation, Inc.,                                       *
19  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
20  ***************************************************************************/
21 
22 #ifndef FCN_PASSWORDFIELD_HPP
23 #define FCN_PASSWORDFIELD_HPP
24 
25 #include <fifechan/widgets/textfield.hpp>
26 
27 namespace fcn
28 {
29     class Text;
30 
31     /**
32      * Password input widget.
33      */
34     class FCN_CORE_DECLSPEC PasswordField : public TextField
35     {
36     public:
37 
38         /**
39          * Constructor.
40          *
41          * @param text Initializes password field's text.
42          */
43         PasswordField(const std::string& text = "");
44 
45         ~PasswordField();
46 
47         // Inherited from TextField
48 
49         virtual void keyPressed(KeyEvent& keyEvent);
50 
51         virtual void setText(const std::string& text);
52 
53         virtual std::string getText() const;
54 
55     private:
56 
57         /**
58          * @return Caret position of the actual text.
59          */
60         unsigned int getActualTextCaretPosition() const;
61 
62         /**
63          * Sets the caret position of the actual text.
64          */
65         void setActualTextCaretPosition(unsigned int position);
66 
67         /**
68          * Holds the actual text of the password field. The standard text
69          * will hold asterisks instead.
70          */
71         Text* mActualText;
72     };
73 };
74 
75 #endif //FCN_PASSWORDFIELD_HPP
76