Changeset - r9285:acbf930223e4
[Not reviewed]
master
0 13 0
rubidium - 17 years ago 2008-05-17 23:11:06
rubidium@openttd.org
(svn r13151) -Codechange: use an enum instead of bool as return type of OnKeyPress/OnCTRLStateChange to make it obvious what the return values mean.
13 files changed with 85 insertions and 81 deletions:
0 comments (0 inline, 0 general)
src/bridge_gui.cpp
Show inline comments
 
@@ -118,22 +118,22 @@ public:
 
			DrawSprite(b->sprite, b->pal, 3, y);
 
			DrawString(44, y, STR_500D, TC_FROMSTRING);
 
			y += this->resize.step_height;
 
		}
 
	}
 

	
 
	virtual bool OnKeyPress(uint16 key, uint16 keycode)
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		const uint8 i = keycode - '1';
 
		if (i < 9 && i < this->bridges->list_length) {
 
			/* Build the requested bridge */
 
			this->BuildBridge(i);
 
			delete this;
 
			return false;
 
			return ES_HANDLED;
 
		}
 
		return true;
 
		return ES_NOT_HANDLED;
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		if (widget == BBSW_BRIDGE_LIST) {
 
			uint i = ((int)pt.y - 14) / this->resize.step_height;
src/console.cpp
Show inline comments
 
@@ -123,13 +123,13 @@ struct IConsoleWindow : Window
 

	
 
	virtual void OnMouseLoop()
 
	{
 
		if (HandleCaret(&_iconsole_cmdline)) this->SetDirty();
 
	}
 

	
 
	virtual bool OnKeyPress(uint16 key, uint16 keycode)
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		switch (keycode) {
 
			case WKC_UP:
 
				IConsoleHistoryNavigate(+1);
 
				this->SetDirty();
 
				break;
 
@@ -227,16 +227,16 @@ struct IConsoleWindow : Window
 
				if (IsValidChar(key, CS_ALPHANUMERAL)) {
 
					IConsoleWindow::scroll = ICON_BUFFER;
 
					InsertTextBufferChar(&_iconsole_cmdline, key);
 
					IConsoleResetHistoryPos();
 
					this->SetDirty();
 
				} else {
 
					return true;
 
					return ES_NOT_HANDLED;
 
				}
 
		}
 
		return false;
 
		return ES_HANDLED;
 
	}
 
};
 

	
 
byte IConsoleWindow::scroll = ICON_BUFFER;
 

	
 
static const Widget _iconsole_window_widgets[] = {
src/depot_gui.cpp
Show inline comments
 
@@ -958,20 +958,20 @@ struct DepotWindow : Window {
 
		this->vscroll.cap += delta.y / (int)this->resize.step_height;
 
		this->hscroll.cap += delta.x / (int)this->resize.step_width;
 
		this->widget[DEPOT_WIDGET_MATRIX].data = (this->vscroll.cap << 8) + (this->type == VEH_TRAIN ? 1 : this->hscroll.cap);
 
		ResizeDepotButtons(this);
 
	}
 

	
 
	virtual bool OnCTRLStateChange()
 
	virtual EventState OnCTRLStateChange()
 
	{
 
		if (this->sel != INVALID_VEHICLE) {
 
			_cursor.vehchain = _ctrl_pressed;
 
			this->InvalidateWidget(DEPOT_WIDGET_MATRIX);
 
		}
 

	
 
		return true;
 
		return ES_HANDLED;
 
	}
 
};
 

	
 
static void DepotSellAllConfirmationCallback(Window *win, bool confirmed)
 
