Changeset - r19778:979f3421fa37
[Not reviewed]
master
0 13 0
frosch - 12 years ago 2012-11-13 21:47:02
frosch@openttd.org
(svn r24733) -Codechange: Move handling of editbox keys to window class.
13 files changed with 34 insertions and 94 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_gui.cpp
Show inline comments
 
@@ -1337,16 +1337,14 @@ struct AIDebugWindow : public QueryStrin
 
		}
 
	}
 

	
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		EventState state = ES_NOT_HANDLED;
 
		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;
 
		int num = CheckHotkeyMatch(aidebug_hotkeys, keycode, this);
 
		if (num != -1) {
 
			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);
src/fios_gui.cpp
Show inline comments
 
@@ -619,16 +619,13 @@ public:
 
	{
 
		if (keycode == WKC_ESC) {
 
			delete this;
 
			return ES_HANDLED;
 
		}
 

	
 
		EventState state = ES_NOT_HANDLED;
 
		this->HandleEditBoxKey(WID_SL_SAVE_OSK_TITLE, key, keycode, state);
 

	
 
		return state;
 
		return ES_NOT_HANDLED;
 
	}
 

	
 
	virtual void OnTimeout()
 
	{
 
		/* This test protects against using widgets 11 and 12 which are only available
 
		 * in those saveload modes. */
src/genworld_gui.cpp
Show inline comments
 
@@ -691,19 +691,12 @@ struct GenerateLandscapeWindow : public 
 
				this->RaiseWidget(*widget);
 
				this->SetWidgetDirty(*widget);
 
			}
 
		}
 
	}
 

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

	
 
	virtual void OnOSKInput(int wid)
 
	{
 
		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
src/misc_gui.cpp
Show inline comments
 
@@ -808,16 +808,16 @@ void QueryString::DrawEditBox(const Wind
 
		DrawString(tb->caretxoffs + delta, tb->caretxoffs + delta + caret_width, 0, "_", TC_WHITE);
 
	}
 

	
 
	_cur_dpi = old_dpi;
 
}
 

	
 
HandleEditBoxResult QueryStringBaseWindow::HandleEditBoxKey(int wid, uint16 key, uint16 keycode, EventState &state)
 
EventState QueryStringBaseWindow::HandleEditBoxKey(int wid, uint16 key, uint16 keycode)
 
{
 
	HandleEditBoxResult result = this->QueryString::HandleEditBoxKey(this, wid, key, keycode, state);
 
	switch (result) {
 
	EventState state = ES_NOT_HANDLED;
 
	switch (this->QueryString::HandleEditBoxKey(this, wid, key, keycode, state)) {
 
		case HEBR_EDITING:
 
			this->OnOSKInput(wid);
 
			break;
 

	
 
		case HEBR_CONFIRM:
 
			if (this->ok_button >= 0) {
 
@@ -832,13 +832,13 @@ HandleEditBoxResult QueryStringBaseWindo
 
				this->UnfocusFocusedWidget();
 
			}
 
			break;
 

	
 
		default: break;
 
	}
 
	return result;
 
	return state;
 
}
 

	
 
/** Class for the string query window. */
 
struct QueryStringWindow : public QueryStringBaseWindow
 
{
 
	QueryStringFlags flags; ///< Flags controlling behaviour of the window.
 
@@ -913,19 +913,12 @@ struct QueryStringWindow : public QueryS
 
			case WID_QS_CANCEL:
 
				delete this;
 
				break;
 
		}
 
	}
 

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

	
 
	~QueryStringWindow()
 
	{
 
		if (!this->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
 
@@ -507,19 +507,21 @@ struct NetworkChatWindow : public QueryS
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		EventState state = ES_NOT_HANDLED;
 
		if (keycode == WKC_TAB) {
 
			ChatTabCompletion();
 
			state = ES_HANDLED;
 
		} else {
 
			_chat_tab_completion_active = false;
 
			this->HandleEditBoxKey(WID_NC_TEXTBOX, key, keycode, state);
 
		}
 
		return state;
 
	}
 

	
 
	virtual void OnOSKInput(int wid)
 
	{
 
		_chat_tab_completion_active = false;
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
 
	 * @param data Information about the changed data.
 
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
 
	 */
 
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
src/network/network_content_gui.cpp
Show inline comments
 
@@ -760,18 +760,14 @@ public:
 
						this->InvalidateData();
 
					}
 
					return ES_HANDLED;
 
				}
 
				/* FALL THROUGH, space is pressed and filter isn't focused. */
 

	
 
			default: {
 
				/* Handle editbox input */
 
				EventState state = ES_NOT_HANDLED;
 
				this->HandleEditBoxKey(WID_NCL_FILTER, key, keycode, state);
 
				return state;
 
			}
 
			default:
 
				return ES_NOT_HANDLED;
 
		}
 

	
 
		if (_network_content_client.Length() == 0) return ES_HANDLED;
 

	
 
		this->selected = *this->content.Get(this->list_pos);
 

	
src/network/network_gui.cpp
Show inline comments
 
@@ -832,20 +832,18 @@ public:
 

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

	
 
		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;
 
				}
 
		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;
 
			}
 
		}
 

	
 
		return state;
 
	}
 

	
 
@@ -1169,19 +1167,12 @@ struct NetworkStartServerWindow : public
 
				NOT_REACHED();
 
		}
 

	
 
		this->SetDirty();
 
	}
 

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

	
 
	virtual void OnOSKInput(int wid)
 
	{
 
		if (wid == WID_NSS_GAMENAME) {
 
			strecpy(_settings_client.network.server_name, this->text.buf, lastof(_settings_client.network.server_name));
 
		}
 
	}
 
@@ -2148,19 +2139,12 @@ struct NetworkCompanyPasswordWindow : pu
 
			case WID_NCP_SAVE_AS_DEFAULT_PASSWORD:
 
				this->ToggleWidgetLoweredState(WID_NCP_SAVE_AS_DEFAULT_PASSWORD);
 
				this->SetDirty();
 
				break;
 
		}
 
	}
 

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

	
 
static const NWidgetPart _nested_network_company_password_window_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_COMPANY_PASSWORD_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
src/newgrf_gui.cpp
Show inline comments
 
@@ -1259,18 +1259,14 @@ struct NewGRFWindow : public QueryString
 

	
 
			case WKC_END:
 
				/* jump to end */
 
				this->avail_pos = this->avails.Length() - 1;
 
				break;
 

	
 
			default: {
 
				/* Handle editbox input */
 
				EventState state = ES_NOT_HANDLED;
 
				this->HandleEditBoxKey(WID_NS_FILTER, key, keycode, state);
 
				return state;
 
			}
 
			default:
 
				return ES_NOT_HANDLED;
 
		}
 

	
 
		if (this->avails.Length() == 0) this->avail_pos = -1;
 
		if (this->avail_pos >= 0) {
 
			this->avail_sel = this->avails[this->avail_pos];
 
			this->vscroll2->ScrollTowards(this->avail_pos);
src/querystring_gui.h
Show inline comments
 
@@ -75,13 +75,13 @@ struct QueryStringBaseWindow : public Wi
 

	
 
	~QueryStringBaseWindow()
 
	{
 
		free(this->edit_str_buf);
 
	}
 

	
 
	HandleEditBoxResult HandleEditBoxKey(int wid, uint16 key, uint16 keycode, EventState &state);
 
	EventState HandleEditBoxKey(int wid, uint16 key, uint16 keycode);
 

	
 
	/**
 
	 * Callback for when on input has been entered with the OSK.
 
	 * @param wid The widget the OSK was attached to.
 
	 */
 
	virtual void OnOSKInput(int wid) {}
src/settings_gui.cpp
Show inline comments
 
@@ -2403,20 +2403,12 @@ struct GameSettingsWindow : QueryStringB
 
		bool all_unfolded = true;
 
		_settings_main_page.GetFoldingState(all_folded, all_unfolded);
 
		this->SetWidgetDisabledState(WID_GS_EXPAND_ALL, all_unfolded);
 
		this->SetWidgetDisabledState(WID_GS_COLLAPSE_ALL, all_folded);
 
	}
 

	
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		/* Handle editbox input */
 
		EventState state = ES_NOT_HANDLED;
 
		this->HandleEditBoxKey(WID_GS_FILTER, key, keycode, state);
 
		return state;
 
	}
 

	
 
	virtual void OnOSKInput(int wid)
 
	{
 
		if (wid == WID_GS_FILTER) {
 
			string_filter.SetFilterTerm(this->edit_str_buf);
 
			if (!string_filter.IsEmpty() && !this->manually_changed_folding) {
 
				/* User never expanded/collapsed single pages and entered a filter term.
src/signs_gui.cpp
Show inline comments
 
@@ -303,18 +303,16 @@ struct SignListWindow : QueryStringBaseW
 
		}
 
	}
 

	
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		EventState state = ES_NOT_HANDLED;
 
		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;
 
			}
 
		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)
 
@@ -537,19 +535,12 @@ struct SignWindow : QueryStringBaseWindo
 

	
 
			case WID_QES_CANCEL:
 
				delete this;
 
				break;
 
		}
 
	}
 

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

	
 
static const NWidgetPart _nested_query_sign_edit_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY, WID_QES_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
src/town_gui.cpp
Show inline comments
 
@@ -1098,19 +1098,12 @@ public:
 
				this->town_layout = (TownLayout)(widget - WID_TF_LAYOUT_ORIGINAL);
 
				this->UpdateButtons(false);
 
				break;
 
		}
 
	}
 

	
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		EventState state = ES_NOT_HANDLED;
 
		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);
 
	}
 

	
 
	virtual void OnPlaceObjectAbort()
src/window.cpp
Show inline comments
 
@@ -2260,14 +2260,19 @@ void HandleKeypress(uint32 raw_key)
 
	 * If both key and keycode is zero, we don't bother to process the event.
 
	 */
 
	if (key == 0 && keycode == 0) return;
 

	
 
	/* Check if the focused window has a focused editbox */
 
	if (EditBoxInGlobalFocus()) {
 
		/* All input will in this case go to the focused window */
 
		if (_focused_window->OnKeyPress(key, keycode) == ES_HANDLED) return;
 
		/* All input will in this case go to the focused editbox */
 
		if (_focused_window->window_class == WC_CONSOLE) {
 
			if (_focused_window->OnKeyPress(key, keycode) == ES_HANDLED) return;
 
		} else {
 
			QueryStringBaseWindow *query = dynamic_cast<QueryStringBaseWindow*>(_focused_window);
 
			if (query != NULL && query->HandleEditBoxKey(_focused_window->nested_focus->index, key, keycode) == ES_HANDLED) return;
 
		}
 
	}
 

	
 
	/* Call the event, start with the uppermost window, but ignore the toolbar. */
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_FRONT(w) {
 
		if (w->window_class == WC_MAIN_TOOLBAR) continue;
0 comments (0 inline, 0 general)