From 116c77c342d0f628235a7f5dbacfbb5bc3fb0829 Mon Sep 17 00:00:00 2001 From: alberth Date: Sat, 19 Sep 2009 11:31:12 +0000 Subject: (svn r17572) -Codechange: Use the Window::GetWidget() function to access nested widgets through the nested_array. --- src/window_gui.h | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'src/window_gui.h') diff --git a/src/window_gui.h b/src/window_gui.h index 13deb83a0..e697a344a 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -391,13 +391,17 @@ public: const Widget *focused_widget; ///< Currently focused widget, or \c NULL if no widget has focus. const NWidgetCore *nested_focus; ///< Currently focused nested widget, or \c NULL if no nested widget has focus. NWidgetBase *nested_root; ///< Root of the nested tree. - NWidgetCore **nested_array; ///< Array of pointers into the tree. + NWidgetBase **nested_array; ///< Array of pointers into the tree. Do not access directly, use #Window::GetWidget() instead. uint nested_array_size; ///< Size of the nested array. Window *parent; ///< Parent window. Window *z_front; ///< The window in front of us in z-order. Window *z_back; ///< The window behind us in z-order. + template + inline NWID *GetWidget(uint widnum) const; + + void InitNested(const WindowDesc *desc, WindowNumber number = 0); void CreateNestedTree(const WindowDesc *desc, bool fill_nested = true); void FinishInitNested(const WindowDesc *desc, WindowNumber window_number); @@ -417,7 +421,7 @@ public: } if (this->nested_array != NULL) { assert(widget_index < this->nested_array_size); - if (this->nested_array[widget_index] != NULL) this->nested_array[widget_index]->SetDisabled(disab_stat); + if (this->nested_array[widget_index] != NULL) this->GetWidget(widget_index)->SetDisabled(disab_stat); } } @@ -448,7 +452,7 @@ public: { if (this->nested_array != NULL) { assert(widget_index < this->nested_array_size); - return this->nested_array[widget_index]->IsDisabled(); + return this->GetWidget(widget_index)->IsDisabled(); } assert(widget_index < this->widget_count); return HasBit(this->widget[widget_index].display_flags, WIDG_DISABLED); @@ -531,7 +535,7 @@ public: } if (this->nested_array != NULL) { assert(widget_index < this->nested_array_size); - this->nested_array[widget_index]->SetLowered(lowered_stat); + this->GetWidget(widget_index)->SetLowered(lowered_stat); } } @@ -547,8 +551,8 @@ public: } if (this->nested_array != NULL) { assert(widget_index < this->nested_array_size); - bool lowered_state = this->nested_array[widget_index]->IsLowered(); - this->nested_array[widget_index]->SetLowered(!lowered_state); + bool lowered_state = this->GetWidget(widget_index)->IsLowered(); + this->GetWidget(widget_index)->SetLowered(!lowered_state); } } @@ -579,7 +583,7 @@ public: { if (this->nested_array != NULL) { assert(widget_index < this->nested_array_size); - return this->nested_array[widget_index]->IsLowered(); + return this->GetWidget(widget_index)->IsLowered(); } assert(widget_index < this->widget_count); return HasBit(this->widget[widget_index].display_flags, WIDG_LOWERED); @@ -838,6 +842,29 @@ public: /*** End of the event handling ***/ }; +/** 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 NWID *Window::GetWidget(uint widnum) const +{ + if (widnum >= this->nested_array_size || this->nested_array[widnum] == NULL) return NULL; + NWID *nwid = dynamic_cast(this->nested_array[widnum]); + assert(nwid != NULL); + return nwid; +} + +/** Specialized case of #Window::GetWidget for the nested widget base class. */ +template <> +inline NWidgetBase *Window::GetWidget(uint widnum) const +{ + if (widnum >= this->nested_array_size) return NULL; + return this->nested_array[widnum]; +} + + /** * Base class for windows opened from a toolbar. */ -- cgit v1.2.3-54-g00ecf