summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-07-04 09:27:15 +0000
committerfrosch <frosch@openttd.org>2010-07-04 09:27:15 +0000
commit397d1186d731a62ffa39a315f13cbafabee75324 (patch)
tree4b347024b2b5a3855a6f1a7cc26909c0fd06625d
parent26be68ae9823b7a078c8251f70038d98961388bc (diff)
downloadopenttd-397d1186d731a62ffa39a315f13cbafabee75324.tar.xz
(svn r20071) -Codechange: Consistently return the toolbar window for ShowBuildXxxToolbar().
-rw-r--r--src/airport_gui.cpp17
-rw-r--r--src/dock_gui.cpp26
-rw-r--r--src/gui.h10
-rw-r--r--src/rail_gui.cpp13
-rw-r--r--src/rail_gui.h2
-rw-r--r--src/terraform_gui.cpp2
6 files changed, 47 insertions, 23 deletions
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<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
+ return AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
}
EventState AirportToolbarGlobalHotkeys(uint16 key, uint16 keycode)
{
int num = CheckHotkeyMatch<BuildAirToolbarWindow>(_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<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
+ return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
}
EventState DockToolbarGlobalHotkeys(uint16 key, uint16 keycode)
{
int num = CheckHotkeyMatch<BuildDocksToolbarWindow>(_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<BuildDocksToolbarWindow>(&_build_docks_scen_toolbar_desc, TRANSPORT_WATER);
+ return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_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<BuildRailToolbarWindow>(_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<TerraformToolbarWindow>(_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<ScenarioEditorLandscapeGenerationWindow>(_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);
}