gui/widgets/password_box.hpp

Go to the documentation of this file.
00001 /* $Id: password_box.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2009 - 2012 by Thomas Baumhauer <thomas.baumhauer@NOSPAMgmail.com>
00004    Copyright (C) 2009 - 2012 by Mark de Wever <koraq@xs4all.nl>
00005    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY.
00013 
00014    See the COPYING file for more details.
00015 */
00016 
00017 #ifndef GUI_WIDGETS_PASSWORD_BOX_HPP_INCLUDED
00018 #define GUI_WIDGETS_PASSWORD_BOX_HPP_INCLUDED
00019 
00020 #include "gui/widgets/text_box.hpp"
00021 
00022 
00023 /**
00024  * A class inherited from ttext_box that displays
00025  * its input as stars
00026  *
00027  * @todo This implementation is quite a hack that
00028  * needs to be rewritten cleanly
00029  */
00030 namespace gui2 {
00031 
00032 class tpassword_box : public ttext_box {
00033 
00034 // The hack works like this: we add the member real_value_
00035 // that holds the actual user input.
00036 // Overridden functions now simply
00037 //  - call set_value() from ttext_box with real_value_,
00038 //    which is done in prefunction()
00039 //  - call ttext_box::overridden_function()
00040 //  - set real_value_ to get_value() from ttext_box and
00041 //    call set_value() from ttext_box with real_value_
00042 //    turned into stars, which is done in post_function()
00043 //
00044 // and overridden function should therefore look like this:
00045 //
00046 // overridden_function(some parameter) {
00047 //  pre_function();
00048 //  ttext_box::overridden_function(some parameter);
00049 //  post_function();
00050 // }
00051 
00052 public:
00053     tpassword_box() : ttext_box(), real_value_() {}
00054 
00055     /** Inherited from ttext_. */
00056     virtual void set_value(const std::string& text);
00057     std::string get_real_value() const { return real_value_; }
00058 
00059 
00060 protected:
00061     // Overwritten functions must of course be virtual!
00062     void insert_char(const Uint16 unicode);
00063     void delete_char(const bool before_cursor);
00064 
00065     void paste_selection(const bool mouse);
00066 
00067     // We do not override copy_selection because we
00068     // actually want it to copy just the stars
00069 
00070 private:
00071     void handle_key_backspace(SDLMod modifier, bool& handled);
00072     void handle_key_delete(SDLMod modifier, bool& handled);
00073 
00074     void pre_function();
00075     void post_function();
00076 
00077     std::string real_value_;
00078 
00079     /** Inherited from ttext_box. */
00080     const std::string& get_control_type() const;
00081 };
00082 
00083 } //namespace gui2
00084 
00085 #endif
00086 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:57 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs