From 8834a0ffc0be61218ab86bf209cb6cd53a18a565 Mon Sep 17 00:00:00 2001 From: that Date: Tue, 5 Jan 2016 23:29:30 +0100 Subject: gui: add keyboard support for Ctrl layer and more special keys - rename NotifyKeyboard to NotifyCharInput - input: handle arrow keys in NotifyKey with standard KEY_* codes - fix page handler to return 0 from NotifyKey if key was handled - fix GUIAction::NotifyKey to not swallow all keys - change home button code from KEY_HOME to KEY_HOMEPAGE (to avoid collision with Home/End, conforms to Android 3.0+) Change-Id: Ib138afa492df8d0c1975415e8b5334c8778ccc90 --- gui/input.cpp | 106 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 62 insertions(+), 44 deletions(-) (limited to 'gui/input.cpp') diff --git a/gui/input.cpp b/gui/input.cpp index ca27ea812..68bd163b9 100644 --- a/gui/input.cpp +++ b/gui/input.cpp @@ -469,7 +469,7 @@ int GUIInput::NotifyTouch(TOUCH_STATE state, int x, int y) if (GetSelection(x, y) >= 0) { // When changing focus, we don't scroll or change the cursor location PageManager::SetKeyBoardFocus(0); - PageManager::NotifyKeyboard(0); + PageManager::NotifyCharInput(0); SetInputFocus(1); DrawCursor = true; mRendered = false; @@ -561,7 +561,66 @@ int GUIInput::NotifyVarChange(const std::string& varName, const std::string& val return 0; } -int GUIInput::NotifyKeyboard(int key) +int GUIInput::NotifyKey(int key, bool down) +{ + if (!HasInputFocus || !down) + return 1; + + string variableValue; + switch (key) + { + case KEY_LEFT: + if (mCursorLocation == 0 && skipChars == 0) + return 0; // we're already at the beginning + if (mCursorLocation == -1) { + DataManager::GetValue(mVariable, variableValue); + if (variableValue.size() == 0) + return 0; + mCursorLocation = variableValue.size() - skipChars - 1; + } else if (mCursorLocation == 0) { + skipChars--; + HandleTextLocation(-1002); + } else { + mCursorLocation--; + HandleTextLocation(-1002); + } + mRendered = false; + return 0; + + case KEY_RIGHT: + if (mCursorLocation == -1) + return 0; // we're already at the end + mCursorLocation++; + DataManager::GetValue(mVariable, variableValue); + if (variableValue.size() <= mCursorLocation + skipChars) + mCursorLocation = -1; + HandleTextLocation(-1001); + mRendered = false; + return 0; + + case KEY_HOME: + case KEY_UP: + DataManager::GetValue(mVariable, variableValue); + if (variableValue.size() == 0) + return 0; + mCursorLocation = 0; + skipChars = 0; + mRendered = false; + HandleTextLocation(-1002); + return 0; + + case KEY_END: + case KEY_DOWN: + mCursorLocation = -1; + mRendered = false; + HandleTextLocation(-1003); + return 0; + } + + return 1; +} + +int GUIInput::NotifyCharInput(int key) { string variableValue; @@ -617,48 +676,7 @@ int GUIInput::NotifyKeyboard(int key) isLocalChange = false; mRendered = false; return 0; - } else if (key == KEYBOARD_ARROW_LEFT) { - if (mCursorLocation == 0 && skipChars == 0) - return 0; // we're already at the beginning - if (mCursorLocation == -1) { - DataManager::GetValue(mVariable, variableValue); - if (variableValue.size() == 0) - return 0; - mCursorLocation = variableValue.size() - skipChars - 1; - } else if (mCursorLocation == 0) { - skipChars--; - HandleTextLocation(-1002); - } else { - mCursorLocation--; - HandleTextLocation(-1002); - } - mRendered = false; - return 0; - } else if (key == KEYBOARD_ARROW_RIGHT) { - if (mCursorLocation == -1) - return 0; // we're already at the end - mCursorLocation++; - DataManager::GetValue(mVariable, variableValue); - if (variableValue.size() <= mCursorLocation + skipChars) - mCursorLocation = -1; - HandleTextLocation(-1001); - mRendered = false; - return 0; - } else if (key == KEYBOARD_HOME || key == KEYBOARD_ARROW_UP) { - DataManager::GetValue(mVariable, variableValue); - if (variableValue.size() == 0) - return 0; - mCursorLocation = 0; - skipChars = 0; - mRendered = false; - HandleTextLocation(-1002); - return 0; - } else if (key == KEYBOARD_END || key == KEYBOARD_ARROW_DOWN) { - mCursorLocation = -1; - mRendered = false; - HandleTextLocation(-1003); - return 0; - } else if (key < KEYBOARD_SPECIAL_KEYS && key > 0) { + } else if (key >= 32) { // Regular key if (HasAllowed && AllowedList.find((char)key) == string::npos) { return 0; -- cgit v1.2.3