Changeset - r19777:9fe4698602ed
[Not reviewed]
master
0 10 0
frosch - 12 years ago 2012-11-13 21:46:58
frosch@openttd.org
(svn r24732) -Codechange: Unify handling of OK and CANCEL actions for editboxes.
10 files changed with 65 insertions and 101 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_gui.cpp
Show inline comments
 
@@ -1337,35 +1337,24 @@ struct AIDebugWindow : public QueryStrin
 
		}
 
	}
 

	
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		EventState state = ES_NOT_HANDLED;
 
		switch (this->HandleEditBoxKey(WID_AID_BREAK_STR_EDIT_BOX, key, keycode, state)) {
 
			case HEBR_CANCEL:
 
				/* Unfocus the text box. */
 
				this->UnfocusFocusedWidget();
 
				break;
 

	
 
			case HEBR_NOT_FOCUSED: {
 
				/* Edit boxs is not globally foused => handle hotkeys of AI Debug window. */
 
				int num = CheckHotkeyMatch(aidebug_hotkeys, keycode, this);
 
				if (num == -1) return ES_NOT_HANDLED;
 
				if (this->show_break_box && num == WID_AID_BREAK_STR_EDIT_BOX) {
 
					this->SetFocusedWidget(WID_AID_BREAK_STR_EDIT_BOX);
 
					SetFocusedWindow(this);
 
					state = ES_HANDLED;
 
				} else if (this->show_break_box || num < WID_AID_BREAK_STRING_WIDGETS) {
 
					this->OnClick(Point(), num, 1);
 
					state = ES_HANDLED;
 
				}
 
				break;
 
		if (this->HandleEditBoxKey(WID_AID_BREAK_STR_EDIT_BOX, key, keycode, state) == HEBR_NOT_FOCUSED) {
 
			/* Edit boxs is not globally foused => handle hotkeys of AI Debug window. */
 
			int num = CheckHotkeyMatch(aidebug_hotkeys, keycode, this);
 
			if (num == -1) return ES_NOT_HANDLED;
 
			if (this->show_break_box && num == WID_AID_BREAK_STR_EDIT_BOX) {
 
				this->SetFocusedWidget(WID_AID_BREAK_STR_EDIT_BOX);
 
				SetFocusedWindow(this);
 
				state = ES_HANDLED;
 
			} else if (this->show_break_box || num < WID_AID_BREAK_STRING_WIDGETS) {
 
				this->OnClick(Point(), num, 1);
 
				state = ES_HANDLED;
 
			}
 

	
 
			default:
 
				break;
 
		}
 
		return state;
 
	}
 

	
 
	virtual void OnOSKInput(int wid)
 
	{
src/fios_gui.cpp
Show inline comments
 
@@ -259,12 +259,13 @@ public:
 
			case SLD_SAVE_GAME:     this->GenerateFileName(); break;
 
			case SLD_SAVE_HEIGHTMAP:
 
			case SLD_SAVE_SCENARIO: strecpy(this->edit_str_buf, "UNNAMED", &this->edit_str_buf[edit_str_size - 1]); break;
 
			default:                break;
 
		}
 

	
 
		this->ok_button = WID_SL_SAVE_GAME;
 
		this->afilter = CS_ALPHANUMERAL;
 
		this->text.Initialize(this->edit_str_buf, this->edit_str_size);
 

	
 
		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];
 
@@ -601,29 +602,31 @@ public:
 
						case SLD_LOAD_HEIGHTMAP: ShowNetworkContentListWindow(NULL, CONTENT_TYPE_HEIGHTMAP); break;
 
					}
 
