diff --git a/src/console_gui.cpp b/src/console_gui.cpp index 916a2ec74f..0555f25c6b 100644 --- a/src/console_gui.cpp +++ b/src/console_gui.cpp @@ -374,6 +374,11 @@ struct IConsoleWindow : Window this->Scroll(-wheel); } + void OnFocus() override + { + VideoDriver::GetInstance()->EditBoxGainedFocus(); + } + void OnFocusLost() override { VideoDriver::GetInstance()->EditBoxLostFocus(); diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp index b774c7ba6e..d7d853c1f2 100644 --- a/src/video/video_driver.hpp +++ b/src/video/video_driver.hpp @@ -93,6 +93,11 @@ public: */ virtual void EditBoxLostFocus() {} + /** + * An edit box gained the input focus + */ + virtual void EditBoxGainedFocus() {} + /** * Get the currently active instance of the video driver. */ diff --git a/src/window.cpp b/src/window.cpp index 25e4eb95a8..c25751fbb6 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -499,11 +499,20 @@ bool Window::SetFocusedWidget(int widget_index) if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus(); } this->nested_focus = this->GetWidget(widget_index); + if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxGainedFocus(); return true; } /** - * Called when window looses focus + * Called when window gains focus + */ +void Window::OnFocus() +{ + if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxGainedFocus(); +} + +/** + * Called when window loses focus */ void Window::OnFocusLost() { diff --git a/src/window_gui.h b/src/window_gui.h index db42cafcd4..a7e28cf787 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -592,10 +592,7 @@ public: */ virtual void SetStringParameters(int widget) const {} - /** - * Called when window gains focus - */ - virtual void OnFocus() {} + virtual void OnFocus(); virtual void OnFocusLost();