{
 
	if (confirmed) {
src/genworld_gui.cpp
Show inline comments
 
@@ -467,23 +467,23 @@ struct GenerateLandscapeWindow : public 
 

	
 
	virtual void OnMouseLoop()
 
	{
 
		this->HandleEditBox(GLAND_RANDOM_EDITBOX);
 
	}
 

	
 
	virtual bool OnKeyPress(uint16 key, uint16 keycode)
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		bool cont;
 
		this->HandleEditBoxKey(GLAND_RANDOM_EDITBOX, key, keycode, cont);
 
		EventState state;
 
		this->HandleEditBoxKey(GLAND_RANDOM_EDITBOX, key, keycode, state);
 
		/* the seed is unsigned, therefore atoi cannot be used.
 
			* As 2^32 - 1 (MAX_UVALUE(uint32)) 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. */
 
		_patches_newgame.generation_seed = minu(strtoul(this->edit_str_buf, NULL, sizeof(this->edit_str_buf) - 1), MAX_UVALUE(uint32) - 1);
 
		return cont;
 
		return state;
 
	}
 

	
 
	virtual void OnDropdownSelect(int widget, int index)
 
	{
 
		switch (widget) {
 
			case GLAND_MAPSIZE_X_PULLDOWN:  _patches_newgame.map_x = index; break;
src/main_gui.cpp
Show inline comments
 
@@ -236,40 +236,40 @@ struct MainWindow : Window
 
			DrawSprite(SPR_OTTD_T, PAL_NONE, off_x +  34, 50);
 
			DrawSprite(SPR_OTTD_T, PAL_NONE, off_x +  65, 50);
 
			DrawSprite(SPR_OTTD_D, PAL_NONE, off_x +  96, 50);
 
		}
 
	}
 

	
 
	virtual bool OnKeyPress(uint16 key, uint16 keycode)
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		switch (keycode) {
 
			case 'Q' | WKC_CTRL:
 
			case 'Q' | WKC_META:
 
				HandleExitGameRequest();
 
				return true;
 
				return ES_HANDLED;
 
		}
 

	
 
		/* Disable all key shortcuts, except quit shortcuts when
 
		* generating the world, otherwise they create threading
 
		* problem during the generating, resulting in random
 
		* assertions that are hard to trigger and debug */
 
		if (IsGeneratingWorld()) return true;
 
		if (IsGeneratingWorld()) return ES_NOT_HANDLED;
 

	
 
		if (keycode == WKC_BACKQUOTE) {
 
			IConsoleSwitch();
 
			return false;
 
			return ES_HANDLED;
 
		}
 

	
 
		if (keycode == ('B' | WKC_CTRL)) {
 
			extern bool _draw_bounding_boxes;
 
			_draw_bounding_boxes = !_draw_bounding_boxes;
 
			MarkWholeScreenDirty();
 
			return false;
 
			return ES_HANDLED;
 
		}
 

	
 
		if (_game_mode == GM_MENU) return true;
 
		if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
 

	
 
		switch (keycode) {
 
			case 'C':
 
			case 'Z': {
 
				Point pt = GetTileBelowCursor();
 
				if (pt.x != -1) {
 
@@ -369,15 +369,15 @@ struct MainWindow : Window
 

	
 
					ShowNetworkChatQueryWindow(DESTTYPE_TEAM, cio->client_playas);
 
				}
 
				break;
 
#endif
 

	
 
			default: return true;
 
			default: return ES_NOT_HANDLED;
 
		}
 
		return false;
 
		return ES_HANDLED;
 
	}
 

	
 
	virtual void OnScroll(Point delta)
 
	{
 
		ViewPort *vp = IsPtInWindowViewport(this, _cursor.pos.x, _cursor.pos.y);
 

	
src/misc_gui.cpp
Show inline comments
 
@@ -409,17 +409,17 @@ public:
 
	{
 
		SetRedErrorSquare(0);
 
		extern StringID _switch_mode_errorstr;
 
		_switch_mode_errorstr = INVALID_STRING_ID;
 
	}
 

	
 
	virtual bool OnKeyPress(uint16 key, uint16 keycode)
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		if (keycode != WKC_SPACE) return true;
 
		if (keycode != WKC_SPACE) return ES_NOT_HANDLED;
 
		delete this;
 
		return false;
 
		return ES_HANDLED;
 
	}
 
};
 

	
 
void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y)
 
{
 
	DeleteWindowById(WC_ERRMSG, 0);
 
@@ -880,15 +880,15 @@ bool HandleCaret(Textbuf *tb)
 
		tb->caret = b;
 
		return true;
 
	}
 
	return false;
 
}
 

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

	
 
	switch (keycode) {
 
		case WKC_ESC: return 2;
 

	
 
		case WKC_RETURN: case WKC_NUM_ENTER: return 1;
 

	
 
@@ -910,13 +910,13 @@ int QueryString::HandleEditBoxKey(Window
 
			break;
 

	
 
		default:
 
			if (IsValidChar(key, this->afilter)) {
 
				if (InsertTextBufferChar(&this->text, key)) w->InvalidateWidget(wid);
 
			} else { // key wasn't caught. Continue only if standard entry specified
 
				cont = (this->afilter == CS_ALPHANUMERAL);
 
				state = (this->afilter == CS_ALPHANUMERAL) ? Window::ES_HANDLED : Window::ES_NOT_HANDLED;
 
			}
 
	}
 

	
 
	return 0;
 
}
 

	
 
