summaryrefslogtreecommitdiff
path: root/src/window.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-11-13 21:47:13 +0000
committerfrosch <frosch@openttd.org>2012-11-13 21:47:13 +0000
commitfc2b12acca38964ed91d35e3d5c4aae20d992e7f (patch)
treeb2234ccb73cc28f3a8cc64600296c5b55954edf2 /src/window.cpp
parent2c22fe98ddae45d1553003a00a7ea0a301e9aa99 (diff)
downloadopenttd-fc2b12acca38964ed91d35e3d5c4aae20d992e7f.tar.xz
(svn r24735) -Codechange: Move HandleEditBoxKey to Window class.
Diffstat (limited to 'src/window.cpp')
-rw-r--r--src/window.cpp43
1 files changed, 41 insertions, 2 deletions
diff --git a/src/window.cpp b/src/window.cpp
index 23db475f4..8aa932859 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -2234,6 +2234,46 @@ static bool MaybeBringWindowToFront(Window *w)
}
/**
+ * Process keypress for editbox widget.
+ * @param wid Editbox widget.
+ * @param key the Unicode value of the key.
+ * @param keycode the untranslated key code including shift state.
+ * @return #ES_HANDLED if the key press has been handled and no other
+ * window should receive the event.
+ */
+EventState Window::HandleEditBoxKey(int wid, uint16 key, uint16 keycode)
+{
+ EventState state = ES_NOT_HANDLED;
+
+ QueryString *query = dynamic_cast<QueryString*>(this);
+ if (query == NULL) return state;
+
+ switch (query->HandleEditBoxKey(this, wid, key, keycode, state)) {
+ case HEBR_EDITING:
+ this->OnEditboxChanged(wid);
+ break;
+
+ case HEBR_CONFIRM:
+ if (query->ok_button >= 0) {
+ this->OnClick(Point(), query->ok_button, 1);
+ }
+ break;
+
+ case HEBR_CANCEL:
+ if (query->cancel_button >= 0) {
+ this->OnClick(Point(), query->cancel_button, 1);
+ } else {
+ this->UnfocusFocusedWidget();
+ }
+ break;
+
+ default: break;
+ }
+
+ return state;
+}
+
+/**
* Handle keyboard input.
* @param raw_key Lower 8 bits contain the ASCII character, the higher 16 bits the keycode
*/
@@ -2267,8 +2307,7 @@ void HandleKeypress(uint32 raw_key)
if (_focused_window->window_class == WC_CONSOLE) {
if (_focused_window->OnKeyPress(key, keycode) == ES_HANDLED) return;
} else {
- QueryStringBaseWindow *query = dynamic_cast<QueryStringBaseWindow*>(_focused_window);
- if (query != NULL && query->HandleEditBoxKey(_focused_window->nested_focus->index, key, keycode) == ES_HANDLED) return;
+ if (_focused_window->HandleEditBoxKey(_focused_window->nested_focus->index, key, keycode) == ES_HANDLED) return;
}
}