Index: ps/trunk/source/gui/CGUI.h =================================================================== --- ps/trunk/source/gui/CGUI.h +++ ps/trunk/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" @@ -288,6 +289,11 @@ 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. * Index: ps/trunk/source/gui/CGUI.cpp =================================================================== --- ps/trunk/source/gui/CGUI.cpp +++ ps/trunk/source/gui/CGUI.cpp @@ -423,6 +423,15 @@ 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) Index: ps/trunk/source/gui/GUIManager.cpp =================================================================== --- ps/trunk/source/gui/GUIManager.cpp +++ ps/trunk/source/gui/GUIManager.cpp @@ -103,7 +103,12 @@ 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 @@ { // 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 @@ 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)