diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/misc_gui.cpp | 16 | ||||
-rw-r--r-- | src/network/network_chat_gui.cpp | 6 | ||||
-rw-r--r-- | src/network/network_gui.cpp | 10 | ||||
-rw-r--r-- | src/querystring_gui.h | 12 | ||||
-rw-r--r-- | src/signs_gui.cpp | 6 |
5 files changed, 32 insertions, 18 deletions
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 76061461f..144602913 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -960,14 +960,14 @@ bool HandleCaret(Textbuf *tb) return false; } -int QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, Window::EventState &state) +HandleEditBoxResult QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, Window::EventState &state) { state = Window::ES_HANDLED; switch (keycode) { - case WKC_ESC: return 2; + case WKC_ESC: return HEBR_CANCEL; - case WKC_RETURN: case WKC_NUM_ENTER: return 1; + case WKC_RETURN: case WKC_NUM_ENTER: return HEBR_CONFIRM; case (WKC_CTRL | 'V'): if (InsertTextBufferClipboard(&this->text)) w->InvalidateWidget(wid); @@ -994,7 +994,7 @@ int QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode } } - return 0; + return HEBR_EDITING; } void QueryString::HandleEditBox(Window *w, int wid) @@ -1124,13 +1124,13 @@ struct QueryStringWindow : public QueryStringBaseWindow EventState state; switch (this->HandleEditBoxKey(QUERY_STR_WIDGET_TEXT, key, keycode, state)) { default: NOT_REACHED(); - case 0: { + case HEBR_EDITING: { Window *osk = FindWindowById(WC_OSK, 0); if (osk != NULL && osk->parent == this) osk->OnInvalidateData(); } break; - case 1: this->OnOk(); // Enter pressed, confirms change + case HEBR_CONFIRM: this->OnOk(); /* FALL THROUGH */ - case 2: delete this; break; // ESC pressed, closes window, abandons changes + case HEBR_CANCEL: delete this; break; // close window, abandon changes } return state; } @@ -1624,7 +1624,7 @@ struct SaveLoadWindow : public QueryStringBaseWindow { EventState state = ES_NOT_HANDLED; if ((_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) && - this->HandleEditBoxKey(10, key, keycode, state) == 1) { // Press Enter + this->HandleEditBoxKey(10, key, keycode, state) == HEBR_CONFIRM) { this->HandleButtonClick(12); } diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp index 12cda3a43..22b2df5fe 100644 --- a/src/network/network_chat_gui.cpp +++ b/src/network/network_chat_gui.cpp @@ -468,14 +468,14 @@ struct NetworkChatWindow : public QueryStringBaseWindow { _chat_tab_completion_active = false; switch (this->HandleEditBoxKey(2, key, keycode, state)) { default: NOT_REACHED(); - case 0: { + case HEBR_EDITING: { Window *osk = FindWindowById(WC_OSK, 0); if (osk != NULL && osk->parent == this) osk->OnInvalidateData(); } break; - case 1: /* Return */ + case HEBR_CONFIRM: SendChat(this->text.buf, this->dtype, this->dest); /* FALLTHROUGH */ - case 2: /* Escape */ delete this; break; + case HEBR_CANCEL: delete this; break; } } return state; diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 9d9fadbbc..0aa429400 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -668,7 +668,7 @@ public: return state; } - if (this->HandleEditBoxKey(NGWW_CLIENT, key, keycode, state) == 1) return state; // enter pressed + if (this->HandleEditBoxKey(NGWW_CLIENT, key, keycode, state) == HEBR_CONFIRM) return state; /* The name is only allowed when it starts with a letter! */ if (!StrEmpty(this->edit_str_buf) && this->edit_str_buf[0] != ' ') { @@ -1047,7 +1047,7 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow { { EventState state = ES_NOT_HANDLED; if (this->field == NSSW_GAMENAME) { - if (this->HandleEditBoxKey(NSSW_GAMENAME, key, keycode, state) == 1) return state; // enter pressed + if (this->HandleEditBoxKey(NSSW_GAMENAME, key, keycode, state) == HEBR_CONFIRM) return state; ttd_strlcpy(_settings_client.network.server_name, this->text.buf, sizeof(_settings_client.network.server_name)); } @@ -1906,11 +1906,13 @@ struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow { { EventState state; switch (this->HandleEditBoxKey(4, key, keycode, state)) { - case 1: // Return + default: break; + + case HEBR_CONFIRM: this->OnOk(); /* FALL THROUGH */ - case 2: // Escape + case HEBR_CANCEL: delete this; break; } diff --git a/src/querystring_gui.h b/src/querystring_gui.h index 9c033200f..8946abd25 100644 --- a/src/querystring_gui.h +++ b/src/querystring_gui.h @@ -9,6 +9,16 @@ #include "window_gui.h" /** + * Return values for HandleEditBoxKey + */ +enum HandleEditBoxResult +{ + HEBR_EDITING = 0, // Other key pressed. + HEBR_CONFIRM, // Return or enter key pressed. + HEBR_CANCEL, // Escape key pressed. +}; + +/** * Data stored about a string that can be modified in the GUI */ struct QueryString { @@ -35,7 +45,7 @@ struct QueryString { void DrawEditBox(Window *w, int wid); void HandleEditBox(Window *w, int wid); - int HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, Window::EventState &state); + HandleEditBoxResult HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, Window::EventState &state); }; struct QueryStringBaseWindow : public Window, public QueryString { diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp index 925092e00..e57c4bfaf 100644 --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -309,11 +309,13 @@ struct SignWindow : QueryStringBaseWindow, SignList { { EventState state = ES_NOT_HANDLED; switch (this->HandleEditBoxKey(QUERY_EDIT_SIGN_WIDGET_TEXT, key, keycode, state)) { - case 1: // Enter pressed, confirms change + default: break; + + case HEBR_CONFIRM: if (RenameSign(this->cur_sign, this->text.buf)) break; /* FALL THROUGH */ - case 2: // ESC pressed, closes window, abandons changes + case HEBR_CANCEL: // close window, abandon changes delete this; break; } |