#endif
 
				}
 
				break;
 

	
 
			case WID_SL_DELETE_SELECTION: case WID_SL_SAVE_GAME: // Delete, Save game
 
			case WID_SL_DELETE_SELECTION: // Delete
 
				break;
 

	
 
			case WID_SL_SAVE_GAME: // Save game
 
				/* Note, this is also called via the OSK; and we need to lower the button. */
 
				this->HandleButtonClick(WID_SL_SAVE_GAME);
 
				break;
 
		}
 
	}
 

	
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		if (keycode == WKC_ESC) {
 
			delete this;
 
			return ES_HANDLED;
 
		}
 

	
 
		EventState state = ES_NOT_HANDLED;
 
		if ((_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP) &&
 
				this->HandleEditBoxKey(WID_SL_SAVE_OSK_TITLE, key, keycode, state) == HEBR_CONFIRM) {
 
			this->HandleButtonClick(WID_SL_SAVE_GAME);
 
		}
 
		this->HandleEditBoxKey(WID_SL_SAVE_OSK_TITLE, key, keycode, state);
 

	
 
		return state;
 
	}
 

	
 
	virtual void OnTimeout()
 
	{
src/misc_gui.cpp
Show inline comments
 
@@ -816,12 +816,26 @@ HandleEditBoxResult QueryStringBaseWindo
 
	HandleEditBoxResult result = this->QueryString::HandleEditBoxKey(this, wid, key, keycode, state);
 
	switch (result) {
 
		case HEBR_EDITING:
 
			this->OnOSKInput(wid);
 
			break;
 

	
 
		case HEBR_CONFIRM:
 
			if (this->ok_button >= 0) {
 
				this->OnClick(Point(), this->ok_button, 1);
 
			}
 
			break;
 

	
 
		case HEBR_CANCEL:
 
			if (this->cancel_button >= 0) {
 
				this->OnClick(Point(), this->cancel_button, 1);
 
			} else {
 
				this->UnfocusFocusedWidget();
 
			}
 
			break;
 

	
 
		default: break;
 
	}
 
	return result;
 
}
 

	
 
/** Class for the string query window. */
 
@@ -902,18 +916,13 @@ struct QueryStringWindow : public QueryS
 
		}
 
	}
 

	
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		EventState state = ES_NOT_HANDLED;
 
		switch (this->HandleEditBoxKey(WID_QS_TEXT, key, keycode, state)) {
 
			default: break;
 
			case HEBR_CONFIRM: this->OnOk();
 
				/* FALL THROUGH */
 
			case HEBR_CANCEL: delete this; break; // close window, abandon changes
 
		}
 
		this->HandleEditBoxKey(WID_QS_TEXT, key, keycode, state);
 
		return state;
 
	}
 

	
 
	~QueryStringWindow()
 
	{
 
		if (!this->handled && this->parent != NULL) {
src/network/network_chat_gui.cpp
Show inline comments
 
@@ -509,19 +509,13 @@ struct NetworkChatWindow : public QueryS
 
		EventState state = ES_NOT_HANDLED;
 
		if (keycode == WKC_TAB) {
 
			ChatTabCompletion();
 
			state = ES_HANDLED;
 
		} else {
 
			_chat_tab_completion_active = false;
 
			switch (this->HandleEditBoxKey(WID_NC_TEXTBOX, key, keycode, state)) {
 
				default: break;
 
				case HEBR_CONFIRM:
 
					SendChat(this->text.buf, this->dtype, this->dest);
 
					/* FALL THROUGH */
 
				case HEBR_CANCEL: delete this; break;
 
			}
 
			this->HandleEditBoxKey(WID_NC_TEXTBOX, key, keycode, state);
 
		}
 
		return state;
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
src/network/network_gui.cpp
Show inline comments
 
@@ -832,26 +832,21 @@ public:
 

	
 
			/* redraw window */
 
			this->SetDirty();
 
			return ES_HANDLED;
 
		}
 

	
 
		switch (this->HandleEditBoxKey(WID_NG_CLIENT, key, keycode, state)) {
 
			case HEBR_NOT_FOCUSED:
 
				if (this->server != NULL) {
 
					if (keycode == WKC_DELETE) { // Press 'delete' to remove servers
 
						NetworkGameListRemoveItem(this->server);
 
						if (this->server == this->last_joined) this->last_joined = NULL;
 
						this->server = NULL;
 
						this->list_pos = SLP_INVALID;
 
					}
 
		if (this->HandleEditBoxKey(WID_NG_CLIENT, key, keycode, state) == HEBR_NOT_FOCUSED) {
 
			if (this->server != NULL) {
 
				if (keycode == WKC_DELETE) { // Press 'delete' to remove servers
 
					NetworkGameListRemoveItem(this->server);
 
					if (this->server == this->last_joined) this->last_joined = NULL;
 
					this->server = NULL;
 
					this->list_pos = SLP_INVALID;
 
				}
 
				break;
 

	
 
			default:
 
				break;
 
			}
 
		}
 

	
 
		return state;
 
	}
 

	
 
	virtual void OnOSKInput(int wid)
 
@@ -2157,23 +2152,13 @@ struct NetworkCompanyPasswordWindow : pu
 
		}
 
	}
 

	
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		EventState state = ES_NOT_HANDLED;
 
		switch (this->HandleEditBoxKey(WID_NCP_PASSWORD, key, keycode, state)) {
 
			default: break;
 

	
 
			case HEBR_CONFIRM:
 
				this->OnOk();
 
				/* FALL THROUGH */
 

	
 
			case HEBR_CANCEL:
 
				delete this;
 
				break;
 
		}
 
		this->HandleEditBoxKey(WID_NCP_PASSWORD, key, keycode, state);
 
		return state;
 
	}
 
};
 

	
 
