diff options
-rw-r--r-- | src/widget.cpp | 2 | ||||
-rw-r--r-- | src/widget_type.h | 8 | ||||
-rw-r--r-- | src/window_gui.h | 19 |
3 files changed, 21 insertions, 8 deletions
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<NWidgetBase>(widget); + const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(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 <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. |