diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -27,6 +27,7 @@ #include "settings_type.h" #include "gfx_func.h" #include "widgets/dropdown_func.h" +#include "string_func.h" #include "table/sprites.h" #include "table/strings.h" @@ -1136,7 +1137,7 @@ static void NewVehicleWndProc(Window *w, break; case WE_ON_EDIT_TEXT: { - if (e->we.edittext.str[0] != '\0') { + if (!StrEmpty(e->we.edittext.str)) { StringID str = STR_NULL; _cmd_text = e->we.edittext.str; switch (bv->vehicle_type) { diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -525,7 +525,7 @@ static void GenerateLandscapeWndProc(Win break; case WE_ON_EDIT_TEXT: - if (e->we.edittext.str != NULL) { + if (!StrEmpty(e->we.edittext.str)) { int32 value = atoi(e->we.edittext.str); switch (WP(w, generate_d).widget_id) { @@ -740,7 +740,7 @@ static void CreateScenarioWndProc(Window break; case WE_ON_EDIT_TEXT: - if (e->we.edittext.str != NULL) { + if (!StrEmpty(e->we.edittext.str)) { int32 value = atoi(e->we.edittext.str); switch (WP(w, generate_d).widget_id) { diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -25,6 +25,7 @@ #include "player_func.h" #include "settings_type.h" #include "tilehighlight_func.h" +#include "string_func.h" #include "table/strings.h" #include "table/sprites.h" @@ -592,7 +593,7 @@ static void IndustryViewWndProc(Window * break; case WE_ON_EDIT_TEXT: - if (e->we.edittext.str[0] != '\0') { + if (!StrEmpty(e->we.edittext.str)) { Industry* i = GetIndustry(w->window_number); int line = WP(w, indview_d).editbox_line; diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -1040,7 +1040,8 @@ static void QueryStringWndProc(Window *w Window *parent = w->parent; qs->handled = true; - e.event = WE_ON_EDIT_TEXT_CANCEL; + e.event = WE_ON_EDIT_TEXT; + e.we.edittext.str = NULL; parent->HandleWindowEvent(&e); } ClrBit(_no_scroll, SCROLL_EDIT); diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -579,8 +579,10 @@ static void NetworkGameWindowWndProc(Win break; case WE_ON_EDIT_TEXT: - NetworkAddServer(e->we.edittext.str); - NetworkRebuildHostList(); + if (!StrEmpty(e->we.edittext.str)) { + NetworkAddServer(e->we.edittext.str); + NetworkRebuildHostList(); + } break; case WE_RESIZE: { @@ -917,7 +919,7 @@ static void NetworkStartServerWindowWndP if (nd->widget_id == NSSW_SETPWD) { ttd_strlcpy(_network_server_password, e->we.edittext.str, lengthof(_network_server_password)); - _network_game_info.use_password = (_network_server_password[0] != '\0'); + _network_game_info.use_password = !StrEmpty(_network_server_password); } else { int32 value = atoi(e->we.edittext.str); w->InvalidateWidget(nd->widget_id); @@ -1673,15 +1675,14 @@ static void NetworkJoinStatusWindowWndPr } break; - /* If the server asks for a password, we need to fill it in */ - case WE_ON_EDIT_TEXT_CANCEL: + case WE_ON_EDIT_TEXT: + if (StrEmpty(e->we.edittext.str)) { NetworkDisconnect(); ShowNetworkGameWindow(); - break; - - case WE_ON_EDIT_TEXT: + } else { SEND_COMMAND(PACKET_CLIENT_PASSWORD)(pw_type, e->we.edittext.str); - break; + } + break; } } diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -516,8 +516,9 @@ static void NewGRFWndProc(Window *w, Win /* parse_intlist returns -1 on error */ if (c->num_params == (byte)-1) c->num_params = 0; + + w->SetDirty(); } - w->SetDirty(); break; case WE_DESTROY: diff --git a/src/player_gui.cpp b/src/player_gui.cpp --- a/src/player_gui.cpp +++ b/src/player_gui.cpp @@ -979,6 +979,7 @@ static void SelectPlayerFaceWndProc(Wind break; case WE_ON_EDIT_TEXT: + if (e->we.edittext.str == NULL) break; /* Set a new player face number */ if (!StrEmpty(e->we.edittext.str)) { *pf = strtoul(e->we.edittext.str, NULL, 10); @@ -1331,7 +1332,7 @@ static void PlayerCompanyWndProc(Window break; case WE_ON_EDIT_TEXT: - if (StrEmpty(e->we.edittext.str)) return; + if (StrEmpty(e->we.edittext.str)) break; _cmd_text = e->we.edittext.str; switch (WP(w, def_d).byte_1) { diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1059,7 +1059,7 @@ static void PatchesSelectionWndProc(Wind break; case WE_ON_EDIT_TEXT: - if (e->we.edittext.str != NULL) { + if (!StrEmpty(e->we.edittext.str)) { const PatchEntry *pe = &_patches_page[WP(w, def_d).data_1].entries[WP(w, def_d).data_3]; const SettingDesc *sd = pe->setting; int32 value = atoi(e->we.edittext.str); @@ -1271,6 +1271,8 @@ static void CustCurrencyWndProc(Window * } break; case WE_ON_EDIT_TEXT: { + if (e->we.edittext.str == NULL) break; + const char *b = e->we.edittext.str; switch (WP(w, def_d).data_2) { @@ -1279,7 +1281,7 @@ static void CustCurrencyWndProc(Window * break; case CUSTCURR_SEPARATOR: /* Thousands seperator */ - _custom_currency.separator = (b[0] == '\0') ? ' ' : b[0]; + _custom_currency.separator = StrEmpty(b) ? ' ' : b[0]; ttd_strlcpy(_str_separator, b, lengthof(_str_separator)); break; diff --git a/src/station_gui.cpp b/src/station_gui.cpp --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -25,6 +25,7 @@ #include "gfx_func.h" #include "widgets/dropdown_func.h" #include "newgrf_cargo.h" +#include "string_func.h" #include "table/strings.h" #include "table/sprites.h" @@ -1002,7 +1003,7 @@ static void StationViewWndProc(Window *w break; case WE_ON_EDIT_TEXT: - if (e->we.edittext.str[0] != '\0') { + if (!StrEmpty(e->we.edittext.str)) { _cmd_text = e->we.edittext.str; DoCommandP(0, w->window_number, 0, NULL, CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION)); diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -249,6 +249,8 @@ static void TimetableWndProc(Window *w, } break; case WE_ON_EDIT_TEXT: { + if (we->we.edittext.str == NULL) break; + const Vehicle *v = GetVehicle(w->window_number); uint32 p1 = PackTimetableArgs(v, WP(w, timetable_d).sel); diff --git a/src/town_gui.cpp b/src/town_gui.cpp --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -23,6 +23,7 @@ #include "core/alloc_func.hpp" #include "settings_type.h" #include "tilehighlight_func.h" +#include "string_func.h" #include "table/sprites.h" #include "table/strings.h" @@ -360,7 +361,7 @@ static void TownViewWndProc(Window *w, W } break; case WE_ON_EDIT_TEXT: - if (e->we.edittext.str[0] != '\0') { + if (!StrEmpty(e->we.edittext.str)) { _cmd_text = e->we.edittext.str; DoCommandP(0, w->window_number, 0, NULL, CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN)); diff --git a/src/window_gui.h b/src/window_gui.h --- a/src/window_gui.h +++ b/src/window_gui.h @@ -125,7 +125,6 @@ enum WindowEventCodes { WE_PLACE_OBJ, WE_ABORT_PLACE_OBJ, WE_ON_EDIT_TEXT, - WE_ON_EDIT_TEXT_CANCEL, WE_DRAGDROP, WE_PLACE_DRAG, WE_PLACE_MOUSEUP,