(svn r13027) -Codechange: use StrEmpty instead of arr[0] == '\0' and remove the need for WE_ON_EDIT_TEXT_CANCEL.

This commit is contained in:
rubidium 2008-05-10 08:58:52 +00:00
parent e099831210
commit f23026cce8
12 changed files with 32 additions and 21 deletions

View File

@ -27,6 +27,7 @@
#include "settings_type.h" #include "settings_type.h"
#include "gfx_func.h" #include "gfx_func.h"
#include "widgets/dropdown_func.h" #include "widgets/dropdown_func.h"
#include "string_func.h"
#include "table/sprites.h" #include "table/sprites.h"
#include "table/strings.h" #include "table/strings.h"
@ -1136,7 +1137,7 @@ static void NewVehicleWndProc(Window *w, WindowEvent *e)
break; break;
case WE_ON_EDIT_TEXT: { case WE_ON_EDIT_TEXT: {
if (e->we.edittext.str[0] != '\0') { if (!StrEmpty(e->we.edittext.str)) {
StringID str = STR_NULL; StringID str = STR_NULL;
_cmd_text = e->we.edittext.str; _cmd_text = e->we.edittext.str;
switch (bv->vehicle_type) { switch (bv->vehicle_type) {

View File

@ -525,7 +525,7 @@ static void GenerateLandscapeWndProc(Window *w, WindowEvent *e)
break; break;
case WE_ON_EDIT_TEXT: case WE_ON_EDIT_TEXT:
if (e->we.edittext.str != NULL) { if (!StrEmpty(e->we.edittext.str)) {
int32 value = atoi(e->we.edittext.str); int32 value = atoi(e->we.edittext.str);
switch (WP(w, generate_d).widget_id) { switch (WP(w, generate_d).widget_id) {
@ -740,7 +740,7 @@ static void CreateScenarioWndProc(Window *w, WindowEvent *e)
break; break;
case WE_ON_EDIT_TEXT: case WE_ON_EDIT_TEXT:
if (e->we.edittext.str != NULL) { if (!StrEmpty(e->we.edittext.str)) {
int32 value = atoi(e->we.edittext.str); int32 value = atoi(e->we.edittext.str);
switch (WP(w, generate_d).widget_id) { switch (WP(w, generate_d).widget_id) {

View File

@ -25,6 +25,7 @@
#include "player_func.h" #include "player_func.h"
#include "settings_type.h" #include "settings_type.h"
#include "tilehighlight_func.h" #include "tilehighlight_func.h"
#include "string_func.h"
#include "table/strings.h" #include "table/strings.h"
#include "table/sprites.h" #include "table/sprites.h"
@ -592,7 +593,7 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
break; break;
case WE_ON_EDIT_TEXT: case WE_ON_EDIT_TEXT:
if (e->we.edittext.str[0] != '\0') { if (!StrEmpty(e->we.edittext.str)) {
Industry* i = GetIndustry(w->window_number); Industry* i = GetIndustry(w->window_number);
int line = WP(w, indview_d).editbox_line; int line = WP(w, indview_d).editbox_line;

View File

@ -1040,7 +1040,8 @@ static void QueryStringWndProc(Window *w, WindowEvent *e)
Window *parent = w->parent; Window *parent = w->parent;
qs->handled = true; qs->handled = true;
e.event = WE_ON_EDIT_TEXT_CANCEL; e.event = WE_ON_EDIT_TEXT;
e.we.edittext.str = NULL;
parent->HandleWindowEvent(&e); parent->HandleWindowEvent(&e);
} }
ClrBit(_no_scroll, SCROLL_EDIT); ClrBit(_no_scroll, SCROLL_EDIT);

View File

@ -579,8 +579,10 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
break; break;
case WE_ON_EDIT_TEXT: case WE_ON_EDIT_TEXT:
NetworkAddServer(e->we.edittext.str); if (!StrEmpty(e->we.edittext.str)) {
NetworkRebuildHostList(); NetworkAddServer(e->we.edittext.str);
NetworkRebuildHostList();
}
break; break;
case WE_RESIZE: { case WE_RESIZE: {
@ -917,7 +919,7 @@ static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e)
if (nd->widget_id == NSSW_SETPWD) { if (nd->widget_id == NSSW_SETPWD) {
ttd_strlcpy(_network_server_password, e->we.edittext.str, lengthof(_network_server_password)); 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 { } else {
int32 value = atoi(e->we.edittext.str); int32 value = atoi(e->we.edittext.str);
w->InvalidateWidget(nd->widget_id); w->InvalidateWidget(nd->widget_id);
@ -1673,15 +1675,14 @@ static void NetworkJoinStatusWindowWndProc(Window *w, WindowEvent *e)
} }
break; break;
/* If the server asks for a password, we need to fill it in */ case WE_ON_EDIT_TEXT:
case WE_ON_EDIT_TEXT_CANCEL: if (StrEmpty(e->we.edittext.str)) {
NetworkDisconnect(); NetworkDisconnect();
ShowNetworkGameWindow(); ShowNetworkGameWindow();
break; } else {
case WE_ON_EDIT_TEXT:
SEND_COMMAND(PACKET_CLIENT_PASSWORD)(pw_type, e->we.edittext.str); SEND_COMMAND(PACKET_CLIENT_PASSWORD)(pw_type, e->we.edittext.str);
break; }
break;
} }
} }

View File

@ -516,8 +516,9 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
/* parse_intlist returns -1 on error */ /* parse_intlist returns -1 on error */
if (c->num_params == (byte)-1) c->num_params = 0; if (c->num_params == (byte)-1) c->num_params = 0;
w->SetDirty();
} }
w->SetDirty();
break; break;
case WE_DESTROY: case WE_DESTROY:

View File

@ -979,6 +979,7 @@ static void SelectPlayerFaceWndProc(Window *w, WindowEvent *e)
break; break;
case WE_ON_EDIT_TEXT: case WE_ON_EDIT_TEXT:
if (e->we.edittext.str == NULL) break;
/* Set a new player face number */ /* Set a new player face number */
if (!StrEmpty(e->we.edittext.str)) { if (!StrEmpty(e->we.edittext.str)) {
*pf = strtoul(e->we.edittext.str, NULL, 10); *pf = strtoul(e->we.edittext.str, NULL, 10);
@ -1331,7 +1332,7 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
break; break;
case WE_ON_EDIT_TEXT: 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; _cmd_text = e->we.edittext.str;
switch (WP(w, def_d).byte_1) { switch (WP(w, def_d).byte_1) {

View File

@ -1059,7 +1059,7 @@ static void PatchesSelectionWndProc(Window *w, WindowEvent *e)
break; break;
case WE_ON_EDIT_TEXT: 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 PatchEntry *pe = &_patches_page[WP(w, def_d).data_1].entries[WP(w, def_d).data_3];
const SettingDesc *sd = pe->setting; const SettingDesc *sd = pe->setting;
int32 value = atoi(e->we.edittext.str); int32 value = atoi(e->we.edittext.str);
@ -1271,6 +1271,8 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
} break; } break;
case WE_ON_EDIT_TEXT: { case WE_ON_EDIT_TEXT: {
if (e->we.edittext.str == NULL) break;
const char *b = e->we.edittext.str; const char *b = e->we.edittext.str;
switch (WP(w, def_d).data_2) { switch (WP(w, def_d).data_2) {
@ -1279,7 +1281,7 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
break; break;
case CUSTCURR_SEPARATOR: /* Thousands seperator */ 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)); ttd_strlcpy(_str_separator, b, lengthof(_str_separator));
break; break;

View File

@ -25,6 +25,7 @@
#include "gfx_func.h" #include "gfx_func.h"
#include "widgets/dropdown_func.h" #include "widgets/dropdown_func.h"
#include "newgrf_cargo.h" #include "newgrf_cargo.h"
#include "string_func.h"
#include "table/strings.h" #include "table/strings.h"
#include "table/sprites.h" #include "table/sprites.h"
@ -1002,7 +1003,7 @@ static void StationViewWndProc(Window *w, WindowEvent *e)
break; break;
case WE_ON_EDIT_TEXT: case WE_ON_EDIT_TEXT:
if (e->we.edittext.str[0] != '\0') { if (!StrEmpty(e->we.edittext.str)) {
_cmd_text = e->we.edittext.str; _cmd_text = e->we.edittext.str;
DoCommandP(0, w->window_number, 0, NULL, DoCommandP(0, w->window_number, 0, NULL,
CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION)); CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION));

View File

@ -249,6 +249,8 @@ static void TimetableWndProc(Window *w, WindowEvent *we)
} break; } break;
case WE_ON_EDIT_TEXT: { case WE_ON_EDIT_TEXT: {
if (we->we.edittext.str == NULL) break;
const Vehicle *v = GetVehicle(w->window_number); const Vehicle *v = GetVehicle(w->window_number);
uint32 p1 = PackTimetableArgs(v, WP(w, timetable_d).sel); uint32 p1 = PackTimetableArgs(v, WP(w, timetable_d).sel);

View File

@ -23,6 +23,7 @@
#include "core/alloc_func.hpp" #include "core/alloc_func.hpp"
#include "settings_type.h" #include "settings_type.h"
#include "tilehighlight_func.h" #include "tilehighlight_func.h"
#include "string_func.h"
#include "table/sprites.h" #include "table/sprites.h"
#include "table/strings.h" #include "table/strings.h"
@ -360,7 +361,7 @@ static void TownViewWndProc(Window *w, WindowEvent *e)
} break; } break;
case WE_ON_EDIT_TEXT: case WE_ON_EDIT_TEXT:
if (e->we.edittext.str[0] != '\0') { if (!StrEmpty(e->we.edittext.str)) {
_cmd_text = e->we.edittext.str; _cmd_text = e->we.edittext.str;
DoCommandP(0, w->window_number, 0, NULL, DoCommandP(0, w->window_number, 0, NULL,
CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN)); CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN));

View File

@ -125,7 +125,6 @@ enum WindowEventCodes {
WE_PLACE_OBJ, WE_PLACE_OBJ,
WE_ABORT_PLACE_OBJ, WE_ABORT_PLACE_OBJ,
WE_ON_EDIT_TEXT, WE_ON_EDIT_TEXT,
WE_ON_EDIT_TEXT_CANCEL,
WE_DRAGDROP, WE_DRAGDROP,
WE_PLACE_DRAG, WE_PLACE_DRAG,
WE_PLACE_MOUSEUP, WE_PLACE_MOUSEUP,