[Libreoffice-commits] core.git: accessibility/inc basctl/source cui/source dbaccess/source desktop/source editeng/source extensions/source fpicker/source framework/inc framework/source include/framework include/sfx2 include/svtools include/svx include/toolkit include/vcl reportdesign/source sc/source sd/source sfx2/source starmath/source svtools/source svx/source sw/inc sw/qa sw/source toolkit/source vcl/inc vcl/source vcl/unx vcl/workben

Noel Grandin noel at peralex.com
Thu Jun 23 06:28:25 UTC 2016


 accessibility/inc/standard/accessiblemenubasecomponent.hxx   |    3 
 accessibility/inc/standard/accessiblemenuitemcomponent.hxx   |    2 
 basctl/source/basicide/baside2b.cxx                          |   10 -
 basctl/source/basicide/bastypes.cxx                          |   28 ++--
 cui/source/customize/cfg.cxx                                 |    5 
 cui/source/tabpages/numpages.cxx                             |    5 
 cui/source/tabpages/tpline.cxx                               |   12 +
 dbaccess/source/ui/app/AppController.cxx                     |    4 
 dbaccess/source/ui/app/AppController.hxx                     |    2 
 dbaccess/source/ui/app/AppDetailPageHelper.cxx               |    8 -
 dbaccess/source/ui/app/AppDetailPageHelper.hxx               |    2 
 dbaccess/source/ui/browser/sbagrid.cxx                       |   24 +--
 dbaccess/source/ui/browser/unodatbr.cxx                      |    4 
 dbaccess/source/ui/control/dbtreelistbox.cxx                 |    6 
 dbaccess/source/ui/control/toolboxcontroller.cxx             |   12 -
 dbaccess/source/ui/inc/callbacks.hxx                         |    3 
 dbaccess/source/ui/inc/dbtreelistbox.hxx                     |    2 
 dbaccess/source/ui/inc/toolboxcontroller.hxx                 |    3 
 dbaccess/source/ui/inc/unodatbr.hxx                          |    9 -
 dbaccess/source/ui/misc/WTypeSelect.cxx                      |    6 
 dbaccess/source/ui/querydesign/JoinTableView.cxx             |    4 
 dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx        |   16 +-
 dbaccess/source/ui/querydesign/TableWindow.cxx               |    4 
 dbaccess/source/ui/tabledesign/TEditControl.cxx              |   28 ++--
 dbaccess/source/ui/tabledesign/TableDesignControl.cxx        |   12 -
 desktop/source/deployment/gui/dp_gui_dialog2.cxx             |   14 +-
 desktop/source/deployment/gui/dp_gui_updatedialog.cxx        |   10 -
 editeng/source/editeng/editview.cxx                          |   34 ++---
 extensions/source/bibliography/toolbar.cxx                   |   16 +-
 extensions/source/bibliography/toolbar.hxx                   |    2 
 extensions/source/update/ui/updatecheckui.cxx                |    2 
 fpicker/source/office/RemoteFilesDialog.hxx                  |    2 
 fpicker/source/office/iodlgimp.cxx                           |    4 
 fpicker/source/office/iodlgimp.hxx                           |    2 
 framework/inc/classes/rootactiontriggercontainer.hxx         |    2 
 framework/inc/uielement/generictoolbarcontroller.hxx         |    2 
 framework/inc/uielement/menubarmanager.hxx                   |    2 
 framework/inc/uielement/menubarmerger.hxx                    |    2 
 framework/source/fwe/classes/addonmenu.cxx                   |   42 +++---
 framework/source/fwe/helper/actiontriggerhelper.cxx          |    2 
 framework/source/layoutmanager/layoutmanager.cxx             |   22 +--
 framework/source/uielement/controlmenucontroller.cxx         |    8 -
 framework/source/uielement/generictoolbarcontroller.cxx      |   13 +-
 framework/source/uielement/menubarmanager.cxx                |   15 +-
 framework/source/uielement/menubarmerger.cxx                 |    6 
 framework/source/uielement/menubarwrapper.cxx                |    4 
 framework/source/uielement/togglebuttontoolbarcontroller.cxx |   12 -
 framework/source/uielement/toolbarmanager.cxx                |   43 +++---
 include/framework/addonmenu.hxx                              |    6 
 include/sfx2/sidebar/SidebarController.hxx                   |    2 
 include/sfx2/templatedlg.hxx                                 |    6 
 include/sfx2/viewsh.hxx                                      |    2 
 include/svtools/treelistbox.hxx                              |    2 
 include/svx/clipboardctl.hxx                                 |    2 
 include/toolkit/awt/vclxmenu.hxx                             |    3 
 include/vcl/builder.hxx                                      |    9 -
 include/vcl/edit.hxx                                         |    3 
 include/vcl/menu.hxx                                         |   14 +-
 include/vcl/menubtn.hxx                                      |    4 
 include/vcl/syswin.hxx                                       |    2 
 include/vcl/vclevent.hxx                                     |    8 -
 reportdesign/source/ui/dlg/GroupsSorting.cxx                 |    6 
 reportdesign/source/ui/dlg/Navigator.cxx                     |   18 +-
 reportdesign/source/ui/report/ReportSection.cxx              |    6 
 sc/source/ui/dbgui/csvgrid.cxx                               |   10 -
 sc/source/ui/inc/csvgrid.hxx                                 |    2 
 sc/source/ui/inc/tphfedit.hxx                                |    4 
 sc/source/ui/miscdlgs/acredlin.cxx                           |   16 +-
 sc/source/ui/navipi/content.cxx                              |   38 +++---
 sc/source/ui/navipi/navipi.cxx                               |    8 -
 sc/source/ui/navipi/scenwnd.cxx                              |    8 -
 sc/source/ui/pagedlg/tphfedit.cxx                            |   11 +
 sc/source/ui/view/tabcont.cxx                                |    8 -
 sd/source/ui/animations/CustomAnimationDialog.cxx            |   26 ++--
 sd/source/ui/animations/CustomAnimationList.cxx              |    5 
 sd/source/ui/animations/CustomAnimationList.hxx              |    2 
 sd/source/ui/annotations/annotationmanager.cxx               |    2 
 sd/source/ui/app/tmplctrl.cxx                                |    8 -
 sd/source/ui/dlg/navigatr.cxx                                |    6 
 sd/source/ui/sidebar/LayoutMenu.cxx                          |    2 
 sd/source/ui/sidebar/MasterPagesSelector.cxx                 |    2 
 sd/source/ui/slideshow/slideshowimpl.cxx                     |    4 
 sd/source/ui/view/drviews4.cxx                               |    8 -
 sfx2/source/appl/newhelp.cxx                                 |   68 +++++------
 sfx2/source/control/templatedefaultview.cxx                  |    2 
 sfx2/source/control/templatelocalview.cxx                    |    2 
 sfx2/source/control/templatesearchview.cxx                   |    2 
 sfx2/source/dialog/templdlg.cxx                              |   10 -
 sfx2/source/doc/templatedlg.cxx                              |    6 
 sfx2/source/inc/templdgi.hxx                                 |    6 
 sfx2/source/sidebar/SidebarController.cxx                    |    8 -
 sfx2/source/view/viewsh.cxx                                  |    4 
 starmath/source/edit.cxx                                     |    7 -
 svtools/source/contnr/fileview.cxx                           |    7 -
 svtools/source/contnr/svimpbox.cxx                           |   10 -
 svtools/source/contnr/treelistbox.cxx                        |    2 
 svtools/source/control/calendar.cxx                          |   18 +-
 svx/source/dialog/imapwnd.cxx                                |   46 +++----
 svx/source/dialog/svxruler.cxx                               |   28 ++--
 svx/source/fmcomp/fmgridcl.cxx                               |   26 ++--
 svx/source/fmcomp/gridctrl.cxx                               |   14 +-
 svx/source/form/datanavi.cxx                                 |    5 
 svx/source/form/filtnav.cxx                                  |   17 +-
 svx/source/form/fmshimp.cxx                                  |    4 
 svx/source/form/navigatortree.cxx                            |   42 +++---
 svx/source/gallery2/galbrws1.cxx                             |   18 +-
 svx/source/gallery2/galbrws2.cxx                             |   57 ++++-----
 svx/source/inc/datanavi.hxx                                  |    2 
 svx/source/inc/fmshimp.hxx                                   |    2 
 svx/source/mnuctrls/clipboardctl.cxx                         |    5 
 svx/source/mnuctrls/smarttagmenu.cxx                         |    9 -
 svx/source/stbctrls/pszctrl.cxx                              |    6 
 svx/source/stbctrls/selctrl.cxx                              |   10 -
 svx/source/stbctrls/xmlsecctrl.cxx                           |    4 
 svx/source/stbctrls/zoomctrl.cxx                             |    8 -
 svx/source/tbxctrls/tbcontrl.cxx                             |   11 -
 sw/inc/AnnotationWin.hxx                                     |    4 
 sw/qa/extras/odfimport/odfimport.cxx                         |    6 
 sw/source/uibase/docvw/AnnotationWin.cxx                     |    4 
 sw/source/uibase/docvw/HeaderFooterWin.cxx                   |    4 
 sw/source/uibase/docvw/PageBreakWin.cxx                      |    5 
 sw/source/uibase/docvw/edtwin.cxx                            |    8 -
 sw/source/uibase/docvw/romenu.cxx                            |    6 
 sw/source/uibase/docvw/romenu.hxx                            |    1 
 sw/source/uibase/inc/HeaderFooterWin.hxx                     |    2 
 sw/source/uibase/inc/PageBreakWin.hxx                        |    2 
 sw/source/uibase/inc/conttree.hxx                            |    4 
 sw/source/uibase/inc/inputwin.hxx                            |    4 
 sw/source/uibase/inc/redlndlg.hxx                            |    2 
 sw/source/uibase/inc/workctrl.hxx                            |    2 
 sw/source/uibase/misc/redlndlg.cxx                           |    8 -
 sw/source/uibase/ribbar/inputwin.cxx                         |    4 
 sw/source/uibase/ribbar/workctrl.cxx                         |   11 -
 sw/source/uibase/uiview/viewling.cxx                         |   12 -
 sw/source/uibase/utlui/bookctrl.cxx                          |    8 -
 sw/source/uibase/utlui/content.cxx                           |   12 -
 sw/source/uibase/utlui/glbltree.cxx                          |   18 +-
 sw/source/uibase/utlui/navipi.cxx                            |    8 -
 sw/source/uibase/utlui/tmplctrl.cxx                          |    8 -
 sw/source/uibase/utlui/unotools.cxx                          |   23 +--
 toolkit/source/awt/vclxmenu.cxx                              |   10 -
 vcl/inc/salmenu.hxx                                          |    2 
 vcl/inc/svdata.hxx                                           |    2 
 vcl/inc/toolbox.h                                            |    2 
 vcl/inc/unx/gtk/gtksalmenu.hxx                               |    2 
 vcl/source/app/vclevent.cxx                                  |   14 ++
 vcl/source/control/edit.cxx                                  |   15 --
 vcl/source/control/menubtn.cxx                               |    2 
 vcl/source/control/tabctrl.cxx                               |   10 -
 vcl/source/edit/vclmedit.cxx                                 |    4 
 vcl/source/window/builder.cxx                                |   11 +
 vcl/source/window/menu.cxx                                   |   33 ++++-
 vcl/source/window/menubarwindow.cxx                          |   12 -
 vcl/source/window/menubarwindow.hxx                          |    4 
 vcl/source/window/menufloatingwindow.cxx                     |   16 +-
 vcl/source/window/menufloatingwindow.hxx                     |    6 
 vcl/source/window/menuitemlist.cxx                           |    5 
 vcl/source/window/menuitemlist.hxx                           |    4 
 vcl/source/window/toolbox2.cxx                               |    4 
 vcl/unx/generic/app/i18n_status.cxx                          |    6 
 vcl/unx/gtk/gtksalmenu.cxx                                   |    2 
 vcl/workben/vcldemo.cxx                                      |   12 -
 162 files changed, 801 insertions(+), 747 deletions(-)

New commits:
commit aa0d0536a444fb26d9e570bd6bf6c1bdc3596cf3
Author: Noel Grandin <noel at peralex.com>
Date:   Mon Jun 20 15:56:35 2016 +0200

    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 at libreoffice.org>
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/accessibility/inc/standard/accessiblemenubasecomponent.hxx b/accessibility/inc/standard/accessiblemenubasecomponent.hxx
index 167c957..9b01b60 100644
--- a/accessibility/inc/standard/accessiblemenubasecomponent.hxx
+++ b/accessibility/inc/standard/accessiblemenubasecomponent.hxx
@@ -26,6 +26,7 @@
 #include <comphelper/accessiblecomponenthelper.hxx>
 #include <cppuhelper/implbase2.hxx>
 #include <tools/link.hxx>
