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 43 insertions and 79 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_gui.cpp
Show inline comments
 
@@ -1340,13 +1340,7 @@ 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: {
 
		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;
 
@@ -1358,11 +1352,6 @@ struct AIDebugWindow : public QueryStrin
 
					this->OnClick(Point(), num, 1);
 
					state = ES_HANDLED;
 
				}
 
				break;
 
			}
 

	
 
			default:
 
				break;
 
		}
 
		return state;
 
	}
src/fios_gui.cpp
Show inline comments
 
@@ -262,6 +262,7 @@ public:
 
			default:                break;
 
		}
 

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

	
 
@@ -604,7 +605,12 @@ public:
 
				}
 
				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;
 
		}
 
	}
 
@@ -617,10 +623,7 @@ public:
 
		}
 

	
 
		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;
 
	}
src/misc_gui.cpp
Show inline comments
 
@@ -819,6 +819,20 @@ HandleEditBoxResult QueryStringBaseWindo
 
			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;
 
@@ -905,12 +919,7 @@ 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;
 
	}
 

	
src/network/network_chat_gui.cpp
Show inline comments
 
@@ -512,13 +512,7 @@ struct NetworkChatWindow : public QueryS
 
			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;
 
	}
src/network/network_gui.cpp
Show inline comments
 
@@ -835,8 +835,7 @@ public:
 
			return ES_HANDLED;
 
		}
 

	
 
		switch (this->HandleEditBoxKey(WID_NG_CLIENT, key, keycode, state)) {
 
			case HEBR_NOT_FOCUSED:
 
		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);
 
@@ -845,10 +844,6 @@ public:
 
						this->list_pos = SLP_INVALID;
 
					}
 
				}
 
				break;
 

	
 
			default:
 
				break;
 
		}
 

	
 
		return state;
 
@@ -2160,17 +2155,7 @@ 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;
 
	}
 
};
src/script/api/game/game_window.hpp.sq
Show inline comments
 
@@ -1021,6 +1021,7 @@ void SQGSWindow_Register(Squirrel *engin
 
	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");
src/script/api/script_window.hpp
Show inline comments
 
@@ -2144,6 +2144,7 @@ public:
 
		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. */
src/signs_gui.cpp
Show inline comments
 
@@ -156,6 +156,8 @@ struct SignListWindow : QueryStringBaseW
 
		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();
 
@@ -254,6 +256,14 @@ struct SignListWindow : QueryStringBaseW
 
				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)
 
@@ -296,29 +306,12 @@ 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 (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;
 
				}
 
				break;
 

	
 
			default:
 
				break;
 
		}
 

	
 
		return state;
 
@@ -551,17 +544,7 @@ 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;
 
	}
 
};
src/town_gui.cpp
Show inline comments
 
@@ -1104,9 +1104,7 @@ 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;
 
	}
 

	
src/widgets/sign_widget.h
Show inline comments
 
@@ -21,6 +21,7 @@ enum SignListWidgets {
 
	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. */
0 comments (0 inline, 0 general)