@@ -960,15 +960,15 @@ void QueryString::DrawEditBox(Window *w,
 
	DoDrawString(tb->buf, delta, 0, TC_YELLOW);
 
	if (tb->caret) DoDrawString("_", tb->caretxoffs + delta, 0, TC_WHITE);
 

	
 
	_cur_dpi = old_dpi;
 
}
 

	
 
int QueryStringBaseWindow::HandleEditBoxKey(int wid, uint16 key, uint16 keycode, bool &cont)
 
int QueryStringBaseWindow::HandleEditBoxKey(int wid, uint16 key, uint16 keycode, EventState &state)
 
{
 
	return this->QueryString::HandleEditBoxKey(this, wid, key, keycode, cont);
 
	return this->QueryString::HandleEditBoxKey(this, wid, key, keycode, state);
 
}
 

	
 
void QueryStringBaseWindow::HandleEditBox(int wid)
 
{
 
	this->QueryString::HandleEditBox(this, wid);
 
}
 
@@ -1035,21 +1035,21 @@ struct QueryStringWindow : public QueryS
 

	
 
	virtual void OnMouseLoop()
 
	{
 
		this->HandleEditBox(QUERY_STR_WIDGET_TEXT);
 
	}
 

	
 
	virtual bool OnKeyPress(uint16 key, uint16 keycode)
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		bool cont;
 
		switch (this->HandleEditBoxKey(QUERY_STR_WIDGET_TEXT, key, keycode, cont)) {
 
		EventState state;
 
		switch (this->HandleEditBoxKey(QUERY_STR_WIDGET_TEXT, key, keycode, state)) {
 
			case 1: this->OnOk(); // Enter pressed, confirms change
 
			/* FALL THROUGH */
 
			case 2: delete this; break; // ESC pressed, closes window, abandons changes
 
		}
 
		return cont;
 
		return state;
 
	}
 

	
 
	~QueryStringWindow()
 
	{
 
		if (!this->handled && this->parent != NULL) {
 
			this->handled = true;
 
@@ -1171,28 +1171,28 @@ struct QueryWindow : public Window {
 
			case QUERY_WIDGET_NO:
 
				delete this;
 
				break;
 
		}
 
	}
 

	
 
	virtual bool OnKeyPress(uint16 key, uint16 keycode)
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		/* ESC closes the window, Enter confirms the action */
 
		switch (keycode) {
 
			case WKC_RETURN:
 
			case WKC_NUM_ENTER:
 
				if (this->proc != NULL) {
 
					this->proc(this->parent, true);
 
					this->proc = NULL;
 
				}
 
				/* Fallthrough */
 
			case WKC_ESC:
 
				delete this;
 
				return false;
 
				return ES_HANDLED;
 
		}
 
		return true;
 
		return ES_NOT_HANDLED;
 
	}
 
};
 

	
 

	
 
