diff options
author | rubidium <rubidium@openttd.org> | 2009-10-30 07:51:33 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-10-30 07:51:33 +0000 |
commit | 3bc0a4ed3ee3b7e7ea084adb431f1afdad52dfad (patch) | |
tree | 8ef956e7e6efb6efd5c0a5a825eaac12149d3441 /src/window_gui.h | |
parent | 87ea1f1dcd16079c064474e298a4931834e5a31e (diff) | |
download | openttd-3bc0a4ed3ee3b7e7ea084adb431f1afdad52dfad.tar.xz |
(svn r17903) -Codechange: don't get a modifiable NWidget from a const Window
Diffstat (limited to 'src/window_gui.h')
-rw-r--r-- | src/window_gui.h | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/window_gui.h b/src/window_gui.h index 2d182ba8b..a78004f89 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -389,7 +389,9 @@ public: Window *z_back; ///< The window behind us in z-order. template <class NWID> - inline NWID *GetWidget(uint widnum) const; + inline const NWID *GetWidget(uint widnum) const; + template <class NWID> + inline NWID *GetWidget(uint widnum); void InitNested(const WindowDesc *desc, WindowNumber number = 0); @@ -847,7 +849,7 @@ public: * @return The requested widget if it is instantiated, \c NULL otherwise. */ template <class NWID> -inline NWID *Window::GetWidget(uint widnum) const +inline NWID *Window::GetWidget(uint widnum) { if (widnum >= this->nested_array_size || this->nested_array[widnum] == NULL) return NULL; NWID *nwid = dynamic_cast<NWID *>(this->nested_array[widnum]); @@ -857,12 +859,23 @@ inline NWID *Window::GetWidget(uint widnum) const /** Specialized case of #Window::GetWidget for the nested widget base class. */ template <> -inline NWidgetBase *Window::GetWidget<NWidgetBase>(uint widnum) const +inline const NWidgetBase *Window::GetWidget<NWidgetBase>(uint widnum) const { if (widnum >= this->nested_array_size) return NULL; return this->nested_array[widnum]; } +/** Get the nested widget with number \a widnum from the nested widget tree. + * @tparam NWID Type of the nested widget. + * @param widnum Widget number of the widget to retrieve. + * @return The requested widget if it is instantiated, \c NULL otherwise. + */ +template <class NWID> +inline const NWID *Window::GetWidget(uint widnum) const +{ + return const_cast<Window *>(this)->GetWidget<NWID>(widnum); +} + /** * Base class for windows opened from a toolbar. |