summaryrefslogtreecommitdiff
path: root/vcl/source/control/menubtn.cxx
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2024-12-10 08:31:24 +0100
committerMichael Weghorn <m.weghorn@posteo.de>2024-12-10 09:46:24 +0100
commit90d9b6e12f0aa9a569958586832bd4abe9561197 (patch)
treea52c43a282b1dbd90d1dbc33d874eea1c60e351e /vcl/source/control/menubtn.cxx
parent06bc2dfc23da1b8ae6fe690b6d8e3557b7419f1e (diff)
tdf#164072 vcl: Let MenuButton dispose its PopupMenu
The MenuButton usually owns the PopupMenu that gets set via MenuButton::SetPopupMenu, but so far didn't dispose it, i.e. the PopupMenu was never disposed. As far as I understand, that is a preexisting issue, but since commit 6708246e20ce522e673f539369cd38687d2dd16d Author: Michael Weghorn <m.weghorn@posteo.de> Date: Thu Dec 5 11:06:48 2024 +0000 tdf#164093 tdf#157001 a11y: Improve menu window disposal , not disposing the menu also means not disposing the menu's MenuFloatingWindow (which gets created when the popup menu shows), resulting in warn:legacy.osl:563630:563630:vcl/source/window/window.cxx:307: Window ( 10MenuButton()) with live SystemWindows destroyed: 18MenuFloatingWindow() Window ( 10MenuButton()) with live SystemWindows destroyed: 18MenuFloatingWindow() and an assert getting triggered as mentioned in tdf#164072 comment 16. Fix this by letting the MenuButton take care of disposing the menu if it is the owner. The only case where the MenuButton is assigned a menu without taking ownership is in SalInstanceComboBox::set_item_menu (which currently only gets called from SvxStyleBox_Base::SetupEntry). In that case, the weld::Menu passed to SalInstanceComboBox::set_item_menu has the ownership: SalInstanceBuilder::weld_menu calls the SalInstanceMenu ctor with a bTakeOwnership=true, and the SalInstanceMenu dtor disposes the menu. Add a `bTakeOwnership` bool param to MenuButton::SetPopupMenu to distinguish between the cases where the PopupMenu is responsible for disposing the menu and where it's not. Change-Id: I32766d5084e4826056ef394a587b8c2e3124c4da Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178197 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'vcl/source/control/menubtn.cxx')
-rw-r--r--vcl/source/control/menubtn.cxx8
1 files changed, 7 insertions, 1 deletions
diff --git a/vcl/source/control/menubtn.cxx b/vcl/source/control/menubtn.cxx
index 28417879888d..1cfd0799fe30 100644
--- a/vcl/source/control/menubtn.cxx
+++ b/vcl/source/control/menubtn.cxx
@@ -166,6 +166,8 @@ void MenuButton::dispose()
{
mpMenuTimer.reset();
mpFloatingWindow.clear();
+ if (mpMenu && mbOwnPopupMenu)
+ mpMenu->dispose();
mpMenu.clear();
PushButton::dispose();
}
@@ -240,12 +242,16 @@ void MenuButton::Select()
maSelectHdl.Call( this );
}
-void MenuButton::SetPopupMenu(PopupMenu* pNewMenu)
+void MenuButton::SetPopupMenu(PopupMenu* pNewMenu, bool bTakeOwnership)
{
if (pNewMenu == mpMenu)
return;
+ if (mpMenu && mbOwnPopupMenu)
+ mpMenu->dispose();
+
mpMenu = pNewMenu;
+ mbOwnPopupMenu = bTakeOwnership;
}
void MenuButton::SetPopover(Window* pWindow)