From db7e24e211ce8c72a0ddd3a7094bf24de4777678 Mon Sep 17 00:00:00 2001 From: alberth Date: Sat, 16 May 2009 11:25:19 +0000 Subject: [PATCH] (svn r16317) -Codechange: Generalized finding a widget by type. --- src/window.cpp | 15 +++++++-------- src/window_gui.h | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/window.cpp b/src/window.cpp index dc887a27ae..daaa18d9b5 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -235,15 +235,15 @@ void Window::HandleButtonClick(byte widget) } /** - * Checks if the window has at least one widget of given type + * Return a widget of the requested type from the window. * @param widget_type the widget type to look for */ -bool Window::HasWidgetOfType(WidgetType widget_type) const +const Widget *Window::GetWidgetOfType(WidgetType widget_type) const { for (uint i = 0; i < this->widget_count; i++) { - if (this->widget[i].type == widget_type) return true; + if (this->widget[i].type == widget_type) return &this->widget[i]; } - return false; + return NULL; } static void StartWindowDrag(Window *w); @@ -822,7 +822,7 @@ void Window::Initialize(int x, int y, int min_width, int min_height, /* Give focus to the opened window unless it is the OSK window or a text box * of focused window has focus (so we don't interrupt typing). But if the new * window has a text box, then take focus anyway. */ - if (this->window_class != WC_OSK && (!EditBoxInGlobalFocus() || this->HasWidgetOfType(WWT_EDITBOX))) SetFocusedWindow(this); + if (this->window_class != WC_OSK && (!EditBoxInGlobalFocus() || this->GetWidgetOfType(WWT_EDITBOX) != NULL)) SetFocusedWindow(this); /* Hacky way of specifying always-on-top windows. These windows are * always above other windows because they are moved below them. @@ -1483,9 +1483,8 @@ static bool HandleWindowDragging() } /* Search for the title bar */ - const Widget *t = w->widget; - while (t->type != WWT_CAPTION && t->type != WWT_LAST) t++; - assert(t->type == WWT_CAPTION); + const Widget *t = w->GetWidgetOfType(WWT_CAPTION); + assert(t != NULL); /* The minimum number of pixels of the title bar must be visible * in both the X or Y direction */ diff --git a/src/window_gui.h b/src/window_gui.h index d35faa4416..6f30a49a32 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -376,7 +376,7 @@ public: } void HandleButtonClick(byte widget); - bool HasWidgetOfType(WidgetType widget_type) const; + const Widget *GetWidgetOfType(WidgetType widget_type) const; void RaiseButtons(); void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets, ...);