From f237caff5e53ff7e60bd1b10e57df63a55516e2c Mon Sep 17 00:00:00 2001 From: Areloch Date: Thu, 8 Feb 2018 16:00:11 -0600 Subject: [PATCH] Stabilizes the add/remove behavior of menubars by also tracking the modeless background control the menubars use for proper cleanup as well. Also fixes an issue where the findMenu call wasn't properly translating the incoming string to StringTableEntry. --- Engine/source/gui/core/guiCanvas.cpp | 23 +++++++++++++++-------- Engine/source/gui/core/guiCanvas.h | 1 + Engine/source/gui/editor/guiMenuBar.cpp | 5 +++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Engine/source/gui/core/guiCanvas.cpp b/Engine/source/gui/core/guiCanvas.cpp index 5202e57bf..71a4eb760 100644 --- a/Engine/source/gui/core/guiCanvas.cpp +++ b/Engine/source/gui/core/guiCanvas.cpp @@ -133,7 +133,8 @@ GuiCanvas::GuiCanvas(): GuiControl(), mLastRenderMs(0), mPlatformWindow(NULL), mDisplayWindow(true), - mMenuBarCtrl(NULL) + mMenuBarCtrl(nullptr), + mMenuBackground(nullptr) { setBounds(0, 0, 640, 480); mAwake = true; @@ -296,8 +297,11 @@ void GuiCanvas::setMenuBar(SimObject *obj) mMenuBarCtrl = dynamic_cast(obj); //remove old menubar - if( oldMenuBar ) - Parent::removeObject( oldMenuBar ); + if (oldMenuBar) + { + Parent::removeObject(oldMenuBar); + Parent::removeObject(mMenuBackground); //also remove the modeless wrapper + } // set new menubar if (mMenuBarCtrl) @@ -312,14 +316,17 @@ void GuiCanvas::setMenuBar(SimObject *obj) return; } - GuiControl* menuBackground = new GuiControl(); - menuBackground->registerObject(); + if (mMenuBackground == nullptr) + { + mMenuBackground = new GuiControl(); + mMenuBackground->registerObject(); - menuBackground->setControlProfile(profile); + mMenuBackground->setControlProfile(profile); + } - menuBackground->addObject(mMenuBarCtrl); + mMenuBackground->addObject(mMenuBarCtrl); - Parent::addObject(menuBackground); + Parent::addObject(mMenuBackground); } // update window accelerator keys diff --git a/Engine/source/gui/core/guiCanvas.h b/Engine/source/gui/core/guiCanvas.h index b193bfbf1..f9f4a37af 100644 --- a/Engine/source/gui/core/guiCanvas.h +++ b/Engine/source/gui/core/guiCanvas.h @@ -198,6 +198,7 @@ protected: static CanvasSizeChangeSignal smCanvasSizeChangeSignal; GuiControl *mMenuBarCtrl; + GuiControl* mMenuBackground; public: DECLARE_CONOBJECT(GuiCanvas); diff --git a/Engine/source/gui/editor/guiMenuBar.cpp b/Engine/source/gui/editor/guiMenuBar.cpp index fc9623498..dc168436b 100644 --- a/Engine/source/gui/editor/guiMenuBar.cpp +++ b/Engine/source/gui/editor/guiMenuBar.cpp @@ -1519,9 +1519,10 @@ DefineConsoleMethod(GuiMenuBar, insert, void, (SimObject* pObject, S32 pos), (nu object->insert(pObject, pos); } -DefineConsoleMethod(GuiMenuBar, findMenu, S32, (StringTableEntry barTitle), (""), "(barTitle)") +DefineConsoleMethod(GuiMenuBar, findMenu, S32, (const char* barTitle), (""), "(barTitle)") { - PopupMenu* menu = object->findMenu(barTitle); + StringTableEntry barTitleStr = StringTable->insert(barTitle); + PopupMenu* menu = object->findMenu(barTitleStr); if (menu) return menu->getId();