mirror of https://github.com/OpenTTD/OpenTTD
(svn r17903) -Codechange: don't get a modifiable NWidget from a const Window
parent
87ea1f1dcd
commit
3bc0a4ed3e
|
@ -855,7 +855,7 @@ void Window::DrawSortButtonState(int widget, SortButtonState state) const
|
||||||
top = this->widget[widget].top;
|
top = this->widget[widget].top;
|
||||||
} else {
|
} else {
|
||||||
assert(this->nested_array != NULL);
|
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);
|
base = offset + nwid->pos_x + (_dynlang.text_dir == TD_LTR ? nwid->current_x - WD_SORTBUTTON_ARROW_WIDTH : 0);
|
||||||
top = nwid->pos_y;
|
top = nwid->pos_y;
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,9 +308,9 @@ public:
|
||||||
void SetDataTip(uint16 widget_data, StringID tool_tip);
|
void SetDataTip(uint16 widget_data, StringID tool_tip);
|
||||||
|
|
||||||
inline void SetLowered(bool lowered);
|
inline void SetLowered(bool lowered);
|
||||||
inline bool IsLowered();
|
inline bool IsLowered() const;
|
||||||
inline void SetDisabled(bool disabled);
|
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);
|
void StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl);
|
||||||
/* virtual */ void FillNestedArray(NWidgetBase **array, uint length);
|
/* virtual */ void FillNestedArray(NWidgetBase **array, uint length);
|
||||||
|
@ -335,7 +335,7 @@ inline void NWidgetCore::SetLowered(bool lowered)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return whether the widget is lowered. */
|
/** Return whether the widget is lowered. */
|
||||||
inline bool NWidgetCore::IsLowered()
|
inline bool NWidgetCore::IsLowered() const
|
||||||
{
|
{
|
||||||
return HasBit(this->disp_flags, NDB_LOWERED);
|
return HasBit(this->disp_flags, NDB_LOWERED);
|
||||||
}
|
}
|
||||||
|
@ -350,7 +350,7 @@ inline void NWidgetCore::SetDisabled(bool disabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return whether the widget is disabled. */
|
/** Return whether the widget is disabled. */
|
||||||
inline bool NWidgetCore::IsDisabled()
|
inline bool NWidgetCore::IsDisabled() const
|
||||||
{
|
{
|
||||||
return HasBit(this->disp_flags, NDB_DISABLED);
|
return HasBit(this->disp_flags, NDB_DISABLED);
|
||||||
}
|
}
|
||||||
|
|
|
@ -389,7 +389,9 @@ public:
|
||||||
Window *z_back; ///< The window behind us in z-order.
|
Window *z_back; ///< The window behind us in z-order.
|
||||||
|
|
||||||
template <class NWID>
|
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);
|
void InitNested(const WindowDesc *desc, WindowNumber number = 0);
|
||||||
|
@ -847,7 +849,7 @@ public:
|
||||||
* @return The requested widget if it is instantiated, \c NULL otherwise.
|
* @return The requested widget if it is instantiated, \c NULL otherwise.
|
||||||
*/
|
*/
|
||||||
template <class NWID>
|
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;
|
if (widnum >= this->nested_array_size || this->nested_array[widnum] == NULL) return NULL;
|
||||||
NWID *nwid = dynamic_cast<NWID *>(this->nested_array[widnum]);
|
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. */
|
/** Specialized case of #Window::GetWidget for the nested widget base class. */
|
||||||
template <>
|
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;
|
if (widnum >= this->nested_array_size) return NULL;
|
||||||
return this->nested_array[widnum];
|
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.
|
* Base class for windows opened from a toolbar.
|
||||||
|
|
Loading…
Reference in New Issue