From 397d1186d731a62ffa39a315f13cbafabee75324 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 4 Jul 2010 09:27:15 +0000 Subject: (svn r20071) -Codechange: Consistently return the toolbar window for ShowBuildXxxToolbar(). --- src/airport_gui.cpp | 17 ++++++++++++----- src/dock_gui.cpp | 26 +++++++++++++++++++------- src/gui.h | 10 ++++++---- src/rail_gui.cpp | 13 +++++++------ src/rail_gui.h | 2 +- src/terraform_gui.cpp | 2 ++ 6 files changed, 47 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index 4e2b5712b..01f421753 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -168,20 +168,27 @@ static const WindowDesc _air_toolbar_desc( _nested_air_toolbar_widgets, lengthof(_nested_air_toolbar_widgets) ); -void ShowBuildAirToolbar() +/** + * Open the build airport toolbar window + * + * If the terraform toolbar is linked to the toolbar, that window is also opened. + * + * @return newly opened airport toolbar, or NULL if the toolbar could not be opened. + */ +Window *ShowBuildAirToolbar() { - if (!Company::IsValidID(_local_company)) return; + if (!Company::IsValidID(_local_company)) return NULL; DeleteWindowByClass(WC_BUILD_TOOLBAR); - AllocateWindowDescFront(&_air_toolbar_desc, TRANSPORT_AIR); + return AllocateWindowDescFront(&_air_toolbar_desc, TRANSPORT_AIR); } EventState AirportToolbarGlobalHotkeys(uint16 key, uint16 keycode) { int num = CheckHotkeyMatch(_airtoolbar_hotkeys, keycode, NULL, true); if (num == -1) return ES_NOT_HANDLED; - ShowBuildAirToolbar(); - Window *w = FindWindowByClass(WC_BUILD_TOOLBAR); + Window *w = ShowBuildAirToolbar(); + if (w == NULL) return ES_NOT_HANDLED; return w->OnKeyPress(key, keycode); } diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp index 54756608f..d50d14fab 100644 --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -294,20 +294,27 @@ static const WindowDesc _build_docks_toolbar_desc( _nested_build_docks_toolbar_widgets, lengthof(_nested_build_docks_toolbar_widgets) ); -void ShowBuildDocksToolbar() +/** + * Open the build water toolbar window + * + * If the terraform toolbar is linked to the toolbar, that window is also opened. + * + * @return newly opened water toolbar, or NULL if the toolbar could not be opened. + */ +Window *ShowBuildDocksToolbar() { - if (!Company::IsValidID(_local_company)) return; + if (!Company::IsValidID(_local_company)) return NULL; DeleteWindowByClass(WC_BUILD_TOOLBAR); - AllocateWindowDescFront(&_build_docks_toolbar_desc, TRANSPORT_WATER); + return AllocateWindowDescFront(&_build_docks_toolbar_desc, TRANSPORT_WATER); } EventState DockToolbarGlobalHotkeys(uint16 key, uint16 keycode) { int num = CheckHotkeyMatch(_dockstoolbar_hotkeys, keycode, NULL, true); if (num == -1) return ES_NOT_HANDLED; - ShowBuildDocksToolbar(); - Window *w = FindWindowByClass(WC_BUILD_TOOLBAR); + Window *w = ShowBuildDocksToolbar(); + if (w == NULL) return ES_NOT_HANDLED; return w->OnKeyPress(key, keycode); } @@ -339,9 +346,14 @@ static const WindowDesc _build_docks_scen_toolbar_desc( _nested_build_docks_scen_toolbar_widgets, lengthof(_nested_build_docks_scen_toolbar_widgets) ); -void ShowBuildDocksScenToolbar() +/** + * Open the build water toolbar window for the scenario editor. + * + * @return newly opened water toolbar, or NULL if the toolbar could not be opened. + */ +Window *ShowBuildDocksScenToolbar() { - AllocateWindowDescFront(&_build_docks_scen_toolbar_desc, TRANSPORT_WATER); + return AllocateWindowDescFront(&_build_docks_scen_toolbar_desc, TRANSPORT_WATER); } /** Widget numbers of the build-dock GUI. */ diff --git a/src/gui.h b/src/gui.h index 5caa110b2..30867d830 100644 --- a/src/gui.h +++ b/src/gui.h @@ -19,6 +19,8 @@ #include "strings_type.h" #include "transport_type.h" +struct Window; + /* main_gui.cpp */ void HandleOnEditText(const char *str); void InitializeGUI(); @@ -33,11 +35,11 @@ void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clic void ShowOrdersWindow(const Vehicle *v); /* dock_gui.cpp */ -void ShowBuildDocksToolbar(); -void ShowBuildDocksScenToolbar(); +Window *ShowBuildDocksToolbar(); +Window *ShowBuildDocksScenToolbar(); -/* aircraft_gui.cpp */ -void ShowBuildAirToolbar(); +/* airport_gui.cpp */ +Window *ShowBuildAirToolbar(); /* tgp_gui.cpp */ void ShowGenerateLandscape(); diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 8d206389c..1cd17d441 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -898,16 +898,17 @@ static const WindowDesc _build_rail_desc( * If the terraform toolbar is linked to the toolbar, that window is also opened. * * @param railtype Rail type to open the window for + * @return newly opened rail toolbar, or NULL if the toolbar could not be opened. */ -void ShowBuildRailToolbar(RailType railtype) +Window *ShowBuildRailToolbar(RailType railtype) { - if (!Company::IsValidID(_local_company)) return; - if (!ValParamRailtype(railtype)) return; + if (!Company::IsValidID(_local_company)) return NULL; + if (!ValParamRailtype(railtype)) return NULL; DeleteWindowByClass(WC_BUILD_TOOLBAR); _cur_railtype = railtype; - BuildRailToolbarWindow *w = new BuildRailToolbarWindow(&_build_rail_desc, TRANSPORT_RAIL, railtype); _remove_button_clicked = false; + return new BuildRailToolbarWindow(&_build_rail_desc, TRANSPORT_RAIL, railtype); } EventState RailToolbarGlobalHotkeys(uint16 key, uint16 keycode) @@ -915,8 +916,8 @@ EventState RailToolbarGlobalHotkeys(uint16 key, uint16 keycode) extern RailType _last_built_railtype; int num = CheckHotkeyMatch(_railtoolbar_hotkeys, keycode, NULL, true); if (num == -1) return ES_NOT_HANDLED; - ShowBuildRailToolbar(_last_built_railtype); - Window *w = FindWindowByClass(WC_BUILD_TOOLBAR); + Window *w = ShowBuildRailToolbar(_last_built_railtype); + if (w == NULL) return ES_NOT_HANDLED; return w->OnKeyPress(key, keycode); } diff --git a/src/rail_gui.h b/src/rail_gui.h index 9d124036b..fc9a7d48e 100644 --- a/src/rail_gui.h +++ b/src/rail_gui.h @@ -14,7 +14,7 @@ #include "rail_type.h" -void ShowBuildRailToolbar(RailType railtype); +Window *ShowBuildRailToolbar(RailType railtype); void ReinitGuiAfterToggleElrail(bool disable); bool ResetSignalVariant(int32 = 0); void InitializeRailGUI(); diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp index 7d708c2fe..cc4e58e73 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -360,6 +360,7 @@ EventState TerraformToolbarGlobalHotkeys(uint16 key, uint16 keycode) int num = CheckHotkeyMatch(_terraform_hotkeys, keycode, NULL, true); if (num == -1) return ES_NOT_HANDLED; Window *w = ShowTerraformToolbar(NULL); + if (w == NULL) return ES_NOT_HANDLED; return w->OnKeyPress(key, keycode); } @@ -769,5 +770,6 @@ EventState TerraformToolbarEditorGlobalHotkeys(uint16 key, uint16 keycode) int num = CheckHotkeyMatch(_terraform_editor_hotkeys, keycode, NULL, true); if (num == -1) return ES_NOT_HANDLED; Window *w = ShowEditorTerraformToolbar(); + if (w == NULL) return ES_NOT_HANDLED; return w->OnKeyPress(key, keycode); } -- cgit v1.2.3-70-g09d2