Changeset - r19787:20d2473dd1cb
[Not reviewed]
master
0 16 0
frosch - 12 years ago 2012-11-14 22:50:35
frosch@openttd.org
(svn r24742) -Codechange: Remove QueryStringBaseWindow and store QueryStrings per widget instead.
16 files changed with 180 insertions and 131 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_gui.cpp
Show inline comments
 
@@ -978,25 +978,26 @@ static bool SetScriptButtonColour(NWidge
 
	return false;
 
}
 

	
 
/**
 
 * Window with everything an AI prints via ScriptLog.
 
 */
 
struct AIDebugWindow : public QueryStringBaseWindow {
 
struct AIDebugWindow : public Window {
 
	static const int top_offset;    ///< Offset of the text at the top of the WID_AID_LOG_PANEL.
 
	static const int bottom_offset; ///< Offset of the text at the bottom of the WID_AID_LOG_PANEL.
 

	
 
	static const unsigned int MAX_BREAK_STR_STRING_LENGTH = 256; ///< Maximum length of the break string.
 

	
 
	static CompanyID ai_debug_company;                     ///< The AI that is (was last) being debugged.
 
	int redraw_timer;                                      ///< Timer for redrawing the window, otherwise it'll happen every tick.
 
	int last_vscroll_pos;                                  ///< Last position of the scrolling.
 
	bool autoscroll;                                       ///< Whether automatically scrolling should be enabled or not.
 
	bool show_break_box;                                   ///< Whether the break/debug box is visible.
 
	static bool break_check_enabled;                       ///< Stop an AI when it prints a matching string
 
	static char break_string[MAX_BREAK_STR_STRING_LENGTH]; ///< The string to match to the AI output
 
	QueryString break_editbox;                             ///< Break editbox
 
	static StringFilter break_string_filter;               ///< Log filter for break.
 
	static bool case_sensitive_break_check;                ///< Is the matching done case-sensitive
 
	int highlight_row;                                     ///< The output row that matches the given string, or -1
 
	Scrollbar *vscroll;                                    ///< Cache of the vertical scrollbar.
 

	
 
	ScriptLog::LogData *GetLogPointer() const
 
@@ -1007,13 +1008,13 @@ struct AIDebugWindow : public QueryStrin
 

	
 
	/**
 
	 * Constructor for the window.
 
	 * @param desc The description of the window.
 
	 * @param number The window number (actually unused).
 
	 */
 
	AIDebugWindow(const WindowDesc *desc, WindowNumber number) : QueryStringBaseWindow(MAX_BREAK_STR_STRING_LENGTH)
 
	AIDebugWindow(const WindowDesc *desc, WindowNumber number) : break_editbox(MAX_BREAK_STR_STRING_LENGTH)
 
	{
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(WID_AID_SCROLLBAR);
 
		this->show_break_box = _settings_client.gui.ai_developer_tools;
 
		this->GetWidget<NWidgetStacked>(WID_AID_BREAK_STRING_WIDGETS)->SetDisplayedPlane(this->show_break_box ? 0 : SZSP_HORIZONTAL);
 
		this->FinishInitNested(desc, number);
 
@@ -1029,14 +1030,16 @@ struct AIDebugWindow : public QueryStrin
 
		this->DisableWidget(WID_AID_CONTINUE_BTN);
 

	
 
		this->last_vscroll_pos = 0;
 
		this->autoscroll = true;
 
		this->highlight_row = -1;
 

	
 
		this->querystrings[WID_AID_BREAK_STR_EDIT_BOX] = &this->break_editbox;
 

	
 
		/* Restore the break string value from static variable */
 
		this->text.Assign(this->break_string);
 
		this->break_editbox.text.Assign(this->break_string);
 

	
 
		/* Restore button state from static class variables */
 
		if (ai_debug_company == OWNER_DEITY) {
 
			this->LowerWidget(WID_AID_SCRIPT_GAME);
 
			this->SetWidgetDisabledState(WID_AID_CONTINUE_BTN, !Game::IsPaused());
 
		} else if (ai_debug_company != INVALID_COMPANY) {
 
@@ -1353,13 +1356,13 @@ struct AIDebugWindow : public QueryStrin
 
	}
 

	
 
	virtual void OnEditboxChanged(int wid)
 
	{
 
		if (wid == WID_AID_BREAK_STR_EDIT_BOX) {
 
			/* Save the current string to static member so it can be restored next time the window is opened. */
 
			strecpy(this->break_string, this->text.buf, lastof(this->break_string));
 
			strecpy(this->break_string, this->break_editbox.text.buf, lastof(this->break_string));
 
			break_string_filter.SetFilterTerm(this->break_string);
 
		}
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
src/fios_gui.cpp
Show inline comments
 
@@ -225,27 +225,28 @@ static void MakeSortedSaveGameList()
 
	}
 

	
 
	uint s_amount = _fios_items.Length() - sort_start - sort_end;
 
	QSortT(_fios_items.Get(sort_start), s_amount, CompareFiosItems);
 
}
 

	
 
struct SaveLoadWindow : public QueryStringBaseWindow {
 
struct SaveLoadWindow : public Window {
 
private:
 
	QueryString filename_editbox; ///< Filename editbox.
 
	FiosItem o_dir;
 
	const FiosItem *selected;
 
	Scrollbar *vscroll;
 
public:
 

	
 
	/** Generate a default save filename. */
 
	void GenerateFileName()
 
	{
 
		GenerateDefaultSaveName(this->text.buf, &this->text.buf[this->text.max_bytes - 1]);
 
		this->text.UpdateSize();
 
		GenerateDefaultSaveName(this->filename_editbox.text.buf, &this->filename_editbox.text.buf[this->filename_editbox.text.max_bytes - 1]);
 
		this->filename_editbox.text.UpdateSize();
 
	}
 

	
 
	SaveLoadWindow(const WindowDesc *desc, SaveLoadDialogMode mode) : QueryStringBaseWindow(64)
 
	SaveLoadWindow(const WindowDesc *desc, SaveLoadDialogMode mode) : filename_editbox(64)
 
	{
 
		static const StringID saveload_captions[] = {
 
			STR_SAVELOAD_LOAD_CAPTION,
 
			STR_SAVELOAD_LOAD_SCENARIO,
 
			STR_SAVELOAD_SAVE_CAPTION,
 
			STR_SAVELOAD_SAVE_SCENARIO,
 
@@ -256,18 +257,19 @@ public:
 

	
 
		/* Use an array to define what will be the current file type being handled
 
		 * by current file mode */
 
		switch (mode) {
 
			case SLD_SAVE_GAME:     this->GenerateFileName(); break;
 
			case SLD_SAVE_HEIGHTMAP:
 
			case SLD_SAVE_SCENARIO: this->text.Assign("UNNAMED"); break;
 
			case SLD_SAVE_SCENARIO: this->filename_editbox.text.Assign("UNNAMED"); break;
 
			default:                break;
 
		}
 

	
 
		this->ok_button = WID_SL_SAVE_GAME;
 
		this->afilter = CS_ALPHANUMERAL;
 
		this->querystrings[WID_SL_SAVE_OSK_TITLE] = &this->filename_editbox;
 
		this->filename_editbox.ok_button = WID_SL_SAVE_GAME;
 
		this->filename_editbox.afilter = CS_ALPHANUMERAL;
 

	
 
		this->CreateNestedTree(desc, true);
 
		if (mode == SLD_LOAD_GAME) this->GetWidget<NWidgetStacked>(WID_SL_CONTENT_DOWNLOAD_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL);
 
		this->GetWidget<NWidgetCore>(WID_SL_CAPTION)->widget_data = saveload_captions[mode];
 
		this->vscroll = this->GetScrollbar(WID_SL_SCROLLBAR);
 

	
 
@@ -564,13 +566,13 @@ public:
 
							}
 

	
 
							this->InvalidateData(1);
 
						}
 
