Changeset - r10295:c0e73453a31c
[Not reviewed]
master
0 5 0
glx - 16 years ago 2008-10-25 19:59:11
glx@openttd.org
(svn r14534) -Codechange [FS#2382]: Enumify magic return values of HandleEditBox function (Zuu)
5 files changed with 32 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/misc_gui.cpp
Show inline comments
 
@@ -960,14 +960,14 @@ bool HandleCaret(Textbuf *tb)
 
	return false;
 
}
 

	
 
int QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, Window::EventState &state)
 
HandleEditBoxResult QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, Window::EventState &state)
 
{
 
	state = Window::ES_HANDLED;
 

	
 
	switch (keycode) {
 
		case WKC_ESC: return 2;
 
		case WKC_ESC: return HEBR_CANCEL;
 

	
 
		case WKC_RETURN: case WKC_NUM_ENTER: return 1;
 
		case WKC_RETURN: case WKC_NUM_ENTER: return HEBR_CONFIRM;
 

	
 
		case (WKC_CTRL | 'V'):
 
			if (InsertTextBufferClipboard(&this->text)) w->InvalidateWidget(wid);
 
@@ -994,7 +994,7 @@ int QueryString::HandleEditBoxKey(Window
 
			}
 
	}
 

	
 
	return 0;
 
	return HEBR_EDITING;
 
}
 

	
 
void QueryString::HandleEditBox(Window *w, int wid)
 
@@ -1124,13 +1124,13 @@ struct QueryStringWindow : public QueryS
 
		EventState state;
 
		switch (this->HandleEditBoxKey(QUERY_STR_WIDGET_TEXT, key, keycode, state)) {
 
			default: NOT_REACHED();
 
			case 0: {
 
			case HEBR_EDITING: {
 
				Window *osk = FindWindowById(WC_OSK, 0);
 
				if (osk != NULL && osk->parent == this) osk->OnInvalidateData();
 
			} break;
 
			case 1: this->OnOk(); // Enter pressed, confirms change
 
			case HEBR_CONFIRM: this->OnOk();
 
			/* FALL THROUGH */
 
			case 2: delete this; break; // ESC pressed, closes window, abandons changes
 
			case HEBR_CANCEL: delete this; break; // close window, abandon changes
 
		}
 
		return state;
 
	}
 
@@ -1624,7 +1624,7 @@ struct SaveLoadWindow : public QueryStri
 

	
 
		EventState state = ES_NOT_HANDLED;
 
		if ((_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) &&
 
				this->HandleEditBoxKey(10, key, keycode, state) == 1) { // Press Enter
 
				this->HandleEditBoxKey(10, key, keycode, state) == HEBR_CONFIRM) {
 
			this->HandleButtonClick(12);
 
		}
 

	
src/network/network_chat_gui.cpp
Show inline comments
 
@@ -468,14 +468,14 @@ struct NetworkChatWindow : public QueryS
 
			_chat_tab_completion_active = false;
 
			switch (this->HandleEditBoxKey(2, key, keycode, state)) {
 
				default: NOT_REACHED();
 
				case 0: {
 
				case HEBR_EDITING: {
 
					Window *osk = FindWindowById(WC_OSK, 0);
 
					if (osk != NULL && osk->parent == this) osk->OnInvalidateData();
 
				} break;
 
				case 1: /* Return */
 
				case HEBR_CONFIRM:
 
					SendChat(this->text.buf, this->dtype, this->dest);
 
				/* FALLTHROUGH */
 
				case 2: /* Escape */ delete this; break;
 
				case HEBR_CANCEL: delete this; break;
 
			}
 
		}
 
		return state;
src/network/network_gui.cpp
Show inline comments
 
@@ -668,7 +668,7 @@ public:
 
			return state;
 
		}
 

	
 
		if (this->HandleEditBoxKey(NGWW_CLIENT, key, keycode, state) == 1) return state; // enter pressed
 
		if (this->HandleEditBoxKey(NGWW_CLIENT, key, keycode, state) == HEBR_CONFIRM) return state;
 

	
 
		/* The name is only allowed when it starts with a letter! */
 
		if (!StrEmpty(this->edit_str_buf) && this->edit_str_buf[0] != ' ') {
 
@@ -1047,7 +1047,7 @@ struct NetworkStartServerWindow : public
 
	{
 
		EventState state = ES_NOT_HANDLED;
 
		if (this->field == NSSW_GAMENAME) {
 
			if (this->HandleEditBoxKey(NSSW_GAMENAME, key, keycode, state) == 1) return state; // enter pressed
 
			if (this->HandleEditBoxKey(NSSW_GAMENAME, key, keycode, state) == HEBR_CONFIRM) return state;
 

	
 
			ttd_strlcpy(_settings_client.network.server_name, this->text.buf, sizeof(_settings_client.network.server_name));
 
		}
 
@@ -1906,11 +1906,13 @@ struct NetworkCompanyPasswordWindow : pu
 
	{
 
		EventState state;
 
		switch (this->HandleEditBoxKey(4, key, keycode, state)) {
 
			case 1: // Return
 
			default: break;
 

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

	
 
			case 2: // Escape
 
			case HEBR_CANCEL:
 
				delete this;
 
				break;
 
		}
src/querystring_gui.h
Show inline comments
 
@@ -9,6 +9,16 @@
 
#include "window_gui.h"
 

	
 
/**
 
 * Return values for HandleEditBoxKey
 
 */
 
enum HandleEditBoxResult
 
{
 
	HEBR_EDITING = 0, // Other key pressed.
 
	HEBR_CONFIRM,     // Return or enter key pressed.
 
	HEBR_CANCEL,      // Escape key pressed.
 
};
 

	
 
/**
 
 * Data stored about a string that can be modified in the GUI
 
 */
 
struct QueryString {
 
@@ -35,7 +45,7 @@ struct QueryString {
 

	
 
	void DrawEditBox(Window *w, int wid);
 
	void HandleEditBox(Window *w, int wid);
 
	int HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, Window::EventState &state);
 
	HandleEditBoxResult HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, Window::EventState &state);
 
};
 

	
 
struct QueryStringBaseWindow : public Window, public QueryString {
src/signs_gui.cpp
Show inline comments
 
@@ -309,11 +309,13 @@ struct SignWindow : QueryStringBaseWindo
 
	{
 
		EventState state = ES_NOT_HANDLED;
 
		switch (this->HandleEditBoxKey(QUERY_EDIT_SIGN_WIDGET_TEXT, key, keycode, state)) {
 
			case 1: // Enter pressed, confirms change
 
			default: break;
 

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

	
 
			case 2: // ESC pressed, closes window, abandons changes
 
			case HEBR_CANCEL: // close window, abandon changes
 
				delete this;
 
				break;
 
		}
0 comments (0 inline, 0 general)