1
0
Fork 0

(svn r17903) -Codechange: don't get a modifiable NWidget from a const Window

release/1.0
rubidium 2009-10-30 07:51:33 +00:00
parent 87ea1f1dcd
commit 3bc0a4ed3e
3 changed files with 21 additions and 8 deletions

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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.