static const Widget _query_widgets[] = {
 
{  WWT_CLOSEBOX, RESIZE_NONE,  4,   0,  10,   0,  13, STR_00C5,        STR_018B_CLOSE_WINDOW},
 
@@ -1520,26 +1520,26 @@ struct SaveLoadWindow : public QueryStri
 
	{
 
		if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
 
			this->HandleEditBox(10);
 
		}
 
	}
 

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

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

	
 
		return cont;
 
		return state;
 
	}
 

	
 
	virtual void OnTimeout()
 
	{
 
		/* This test protects against using widgets 11 and 12 which are only available
 
		 * in those two saveload mode  */
src/network/network_gui.cpp
Show inline comments
 
@@ -540,35 +540,35 @@ struct NetworkGameWindow : public QueryS
 
	{
 
		if (data != 0) this->server = NULL;
 
		this->servers.flags |= VL_REBUILD;
 
		this->SetDirty();
 
	}
 

	
 
	virtual bool OnKeyPress(uint16 key, uint16 keycode)
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		bool cont = true;
 
		EventState state = ES_NOT_HANDLED;
 
		if (this->field != NGWW_PLAYER) {
 
			if (this->server != NULL) {
 
				if (keycode == WKC_DELETE) { // Press 'delete' to remove servers
 
					NetworkGameListRemoveItem(this->server);
 
					NetworkRebuildHostList();
 
					this->server = NULL;
 
				}
 
			}
 
			return cont;
 
			return state;
 
		}
 

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

	
 
		/* The name is only allowed when it starts with a letter! */
 
		if (StrEmpty(this->edit_str_buf) && this->edit_str_buf[0] != ' ') {
 
			ttd_strlcpy(_network_player_name, this->edit_str_buf, lengthof(_network_player_name));
 
		} else {
 
			ttd_strlcpy(_network_player_name, "Player", lengthof(_network_player_name));
 
		}
 
		return cont;
 
		return state;
 
	}
 

	
 
	virtual void OnQueryTextFinished(char *str)
 
	{
 
		if (!StrEmpty(str)) {
 
			NetworkAddServer(str);
 
@@ -889,22 +889,22 @@ struct NetworkStartServerWindow : public
 

	
 
	virtual void OnMouseLoop()
 
	{
 
		if (this->field == NSSW_GAMENAME) this->HandleEditBox(NSSW_GAMENAME);
 
	}
 

	
 
	virtual bool OnKeyPress(uint16 key, uint16 keycode)
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		bool cont = true;
 
		EventState state = ES_NOT_HANDLED;
 
		if (this->field == NSSW_GAMENAME) {
 
			if (this->HandleEditBoxKey(NSSW_GAMENAME, key, keycode, cont) == 1) return cont; // enter pressed
 
			if (this->HandleEditBoxKey(NSSW_GAMENAME, key, keycode, state) == 1) return state; // enter pressed
 

	
 
			ttd_strlcpy(_network_server_name, this->text.buf, sizeof(_network_server_name));
 
		}
 

	
 
		return cont;
 
		return state;
 
	}
 

	
 
	virtual void OnQueryTextFinished(char *str)
 
	{
 
		if (str == NULL) return;
 

	
 
@@ -1875,27 +1875,27 @@ struct NetworkChatWindow : public QueryS
 

	
 
	virtual void OnMouseLoop()
 
	{
 
		this->HandleEditBox(2);
 
	}
 

	
 
	virtual bool OnKeyPress(uint16 key, uint16 keycode)
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		bool cont = true;
 
		EventState state = ES_NOT_HANDLED;
 
		if (keycode == WKC_TAB) {
 
			ChatTabCompletion();
 
		} else {
 
			_chat_tab_completion_active = false;
 
			switch (this->HandleEditBoxKey(2, key, keycode, cont)) {
 
			switch (this->HandleEditBoxKey(2, key, keycode, state)) {
 
				case 1: /* Return */
 
					SendChat(this->text.buf, this->dtype, this->dest);
 
				/* FALLTHROUGH */
 
				case 2: /* Escape */ delete this; break;
 
			}
 
		}
 
		return cont;
 
		return state;
 
	}
 
};
 

	
 
static const Widget _chat_window_widgets[] = {
 
{   WWT_CLOSEBOX, RESIZE_NONE,  14,   0,  10,  0, 13, STR_00C5,                  STR_018B_CLOSE_WINDOW},
 
{      WWT_PANEL, RESIZE_RIGHT, 14,  11, 319,  0, 13, 0x0,                       STR_NULL}, // background
 
@@ -1982,25 +1982,25 @@ struct NetworkCompanyPasswordWindow : pu
 

	
 
	virtual void OnMouseLoop()
 
	{
 
		this->HandleEditBox(4);
 
	}
 

	
 
	virtual bool OnKeyPress(uint16 key, uint16 keycode)
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		bool cont;
 
		switch (this->HandleEditBoxKey(4, key, keycode, cont)) {
 
		EventState state;
 
		switch (this->HandleEditBoxKey(4, key, keycode, state)) {
 
			case 1: // Return
 
				this->OnOk();
 
				/* FALL THROUGH */
 

	
 
			case 2: // Escape
 
				delete this;
 
				break;
 
		}
 
		return cont;
 
		return state;
 
	}
 
};
 

	
 
static const Widget _ncp_window_widgets[] = {
 
{   WWT_CLOSEBOX, RESIZE_NONE, 14,   0,  10,  0, 13, STR_00C5,                          STR_018B_CLOSE_WINDOW},
 
{    WWT_CAPTION, RESIZE_NONE, 14,  11, 299,  0, 13, STR_COMPANY_PASSWORD_CAPTION,      STR_018C_WINDOW_TITLE_DRAG_THIS},
src/news_gui.cpp
Show inline comments
 
@@ -305,20 +305,20 @@ struct NewsWindow : Window {
 
					}
 
				}
 
				break;
 
		}
 
	}
 

	
 
	virtual bool OnKeyPress(uint16 key, uint16 keycode)
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		if (keycode == WKC_SPACE) {
 
			/* Don't continue. */
 
			delete this;
 
			return false;
 
			return ES_HANDLED;
 
		}
 
		return true;
 
		return ES_NOT_HANDLED;
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		/* The chatbar has notified us that is was either created or closed */
 
		this->chat_height = data;
