aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2011-05-17 12:12:02 +0200
committerMax Horn2011-05-17 12:23:55 +0200
commit29851abaea1a693f170f726aaa73d50af24b4761 (patch)
tree8ea00df6a06f5c4559259aa35fc6d2e790404bf6
parenta3fe84cfe67a3eb4ae4750923f712bc9216a2f3f (diff)
downloadscummvm-rg350-29851abaea1a693f170f726aaa73d50af24b4761.tar.gz
scummvm-rg350-29851abaea1a693f170f726aaa73d50af24b4761.tar.bz2
scummvm-rg350-29851abaea1a693f170f726aaa73d50af24b4761.zip
GUI: Text editing tweaks
- Streamline keypad handling - Allow up/down to act like home/end - On Mac OS X, allow ctrl-a and ctrl-e to act like home/end
-rw-r--r--gui/widgets/editable.cpp89
1 files changed, 48 insertions, 41 deletions
diff --git a/gui/widgets/editable.cpp b/gui/widgets/editable.cpp
index 35e85ca414..de331d9cc2 100644
--- a/gui/widgets/editable.cpp
+++ b/gui/widgets/editable.cpp
@@ -93,6 +93,28 @@ bool EditableWidget::handleKeyDown(Common::KeyState state) {
if (_caretVisible)
drawCaret(true);
+ // Remap numeric keypad if NUM lock is *not* active.
+ // This code relies on the fact that the various KEYCODE_KP* values are
+ // consecutive.
+ if (0 == (state.flags & Common::KBD_NUM)
+ && Common::KEYCODE_KP0 <= state.keycode
+ && state.keycode <= Common::KEYCODE_KP_PERIOD) {
+ const Common::KeyCode remap[11] = {
+ Common::KEYCODE_INSERT, // KEYCODE_KP0
+ Common::KEYCODE_END, // KEYCODE_KP1
+ Common::KEYCODE_DOWN, // KEYCODE_KP2
+ Common::KEYCODE_PAGEDOWN, // KEYCODE_KP3
+ Common::KEYCODE_LEFT, // KEYCODE_KP4
+ Common::KEYCODE_INVALID, // KEYCODE_KP5
+ Common::KEYCODE_RIGHT, // KEYCODE_KP6
+ Common::KEYCODE_HOME, // KEYCODE_KP7
+ Common::KEYCODE_UP, // KEYCODE_KP8
+ Common::KEYCODE_PAGEUP, // KEYCODE_KP9
+ Common::KEYCODE_DELETE, // KEYCODE_KP_PERIOD
+ };
+ state.keycode = remap[state.keycode - Common::KEYCODE_KP0];
+ }
+
switch (state.keycode) {
case Common::KEYCODE_RETURN:
case Common::KEYCODE_KP_ENTER:
@@ -117,27 +139,6 @@ bool EditableWidget::handleKeyDown(Common::KeyState state) {
forcecaret = true;
break;
- // Keypad & special keys
- // - if num lock is set, we always go to the default case
- // - if num lock is not set, we either fall down to the special key case
- // or ignore the key press in case of 0 (INSERT), 2 (DOWN), 3 (PGDWN)
- // 5, 8 (UP) and 9 (PGUP)
-
- case Common::KEYCODE_KP0:
- case Common::KEYCODE_KP2:
- case Common::KEYCODE_KP3:
- case Common::KEYCODE_KP5:
- case Common::KEYCODE_KP8:
- case Common::KEYCODE_KP9:
- if (state.flags & Common::KBD_NUM)
- defaultKeyDownHandler(state, dirty, forcecaret, handled);
- break;
-
- case Common::KEYCODE_KP_PERIOD:
- if (state.flags & Common::KBD_NUM) {
- defaultKeyDownHandler(state, dirty, forcecaret, handled);
- break;
- }
case Common::KEYCODE_DELETE:
if (_caretPos < (int)_editString.size()) {
_editString.deleteChar(_caretPos);
@@ -148,22 +149,15 @@ bool EditableWidget::handleKeyDown(Common::KeyState state) {
forcecaret = true;
break;
- case Common::KEYCODE_KP1:
- if (state.flags & Common::KBD_NUM) {
- defaultKeyDownHandler(state, dirty, forcecaret, handled);
- break;
- }
+ case Common::KEYCODE_DOWN:
case Common::KEYCODE_END:
+ // Move caret to end
dirty = setCaretPos(_editString.size());
forcecaret = true;
break;
- case Common::KEYCODE_KP4:
- if (state.flags & Common::KBD_NUM) {
- defaultKeyDownHandler(state, dirty, forcecaret, handled);
- break;
- }
case Common::KEYCODE_LEFT:
+ // Move caret one left (if possible)
if (_caretPos > 0) {
dirty = setCaretPos(_caretPos - 1);
}
@@ -171,12 +165,8 @@ bool EditableWidget::handleKeyDown(Common::KeyState state) {
dirty = true;
break;
- case Common::KEYCODE_KP6:
- if (state.flags & Common::KBD_NUM) {
- defaultKeyDownHandler(state, dirty, forcecaret, handled);
- break;
- }
case Common::KEYCODE_RIGHT:
+ // Move caret one right (if possible)
if (_caretPos < (int)_editString.size()) {
dirty = setCaretPos(_caretPos + 1);
}
@@ -184,16 +174,33 @@ bool EditableWidget::handleKeyDown(Common::KeyState state) {
dirty = true;
break;
- case Common::KEYCODE_KP7:
- if (state.flags & Common::KBD_NUM) {
- defaultKeyDownHandler(state, dirty, forcecaret, handled);
- break;
- }
+ case Common::KEYCODE_UP:
case Common::KEYCODE_HOME:
+ // Move caret to start
dirty = setCaretPos(0);
forcecaret = true;
break;
+#ifdef MACOSX
+ // Mac OS X GUI style shortcuts: Ctrl-A goes to start of line, Ctrl-e to end of line.
+ // TODO: Should we disable these on Windows? There, Ctrl-A usually means
+ // "select all".
+ case Common::KEYCODE_a:
+ case Common::KEYCODE_e:
+ if (state.flags & Common::KBD_CTRL) {
+ if (state.keycode == Common::KEYCODE_a) {
+ // Move caret to start
+ dirty = setCaretPos(0);
+ forcecaret = true;
+ } else if (state.keycode == Common::KEYCODE_e) {
+ // Move caret to end
+ dirty = setCaretPos(_editString.size());
+ forcecaret = true;
+ }
+ break;
+ }
+#endif
+
default:
defaultKeyDownHandler(state, dirty, forcecaret, handled);
}