diff options
author | alberth <alberth@openttd.org> | 2009-05-16 11:25:19 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2009-05-16 11:25:19 +0000 |
commit | db7e24e211ce8c72a0ddd3a7094bf24de4777678 (patch) | |
tree | 4ae9044dfec3db872aa45d06ede58f84a8679e17 /src | |
parent | c299a38e1f33464fd8c521915bc2391623b56971 (diff) | |
download | openttd-db7e24e211ce8c72a0ddd3a7094bf24de4777678.tar.xz |
(svn r16317) -Codechange: Generalized finding a widget by type.
Diffstat (limited to 'src')
-rw-r--r-- | src/window.cpp | 15 | ||||
-rw-r--r-- | src/window_gui.h | 2 |
2 files changed, 8 insertions, 9 deletions
diff --git a/src/window.cpp b/src/window.cpp index dc887a27a..daaa18d9b 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 d35faa441..6f30a49a3 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, ...); |