diff options
author | alberth <alberth@openttd.org> | 2009-09-11 19:12:05 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2009-09-11 19:12:05 +0000 |
commit | afe190a216402e1427fc836a4cf2e13c067a67bd (patch) | |
tree | 85a935cf42403a3445c40fdae2f4c648afa9c660 | |
parent | e1ae20a30740f652906f85c1f82cac85c66e9525 (diff) | |
download | openttd-afe190a216402e1427fc836a4cf2e13c067a67bd.tar.xz |
(svn r17504) -Codechange: un-inlining SetFocusedWidget() as it is not often used.
-rw-r--r-- | src/window.cpp | 36 | ||||
-rw-r--r-- | src/window_gui.h | 38 |
2 files changed, 38 insertions, 36 deletions
diff --git a/src/window.cpp b/src/window.cpp index 9ce9f105d..70fee8754 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -140,6 +140,42 @@ bool EditBoxInGlobalFocus() } /** + * Set focus within this window to the given widget. The function however doesn't change which window has focus. + * @param widget_index Index of the widget in the window to set the focus to. + * @return Focus has changed. + */ +bool Window::SetFocusedWidget(byte widget_index) +{ + if (this->widget != NULL) { + /* Do nothing if widget_index is already focused, or if it wasn't a valid widget. */ + if (widget_index >= this->widget_count || this->widget + widget_index == this->focused_widget) return false; + + if (this->focused_widget != NULL) { + /* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */ + this->InvalidateWidget(this->focused_widget - this->widget); + } + this->focused_widget = &this->widget[widget_index]; + return true; + } + + if (this->nested_array != NULL) { + /* Do nothing if widget_index is already focused, or if it wasn't a valid widget. */ + if (widget_index >= this->nested_array_size) return false; + + assert(this->nested_array[widget_index] != NULL); // Setting focus to a non-existing widget is a bad idea. + if (this->nested_focus != NULL) { + if (this->nested_array[widget_index] == this->nested_focus) return false; + + /* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */ + this->nested_focus->Invalidate(this); + } + this->nested_focus = this->nested_array[widget_index]; + return true; + } + NOT_REACHED(); +} + +/** * Sets the enabled/disabled status of a list of widgets. * By default, widgets are enabled. * On certain conditions, they have to be disabled. diff --git a/src/window_gui.h b/src/window_gui.h index 2e8b12a4a..9a52ae846 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -497,42 +497,6 @@ public: } /** - * Set focus within this window to the given widget. The function however doesn't change which window has focus. - * @param widget_index Index of the widget in the window to set the focus to. - * @return Focus has changed. - */ - inline bool SetFocusedWidget(byte widget_index) - { - if (this->widget != NULL) { - /* Do nothing if widget_index is already focused, or if it wasn't a valid widget. */ - if (widget_index >= this->widget_count || this->widget + widget_index == this->focused_widget) return false; - - if (this->focused_widget != NULL) { - /* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */ - this->InvalidateWidget(this->focused_widget - this->widget); - } - this->focused_widget = &this->widget[widget_index]; - return true; - } - - if (this->nested_array != NULL) { - /* Do nothing if widget_index is already focused, or if it wasn't a valid widget. */ - if (widget_index >= this->nested_array_size) return false; - - assert(this->nested_array[widget_index] != NULL); // Setting focus to a non-existing widget is a bad idea. - if (this->nested_focus != NULL) { - if (this->nested_array[widget_index] == this->nested_focus) return false; - - /* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */ - this->nested_focus->Invalidate(this); - } - this->nested_focus = this->nested_array[widget_index]; - return true; - } - NOT_REACHED(); - } - - /** * Check if given widget is focused within this window * @param widget_index : index of the widget in the window to check * @return true if given widget is the focused window in this window @@ -646,6 +610,8 @@ public: return this->widget[widget_index].right - this->widget[widget_index].left + 1; } + bool SetFocusedWidget(byte widget_index); + void HandleButtonClick(byte widget); const Widget *GetWidgetOfType(WidgetType widget_type) const; |