summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2013-08-05 20:37:02 +0000
committermichi_cc <michi_cc@openttd.org>2013-08-05 20:37:02 +0000
commit13873d2534208ddc4596a9354d23d1e4940339ac (patch)
treec0145e41d56780536e4a15f26eaad1249fe3132c /src
parentb96ef5c758ccb25e2ad780ea06c78c8b39df8ca8 (diff)
downloadopenttd-13873d2534208ddc4596a9354d23d1e4940339ac.tar.xz
(svn r25678) -Codechange: Notify the video driver when an edit box lost (global) focus so it can abort any current input composition.
Diffstat (limited to 'src')
-rw-r--r--src/console_gui.cpp6
-rw-r--r--src/osk_gui.cpp2
-rw-r--r--src/video/video_driver.hpp5
-rw-r--r--src/window.cpp17
-rw-r--r--src/window_gui.h5
5 files changed, 30 insertions, 5 deletions
diff --git a/src/console_gui.cpp b/src/console_gui.cpp
index dc9a0cb79..ce23952d2 100644
--- a/src/console_gui.cpp
+++ b/src/console_gui.cpp
@@ -21,6 +21,7 @@
#include "settings_type.h"
#include "console_func.h"
#include "rev.h"
+#include "video/video_driver.hpp"
#include "widgets/console_widget.h"
@@ -311,6 +312,11 @@ struct IConsoleWindow : Window
{
this->Scroll(-wheel);
}
+
+ virtual void OnFocusLost()
+ {
+ _video_driver->EditBoxLostFocus();
+ }
};
int IConsoleWindow::scroll = 0;
diff --git a/src/osk_gui.cpp b/src/osk_gui.cpp
index 5dafdef11..2516c4dbf 100644
--- a/src/osk_gui.cpp
+++ b/src/osk_gui.cpp
@@ -16,6 +16,7 @@
#include "window_func.h"
#include "gfx_func.h"
#include "querystring_gui.h"
+#include "video/video_driver.hpp"
#include "widgets/osk_widget.h"
@@ -205,6 +206,7 @@ struct OskWindow : public Window {
virtual void OnFocusLost()
{
+ _video_driver->EditBoxLostFocus();
delete this;
}
};
diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp
index 306fe2803..d8249b1f7 100644
--- a/src/video/video_driver.hpp
+++ b/src/video/video_driver.hpp
@@ -73,6 +73,11 @@ public:
{
return true;
}
+
+ /**
+ * An edit box lost the input focus. Abort character compositing if necessary.
+ */
+ virtual void EditBoxLostFocus() {}
};
/** Base of the factory for the video drivers. */
diff --git a/src/window.cpp b/src/window.cpp
index 93a84812c..1ef8afa44 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -35,6 +35,7 @@
#include "statusbar_gui.h"
#include "error.h"
#include "game/game.hpp"
+#include "video/video_driver.hpp"
/** Values for _settings_client.gui.auto_scrolling */
enum ViewportAutoscrolling {
@@ -366,6 +367,8 @@ bool EditBoxInGlobalFocus()
void Window::UnfocusFocusedWidget()
{
if (this->nested_focus != NULL) {
+ if (this->nested_focus->type == WWT_EDITBOX) _video_driver->EditBoxLostFocus();
+
/* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */
this->nested_focus->SetDirty(this);
this->nested_focus = NULL;
@@ -388,12 +391,21 @@ bool Window::SetFocusedWidget(int widget_index)
/* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */
this->nested_focus->SetDirty(this);
+ if (this->nested_focus->type == WWT_EDITBOX) _video_driver->EditBoxLostFocus();
}
this->nested_focus = this->GetWidget<NWidgetCore>(widget_index);
return true;
}
/**
+ * Called when window looses focus
+ */
+void Window::OnFocusLost()
+{
+ if (this->nested_focus != NULL && this->nested_focus->type == WWT_EDITBOX) _video_driver->EditBoxLostFocus();
+}
+
+/**
* Sets the enabled/disabled status of a list of widgets.
* By default, widgets are enabled.
* On certain conditions, they have to be disabled.
@@ -953,7 +965,10 @@ Window::~Window()
if (_last_scroll_window == this) _last_scroll_window = NULL;
/* Make sure we don't try to access this window as the focused window when it doesn't exist anymore. */
- if (_focused_window == this) _focused_window = NULL;
+ if (_focused_window == this) {
+ this->OnFocusLost();
+ _focused_window = NULL;
+ }
this->DeleteChildWindows();
diff --git a/src/window_gui.h b/src/window_gui.h
index ce9c062c6..ade8a3f1d 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -582,10 +582,7 @@ public:
*/
virtual void OnFocus() {}
- /**
- * Called when window looses focus
- */
- virtual void OnFocusLost() {}
+ virtual void OnFocusLost();
/**
* A key has been pressed.