src/order_gui.cpp
Show inline comments
 
@@ -923,34 +923,34 @@ public:
 
				break;
 
		}
 

	
 
		ResetObjectToPlace();
 
	}
 

	
 
	virtual bool OnKeyPress(uint16 key, uint16 keycode)
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		static const KeyToEvent keytoevent[] = {
 
			{'D', OrderClick_Skip},
 
			{'F', OrderClick_Delete},
 
			{'G', OrderClick_Goto},
 
			{'H', OrderClick_Nonstop},
 
			{'J', OrderClick_FullLoad},
 
			{'K', OrderClick_Unload},
 
			//{'?', OrderClick_Transfer},
 
			//('?', OrderClick_Service},
 
		};
 

	
 
		if (this->vehicle->owner != _local_player) return true;
 
		if (this->vehicle->owner != _local_player) return ES_NOT_HANDLED;
 

	
 
		for (uint i = 0; i < lengthof(keytoevent); i++) {
 
			if (keycode == keytoevent[i].keycode) {
 
				keytoevent[i].proc(this, -1);
 
				return false;
 
				return ES_HANDLED;
 
			}
 
		}
 
		return true;
 
		return ES_NOT_HANDLED;
 
	}
 

	
 
	virtual void OnPlaceObject(Point pt, TileIndex tile)
 
	{
 
		if (this->goto_type == OPOS_GOTO) {
 
			/* check if we're clicking on a vehicle first.. clone orders in that case. */
src/querystring_gui.h
Show inline comments
 
@@ -14,25 +14,25 @@ struct QueryString {
 
	const char *orig;
 
	CharSetFilter afilter;
 
	bool handled;
 

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

	
 
struct QueryStringBaseWindow : public Window, public QueryString {
 
	char edit_str_buf[64];
 
	char orig_str_buf[64];
 

	
 
	QueryStringBaseWindow(const WindowDesc *desc, WindowNumber window_number = 0) : Window(desc, window_number)
 
	{
 
	}
 

	
 
	void DrawEditBox(int wid);
 
	void HandleEditBox(int wid);
 
	int HandleEditBoxKey(int wid, uint16 key, uint16 keycode, bool &cont);
 
	int HandleEditBoxKey(int wid, uint16 key, uint16 keycode, EventState &state);
 
};
 

	
 
void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button, int cancel, int ok);
 

	
 
#endif /* QUERYSTRING_GUI_H */
src/signs_gui.cpp
Show inline comments
 
@@ -252,25 +252,25 @@ struct SignWindow : QueryStringBaseWindo
 
			case QUERY_EDIT_SIGN_WIDGET_CANCEL:
 
				delete this;
 
				break;
 
		}
 
	}
 

	
 
	virtual bool OnKeyPress(uint16 key, uint16 keycode)
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		bool cont = true;
 
		switch (this->HandleEditBoxKey(QUERY_EDIT_SIGN_WIDGET_TEXT, key, keycode, cont)) {
 
		EventState state = ES_NOT_HANDLED;
 
		switch (this->HandleEditBoxKey(QUERY_EDIT_SIGN_WIDGET_TEXT, key, keycode, state)) {
 
			case 1: // Enter pressed, confirms change
 
				RenameSign(this->cur_sign, this->text.buf);
 
				/* FALL THROUGH */
 

	
 
			case 2: // ESC pressed, closes window, abandons changes
 
				delete this;
 
				break;
 
		}
 
		return cont;
 
		return state;
 
	}
 

	
 
	virtual void OnMouseLoop()
 
	{
 
		this->HandleEditBox(QUERY_EDIT_SIGN_WIDGET_TEXT);
 
	}
src/window.cpp
Show inline comments
 
@@ -65,32 +65,32 @@ void Window::OnPaint()
 
