diff a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -1405,14 +1405,15 @@ /** * Handler for global hotkeys of the AIDebugWindow. * @param hotkey Hotkey - * @return ES_HANDLED if hotkey was accepted. + * @return HES_NORMAL_HANDLED if the hotkey was handled as there are no tool hotkeys in this window, HES_NOT_HANDLED otherwise. */ -static EventState AIDebugGlobalHotkeys(int hotkey) +static HotkeyEventState AIDebugGlobalHotkeys(int hotkey) { - if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED; + if (_game_mode != GM_NORMAL) return HES_NOT_HANDLED; Window *w = ShowAIDebugWindow(INVALID_COMPANY); - if (w == NULL) return ES_NOT_HANDLED; - return w->OnHotkey(hotkey); + if (w == NULL) return HES_NOT_HANDLED; + w->OnHotkey(hotkey); + return HES_NORMAL_HANDLED; } static Hotkey aidebug_hotkeys[] = { diff a/src/airport_gui.cpp b/src/airport_gui.cpp --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -141,13 +141,13 @@ /** * Handler for global hotkeys of the BuildAirToolbarWindow. * @param hotkey Hotkey - * @return ES_HANDLED if hotkey was accepted. + * @return The return value of OnHotkey (normally HES_TOOL_HANDLED if the key was handled because there are only tool hotkeys in this window), or HES_NOT_HANDLED if the hotkey could not be handled. */ -static EventState AirportToolbarGlobalHotkeys(int hotkey) +static HotkeyEventState AirportToolbarGlobalHotkeys(int hotkey) { - if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) return ES_NOT_HANDLED; + if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) return HES_NOT_HANDLED; Window *w = ShowBuildAirToolbar(); - if (w == NULL) return ES_NOT_HANDLED; + if (w == NULL) return HES_NOT_HANDLED; return w->OnHotkey(hotkey); } diff a/src/dock_gui.cpp b/src/dock_gui.cpp --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -272,13 +272,13 @@ /** * Handler for global hotkeys of the BuildDocksToolbarWindow. * @param hotkey Hotkey - * @return ES_HANDLED if hotkey was accepted. + * @return The return value of OnHotkey (normally HES_TOOL_HANDLED if the key was handled because there are only tool hotkeys in this window), or HES_NOT_HANDLED if the hotkey could not be handled. */ -static EventState DockToolbarGlobalHotkeys(int hotkey) +static HotkeyEventState DockToolbarGlobalHotkeys(int hotkey) { - if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED; + if (_game_mode != GM_NORMAL) return HES_NOT_HANDLED; Window *w = ShowBuildDocksToolbar(); - if (w == NULL) return ES_NOT_HANDLED; + if (w == NULL) return HES_NOT_HANDLED; return w->OnHotkey(hotkey); } diff a/src/hotkeys.cpp b/src/hotkeys.cpp --- a/src/hotkeys.cpp +++ b/src/hotkeys.cpp @@ -355,7 +355,7 @@ int hotkey = -1; hotkey = (*list)->CheckMatch(keycode, hotkey, true); - if (hotkey >= 0 && ((*list)->global_hotkey_handler(hotkey) == ES_HANDLED)) return; + if (hotkey >= 0 && ((*list)->global_hotkey_handler(hotkey) != HES_NOT_HANDLED)) return; } } diff a/src/hotkeys.h b/src/hotkeys.h --- a/src/hotkeys.h +++ b/src/hotkeys.h @@ -39,7 +39,7 @@ * List of hotkeys for a window. */ struct HotkeyList { - typedef EventState (*GlobalHotkeyHandlerFunc)(int hotkey); + typedef HotkeyEventState (*GlobalHotkeyHandlerFunc)(int hotkey); HotkeyList(const char *ini_group, Hotkey *items, GlobalHotkeyHandlerFunc global_hotkey_handler = NULL); ~HotkeyList(); diff a/src/main_gui.cpp b/src/main_gui.cpp --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -280,45 +280,45 @@ } } - virtual EventState OnHotkey(int hotkey) + virtual HotkeyEventState OnHotkey(int hotkey) { if (hotkey == GHK_QUIT) { HandleExitGameRequest(); - return ES_HANDLED; + return HES_NORMAL_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 (HasModalProgress()) return ES_NOT_HANDLED; + if (HasModalProgress()) return HES_NOT_HANDLED; switch (hotkey) { case GHK_ABANDON: /* No point returning from the main menu to itself */ - if (_game_mode == GM_MENU) return ES_HANDLED; + if (_game_mode == GM_MENU) return HES_NORMAL_HANDLED; if (_settings_client.gui.autosave_on_exit) { DoExitSave(); _switch_mode = SM_MENU; } else { AskExitToGameMenu(); } - return ES_HANDLED; + return HES_NORMAL_HANDLED; case GHK_CONSOLE: IConsoleSwitch(); - return ES_HANDLED; + return HES_NORMAL_HANDLED; case GHK_BOUNDING_BOXES: ToggleBoundingBoxes(); - return ES_HANDLED; + return HES_NORMAL_HANDLED; case GHK_DIRTY_BLOCKS: ToggleDirtyBlocks(); - return ES_HANDLED; + return HES_NORMAL_HANDLED; } - if (_game_mode == GM_MENU) return ES_NOT_HANDLED; + if (_game_mode == GM_MENU) return HES_NOT_HANDLED; switch (hotkey) { case GHK_CENTER: @@ -415,9 +415,9 @@ break; #endif - default: return ES_NOT_HANDLED; + default: return HES_NOT_HANDLED; } - return ES_HANDLED; + return HES_NORMAL_HANDLED; } virtual void OnScroll(Point delta) diff a/src/order_gui.cpp b/src/order_gui.cpp --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -1445,14 +1445,16 @@ } } - virtual EventState OnHotkey(int hotkey) + virtual HotkeyEventState OnHotkey(int hotkey) { - if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED; + if (this->vehicle->owner != _local_company) return HES_NOT_HANDLED; switch (hotkey) { case OHK_SKIP: this->OrderClick_Skip(); break; case OHK_DELETE: this->OrderClick_Delete(); break; - case OHK_GOTO: this->OrderClick_Goto(); break; + case OHK_GOTO: + this->OrderClick_Goto(); + return HES_TOOL_HANDLED; case OHK_NONSTOP: this->OrderClick_Nonstop(-1); break; case OHK_FULLLOAD: this->OrderClick_FullLoad(-1); break; case OHK_UNLOAD: this->OrderClick_Unload(-1); break; @@ -1461,9 +1463,9 @@ case OHK_TRANSFER: this->OrderHotkey_Transfer(); break; case OHK_NO_UNLOAD: this->OrderHotkey_NoUnload(); break; case OHK_NO_LOAD: this->OrderHotkey_NoLoad(); break; - default: return ES_NOT_HANDLED; + default: return HES_NOT_HANDLED; } - return ES_HANDLED; + return HES_NORMAL_HANDLED; } virtual void OnPlaceObject(Point pt, TileIndex tile) diff a/src/rail_gui.cpp b/src/rail_gui.cpp --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -597,7 +597,7 @@ if (_ctrl_pressed) RailToolbar_CtrlChanged(this); } - virtual EventState OnHotkey(int hotkey) + virtual HotkeyEventState OnHotkey(int hotkey) { MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection return Window::OnHotkey(hotkey); @@ -758,14 +758,14 @@ /** * Handler for global hotkeys of the BuildRailToolbarWindow. * @param hotkey Hotkey - * @return ES_HANDLED if hotkey was accepted. + * @return The return value of OnHotkey (normally HES_TOOL_HANDLED if the key was handled because there are only tool hotkeys in this window), or HES_NOT_HANDLED if the hotkey could not be handled. */ -static EventState RailToolbarGlobalHotkeys(int hotkey) +static HotkeyEventState RailToolbarGlobalHotkeys(int hotkey) { - if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_TRAIN)) return ES_NOT_HANDLED; + if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_TRAIN)) return HES_NOT_HANDLED; extern RailType _last_built_railtype; Window *w = ShowBuildRailToolbar(_last_built_railtype); - if (w == NULL) return ES_NOT_HANDLED; + if (w == NULL) return HES_NOT_HANDLED; return w->OnHotkey(hotkey); } diff a/src/road_gui.cpp b/src/road_gui.cpp --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -473,7 +473,7 @@ if (_ctrl_pressed) RoadToolbar_CtrlChanged(this); } - virtual EventState OnHotkey(int hotkey) + virtual HotkeyEventState OnHotkey(int hotkey) { MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection return Window::OnHotkey(hotkey); @@ -663,9 +663,9 @@ /** * Handler for global hotkeys of the BuildRoadToolbarWindow. * @param hotkey Hotkey - * @return ES_HANDLED if hotkey was accepted. + * @return The return value of OnHotkey (normally HES_TOOL_HANDLED if the key was handled because there are only tool hotkeys in this window), or HES_NOT_HANDLED if the hotkey could not be handled. */ -static EventState RoadToolbarGlobalHotkeys(int hotkey) +static HotkeyEventState RoadToolbarGlobalHotkeys(int hotkey) { Window *w = NULL; switch (_game_mode) { @@ -683,7 +683,7 @@ break; } - if (w == NULL) return ES_NOT_HANDLED; + if (w == NULL) return HES_NOT_HANDLED; return w->OnHotkey(hotkey); } diff a/src/signs_gui.cpp b/src/signs_gui.cpp --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -281,7 +281,7 @@ } } - virtual EventState OnHotkey(int hotkey) + virtual HotkeyEventState OnHotkey(int hotkey) { switch (hotkey) { case SLHK_FOCUS_FILTER_BOX: @@ -290,10 +290,10 @@ break; default: - return ES_NOT_HANDLED; + return HES_NOT_HANDLED; } - return ES_HANDLED; + return HES_NORMAL_HANDLED; } virtual void OnEditboxChanged(int widget) @@ -341,13 +341,13 @@ /** * Handler for global hotkeys of the SignListWindow. * @param hotkey Hotkey - * @return ES_HANDLED if hotkey was accepted. + * @return HES_NORMAL_HANDLED if the hotkey was handled as there are no tool hotkeys in this window, HES_NOT_HANDLED otherwise. */ -static EventState SignListGlobalHotkeys(int hotkey) +static HotkeyEventState SignListGlobalHotkeys(int hotkey) { - if (_game_mode == GM_MENU) return ES_NOT_HANDLED; + if (_game_mode == GM_MENU) return HES_NOT_HANDLED; Window *w = ShowSignList(); - if (w == NULL) return ES_NOT_HANDLED; + if (w == NULL) return HES_NOT_HANDLED; return w->OnHotkey(hotkey); } diff a/src/terraform_gui.cpp b/src/terraform_gui.cpp --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -293,13 +293,13 @@ /** * Handler for global hotkeys of the TerraformToolbarWindow. * @param hotkey Hotkey - * @return ES_HANDLED if hotkey was accepted. + * @return The return value of OnHotkey (normally HES_TOOL_HANDLED if the key was handled because there are only tool hotkeys in this window), or HES_NOT_HANDLED if the hotkey could not be handled. */ -static EventState TerraformToolbarGlobalHotkeys(int hotkey) +static HotkeyEventState TerraformToolbarGlobalHotkeys(int hotkey) { - if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED; + if (_game_mode != GM_NORMAL) return HES_NOT_HANDLED; Window *w = ShowTerraformToolbar(NULL); - if (w == NULL) return ES_NOT_HANDLED; + if (w != NULL) return HES_NOT_HANDLED; return w->OnHotkey(hotkey); } @@ -719,13 +719,13 @@ /** * Handler for global hotkeys of the ScenarioEditorLandscapeGenerationWindow. * @param hotkey Hotkey - * @return ES_HANDLED if hotkey was accepted. + * @return The return value of OnHotkey (normally HES_TOOL_HANDLED if the key was handled because there are only tool hotkeys in this window), or HES_NOT_HANDLED if the hotkey could not be handled. */ -static EventState TerraformToolbarEditorGlobalHotkeys(int hotkey) +static HotkeyEventState TerraformToolbarEditorGlobalHotkeys(int hotkey) { - if (_game_mode != GM_EDITOR) return ES_NOT_HANDLED; + if (_game_mode != GM_EDITOR) return HES_NOT_HANDLED; Window *w = ShowEditorTerraformToolbar(); - if (w == NULL) return ES_NOT_HANDLED; + if (w == NULL) return HES_NOT_HANDLED; return w->OnHotkey(hotkey); } diff a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -1660,7 +1660,7 @@ if (cbf != CBF_NONE) this->last_started_action = cbf; } - virtual EventState OnHotkey(int hotkey) + virtual HotkeyEventState OnHotkey(int hotkey) { switch (hotkey) { case MTHK_PAUSE: ToolbarPauseClick(this); break; @@ -1703,9 +1703,9 @@ case MTHK_CLIENT_LIST: if (_networking) ShowClientList(); break; #endif case MTHK_SIGN_LIST: ShowSignList(); break; - default: return ES_NOT_HANDLED; + default: return HES_NOT_HANDLED; } - return ES_HANDLED; + return HES_NORMAL_HANDLED; } virtual void OnPlaceObject(Point pt, TileIndex tile) @@ -2007,7 +2007,7 @@ if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); } - virtual EventState OnHotkey(int hotkey) + virtual HotkeyEventState OnHotkey(int hotkey) { CallBackFunction cbf = CBF_NONE; switch (hotkey) { @@ -2033,10 +2033,13 @@ case MTEHK_TERRAFORM: ShowEditorTerraformToolbar(); break; case MTEHK_SMALLMAP: ShowSmallMap(); break; case MTEHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break; - default: return ES_NOT_HANDLED; + default: return HES_NOT_HANDLED; } - if (cbf != CBF_NONE) this->last_started_action = cbf; - return ES_HANDLED; + if (cbf != CBF_NONE) { + this->last_started_action = cbf; + return HES_TOOL_HANDLED; + } + return HES_NORMAL_HANDLED; } virtual void OnPlaceObject(Point pt, TileIndex tile) diff a/src/window.cpp b/src/window.cpp --- a/src/window.cpp +++ b/src/window.cpp @@ -472,17 +472,17 @@ /** * A hotkey has been pressed. * @param hotkey Hotkey index, by default a widget index of a button or editbox. - * @return #ES_HANDLED if the key press has been handled, and the hotkey is not unavailable for some reason. + * @return #HES_TOOL_HANDLED if the key press has been handled, and the hotkey is not unavailable for some reason, otherwise HES_NOT_HANDLED. */ -EventState Window::OnHotkey(int hotkey) +HotkeyEventState Window::OnHotkey(int hotkey) { - if (hotkey < 0) return ES_NOT_HANDLED; + if (hotkey < 0) return HES_NOT_HANDLED; NWidgetCore *nw = this->GetWidget(hotkey); - if (nw == NULL || nw->IsDisabled()) return ES_NOT_HANDLED; + if (nw == NULL || nw->IsDisabled()) return HES_NOT_HANDLED; if (nw->type == WWT_EDITBOX) { - if (this->IsShaded()) return ES_NOT_HANDLED; + if (this->IsShaded()) return HES_NOT_HANDLED; /* Focus editbox */ this->SetFocusedWidget(hotkey); @@ -491,7 +491,7 @@ /* Click button */ this->OnClick(Point(), hotkey, 1); } - return ES_HANDLED; + return HES_TOOL_HANDLED; } /** @@ -2486,7 +2486,7 @@ if (w->window_desc->hotkeys != NULL) { int hotkey = -1; hotkey = w->window_desc->hotkeys->CheckMatch(keycode, hotkey); - if (hotkey >= 0 && w->OnHotkey(hotkey) == ES_HANDLED) return; + if (hotkey >= 0 && w->OnHotkey(hotkey) != HES_NOT_HANDLED) return; } if (w->OnKeyPress(key, keycode) == ES_HANDLED) return; } @@ -2497,7 +2497,7 @@ if (w->window_desc->hotkeys != NULL) { int hotkey = -1; hotkey = w->window_desc->hotkeys->CheckMatch(keycode, hotkey); - if (hotkey >= 0 && w->OnHotkey(hotkey) == ES_HANDLED) return; + if (hotkey >= 0 && w->OnHotkey(hotkey) != HES_NOT_HANDLED) return; } if (w->OnKeyPress(key, keycode) == ES_HANDLED) return; } diff a/src/window_gui.h b/src/window_gui.h --- a/src/window_gui.h +++ b/src/window_gui.h @@ -595,7 +595,7 @@ */ virtual EventState OnKeyPress(uint16 key, uint16 keycode) { return ES_NOT_HANDLED; } - virtual EventState OnHotkey(int hotkey); + virtual HotkeyEventState OnHotkey(int hotkey); /** * The state of the control key has changed diff a/src/window_type.h b/src/window_type.h --- a/src/window_type.h +++ b/src/window_type.h @@ -697,4 +697,11 @@ ES_NOT_HANDLED, ///< The passed event is not handled. }; +/** State of handling a hotkey event. */ +enum HotkeyEventState { + HES_TOOL_HANDLED, ///< the hotkey activated a tool. + HES_NORMAL_HANDLED, ///< the hotkey didn't activate a tool. + HES_NOT_HANDLED, ///< the hotkey didn't have any associated action. +}; + #endif /* WINDOW_TYPE_H */