(svn r1890) Begin to clean up the edit box: Remove one global variable and split the combined edit/original buffer into two
authortron
Sat, 19 Feb 2005 14:40:32 +0000
changeset 1386 aa5a172a8431
parent 1385 324d3d06a930
child 1387 eff794048d92
(svn r1890) Begin to clean up the edit box: Remove one global variable and split the combined edit/original buffer into two
gui.h
industry_gui.c
misc_gui.c
window.h
--- a/gui.h	Fri Feb 18 22:17:33 2005 +0000
+++ b/gui.h	Sat Feb 19 14:40:32 2005 +0000
@@ -116,7 +116,7 @@
 
 bool DoZoomInOutWindow(int how, Window * w);
 void ShowBuildIndustryWindow(void);
-void ShowQueryString(StringID str, StringID caption, int maxlen, int maxwidth, byte window_class, uint16 window_number);
+void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth, WindowClass window_class, WindowNumber window_number);
 void ShowMusicWindow(void);
 
 /* main_gui.c */
--- a/industry_gui.c	Fri Feb 18 22:17:33 2005 +0000
+++ b/industry_gui.c	Sat Feb 19 14:40:32 2005 +0000
@@ -4,7 +4,7 @@
 #include "strings.h"
 #include "table/strings.h"
 #include "map.h"
-//#include "gui.h"
+#include "gui.h"
 #include "window.h"
 #include "gfx.h"
 #include "command.h"
@@ -23,7 +23,6 @@
 
 static void UpdateIndustryProduction(Industry *i);
 extern void DrawArrowButtons(int x, int y, int state);
-extern void ShowQueryString(StringID str, StringID caption, int maxlen, int maxwidth, byte window_class, uint16 window_number);
 
 static void BuildIndustryWndProc(Window *w, WindowEvent *e)
 {
--- a/misc_gui.c	Fri Feb 18 22:17:33 2005 +0000
+++ b/misc_gui.c	Sat Feb 19 14:40:32 2005 +0000
@@ -26,9 +26,6 @@
 
 bool _query_string_active;
 
-/* Now this is what I call dirty.. the edit-box needs to be rewritten! */
-static bool _do_edit_on_text_even_when_no_change_to_edit_box;
-
 typedef struct LandInfoData {
 	Town *town;
 	int32 costclear;
@@ -884,8 +881,6 @@
 }
 
 
-#define MAX_QUERYSTR_LEN 64
-
 static void QueryStringWndProc(Window *w, WindowEvent *e)
 {
 	static bool closed = false;
@@ -904,8 +899,8 @@
 		case 3: DeleteWindow(w); break;
 		case 4:
 press_ok:;
-			if (strcmp(WP(w,querystr_d).buf, WP(w,querystr_d).buf + MAX_QUERYSTR_LEN) == 0 &&
-					!_do_edit_on_text_even_when_no_change_to_edit_box) {
+			if (WP(w, querystr_d).orig != NULL &&
+					strcmp(WP(w, querystr_d).buf, WP(w, querystr_d).orig) == 0) {
 				DeleteWindow(w);
 			} else {
 				char *buf = WP(w,querystr_d).buf;
@@ -985,30 +980,30 @@
 	QueryStringWndProc
 };
 
-static char _edit_str_buf[MAX_QUERYSTR_LEN*2];
+static char _edit_str_buf[64];
+static char _orig_str_buf[lengthof(_edit_str_buf)];
 
-void ShowQueryString(StringID str, StringID caption, int maxlen, int maxwidth, byte window_class, uint16 window_number)
+void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth, WindowClass window_class, WindowNumber window_number)
 {
 	Window *w;
 
-#define _orig_edit_str_buf (_edit_str_buf+MAX_QUERYSTR_LEN)
+	assert(maxlen < lengthof(_edit_str_buf));
 
 	DeleteWindowById(WC_QUERY_STRING, 0);
 	DeleteWindowById(WC_SAVELOAD, 0);
 
-	GetString(_orig_edit_str_buf, str);
+	w = AllocateWindowDesc(&_query_string_desc);
+
+	GetString(_edit_str_buf, str);
+	_edit_str_buf[maxlen] = '\0';
 
 	if (maxlen & 0x1000) {
-		_do_edit_on_text_even_when_no_change_to_edit_box = true;
+		WP(w, querystr_d).orig = NULL;
 		maxlen &= ~0x1000;
-	} else
-		_do_edit_on_text_even_when_no_change_to_edit_box = false;
-
-	_orig_edit_str_buf[maxlen] = 0;
-
-	memcpy(_edit_str_buf, _orig_edit_str_buf, MAX_QUERYSTR_LEN);
-
-	w = AllocateWindowDesc(&_query_string_desc);
+	} else {
+		strcpy(_orig_str_buf, _edit_str_buf);
+		WP(w, querystr_d).orig = _orig_str_buf;
+	}
 
 	w->click_state = 1 << 5;
 	WP(w,querystr_d).caption = caption;
@@ -1346,7 +1341,7 @@
 	w->resize.height = w->height - 14 * 10; // Minimum of 10 items
 	w->click_state |= (1 << 6);
 	WP(w,querystr_d).caret = 0;
-	WP(w,querystr_d).maxlen = MAX_QUERYSTR_LEN;
+	WP(w,querystr_d).maxlen = lengthof(_edit_str_buf);
 	WP(w,querystr_d).maxwidth = 240;
 	WP(w,querystr_d).buf = _edit_str_buf;
 
--- a/window.h	Fri Feb 18 22:17:33 2005 +0000
+++ b/window.h	Sat Feb 19 14:40:32 2005 +0000
@@ -229,6 +229,7 @@
 	WindowNumber wnd_num;
 	uint16 maxlen, maxwidth;
 	char *buf;
+	const char* orig;
 } querystr_d;
 
 #define WP(ptr,str) (*(str*)(ptr)->custom)