summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-03-02 14:21:37 +0300
committerAndrei Karas <akaras@inbox.ru>2014-03-02 14:21:37 +0300
commit2f8fac791e34fe3831518490ae26c752b49ec1f6 (patch)
treefc3ba7526d8dfc7d2f796d895881142eae42b6fe /src/gui/widgets
parentfa4ce6cc00f1d3029ccfe7fd02cca29d4147bfb3 (diff)
downloadmanaplus-2f8fac791e34fe3831518490ae26c752b49ec1f6.tar.gz
manaplus-2f8fac791e34fe3831518490ae26c752b49ec1f6.tar.bz2
manaplus-2f8fac791e34fe3831518490ae26c752b49ec1f6.tar.xz
manaplus-2f8fac791e34fe3831518490ae26c752b49ec1f6.zip
Simplify actions handling in textfield.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/textfield.cpp133
-rw-r--r--src/gui/widgets/textfield.h4
2 files changed, 25 insertions, 112 deletions
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index 78a2826d5..aef977d80 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -271,40 +271,22 @@ void TextField::keyPressed(KeyEvent &keyEvent)
mLastEventPaste = 0;
bool consumed(false);
- handleSDLKeys(val, consumed);
-
- if (consumed)
- {
- if (mSendAlwaysEvents)
- distributeActionEvent();
-
- keyEvent.consume();
- fixScroll();
- return;
- }
#endif
- if (consumed)
+ const int action = keyEvent.getActionId();
+ if (!inputManager.isActionActive(static_cast<int>(
+ Input::KEY_GUI_CTRL)))
{
- keyEvent.consume();
+ if (!handleNormalKeys(action, consumed))
+ {
+ if (consumed)
+ keyEvent.consume();
+ return;
+ }
}
else
{
- const int action = keyEvent.getActionId();
- if (!inputManager.isActionActive(static_cast<int>(
- Input::KEY_GUI_CTRL)))
- {
- if (!handleNormalKeys(action, consumed))
- {
- if (consumed)
- keyEvent.consume();
- return;
- }
- }
- else
- {
- handleCtrlKeys(action, consumed);
- }
+ handleCtrlKeys(action, consumed);
}
if (mSendAlwaysEvents)
@@ -413,16 +395,15 @@ void TextField::handleCtrlKeys(const int action, bool &consumed)
consumed = true;
break;
}
-#ifdef USE_SDL2
case Input::KEY_GUI_B:
{
moveCaretBack();
consumed = true;
break;
}
- case Input::KEY_GUI_C:
+ case Input::KEY_GUI_F:
{
- handleCopy();
+ moveCaretForward();
consumed = true;
break;
}
@@ -438,118 +419,54 @@ void TextField::handleCtrlKeys(const int action, bool &consumed)
consumed = true;
break;
}
- case Input::KEY_GUI_F:
- {
- moveCaretBack();
- consumed = true;
- break;
- }
case Input::KEY_GUI_H:
{
deleteCharLeft(mText, &mCaretPosition);
consumed = true;
break;
}
- case Input::KEY_GUI_U:
- {
- caretDeleteToStart();
- consumed = true;
- break;
- }
case Input::KEY_GUI_K:
{
mText = mText.substr(0, mCaretPosition);
consumed = true;
break;
}
- case Input::KEY_GUI_V:
- {
- handlePaste();
- consumed = true;
- break;
- }
- case Input::KEY_GUI_W:
- {
- caretDeleteWord();
- consumed = true;
- break;
- }
-#endif
- default:
- break;
- }
-}
-
-#ifndef USE_SDL2
-void TextField::handleSDLKeys(const int val, bool &consumed)
-{
- switch (val)
- {
- case 2: // Ctrl+b
+ case Input::KEY_GUI_U:
{
- moveCaretBack();
+ caretDeleteToStart();
consumed = true;
break;
}
-
- case 6: // Ctrl+f
+ case Input::KEY_GUI_C:
{
- moveCaretForward();
+ handleCopy();
consumed = true;
break;
}
-
- case 4: // Ctrl+d
+ case Input::KEY_GUI_V:
{
- caretDelete();
- consumed = true;
- break;
- }
-
- case 8: // Ctrl+h
- deleteCharLeft(mText, &mCaretPosition);
- consumed = true;
- break;
-
- case 5: // Ctrl+e
- mCaretPosition = static_cast<int>(mText.size());
- consumed = true;
- break;
-
- case 11: // Ctrl+k
- mText = mText.substr(0, mCaretPosition);
- consumed = true;
- break;
-
- case 21: // Ctrl+u
- caretDeleteToStart();
- consumed = true;
- break;
-
- case 3: // Ctrl+c
- handleCopy();
- consumed = true;
- break;
-
- case 22: // Control code 22, SYNCHRONOUS IDLE, sent on Ctrl+v
+#ifdef USE_SDL2
+ handlePaste();
+#else
// hack to prevent paste key sticking
if (mLastEventPaste && mLastEventPaste > cur_time)
break;
handlePaste();
mLastEventPaste = cur_time + 2;
+#endif
consumed = true;
break;
-
- case 23: // Ctrl+w
+ }
+ case Input::KEY_GUI_W:
+ {
caretDeleteWord();
consumed = true;
break;
-
+ }
default:
break;
}
}
-#endif
void TextField::moveCaretBack()
{
diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h
index ccc1b16d6..c459d34f7 100644
--- a/src/gui/widgets/textfield.h
+++ b/src/gui/widgets/textfield.h
@@ -152,10 +152,6 @@ class TextField : public gcn::TextField,
void handleCtrlKeys(const int action, bool &consumed);
-#ifndef USE_SDL2
- void handleSDLKeys(const int val, bool &consumed);
-#endif
-
static Skin *mSkin;
private: