Index: src/misc_gui.cpp =================================================================== --- src/misc_gui.cpp (revision 18684) +++ src/misc_gui.cpp (working copy) @@ -1284,7 +1284,12 @@ HandleEditBoxResult QueryStringBaseWindow::HandleEditBoxKey(int wid, uint16 key, uint16 keycode, EventState &state) { - return this->QueryString::HandleEditBoxKey(this, wid, key, keycode, state); + HandleEditBoxResult result = this->QueryString::HandleEditBoxKey(this, wid, key, keycode, state); + + if (result == HEBR_CANCEL) + this->UnfocusFocusedWidget(); + + return result; } void QueryStringBaseWindow::HandleEditBox(int wid) Index: src/window.cpp =================================================================== --- src/window.cpp (revision 18684) +++ src/window.cpp (working copy) @@ -166,6 +166,35 @@ } /** + * Focus the next widget that accepts keyboard input. + */ +void Window::FocusNextEditWidget() +{ + uint start_find_at = 0; + uint num_loops = this->nested_array_size; + + if (this->nested_focus != NULL) { + start_find_at = this->nested_focus->index + 1 % this->nested_array_size; + num_loops = this->nested_array_size - 1; + } + + uint widget_index = start_find_at; + for (uint i = 0; i < num_loops; i++) { + const NWidgetBase *widget = this->GetWidget(widget_index); + + /* Focus next edit box */ + if (widget != NULL && widget->type == WWT_EDITBOX) { + this->SetFocusedWidget(widget_index); + break; + } + + /* Next widget index */ + if (++widget_index == this->nested_array_size) + widget_index = 0; + } +} + +/** * Sets the enabled/disabled status of a list of widgets. * By default, widgets are enabled. * On certain conditions, they have to be disabled. @@ -1915,6 +1944,12 @@ if (_focused_window->OnKeyPress(key, keycode) == Window::ES_HANDLED) return; } + /* Focus next edit widget in the focused widget on ctrl + tab */ + if (keycode == (WKC_CTRL | WKC_TAB) && _focused_window != NULL) { + _focused_window->FocusNextEditWidget(); + return; + } + /* Call the event, start with the uppermost window, but ignore the toolbar. */ Window *w; FOR_ALL_WINDOWS_FROM_FRONT(w) { Index: src/window_gui.h =================================================================== --- src/window_gui.h (revision 18684) +++ src/window_gui.h (working copy) @@ -521,6 +521,7 @@ void UnfocusFocusedWidget(); bool SetFocusedWidget(byte widget_index); + void FocusNextEditWidget(); void HandleButtonClick(byte widget);