(svn r13027) -Codechange: use StrEmpty instead of arr[0] == '\0' and remove the need for WE_ON_EDIT_TEXT_CANCEL.
authorrubidium
Sat, 10 May 2008 08:58:52 +0000
changeset 10484 e8beb2845f13
parent 10483 200609cedea9
child 10485 331014dcd0d3
(svn r13027) -Codechange: use StrEmpty instead of arr[0] == '\0' and remove the need for WE_ON_EDIT_TEXT_CANCEL.
src/build_vehicle_gui.cpp
src/genworld_gui.cpp
src/industry_gui.cpp
src/misc_gui.cpp
src/network/network_gui.cpp
src/newgrf_gui.cpp
src/player_gui.cpp
src/settings_gui.cpp
src/station_gui.cpp
src/timetable_gui.cpp
src/town_gui.cpp
src/window_gui.h
--- a/src/build_vehicle_gui.cpp	Sat May 10 02:59:52 2008 +0000
+++ b/src/build_vehicle_gui.cpp	Sat May 10 08:58:52 2008 +0000
@@ -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 @@
 			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) {
--- a/src/genworld_gui.cpp	Sat May 10 02:59:52 2008 +0000
+++ b/src/genworld_gui.cpp	Sat May 10 08:58:52 2008 +0000
@@ -525,7 +525,7 @@
 			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 @@
 			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) {
--- a/src/industry_gui.cpp	Sat May 10 02:59:52 2008 +0000
+++ b/src/industry_gui.cpp	Sat May 10 08:58:52 2008 +0000
@@ -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 @@
 			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;
 
--- a/src/misc_gui.cpp	Sat May 10 02:59:52 2008 +0000
+++ b/src/misc_gui.cpp	Sat May 10 08:58:52 2008 +0000
@@ -1040,7 +1040,8 @@
 				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);
--- a/src/network/network_gui.cpp	Sat May 10 02:59:52 2008 +0000
+++ b/src/network/network_gui.cpp	Sat May 10 08:58:52 2008 +0000
@@ -579,8 +579,10 @@
 			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 @@
 
 			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 @@
 			}
 			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;
 	}
 }
 
--- a/src/newgrf_gui.cpp	Sat May 10 02:59:52 2008 +0000
+++ b/src/newgrf_gui.cpp	Sat May 10 08:58:52 2008 +0000
@@ -516,8 +516,9 @@
 
 				/* parse_intlist returns -1 on error */
 				if (c->num_params == (byte)-1) c->num_params = 0;
+
+				w->SetDirty();
 			}
-			w->SetDirty();
 			break;
 
 		case WE_DESTROY:
--- a/src/player_gui.cpp	Sat May 10 02:59:52 2008 +0000
+++ b/src/player_gui.cpp	Sat May 10 08:58:52 2008 +0000
@@ -979,6 +979,7 @@
 			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 @@
 			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) {
--- a/src/settings_gui.cpp	Sat May 10 02:59:52 2008 +0000
+++ b/src/settings_gui.cpp	Sat May 10 08:58:52 2008 +0000
@@ -1059,7 +1059,7 @@
 			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 @@
 		} 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 @@
 					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;
 
--- a/src/station_gui.cpp	Sat May 10 02:59:52 2008 +0000
+++ b/src/station_gui.cpp	Sat May 10 08:58:52 2008 +0000
@@ -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 @@
 			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));
--- a/src/timetable_gui.cpp	Sat May 10 02:59:52 2008 +0000
+++ b/src/timetable_gui.cpp	Sat May 10 08:58:52 2008 +0000
@@ -249,6 +249,8 @@
 		} 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);
--- a/src/town_gui.cpp	Sat May 10 02:59:52 2008 +0000
+++ b/src/town_gui.cpp	Sat May 10 08:58:52 2008 +0000
@@ -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 @@
 			} 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));
--- a/src/window_gui.h	Sat May 10 02:59:52 2008 +0000
+++ b/src/window_gui.h	Sat May 10 08:58:52 2008 +0000
@@ -125,7 +125,6 @@
 	WE_PLACE_OBJ,
 	WE_ABORT_PLACE_OBJ,
 	WE_ON_EDIT_TEXT,
-	WE_ON_EDIT_TEXT_CANCEL,
 	WE_DRAGDROP,
 	WE_PLACE_DRAG,
 	WE_PLACE_MOUSEUP,