diff options
author | rubidium <rubidium@openttd.org> | 2008-05-17 23:11:06 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-05-17 23:11:06 +0000 |
commit | d284ba228327b83b74a5bf2448406f9021f67c8b (patch) | |
tree | cdbaf12f7c5a7666ecc23983c51dca268e3b58e2 /src | |
parent | b101faea201219afd52f6a743dad244c1c33b991 (diff) | |
download | openttd-d284ba228327b83b74a5bf2448406f9021f67c8b.tar.xz |
(svn r13151) -Codechange: use an enum instead of bool as return type of OnKeyPress/OnCTRLStateChange to make it obvious what the return values mean.
Diffstat (limited to 'src')
-rw-r--r-- | src/bridge_gui.cpp | 6 | ||||
-rw-r--r-- | src/console.cpp | 6 | ||||
-rw-r--r-- | src/depot_gui.cpp | 4 | ||||
-rw-r--r-- | src/genworld_gui.cpp | 8 | ||||
-rw-r--r-- | src/main_gui.cpp | 16 | ||||
-rw-r--r-- | src/misc_gui.cpp | 40 | ||||
-rw-r--r-- | src/network/network_gui.cpp | 34 | ||||
-rw-r--r-- | src/news_gui.cpp | 6 | ||||
-rw-r--r-- | src/order_gui.cpp | 8 | ||||
-rw-r--r-- | src/querystring_gui.h | 4 | ||||
-rw-r--r-- | src/signs_gui.cpp | 8 | ||||
-rw-r--r-- | src/window.cpp | 13 | ||||
-rw-r--r-- | src/window_gui.h | 13 |
13 files changed, 85 insertions, 81 deletions
diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp index 4686ac59b..b19571599 100644 --- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -121,16 +121,16 @@ public: } } - 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) diff --git a/src/console.cpp b/src/console.cpp index 8a01f7786..20464a71f 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -126,7 +126,7 @@ struct IConsoleWindow : Window 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: @@ -230,10 +230,10 @@ struct IConsoleWindow : Window IConsoleResetHistoryPos(); this->SetDirty(); } else { - return true; + return ES_NOT_HANDLED; } } - return false; + return ES_HANDLED; } }; diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 14d90acd6..ef4947d34 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -961,14 +961,14 @@ struct DepotWindow : Window { 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; } }; diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index ba6f1f3d2..446762959 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -470,17 +470,17 @@ struct GenerateLandscapeWindow : public QueryStringBaseWindow { 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) diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 7fd97015d..36cda036b 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -239,34 +239,34 @@ struct MainWindow : Window } } - 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': @@ -372,9 +372,9 @@ struct MainWindow : Window break; #endif - default: return true; + default: return ES_NOT_HANDLED; } - return false; + return ES_HANDLED; } virtual void OnScroll(Point delta) diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index dadbff049..3eb985d9f 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -412,11 +412,11 @@ public: _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; } }; @@ -883,9 +883,9 @@ bool HandleCaret(Textbuf *tb) 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; @@ -913,7 +913,7 @@ int QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode 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; } } @@ -963,9 +963,9 @@ void QueryString::DrawEditBox(Window *w, int wid) _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) @@ -1038,15 +1038,15 @@ struct QueryStringWindow : public QueryStringBaseWindow 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() @@ -1174,7 +1174,7 @@ struct QueryWindow : public Window { } } - virtual bool OnKeyPress(uint16 key, uint16 keycode) + virtual EventState OnKeyPress(uint16 key, uint16 keycode) { /* ESC closes the window, Enter confirms the action */ switch (keycode) { @@ -1187,9 +1187,9 @@ struct QueryWindow : public Window { /* Fallthrough */ case WKC_ESC: delete this; - return false; + return ES_HANDLED; } - return true; + return ES_NOT_HANDLED; } }; @@ -1523,20 +1523,20 @@ struct SaveLoadWindow : public QueryStringBaseWindow { } } - 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() diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index f433eddbd..d92ee5aac 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -543,9 +543,9 @@ struct NetworkGameWindow : public QueryStringBaseWindow { 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 @@ -554,10 +554,10 @@ struct NetworkGameWindow : public QueryStringBaseWindow { 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] != ' ') { @@ -565,7 +565,7 @@ struct NetworkGameWindow : public QueryStringBaseWindow { } else { ttd_strlcpy(_network_player_name, "Player", lengthof(_network_player_name)); } - return cont; + return state; } virtual void OnQueryTextFinished(char *str) @@ -892,16 +892,16 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow { 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) @@ -1878,21 +1878,21 @@ struct NetworkChatWindow : public QueryStringBaseWindow { 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; } }; @@ -1985,10 +1985,10 @@ struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow { 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 */ @@ -1997,7 +1997,7 @@ struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow { delete this; break; } - return cont; + return state; } }; diff --git a/src/news_gui.cpp b/src/news_gui.cpp index 5f7faa26d..06b1e1905 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -308,14 +308,14 @@ struct NewsWindow : Window { } } - 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) diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 301e57374..82c0cbb3e 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -926,7 +926,7 @@ public: ResetObjectToPlace(); } - virtual bool OnKeyPress(uint16 key, uint16 keycode) + virtual EventState OnKeyPress(uint16 key, uint16 keycode) { static const KeyToEvent keytoevent[] = { {'D', OrderClick_Skip}, @@ -939,15 +939,15 @@ public: //('?', 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) diff --git a/src/querystring_gui.h b/src/querystring_gui.h index 8df54d1b2..004501b31 100644 --- a/src/querystring_gui.h +++ b/src/querystring_gui.h @@ -17,7 +17,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, bool &cont); + int HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, Window::EventState &state); }; struct QueryStringBaseWindow : public Window, public QueryString { @@ -30,7 +30,7 @@ struct QueryStringBaseWindow : public Window, public QueryString { 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); diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp index 63fb571b1..15568528a 100644 --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -255,10 +255,10 @@ struct SignWindow : QueryStringBaseWindow { } } - 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 */ @@ -267,7 +267,7 @@ struct SignWindow : QueryStringBaseWindow { delete this; break; } - return cont; + return state; } virtual void OnMouseLoop() diff --git a/src/window.cpp b/src/window.cpp index b728fed28..5d791d807 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -68,7 +68,7 @@ void Window::OnPaint() this->HandleWindowEvent(&e); } -bool Window::OnKeyPress(uint16 key, uint16 keycode) +Window::EventState Window::OnKeyPress(uint16 key, uint16 keycode) { WindowEvent e; e.event = WE_KEYPRESS; @@ -77,17 +77,17 @@ bool Window::OnKeyPress(uint16 key, uint16 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) @@ -1802,8 +1802,7 @@ void HandleKeypress(uint32 raw_key) 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); @@ -1819,7 +1818,7 @@ 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; } } diff --git a/src/window_gui.h b/src/window_gui.h index 70c6d0e86..3b8e792b6 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -266,6 +266,11 @@ 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); @@ -345,17 +350,17 @@ 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(); /** |