From fefde41317169389a2ee840f394d44e0ae12b869 Mon Sep 17 00:00:00 2001 From: bb Date: Thu, 3 Mar 2022 11:36:08 +0000 Subject: [PATCH] Allied chat opens with t bug (on linux) Comments By: vladislav, elexis Solution Proposed By: elexis fixes #5194 refs #3870 Differential Revision: D1386 This was SVN commit r26530. --- source/gui/CGUI.cpp | 9 +++++++++ source/gui/CGUI.h | 6 ++++++ source/gui/GUIManager.cpp | 18 +++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index 1d38295557..96f646a57e 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -423,6 +423,15 @@ CSize2D CGUI::GetWindowSize() const return CSize2D{static_cast(g_xres) / g_VideoMode.GetScale(), static_cast(g_yres) / g_VideoMode.GetScale() }; } +void CGUI::SendFocusMessage(EGUIMessageType msgType) +{ + if (m_FocusedObject) + { + SGUIMessage msg(msgType); + m_FocusedObject->HandleMessage(msg); + } +} + void CGUI::SetFocusedObject(IGUIObject* pObject) { if (pObject == m_FocusedObject) diff --git a/source/gui/CGUI.h b/source/gui/CGUI.h index 5a906018cd..d1b9cd8c31 100644 --- a/source/gui/CGUI.h +++ b/source/gui/CGUI.h @@ -26,6 +26,7 @@ #include "gui/GUITooltip.h" #include "gui/SettingTypes/CGUIColor.h" #include "gui/SGUIIcon.h" +#include "gui/SGUIMessage.h" #include "gui/SGUIStyle.h" #include "lib/input.h" #include "maths/Rect.h" @@ -287,6 +288,11 @@ public: */ void SetFocusedObject(IGUIObject* pObject); + /** + * Alert the focussed object of this GUIPage that the focus of the page has changed. + */ + void SendFocusMessage(EGUIMessageType msg); + /** * Reads a string value and modifies the given value of type T if successful. * Does not change the value upon conversion failure. diff --git a/source/gui/GUIManager.cpp b/source/gui/GUIManager.cpp index 51e6e7d0b5..055421c119 100644 --- a/source/gui/GUIManager.cpp +++ b/source/gui/GUIManager.cpp @@ -103,7 +103,12 @@ void CGUIManager::SwitchPage(const CStrW& pageName, const ScriptInterface* srcSc initDataClone = Script::WriteStructuredClone(rq, initData); } - m_PageStack.clear(); + if (!m_PageStack.empty()) + { + // Make sure we unfocus anything on the current page. + m_PageStack.back().gui->SendFocusMessage(GUIM_LOST_FOCUS); + m_PageStack.clear(); + } PushPage(pageName, initDataClone, JS::UndefinedHandleValue); } @@ -112,8 +117,13 @@ void CGUIManager::PushPage(const CStrW& pageName, Script::StructuredClone initDa { // Store the callback handler in the current GUI page before opening the new one if (!m_PageStack.empty() && !callbackFunction.isUndefined()) + { m_PageStack.back().SetCallbackFunction(*m_ScriptInterface, callbackFunction); + // Make sure we unfocus anything on the current page. + m_PageStack.back().gui->SendFocusMessage(GUIM_LOST_FOCUS); + } + // Push the page prior to loading its contents, because that may push // another GUI page on init which should be pushed on top of this new page. m_PageStack.emplace_back(pageName, initData); @@ -128,8 +138,14 @@ void CGUIManager::PopPage(Script::StructuredClone args) return; } + // Make sure we unfocus anything on the current page. + m_PageStack.back().gui->SendFocusMessage(GUIM_LOST_FOCUS); + m_PageStack.pop_back(); m_PageStack.back().PerformCallbackFunction(args); + + // We return to a page where some object might have been focused. + m_PageStack.back().gui->SendFocusMessage(GUIM_GOT_FOCUS); } CGUIManager::SGUIPage::SGUIPage(const CStrW& pageName, const Script::StructuredClone initData)