summaryrefslogtreecommitdiff
path: root/src/gui/widgets/textfield.h
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-03-15 20:16:16 +0300
committerAndrei Karas <akaras@inbox.ru>2014-03-15 20:16:16 +0300
commit5c83a96b8ad85ad0562542b9720a0df6c5fb550c (patch)
tree1759cd93802d506583c7030119f1115b0444e226 /src/gui/widgets/textfield.h
parenta260aeab234704ace8ba672b1d1ce57e18425e07 (diff)
parent22cb237571e06395ec241377721c02716f0ea8a7 (diff)
downloadmv-5c83a96b8ad85ad0562542b9720a0df6c5fb550c.tar.gz
mv-5c83a96b8ad85ad0562542b9720a0df6c5fb550c.tar.bz2
mv-5c83a96b8ad85ad0562542b9720a0df6c5fb550c.tar.xz
mv-5c83a96b8ad85ad0562542b9720a0df6c5fb550c.zip
Merge branch 'master' into stable
Diffstat (limited to 'src/gui/widgets/textfield.h')
-rw-r--r--src/gui/widgets/textfield.h116
1 files changed, 105 insertions, 11 deletions
diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h
index ccc1b16d6..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:
/**
@@ -139,26 +186,71 @@ class TextField : public gcn::TextField,
void caretDeleteWord();
+ void setAllowSpecialActions(const bool b)
+ { mAllowSpecialActions = b; }
+
+ 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);
-#ifndef USE_SDL2
- void handleSDLKeys(const int val, bool &consumed);
-#endif
-
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;
@@ -170,6 +262,8 @@ class TextField : public gcn::TextField,
int mPadding;
bool mNumeric;
bool mLoseFocusOnTab;
+ bool mAllowSpecialActions;
+ bool mSendAlwaysEvents;
};
#endif // GUI_WIDGETS_TEXTFIELD_H