src/querystring_gui.h
author smatz
Wed, 22 Oct 2008 19:12:10 +0000
changeset 10276 b60b7e17db62
parent 9916 40b0040c754b
child 10295 52982b3d0d84
permissions -rw-r--r--
(svn r14514) -Codechange: use 'size' instead of 'length' for querystring and textbuf, explicitly say it includes the terminating zero
-Fix: one couldn't rename things with too long default/automatic name
-Fix: buffer overflow in console when too long (1024 bytes) command was entered
9179
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
     1
/* $Id$ */
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
     2
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
     3
/** @file querystring_gui.h Base for the GUIs that have an edit box in them. */
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
     4
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
     5
#ifndef QUERYSTRING_GUI_H
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
     6
#define QUERYSTRING_GUI_H
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
     7
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
     8
#include "textbuf_gui.h"
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
     9
#include "window_gui.h"
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    10
9897
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    11
/**
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    12
 * Data stored about a string that can be modified in the GUI
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    13
 */
9179
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    14
struct QueryString {
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    15
	StringID caption;
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    16
	Textbuf text;
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    17
	const char *orig;
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    18
	CharSetFilter afilter;
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    19
	bool handled;
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    20
9897
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    21
	/**
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    22
	 * Make sure everything gets initialized properly.
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    23
	 */
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    24
	QueryString() : orig(NULL)
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    25
	{
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    26
	}
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    27
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    28
	/**
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    29
	 * Make sure everything gets freed.
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    30
	 */
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    31
	~QueryString()
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    32
	{
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    33
		free((void*)this->orig);
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    34
	}
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    35
9179
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    36
	void DrawEditBox(Window *w, int wid);
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    37
	void HandleEditBox(Window *w, int wid);
9285
235e5e2d7f55 (svn r13151) -Codechange: use an enum instead of bool as return type of OnKeyPress/OnCTRLStateChange to make it obvious what the return values mean.
rubidium
parents: 9203
diff changeset
    38
	int HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, Window::EventState &state);
9179
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    39
};
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    40
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    41
struct QueryStringBaseWindow : public Window, public QueryString {
9897
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    42
	char *edit_str_buf;
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    43
	char *orig_str_buf;
10276
b60b7e17db62 (svn r14514) -Codechange: use 'size' instead of 'length' for querystring and textbuf, explicitly say it includes the terminating zero
smatz
parents: 9916
diff changeset
    44
	const uint16 edit_str_size; ///< maximum length of string (in bytes), including terminating '\0'
9179
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    45
9916
40b0040c754b (svn r14069) -Fix: silence MSVC 64-bits compile warnings.
rubidium
parents: 9897
diff changeset
    46
	QueryStringBaseWindow(uint16 size, const WindowDesc *desc, WindowNumber window_number = 0) : Window(desc, window_number), edit_str_size(size)
9179
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    47
	{
10276
b60b7e17db62 (svn r14514) -Codechange: use 'size' instead of 'length' for querystring and textbuf, explicitly say it includes the terminating zero
smatz
parents: 9916
diff changeset
    48
		assert(size != 0);
9897
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    49
		this->edit_str_buf = CallocT<char>(size);
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    50
	}
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    51
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    52
	~QueryStringBaseWindow()
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    53
	{
4d9a6ff6703e (svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
rubidium
parents: 9285
diff changeset
    54
		free(this->edit_str_buf);
9179
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    55
	}
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    56
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    57
	void DrawEditBox(int wid);
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    58
	void HandleEditBox(int wid);
9285
235e5e2d7f55 (svn r13151) -Codechange: use an enum instead of bool as return type of OnKeyPress/OnCTRLStateChange to make it obvious what the return values mean.
rubidium
parents: 9203
diff changeset
    59
	int HandleEditBoxKey(int wid, uint16 key, uint16 keycode, EventState &state);
9179
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    60
};
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    61
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    62
void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button, int cancel, int ok);
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    63
780666b686ed (svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
rubidium
parents:
diff changeset
    64
#endif /* QUERYSTRING_GUI_H */