static const NWidgetPart _nested_network_company_password_window_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
src/script/api/game/game_window.hpp.sq
Show inline comments
 
@@ -1018,12 +1018,13 @@ void SQGSWindow_Register(Squirrel *engin
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SIL_CAPTION,                           "WID_SIL_CAPTION");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SIL_LIST,                              "WID_SIL_LIST");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SIL_SCROLLBAR,                         "WID_SIL_SCROLLBAR");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SIL_FILTER_TEXT,                       "WID_SIL_FILTER_TEXT");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SIL_FILTER_MATCH_CASE_BTN,             "WID_SIL_FILTER_MATCH_CASE_BTN");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SIL_FILTER_CLEAR_BTN,                  "WID_SIL_FILTER_CLEAR_BTN");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SIL_FILTER_ENTER_BTN,                  "WID_SIL_FILTER_ENTER_BTN");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QES_CAPTION,                           "WID_QES_CAPTION");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QES_TEXT,                              "WID_QES_TEXT");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QES_OK,                                "WID_QES_OK");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QES_CANCEL,                            "WID_QES_CANCEL");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QES_DELETE,                            "WID_QES_DELETE");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QES_PREVIOUS,                          "WID_QES_PREVIOUS");
src/script/api/script_window.hpp
Show inline comments
 
@@ -2141,12 +2141,13 @@ public:
 
		WID_SIL_CAPTION                              = ::WID_SIL_CAPTION,                              ///< Caption of the window.
 
		WID_SIL_LIST                                 = ::WID_SIL_LIST,                                 ///< List of signs.
 
		WID_SIL_SCROLLBAR                            = ::WID_SIL_SCROLLBAR,                            ///< Scrollbar of list.
 
		WID_SIL_FILTER_TEXT                          = ::WID_SIL_FILTER_TEXT,                          ///< Text box for typing a filter string.
 
		WID_SIL_FILTER_MATCH_CASE_BTN                = ::WID_SIL_FILTER_MATCH_CASE_BTN,                ///< Button to toggle if case sensitive filtering should be used.
 
		WID_SIL_FILTER_CLEAR_BTN                     = ::WID_SIL_FILTER_CLEAR_BTN,                     ///< Button to clear the filter.
 
		WID_SIL_FILTER_ENTER_BTN                     = ::WID_SIL_FILTER_ENTER_BTN,                     ///< Scroll to first sign.
 
	};
 

	
 
	/** Widgets of the #SignWindow class. */
 
	enum QueryEditSignWidgets {
 
		WID_QES_CAPTION                              = ::WID_QES_CAPTION,                              ///< Caption of the window.
 
		WID_QES_TEXT                                 = ::WID_QES_TEXT,                                 ///< Text of the query.
src/signs_gui.cpp
Show inline comments
 
@@ -153,12 +153,14 @@ struct SignListWindow : QueryStringBaseW
 
		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->text.Initialize(this->edit_str_buf, MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS);
 
		ClearFilterTextWidget();
 

	
 
		/* Initialize the filtering variables */
 
		this->SetFilterString("");
 
@@ -251,12 +253,20 @@ struct SignListWindow : QueryStringBaseW
 
				if (id_v == INT_MAX) return;
 

	
 
				const Sign *si = this->signs[id_v];
 
				ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
 
				break;
 
			}
 

	
 
			case WID_SIL_FILTER_ENTER_BTN:
 
				if (this->signs.Length() >= 1) {
 
					const Sign *si = this->signs[0];
 
					ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
 
				}
 
				break;
 

	
 
			case WID_SIL_FILTER_CLEAR_BTN:
 
				this->ClearFilterTextWidget(); // Empty the text in the EditBox widget
 
				this->SetFilterString("");     // Use empty text as filter text (= view all signs)
 
				break;
 

	
 
			case WID_SIL_FILTER_MATCH_CASE_BTN:
 
