diff options
author | frosch <frosch@openttd.org> | 2012-11-28 21:14:28 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2012-11-28 21:14:28 +0000 |
commit | 5dfd5e58ee58cc8205c430075ec1325aa9fda0ca (patch) | |
tree | dcd42222d5d1492237a22e24f0f85cffb93a4a16 /src/misc_gui.cpp | |
parent | bfba90f8648cdb8b10ddd1322f46411761a9c29b (diff) | |
download | openttd-5dfd5e58ee58cc8205c430075ec1325aa9fda0ca.tar.xz |
(svn r24774) -Fix: Invert the focus handling of the OSK. Keep the focus at the OSK and close it on losing focus. This makes the editbox in the OSK behave correctly.
Diffstat (limited to 'src/misc_gui.cpp')
-rw-r--r-- | src/misc_gui.cpp | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index a94e49a3b..3a87437d7 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -706,16 +706,9 @@ void GuiShowTooltips(Window *parent, StringID str, uint paramcount, const uint64 new TooltipsWindow(parent, str, paramcount, params, close_tooltip); } -bool QueryString::HasEditBoxFocus(const Window *w, int wid) const -{ - if (w->IsWidgetGloballyFocused(wid)) return true; - if (w->window_class != WC_OSK || _focused_window != w->parent) return false; - return w->parent->nested_focus != NULL && w->parent->nested_focus->type == WWT_EDITBOX; -} - HandleEditBoxResult QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, EventState &state) { - if (!QueryString::HasEditBoxFocus(w, wid)) return HEBR_NOT_FOCUSED; + if (!w->IsWidgetGloballyFocused(wid)) return HEBR_NOT_FOCUSED; state = ES_HANDLED; @@ -757,24 +750,19 @@ HandleEditBoxResult QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key } else { state = ES_NOT_HANDLED; } + break; } - Window *osk = FindWindowById(WC_OSK, 0); - if (osk != NULL && osk->parent == w) osk->InvalidateData(); - return edited ? HEBR_EDITING : HEBR_CURSOR; } void QueryString::HandleEditBox(Window *w, int wid) { - if (HasEditBoxFocus(w, wid) && this->text.HandleCaret()) { + if (w->IsWidgetGloballyFocused(wid) && this->text.HandleCaret()) { w->SetWidgetDirty(wid); - /* When we're not the OSK, notify 'our' OSK to redraw the widget, - * so the caret changes appropriately. */ - if (w->window_class != WC_OSK) { - Window *w_osk = FindWindowById(WC_OSK, 0); - if (w_osk != NULL && w_osk->parent == w) w_osk->InvalidateData(); - } + + /* For the OSK also invalidate the parent window */ + if (w->window_class == WC_OSK) w->InvalidateData(); } } @@ -818,7 +806,8 @@ void QueryString::DrawEditBox(const Window *w, int wid) const if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs; DrawString(delta, tb->pixels, 0, tb->buf, TC_YELLOW); - if (HasEditBoxFocus(w, wid) && tb->caret) { + bool focussed = w->IsWidgetGloballyFocused(wid) || IsOSKOpenedFor(w, wid); + if (focussed && tb->caret) { int caret_width = GetStringBoundingBox("_").width; DrawString(tb->caretxoffs + delta, tb->caretxoffs + delta + caret_width, 0, "_", TC_WHITE); } |