Index: src/ai/ai_gui.cpp =================================================================== --- src/ai/ai_gui.cpp (revision 20006) +++ src/ai/ai_gui.cpp (working copy) @@ -982,7 +982,7 @@ virtual EventState OnKeyPress(uint16 key, uint16 keycode) { - EventState state; + EventState state = ES_NOT_HANDLED; if (this->HandleEditBoxKey(AID_WIDGET_BREAK_STR_EDIT_BOX, key, keycode, state) != HEBR_NOT_FOCUSED) { /* Save the current string to static member so it can be restored next time the window is opened */ strecpy(this->break_string, this->edit_str_buf, lastof(this->break_string)); Index: src/genworld_gui.cpp =================================================================== --- src/genworld_gui.cpp (revision 20006) +++ src/genworld_gui.cpp (working copy) @@ -688,7 +688,7 @@ virtual EventState OnKeyPress(uint16 key, uint16 keycode) { - EventState state; + EventState state = ES_NOT_HANDLED; this->HandleEditBoxKey(GLAND_RANDOM_EDITBOX, key, keycode, state); /* the seed is unsigned, therefore atoi cannot be used. * As UINT32_MAX is a 'magic' value (use random seed) it Index: src/misc_gui.cpp =================================================================== --- src/misc_gui.cpp (revision 20006) +++ src/misc_gui.cpp (working copy) @@ -1147,8 +1147,22 @@ return w->parent->nested_focus != NULL && w->parent->nested_focus->type == WWT_EDITBOX; } +/* + * Handles key press for text edit widget. Call this function from OnKeyPress + * so that the key input for the edit box gets processed. The function will + * check that the edit widget is focused, so it can safely be called without + * checking for that. + * @param w The window. + * @param wid The text edit widget to handle. + * @param key The key argument from OnKeyPress + * @param keycode The keycode argument from OnKeyPress + * @param state Will be set to ES_NOT_HANDELED or ES_HANDELED depending on if the key input has been handled or not. The state parameter may be uninitialized as it will only be written to, not read. + * @return a HandleEditBoxResult enum value that tells how the key was handled by the edit box. + */ HandleEditBoxResult QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, EventState &state) { + state = ES_NOT_HANDLED; + if (!QueryString::HasEditBoxFocus(w, wid)) return HEBR_NOT_FOCUSED; state = ES_HANDLED; Index: src/town_gui.cpp =================================================================== --- src/town_gui.cpp (revision 20006) +++ src/town_gui.cpp (working copy) @@ -1188,7 +1188,7 @@ virtual EventState OnKeyPress(uint16 key, uint16 keycode) { - EventState state; + EventState state = ES_NOT_HANDLED; if (this->HandleEditBoxKey(TSEW_TOWNNAME_EDITBOX, key, keycode, state) == HEBR_CANCEL) { this->UnfocusFocusedWidget(); }