diff options
author | Noel Grandin <noel@peralex.com> | 2016-06-20 15:56:35 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-06-23 06:28:00 +0000 |
commit | aa0d0536a444fb26d9e570bd6bf6c1bdc3596cf3 (patch) | |
tree | 8b2a5207e77fa4054a37b33c25378c23a00af8ed /framework | |
parent | b722f3d6fc72877e8caaaae7291d5d736ddc494d (diff) |
tdf#97527 - vcl: reference-count Menu
some places are marked with "dodgy"- need to check those to see
what is going on, because they are leaving dangling pointers behind
in the Menu class
Change-Id: I41d5c7c0fec2f70ce9e3ffdc48cd03d26c0a869b
Reviewed-on: https://gerrit.libreoffice.org/26516
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'framework')
-rw-r--r-- | framework/inc/classes/rootactiontriggercontainer.hxx | 2 | ||||
-rw-r--r-- | framework/inc/uielement/generictoolbarcontroller.hxx | 2 | ||||
-rw-r--r-- | framework/inc/uielement/menubarmanager.hxx | 2 | ||||
-rw-r--r-- | framework/inc/uielement/menubarmerger.hxx | 2 | ||||
-rw-r--r-- | framework/source/fwe/classes/addonmenu.cxx | 42 | ||||
-rw-r--r-- | framework/source/fwe/helper/actiontriggerhelper.cxx | 2 | ||||
-rw-r--r-- | framework/source/layoutmanager/layoutmanager.cxx | 22 | ||||
-rw-r--r-- | framework/source/uielement/controlmenucontroller.cxx | 8 | ||||
-rw-r--r-- | framework/source/uielement/generictoolbarcontroller.cxx | 13 | ||||
-rw-r--r-- | framework/source/uielement/menubarmanager.cxx | 15 | ||||
-rw-r--r-- | framework/source/uielement/menubarmerger.cxx | 6 | ||||
-rw-r--r-- | framework/source/uielement/menubarwrapper.cxx | 4 | ||||
-rw-r--r-- | framework/source/uielement/togglebuttontoolbarcontroller.cxx | 12 | ||||
-rw-r--r-- | framework/source/uielement/toolbarmanager.cxx | 43 |
14 files changed, 87 insertions, 88 deletions
diff --git a/framework/inc/classes/rootactiontriggercontainer.hxx b/framework/inc/classes/rootactiontriggercontainer.hxx index bc0fa2b204bf..53d009cec6ab 100644 --- a/framework/inc/classes/rootactiontriggercontainer.hxx +++ b/framework/inc/classes/rootactiontriggercontainer.hxx @@ -106,7 +106,7 @@ class FWE_DLLPUBLIC RootActionTriggerContainer : public PropertySetContainer, bool m_bContainerCreated; bool m_bContainerChanged; bool m_bInContainerCreation; - const Menu* m_pMenu; + VclPtr<const Menu> m_pMenu; const OUString* m_pMenuIdentifier; }; diff --git a/framework/inc/uielement/generictoolbarcontroller.hxx b/framework/inc/uielement/generictoolbarcontroller.hxx index 805a232f0dca..69f57f7f5e54 100644 --- a/framework/inc/uielement/generictoolbarcontroller.hxx +++ b/framework/inc/uielement/generictoolbarcontroller.hxx @@ -70,7 +70,7 @@ class GenericToolbarController : public svt::ToolboxController class MenuToolbarController : public GenericToolbarController { css::uno::Reference< css::container::XIndexAccess > m_xMenuDesc; - PopupMenu* pMenu; + VclPtr<PopupMenu> pMenu; css::uno::Reference< css::lang::XComponent > m_xMenuManager; OUString m_aModuleIdentifier; public: diff --git a/framework/inc/uielement/menubarmanager.hxx b/framework/inc/uielement/menubarmanager.hxx index 0405df3afd44..8e30d5dc8c48 100644 --- a/framework/inc/uielement/menubarmanager.hxx +++ b/framework/inc/uielement/menubarmanager.hxx @@ -215,7 +215,7 @@ class MenuBarManager : public css::frame::XStatusListener , bool m_bHasMenuBar; OUString m_aMenuItemCommand; OUString m_aModuleIdentifier; - Menu* m_pVCLMenu; + VclPtr<Menu> m_pVCLMenu; css::uno::Reference< css::frame::XFrame > m_xFrame; css::uno::Reference< css::container::XNameAccess > m_xUICommandLabels; css::uno::Reference< css::frame::XUIControllerFactory > m_xPopupMenuControllerFactory; diff --git a/framework/inc/uielement/menubarmerger.hxx b/framework/inc/uielement/menubarmerger.hxx index 354c0fdb6b9e..1cced9978330 100644 --- a/framework/inc/uielement/menubarmerger.hxx +++ b/framework/inc/uielement/menubarmerger.hxx @@ -51,7 +51,7 @@ enum RPResultInfo struct ReferencePathInfo { - Menu* pPopupMenu; + VclPtr<Menu> pPopupMenu; sal_uInt16 nPos; sal_Int32 nLevel; RPResultInfo eResult; diff --git a/framework/source/fwe/classes/addonmenu.cxx b/framework/source/fwe/classes/addonmenu.cxx index f69ae27ee94b..2e20b304bc0b 100644 --- a/framework/source/fwe/classes/addonmenu.cxx +++ b/framework/source/fwe/classes/addonmenu.cxx @@ -53,14 +53,12 @@ AddonMenu::AddonMenu( const css::uno::Reference< css::frame::XFrame >& rFrame ) AddonMenu::~AddonMenu() { - for ( sal_uInt16 i = 0; i < GetItemCount(); i++ ) - { - if ( GetItemType( i ) != MenuItemType::SEPARATOR ) - { - sal_uInt16 nId = GetItemId( i ); - delete GetPopupMenu( nId ); - } - } + disposeOnce(); +} + +void AddonMenu::dispose() +{ + PopupMenu::dispose(); } // Check if command URL string has the unique prefix to identify addon popup menus @@ -101,36 +99,35 @@ bool AddonMenuManager::HasAddonMenuElements() } // Factory method to create different Add-On menu types -PopupMenu* AddonMenuManager::CreatePopupMenuType( MenuType eMenuType, const Reference< XFrame >& rFrame ) +VclPtr<PopupMenu> AddonMenuManager::CreatePopupMenuType( MenuType eMenuType, const Reference< XFrame >& rFrame ) { if ( eMenuType == ADDON_MENU ) - return new AddonMenu( rFrame ); + return VclPtr<AddonMenu>::Create( rFrame ); else if ( eMenuType == ADDON_POPUPMENU ) - return new AddonPopupMenu( rFrame ); + return VclPtr<AddonPopupMenu>::Create( rFrame ); else return nullptr; } // Create the Add-Ons menu -AddonMenu* AddonMenuManager::CreateAddonMenu( const Reference< XFrame >& rFrame, +VclPtr<AddonMenu> AddonMenuManager::CreateAddonMenu( const Reference< XFrame >& rFrame, const Reference< XComponentContext >& rContext ) { - AddonsOptions aOptions; - AddonMenu* pAddonMenu = nullptr; - sal_uInt16 nUniqueMenuId = ADDONMENU_ITEMID_START; + AddonsOptions aOptions; + VclPtr<AddonMenu> pAddonMenu; + sal_uInt16 nUniqueMenuId = ADDONMENU_ITEMID_START; const Sequence< Sequence< PropertyValue > >& rAddonMenuEntries = aOptions.GetAddonsMenu(); if ( rAddonMenuEntries.getLength() > 0 ) { - pAddonMenu = static_cast<AddonMenu *>(AddonMenuManager::CreatePopupMenuType( ADDON_MENU, rFrame )); + pAddonMenu = static_cast<AddonMenu *>(AddonMenuManager::CreatePopupMenuType( ADDON_MENU, rFrame ).get()); ::rtl::OUString aModuleIdentifier = GetModuleIdentifier( rContext, rFrame ); AddonMenuManager::BuildMenu( pAddonMenu, ADDON_MENU, MENU_APPEND, nUniqueMenuId, rAddonMenuEntries, rFrame, aModuleIdentifier ); // Don't return an empty Add-On menu if ( pAddonMenu->GetItemCount() == 0 ) { - delete pAddonMenu; - pAddonMenu = nullptr; + pAddonMenu.disposeAndClear(); } } @@ -243,7 +240,7 @@ void AddonMenuManager::MergeAddonPopupMenus( const Reference< XFrame >& rFrame, AddonMenuManager::IsCorrectContext( aModuleIdentifier, aContext )) { sal_uInt16 nId = nUniqueMenuId++; - AddonPopupMenu* pAddonPopupMenu = static_cast<AddonPopupMenu *>(AddonMenuManager::CreatePopupMenuType( ADDON_POPUPMENU, rFrame )); + VclPtr<AddonPopupMenu> pAddonPopupMenu = static_cast<AddonPopupMenu *>(AddonMenuManager::CreatePopupMenuType( ADDON_POPUPMENU, rFrame ).get()); AddonMenuManager::BuildMenu( pAddonPopupMenu, ADDON_MENU, MENU_APPEND, nUniqueMenuId, aAddonSubMenu, rFrame, aModuleIdentifier ); @@ -257,7 +254,7 @@ void AddonMenuManager::MergeAddonPopupMenus( const Reference< XFrame >& rFrame, pMergeMenuBar->SetItemCommand( nId, aURL ); } else - delete pAddonPopupMenu; + pAddonPopupMenu.disposeAndClear(); } } } @@ -296,7 +293,7 @@ void AddonMenuManager::BuildMenu( PopupMenu* pCurrent bInsertSeparator = true; else { - PopupMenu* pSubMenu = nullptr; + VclPtr<PopupMenu> pSubMenu; if ( aAddonSubMenu.getLength() > 0 ) { pSubMenu = AddonMenuManager::CreatePopupMenuType( nSubMenuType, rFrame ); @@ -305,8 +302,7 @@ void AddonMenuManager::BuildMenu( PopupMenu* pCurrent // Don't create a menu item for an empty sub menu if ( pSubMenu->GetItemCount() == 0 ) { - delete pSubMenu; - pSubMenu = nullptr; + pSubMenu.disposeAndClear(); continue; } } diff --git a/framework/source/fwe/helper/actiontriggerhelper.cxx b/framework/source/fwe/helper/actiontriggerhelper.cxx index 3749606f7c3f..33a171b22d87 100644 --- a/framework/source/fwe/helper/actiontriggerhelper.cxx +++ b/framework/source/fwe/helper/actiontriggerhelper.cxx @@ -208,7 +208,7 @@ void InsertSubMenuItems( Menu* pSubMenu, sal_uInt16& nItemId, const Reference< X if ( xSubContainer.is() ) { - PopupMenu* pNewSubMenu = new PopupMenu; + VclPtr<PopupMenu> pNewSubMenu = VclPtr<PopupMenu>::Create(); // Sub menu (recursive call CreateSubMenu ) InsertSubMenuItems( pNewSubMenu, nItemId, xSubContainer ); diff --git a/framework/source/layoutmanager/layoutmanager.cxx b/framework/source/layoutmanager/layoutmanager.cxx index 3dfab060f3f4..7d65c33c4c97 100644 --- a/framework/source/layoutmanager/layoutmanager.cxx +++ b/framework/source/layoutmanager/layoutmanager.cxx @@ -208,7 +208,7 @@ void LayoutManager::impl_clearUpMenuBar() } // reset inplace menubar manager - Menu *pMenuBar = nullptr; + VclPtr<Menu> pMenuBar; if (m_pInplaceMenuBar) { pMenuBar = m_pInplaceMenuBar->GetMenuBar(); @@ -219,7 +219,7 @@ void LayoutManager::impl_clearUpMenuBar() m_xInplaceMenuBar->dispose(); m_xInplaceMenuBar.clear(); } - delete pMenuBar; + pMenuBar.disposeAndClear(); Reference< XComponent > xComp( m_xMenuBar, UNO_QUERY ); if ( xComp.is() ) @@ -1150,7 +1150,7 @@ throw (uno::RuntimeException, std::exception) SolarMutexGuard aGuard; // Reset old inplace menubar! - Menu *pOldMenuBar = nullptr; + VclPtr<Menu> pOldMenuBar; if (m_pInplaceMenuBar) { pOldMenuBar = m_pInplaceMenuBar->GetMenuBar(); @@ -1161,7 +1161,7 @@ throw (uno::RuntimeException, std::exception) m_xInplaceMenuBar->dispose(); m_xInplaceMenuBar.clear(); } - delete pOldMenuBar; + pOldMenuBar.disposeAndClear(); m_bInplaceMenuSet = false; @@ -1170,7 +1170,7 @@ throw (uno::RuntimeException, std::exception) OUString aModuleIdentifier; Reference< XDispatchProvider > xDispatchProvider; - MenuBar* pMenuBar = new MenuBar; + VclPtr<MenuBar> pMenuBar = VclPtr<MenuBar>::Create(); m_pInplaceMenuBar = new MenuBarManager( m_xContext, m_xFrame, m_xURLTransformer, xDispatchProvider, aModuleIdentifier, pMenuBar, true, true ); m_pInplaceMenuBar->SetItemContainer( xMergedMenuBar ); @@ -1210,7 +1210,7 @@ throw (uno::RuntimeException) } // Remove inplace menu bar - Menu *pMenuBar = nullptr; + VclPtr<Menu> pMenuBar; if (m_pInplaceMenuBar) { pMenuBar = m_pInplaceMenuBar->GetMenuBar(); @@ -1221,7 +1221,7 @@ throw (uno::RuntimeException) m_xInplaceMenuBar->dispose(); m_xInplaceMenuBar.clear(); } - delete pMenuBar; + pMenuBar.disposeAndClear(); } void SAL_CALL LayoutManager::attachFrame( const Reference< XFrame >& xFrame ) @@ -2830,7 +2830,7 @@ throw( RuntimeException, std::exception ) implts_destroyElements(); impl_clearUpMenuBar(); m_xMenuBar.clear(); - Menu *pMenuBar = nullptr; + VclPtr<Menu> pMenuBar; if (m_pInplaceMenuBar) { pMenuBar = m_pInplaceMenuBar->GetMenuBar(); @@ -2841,7 +2841,7 @@ throw( RuntimeException, std::exception ) m_xInplaceMenuBar->dispose(); m_xInplaceMenuBar.clear(); } - delete pMenuBar; + pMenuBar.disposeAndClear(); m_xContainerWindow.clear(); m_xContainerTopWindow.clear(); @@ -2894,7 +2894,7 @@ throw( RuntimeException, std::exception ) } impl_clearUpMenuBar(); m_xMenuBar.clear(); - Menu *pMenuBar = nullptr; + VclPtr<Menu> pMenuBar; if (m_pInplaceMenuBar) { pMenuBar = m_pInplaceMenuBar->GetMenuBar(); @@ -2905,7 +2905,7 @@ throw( RuntimeException, std::exception ) m_xInplaceMenuBar->dispose(); m_xInplaceMenuBar.clear(); } - delete pMenuBar; + pMenuBar.disposeAndClear(); m_xContainerWindow.clear(); m_xContainerTopWindow.clear(); } diff --git a/framework/source/uielement/controlmenucontroller.cxx b/framework/source/uielement/controlmenucontroller.cxx index 00e91ace4749..f9852acbceab 100644 --- a/framework/source/uielement/controlmenucontroller.cxx +++ b/framework/source/uielement/controlmenucontroller.cxx @@ -233,8 +233,8 @@ private: void updateImagesPopupMenu( PopupMenu* pPopupMenu ); void fillPopupMenu( uno::Reference< awt::XPopupMenu >& rPopupMenu ); - bool m_bShowMenuImages : 1; - PopupMenu* m_pResPopupMenu; + bool m_bShowMenuImages : 1; + VclPtr<PopupMenu> m_pResPopupMenu; UrlToDispatchMap m_aURLToDispatchMap; }; @@ -300,7 +300,7 @@ void SAL_CALL ControlMenuController::disposing( const EventObject& ) throw ( Run if ( m_xPopupMenu.is() ) m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(static_cast<OWeakObject *>(this), UNO_QUERY )); m_xPopupMenu.clear(); - delete m_pResPopupMenu; + m_pResPopupMenu.disposeAndClear(); } // XStatusListener @@ -398,7 +398,7 @@ void ControlMenuController::impl_setPopupMenu() aResId.SetRT( RSC_MENU ); if ( pResMgr->IsAvailable( aResId )) { - m_pResPopupMenu = new PopupMenu( aResId ); + m_pResPopupMenu = VclPtr<PopupMenu>::Create( aResId ); updateImagesPopupMenu( m_pResPopupMenu ); } } diff --git a/framework/source/uielement/generictoolbarcontroller.cxx b/framework/source/uielement/generictoolbarcontroller.cxx index 620462b71fdc..46fd4e0f9799 100644 --- a/framework/source/uielement/generictoolbarcontroller.cxx +++ b/framework/source/uielement/generictoolbarcontroller.cxx @@ -305,10 +305,8 @@ MenuToolbarController::~MenuToolbarController() catch( const Exception& ) {} if ( pMenu ) { - delete pMenu; - pMenu = nullptr; + pMenu.disposeAndClear(); } - } class Toolbarmenu : public ::PopupMenu @@ -316,6 +314,7 @@ class Toolbarmenu : public ::PopupMenu public: Toolbarmenu(); virtual ~Toolbarmenu(); + virtual void dispose() override; }; Toolbarmenu::Toolbarmenu() @@ -325,7 +324,13 @@ Toolbarmenu::Toolbarmenu() Toolbarmenu::~Toolbarmenu() { + disposeOnce(); +} + +void Toolbarmenu::dispose() +{ SAL_INFO("fwk.uielement", "destructing Toolbarmenu " << this); + ::PopupMenu::dispose(); } void SAL_CALL MenuToolbarController::click() throw (RuntimeException, std::exception) @@ -340,7 +345,7 @@ MenuToolbarController::createPopupWindow() throw (css::uno::RuntimeException, st { Reference< XDispatchProvider > xDispatch; Reference< XURLTransformer > xURLTransformer = URLTransformer::create( m_xContext ); - pMenu = new Toolbarmenu(); + pMenu = VclPtr<Toolbarmenu>::Create(); m_xMenuManager.set( new MenuBarManager( m_xContext, m_xFrame, xURLTransformer, xDispatch, m_aModuleIdentifier, pMenu, true, true, false ) ); if (m_xMenuManager.is()) { diff --git a/framework/source/uielement/menubarmanager.cxx b/framework/source/uielement/menubarmanager.cxx index 3007e8a44102..3f1d1c26c66e 100644 --- a/framework/source/uielement/menubarmanager.cxx +++ b/framework/source/uielement/menubarmanager.cxx @@ -250,8 +250,7 @@ void MenuBarManager::Destroy() if ( m_bDeleteMenu ) { - delete m_pVCLMenu; - m_pVCLMenu = nullptr; + m_pVCLMenu.disposeAndClear(); } } } @@ -1190,7 +1189,7 @@ void MenuBarManager::FillMenuManager( Menu* pMenu, const Reference< XFrame >& rF Reference< XDispatch > xDispatch; Reference< XStatusListener > xStatusListener; - PopupMenu* pPopup = pMenu->GetPopupMenu( nItemId ); + VclPtr<PopupMenu> pPopup = pMenu->GetPopupMenu( nItemId ); bool bItemShowMenuImages = m_bShowMenuImages; // overwrite the show icons on menu option? if (!bItemShowMenuImages) @@ -1223,7 +1222,7 @@ void MenuBarManager::FillMenuManager( Menu* pMenu, const Reference< XFrame >& rF pItemHandler->xPopupMenu.set( static_cast<OWeakObject *>(pVCLXPopupMenu), UNO_QUERY ); pItemHandler->aMenuItemURL = aItemCommand; m_aMenuItemHandlerVector.push_back( pItemHandler ); - delete pPopup; + pPopup.disposeAndClear(); if ( bAccessibilityEnabled ) { @@ -1258,7 +1257,7 @@ void MenuBarManager::FillMenuManager( Menu* pMenu, const Reference< XFrame >& rF AddonMenuManager::HasAddonMenuElements() ) { // Create addon popup menu if there exist elements and this is the tools popup menu - AddonMenu* pSubMenu = AddonMenuManager::CreateAddonMenu(rFrame, m_xContext); + VclPtr<AddonMenu> pSubMenu = AddonMenuManager::CreateAddonMenu(rFrame, m_xContext); if ( pSubMenu && ( pSubMenu->GetItemCount() > 0 )) { sal_uInt16 nCount = 0; @@ -1275,12 +1274,12 @@ void MenuBarManager::FillMenuManager( Menu* pMenu, const Reference< XFrame >& rF pPopup->SetItemCommand( ITEMID_ADDONLIST, aNewItemCommand ); } else - delete pSubMenu; + pSubMenu.disposeAndClear(); } if ( nItemId == ITEMID_ADDONLIST ) { - AddonMenu* pSubMenu = dynamic_cast< AddonMenu* >( pPopup ); + AddonMenu* pSubMenu = dynamic_cast< AddonMenu* >( pPopup.get() ); if ( pSubMenu ) { MenuBarManager* pSubMenuManager = new MenuBarManager( m_xContext, m_xFrame, m_xURLTransformer,pSubMenu, true, false, false ); @@ -1672,7 +1671,7 @@ void MenuBarManager::FillMenu( if ( xIndexContainer.is() ) { - PopupMenu* pNewPopupMenu = new PopupMenu; + VclPtr<PopupMenu> pNewPopupMenu = VclPtr<PopupMenu>::Create(); pMenu->SetPopupMenu( nId, pNewPopupMenu ); if ( xDispatchProvider.is() ) diff --git a/framework/source/uielement/menubarmerger.cxx b/framework/source/uielement/menubarmerger.cxx index 47514143a0dd..8adb19f0b28e 100644 --- a/framework/source/uielement/menubarmerger.cxx +++ b/framework/source/uielement/menubarmerger.cxx @@ -180,7 +180,7 @@ bool MenuBarMerger::CreateSubMenu( pSubMenu->SetItemCommand( nItemId, rMenuItem.aURL ); if ( !rMenuItem.aSubMenu.empty() ) { - PopupMenu* pPopupMenu = new PopupMenu(); + VclPtr<PopupMenu> pPopupMenu = VclPtr<PopupMenu>::Create(); pSubMenu->SetPopupMenu( nItemId, pPopupMenu ); ++nItemId; @@ -221,7 +221,7 @@ bool MenuBarMerger::MergeMenuItems( pMenu->SetItemCommand( nItemId, rMenuItem.aURL ); if ( !rMenuItem.aSubMenu.empty() ) { - PopupMenu* pSubMenu = new PopupMenu(); + VclPtr<PopupMenu> pSubMenu = VclPtr<PopupMenu>::Create(); pMenu->SetPopupMenu( nItemId, pSubMenu ); ++nItemId; @@ -352,7 +352,7 @@ bool MenuBarMerger::ProcessFallbackOperation( const OUString aCmd( rReferencePath[nLevel] ); sal_uInt16 nInsPos( MENU_APPEND ); - PopupMenu* pPopupMenu( new PopupMenu ); + VclPtr<PopupMenu> pPopupMenu = VclPtr<PopupMenu>::Create(); if ( bFirstLevel && ( aRefPathInfo.eResult == RP_MENUITEM_INSTEAD_OF_POPUPMENU_FOUND )) { diff --git a/framework/source/uielement/menubarwrapper.cxx b/framework/source/uielement/menubarwrapper.cxx index 1d202720884f..d420fa14d8b4 100644 --- a/framework/source/uielement/menubarwrapper.cxx +++ b/framework/source/uielement/menubarwrapper.cxx @@ -126,11 +126,11 @@ void SAL_CALL MenuBarWrapper::initialize( const Sequence< Any >& aArguments ) th if ( xFrame.is() && m_xConfigSource.is() ) { // Create VCL menubar which will be filled with settings data - MenuBar* pVCLMenuBar = nullptr; + VclPtr<MenuBar> pVCLMenuBar; VCLXMenuBar* pAwtMenuBar = nullptr; { SolarMutexGuard aSolarMutexGuard; - pVCLMenuBar = new MenuBar(); + pVCLMenuBar = VclPtr<MenuBar>::Create(); } Reference< XModuleManager2 > xModuleManager = ModuleManager::create( m_xContext ); diff --git a/framework/source/uielement/togglebuttontoolbarcontroller.cxx b/framework/source/uielement/togglebuttontoolbarcontroller.cxx index 5dd73a65a47e..4e726c191312 100644 --- a/framework/source/uielement/togglebuttontoolbarcontroller.cxx +++ b/framework/source/uielement/togglebuttontoolbarcontroller.cxx @@ -102,21 +102,21 @@ throw (css::uno::RuntimeException, std::exception) ( m_eStyle == STYLE_TOGGLE_DROPDOWNBUTTON )) { // create popup menu - ::PopupMenu aPopup; + ScopedVclPtrInstance<::PopupMenu> aPopup; const sal_uInt32 nCount = m_aDropdownMenuList.size(); for ( sal_uInt32 i = 0; i < nCount; i++ ) { OUString aLabel( m_aDropdownMenuList[i] ); - aPopup.InsertItem( sal_uInt16( i+1 ), aLabel ); + aPopup->InsertItem( sal_uInt16( i+1 ), aLabel ); if ( aLabel == m_aCurrentSelection ) - aPopup.CheckItem( sal_uInt16( i+1 ) ); + aPopup->CheckItem( sal_uInt16( i+1 ) ); else - aPopup.CheckItem( sal_uInt16( i+1 ), false ); + aPopup->CheckItem( sal_uInt16( i+1 ), false ); } m_pToolbar->SetItemDown( m_nID, true ); - aPopup.SetSelectHdl( LINK( this, ToggleButtonToolbarController, MenuSelectHdl )); - aPopup.Execute( m_pToolbar, m_pToolbar->GetItemRect( m_nID )); + aPopup->SetSelectHdl( LINK( this, ToggleButtonToolbarController, MenuSelectHdl )); + aPopup->Execute( m_pToolbar, m_pToolbar->GetItemRect( m_nID )); m_pToolbar->SetItemDown( m_nID, false ); } diff --git a/framework/source/uielement/toolbarmanager.cxx b/framework/source/uielement/toolbarmanager.cxx index 752138447db6..68a3e00c494a 100644 --- a/framework/source/uielement/toolbarmanager.cxx +++ b/framework/source/uielement/toolbarmanager.cxx @@ -1326,12 +1326,11 @@ void ToolBarManager::ImplClearPopupMenu( ToolBox *pToolBar ) // remove config entries from menu, so we have a clean menu to start with // remove submenu first - ::PopupMenu* pItemMenu = pMenu->GetPopupMenu( 1 ); + VclPtr<::PopupMenu> pItemMenu = pMenu->GetPopupMenu( 1 ); if( pItemMenu ) { pItemMenu->Clear(); - delete pItemMenu; - pItemMenu = nullptr; + pItemMenu.disposeAndClear(); pMenu->SetPopupMenu( 1, pItemMenu ); } @@ -1412,12 +1411,12 @@ bool ToolBarManager::MenuItemAllowed( sal_uInt16 ) const // popup menu for quick customization bool bHideDisabledEntries = !SvtMenuOptions().IsEntryHidingEnabled(); - ::PopupMenu aQuickCustomizationMenu( FwkResId( POPUPMENU_TOOLBAR_QUICKCUSTOMIZATION )); + ScopedVclPtrInstance<::PopupMenu> aQuickCustomizationMenu( FwkResId( POPUPMENU_TOOLBAR_QUICKCUSTOMIZATION )); if ( m_pToolBar->IsCustomize() ) { sal_uInt16 nPos( 0 ); - ::PopupMenu* pVisibleItemsPopupMenu( aQuickCustomizationMenu.GetPopupMenu( 1 )); + ::PopupMenu* pVisibleItemsPopupMenu( aQuickCustomizationMenu->GetPopupMenu( 1 )); bool bIsFloating( false ); @@ -1427,25 +1426,25 @@ bool ToolBarManager::MenuItemAllowed( sal_uInt16 ) const if ( !bIsFloating ) { - aQuickCustomizationMenu.EnableItem( MENUITEM_TOOLBAR_DOCKTOOLBAR, false ); - aQuickCustomizationMenu.EnableItem( MENUITEM_TOOLBAR_DOCKALLTOOLBAR, false ); + aQuickCustomizationMenu->EnableItem( MENUITEM_TOOLBAR_DOCKTOOLBAR, false ); + aQuickCustomizationMenu->EnableItem( MENUITEM_TOOLBAR_DOCKALLTOOLBAR, false ); Reference< XDockableWindow > xDockable( VCLUnoHelper::GetInterface( m_pToolBar ), UNO_QUERY ); if( xDockable.is() ) - aQuickCustomizationMenu.CheckItem( MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION, xDockable->isLocked() ); + aQuickCustomizationMenu->CheckItem( MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION, xDockable->isLocked() ); } else - aQuickCustomizationMenu.EnableItem( MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION, false ); + aQuickCustomizationMenu->EnableItem( MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION, false ); if ( SvtMiscOptions().DisableUICustomization() ) { - aQuickCustomizationMenu.EnableItem( MENUITEM_TOOLBAR_VISIBLEBUTTON, false ); - aQuickCustomizationMenu.EnableItem( MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR, false ); - aQuickCustomizationMenu.EnableItem( MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION, false ); + aQuickCustomizationMenu->EnableItem( MENUITEM_TOOLBAR_VISIBLEBUTTON, false ); + aQuickCustomizationMenu->EnableItem( MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR, false ); + aQuickCustomizationMenu->EnableItem( MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION, false ); } // Disable menu item CLOSE if the toolbar has no closer if( !(pToolBar->GetFloatStyle() & WB_CLOSEABLE) ) - aQuickCustomizationMenu.EnableItem(MENUITEM_TOOLBAR_CLOSE, false); + aQuickCustomizationMenu->EnableItem(MENUITEM_TOOLBAR_CLOSE, false); // Temporary stores a Command --> Url map to update contextual menu with the // correct icons. The popup icons are by default the same as those in the @@ -1486,9 +1485,9 @@ bool ToolBarManager::MenuItemAllowed( sal_uInt16 ) const } else { - sal_uInt16 nPos = aQuickCustomizationMenu.GetItemPos( MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR ); + sal_uInt16 nPos = aQuickCustomizationMenu->GetItemPos( MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR ); if ( nPos != MENU_ITEM_NOTFOUND ) - aQuickCustomizationMenu.RemoveItem( nPos ); + aQuickCustomizationMenu->RemoveItem( nPos ); } // copy all menu items 'Visible buttons, Customize toolbar, Dock toolbar, @@ -1497,21 +1496,21 @@ bool ToolBarManager::MenuItemAllowed( sal_uInt16 ) const pMenu->InsertSeparator(); sal_uInt16 i; - for( i=0; i< aQuickCustomizationMenu.GetItemCount(); i++) + for( i=0; i< aQuickCustomizationMenu->GetItemCount(); i++) { - sal_uInt16 nId = aQuickCustomizationMenu.GetItemId( i ); + sal_uInt16 nId = aQuickCustomizationMenu->GetItemId( i ); if ( MenuItemAllowed( nId )) - pMenu->CopyItem( aQuickCustomizationMenu, i ); + pMenu->CopyItem( *aQuickCustomizationMenu.get(), i ); } // set submenu to toolbar menu - if( aQuickCustomizationMenu.GetPopupMenu( 1 ) ) + if( aQuickCustomizationMenu->GetPopupMenu( 1 ) ) { // create an own submenu to avoid auto-delete when resource menu is deleted - ::PopupMenu *pItemMenu = new ::PopupMenu(); + VclPtr<::PopupMenu> pItemMenu = VclPtr<::PopupMenu>::Create(); - for( i=0; i< aQuickCustomizationMenu.GetPopupMenu( 1 )->GetItemCount(); i++) - pItemMenu->CopyItem( *aQuickCustomizationMenu.GetPopupMenu( 1 ), i ); + for( i=0; i< aQuickCustomizationMenu->GetPopupMenu( 1 )->GetItemCount(); i++) + pItemMenu->CopyItem( *aQuickCustomizationMenu->GetPopupMenu( 1 ), i ); pMenu->SetPopupMenu( 1, pItemMenu ); } |