(svn r1890) Begin to clean up the edit box: Remove one global variable and split the combined edit/original buffer into two

This commit is contained in:
tron 2005-02-19 14:40:32 +00:00
parent bf5e0c10ce
commit 2de3dc2735
4 changed files with 19 additions and 24 deletions

2
gui.h
View File

@ -116,7 +116,7 @@ enum {
bool DoZoomInOutWindow(int how, Window * w); bool DoZoomInOutWindow(int how, Window * w);
void ShowBuildIndustryWindow(void); 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); void ShowMusicWindow(void);
/* main_gui.c */ /* main_gui.c */

View File

@ -4,7 +4,7 @@
#include "strings.h" #include "strings.h"
#include "table/strings.h" #include "table/strings.h"
#include "map.h" #include "map.h"
//#include "gui.h" #include "gui.h"
#include "window.h" #include "window.h"
#include "gfx.h" #include "gfx.h"
#include "command.h" #include "command.h"
@ -23,7 +23,6 @@ extern const byte _industry_type_costs[37];
static void UpdateIndustryProduction(Industry *i); static void UpdateIndustryProduction(Industry *i);
extern void DrawArrowButtons(int x, int y, int state); 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) static void BuildIndustryWndProc(Window *w, WindowEvent *e)
{ {

View File

@ -26,9 +26,6 @@
bool _query_string_active; 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 { typedef struct LandInfoData {
Town *town; Town *town;
int32 costclear; int32 costclear;
@ -884,8 +881,6 @@ void DrawEditBox(Window *w, int wid)
} }
#define MAX_QUERYSTR_LEN 64
static void QueryStringWndProc(Window *w, WindowEvent *e) static void QueryStringWndProc(Window *w, WindowEvent *e)
{ {
static bool closed = false; static bool closed = false;
@ -904,8 +899,8 @@ static void QueryStringWndProc(Window *w, WindowEvent *e)
case 3: DeleteWindow(w); break; case 3: DeleteWindow(w); break;
case 4: case 4:
press_ok:; press_ok:;
if (strcmp(WP(w,querystr_d).buf, WP(w,querystr_d).buf + MAX_QUERYSTR_LEN) == 0 && if (WP(w, querystr_d).orig != NULL &&
!_do_edit_on_text_even_when_no_change_to_edit_box) { strcmp(WP(w, querystr_d).buf, WP(w, querystr_d).orig) == 0) {
DeleteWindow(w); DeleteWindow(w);
} else { } else {
char *buf = WP(w,querystr_d).buf; char *buf = WP(w,querystr_d).buf;
@ -985,30 +980,30 @@ static const WindowDesc _query_string_desc = {
QueryStringWndProc 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; 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_QUERY_STRING, 0);
DeleteWindowById(WC_SAVELOAD, 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) { if (maxlen & 0x1000) {
_do_edit_on_text_even_when_no_change_to_edit_box = true; WP(w, querystr_d).orig = NULL;
maxlen &= ~0x1000; maxlen &= ~0x1000;
} else } else {
_do_edit_on_text_even_when_no_change_to_edit_box = false; strcpy(_orig_str_buf, _edit_str_buf);
WP(w, querystr_d).orig = _orig_str_buf;
_orig_edit_str_buf[maxlen] = 0; }
memcpy(_edit_str_buf, _orig_edit_str_buf, MAX_QUERYSTR_LEN);
w = AllocateWindowDesc(&_query_string_desc);
w->click_state = 1 << 5; w->click_state = 1 << 5;
WP(w,querystr_d).caption = caption; WP(w,querystr_d).caption = caption;
@ -1346,7 +1341,7 @@ void ShowSaveLoadDialog(int mode)
w->resize.height = w->height - 14 * 10; // Minimum of 10 items w->resize.height = w->height - 14 * 10; // Minimum of 10 items
w->click_state |= (1 << 6); w->click_state |= (1 << 6);
WP(w,querystr_d).caret = 0; 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).maxwidth = 240;
WP(w,querystr_d).buf = _edit_str_buf; WP(w,querystr_d).buf = _edit_str_buf;

View File

@ -229,6 +229,7 @@ typedef struct {
WindowNumber wnd_num; WindowNumber wnd_num;
uint16 maxlen, maxwidth; uint16 maxlen, maxwidth;
char *buf; char *buf;
const char* orig;
} querystr_d; } querystr_d;
#define WP(ptr,str) (*(str*)(ptr)->custom) #define WP(ptr,str) (*(str*)(ptr)->custom)