diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-03-05 12:25:56 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-03-05 12:25:56 +0300 |
commit | 833e498f54c1d33be94c09214315b368cccaec06 (patch) | |
tree | cead9d12e6a4ffbcbcd978b6c04df5bacdf55473 /src/gui/widgets/textfield.h | |
parent | 050c957927ccd7da1da135ce4fc51c3e53101ba6 (diff) | |
download | manaverse-833e498f54c1d33be94c09214315b368cccaec06.tar.gz manaverse-833e498f54c1d33be94c09214315b368cccaec06.tar.bz2 manaverse-833e498f54c1d33be94c09214315b368cccaec06.tar.xz manaverse-833e498f54c1d33be94c09214315b368cccaec06.zip |
Merger textfield and merge textbox.
Diffstat (limited to 'src/gui/widgets/textfield.h')
-rw-r--r-- | src/gui/widgets/textfield.h | 105 |
1 files changed, 98 insertions, 7 deletions
diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h index 4c1b4bffc..93ae155be 100644 --- a/src/gui/widgets/textfield.h +++ b/src/gui/widgets/textfield.h @@ -20,12 +20,57 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #ifndef GUI_WIDGETS_TEXTFIELD_H #define GUI_WIDGETS_TEXTFIELD_H #include "listeners/focuslistener.h" +#include "listeners/keylistener.h" +#include "listeners/mouselistener.h" -#include "gui/base/widgets/textfield.hpp" +#include "gui/widgets/widget.h" #include "localconsts.h" @@ -36,8 +81,10 @@ class PopupMenu; * * \ingroup GUI */ -class TextField : public gcn::TextField, - public FocusListener +class TextField : public Widget, + public FocusListener, + public KeyListener, + public MouseListener { public: /** @@ -145,22 +192,65 @@ class TextField : public gcn::TextField, std::string getTextBeforeCaret() const { return mText.substr(0, mCaretPosition); } + /** + * Sets the text of the text field. + * + * @param text The text of the text field. + * @see getText + */ + void setText(const std::string& text); + + /** + * Gets the text of the text field. + * + * @return The text of the text field. + * @see setText + */ + const std::string& getText() const + { return mText; } + + /** + * Gets the caret position. As there is only one line of text + * in a text field the position is the caret's x coordinate. + * + * @return The caret position. + * @see setCaretPosition + */ + unsigned int getCaretPosition() const + { return mCaretPosition; } + + void mouseDragged(MouseEvent& mouseEvent) override final; + protected: - void drawCaret(Graphics* graphics, int x) override final; + void drawCaret(Graphics* graphics, int x); void fixScroll(); void fontChanged(); - bool mSendAlwaysEvents; - bool handleNormalKeys(const int action, bool &consumed); void handleCtrlKeys(const int action, bool &consumed); static Skin *mSkin; - private: + /** + * Holds the text of the text box. + */ + std::string mText; + + /** + * Holds the caret position. + */ + unsigned int mCaretPosition; + + /** + * Holds the amount scrolled in x. If a user types more characters than + * the text field can display, due to the text field being to small, the + * text needs to scroll in order to show the last type character. + */ + int mXScroll; + const Color *mCaretColor; PopupMenu *mPopupMenu; static int instances; @@ -173,6 +263,7 @@ class TextField : public gcn::TextField, bool mNumeric; bool mLoseFocusOnTab; bool mAllowSpecialActions; + bool mSendAlwaysEvents; }; #endif // GUI_WIDGETS_TEXTFIELD_H |