+#include <vcl/vclptr.hxx>
 
 #include <vector>
 
@@ -59,7 +60,7 @@ protected:
     typedef ::std::vector< css::uno::Reference< css::accessibility::XAccessible > > AccessibleChildren;
 
     AccessibleChildren      m_aAccessibleChildren;
-    Menu*                   m_pMenu;
+    VclPtr<Menu>            m_pMenu;
 
     bool                    m_bEnabled;
     bool                    m_bFocused;
diff --git a/accessibility/inc/standard/accessiblemenuitemcomponent.hxx b/accessibility/inc/standard/accessiblemenuitemcomponent.hxx
index 84d0cc2..8abeb8a 100644
--- a/accessibility/inc/standard/accessiblemenuitemcomponent.hxx
+++ b/accessibility/inc/standard/accessiblemenuitemcomponent.hxx
@@ -31,7 +31,7 @@ class OAccessibleMenuItemComponent : public OAccessibleMenuBaseComponent
     friend class OAccessibleMenuBaseComponent;
 
 protected:
-    Menu*                   m_pParent;
+    VclPtr<Menu>            m_pParent;
     sal_uInt16              m_nItemPos;
     OUString                m_sAccessibleName;
     OUString                m_sItemText;
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx
index d1159c8..b33e9bd 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -1479,9 +1479,9 @@ void BreakPointWindow::Command( const CommandEvent& rCEvt )
         if ( pBrk )
         {
             // test if break point is enabled...
-            PopupMenu aBrkPropMenu( IDEResId( RID_POPUP_BRKPROPS ) );
-            aBrkPropMenu.CheckItem( RID_ACTIV, pBrk->bEnabled );
-            switch ( aBrkPropMenu.Execute( this, aPos ) )
+            ScopedVclPtrInstance<PopupMenu> aBrkPropMenu( IDEResId( RID_POPUP_BRKPROPS ) );
+            aBrkPropMenu->CheckItem( RID_ACTIV, pBrk->bEnabled );
+            switch ( aBrkPropMenu->Execute( this, aPos ) )
             {
                 case RID_ACTIV:
                 {
@@ -1502,8 +1502,8 @@ void BreakPointWindow::Command( const CommandEvent& rCEvt )
         }
         else
         {
-            PopupMenu aBrkListMenu( IDEResId( RID_POPUP_BRKDLG ) );
-            switch ( aBrkListMenu.Execute( this, aPos ) )
+            ScopedVclPtrInstance<PopupMenu> aBrkListMenu( IDEResId( RID_POPUP_BRKDLG ) );
+            switch ( aBrkListMenu->Execute( this, aPos ) )
             {
                 case RID_BRKDLG:
                 {
diff --git a/basctl/source/basicide/bastypes.cxx b/basctl/source/basicide/bastypes.cxx
index 1aefb75..88c1e9d 100644
--- a/basctl/source/basicide/bastypes.cxx
+++ b/basctl/source/basicide/bastypes.cxx
@@ -480,19 +480,19 @@ void TabBar::Command( const CommandEvent& rCEvt )
             ::TabBar::MouseButtonDown( aMouseEvent ); // base class
         }
 
-        PopupMenu aPopup( IDEResId( RID_POPUP_TABBAR ) );
+        ScopedVclPtrInstance<PopupMenu> aPopup( IDEResId( RID_POPUP_TABBAR ) );
         if ( GetPageCount() == 0 )
         {
-            aPopup.EnableItem(SID_BASICIDE_DELETECURRENT, false);
-            aPopup.EnableItem(SID_BASICIDE_RENAMECURRENT, false);
-            aPopup.EnableItem(SID_BASICIDE_HIDECURPAGE, false);
+            aPopup->EnableItem(SID_BASICIDE_DELETECURRENT, false);
+            aPopup->EnableItem(SID_BASICIDE_RENAMECURRENT, false);
+            aPopup->EnableItem(SID_BASICIDE_HIDECURPAGE, false);
         }
 
         if ( StarBASIC::IsRunning() )
         {
-            aPopup.EnableItem(SID_BASICIDE_DELETECURRENT, false);
-            aPopup.EnableItem(SID_BASICIDE_RENAMECURRENT, false);
-            aPopup.EnableItem(SID_BASICIDE_MODULEDLG, false);
+            aPopup->EnableItem(SID_BASICIDE_DELETECURRENT, false);
+            aPopup->EnableItem(SID_BASICIDE_RENAMECURRENT, false);
+            aPopup->EnableItem(SID_BASICIDE_MODULEDLG, false);
         }
 
         if (Shell* pShell = GetShell())
@@ -504,10 +504,10 @@ void TabBar::Command( const CommandEvent& rCEvt )
             if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) ) ||
                  ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) ) )
             {
-                aPopup.EnableItem(aPopup.GetItemId( 0 ), false);
-                aPopup.EnableItem(SID_BASICIDE_DELETECURRENT, false);
-                aPopup.EnableItem(SID_BASICIDE_RENAMECURRENT, false);
-                aPopup.RemoveDisabledEntries();
+                aPopup->EnableItem(aPopup->GetItemId( 0 ), false);
+                aPopup->EnableItem(SID_BASICIDE_DELETECURRENT, false);
+                aPopup->EnableItem(SID_BASICIDE_RENAMECURRENT, false);
+                aPopup->RemoveDisabledEntries();
             }
              if ( aDocument.isInVBAMode() )
             {
@@ -523,8 +523,8 @@ void TabBar::Command( const CommandEvent& rCEvt )
                             SbModule* pActiveModule = pBasic->FindModule( it->second->GetName() );
                             if( pActiveModule && ( pActiveModule->GetModuleType() == script::ModuleType::DOCUMENT ) )
                             {
-                                aPopup.EnableItem(SID_BASICIDE_DELETECURRENT, false);
-                                aPopup.EnableItem(SID_BASICIDE_RENAMECURRENT, false);
+                                aPopup->EnableItem(SID_BASICIDE_DELETECURRENT, false);
+                                aPopup->EnableItem(SID_BASICIDE_RENAMECURRENT, false);
                             }
                         }
                     }
@@ -532,7 +532,7 @@ void TabBar::Command( const CommandEvent& rCEvt )
             }
         }
         if (SfxDispatcher* pDispatcher = GetDispatcher())
-            pDispatcher->Execute(aPopup.Execute(this, aPos));
+            pDispatcher->Execute(aPopup->Execute(this, aPos));
     }
 }
 
diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx
index f3e1b62..1b08c29 100644
--- a/cui/source/customize/cfg.cxx
+++ b/cui/source/customize/cfg.cxx
@@ -3134,7 +3134,7 @@ SvxToolbarConfigPage::SvxToolbarConfigPage(vcl::Window *pParent, const SfxItemSe
     m_pMoveDownButton->Enable();
     m_pMoveUpButton->Enable();
 
-    PopupMenu* pMenu = new PopupMenu( CUI_RES( MODIFY_TOOLBAR ) );
+    VclPtrInstance<PopupMenu> pMenu( CUI_RES( MODIFY_TOOLBAR ) );
     pMenu->SetMenuFlags(
         pMenu->GetMenuFlags() | MenuFlags::AlwaysShowDisabledEntries );
 
@@ -3142,8 +3142,7 @@ SvxToolbarConfigPage::SvxToolbarConfigPage(vcl::Window *pParent, const SfxItemSe
     m_pModifyTopLevelButton->SetSelectHdl(
         LINK( this, SvxToolbarConfigPage, ToolbarSelectHdl ) );
 
-    PopupMenu* pEntry = new PopupMenu(
-        CUI_RES( MODIFY_TOOLBAR_CONTENT ) );
+    VclPtrInstance<PopupMenu> pEntry( CUI_RES( MODIFY_TOOLBAR_CONTENT ) );
     pEntry->SetMenuFlags(
         pEntry->GetMenuFlags() | MenuFlags::AlwaysShowDisabledEntries );
 
diff --git a/cui/source/tabpages/numpages.cxx b/cui/source/tabpages/numpages.cxx
index 5c5eed2..4eafff9 100644
--- a/cui/source/tabpages/numpages.cxx
+++ b/cui/source/tabpages/numpages.cxx
@@ -1239,7 +1239,7 @@ SvxNumOptionsTabPage::SvxNumOptionsTabPage(vcl::Window* pParent,
     pBitmapMenu->SetHighlightHdl(LINK(this, SvxNumOptionsTabPage, PopupActivateHdl_Impl));
     m_nGalleryId = pBitmapMenu->GetItemId("gallery");
     assert(m_nGalleryId != MENU_ITEM_NOTFOUND);
-    PopupMenu* pPopup = new PopupMenu;
+    VclPtrInstance<PopupMenu> pPopup;
     pBitmapMenu->SetPopupMenu(m_nGalleryId, pPopup);
 
     eCoreUnit = rSet.GetPool()->GetMetric(rSet.GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE));
@@ -1258,7 +1258,8 @@ void SvxNumOptionsTabPage::dispose()
 {
     if (m_pBitmapMB)
     {
-        delete m_pBitmapMB->GetPopupMenu()->GetPopupMenu(m_nGalleryId);
+        VclPtr<PopupMenu> p = m_pBitmapMB->GetPopupMenu()->GetPopupMenu(m_nGalleryId);
+        p.disposeAndClear(); // NoelG: dodgy, this leaves a dangling pointer
     }
     delete pActNum;
     pActNum = nullptr;
diff --git a/cui/source/tabpages/tpline.cxx b/cui/source/tabpages/tpline.cxx
index 4c12af0..ca323ab 100644
--- a/cui/source/tabpages/tpline.cxx
+++ b/cui/source/tabpages/tpline.cxx
@@ -229,10 +229,14 @@ void SvxLineTabPage::dispose()
     // Symbols on a line (e.g. StarCharts), dtor new!
     if (m_pSymbolMB)
     {
-        delete m_pSymbolMB->GetPopupMenu()->GetPopupMenu( MN_GALLERY );
+        VclPtr<PopupMenu> p = m_pSymbolMB->GetPopupMenu()->GetPopupMenu( MN_GALLERY );
+        p.disposeAndClear(); // NoelG: dodgy, this leaves a dangling pointer
 
         if(m_pSymbolList)
-            delete m_pSymbolMB->GetPopupMenu()->GetPopupMenu( MN_SYMBOLS );
+        {
+            VclPtr<PopupMenu> p2 = m_pSymbolMB->GetPopupMenu()->GetPopupMenu( MN_SYMBOLS );
+            p2.disposeAndClear(); // NoelG: dodgy, this leaves a dangling pointer
+        }
         m_pSymbolMB = nullptr;
     }
 
@@ -290,7 +294,7 @@ void SvxLineTabPage::InitSymbols(MenuButton* pButton)
         // Get gallery entries
         GalleryExplorer::FillObjList(GALLERY_THEME_BULLETS, m_aGrfNames);
 
-        PopupMenu* pPopup = new PopupMenu;
+        VclPtrInstance<PopupMenu> pPopup;
         sal_uInt32 i = 0;
         m_nNumMenuGalleryItems = m_aGrfNames.size();
         for(std::vector<OUString>::iterator it = m_aGrfNames.begin(); it != m_aGrfNames.end(); ++it, ++i)
@@ -363,7 +367,7 @@ void SvxLineTabPage::InitSymbols(MenuButton* pButton)
         pView->hideMarkHandles();
         pView->ShowSdrPage(pPage);
 
-        PopupMenu* pPopup = new PopupMenu;
+        VclPtrInstance<PopupMenu> pPopup;
 
         // Generate invisible square to give all symbols a
         // bitmap size, which is independent from specific glyph
diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx
index c7850b2..b6d7c75 100644
--- a/dbaccess/source/ui/app/AppController.cxx
+++ b/dbaccess/source/ui/app/AppController.cxx
@@ -2331,9 +2331,9 @@ bool OApplicationController::interceptUserInput( const NotifyEvent& _rEvent )
     return OGenericUnoController::interceptUserInput( _rEvent );
 }
 
-PopupMenu* OApplicationController::getContextMenu( Control& /*_rControl*/ ) const
+VclPtr<PopupMenu> OApplicationController::getContextMenu( Control& /*_rControl*/ ) const
 {
-    return new PopupMenu( ModuleRes( RID_MENU_APP_EDIT ) );
+    return VclPtr<PopupMenu>::Create( ModuleRes( RID_MENU_APP_EDIT ) );
 }
 
 IController& OApplicationController::getCommandController()
diff --git a/dbaccess/source/ui/app/AppController.hxx b/dbaccess/source/ui/app/AppController.hxx
index dec7e2f..2fe7d7e 100644
--- a/dbaccess/source/ui/app/AppController.hxx
+++ b/dbaccess/source/ui/app/AppController.hxx
@@ -532,7 +532,7 @@ namespace dbaui
         virtual sal_Int8    executeDrop( const ExecuteDropEvent& _rEvt ) override;
 
         // IContextMenuProvider
-        virtual PopupMenu*      getContextMenu( Control& _rControl ) const override;
+        virtual VclPtr<PopupMenu> getContextMenu( Control& _rControl ) const override;
         virtual IController&    getCommandController() override;
         virtual ::comphelper::OInterfaceContainerHelper2*
                                 getContextMenuInterceptors() override;
diff --git a/dbaccess/source/ui/app/AppDetailPageHelper.cxx b/dbaccess/source/ui/app/AppDetailPageHelper.cxx
index fb4564f..e8c9f37 100644
--- a/dbaccess/source/ui/app/AppDetailPageHelper.cxx
+++ b/dbaccess/source/ui/app/AppDetailPageHelper.cxx
@@ -187,13 +187,11 @@ OAppDetailPageHelper::OAppDetailPageHelper(vcl::Window* _pParent,OAppBorderWindo
     ,m_aBorder(VclPtr<Window>::Create(this,WB_BORDER | WB_READONLY))
     ,m_aPreview(VclPtr<OPreviewWindow>::Create(m_aBorder.get()))
     ,m_aDocumentInfo(VclPtr< ::svtools::ODocumentInfoPreview>::Create(m_aBorder.get(), WB_LEFT | WB_VSCROLL | WB_READONLY) )
+    ,m_aMenu( VclPtr<PopupMenu>::Create( ModuleRes( RID_MENU_APP_PREVIEW ) ) )
     ,m_ePreviewMode(_ePreviewMode)
 {
-
     m_aBorder->SetBorderStyle(WindowBorderStyle::MONO);
 
-    m_aMenu.reset(new PopupMenu( ModuleRes( RID_MENU_APP_PREVIEW ) ));
-
     m_aTBPreview->SetOutStyle(TOOLBOX_STYLE_FLAT);
     m_aTBPreview->InsertItem(SID_DB_APP_DISABLE_PREVIEW,m_aMenu->GetItemText(SID_DB_APP_DISABLE_PREVIEW),ToolBoxItemBits::LEFT|ToolBoxItemBits::DROPDOWN|ToolBoxItemBits::AUTOSIZE|ToolBoxItemBits::RADIOCHECK);
     m_aTBPreview->SetHelpId(HID_APP_VIEW_PREVIEW_CB);
@@ -242,7 +240,7 @@ void OAppDetailPageHelper::dispose()
             rpBox.disposeAndClear();
         }
     }
-    m_aMenu.reset();
+    m_aMenu.disposeAndClear();
     m_pTablePreview.disposeAndClear();
     m_aDocumentInfo.disposeAndClear();
     m_aPreview.disposeAndClear();
@@ -1153,7 +1151,7 @@ IMPL_LINK_NOARG_TYPED(OAppDetailPageHelper, OnDropdownClickHdl, ToolBox*, void)
     m_aTBPreview->Update();
 
     // execute the menu
-    std::unique_ptr<PopupMenu> aMenu(new PopupMenu( ModuleRes( RID_MENU_APP_PREVIEW ) ));
+    ScopedVclPtrInstance<PopupMenu> aMenu( ModuleRes( RID_MENU_APP_PREVIEW ) );
 
     const sal_uInt16 pActions[] = { SID_DB_APP_DISABLE_PREVIEW
                             , SID_DB_APP_VIEW_DOC_PREVIEW
diff --git a/dbaccess/source/ui/app/AppDetailPageHelper.hxx b/dbaccess/source/ui/app/AppDetailPageHelper.hxx
index 819a521..8f0d799 100644
--- a/dbaccess/source/ui/app/AppDetailPageHelper.hxx
+++ b/dbaccess/source/ui/app/AppDetailPageHelper.hxx
@@ -86,7 +86,7 @@ namespace dbaui
         VclPtr< ::svtools::ODocumentInfoPreview>
                                   m_aDocumentInfo;
         VclPtr<vcl::Window>       m_pTablePreview;
-        ::std::unique_ptr<PopupMenu> m_aMenu;
+        ScopedVclPtr<PopupMenu>   m_aMenu;
         PreviewMode               m_ePreviewMode;
         css::uno::Reference < css::frame::XFrame2 >
                                   m_xFrame;
diff --git a/dbaccess/source/ui/browser/sbagrid.cxx b/dbaccess/source/ui/browser/sbagrid.cxx
index 226eaae..695a223 100644
--- a/dbaccess/source/ui/browser/sbagrid.cxx
+++ b/dbaccess/source/ui/browser/sbagrid.cxx
@@ -650,7 +650,7 @@ void SbaGridHeader::PreExecuteColumnContextMenu(sal_uInt16 nColId, PopupMenu& rM
     bool bColAttrs = (nColId != (sal_uInt16)-1) && (nColId != 0);
     if ( bColAttrs && !bDBIsReadOnly)
     {
-        PopupMenu aNewItems(ModuleRes(RID_SBA_GRID_COLCTXMENU));
+        ScopedVclPtrInstance<PopupMenu> aNewItems(ModuleRes(RID_SBA_GRID_COLCTXMENU));
         sal_uInt16 nPos = 0;
         sal_uInt16 nModelPos = static_cast<SbaGridControl*>(GetParent())->GetModelColumnPos(nColId);
         Reference< XPropertySet >  xField = static_cast<SbaGridControl*>(GetParent())->getField(nModelPos);
@@ -669,14 +669,14 @@ void SbaGridHeader::PreExecuteColumnContextMenu(sal_uInt16 nColId, PopupMenu& rM
             case DataType::REF:
                 break;
             default:
-                rMenu.InsertItem(ID_BROWSER_COLATTRSET, aNewItems.GetItemText(ID_BROWSER_COLATTRSET), MenuItemBits::NONE, OString(), nPos++);
-                rMenu.SetHelpId(ID_BROWSER_COLATTRSET, aNewItems.GetHelpId(ID_BROWSER_COLATTRSET));
+                rMenu.InsertItem(ID_BROWSER_COLATTRSET, aNewItems->GetItemText(ID_BROWSER_COLATTRSET), MenuItemBits::NONE, OString(), nPos++);
+                rMenu.SetHelpId(ID_BROWSER_COLATTRSET, aNewItems->GetHelpId(ID_BROWSER_COLATTRSET));
                 rMenu.InsertSeparator(OString(), nPos++);
             }
         }
 
-        rMenu.InsertItem(ID_BROWSER_COLWIDTH, aNewItems.GetItemText(ID_BROWSER_COLWIDTH), MenuItemBits::NONE, OString(), nPos++);
-        rMenu.SetHelpId(ID_BROWSER_COLWIDTH, aNewItems.GetHelpId(ID_BROWSER_COLWIDTH));
+        rMenu.InsertItem(ID_BROWSER_COLWIDTH, aNewItems->GetItemText(ID_BROWSER_COLWIDTH), MenuItemBits::NONE, OString(), nPos++);
+        rMenu.SetHelpId(ID_BROWSER_COLWIDTH, aNewItems->GetHelpId(ID_BROWSER_COLWIDTH));
         rMenu.InsertSeparator(OString(), nPos++);
     }
 }
@@ -751,23 +751,23 @@ void SbaGridControl::PreExecuteRowContextMenu(sal_uInt16 nRow, PopupMenu& rMenu)
 {
     FmGridControl::PreExecuteRowContextMenu(nRow, rMenu);
 
-    PopupMenu aNewItems(ModuleRes(RID_SBA_GRID_ROWCTXMENU));
+    ScopedVclPtrInstance<PopupMenu> aNewItems(ModuleRes(RID_SBA_GRID_ROWCTXMENU));
     sal_uInt16 nPos = 0;
 
     if (!IsReadOnlyDB())
     {
-        rMenu.InsertItem(ID_BROWSER_TABLEATTR, aNewItems.GetItemText(ID_BROWSER_TABLEATTR), MenuItemBits::NONE, OString(), nPos++);
-        rMenu.SetHelpId(ID_BROWSER_TABLEATTR, aNewItems.GetHelpId(ID_BROWSER_TABLEATTR));
+        rMenu.InsertItem(ID_BROWSER_TABLEATTR, aNewItems->GetItemText(ID_BROWSER_TABLEATTR), MenuItemBits::NONE, OString(), nPos++);
+        rMenu.SetHelpId(ID_BROWSER_TABLEATTR, aNewItems->GetHelpId(ID_BROWSER_TABLEATTR));
 
-        rMenu.InsertItem(ID_BROWSER_ROWHEIGHT, aNewItems.GetItemText(ID_BROWSER_ROWHEIGHT), MenuItemBits::NONE, OString(), nPos++);
-        rMenu.SetHelpId(ID_BROWSER_ROWHEIGHT, aNewItems.GetHelpId(ID_BROWSER_ROWHEIGHT));
+        rMenu.InsertItem(ID_BROWSER_ROWHEIGHT, aNewItems->GetItemText(ID_BROWSER_ROWHEIGHT), MenuItemBits::NONE, OString(), nPos++);
+        rMenu.SetHelpId(ID_BROWSER_ROWHEIGHT, aNewItems->GetHelpId(ID_BROWSER_ROWHEIGHT));
         rMenu.InsertSeparator(OString(), nPos++);
     }
 
     if ( GetSelectRowCount() > 0 )
     {
-        rMenu.InsertItem(ID_BROWSER_COPY, aNewItems.GetItemText(SID_COPY), MenuItemBits::NONE, OString(), nPos++);
-        rMenu.SetHelpId(ID_BROWSER_COPY, aNewItems.GetHelpId(SID_COPY));
+        rMenu.InsertItem(ID_BROWSER_COPY, aNewItems->GetItemText(SID_COPY), MenuItemBits::NONE, OString(), nPos++);
+        rMenu.SetHelpId(ID_BROWSER_COPY, aNewItems->GetHelpId(SID_COPY));
 
         rMenu.InsertSeparator(OString(), nPos++);
     }
diff --git a/dbaccess/source/ui/browser/unodatbr.cxx b/dbaccess/source/ui/browser/unodatbr.cxx
index f41c7e0..bae2bbf 100644
--- a/dbaccess/source/ui/browser/unodatbr.cxx
+++ b/dbaccess/source/ui/browser/unodatbr.cxx
@@ -3473,14 +3473,14 @@ bool SbaTableQueryBrowser::requestQuickHelp( const SvTreeListEntry* _pEntry, OUS
     return false;
 }
 
-PopupMenu* SbaTableQueryBrowser::getContextMenu( Control& _rControl ) const
+VclPtr<PopupMenu> SbaTableQueryBrowser::getContextMenu( Control& _rControl ) const
 {
     OSL_PRECOND( &m_pTreeView->getListBox() == &_rControl,
         "SbaTableQueryBrowser::getContextMenu: where does this come from?" );
     if ( &m_pTreeView->getListBox() != &_rControl )
         return nullptr;
 
-    return new PopupMenu( ModuleRes( MENU_BROWSER_DEFAULTCONTEXT ) );
+    return VclPtr<PopupMenu>::Create( ModuleRes( MENU_BROWSER_DEFAULTCONTEXT ) );
 }
 
 IController& SbaTableQueryBrowser::getCommandController()
diff --git a/dbaccess/source/ui/control/dbtreelistbox.cxx b/dbaccess/source/ui/control/dbtreelistbox.cxx
index 5fefdad..d212bd2 100644
--- a/dbaccess/source/ui/control/dbtreelistbox.cxx
+++ b/dbaccess/source/ui/control/dbtreelistbox.cxx
@@ -551,9 +551,9 @@ namespace
     }
 }
 
-std::unique_ptr<PopupMenu> DBTreeListBox::CreateContextMenu()
+VclPtr<PopupMenu> DBTreeListBox::CreateContextMenu()
 {
-    ::std::unique_ptr< PopupMenu > pContextMenu;
+    VclPtr< PopupMenu > pContextMenu;
 
     if ( !m_pContextMenuProvider )
         return pContextMenu;
@@ -621,7 +621,7 @@ std::unique_ptr<PopupMenu> DBTreeListBox::CreateContextMenu()
     if ( bModifiedMenu )
     {
         // the interceptor(s) modified the menu description => create a new PopupMenu
-        PopupMenu* pModifiedMenu = new PopupMenu;
+        VclPtrInstance<PopupMenu> pModifiedMenu;
         ::framework::ActionTriggerHelper::CreateMenuFromActionTriggerContainer(
             pModifiedMenu, aEvent.ActionTriggerContainer );
         aEvent.ActionTriggerContainer.clear();
diff --git a/dbaccess/source/ui/control/toolboxcontroller.cxx b/dbaccess/source/ui/control/toolboxcontroller.cxx
index 2f8816e..2208de1 100644
--- a/dbaccess/source/ui/control/toolboxcontroller.cxx
+++ b/dbaccess/source/ui/control/toolboxcontroller.cxx
@@ -159,7 +159,7 @@ namespace dbaui
             aFind->second = Event.IsEnabled;
             if ( m_aCommandURL == aFind->first && !Event.IsEnabled )
             {
-                ::std::unique_ptr<PopupMenu> pMenu = getMenu();
+                ScopedVclPtr<PopupMenu> pMenu(getMenu());
                 sal_uInt16 nCount = pMenu->GetItemCount();
                 for (sal_uInt16 i = 0; i < nCount; ++i)
                 {
@@ -177,12 +177,12 @@ namespace dbaui
             }
         }
     }
-    ::std::unique_ptr<PopupMenu> OToolboxController::getMenu()
+    VclPtr<PopupMenu> OToolboxController::getMenu()
     {
-        ::std::unique_ptr<PopupMenu> pMenu;
+        VclPtr<PopupMenu> pMenu;
         if ( m_aStates.size() > 2 )
         {
-            pMenu.reset( new PopupMenu( ModuleRes( RID_MENU_APP_NEW ) ) );
+            pMenu = VclPtr<PopupMenu>::Create( ModuleRes( RID_MENU_APP_NEW ) );
 
             try
             {
@@ -217,7 +217,7 @@ namespace dbaui
         }
         else
         {
-            pMenu.reset( new PopupMenu( ModuleRes( RID_MENU_REFRESH_DATA ) ) );
+            pMenu = VclPtr<PopupMenu>::Create( ModuleRes( RID_MENU_REFRESH_DATA ) );
         }
         return pMenu;
     }
@@ -229,7 +229,7 @@ namespace dbaui
         ::osl::MutexGuard aGuard(m_aMutex);
 
         VclPtr< ToolBox > pToolBox = static_cast<ToolBox*>(VCLUnoHelper::GetWindow(getParent()).get());
-        ::std::unique_ptr<PopupMenu> pMenu = getMenu();
+        ScopedVclPtr<PopupMenu> pMenu(getMenu());
 
         sal_uInt16 nSelected = pMenu->Execute(pToolBox, pToolBox->GetItemRect( m_nToolBoxId ),PopupMenuFlags::ExecuteDown);
         // "cleanup" the toolbox state
diff --git a/dbaccess/source/ui/inc/callbacks.hxx b/dbaccess/source/ui/inc/callbacks.hxx
index 9c2a579..c9e98ea 100644
--- a/dbaccess/source/ui/inc/callbacks.hxx
+++ b/dbaccess/source/ui/inc/callbacks.hxx
@@ -22,6 +22,7 @@
 
 #include <sot/exchange.hxx>
 #include <sot/formats.hxx>
+#include <vcl/vclptr.hxx>
 #include <com/sun/star/container/XContainer.hpp>
 
 class SvTreeListEntry;
@@ -74,7 +75,7 @@ namespace dbaui
             The control itself will, using the controller provided by getCommandController,
             disable menu entries as needed.
         */
-        virtual PopupMenu*      getContextMenu( Control& _rControl ) const = 0;
+        virtual VclPtr<PopupMenu> getContextMenu( Control& _rControl ) const = 0;
 
         /** returns the controller which is responsible for providing states of certain features,
             and executing them.
diff --git a/dbaccess/source/ui/inc/dbtreelistbox.hxx b/dbaccess/source/ui/inc/dbtreelistbox.hxx
index 21723a7..9a7413a 100644
--- a/dbaccess/source/ui/inc/dbtreelistbox.hxx
+++ b/dbaccess/source/ui/inc/dbtreelistbox.hxx
@@ -111,7 +111,7 @@ namespace dbaui
 
         virtual bool    DoubleClickHdl() override;
 
-        virtual std::unique_ptr<PopupMenu> CreateContextMenu() override;
+        virtual VclPtr<PopupMenu> CreateContextMenu() override;
         virtual void    ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry ) override;
 
         void            SetEnterKeyHdl(const Link<DBTreeListBox*,void>& rNewHdl) {m_aEnterKeyHdl = rNewHdl;}
diff --git a/dbaccess/source/ui/inc/toolboxcontroller.hxx b/dbaccess/source/ui/inc/toolboxcontroller.hxx
index 3e76fc2..05fba56 100644
--- a/dbaccess/source/ui/inc/toolboxcontroller.hxx
+++ b/dbaccess/source/ui/inc/toolboxcontroller.hxx
@@ -22,6 +22,7 @@
 #include <svtools/toolboxcontroller.hxx>
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <cppuhelper/implbase1.hxx>
+#include <vcl/vclptr.hxx>
 #include "apitools.hxx"
 #include "moduledbu.hxx"
 
@@ -41,7 +42,7 @@ namespace dbaui
         TCommandState   m_aStates;
         sal_uInt16      m_nToolBoxId;
 
-        ::std::unique_ptr<PopupMenu> getMenu();
+        VclPtr<PopupMenu> getMenu();
     public:
         OToolboxController(const css::uno::Reference< css::uno::XComponentContext >& _rxORB);
 
diff --git a/dbaccess/source/ui/inc/unodatbr.hxx b/dbaccess/source/ui/inc/unodatbr.hxx
index 02673fb..68b7acc 100644
--- a/dbaccess/source/ui/inc/unodatbr.hxx
+++ b/dbaccess/source/ui/inc/unodatbr.hxx
@@ -230,12 +230,11 @@ namespace dbaui
         virtual sal_Int8    executeDrop( const ExecuteDropEvent& _rEvt ) override;
 
         // IContextMenuProvider
-        virtual PopupMenu*      getContextMenu( Control& _rControl ) const override;
-        virtual IController&    getCommandController() override;
+        virtual VclPtr<PopupMenu> getContextMenu( Control& _rControl ) const override;
+        virtual IController&      getCommandController() override;
         virtual ::comphelper::OInterfaceContainerHelper2*
-                                getContextMenuInterceptors() override;
-        virtual css::uno::Any
-                                getCurrentSelection( Control& _rControl ) const override;
+                                  getContextMenuInterceptors() override;
+        virtual css::uno::Any     getCurrentSelection( Control& _rControl ) const override;
 
         virtual void impl_initialize() override;
 
diff --git a/dbaccess/source/ui/misc/WTypeSelect.cxx b/dbaccess/source/ui/misc/WTypeSelect.cxx
index 4b85643..b2b839d 100644
--- a/dbaccess/source/ui/misc/WTypeSelect.cxx
+++ b/dbaccess/source/ui/misc/WTypeSelect.cxx
@@ -423,7 +423,7 @@ bool OWizTypeSelectList::PreNotify( NotifyEvent& rEvt )
             if (pComEvt->IsMouseEvent())
                 ptWhere = pComEvt->GetMousePosPixel();
 
-            PopupMenu aContextMenu(ModuleRes(RID_SBA_RTF_PKEYPOPUP));
+            ScopedVclPtrInstance<PopupMenu> aContextMenu(ModuleRes(RID_SBA_RTF_PKEYPOPUP));
             // Should primary key checkbox be checked?
             const sal_Int32 nCount = GetEntryCount();
             bool bCheckOk = false;
@@ -443,9 +443,9 @@ bool OWizTypeSelectList::PreNotify( NotifyEvent& rEvt )
             }
 
             if (bCheckOk)
-                aContextMenu.CheckItem( SID_TABLEDESIGN_TABED_PRIMARYKEY );
+                aContextMenu->CheckItem( SID_TABLEDESIGN_TABED_PRIMARYKEY );
 
-            switch( aContextMenu.Execute( this, ptWhere ) )
+            switch( aContextMenu->Execute( this, ptWhere ) )
             {
                 case SID_TABLEDESIGN_TABED_PRIMARYKEY:
                 {
diff --git a/dbaccess/source/ui/querydesign/JoinTableView.cxx b/dbaccess/source/ui/querydesign/JoinTableView.cxx
index d12eca7..1ea84c3 100644
--- a/dbaccess/source/ui/querydesign/JoinTableView.cxx
+++ b/dbaccess/source/ui/querydesign/JoinTableView.cxx
@@ -1128,8 +1128,8 @@ bool OJoinTableView::IsAddAllowed()
 
 void OJoinTableView::executePopup(const Point& _aPos, VclPtr<OTableConnection>& rSelConnection)
 {
-    PopupMenu aContextMenu( ModuleRes( RID_MENU_JOINVIEW_CONNECTION ) );
-    switch (aContextMenu.Execute(this, _aPos))
+    ScopedVclPtrInstance<PopupMenu> aContextMenu( ModuleRes( RID_MENU_JOINVIEW_CONNECTION ) );
+    switch (aContextMenu->Execute(this, _aPos))
     {
         case SID_DELETE:
             RemoveConnection(rSelConnection, true);
diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
index cff9469..e9d14eb 100644
--- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
+++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
@@ -1951,8 +1951,8 @@ void OSelectionBrowseBox::Command(const CommandEvent& rEvt)
 
                 if (!static_cast<OQueryController&>(getDesignView()->getController()).isReadOnly())
                 {
-                    PopupMenu aContextMenu( ModuleRes( RID_QUERYCOLPOPUPMENU ) );
-                    switch (aContextMenu.Execute(this, aMenuPos))
+                    ScopedVclPtrInstance<PopupMenu> aContextMenu( ModuleRes( RID_QUERYCOLPOPUPMENU ) );
+                    switch (aContextMenu->Execute(this, aMenuPos))
                     {
                         case SID_DELETE:
                             RemoveField(nColId);
@@ -1968,13 +1968,13 @@ void OSelectionBrowseBox::Command(const CommandEvent& rEvt)
             {
                 if (!static_cast<OQueryController&>(getDesignView()->getController()).isReadOnly())
                 {
-                    PopupMenu aContextMenu(ModuleRes(RID_QUERYFUNCTION_POPUPMENU));
-                    aContextMenu.CheckItem( ID_QUERY_FUNCTION, m_bVisibleRow[BROW_FUNCTION_ROW]);
-                    aContextMenu.CheckItem( ID_QUERY_TABLENAME, m_bVisibleRow[BROW_TABLE_ROW]);
-                    aContextMenu.CheckItem( ID_QUERY_ALIASNAME, m_bVisibleRow[BROW_COLUMNALIAS_ROW]);
-                    aContextMenu.CheckItem( ID_QUERY_DISTINCT, static_cast<OQueryController&>(getDesignView()->getController()).isDistinct());
+                    ScopedVclPtrInstance<PopupMenu> aContextMenu(ModuleRes(RID_QUERYFUNCTION_POPUPMENU));
+                    aContextMenu->CheckItem( ID_QUERY_FUNCTION, m_bVisibleRow[BROW_FUNCTION_ROW]);
+                    aContextMenu->CheckItem( ID_QUERY_TABLENAME, m_bVisibleRow[BROW_TABLE_ROW]);
+                    aContextMenu->CheckItem( ID_QUERY_ALIASNAME, m_bVisibleRow[BROW_COLUMNALIAS_ROW]);
+                    aContextMenu->CheckItem( ID_QUERY_DISTINCT, static_cast<OQueryController&>(getDesignView()->getController()).isDistinct());
 
-                    switch (aContextMenu.Execute(this, aMenuPos))
+                    switch (aContextMenu->Execute(this, aMenuPos))
                     {
                         case ID_QUERY_FUNCTION:
                             SetRowVisible(BROW_FUNCTION_ROW, !IsRowVisible(BROW_FUNCTION_ROW));
diff --git a/dbaccess/source/ui/querydesign/TableWindow.cxx b/dbaccess/source/ui/querydesign/TableWindow.cxx
index 10d3fd4e..b699f0d 100644
--- a/dbaccess/source/ui/querydesign/TableWindow.cxx
+++ b/dbaccess/source/ui/querydesign/TableWindow.cxx
@@ -603,8 +603,8 @@ void OTableWindow::Command(const CommandEvent& rEvt)
                         ptWhere = m_xTitle->GetPosPixel();
                 }
 
-                PopupMenu aContextMenu(ModuleRes(RID_MENU_JOINVIEW_TABLE));
-                switch (aContextMenu.Execute(this, ptWhere))
+                ScopedVclPtrInstance<PopupMenu> aContextMenu(ModuleRes(RID_MENU_JOINVIEW_TABLE));
+                switch (aContextMenu->Execute(this, ptWhere))
                 {
                     case SID_DELETE:
                         Remove();
diff --git a/dbaccess/source/ui/tabledesign/TEditControl.cxx b/dbaccess/source/ui/tabledesign/TEditControl.cxx
index 04da703..7a39f55d 100644
--- a/dbaccess/source/ui/tabledesign/TEditControl.cxx
+++ b/dbaccess/source/ui/tabledesign/TEditControl.cxx
@@ -1361,10 +1361,10 @@ void OTableEditorCtrl::Command(const CommandEvent& rEvt)
                             if ( !IsColumnSelected( nColId ) )
                                 SelectColumnId( nColId );
 
-                            PopupMenu aContextMenu( ModuleRes( RID_QUERYCOLPOPUPMENU ) );
-                            aContextMenu.EnableItem( SID_DELETE, false );
-                            aContextMenu.RemoveDisabledEntries(true, true);
-                            switch ( aContextMenu.Execute( this, aMenuPos ) )
+                            ScopedVclPtrInstance<PopupMenu> aContextMenu( ModuleRes( RID_QUERYCOLPOPUPMENU ) );
+                            aContextMenu->EnableItem( SID_DELETE, false );
+                            aContextMenu->RemoveDisabledEntries(true, true);
+                            switch ( aContextMenu->Execute( this, aMenuPos ) )
                             {
                                 case ID_BROWSER_COLWIDTH:
                                     adjustBrowseBoxColumnWidth( this, nColId );
@@ -1375,18 +1375,18 @@ void OTableEditorCtrl::Command(const CommandEvent& rEvt)
                 }
                 else
                 {
-                    PopupMenu aContextMenu(ModuleRes(RID_TABLEDESIGNROWPOPUPMENU));
+                    ScopedVclPtrInstance<PopupMenu> aContextMenu(ModuleRes(RID_TABLEDESIGNROWPOPUPMENU));
 
-                    aContextMenu.EnableItem( SID_CUT, IsCutAllowed(nRow) );
-                    aContextMenu.EnableItem( SID_COPY, IsCopyAllowed(nRow) );
-                    aContextMenu.EnableItem( SID_PASTE, IsPasteAllowed(nRow) );
-                    aContextMenu.EnableItem( SID_DELETE, IsDeleteAllowed(nRow) );
-                    aContextMenu.EnableItem( SID_TABLEDESIGN_TABED_PRIMARYKEY, IsPrimaryKeyAllowed(nRow) );
-                    aContextMenu.EnableItem( SID_TABLEDESIGN_INSERTROWS, IsInsertNewAllowed(nRow) );
-                    aContextMenu.CheckItem( SID_TABLEDESIGN_TABED_PRIMARYKEY, IsRowSelected(GetCurRow()) && IsPrimaryKey() );
+                    aContextMenu->EnableItem( SID_CUT, IsCutAllowed(nRow) );
+                    aContextMenu->EnableItem( SID_COPY, IsCopyAllowed(nRow) );
+                    aContextMenu->EnableItem( SID_PASTE, IsPasteAllowed(nRow) );
+                    aContextMenu->EnableItem( SID_DELETE, IsDeleteAllowed(nRow) );
+                    aContextMenu->EnableItem( SID_TABLEDESIGN_TABED_PRIMARYKEY, IsPrimaryKeyAllowed(nRow) );
+                    aContextMenu->EnableItem( SID_TABLEDESIGN_INSERTROWS, IsInsertNewAllowed(nRow) );
+                    aContextMenu->CheckItem( SID_TABLEDESIGN_TABED_PRIMARYKEY, IsRowSelected(GetCurRow()) && IsPrimaryKey() );
 
                     // remove all the disable entries
-                    aContextMenu.RemoveDisabledEntries(true, true);
+                    aContextMenu->RemoveDisabledEntries(true, true);
 
                     if( SetDataPtr(m_nDataPos) )
                         pDescrWin->SaveData( pActRow->GetActFieldDescr() );
@@ -1394,7 +1394,7 @@ void OTableEditorCtrl::Command(const CommandEvent& rEvt)
                     // All actions which change the number of rows must be run asynchronously
                     // otherwise there may be problems between the Context menu and the Browser
                     m_nDataPos = GetCurRow();
-                    switch (aContextMenu.Execute(this, aMenuPos))
+                    switch (aContextMenu->Execute(this, aMenuPos))
                     {
                         case SID_CUT:
                             cut();
diff --git a/dbaccess/source/ui/tabledesign/TableDesignControl.cxx b/dbaccess/source/ui/tabledesign/TableDesignControl.cxx
index 77f0650..668edcd 100644
--- a/dbaccess/source/ui/tabledesign/TableDesignControl.cxx
+++ b/dbaccess/source/ui/tabledesign/TableDesignControl.cxx
@@ -107,13 +107,13 @@ void OTableRowView::Command(const CommandEvent& rEvt)
 
             if ( nColId == HANDLE_ID )
             {
-                PopupMenu aContextMenu(ModuleRes(RID_TABLEDESIGNROWPOPUPMENU));
+                ScopedVclPtrInstance<PopupMenu> aContextMenu(ModuleRes(RID_TABLEDESIGNROWPOPUPMENU));
                 long nSelectRowCount = GetSelectRowCount();
-                aContextMenu.EnableItem( SID_CUT, nSelectRowCount != 0);
-                aContextMenu.EnableItem( SID_COPY, nSelectRowCount  != 0);
-                aContextMenu.EnableItem( SID_PASTE, m_bClipboardFilled );
-                aContextMenu.EnableItem( SID_DELETE, false );
-                switch (aContextMenu.Execute(this, rEvt.GetMousePosPixel()))
+                aContextMenu->EnableItem( SID_CUT, nSelectRowCount != 0);
+                aContextMenu->EnableItem( SID_COPY, nSelectRowCount  != 0);
+                aContextMenu->EnableItem( SID_PASTE, m_bClipboardFilled );
+                aContextMenu->EnableItem( SID_DELETE, false );
+                switch (aContextMenu->Execute(this, rEvt.GetMousePosPixel()))
                 {
                     case SID_CUT:
                         cut();
diff --git a/desktop/source/deployment/gui/dp_gui_dialog2.cxx b/desktop/source/deployment/gui/dp_gui_dialog2.cxx
index a4a5867..b14650a 100644
--- a/desktop/source/deployment/gui/dp_gui_dialog2.cxx
+++ b/desktop/source/deployment/gui/dp_gui_dialog2.cxx
@@ -359,10 +359,10 @@ MENU_COMMAND ExtBoxWithBtns_Impl::ShowPopupMenu( const Point & rPos, const long
     if ( nPos >= (long) getItemCount() )
         return CMD_NONE;
 
-    PopupMenu aPopup;
+    ScopedVclPtrInstance<PopupMenu> aPopup;
 
 #if ENABLE_EXTENSION_UPDATE
-    aPopup.InsertItem( CMD_UPDATE, DialogHelper::getResourceString( RID_CTX_ITEM_CHECK_UPDATE ) );
+    aPopup->InsertItem( CMD_UPDATE, DialogHelper::getResourceString( RID_CTX_ITEM_CHECK_UPDATE ) );
 #endif
 
     if ( ! GetEntryData( nPos )->m_bLocked )
@@ -370,17 +370,17 @@ MENU_COMMAND ExtBoxWithBtns_Impl::ShowPopupMenu( const Point & rPos, const long
         if ( GetEntryData( nPos )->m_bUser )
         {
             if ( GetEntryData( nPos )->m_eState == REGISTERED )
-                aPopup.InsertItem( CMD_DISABLE, DialogHelper::getResourceString( RID_CTX_ITEM_DISABLE ) );
+                aPopup->InsertItem( CMD_DISABLE, DialogHelper::getResourceString( RID_CTX_ITEM_DISABLE ) );
             else if ( GetEntryData( nPos )->m_eState != NOT_AVAILABLE )
-                aPopup.InsertItem( CMD_ENABLE, DialogHelper::getResourceString( RID_CTX_ITEM_ENABLE ) );
+                aPopup->InsertItem( CMD_ENABLE, DialogHelper::getResourceString( RID_CTX_ITEM_ENABLE ) );
         }
-        aPopup.InsertItem( CMD_REMOVE, DialogHelper::getResourceString( RID_CTX_ITEM_REMOVE ) );
+        aPopup->InsertItem( CMD_REMOVE, DialogHelper::getResourceString( RID_CTX_ITEM_REMOVE ) );
     }
 
     if ( !GetEntryData( nPos )->m_sLicenseText.isEmpty() )
-        aPopup.InsertItem( CMD_SHOW_LICENSE, DialogHelper::getResourceString( RID_STR_SHOW_LICENSE_CMD ) );
+        aPopup->InsertItem( CMD_SHOW_LICENSE, DialogHelper::getResourceString( RID_STR_SHOW_LICENSE_CMD ) );
 
-    return (MENU_COMMAND) aPopup.Execute( this, rPos );
+    return (MENU_COMMAND) aPopup->Execute( this, rPos );
 }
 
 
diff --git a/desktop/source/deployment/gui/dp_gui_updatedialog.cxx b/desktop/source/deployment/gui/dp_gui_updatedialog.cxx
index 624a64d..5354816 100644
--- a/desktop/source/deployment/gui/dp_gui_updatedialog.cxx
+++ b/desktop/source/deployment/gui/dp_gui_updatedialog.cxx
@@ -654,17 +654,17 @@ void UpdateDialog::CheckListBox::handlePopupMenu( const Point &rPos )
 
         if ( ( p->m_eKind == ENABLED_UPDATE ) || ( p->m_eKind == DISABLED_UPDATE ) )
         {
-            PopupMenu aPopup;
+            ScopedVclPtrInstance<PopupMenu> aPopup;
 
             if ( p->m_bIgnored )
-                aPopup.InsertItem( CMD_ENABLE_UPDATE, m_enableUpdate );
+                aPopup->InsertItem( CMD_ENABLE_UPDATE, m_enableUpdate );
             else
             {
-                aPopup.InsertItem( CMD_IGNORE_UPDATE, m_ignoreUpdate );
-                aPopup.InsertItem( CMD_IGNORE_ALL_UPDATES, m_ignoreAllUpdates );
+                aPopup->InsertItem( CMD_IGNORE_UPDATE, m_ignoreUpdate );
+                aPopup->InsertItem( CMD_IGNORE_ALL_UPDATES, m_ignoreAllUpdates );
             }
 
-            sal_uInt16 aCmd = aPopup.Execute( this, rPos );
+            sal_uInt16 aCmd = aPopup->Execute( this, rPos );
             if ( ( aCmd == CMD_IGNORE_UPDATE ) || ( aCmd == CMD_IGNORE_ALL_UPDATES ) )
             {
                 p->m_bIgnored = true;
diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx
index 84dba19..0cd9e6f 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -765,9 +765,9 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo
     ESelection aOldSel = GetSelection();
     if ( xSpeller.is() && pImpEditView->IsWrongSpelledWord( aPaM, true ) )
     {
-        PopupMenu aPopupMenu( EditResId( RID_MENU_SPELL ) );
-        PopupMenu *pAutoMenu = aPopupMenu.GetPopupMenu( MN_AUTOCORR );
-        PopupMenu *pInsertMenu = aPopupMenu.GetPopupMenu( MN_INSERT );  // add word to user-dictionaries
+        ScopedVclPtrInstance<PopupMenu> aPopupMenu( EditResId( RID_MENU_SPELL ) );
+        PopupMenu *pAutoMenu = aPopupMenu->GetPopupMenu( MN_AUTOCORR );
+        PopupMenu *pInsertMenu = aPopupMenu->GetPopupMenu( MN_INSERT );  // add word to user-dictionaries
         pInsertMenu->SetMenuFlags( MenuFlags::NoAutoMnemonics );         //! necessary to retrieve the correct dictionary names later
 
         EditPaM aPaM2( aPaM );
@@ -824,24 +824,24 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo
             if (nGuessLangPara == LANGUAGE_NONE)
                 nGuessLangPara = nGuessLangWord;
 
-            aPopupMenu.InsertSeparator();
+            aPopupMenu->InsertSeparator();
             OUString aTmpWord( SvtLanguageTable::GetLanguageString( nGuessLangWord ) );
             OUString aTmpPara( SvtLanguageTable::GetLanguageString( nGuessLangPara ) );
             OUString aWordStr( EE_RESSTR( RID_STR_WORD ) );
             aWordStr = aWordStr.replaceFirst( "%x", aTmpWord );
             OUString aParaStr( EE_RESSTR( RID_STR_PARAGRAPH ) );
             aParaStr = aParaStr.replaceFirst( "%x", aTmpPara );
-            aPopupMenu.InsertItem( MN_WORDLANGUAGE, aWordStr );
-            aPopupMenu.SetHelpId( MN_WORDLANGUAGE, HID_EDITENG_SPELLER_WORDLANGUAGE );
-            aPopupMenu.InsertItem( MN_PARALANGUAGE, aParaStr );
-            aPopupMenu.SetHelpId( MN_PARALANGUAGE, HID_EDITENG_SPELLER_PARALANGUAGE );
+            aPopupMenu->InsertItem( MN_WORDLANGUAGE, aWordStr );
+            aPopupMenu->SetHelpId( MN_WORDLANGUAGE, HID_EDITENG_SPELLER_WORDLANGUAGE );
+            aPopupMenu->InsertItem( MN_PARALANGUAGE, aParaStr );
+            aPopupMenu->SetHelpId( MN_PARALANGUAGE, HID_EDITENG_SPELLER_PARALANGUAGE );
         }
 
         // ## Create mnemonics here
         if ( Application::IsAutoMnemonicEnabled() )
         {
-            aPopupMenu.CreateAutoMnemonics();
-            aPopupMenu.SetMenuFlags( aPopupMenu.GetMenuFlags() | MenuFlags::NoAutoMnemonics );
+            aPopupMenu->CreateAutoMnemonics();
+            aPopupMenu->SetMenuFlags( aPopupMenu->GetMenuFlags() | MenuFlags::NoAutoMnemonics );
         }
 
         // Replace suggestions...
@@ -855,13 +855,13 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo
             for ( sal_uInt16 nW = 0; nW < nWords; nW++ )
             {
                 OUString aAlternate( pAlt[nW] );
-                aPopupMenu.InsertItem( MN_ALTSTART+nW, aAlternate, MenuItemBits::NONE, OString(), nW );
+                aPopupMenu->InsertItem( MN_ALTSTART+nW, aAlternate, MenuItemBits::NONE, OString(), nW );
                 pAutoMenu->InsertItem( MN_AUTOSTART+nW, aAlternate, MenuItemBits::NONE, OString(), nW );
             }
-            aPopupMenu.InsertSeparator(OString(), nWords);
+            aPopupMenu->InsertSeparator(OString(), nWords);
         }
         else
-            aPopupMenu.RemoveItem( MN_AUTOCORR );   // delete?
+            aPopupMenu->RemoveItem( MN_AUTOCORR );   // delete?
 
         SvtLinguConfig aCfg;
 
@@ -915,18 +915,18 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo
             }
         }
         if ( pInsertMenu->GetItemCount() != 1)
-            aPopupMenu.EnableItem( MN_INSERT_SINGLE, false );
+            aPopupMenu->EnableItem( MN_INSERT_SINGLE, false );
         if ( pInsertMenu->GetItemCount() < 2 )
-            aPopupMenu.EnableItem( MN_INSERT, false );
+            aPopupMenu->EnableItem( MN_INSERT, false );
 
-        aPopupMenu.RemoveDisabledEntries( true, true );
+        aPopupMenu->RemoveDisabledEntries( true, true );
 
         Rectangle aTempRect = pImpEditView->pEditEngine->pImpEditEngine->PaMtoEditCursor( aPaM, GETCRSR_TXTONLY );
         Point aScreenPos = pImpEditView->GetWindowPos( aTempRect.TopLeft() );
         aScreenPos = pImpEditView->GetWindow()->OutputToScreenPixel( aScreenPos );
         aTempRect = pImpEditView->GetWindow()->LogicToPixel( Rectangle(aScreenPos, aTempRect.GetSize() ));
 
-        sal_uInt16 nId = aPopupMenu.Execute( pImpEditView->GetWindow(), aTempRect, PopupMenuFlags::NoMouseUpClose );
+        sal_uInt16 nId = aPopupMenu->Execute( pImpEditView->GetWindow(), aTempRect, PopupMenuFlags::NoMouseUpClose );
         if ( nId == MN_IGNORE )
         {
             OUString aWord = pImpEditView->SpellIgnoreWord();
diff --git a/extensions/source/bibliography/toolbar.cxx b/extensions/source/bibliography/toolbar.cxx
index 3cf37e4..65e4010 100644
--- a/extensions/source/bibliography/toolbar.cxx
+++ b/extensions/source/bibliography/toolbar.cxx
@@ -383,21 +383,21 @@ void BibToolBar::Click()
 
 void BibToolBar::ClearFilterMenu()
 {
-    aPopupMenu.Clear();
+    pPopupMenu->Clear();
     nMenuId=0;
 }
 sal_uInt16 BibToolBar::InsertFilterItem(const OUString& aMenuEntry)
 {
     nMenuId++;
-    aPopupMenu.InsertItem(nMenuId,aMenuEntry);
+    pPopupMenu->InsertItem(nMenuId,aMenuEntry);
 
     return nMenuId;
 }
 void BibToolBar::SelectFilterItem(sal_uInt16    nId)
 {
-    aPopupMenu.CheckItem(nId);
+    pPopupMenu->CheckItem(nId);
     nSelMenuItem=nId;
-    aQueryField = MnemonicGenerator::EraseAllMnemonicChars( aPopupMenu.GetItemText(nId) );
+    aQueryField = MnemonicGenerator::EraseAllMnemonicChars( pPopupMenu->GetItemText(nId) );
 }
 
 void BibToolBar::EnableSourceList(bool bFlag)
@@ -490,15 +490,15 @@ IMPL_LINK_NOARG_TYPED( BibToolBar, MenuHdl, ToolBox*, void)
         EndSelection();     // vor SetDropMode (SetDropMode ruft SetItemImage)
 
         SetItemDown(nTBC_BT_AUTOFILTER, true);
-        nId = aPopupMenu.Execute(this, GetItemRect(nTBC_BT_AUTOFILTER));
+        nId = pPopupMenu->Execute(this, GetItemRect(nTBC_BT_AUTOFILTER));
 
 
         if(nId>0)
         {
-            aPopupMenu.CheckItem(nSelMenuItem,false);
-            aPopupMenu.CheckItem(nId);
+            pPopupMenu->CheckItem(nSelMenuItem,false);
+            pPopupMenu->CheckItem(nId);
             nSelMenuItem=nId;
-            aQueryField = MnemonicGenerator::EraseAllMnemonicChars( aPopupMenu.GetItemText(nId) );
+            aQueryField = MnemonicGenerator::EraseAllMnemonicChars( pPopupMenu->GetItemText(nId) );
             Sequence<PropertyValue> aPropVal(2);
             PropertyValue* pPropertyVal = const_cast<PropertyValue*>(aPropVal.getConstArray());
             pPropertyVal[0].Name = "QueryText";
diff --git a/extensions/source/bibliography/toolbar.hxx b/extensions/source/bibliography/toolbar.hxx
index 9743e28..97f189c 100644
--- a/extensions/source/bibliography/toolbar.hxx
+++ b/extensions/source/bibliography/toolbar.hxx
@@ -116,7 +116,7 @@ class BibToolBar:   public ToolBox
         VclPtr<ListBox>         aLBSource;
         VclPtr<FixedText>       aFtQuery;
         VclPtr<Edit>            aEdQuery;
-        PopupMenu               aPopupMenu;
+        ScopedVclPtr<PopupMenu> pPopupMenu;
         sal_uInt16              nMenuId;
         sal_uInt16              nSelMenuItem;
         OUString                aQueryField;
diff --git a/extensions/source/update/ui/updatecheckui.cxx b/extensions/source/update/ui/updatecheckui.cxx
index f8f9e9f..25f5655 100644
--- a/extensions/source/update/ui/updatecheckui.cxx
+++ b/extensions/source/update/ui/updatecheckui.cxx
@@ -126,7 +126,7 @@ class UpdateCheckUI : public ::cppu::WeakImplHelper
     Image               maBubbleImage;
     VclPtr<BubbleWindow> mpBubbleWin;
     VclPtr<SystemWindow> mpIconSysWin;
-    MenuBar*            mpIconMBar;
+    VclPtr<MenuBar>     mpIconMBar;
     ResMgr*             mpUpdResMgr;
     ResMgr*             mpSfxResMgr;
     Idle                maWaitIdle;
diff --git a/fpicker/source/office/RemoteFilesDialog.hxx b/fpicker/source/office/RemoteFilesDialog.hxx
index a2a7d16..84ba1e7 100644
--- a/fpicker/source/office/RemoteFilesDialog.hxx
+++ b/fpicker/source/office/RemoteFilesDialog.hxx
@@ -162,7 +162,7 @@ private:
     VclPtr< FileViewContainer > m_pContainer;
     VclPtr< ListBox > m_pFilter_lb;
     VclPtr< AutocompleteEdit > m_pName_ed;
-    PopupMenu* m_pAddMenu;
+    VclPtr<PopupMenu> m_pAddMenu;
 
     ImageList m_aImages;
 
diff --git a/fpicker/source/office/iodlgimp.cxx b/fpicker/source/office/iodlgimp.cxx
index 7aaa3d0..9cee811 100644
--- a/fpicker/source/office/iodlgimp.cxx
+++ b/fpicker/source/office/iodlgimp.cxx
@@ -91,7 +91,7 @@ SvtFileDialogFilter_Impl::~SvtFileDialogFilter_Impl()
 SvtFileDialogURLSelector::SvtFileDialogURLSelector( vcl::Window* _pParent, SvtFileDialog* _pDlg, WinBits nBits, sal_uInt16 _nButtonId )
     :MenuButton ( _pParent, nBits )
     ,m_pDlg     ( _pDlg )
-    ,m_pMenu    ( new PopupMenu )
+    ,m_pMenu    ( VclPtr<PopupMenu>::Create() )
 {
     SetStyle( GetStyle() | WB_NOPOINTERFOCUS | WB_RECTSTYLE | WB_SMALLSTYLE );
     SetModeImage( _pDlg->GetButtonImage( _nButtonId ) );
@@ -107,7 +107,7 @@ SvtFileDialogURLSelector::~SvtFileDialogURLSelector()
 
 void SvtFileDialogURLSelector::dispose()
 {
-    delete m_pMenu;
+    m_pMenu.disposeAndClear();
     m_pDlg.clear();
     MenuButton::dispose();
 }
diff --git a/fpicker/source/office/iodlgimp.hxx b/fpicker/source/office/iodlgimp.hxx
index 1726a39..7ad9443 100644
--- a/fpicker/source/office/iodlgimp.hxx
+++ b/fpicker/source/office/iodlgimp.hxx
@@ -84,7 +84,7 @@ public:
     virtual void dispose() override;
 private:
     VclPtr<SvtFileDialog>      m_pDlg;
-    PopupMenu*          m_pMenu;
+    VclPtr<PopupMenu>          m_pMenu;
 
 protected:
     inline        SvtFileDialog*  GetDialogParent()       { return m_pDlg; }
diff --git a/framework/inc/classes/rootactiontriggercontainer.hxx b/framework/inc/classes/rootactiontriggercontainer.hxx
index bc0fa2b..53d009c 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 805a232..69f57f7 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 0405df3..8e30d5d 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 354c0fd..1cced99 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 f69ae27..2e20b30 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 3749606..33a171b 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 3dfab06..7d65c33 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 00e91ac..f9852ac 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 620462b..46fd4e0 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 3007e8a44..3f1d1c2 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 4751414..8adb19f 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 1d20272..d420fa1 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 5dd73a6..4e726c1 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 7521384..68a3e00 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 );
     }
diff --git a/include/framework/addonmenu.hxx b/include/framework/addonmenu.hxx
index b909d61..fec0de7 100644
--- a/include/framework/addonmenu.hxx
+++ b/include/framework/addonmenu.hxx
@@ -39,6 +39,7 @@ class FWE_DLLPUBLIC AddonMenu : public PopupMenu
     public:
         AddonMenu( const css::uno::Reference< css::frame::XFrame >& rFrame );
         virtual ~AddonMenu();
+        virtual void dispose() override;
 
     protected:
         css::uno::Reference< css::frame::XFrame > m_xFrame;
@@ -62,6 +63,7 @@ class FWE_DLLPUBLIC AddonPopupMenu : public AddonMenu
         OUString               m_aCommandURL;
 
     friend class AddonMenuManager;
+    friend class ::VclPtr<AddonPopupMenu>;
 };
 
 class FWE_DLLPUBLIC AddonMenuManager
@@ -81,10 +83,10 @@ class FWE_DLLPUBLIC AddonMenuManager
         static bool IsCorrectContext(const OUString& rModuleIdentifier, const OUString& rContext);
 
         // Factory method to create different Add-On menu types
-        static PopupMenu* CreatePopupMenuType( MenuType eMenuType, const css::uno::Reference< css::frame::XFrame >& rFrame );
+        static VclPtr<PopupMenu> CreatePopupMenuType( MenuType eMenuType, const css::uno::Reference< css::frame::XFrame >& rFrame );
 
         // Create the Add-Ons menu
-        static AddonMenu* CreateAddonMenu( const css::uno::Reference< css::frame::XFrame >& rFrame,
+        static VclPtr<AddonMenu> CreateAddonMenu( const css::uno::Reference< css::frame::XFrame >& rFrame,
                                            const css::uno::Reference< css::uno::XComponentContext >& rContext );
 
         // Merge the Add-Ons help menu items into the given menu bar at a defined pos
diff --git a/include/sfx2/sidebar/SidebarController.hxx b/include/sfx2/sidebar/SidebarController.hxx
index 7634272..cbed84e 100644
--- a/include/sfx2/sidebar/SidebarController.hxx
+++ b/include/sfx2/sidebar/SidebarController.hxx
@@ -237,7 +237,7 @@ private:
     void ShowPopupMenu (
         const Rectangle& rButtonBox,
         const ::std::vector<TabBar::DeckMenuData>& rMenuData) const;
-    std::shared_ptr<PopupMenu> CreatePopupMenu (
+    VclPtr<PopupMenu> CreatePopupMenu (
         const ::std::vector<TabBar::DeckMenuData>& rMenuData) const;
     DECL_LINK_TYPED(OnMenuItemSelected, Menu*, bool);
     void BroadcastPropertyChange();
diff --git a/include/sfx2/templatedlg.hxx b/include/sfx2/templatedlg.hxx
index 3b7f2b9..eeec07c 100644
--- a/include/sfx2/templatedlg.hxx
+++ b/include/sfx2/templatedlg.hxx
@@ -155,9 +155,9 @@ protected:
     VclPtr<TemplateAbstractView> mpCurView;
     VclPtr<TemplateLocalView> mpLocalView;
     VclPtr<TemplateRemoteView> mpRemoteView;
-    PopupMenu *mpActionMenu;
-    PopupMenu *mpRepositoryMenu;
-    PopupMenu *mpTemplateDefaultMenu;
+    VclPtr<PopupMenu> mpActionMenu;
+    VclPtr<PopupMenu> mpRepositoryMenu;
+    VclPtr<PopupMenu> mpTemplateDefaultMenu;
 
     std::set<const ThumbnailViewItem*,selection_cmp_fn> maSelTemplates;
 
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index b46b092..fba08dfea 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -282,7 +282,7 @@ public:
     css::uno::Reference< css::frame::XController >
                                 GetController();
 
-    bool                        TryContextMenuInterception( Menu& rIn, const OUString& rMenuIdentifier, Menu*& rpOut, css::ui::ContextMenuExecuteEvent aEvent );
+    bool                        TryContextMenuInterception( Menu& rIn, const OUString& rMenuIdentifier, VclPtr<Menu>& rpOut, css::ui::ContextMenuExecuteEvent aEvent );
     bool                        TryContextMenuInterception( Menu& rMenu, const OUString& rMenuIdentifier, css::ui::ContextMenuExecuteEvent aEvent );
 
     void                        ExecPrint( const css::uno::Sequence < css::beans::PropertyValue >&, bool, bool );
diff --git a/include/svtools/treelistbox.hxx b/include/svtools/treelistbox.hxx
index 88d39df..9421703 100644
--- a/include/svtools/treelistbox.hxx
+++ b/include/svtools/treelistbox.hxx
@@ -775,7 +775,7 @@ public:
     void            ShowFocusRect( const SvTreeListEntry* pEntry );
     void            InitStartEntry();
 
-    virtual std::unique_ptr<PopupMenu> CreateContextMenu();
+    virtual VclPtr<PopupMenu> CreateContextMenu();
     virtual void    ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry );
 
     void            EnableContextMenuHandling();
diff --git a/include/svx/clipboardctl.hxx b/include/svx/clipboardctl.hxx
index f244d32..931b3d2 100644
--- a/include/svx/clipboardctl.hxx
+++ b/include/svx/clipboardctl.hxx
@@ -33,7 +33,7 @@ class SvxClipboardFormatItem;
 class SAL_WARN_UNUSED SVX_DLLPUBLIC SvxClipBoardControl : public SfxToolBoxControl
 {
     SfxPoolItem*            pClipboardFmtItem;
-    PopupMenu*              pPopup;
+    VclPtr<PopupMenu>       pPopup;
     bool                    bDisabled;
 
     void                    DelPopup();
diff --git a/include/toolkit/awt/vclxmenu.hxx b/include/toolkit/awt/vclxmenu.hxx
index d092692..e042e01 100644
--- a/include/toolkit/awt/vclxmenu.hxx
+++ b/include/toolkit/awt/vclxmenu.hxx
@@ -33,6 +33,7 @@
 #include <osl/mutex.hxx>
 
 #include <tools/link.hxx>
+#include <vcl/vclptr.hxx>
 
 #include <vector>
 
@@ -59,7 +60,7 @@ class TOOLKIT_DLLPUBLIC VCLXMenu :  public css::awt::XMenuBar,
 {
 private:
     ::osl::Mutex            maMutex;
-    Menu*                   mpMenu;
+    VclPtr<Menu>            mpMenu;
     MenuListenerMultiplexer maMenuListeners;
     PopupMenuRefList        maPopupMenuRefs;
 
diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx
index 928e512..8c50fee 100644
--- a/include/vcl/builder.hxx
+++ b/include/vcl/builder.hxx
@@ -156,12 +156,9 @@ private:
     struct MenuAndId
     {
         OString m_sID;
-        PopupMenu *m_pMenu;
-        MenuAndId(const OString &rId, PopupMenu *pMenu)
-            : m_sID(rId)
-            , m_pMenu(pMenu)
-        {
-        }
+        VclPtr<PopupMenu> m_pMenu;
+        MenuAndId(const OString &rId, PopupMenu *pMenu);
+        ~MenuAndId();
     };
     std::vector<MenuAndId> m_aMenus;
 
diff --git a/include/vcl/edit.hxx b/include/vcl/edit.hxx
index 357dc6a..4c9424c 100644
--- a/include/vcl/edit.hxx
+++ b/include/vcl/edit.hxx
@@ -265,8 +265,7 @@ public:
     static void                 SetGetSpecialCharsFunction( FncGetSpecialChars fn );
     static FncGetSpecialChars   GetGetSpecialCharsFunction();
 
-    static PopupMenu*   CreatePopupMenu();
-    static void         DeletePopupMenu( PopupMenu* pMenu );
+    static VclPtr<PopupMenu>    CreatePopupMenu();
 
     virtual OUString GetSurroundingText() const override;
     virtual Selection GetSurroundingTextSelection() const override;
diff --git a/include/vcl/menu.hxx b/include/vcl/menu.hxx
index c4fa65b..81bb0c5 100644
--- a/include/vcl/menu.hxx
+++ b/include/vcl/menu.hxx
@@ -28,6 +28,7 @@
 #include <vcl/dllapi.h>
 #include <vcl/bitmapex.hxx>
 #include <vcl/keycod.hxx>
+#include <vcl/vclreferencebase.hxx>
 #include <vcl/vclevent.hxx>
 #include <com/sun/star/frame/XFrame.hpp>
 #include <com/sun/star/uno/Reference.hxx>
@@ -104,7 +105,7 @@ namespace o3tl
 struct ImplMenuDelData
 {
     ImplMenuDelData* mpNext;
-    const Menu* mpMenu;
+    VclPtr<const Menu> mpMenu;
 
     explicit ImplMenuDelData( const Menu* );
     ~ImplMenuDelData();
@@ -121,7 +122,7 @@ struct MenuLogo
 
 typedef void (*MenuUserDataReleaseFunction)(sal_uLong);
 
-class VCL_DLLPUBLIC Menu : public Resource
+class VCL_DLLPUBLIC Menu : public Resource, public VclReferenceBase
 {
     friend class MenuBar;
     friend class MenuBarWindow;
@@ -134,7 +135,7 @@ private:
     ImplMenuDelData* mpFirstDel;
     MenuItemList* pItemList; // Liste mit den MenuItems
     MenuLogo* pLogo;
-    Menu* pStartedFrom;
+    VclPtr<Menu> pStartedFrom;
     VclPtr<vcl::Window> pWindow;
 
     Link<Menu*, bool> aActivateHdl;       // Active-Handler
@@ -230,6 +231,7 @@ protected:
 
 public:
     virtual ~Menu();
+    virtual void dispose() override;
 
     void Activate();
     void Deactivate();
@@ -432,6 +434,7 @@ public:
     MenuBar();
     MenuBar( const MenuBar& rMenu );
     virtual ~MenuBar();
+    virtual void dispose() override;
 
     MenuBar& operator =( const MenuBar& rMenu );
 
@@ -467,7 +470,7 @@ public:
     {
         sal_uInt16 nId;    // Id of the button
         bool bHighlight;   // highlight on/off
-        MenuBar* pMenuBar; // menubar the button belongs to
+        VclPtr<MenuBar> pMenuBar; // menubar the button belongs to
     };
     // add an arbitrary button to the menubar (will appear next to closer)
     // passed link will be call with a MenuBarButtonCallbackArg on press
@@ -498,7 +501,7 @@ class VCL_DLLPUBLIC PopupMenu : public Menu
     friend struct MenuItemData;
 
 private:
-    Menu** pRefAutoSubMenu; // keeps track if a pointer to this Menu is stored in the MenuItemData
+    VclPtr<Menu>* pRefAutoSubMenu; // keeps track if a pointer to this Menu is stored in the MenuItemData
 
     SAL_DLLPRIVATE MenuFloatingWindow * ImplGetFloatingWindow() const;
 
@@ -513,6 +516,7 @@ public:
     PopupMenu( const PopupMenu& rMenu );
     explicit PopupMenu( const ResId& );
     virtual ~PopupMenu();
+    virtual void dispose() override;
 
     virtual bool IsMenuBar() const override { return false; }
 
diff --git a/include/vcl/menubtn.hxx b/include/vcl/menubtn.hxx
index 5f791cb..8d8438f 100644
--- a/include/vcl/menubtn.hxx
+++ b/include/vcl/menubtn.hxx
@@ -36,8 +36,8 @@ private:
     friend class VclBuilder;
 
     Timer*          mpMenuTimer;
-    PopupMenu*      mpOwnMenu;
-    PopupMenu*      mpMenu;
+    VclPtr<PopupMenu> mpOwnMenu;
+    VclPtr<PopupMenu> mpMenu;
     sal_uInt16      mnCurItemId;
     sal_uInt16      mnMenuMode;
     Link<MenuButton*,void> maActivateHdl;
diff --git a/include/vcl/syswin.hxx b/include/vcl/syswin.hxx
index fd09ad9..cbd2a9c 100644
--- a/include/vcl/syswin.hxx
+++ b/include/vcl/syswin.hxx
@@ -151,7 +151,7 @@ class VCL_DLLPUBLIC SystemWindow
     class ImplData;
 
 private:
-    MenuBar*        mpMenuBar;
+    VclPtr<MenuBar> mpMenuBar;
     Size            maOrgSize;
     Size            maRollUpOutSize;
     Size            maMinOutSize;
diff --git a/include/vcl/vclevent.hxx b/include/vcl/vclevent.hxx
index 83bcd57..b376054 100644
--- a/include/vcl/vclevent.hxx
+++ b/include/vcl/vclevent.hxx
@@ -222,14 +222,14 @@ public:
 class VCL_DLLPUBLIC VclMenuEvent : public VclSimpleEvent
 {
 private:
-    Menu* pMenu;
+    VclPtr<Menu> pMenu;
     sal_uInt16 mnPos;
 
 public:
-    VclMenuEvent( Menu* pM, sal_uLong n, sal_uInt16 nPos ) : VclSimpleEvent(n) { pMenu = pM; mnPos = nPos; }
-    virtual ~VclMenuEvent() {}
+    VclMenuEvent( Menu* pM, sal_uLong n, sal_uInt16 nPos );
+    virtual ~VclMenuEvent();
 
-    Menu* GetMenu() const { return pMenu; }
+    Menu* GetMenu() const;
     sal_uInt16 GetItemPos() const { return mnPos; }
 };
 
diff --git a/reportdesign/source/ui/dlg/GroupsSorting.cxx b/reportdesign/source/ui/dlg/GroupsSorting.cxx
index 83b28b2..fdd00a7 100644
--- a/reportdesign/source/ui/dlg/GroupsSorting.cxx
+++ b/reportdesign/source/ui/dlg/GroupsSorting.cxx
@@ -717,7 +717,7 @@ void OFieldExpressionControl::Command(const CommandEvent& rEvt)
 
             if ( nColId == HANDLE_ID )
             {
-                PopupMenu aContextMenu(ModuleRes(RID_GROUPSROWPOPUPMENU));
+                ScopedVclPtrInstance<PopupMenu> aContextMenu(ModuleRes(RID_GROUPSROWPOPUPMENU));
                 bool bEnable = false;
                 long nIndex = FirstSelectedRow();
                 while( nIndex >= 0 && !bEnable )
@@ -726,8 +726,8 @@ void OFieldExpressionControl::Command(const CommandEvent& rEvt)
                         bEnable = true;
                     nIndex = NextSelectedRow();
                 }
-                aContextMenu.EnableItem( SID_DELETE, IsDeleteAllowed() && bEnable );
-                switch (aContextMenu.Execute(this, rEvt.GetMousePosPixel()))
+                aContextMenu->EnableItem( SID_DELETE, IsDeleteAllowed() && bEnable );
+                switch (aContextMenu->Execute(this, rEvt.GetMousePosPixel()))
                 {
                     case SID_CUT:
                         cut();
diff --git a/reportdesign/source/ui/dlg/Navigator.cxx b/reportdesign/source/ui/dlg/Navigator.cxx
index 0413884..da0e0fa 100644
--- a/reportdesign/source/ui/dlg/Navigator.cxx
+++ b/reportdesign/source/ui/dlg/Navigator.cxx
@@ -306,27 +306,27 @@ void NavigatorTree::Command( const CommandEvent& rEvt )
             uno::Reference< report::XGroup> xGroup(pData->getContent(),uno::UNO_QUERY);
             bool bDeleteAllowed = m_rController.isEditable() && (xGroup.is() ||
                                       uno::Reference< report::XFunction>(pData->getContent(),uno::UNO_QUERY).is());
-            PopupMenu aContextMenu( ModuleRes( RID_MENU_NAVIGATOR ) );
+            ScopedVclPtrInstance<PopupMenu> aContextMenu( ModuleRes( RID_MENU_NAVIGATOR ) );
 
-            sal_uInt16 nCount = aContextMenu.GetItemCount();
+            sal_uInt16 nCount = aContextMenu->GetItemCount();
             for (sal_uInt16 i = 0; i < nCount; ++i)
             {
-                if ( MenuItemType::SEPARATOR != aContextMenu.GetItemType(i))
+                if ( MenuItemType::SEPARATOR != aContextMenu->GetItemType(i))
                 {
-                    sal_uInt16 nId = aContextMenu.GetItemId(i);
+                    sal_uInt16 nId = aContextMenu->GetItemId(i);
 
-                    aContextMenu.CheckItem(nId,m_rController.isCommandChecked(nId));
+                    aContextMenu->CheckItem(nId,m_rController.isCommandChecked(nId));
                     bool bEnabled = m_rController.isCommandEnabled(nId);
                     if ( nId == SID_RPT_NEW_FUNCTION )
-                        aContextMenu.EnableItem(nId,m_rController.isEditable() && (xSupplier.is() || xFunctions.is()) );
+                        aContextMenu->EnableItem(nId,m_rController.isEditable() && (xSupplier.is() || xFunctions.is()) );
                     // special condition, check for function and group
                     else if ( nId == SID_DELETE )
-                        aContextMenu.EnableItem(SID_DELETE,bDeleteAllowed);
+                        aContextMenu->EnableItem(SID_DELETE,bDeleteAllowed);
                     else
-                        aContextMenu.EnableItem(nId,bEnabled);
+                        aContextMenu->EnableItem(nId,bEnabled);
                 }
             }
-            sal_uInt16 nId = aContextMenu.Execute(this, aWhere);
+            sal_uInt16 nId = aContextMenu->Execute(this, aWhere);
             if ( nId )
             {
                 uno::Sequence< beans::PropertyValue> aArgs;
diff --git a/reportdesign/source/ui/report/ReportSection.cxx b/reportdesign/source/ui/report/ReportSection.cxx
index 4566566..ce723b9 100644
--- a/reportdesign/source/ui/report/ReportSection.cxx
+++ b/reportdesign/source/ui/report/ReportSection.cxx
@@ -477,14 +477,14 @@ void OReportSection::Command( const CommandEvent& _rCEvt )
     {
         OReportController& rController = m_pParent->getViewsWindow()->getView()->getReportView()->getController();
         uno::Reference<frame::XFrame> xFrame = rController.getFrame();
-        PopupMenu aContextMenu( ModuleRes( RID_MENU_REPORT ) );
+        ScopedVclPtrInstance<PopupMenu> aContextMenu( ModuleRes( RID_MENU_REPORT ) );
         uno::Reference< report::XReportDefinition> xReportDefinition = getSection()->getReportDefinition();
 
-        lcl_insertMenuItemImages(aContextMenu,rController,xReportDefinition,xFrame);
+        lcl_insertMenuItemImages(*aContextMenu.get(),rController,xReportDefinition,xFrame);
 
         Point aPos = _rCEvt.GetMousePosPixel();
         m_pView->EndAction();
-        const sal_uInt16 nId = aContextMenu.Execute(this, aPos);
+        const sal_uInt16 nId = aContextMenu->Execute(this, aPos);
         if ( nId )
         {
             uno::Sequence< beans::PropertyValue> aArgs;
diff --git a/sc/source/ui/dbgui/csvgrid.cxx b/sc/source/ui/dbgui/csvgrid.cxx
index e2a8ec2..850453b 100644
--- a/sc/source/ui/dbgui/csvgrid.cxx
+++ b/sc/source/ui/dbgui/csvgrid.cxx
@@ -78,7 +78,7 @@ ScCsvGrid::ScCsvGrid( ScCsvControl& rParent ) :
     mpEditEngine->SetRefMapMode( MapMode( MAP_PIXEL ) );
     maEdEngSize = mpEditEngine->GetPaperSize();
 
-    maPopup.SetMenuFlags( maPopup.GetMenuFlags() | MenuFlags::NoAutoMnemonics );
+    mpPopup->SetMenuFlags( mpPopup->GetMenuFlags() | MenuFlags::NoAutoMnemonics );
 
     EnableRTL( false ); // RTL
     InitFonts();
@@ -505,12 +505,12 @@ void ScCsvGrid::SetTypeNames( const std::vector<OUString>& rTypeNames )
     maTypeNames = rTypeNames;
     Repaint( true );
 
-    maPopup.Clear();
+    mpPopup->Clear();
     sal_uInt32 nCount = maTypeNames.size();
     sal_uInt32 nIx;
     sal_uInt16 nItemId;
     for( nIx = 0, nItemId = 1; nIx < nCount; ++nIx, ++nItemId )
-        maPopup.InsertItem( nItemId, maTypeNames[ nIx ] );
+        mpPopup->InsertItem( nItemId, maTypeNames[ nIx ] );
 
     ::std::for_each( maColStates.begin(), maColStates.end(), Func_SetType( CSV_TYPE_DEFAULT ) );
 }
@@ -582,9 +582,9 @@ void ScCsvGrid::ScrollVertRel( ScMoveMode eDir )
 
 void ScCsvGrid::ExecutePopup( const Point& rPos )
 {
-    sal_uInt16 nItemId = maPopup.Execute( this, rPos );
+    sal_uInt16 nItemId = mpPopup->Execute( this, rPos );
     if( nItemId )   // 0 = cancelled
-        Execute( CSVCMD_SETCOLUMNTYPE, maPopup.GetItemPos( nItemId ) );
+        Execute( CSVCMD_SETCOLUMNTYPE, mpPopup->GetItemPos( nItemId ) );
 }
 
 // selection handling ---------------------------------------------------------
diff --git a/sc/source/ui/inc/csvgrid.hxx b/sc/source/ui/inc/csvgrid.hxx
index 772ef36..63e2013 100644
--- a/sc/source/ui/inc/csvgrid.hxx
+++ b/sc/source/ui/inc/csvgrid.hxx
@@ -62,7 +62,7 @@ private:
 
     VclPtr<VirtualDevice>       mpBackgrDev;        /// Grid background, headers, cell texts.
     VclPtr<VirtualDevice>       mpGridDev;          /// Data grid with selection and cursor.
-    PopupMenu                   maPopup;            /// Popup menu for column types.
+    VclPtr<PopupMenu>           mpPopup;            /// Popup menu for column types.
 
     ::svtools::ColorConfig*     mpColorConfig;      /// Application color configuration.
     Color                       maBackColor;        /// Cell background color.
diff --git a/sc/source/ui/inc/tphfedit.hxx b/sc/source/ui/inc/tphfedit.hxx
index fcb829f..31c331c 100644
--- a/sc/source/ui/inc/tphfedit.hxx
+++ b/sc/source/ui/inc/tphfedit.hxx
@@ -104,7 +104,7 @@ class SC_DLLPUBLIC ScExtIButton : public ImageButton
 private:
 
     Idle            aIdle;
-    PopupMenu*      pPopupMenu;
+    VclPtr<PopupMenu>        pPopupMenu;
     Link<ScExtIButton&,void> aMLink;
     sal_uInt16      nSelected;
     OString         aSelectedIdent;
@@ -122,6 +122,8 @@ protected:
 public:
 
     ScExtIButton(vcl::Window* pParent, WinBits nBits );
+    virtual ~ScExtIButton();
+    virtual void dispose() override;
 
     void            SetPopupMenu(PopupMenu* pPopUp);
 
diff --git a/sc/source/ui/miscdlgs/acredlin.cxx b/sc/source/ui/miscdlgs/acredlin.cxx
index 407bd39..3121b36 100644
--- a/sc/source/ui/miscdlgs/acredlin.cxx
+++ b/sc/source/ui/miscdlgs/acredlin.cxx
@@ -1676,9 +1676,9 @@ IMPL_LINK_NOARG_TYPED(ScAcceptChgDlg, CommandHdl, SvSimpleTable*, void)
 
     if(aCEvt.GetCommand()==CommandEventId::ContextMenu)
     {
-        ScPopupMenu aPopup(ScResId(RID_POPUP_CHANGES));
+        ScopedVclPtrInstance<ScPopupMenu> aPopup(ScResId(RID_POPUP_CHANGES));
 
-        aPopup.SetMenuFlags(MenuFlags::HideDisabledEntries);
+        aPopup->SetMenuFlags(MenuFlags::HideDisabledEntries);
 
         SvTreeListEntry* pEntry=pTheView->GetCurEntry();
         if(pEntry!=nullptr)
@@ -1687,7 +1687,7 @@ IMPL_LINK_NOARG_TYPED(ScAcceptChgDlg, CommandHdl, SvSimpleTable*, void)
         }
         else
         {
-            aPopup.Deactivate();
+            aPopup->Deactivate();
         }
 
         sal_uInt16 nSortedCol= pTheView->GetSortedCol();
@@ -1696,15 +1696,15 @@ IMPL_LINK_NOARG_TYPED(ScAcceptChgDlg, CommandHdl, SvSimpleTable*, void)
         {
             sal_uInt16 nItemId=nSortedCol+SC_SUB_SORT+1;
 
-            aPopup.CheckItem(nItemId);
+            aPopup->CheckItem(nItemId);
 
-            PopupMenu *pSubMenu = aPopup.GetPopupMenu(SC_SUB_SORT);
+            PopupMenu *pSubMenu = aPopup->GetPopupMenu(SC_SUB_SORT);
 
             if (pSubMenu)
                 pSubMenu->CheckItem(nItemId);
         }
 
-        aPopup.EnableItem(SC_CHANGES_COMMENT,false);
+        aPopup->EnableItem(SC_CHANGES_COMMENT,false);
 
         if(pDoc->IsDocEditable() && pEntry!=nullptr)
         {
@@ -1714,11 +1714,11 @@ IMPL_LINK_NOARG_TYPED(ScAcceptChgDlg, CommandHdl, SvSimpleTable*, void)
                 ScChangeAction* pScChangeAction=
                         static_cast<ScChangeAction*>(pEntryData->pData);
                 if(pScChangeAction!=nullptr && !pTheView->GetParent(pEntry))
-                    aPopup.EnableItem(SC_CHANGES_COMMENT);
+                    aPopup->EnableItem(SC_CHANGES_COMMENT);
             }
         }
 
-        sal_uInt16 nCommand=aPopup.Execute( this, GetPointerPosPixel() );
+        sal_uInt16 nCommand = aPopup->Execute( this, GetPointerPosPixel() );
 
         if(nCommand)
         {
diff --git a/sc/source/ui/navipi/content.cxx b/sc/source/ui/navipi/content.cxx
index 7e7a043..1817750 100644
--- a/sc/source/ui/navipi/content.cxx
+++ b/sc/source/ui/navipi/content.cxx
@@ -579,16 +579,16 @@ void ScContentTree::Command( const CommandEvent& rCEvt )
             {
                 //  Drag-Drop Modus
 

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list