@@ -293,35 +303,18 @@ struct SignListWindow : QueryStringBaseW
 
		}
 
	}
 

	
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		EventState state = ES_NOT_HANDLED;
 
		switch (this->HandleEditBoxKey(WID_SIL_FILTER_TEXT, key, keycode, state)) {
 
			case HEBR_CONFIRM: // Enter pressed -> goto first sign in list
 
				if (this->signs.Length() >= 1) {
 
					const Sign *si = this->signs[0];
 
					ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
 
				}
 
				return state;
 

	
 
			case HEBR_CANCEL: // ESC pressed, clear filter.
 
				this->OnClick(Point(), WID_SIL_FILTER_CLEAR_BTN, 1); // Simulate click on clear button.
 
				this->UnfocusFocusedWidget();                    // Unfocus the text box.
 
				return state;
 

	
 
			case HEBR_NOT_FOCUSED: // The filter text box is not globaly focused.
 
				if (CheckHotkeyMatch(signlist_hotkeys, keycode, this) == SLHK_FOCUS_FILTER_BOX) {
 
					this->SetFocusedWidget(WID_SIL_FILTER_TEXT);
 
					SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused.
 
					state = ES_HANDLED;
 
				}
 
				break;
 

	
 
			default:
 
				break;
 
		if (this->HandleEditBoxKey(WID_SIL_FILTER_TEXT, key, keycode, state) == HEBR_NOT_FOCUSED) {
 
			if (CheckHotkeyMatch(signlist_hotkeys, keycode, this) == SLHK_FOCUS_FILTER_BOX) {
 
				this->SetFocusedWidget(WID_SIL_FILTER_TEXT);
 
				SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused.
 
				state = ES_HANDLED;
 
			}
 
		}
 

	
 
		return state;
 
	}
 

	
 
	virtual void OnOSKInput(int widget)
 
@@ -548,23 +541,13 @@ struct SignWindow : QueryStringBaseWindo
 
		}
 
	}
 

	
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		EventState state = ES_NOT_HANDLED;
 
		switch (this->HandleEditBoxKey(WID_QES_TEXT, key, keycode, state)) {
 
			default: break;
 

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

	
 
			case HEBR_CANCEL: // close window, abandon changes
 
				delete this;
 
				break;
 
		}
 
		this->HandleEditBoxKey(WID_QES_TEXT, key, keycode, state);
 
		return state;
 
	}
 
};
 

	
 
static const NWidgetPart _nested_query_sign_edit_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
src/town_gui.cpp
Show inline comments
 
@@ -1101,15 +1101,13 @@ public:
 
		}
 
	}
 

	
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		EventState state = ES_NOT_HANDLED;
 
		if (this->HandleEditBoxKey(WID_TF_TOWN_NAME_EDITBOX, key, keycode, state) == HEBR_CANCEL) {
 
			this->UnfocusFocusedWidget();
 
		}
 
		this->HandleEditBoxKey(WID_TF_TOWN_NAME_EDITBOX, key, keycode, state);
 
		return state;
 
	}
 

	
 
	virtual void OnPlaceObject(Point pt, TileIndex tile)
 
	{
 
		this->ExecuteFoundTownCommand(tile, false, STR_ERROR_CAN_T_FOUND_TOWN_HERE, CcFoundTown);
src/widgets/sign_widget.h
Show inline comments
 
@@ -18,12 +18,13 @@ enum SignListWidgets {
 
	WID_SIL_CAPTION,               ///< Caption of the window.
 
	WID_SIL_LIST,                  ///< List of signs.
 
	WID_SIL_SCROLLBAR,             ///< Scrollbar of list.
 
	WID_SIL_FILTER_TEXT,           ///< Text box for typing a filter string.
 
	WID_SIL_FILTER_MATCH_CASE_BTN, ///< Button to toggle if case sensitive filtering should be used.
 
	WID_SIL_FILTER_CLEAR_BTN,      ///< Button to clear the filter.
 
	WID_SIL_FILTER_ENTER_BTN,      ///< Scroll to first sign.
 
};
 

	
 
/** Widgets of the #SignWindow class. */
 
enum QueryEditSignWidgets {
 
	WID_QES_CAPTION,  ///< Caption of the window.
 
	WID_QES_TEXT,     ///< Text of the query.
0 comments (0 inline, 0 general)