{
 
	WindowEvent e;
 
	e.event = WE_PAINT;
 
	this->HandleWindowEvent(&e);
 
}
 

	
 
bool Window::OnKeyPress(uint16 key, uint16 keycode)
 
Window::EventState Window::OnKeyPress(uint16 key, uint16 keycode)
 
{
 
	WindowEvent e;
 
	e.event = WE_KEYPRESS;
 
	e.we.keypress.key     = key;
 
	e.we.keypress.keycode = keycode;
 
	e.we.keypress.cont    = true;
 
	this->HandleWindowEvent(&e);
 

	
 
	return e.we.keypress.cont;
 
	return e.we.keypress.cont ? ES_NOT_HANDLED : ES_HANDLED;
 
}
 

	
 
bool Window::OnCTRLStateChange()
 
Window::EventState Window::OnCTRLStateChange()
 
{
 
	WindowEvent e;
 
	e.event = WE_CTRL_CHANGED;
 
	e.we.ctrl.cont = true;
 
	this->HandleWindowEvent(&e);
 

	
 
	return e.we.ctrl.cont;
 
	return e.we.ctrl.cont ? ES_NOT_HANDLED : ES_HANDLED;
 
}
 

	
 
void Window::OnClick(Point pt, int widget)
 
{
 
	WindowEvent e;
 
	e.event = WE_CLICK;
 
@@ -1799,14 +1799,13 @@ void HandleKeypress(uint32 raw_key)
 
				w->window_class != WC_GENERATE_LANDSCAPE &&
 
				w->window_class != WC_CONSOLE &&
 
				w->window_class != WC_SAVELOAD &&
 
				w->window_class != WC_COMPANY_PASSWORD_WINDOW) {
 
			continue;
 
		}
 
		;
 
		if (!w->OnKeyPress(key, keycode)) return;
 
		if (w->OnKeyPress(key, keycode) == Window::ES_HANDLED) return;
 
	}
 

	
 
	Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
 
	/* When there is no toolbar w is null, check for that */
 
	if (w != NULL) w->OnKeyPress(key, keycode);
 
}
 
@@ -1816,13 +1815,13 @@ void HandleKeypress(uint32 raw_key)
 
 */
 
void HandleCtrlChanged()
 
{
 
	/* Call the event, start with the uppermost window. */
 
	for (Window* const *wz = _last_z_window; wz != _z_windows;) {
 
		Window *w = *--wz;
 
		if (!w->OnCTRLStateChange()) break;
 
		if (w->OnCTRLStateChange() == Window::ES_HANDLED) return;
 
	}
 
}
 

	
 
/**
 
 * Local counter that is incremented each time an mouse input event is detected.
 
 * The counter is used to stop auto-scrolling.
src/window_gui.h
Show inline comments
 
@@ -263,12 +263,17 @@ struct ViewportData : ViewPort {
 
};
 

	
 
/**
 
 * Data structure for an opened window
 
 */
 
struct Window : ZeroedMemoryAllocator {
 
	enum EventState {
 
		ES_HANDLED,
 
		ES_NOT_HANDLED,
 
	};
 

	
 
private:
 
	WindowProc *wndproc;   ///< Event handler function for the window. Do not use directly, call HandleWindowEvent() instead.
 
	void HandleWindowEvent(WindowEvent *e);
 

	
 
protected:
 
	void Initialize(int x, int y, int min_width, int min_height,
 
@@ -342,23 +347,23 @@ public:
 

	
 

	
 
	/**
 
	 * A key has been pressed.
 
	 * @param key     the Unicode value of the key.
 
	 * @param keycode the untranslated key code including shift state.
 
	 * @return true if the key press has been handled and no other
 
	 * @return ES_HANDLED if the key press has been handled and no other
 
	 *         window should receive the event.
 
	 */
 
	virtual bool OnKeyPress(uint16 key, uint16 keycode);
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode);
 

	
 
	/**
 
	 * The state of the control key has changed
 
	 * @return true if the change has been handled and no other
 
	 * @return ES_HANDLED if the change has been handled and no other
 
	 *         window should receive the event.
 
	 */
 
	virtual bool OnCTRLStateChange();
 
	virtual EventState OnCTRLStateChange();
 

	
 

	
 
	/**
 
	 * A click with the left mouse button has been made on the window.
 
	 * @param pt     the point inside the window that has been clicked.
 
	 * @param widget the clicked widget.
0 comments (0 inline, 0 general)