summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMaxim Monastirsky <momonasmon@gmail.com>2016-10-30 14:34:18 +0200
committerMaxim Monastirsky <momonasmon@gmail.com>2016-10-30 15:50:31 +0200
commit94876fe2704cb5107234ad76c86122ac9d95f866 (patch)
treed55701606099ce3db9f3b051166a4ba33fb58e7f /vcl
parent99da628e17e873a5fa2f726e7a1732b21c3d4b33 (diff)
Let Menu dispose submenus
(I'm not sure about how good are the changes from ScopedVclPtr to non-scoped, and disposeAndClear to clear. They aren't really needed, because of the VclReferenceBase::mbDisposed logic. But at least they should be safe, as long as we have disposeOnce calls in Menu's dtor.) See also previous commits: 4433d95b374c13a3501cdf3a6e273f68eb49873a ("MenuItemData now properly disposes the submenu") 89c23b4aaef931b5d6009efaf44ce6e6c976e8d4 ("Sub menus no longer need manual disposing") Change-Id: I9d455a94590f5eec9b097947f6984f1b3e477b52
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/window/menu.cxx17
-rw-r--r--vcl/workben/vcldemo.cxx9
2 files changed, 10 insertions, 16 deletions
diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx
index cd1b3fd9498c..fbc6ac1eb40a 100644
--- a/vcl/source/window/menu.cxx
+++ b/vcl/source/window/menu.cxx
@@ -578,8 +578,7 @@ void Menu::RemoveItem( sal_uInt16 nPos )
ImplCallEventListeners( VCLEVENT_MENU_REMOVEITEM, nPos );
}
-void ImplCopyItem( Menu* pThis, const Menu& rMenu, sal_uInt16 nPos, sal_uInt16 nNewPos,
- sal_uInt16 nMode = 0 )
+void ImplCopyItem( Menu* pThis, const Menu& rMenu, sal_uInt16 nPos, sal_uInt16 nNewPos )
{
MenuItemType eType = rMenu.GetItemType( nPos );
@@ -621,13 +620,8 @@ void ImplCopyItem( Menu* pThis, const Menu& rMenu, sal_uInt16 nPos, sal_uInt16 n
if ( pSubMenu )
{
// create auto-copy
- if ( nMode == 1 )
- {
- VclPtr<PopupMenu> pNewMenu = VclPtr<PopupMenu>::Create( *pSubMenu );
- pThis->SetPopupMenu( nId, pNewMenu );
- }
- else
- pThis->SetPopupMenu( nId, pSubMenu );
+ VclPtr<PopupMenu> pNewMenu = VclPtr<PopupMenu>::Create( *pSubMenu );
+ pThis->SetPopupMenu( nId, pNewMenu );
}
}
}
@@ -790,6 +784,9 @@ void Menu::SetPopupMenu( sal_uInt16 nItemId, PopupMenu* pMenu )
if ( static_cast<PopupMenu*>(pData->pSubMenu.get()) == pMenu )
return;
+ // remove old menu
+ pData->pSubMenu.disposeAndClear();
+
// data exchange
pData->pSubMenu = pMenu;
@@ -1203,7 +1200,7 @@ Menu& Menu::operator=( const Menu& rMenu )
// copy items
sal_uInt16 nCount = rMenu.GetItemCount();
for ( sal_uInt16 i = 0; i < nCount; i++ )
- ImplCopyItem( this, rMenu, i, MENU_APPEND, 1 );
+ ImplCopyItem( this, rMenu, i, MENU_APPEND );
nDefaultItem = rMenu.nDefaultItem;
aActivateHdl = rMenu.aActivateHdl;
diff --git a/vcl/workben/vcldemo.cxx b/vcl/workben/vcldemo.cxx
index e1b65851edcf..5458bb4799fd 100644
--- a/vcl/workben/vcldemo.cxx
+++ b/vcl/workben/vcldemo.cxx
@@ -1813,8 +1813,6 @@ public:
class DemoWidgets : public WorkWindow
{
VclPtr<MenuBar> mpBar;
- VclPtr<PopupMenu> mpPopup;
-
VclPtr<VclBox> mpBox;
VclPtr<ToolBox> mpToolbox;
VclPtr<PushButton> mpButton;
@@ -1869,9 +1867,9 @@ public:
mpBar = VclPtr<MenuBar>::Create();
mpBar->InsertItem(0,"File");
- mpPopup = VclPtr<PopupMenu>::Create();
- mpPopup->InsertItem(0,"Item");
- mpBar->SetPopupMenu(0, mpPopup);
+ VclPtrInstance<PopupMenu> pPopup;
+ pPopup->InsertItem(0,"Item");
+ mpBar->SetPopupMenu(0, pPopup);
SetMenuBar(mpBar);
Show();
@@ -1886,7 +1884,6 @@ public:
mpToolbox.disposeAndClear();
mpButton.disposeAndClear();
mpBox.disposeAndClear();
- mpPopup.disposeAndClear();
mpBar.disposeAndClear();
WorkWindow::dispose();
}