summaryrefslogtreecommitdiff
path: root/src/window_gui.h
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2009-05-30 12:41:53 +0000
committeralberth <alberth@openttd.org>2009-05-30 12:41:53 +0000
commit101a6b332064fca3fd8692360375020fcfd69324 (patch)
tree51712da823d1a48992d335045b240352ffe7e8fc /src/window_gui.h
parentbfaf610fff372d6c4b0cdd887ec1997b97e8d25f (diff)
downloadopenttd-101a6b332064fca3fd8692360375020fcfd69324.tar.xz
(svn r16467) -Codechange: Unduplicate setting of widget focus (with thanks to Smatz).
Diffstat (limited to 'src/window_gui.h')
-rw-r--r--src/window_gui.h16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/window_gui.h b/src/window_gui.h
index b035a9cfc..6f819cf28 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -266,16 +266,20 @@ 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 void SetFocusedWidget(byte widget_index)
+ inline bool SetFocusedWidget(byte widget_index)
{
- if (widget_index < this->widget_count) {
+ 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. */
- if (this->focused_widget != NULL && this->focused_widget - this->widget != widget_index) {
- this->InvalidateWidget(this->focused_widget - this->widget);
- }
- this->focused_widget = &this->widget[widget_index];
+ this->InvalidateWidget(this->focused_widget - this->widget);
}
+ this->focused_widget = &this->widget[widget_index];
+ return true;
}
/**