						if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP) {
 
							/* Copy clicked name to editbox */
 
							this->text.Assign(file->title);
 
							this->filename_editbox.text.Assign(file->title);
 
							this->SetWidgetDirty(WID_SL_SAVE_OSK_TITLE);
 
						}
 
					} else if (!_load_check_data.HasErrors()) {
 
						this->selected = file;
 
						if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) {
 
							this->OnClick(pt, WID_SL_LOAD_BUTTON, 1);
 
@@ -628,26 +630,26 @@ public:
 
	{
 
		/* This test protects against using widgets 11 and 12 which are only available
 
		 * in those saveload modes. */
 
		if (!(_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP)) return;
 

	
 
		if (this->IsWidgetLowered(WID_SL_DELETE_SELECTION)) { // Delete button clicked
 
			if (!FiosDelete(this->text.buf)) {
 
			if (!FiosDelete(this->filename_editbox.text.buf)) {
 
				ShowErrorMessage(STR_ERROR_UNABLE_TO_DELETE_FILE, INVALID_STRING_ID, WL_ERROR);
 
			} else {
 
				this->InvalidateData();
 
				/* Reset file name to current date on successful delete */
 
				if (_saveload_mode == SLD_SAVE_GAME) GenerateFileName();
 
			}
 
		} else if (this->IsWidgetLowered(WID_SL_SAVE_GAME)) { // Save button clicked
 
			if (_saveload_mode  == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
 
				_switch_mode = SM_SAVE_GAME;
 
				FiosMakeSavegameName(_file_to_saveload.name, this->text.buf, sizeof(_file_to_saveload.name));
 
				FiosMakeSavegameName(_file_to_saveload.name, this->filename_editbox.text.buf, sizeof(_file_to_saveload.name));
 
			} else {
 
				_switch_mode = SM_SAVE_HEIGHTMAP;
 
				FiosMakeHeightmapName(_file_to_saveload.name, this->text.buf, sizeof(_file_to_saveload.name));
 
				FiosMakeHeightmapName(_file_to_saveload.name, this->filename_editbox.text.buf, sizeof(_file_to_saveload.name));
 
			}
 

	
 
			/* In the editor set up the vehicle engines correctly (date might have changed) */
 
			if (_game_mode == GM_EDITOR) StartupEngines();
 
		}
 
	}
src/genworld_gui.cpp
Show inline comments
 
@@ -300,28 +300,30 @@ static const StringID _landscape[]   = {
 
static const StringID _num_towns[]   = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM, INVALID_STRING_ID};
 
static const StringID _num_inds[]    = {STR_FUNDING_ONLY, STR_MINIMAL, STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, INVALID_STRING_ID};
 
static const StringID _variety[]     = {STR_VARIETY_NONE, STR_VARIETY_VERY_LOW, STR_VARIETY_LOW, STR_VARIETY_MEDIUM, STR_VARIETY_HIGH, STR_VARIETY_VERY_HIGH, INVALID_STRING_ID};
 

	
 
assert_compile(lengthof(_num_inds) == ID_END + 1);
 

	
 
struct GenerateLandscapeWindow : public QueryStringBaseWindow {
 
struct GenerateLandscapeWindow : public Window {
 
	uint widget_id;
 
	uint x;
 
	uint y;
 
	char name[64];
 
	GenenerateLandscapeWindowMode mode;
 
	QueryString seed_editbox;
 

	
 
	GenerateLandscapeWindow(const WindowDesc *desc, WindowNumber number = 0) : QueryStringBaseWindow(11)
 
	GenerateLandscapeWindow(const WindowDesc *desc, WindowNumber number = 0) : seed_editbox(11)
 
	{
 
		this->InitNested(desc, number);
 

	
 
		this->LowerWidget(_settings_newgame.game_creation.landscape + WID_GL_TEMPERATE);
 

	
 
		this->text.Print("%u", _settings_newgame.game_creation.generation_seed);
 
		this->caption = STR_NULL;
 
		this->afilter = CS_NUMERAL;
 
		this->querystrings[WID_GL_RANDOM_EDITBOX] = &this->seed_editbox;
 
		this->seed_editbox.text.Print("%u", _settings_newgame.game_creation.generation_seed);
 
		this->seed_editbox.caption = STR_NULL;
 
		this->seed_editbox.afilter = CS_NUMERAL;
 

	
 
		this->mode = (GenenerateLandscapeWindowMode)this->window_number;
 

	
 
		/* Disable town, industry and trees in SE */
 
		this->SetWidgetDisabledState(WID_GL_TOWN_PULLDOWN,     _game_mode == GM_EDITOR);
 
		this->SetWidgetDisabledState(WID_GL_INDUSTRY_PULLDOWN, _game_mode == GM_EDITOR);
 
@@ -544,13 +546,13 @@ struct GenerateLandscapeWindow : public 
 
			case WID_GL_INDUSTRY_PULLDOWN: // Number of industries
 
				ShowDropDownMenu(this, _num_inds, _settings_newgame.difficulty.industry_density, WID_GL_INDUSTRY_PULLDOWN, 0, 0);
 
				break;
 

	
 
			case WID_GL_RANDOM_BUTTON: // Random seed
 
				_settings_newgame.game_creation.generation_seed = InteractiveRandom();
 
				this->text.Print("%u", _settings_newgame.game_creation.generation_seed);
 
				this->seed_editbox.text.Print("%u", _settings_newgame.game_creation.generation_seed);
 
				this->SetDirty();
 
				break;
 

	
 
			case WID_GL_GENERATE_BUTTON: { // Generate
 
				/* Get rotated map size. */
 
				uint map_x;
 
@@ -695,13 +697,13 @@ struct GenerateLandscapeWindow : public 
 
	{
 
		if (wid == WID_GL_RANDOM_EDITBOX) {
 
			/* the seed is unsigned, therefore atoi cannot be used.
 
			 * As UINT32_MAX is a 'magic' value (use random seed) it
 
			 * should not be possible to be entered into the input
 
			 * field; the generate seed button can be used instead. */
 
			_settings_newgame.game_creation.generation_seed = minu(strtoul(this->text.buf, NULL, 10), UINT32_MAX - 1);
 
			_settings_newgame.game_creation.generation_seed = minu(strtoul(this->seed_editbox.text.buf, NULL, 10), UINT32_MAX - 1);
 
		}
 
	}
 

	
 
	virtual void OnDropdownSelect(int widget, int index)
 
	{
 
		switch (widget) {
src/misc_gui.cpp
Show inline comments
 
@@ -809,36 +809,39 @@ void QueryString::DrawEditBox(const Wind
 
	}
 

	
 
	_cur_dpi = old_dpi;
 
}
 

	
 
/** Class for the string query window. */
 
struct QueryStringWindow : public QueryStringBaseWindow
 
struct QueryStringWindow : public Window
 
{
 
	QueryString editbox;    ///< Editbox.
 
	QueryStringFlags flags; ///< Flags controlling behaviour of the window.
 

	
 
	QueryStringWindow(StringID str, StringID caption, uint max_bytes, uint max_chars, const WindowDesc *desc, Window *parent, CharSetFilter afilter, QueryStringFlags flags) :
 
			QueryStringBaseWindow(max_bytes, max_chars)
 
			editbox(max_bytes, max_chars)
 
	{
 
		GetString(this->text.buf, str, &this->text.buf[this->text.max_bytes - 1]);
 
		str_validate(this->text.buf, &this->text.buf[this->text.max_bytes - 1], SVS_NONE);
 
		char *last_of = &this->editbox.text.buf[this->editbox.text.max_bytes - 1];
 
		GetString(this->editbox.text.buf, str, last_of);
 
		str_validate(this->editbox.text.buf, last_of, SVS_NONE);
 

	
 
		/* Make sure the name isn't too long for the text buffer in the number of
 
		 * characters (not bytes). max_chars also counts the '\0' characters. */
 
		while (Utf8StringLength(this->text.buf) + 1 > this->text.max_chars) {
 
			*Utf8PrevChar(this->text.buf + strlen(this->text.buf)) = '\0';
 
		while (Utf8StringLength(this->editbox.text.buf) + 1 > this->editbox.text.max_chars) {
 
			*Utf8PrevChar(this->editbox.text.buf + strlen(this->editbox.text.buf)) = '\0';
 
		}
 

	
 
		this->text.UpdateSize();
 
		this->editbox.text.UpdateSize();
 

	
 
		if ((flags & QSF_ACCEPT_UNCHANGED) == 0) this->orig = strdup(this->text.buf);
 
		if ((flags & QSF_ACCEPT_UNCHANGED) == 0) this->editbox.orig = strdup(this->editbox.text.buf);
 

	
 
		this->caption = caption;
 
		this->cancel_button = WID_QS_CANCEL;
 
		this->ok_button = WID_QS_OK;
 
		this->afilter = afilter;
 
		this->querystrings[WID_QS_TEXT] = &this->editbox;
 
		this->editbox.caption = caption;
 
		this->editbox.cancel_button = WID_QS_CANCEL;
 
		this->editbox.ok_button = WID_QS_OK;
 
		this->editbox.afilter = afilter;
 
		this->flags = flags;
 

	
 
		this->InitNested(desc, WN_QUERY_STRING);
 

	
 
		this->parent = parent;
 

	
 
@@ -855,47 +858,47 @@ struct QueryStringWindow : public QueryS
 
			size->width = 0;
 
		}
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		if (widget == WID_QS_CAPTION) SetDParam(0, this->caption);
 
		if (widget == WID_QS_CAPTION) SetDParam(0, this->editbox.caption);
 
	}
 

	
 
	void OnOk()
 
	{
 
		if (this->orig == NULL || strcmp(this->text.buf, this->orig) != 0) {
 
		if (this->editbox.orig == NULL || strcmp(this->editbox.text.buf, this->editbox.orig) != 0) {
 
			/* If the parent is NULL, the editbox is handled by general function
 
			 * HandleOnEditText */
 
			if (this->parent != NULL) {
 
				this->parent->OnQueryTextFinished(this->text.buf);
 
				this->parent->OnQueryTextFinished(this->editbox.text.buf);
 
			} else {
 
				HandleOnEditText(this->text.buf);
 
				HandleOnEditText(this->editbox.text.buf);
 
			}
 
			this->handled = true;
 
			this->editbox.handled = true;
 
		}
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
 
			case WID_QS_DEFAULT:
 
				this->text.buf[0] = '\0';
 
				this->editbox.text.DeleteAll();
 
				/* FALL THROUGH */
 
			case WID_QS_OK:
 
				this->OnOk();
 
				/* FALL THROUGH */
 
			case WID_QS_CANCEL:
 
				delete this;
 
				break;
 
		}
 
	}
 

	
 
	~QueryStringWindow()
 
	{
 
		if (!this->handled && this->parent != NULL) {
 
		if (!this->editbox.handled && this->parent != NULL) {
 
			Window *parent = this->parent;
 
			this->parent = NULL; // so parent doesn't try to delete us again
 
			parent->OnQueryTextFinished(NULL);
 
		}
 
	}
 
};
src/network/network_chat_gui.cpp
Show inline comments
 
@@ -281,30 +281,32 @@ static void SendChat(const char *buf, De
 
	} else {
 
		NetworkServerSendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, CLIENT_ID_SERVER);
 
	}
 
}
 

	
 
/** Window to enter the chat message in. */
 
struct NetworkChatWindow : public QueryStringBaseWindow {
 
struct NetworkChatWindow : public Window {
 
	DestType dtype;       ///< The type of destination.
 
	StringID dest_string; ///< String representation of the destination.
 
	int dest;             ///< The identifier of the destination.
 
	QueryString message_editbox; ///< Message editbox.
 

	
 
	/**
 
	 * Create a chat input window.
 
	 * @param desc Description of the looks of the window.
 
	 * @param type The type of destination.
 
	 * @param dest The actual destination index.
 
	 */
 
	NetworkChatWindow(const WindowDesc *desc, DestType type, int dest) : QueryStringBaseWindow(NETWORK_CHAT_LENGTH)
 
	NetworkChatWindow(const WindowDesc *desc, DestType type, int dest) : message_editbox(NETWORK_CHAT_LENGTH)
 
	{
 
		this->dtype   = type;
 
		this->dest    = dest;
 
		this->cancel_button = WID_NC_CLOSE;
 
		this->ok_button = WID_NC_SENDBUTTON;
 
		this->afilter = CS_ALPHANUMERAL;
 
		this->querystrings[WID_NC_TEXTBOX] = &this->message_editbox;
 
		this->message_editbox.cancel_button = WID_NC_CLOSE;
 
		this->message_editbox.ok_button = WID_NC_SENDBUTTON;
 
		this->message_editbox.afilter = CS_ALPHANUMERAL;
 

	
 
		static const StringID chat_captions[] = {
 
			STR_NETWORK_CHAT_ALL_CAPTION,
 
			STR_NETWORK_CHAT_COMPANY_CAPTION,
 
			STR_NETWORK_CHAT_CLIENT_CAPTION
 
		};
 
@@ -380,15 +382,15 @@ struct NetworkChatWindow : public QueryS
 
	/**
 
	 * See if we can auto-complete the current text of the user.
 
	 */
 
	void ChatTabCompletion()
 
	{
 
		static char _chat_tab_completion_buf[NETWORK_CHAT_LENGTH];
 
		assert(this->text.max_bytes == lengthof(_chat_tab_completion_buf));
 
		assert(this->message_editbox.text.max_bytes == lengthof(_chat_tab_completion_buf));
 

	
 
		Textbuf *tb = &this->text;
 
		Textbuf *tb = &this->message_editbox.text;
 
		size_t len, tb_len;
 
		uint item;
 
		char *tb_buf, *pre_buf;
 
		const char *cur_name;
 
		bool second_scan = false;
 

	
 
@@ -434,26 +436,26 @@ struct NetworkChatWindow : public QueryS
 
				/* Save the data it was before completion */
 
				if (!second_scan) snprintf(_chat_tab_completion_buf, lengthof(_chat_tab_completion_buf), "%s", tb->buf);
 
				_chat_tab_completion_active = true;
 

	
 
				/* Change to the found name. Add ': ' if we are at the start of the line (pretty) */
 
				if (pre_buf == tb_buf) {
 
					this->text.Print("%s: ", cur_name);
 
					this->message_editbox.text.Print("%s: ", cur_name);
 
				} else {
 
					this->text.Print("%s %s", pre_buf, cur_name);
 
					this->message_editbox.text.Print("%s %s", pre_buf, cur_name);
 
				}
 

	
 
				this->SetDirty();
 
				free(pre_buf);
 
				return;
 
			}
 
		}
 

	
 
		if (second_scan) {
 
			/* We walked all posibilities, and the user presses tab again.. revert to original text */
 
			this->text.Assign(_chat_tab_completion_buf);
 
			this->message_editbox.text.Assign(_chat_tab_completion_buf);
 
			_chat_tab_completion_active = false;
 

	
 
			this->SetDirty();
 
		}
 
		free(pre_buf);
 
	}
 
@@ -488,13 +490,13 @@ struct NetworkChatWindow : public QueryS
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
 
			/* Send */
 
			case WID_NC_SENDBUTTON: SendChat(this->text.buf, this->dtype, this->dest);
 
			case WID_NC_SENDBUTTON: SendChat(this->message_editbox.text.buf, this->dtype, this->dest);
 
				/* FALL THROUGH */
 
			case WID_NC_CLOSE: /* Cancel */ delete this; break;
 
		}
 
	}
 

	
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
src/network/network_content_gui.cpp
Show inline comments
 
@@ -273,25 +273,26 @@ public:
 
			this->GetWidget<NWidgetCore>(WID_NCDS_CANCELOK)->widget_data = STR_BUTTON_OK;
 
		}
 
	}
 
};
 

	
 
/** Window that lists the content that's at the content server */
 
class NetworkContentListWindow : public QueryStringBaseWindow, ContentCallback {
 
class NetworkContentListWindow : public Window, ContentCallback {
 
	/** List with content infos. */
 
	typedef GUIList<const ContentInfo *, StringFilter &> GUIContentList;
 

	
 
	static const uint EDITBOX_MAX_SIZE   =  50; ///< Maximum size of the editbox in characters.
 

	
 
	static Listing last_sorting;     ///< The last sorting setting.
 
	static Filtering last_filtering; ///< The last filtering setting.
 
	static GUIContentList::SortFunction * const sorter_funcs[];   ///< Sorter functions
 
	static GUIContentList::FilterFunction * const filter_funcs[]; ///< Filter functions.
 
	GUIContentList content;      ///< List with content
 
	bool auto_select;            ///< Automatically select all content when the meta-data becomes available
 
	StringFilter string_filter;  ///< Filter for content list
 
	QueryString filter_editbox;  ///< Filter editbox;
 

	
 
	const ContentInfo *selected; ///< The selected content info
 
	int list_pos;                ///< Our position in the list
 
	uint filesize_sum;           ///< The sum of all selected file sizes
 
	Scrollbar *vscroll;          ///< Cache of the vertical scrollbar
 

	
 
@@ -402,24 +403,25 @@ public:
 
	/**
 
	 * Create the content list window.
 
	 * @param desc the window description to pass to Window's constructor.
 
	 * @param select_all Whether the select all button is allowed or not.
 
	 */
 
	NetworkContentListWindow(const WindowDesc *desc, bool select_all) :
 
			QueryStringBaseWindow(EDITBOX_MAX_SIZE),
 
			auto_select(select_all),
 
			filter_editbox(EDITBOX_MAX_SIZE),
 
			selected(NULL),
 
			list_pos(0)
 
	{
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(WID_NCL_SCROLLBAR);
 
		this->FinishInitNested(desc, WN_NETWORK_WINDOW_CONTENT_LIST);
 

	
 
		this->GetWidget<NWidgetStacked>(WID_NCL_SEL_ALL_UPDATE)->SetDisplayedPlane(select_all);
 

	
 
		this->afilter = CS_ALPHANUMERAL;
 
		this->querystrings[WID_NCL_FILTER] = &this->filter_editbox;
 
		this->filter_editbox.afilter = CS_ALPHANUMERAL;
 
		this->SetFocusedWidget(WID_NCL_FILTER);
 

	
 
		_network_content_client.AddCallback(this);
 
		this->content.SetListing(this->last_sorting);
 
		this->content.SetFiltering(this->last_filtering);
 
		this->content.SetSortFuncs(this->sorter_funcs);
 
@@ -777,13 +779,13 @@ public:
 
		return ES_HANDLED;
 
	}
 

	
 
	virtual void OnEditboxChanged(int wid)
 
	{
 
		if (wid == WID_NCL_FILTER) {
 
			this->string_filter.SetFilterTerm(this->text.buf);
 
			this->string_filter.SetFilterTerm(this->filter_editbox.text.buf);
 
			this->content.SetFilterState(!this->string_filter.IsEmpty());
 
			this->content.ForceRebuild();
 
			this->InvalidateData();
 
		}
 
	}
 

	
src/network/network_gui.cpp
Show inline comments
 
@@ -206,25 +206,26 @@ public:
 
	{
 
		assert((uint)(widget - WID_NG_NAME) < lengthof(this->visible));
 
		return this->visible[widget - WID_NG_NAME];
 
	}
 
};
 

	
 
class NetworkGameWindow : public QueryStringBaseWindow {
 
class NetworkGameWindow : public Window {
 
protected:
 
	/* Runtime saved values */
 
	static Listing last_sorting;
 

	
 
	/* Constants for sorting servers */
 
	static GUIGameServerList::SortFunction * const sorter_funcs[];
 

	
 
	NetworkGameList *server;      ///< selected server
 
	NetworkGameList *last_joined; ///< the last joined server
 
	GUIGameServerList servers;    ///< list with game servers.
 
	ServerListPosition list_pos;  ///< position of the selected server
 
	Scrollbar *vscroll;
 
	QueryString name_editbox;     ///< Client name editbox.
 

	
 
	/**
 
	 * (Re)build the network game list as its amount has changed because
 
	 * an item has been added or deleted for example
 
	 */
 
	void BuildNetworkGameList()
 
@@ -432,23 +433,24 @@ protected:
 
	{
 
		if (this->list_pos == SLP_INVALID) return; // no server selected
 
		this->vscroll->ScrollTowards(this->list_pos);
 
	}
 

	
 
public:
 
	NetworkGameWindow(const WindowDesc *desc) : QueryStringBaseWindow(NETWORK_CLIENT_NAME_LENGTH)
 
	NetworkGameWindow(const WindowDesc *desc) : name_editbox(NETWORK_CLIENT_NAME_LENGTH)
 
	{
 
		this->list_pos = SLP_INVALID;
 
		this->server = NULL;
 

	
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(WID_NG_SCROLLBAR);
 
		this->FinishInitNested(desc, WN_NETWORK_WINDOW_GAME);
 

	
 
		this->text.Assign(_settings_client.network.client_name);
 
		this->afilter = CS_ALPHANUMERAL;
 
		this->querystrings[WID_NG_CLIENT] = &this->name_editbox;
 
		this->name_editbox.text.Assign(_settings_client.network.client_name);
 
		this->name_editbox.afilter = CS_ALPHANUMERAL;
 
		this->SetFocusedWidget(WID_NG_CLIENT);
 

	
 
		this->last_joined = NetworkGameListAddItem(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port));
 
		this->server = this->last_joined;
 
		if (this->last_joined != NULL) NetworkUDPQueryServer(this->last_joined->address);
 

	
 
@@ -847,14 +849,14 @@ public:
 
	}
 

	
 
	virtual void OnEditboxChanged(int wid)
 
	{
 
		if (wid == WID_NG_CLIENT) {
 
			/* The name is only allowed when it starts with a letter! */
 
			if (!StrEmpty(this->text.buf) && this->text.buf[0] != ' ') {
 
				strecpy(_settings_client.network.client_name, this->text.buf, lastof(_settings_client.network.client_name));
 
			if (!StrEmpty(this->name_editbox.text.buf) && this->name_editbox.text.buf[0] != ' ') {
 
				strecpy(_settings_client.network.client_name, this->name_editbox.text.buf, lastof(_settings_client.network.client_name));
 
			} else {
 
				strecpy(_settings_client.network.client_name, "Player", lastof(_settings_client.network.client_name));
 
			}
 
		}
 
	}
 

	
 
@@ -995,22 +997,24 @@ void ShowNetworkGameWindow()
 
		}
 
	}
 

	
 
	new NetworkGameWindow(&_network_game_window_desc);
 
}
 

	
 
struct NetworkStartServerWindow : public QueryStringBaseWindow {
 
struct NetworkStartServerWindow : public Window {
 
	byte widget_id;              ///< The widget that has the pop-up input menu
 
	QueryString name_editbox;    ///< Server name editbox.
 

	
 
	NetworkStartServerWindow(const WindowDesc *desc) : QueryStringBaseWindow(NETWORK_NAME_LENGTH)
 
	NetworkStartServerWindow(const WindowDesc *desc) : name_editbox(NETWORK_NAME_LENGTH)
 
	{
 
		this->InitNested(desc, WN_NETWORK_WINDOW_START);
 

	
 
		this->text.Assign(_settings_client.network.server_name);
 
		this->querystrings[WID_NSS_GAMENAME] = &this->name_editbox;
 
		this->name_editbox.text.Assign(_settings_client.network.server_name);
 

	
 
		this->afilter = CS_ALPHANUMERAL;
 
		this->name_editbox.afilter = CS_ALPHANUMERAL;
 
		this->SetFocusedWidget(WID_NSS_GAMENAME);
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		switch (widget) {
 
@@ -1168,13 +1172,13 @@ struct NetworkStartServerWindow : public
 
		this->SetDirty();
 
	}
 

	
 
	virtual void OnEditboxChanged(int wid)
 
	{
 
		if (wid == WID_NSS_GAMENAME) {
 
			strecpy(_settings_client.network.server_name, this->text.buf, lastof(_settings_client.network.server_name));
 
			strecpy(_settings_client.network.server_name, this->name_editbox.text.buf, lastof(_settings_client.network.server_name));
 
		}
 
	}
 

	
 
	virtual void OnTimeout()
 
	{
 
		static const int raise_widgets[] = {WID_NSS_CLIENTS_BTND, WID_NSS_CLIENTS_BTNU, WID_NSS_COMPANIES_BTND, WID_NSS_COMPANIES_BTNU, WID_NSS_SPECTATORS_BTND, WID_NSS_SPECTATORS_BTNU, WIDGET_LIST_END};
 
@@ -2098,31 +2102,34 @@ void ShowNetworkNeedPassword(NetworkPass
 
		case NETWORK_GAME_PASSWORD:    caption = STR_NETWORK_NEED_GAME_PASSWORD_CAPTION; break;
 
		case NETWORK_COMPANY_PASSWORD: caption = STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION; break;
 
	}
 
	ShowQueryString(STR_EMPTY, caption, NETWORK_PASSWORD_LENGTH, w, CS_ALPHANUMERAL, QSF_NONE);
 
}
 

	
 
struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow {
 
	NetworkCompanyPasswordWindow(const WindowDesc *desc, Window *parent) : QueryStringBaseWindow(lengthof(_settings_client.network.default_company_pass))
 
struct NetworkCompanyPasswordWindow : public Window {
 
	QueryString password_editbox; ///< Password editbox.
 

	
 
	NetworkCompanyPasswordWindow(const WindowDesc *desc, Window *parent) : password_editbox(lengthof(_settings_client.network.default_company_pass))
 
	{
 
		this->InitNested(desc, 0);
 

	
 
		this->parent = parent;
 
		this->cancel_button = WID_NCP_CANCEL;
 
		this->ok_button = WID_NCP_OK;
 
		this->afilter = CS_ALPHANUMERAL;
 
		this->querystrings[WID_NCP_PASSWORD] = &this->password_editbox;
 
		this->password_editbox.cancel_button = WID_NCP_CANCEL;
 
		this->password_editbox.ok_button = WID_NCP_OK;
 
		this->password_editbox.afilter = CS_ALPHANUMERAL;
 
		this->SetFocusedWidget(WID_NCP_PASSWORD);
 
	}
 

	
 
	void OnOk()
 
	{
 
		if (this->IsWidgetLowered(WID_NCP_SAVE_AS_DEFAULT_PASSWORD)) {
 
			strecpy(_settings_client.network.default_company_pass, this->text.buf, lastof(_settings_client.network.default_company_pass));
 
			strecpy(_settings_client.network.default_company_pass, this->password_editbox.text.buf, lastof(_settings_client.network.default_company_pass));
 
		}
 

	
 
		NetworkChangeCompanyPassword(_local_company, this->text.buf);
 
		NetworkChangeCompanyPassword(_local_company, this->password_editbox.text.buf);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
 
			case WID_NCP_OK:
src/newgrf_gui.cpp
Show inline comments
 
@@ -582,13 +582,13 @@ public:
 

	
 
static void NewGRFConfirmationCallback(Window *w, bool confirmed);
 

	
 
/**
 
 * Window for showing NewGRF files
 
 */
 
struct NewGRFWindow : public QueryStringBaseWindow, NewGRFScanCallback {
 
struct NewGRFWindow : public Window, NewGRFScanCallback {
 
	typedef GUIList<const GRFConfig *, StringFilter &> GUIGRFConfigList;
 

	
 
	static const uint EDITBOX_MAX_SIZE   =  50;
 

	
 
	static Listing   last_sorting;   ///< Default sorting of #GUIGRFConfigList.
 
	static Filtering last_filtering; ///< Default filtering of #GUIGRFConfigList.
 
@@ -596,12 +596,13 @@ struct NewGRFWindow : public QueryString
 
	static GUIGRFConfigList::FilterFunction * const filter_funcs[]; ///< Filter functions of the #GUIGRFConfigList.
 

	
 
	GUIGRFConfigList avails;    ///< Available (non-active) grfs.
 
	const GRFConfig *avail_sel; ///< Currently selected available grf. \c NULL is none is selected.
 
	int avail_pos;              ///< Index of #avail_sel if existing, else \c -1.
 
	StringFilter string_filter; ///< Filter for available grf.
 
	QueryString filter_editbox; ///< Filter editbox;
 

	
 
	GRFConfig *actives;         ///< Temporary active grf list to which changes are made.
 
	GRFConfig *active_sel;      ///< Selected active grf item.
 

	
 
	GRFConfig **orig_list;      ///< List active grfs in the game. Used as initial value, may be updated by the window.
 
	bool editable;              ///< Is the window editable?
 
@@ -610,13 +611,13 @@ struct NewGRFWindow : public QueryString
 
	int preset;                 ///< Selected preset.
 
	int active_over;            ///< Active GRF item over which another one is dragged, \c -1 if none.
 

	
 
	Scrollbar *vscroll;
 
	Scrollbar *vscroll2;
 

	
 
	NewGRFWindow(const WindowDesc *desc, bool editable, bool show_params, bool execute, GRFConfig **orig_list) : QueryStringBaseWindow(EDITBOX_MAX_SIZE)
 
	NewGRFWindow(const WindowDesc *desc, bool editable, bool show_params, bool execute, GRFConfig **orig_list) : filter_editbox(EDITBOX_MAX_SIZE)
 
	{
 
		this->avail_sel   = NULL;
 
		this->avail_pos   = -1;
 
		this->active_sel  = NULL;
 
		this->actives     = NULL;
 
		this->orig_list   = orig_list;
 
@@ -634,12 +635,13 @@ struct NewGRFWindow : public QueryString
 
		this->vscroll2 = this->GetScrollbar(WID_NS_SCROLL2BAR);
 

	
 
		this->GetWidget<NWidgetStacked>(WID_NS_SHOW_REMOVE)->SetDisplayedPlane(this->editable ? 0 : 1);
 
		this->GetWidget<NWidgetStacked>(WID_NS_SHOW_APPLY)->SetDisplayedPlane(this->editable ? 0 : this->show_params ? 1 : SZSP_HORIZONTAL);
 
		this->FinishInitNested(desc, WN_GAME_OPTIONS_NEWGRF_STATE);
 

	
 
		this->querystrings[WID_NS_FILTER] = &this->filter_editbox;
 
		this->SetFocusedWidget(WID_NS_FILTER);
 

	
 
		this->avails.SetListing(this->last_sorting);
 
		this->avails.SetFiltering(this->last_filtering);
 
		this->avails.SetSortFuncs(this->sorter_funcs);
 
		this->avails.SetFilterFuncs(this->filter_funcs);
 
@@ -1276,13 +1278,13 @@ struct NewGRFWindow : public QueryString
 
	}
 

	
 
	virtual void OnEditboxChanged(int wid)
 
	{
 
		if (!this->editable) return;
 

	
 
		string_filter.SetFilterTerm(this->text.buf);
 
		string_filter.SetFilterTerm(this->filter_editbox.text.buf);
 
		this->avails.SetFilterState(!string_filter.IsEmpty());
 
		this->avails.ForceRebuild();
 
		this->InvalidateData(0);
 
	}
 

	
 
	virtual void OnDragDrop(Point pt, int widget)
src/osk_gui.cpp
Show inline comments
 
@@ -37,24 +37,25 @@ struct OskWindow : public Window {
 
	QueryString *qs;       ///< text-input
 
	int text_btn;          ///< widget number of parent's text field
 
	Textbuf *text;         ///< pointer to parent's textbuffer (to update caret position)
 
	char *orig_str_buf;    ///< Original string.
 
	bool shift;            ///< Is the shift effectively pressed?
 

	
 
	OskWindow(const WindowDesc *desc, QueryStringBaseWindow *parent, int button) : Window()
 
	OskWindow(const WindowDesc *desc, Window *parent, int button) : Window()
 
	{
 
		this->parent = parent;
 
		assert(parent != NULL);
 

	
 
		NWidgetCore *par_wid = parent->GetWidget<NWidgetCore>(button);
 
		assert(par_wid != NULL);
 
		this->caption = (par_wid->widget_data != STR_NULL) ? par_wid->widget_data : parent->caption;
 

	
 
		this->qs         = parent;
 
		assert(parent->querystrings.Contains(button));
 
		this->qs         = parent->querystrings.Find(button)->second;
 
		this->caption = (par_wid->widget_data != STR_NULL) ? par_wid->widget_data : this->qs->caption;
 
		this->text_btn   = button;
 
		this->text       = &parent->text;
 
		this->text       = &this->qs->text;
 

	
 
		/* make a copy in case we need to reset later */
 
		this->orig_str_buf = strdup(this->qs->text.buf);
 

	
 
		this->InitNested(desc, 0);
 

	
 
@@ -420,13 +421,13 @@ void GetKeyboardLayout()
 

	
 
/**
 
 * Show the on-screen keyboard (osk) associated with a given textbox
 
 * @param parent pointer to the Window where this keyboard originated from
 
 * @param button widget number of parent's textbox
 
 */
 
void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button)
 
void ShowOnScreenKeyboard(Window *parent, int button)
 
{
 
	DeleteWindowById(WC_OSK, 0);
 

	
 
	GetKeyboardLayout();
 
	new OskWindow(&_osk_desc, parent, button);
 
}
 
@@ -435,16 +436,16 @@ void ShowOnScreenKeyboard(QueryStringBas
 
 * Updates the original text of the OSK so when the 'parent' changes the
 
 * original and you press on cancel you won't get the 'old' original text
 
 * but the updated one.
 
 * @param parent window that just updated its orignal text
 
 * @param button widget number of parent's textbox to update
 
 */
 
void UpdateOSKOriginalText(const QueryStringBaseWindow *parent, int button)
 
void UpdateOSKOriginalText(const Window *parent, int button)
 
{
 
	OskWindow *osk = dynamic_cast<OskWindow *>(FindWindowById(WC_OSK, 0));
 
	if (osk == NULL || osk->qs != parent || osk->text_btn != button) return;
 
	if (osk == NULL || osk->parent != parent || osk->text_btn != button) return;
 

	
 
	free(osk->orig_str_buf);
 
	osk->orig_str_buf = strdup(osk->qs->text.buf);
 

	
 
	osk->SetDirty();
 
}
src/querystring_gui.h
Show inline comments
 
@@ -61,17 +61,10 @@ private:
 
public:
 
	void DrawEditBox(const Window *w, int wid) const;
 
	void HandleEditBox(Window *w, int wid);
 
	HandleEditBoxResult HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, EventState &state);
 
};
 

	
 
struct QueryStringBaseWindow : public Window, public QueryString {
 
	QueryStringBaseWindow(uint16 size, uint16 chars = UINT16_MAX) : Window(), QueryString(size, chars)
 
	{
 
	}
 

	
 
};
 

	
 
void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button);
 
void UpdateOSKOriginalText(const QueryStringBaseWindow *parent, int button);
 
void ShowOnScreenKeyboard(Window *parent, int button);
 
void UpdateOSKOriginalText(const Window *parent, int button);
 

	
 
#endif /* QUERYSTRING_GUI_H */
src/settings_gui.cpp
Show inline comments
 
@@ -1953,13 +1953,13 @@ static const StringID _game_settings_res
 
	STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_DEFAULT,          // RM_CHANGED_AGAINST_DEFAULT
 
	STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_DEFAULT_WO_LOCAL, // RM_CHANGED_AGAINST_DEFAULT_WO_LOCAL
 
	STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_NEW,              // RM_CHANGED_AGAINST_NEW
 
};
 
assert_compile(lengthof(_game_settings_restrict_dropdown) == RM_END);
 

	
 
struct GameSettingsWindow : QueryStringBaseWindow {
 
struct GameSettingsWindow : Window {
 
	static const int SETTINGTREE_LEFT_OFFSET   = 5; ///< Position of left edge of setting values
 
	static const int SETTINGTREE_RIGHT_OFFSET  = 5; ///< Position of right edge of setting values
 
	static const int SETTINGTREE_TOP_OFFSET    = 5; ///< Position of top edge of setting values
 
	static const int SETTINGTREE_BOTTOM_OFFSET = 5; ///< Position of bottom edge of setting values
 

	
 
	static GameSettings *settings_ptr; ///< Pointer to the game settings being displayed and modified.
 
@@ -1968,19 +1968,20 @@ struct GameSettingsWindow : QueryStringB
 
	SettingEntry *clicked_entry;       ///< If non-NULL, pointer to a clicked numeric setting (with a depressed left or right button).
 
	SettingEntry *last_clicked;        ///< If non-NULL, pointer to the last clicked setting.
 
	SettingEntry *valuedropdown_entry; ///< If non-NULL, pointer to the value for which a dropdown window is currently opened.
 
	bool closing_dropdown;             ///< True, if the dropdown list is currently closing.
 

	
 
	StringFilter string_filter;        ///< Text filter for settings.
 
	QueryString filter_editbox;        ///< Filter editbox;
 
	bool manually_changed_folding;     ///< Whether the user expanded/collapsed something manually.
 

	
 
	RestrictionMode cur_restriction_mode; ///< Currently selected index of the drop down list for the restrict drop down.
 

	
 
	Scrollbar *vscroll;
 

	
 
	GameSettingsWindow(const WindowDesc *desc) : QueryStringBaseWindow(50), cur_restriction_mode((RestrictionMode)_settings_client.gui.settings_restriction_mode)
 
	GameSettingsWindow(const WindowDesc *desc) : filter_editbox(50), cur_restriction_mode((RestrictionMode)_settings_client.gui.settings_restriction_mode)
 
	{
 
		static bool first_time = true;
 

	
 
		settings_ptr = &GetGameSettings();
 

	
 
		/* Build up the dynamic settings-array only once per OpenTTD session */
 
@@ -1999,12 +2000,13 @@ struct GameSettingsWindow : QueryStringB
 
		this->manually_changed_folding = false;
 

	
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(WID_GS_SCROLLBAR);
 
		this->FinishInitNested(desc, WN_GAME_OPTIONS_GAME_SETTINGS);
 

	
 
		this->querystrings[WID_GS_FILTER] = &this->filter_editbox;
 
		this->SetFocusedWidget(WID_GS_FILTER);
 

	
 
		this->InvalidateData();
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
@@ -2405,13 +2407,13 @@ struct GameSettingsWindow : QueryStringB
 
		this->SetWidgetDisabledState(WID_GS_COLLAPSE_ALL, all_folded);
 
	}
 

	
 
	virtual void OnEditboxChanged(int wid)
 
	{
 
		if (wid == WID_GS_FILTER) {
 
			string_filter.SetFilterTerm(this->text.buf);
 
			string_filter.SetFilterTerm(this->filter_editbox.text.buf);
 
			if (!string_filter.IsEmpty() && !this->manually_changed_folding) {
 
				/* User never expanded/collapsed single pages and entered a filter term.
 
				 * Expand everything, to save weird expand clicks, */
 
				_settings_main_page.UnFoldAll();
 
			}
 
			this->InvalidateData();
src/signs_gui.cpp
Show inline comments
 
@@ -141,27 +141,29 @@ bool SignList::match_case = false;
 

	
 
/** Enum referring to the Hotkeys in the sign list window */
 
enum SignListHotkeys {
 
	SLHK_FOCUS_FILTER_BOX, ///< Focus the edit box for editing the filter string
 
};
 

	
 
struct SignListWindow : QueryStringBaseWindow, SignList {
 
struct SignListWindow : Window, SignList {
 
	QueryString filter_editbox; ///< Filter editbox;
 
	int text_offset; ///< Offset of the sign text relative to the left edge of the WID_SIL_LIST widget.
 
	Scrollbar *vscroll;
 

	
 
	SignListWindow(const WindowDesc *desc, WindowNumber window_number) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
 
	SignListWindow(const WindowDesc *desc, WindowNumber window_number) : filter_editbox(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
 
	{
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(WID_SIL_SCROLLBAR);
 
		this->FinishInitNested(desc, window_number);
 
		this->SetWidgetLoweredState(WID_SIL_FILTER_MATCH_CASE_BTN, SignList::match_case);
 

	
 
		/* Initialize the text edit widget */
 
		this->ok_button = WID_SIL_FILTER_ENTER_BTN;
 
		this->cancel_button = WID_SIL_FILTER_CLEAR_BTN;
 
		this->afilter = CS_ALPHANUMERAL;
 
		this->querystrings[WID_SIL_FILTER_TEXT] = &this->filter_editbox;
 
		this->filter_editbox.ok_button = WID_SIL_FILTER_ENTER_BTN;
 
		this->filter_editbox.cancel_button = WID_SIL_FILTER_CLEAR_BTN;
 
		this->filter_editbox.afilter = CS_ALPHANUMERAL;
 

	
 
		/* Initialize the filtering variables */
 
		this->SetFilterString("");
 

	
 
		/* Create initial list. */
 
		this->signs.ForceRebuild();
 
@@ -172,13 +174,13 @@ struct SignListWindow : QueryStringBaseW
 
	/**
 
	 * Empties the string buffer that is edited by the filter text edit widget.
 
	 * It also triggers the redraw of the widget so it become visible that the string has been made empty.
 
	 */
 
	void ClearFilterTextWidget()
 
	{
 
		this->text.DeleteAll();
 
		this->filter_editbox.text.DeleteAll();
 

	
 
		this->SetWidgetDirty(WID_SIL_FILTER_TEXT);
 
	}
 

	
 
	/**
 
	 * This function sets the filter string of the sign list. The contents of
 
@@ -311,13 +313,13 @@ struct SignListWindow : QueryStringBaseW
 

	
 
		return state;
 
	}
 

	
 
	virtual void OnEditboxChanged(int widget)
 
	{
 
		if (widget == WID_SIL_FILTER_TEXT) this->SetFilterString(this->text.buf);
 
		if (widget == WID_SIL_FILTER_TEXT) this->SetFilterString(this->filter_editbox.text.buf);
 
	}
 

	
 
	void BuildSortSignList()
 
	{
 
		if (this->signs.NeedRebuild()) {
 
			this->BuildSignsList();
 
@@ -425,21 +427,23 @@ static bool RenameSign(SignID index, con
 
{
 
	bool remove = StrEmpty(text);
 
	DoCommandP(0, index, 0, CMD_RENAME_SIGN | (StrEmpty(text) ? CMD_MSG(STR_ERROR_CAN_T_DELETE_SIGN) : CMD_MSG(STR_ERROR_CAN_T_CHANGE_SIGN_NAME)), NULL, text);
 
	return remove;
 
}
 

	
 
struct SignWindow : QueryStringBaseWindow, SignList {
 
struct SignWindow : Window, SignList {
 
	QueryString name_editbox;
 
	SignID cur_sign;
 

	
 
	SignWindow(const WindowDesc *desc, const Sign *si) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
 
	SignWindow(const WindowDesc *desc, const Sign *si) : name_editbox(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
 
	{
 
		this->caption = STR_EDIT_SIGN_CAPTION;
 
		this->cancel_button = WID_QES_CANCEL;
 
		this->ok_button = WID_QES_OK;
 
		this->afilter = CS_ALPHANUMERAL;
 
		this->querystrings[WID_QES_TEXT] = &this->name_editbox;
 
		this->name_editbox.caption = STR_EDIT_SIGN_CAPTION;
 
		this->name_editbox.cancel_button = WID_QES_CANCEL;
 
		this->name_editbox.ok_button = WID_QES_OK;
 
		this->name_editbox.afilter = CS_ALPHANUMERAL;
 

	
 
		this->InitNested(desc, WN_QUERY_STRING_SIGN);
 

	
 
		this->LowerWidget(WID_QES_TEXT);
 
		UpdateSignEditWindow(si);
 
		this->SetFocusedWidget(WID_QES_TEXT);
 
@@ -447,15 +451,15 @@ struct SignWindow : QueryStringBaseWindo
 

	
 
	void UpdateSignEditWindow(const Sign *si)
 
	{
 
		/* Display an empty string when the sign hasnt been edited yet */
 
		if (si->name != NULL) {
 
			SetDParam(0, si->index);
 
			this->text.Assign(STR_SIGN_NAME);
 
			this->name_editbox.text.Assign(STR_SIGN_NAME);
 
		} else {
 
			this->text.DeleteAll();
 
			this->name_editbox.text.DeleteAll();
 
		}
 

	
 
		this->cur_sign = si->index;
 

	
 
		this->SetWidgetDirty(WID_QES_TEXT);
 
		this->SetFocusedWidget(WID_QES_TEXT);
 
@@ -489,13 +493,13 @@ struct SignWindow : QueryStringBaseWindo
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		switch (widget) {
 
			case WID_QES_CAPTION:
 
				SetDParam(0, this->caption);
 
				SetDParam(0, this->name_editbox.caption);
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
@@ -520,13 +524,13 @@ struct SignWindow : QueryStringBaseWindo
 
				/* Only need to set the buffer to null, the rest is handled as the OK button */
 
				RenameSign(this->cur_sign, "");
 
				/* don't delete this, we are deleted in Sign::~Sign() -> DeleteRenameSignWindow() */
 
				break;
 

	
 
			case WID_QES_OK:
 
				if (RenameSign(this->cur_sign, this->text.buf)) break;
 
				if (RenameSign(this->cur_sign, this->name_editbox.text.buf)) break;
 
				/* FALL THROUGH */
 

	
 
			case WID_QES_CANCEL:
 
				delete this;
 
				break;
 
		}
src/town_gui.cpp
Show inline comments
 
@@ -975,42 +975,44 @@ static const NWidgetPart _nested_found_t
 
										SetDataTip(STR_FOUND_TOWN_SELECT_LAYOUT_RANDOM, STR_FOUND_TOWN_SELECT_TOWN_ROAD_LAYOUT), SetFill(1, 0),
 
		NWidget(NWID_SPACER), SetMinimalSize(0, 2),
 
	EndContainer(),
 
};
 

	
 
/** Found a town window class. */
 
struct FoundTownWindow : QueryStringBaseWindow {
 
struct FoundTownWindow : Window {
 
private:
 
	TownSize town_size;     ///< Selected town size
 
	TownLayout town_layout; ///< Selected town layout
 
	bool city;              ///< Are we building a city?
 
	QueryString townname_editbox; ///< Townname editbox
 
	bool townnamevalid;     ///< Is generated town name valid?
 
	uint32 townnameparts;   ///< Generated town name
 
	TownNameParams params;  ///< Town name parameters
 

	
 
public:
 
	FoundTownWindow(const WindowDesc *desc, WindowNumber window_number) :
 
			QueryStringBaseWindow(MAX_LENGTH_TOWN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_TOWN_NAME_CHARS),
 
			town_size(TSZ_MEDIUM),
 
			town_layout(_settings_game.economy.town_layout),
 
			townname_editbox(MAX_LENGTH_TOWN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_TOWN_NAME_CHARS),
 
			params(_settings_game.game_creation.town_name)
 
	{
 
		this->InitNested(desc, window_number);
 
		this->querystrings[WID_TF_TOWN_NAME_EDITBOX] = &this->townname_editbox;
 
		this->RandomTownName();
 
		this->UpdateButtons(true);
 
	}
 

	
 
	void RandomTownName()
 
	{
 
		this->townnamevalid = GenerateTownName(&this->townnameparts);
 

	
 
		if (!this->townnamevalid) {
 
			this->text.DeleteAll();
 
			this->townname_editbox.text.DeleteAll();
 
		} else {
 
			GetTownName(this->text.buf, &this->params, this->townnameparts, &this->text.buf[this->text.max_bytes - 1]);
 
			this->text.UpdateSize();
 
			GetTownName(this->townname_editbox.text.buf, &this->params, this->townnameparts, &this->townname_editbox.text.buf[this->townname_editbox.text.max_bytes - 1]);
 
			this->townname_editbox.text.UpdateSize();
 
		}
 
		UpdateOSKOriginalText(this, WID_TF_TOWN_NAME_EDITBOX);
 

	
 
		this->SetWidgetDirty(WID_TF_TOWN_NAME_EDITBOX);
 
	}
 

	
 
@@ -1038,18 +1040,18 @@ public:
 

	
 
	void ExecuteFoundTownCommand(TileIndex tile, bool random, StringID errstr, CommandCallback cc)
 
	{
 
		const char *name = NULL;
 

	
 
		if (!this->townnamevalid) {
 
			name = this->text.buf;
 
			name = this->townname_editbox.text.buf;
 
		} else {
 
			/* If user changed the name, send it */
 
			char buf[MAX_LENGTH_TOWN_NAME_CHARS * MAX_CHAR_LENGTH];
 
			GetTownName(buf, &this->params, this->townnameparts, lastof(buf));
 
			if (strcmp(buf, this->text.buf) != 0) name = this->text.buf;
 
			if (strcmp(buf, this->townname_editbox.text.buf) != 0) name = this->townname_editbox.text.buf;
 
		}
 

	
 
		bool success = DoCommandP(tile, this->town_size | this->city << 2 | this->town_layout << 3 | random << 6,
 
				townnameparts, CMD_FOUND_TOWN | CMD_MSG(errstr), cc, name);
 

	
 
		if (success) this->RandomTownName();
src/widget.cpp
Show inline comments
 
@@ -2364,13 +2364,13 @@ void NWidgetLeaf::Draw(const Window *w)
 
		case WWT_MATRIX:
 
			DrawMatrix(r, this->colour, clicked, this->widget_data);
 
			break;
 

	
 
		case WWT_EDITBOX: {
 
			DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, FR_LOWERED | FR_DARKENED);
 
			const QueryString *query = dynamic_cast<const QueryString*>(w);
 
			const QueryString *query = w->GetQueryString(this->index);
 
			if (query != NULL) query->DrawEditBox(w, this->index);
 
			break;
 
		}
 

	
 
		case WWT_CAPTION:
 
			if (this->index >= 0) w->SetStringParameters(this->index);
src/window.cpp
Show inline comments
 
@@ -224,12 +224,34 @@ const Scrollbar *Window::GetScrollbar(ui
 
 */
 
Scrollbar *Window::GetScrollbar(uint widnum)
 
{
 
	return this->GetWidget<NWidgetScrollbar>(widnum);
 
}
 

	
 
/**
 
 * Return the querystring associated to a editbox.
 
 * @param widnum Editbox widget index
 
 * @return QueryString or NULL.
 
 */
 
const QueryString *Window::GetQueryString(uint widnum) const
 
{
 
	const SmallMap<int, QueryString*>::Pair *query = this->querystrings.Find(widnum);
 
	return query != this->querystrings.End() ? query->second : NULL;
 
}
 

	
 
/**
 
 * Return the querystring associated to a editbox.
 
 * @param widnum Editbox widget index
 
 * @return QueryString or NULL.
 
 */
 
QueryString *Window::GetQueryString(uint widnum)
 
{
 
	SmallMap<int, QueryString*>::Pair *query = this->querystrings.Find(widnum);
 
	return query != this->querystrings.End() ? query->second : NULL;
 
}
 

	
 

	
 
/**
 
 * Set the window that has the focus
 
 * @param w The window to set the focus on
 
 */
 
void SetFocusedWindow(Window *w)
 
@@ -447,15 +469,14 @@ static void DispatchLeftClickEvent(Windo
 
			ScrollbarClickHandler(w, nw, x, y);
 
			break;
 

	
 
		case WWT_EDITBOX:
 
			if (!focused_widget_changed) { // Only open the OSK window if clicking on an already focused edit box
 
				/* Open the OSK window if clicked on an edit box */
 
				QueryStringBaseWindow *qs = dynamic_cast<QueryStringBaseWindow *>(w);
 
				if (qs != NULL) {
 
					ShowOnScreenKeyboard(qs, widget_index);
 
				if (w->querystrings.Contains(widget_index)) {
 
					ShowOnScreenKeyboard(w, widget_index);
 
				}
 
			}
 
			break;
 

	
 
		case WWT_CLOSEBOX: // 'X'
 
			delete w;
 
@@ -1619,18 +1640,14 @@ static void DecreaseWindowCounters()
 
					}
 
				}
 
			}
 
		}
 

	
 
		/* Handle editboxes */
 
		for (uint i = 0; i < w->nested_array_size; i++) {
 
			NWidgetBase *nwid = w->nested_array[i];
 
			if (nwid != NULL && nwid->type == WWT_EDITBOX) {
 
				QueryString *query = dynamic_cast<QueryString*>(w);
 
				if (query != NULL) query->HandleEditBox(w, i);
 
			}
 
		for (SmallMap<int, QueryString*>::Pair *it = w->querystrings.Begin(); it != w->querystrings.End(); ++it) {
 
			it->second->HandleEditBox(w, it->first);
 
		}
 

	
 
		w->OnMouseLoop();
 
	}
 

	
 
	FOR_ALL_WINDOWS_FROM_FRONT(w) {
 
@@ -2242,13 +2259,13 @@ static bool MaybeBringWindowToFront(Wind
 
 *         window should receive the event.
 
 */
 
EventState Window::HandleEditBoxKey(int wid, uint16 key, uint16 keycode)
 
{
 
	EventState state = ES_NOT_HANDLED;
 

	
 
	QueryString *query = dynamic_cast<QueryString*>(this);
 
	QueryString *query = this->GetQueryString(wid);
 
	if (query == NULL) return state;
 

	
 
	switch (query->HandleEditBoxKey(this, wid, key, keycode, state)) {
 
		case HEBR_EDITING:
 
			this->OnEditboxChanged(wid);
 
			break;
src/window_gui.h
Show inline comments
 
@@ -15,12 +15,13 @@
 
#include "vehicle_type.h"
 
#include "viewport_type.h"
 
#include "company_type.h"
 
#include "tile_type.h"
 
#include "widget_type.h"
 
#include "core/smallvec_type.hpp"
 
#include "core/smallmap_type.hpp"
 

	
 
/** State of handling an event. */
 
enum EventState {
 
	ES_HANDLED,     ///< The passed event is handled.
 
	ES_NOT_HANDLED, ///< The passed event is not handled.
 
};
 
@@ -237,12 +238,14 @@ struct ViewportData : ViewPort {
 
	int32 scrollpos_x;        ///< Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
 
	int32 scrollpos_y;        ///< Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
 
	int32 dest_scrollpos_x;   ///< Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewport).
 
	int32 dest_scrollpos_y;   ///< Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewport).
 
};
 

	
 
struct QueryString;
 

	
 
/**
 
 * Data structure for an opened window
 
 */
 
struct Window : ZeroedMemoryAllocator {
 
protected:
 
	void InitializeData(const WindowDesc *desc, WindowNumber window_number);
 
@@ -292,12 +295,13 @@ public:
 

	
 
	Owner owner;        ///< The owner of the content shown in this window. Company colour is acquired from this variable.
 

	
 
	ViewportData *viewport;          ///< Pointer to viewport data, if present.
 
	uint32 desc_flags;               ///< Window/widgets default flags setting. @see WindowDefaultFlag
 
	const NWidgetCore *nested_focus; ///< Currently focused nested widget, or \c NULL if no nested widget has focus.
 
	SmallMap<int, QueryString*> querystrings; ///< QueryString associated to WWT_EDITBOX widgets.
 
	NWidgetBase *nested_root;        ///< Root of the nested tree.
 
	NWidgetBase **nested_array;      ///< Array of pointers into the tree. Do not access directly, use #Window::GetWidget() instead.
 
	uint nested_array_size;          ///< Size of the nested array.
 
	NWidgetStacked *shade_select;    ///< Selection widget (#NWID_SELECTION) to use for shading the window. If \c NULL, window cannot shade.
 
	Dimension unshaded_size;         ///< Last known unshaded size (only valid while shaded).
 

	
 
@@ -312,12 +316,15 @@ public:
 
	template <class NWID>
 
	inline NWID *GetWidget(uint widnum);
 

	
 
	const Scrollbar *GetScrollbar(uint widnum) const;
 
	Scrollbar *GetScrollbar(uint widnum);
 

	
 
	const QueryString *GetQueryString(uint widnum) const;
 
	QueryString *GetQueryString(uint widnum);
 

	
 
	void InitNested(const WindowDesc *desc, WindowNumber number = 0);
 
	void CreateNestedTree(const WindowDesc *desc, bool fill_nested = true);
 
	void FinishInitNested(const WindowDesc *desc, WindowNumber window_number = 0);
 

	
 
	/**
 
	 * Set the timeout flag of the window and initiate the timer.
0 comments (0 inline, 0 general)