From 3bc0a4ed3ee3b7e7ea084adb431f1afdad52dfad Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 30 Oct 2009 07:51:33 +0000 Subject: (svn r17903) -Codechange: don't get a modifiable NWidget from a const Window --- src/widget.cpp | 2 +- src/widget_type.h | 8 ++++---- src/window_gui.h | 19 ++++++++++++++++--- 3 files changed, 21 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/widget.cpp b/src/widget.cpp index 880a94ae5..befc94da3 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -855,7 +855,7 @@ void Window::DrawSortButtonState(int widget, SortButtonState state) const top = this->widget[widget].top; } else { assert(this->nested_array != NULL); - NWidgetBase *nwid = this->GetWidget(widget); + const NWidgetBase *nwid = this->GetWidget(widget); base = offset + nwid->pos_x + (_dynlang.text_dir == TD_LTR ? nwid->current_x - WD_SORTBUTTON_ARROW_WIDTH : 0); top = nwid->pos_y; } diff --git a/src/widget_type.h b/src/widget_type.h index e655a465f..f273b2250 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -308,9 +308,9 @@ public: void SetDataTip(uint16 widget_data, StringID tool_tip); inline void SetLowered(bool lowered); - inline bool IsLowered(); + inline bool IsLowered() const; inline void SetDisabled(bool disabled); - inline bool IsDisabled(); + inline bool IsDisabled() const; void StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl); /* virtual */ void FillNestedArray(NWidgetBase **array, uint length); @@ -335,7 +335,7 @@ inline void NWidgetCore::SetLowered(bool lowered) } /** Return whether the widget is lowered. */ -inline bool NWidgetCore::IsLowered() +inline bool NWidgetCore::IsLowered() const { return HasBit(this->disp_flags, NDB_LOWERED); } @@ -350,7 +350,7 @@ inline void NWidgetCore::SetDisabled(bool disabled) } /** Return whether the widget is disabled. */ -inline bool NWidgetCore::IsDisabled() +inline bool NWidgetCore::IsDisabled() const { return HasBit(this->disp_flags, NDB_DISABLED); } 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 - inline NWID *GetWidget(uint widnum) const; + inline const NWID *GetWidget(uint widnum) const; + template + 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 -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(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(uint widnum) const +inline const NWidgetBase *Window::GetWidget(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 +inline const NWID *Window::GetWidget(uint widnum) const +{ + return const_cast(this)->GetWidget(widnum); +} + /** * Base class for windows opened from a toolbar. -- cgit v1.2.3-54-g00ecf