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.cpp | |
parent | 050c957927ccd7da1da135ce4fc51c3e53101ba6 (diff) | |
download | manaplus-833e498f54c1d33be94c09214315b368cccaec06.tar.gz manaplus-833e498f54c1d33be94c09214315b368cccaec06.tar.bz2 manaplus-833e498f54c1d33be94c09214315b368cccaec06.tar.xz manaplus-833e498f54c1d33be94c09214315b368cccaec06.zip |
Merger textfield and merge textbox.
Diffstat (limited to 'src/gui/widgets/textfield.cpp')
-rw-r--r-- | src/gui/widgets/textfield.cpp | 77 |
1 files changed, 72 insertions, 5 deletions
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 1906c5c32..98e852b00 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -20,6 +20,49 @@ * 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. + */ + #include "gui/widgets/textfield.h" #include "client.h" @@ -54,9 +97,13 @@ TextField::TextField(const Widget2 *restrict const widget, ActionListener *restrict const listener, const std::string &restrict eventId, const bool sendAlwaysEvents): - gcn::TextField(widget, text), + Widget(widget), FocusListener(), - mSendAlwaysEvents(sendAlwaysEvents), + KeyListener(), + MouseListener(), + mText(text), + mCaretPosition(0), + mXScroll(0), mCaretColor(&getThemeColor(Theme::CARET)), mPopupMenu(nullptr), mMinimum(0), @@ -65,8 +112,13 @@ TextField::TextField(const Widget2 *restrict const widget, mPadding(1), mNumeric(false), mLoseFocusOnTab(loseFocusOnTab), - mAllowSpecialActions(true) + mAllowSpecialActions(true), + mSendAlwaysEvents(sendAlwaysEvents) { + setFocusable(true); + addMouseListener(this); + addKeyListener(this); + setFrameSize(2); mForegroundColor = getThemeColor(Theme::TEXTFIELD); mForegroundColor2 = getThemeColor(Theme::TEXTFIELD_OUTLINE); @@ -672,9 +724,11 @@ void TextField::mousePressed(MouseEvent &mouseEvent) } } } - else + else if (mouseEvent.getButton() == MouseEvent::LEFT) { - gcn::TextField::mousePressed(mouseEvent); + mCaretPosition = getFont()->getStringIndexAt( + mText, mouseEvent.getX() + mXScroll); + fixScroll(); } } @@ -689,3 +743,16 @@ void TextField::focusGained(const Event &event A_UNUSED) void TextField::focusLost(const Event &event A_UNUSED) { } + +void TextField::setText(const std::string& text) +{ + const size_t sz = text.size(); + if (sz < mCaretPosition) + mCaretPosition = sz; + mText = text; +} + +void TextField::mouseDragged(MouseEvent& mouseEvent) +{ + mouseEvent.consume(); +} |