From 120ef46ea296729baee0c88c046008d8e18644fa Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 11 May 2013 22:25:21 +0300 Subject: Add ability to show onscreen keyboard if input field focused. --- src/gui/widgets/popuplist.h | 2 +- src/gui/widgets/textfield.cpp | 20 ++++++++++++++++++++ src/gui/widgets/textfield.h | 6 ++++++ 3 files changed, 27 insertions(+), 1 deletion(-) (limited to 'src/gui/widgets') diff --git a/src/gui/widgets/popuplist.h b/src/gui/widgets/popuplist.h index 5e0f4f260..59e04df63 100644 --- a/src/gui/widgets/popuplist.h +++ b/src/gui/widgets/popuplist.h @@ -25,7 +25,7 @@ #include "gui/widgets/popup.h" #include -#include "guichan/focuslistener.hpp" +#include #include #include "localconsts.h" diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 73e01fb63..5d0621e1e 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -24,6 +24,7 @@ #include "client.h" #include "configuration.h" +#include "inputmanager.h" #include "keyevent.h" #include "gui/popupmenu.h" @@ -51,6 +52,7 @@ TextField::TextField(const Widget2 *const widget, gcn::ActionListener *const listener, std::string eventId, const bool sendAlwaysEvents): gcn::TextField(text), + gcn::FocusListener(), Widget2(widget), mSendAlwaysEvents(sendAlwaysEvents), mNumeric(false), @@ -66,6 +68,8 @@ TextField::TextField(const Widget2 *const widget, setFrameSize(2); mForegroundColor = getThemeColor(Theme::TEXTFIELD); + addFocusListener(this); + if (instances == 0) { if (Theme::instance()) @@ -529,6 +533,10 @@ void TextField::fontChanged() void TextField::mousePressed(gcn::MouseEvent &mouseEvent) { +#ifdef ANDROID + if (!Client::isKeyboardVisible()) + inputManager.executeAction(Input::KEY_SHOW_KEYBOARD); +#endif if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT) { if (viewport) @@ -550,3 +558,15 @@ void TextField::mousePressed(gcn::MouseEvent &mouseEvent) gcn::TextField::mousePressed(mouseEvent); } } + +void TextField::focusGained(const gcn::Event &event A_UNUSED) +{ +#ifdef ANDROID + if (!Client::isKeyboardVisible()) + inputManager.executeAction(Input::KEY_SHOW_KEYBOARD); +#endif +} + +void TextField::focusLost(const gcn::Event &event A_UNUSED) +{ +} diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h index 0c30fc819..0569d5d30 100644 --- a/src/gui/widgets/textfield.h +++ b/src/gui/widgets/textfield.h @@ -25,6 +25,7 @@ #include "gui/widgets/widget2.h" +#include #include #include "localconsts.h" @@ -39,6 +40,7 @@ class TextField; * \ingroup GUI */ class TextField : public gcn::TextField, + public gcn::FocusListener, public Widget2 { public: @@ -122,6 +124,10 @@ class TextField : public gcn::TextField, void handleCopy() const; + void focusGained(const gcn::Event &event); + + void focusLost(const gcn::Event &event); + protected: void drawCaret(gcn::Graphics* graphics, int x) override; -- cgit v1.2.3-70-g09d2