diff options
author | Noel Grandin <noel@peralex.com> | 2016-06-20 15:56:35 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-06-23 06:28:00 +0000 |
commit | aa0d0536a444fb26d9e570bd6bf6c1bdc3596cf3 (patch) | |
tree | 8b2a5207e77fa4054a37b33c25378c23a00af8ed /sw | |
parent | b722f3d6fc72877e8caaaae7291d5d736ddc494d (diff) |
tdf#97527 - vcl: reference-count Menu
some places are marked with "dodgy"- need to check those to see
what is going on, because they are leaving dangling pointers behind
in the Menu class
Change-Id: I41d5c7c0fec2f70ce9e3ffdc48cd03d26c0a869b
Reviewed-on: https://gerrit.libreoffice.org/26516
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'sw')
24 files changed, 85 insertions, 81 deletions
diff --git a/sw/inc/AnnotationWin.hxx b/sw/inc/AnnotationWin.hxx index 7296528e9f5b..9d556ed7899d 100644 --- a/sw/inc/AnnotationWin.hxx +++ b/sw/inc/AnnotationWin.hxx @@ -63,8 +63,8 @@ class SwAnnotationWin : public sw::sidebarwindows::SwSidebarWin sal_uInt32 CountFollowing(); SwFormatField* mpFormatField; - SwPostItField* mpField; - PopupMenu* mpButtonPopup; + SwPostItField* mpField; + VclPtr<PopupMenu> mpButtonPopup; }; diff --git a/sw/qa/extras/odfimport/odfimport.cxx b/sw/qa/extras/odfimport/odfimport.cxx index 6a1f493b1ae0..57182c158bad 100644 --- a/sw/qa/extras/odfimport/odfimport.cxx +++ b/sw/qa/extras/odfimport/odfimport.cxx @@ -573,12 +573,12 @@ DECLARE_ODFIMPORT_TEST(testSpellmenuRedline, "spellmenu-redline.odt") SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell(); OUString aParaText; uno::Reference<linguistic2::XSpellAlternatives> xAlt; - SwSpellPopup aPopup(pWrtShell, xAlt, aParaText); + ScopedVclPtrInstance<SwSpellPopup> aPopup(pWrtShell, xAlt, aParaText); // Make sure that if we show the spellcheck popup menu (for the current // document, which contains redlines), then the last two entries will be // always 'go to next/previous change'. - CPPUNIT_ASSERT_EQUAL(sal_uInt16(FN_REDLINE_NEXT_CHANGE), aPopup.GetItemId(aPopup.GetItemCount() - 2)); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(FN_REDLINE_PREV_CHANGE), aPopup.GetItemId(aPopup.GetItemCount() - 1)); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(FN_REDLINE_NEXT_CHANGE), aPopup->GetItemId(aPopup->GetItemCount() - 2)); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(FN_REDLINE_PREV_CHANGE), aPopup->GetItemId(aPopup->GetItemCount() - 1)); } DECLARE_ODFIMPORT_TEST(testAnnotationFormatting, "annotation-formatting.odt") diff --git a/sw/source/uibase/docvw/AnnotationWin.cxx b/sw/source/uibase/docvw/AnnotationWin.cxx index 17bc48ebc4b2..8d9bff9a2a51 100644 --- a/sw/source/uibase/docvw/AnnotationWin.cxx +++ b/sw/source/uibase/docvw/AnnotationWin.cxx @@ -79,7 +79,7 @@ SwAnnotationWin::~SwAnnotationWin() void SwAnnotationWin::dispose() { - delete mpButtonPopup; + mpButtonPopup.disposeAndClear(); sw::sidebarwindows::SwSidebarWin::dispose(); } @@ -220,7 +220,7 @@ sal_uInt32 SwAnnotationWin::CountFollowing() VclPtr<MenuButton> SwAnnotationWin::CreateMenuButton() { - mpButtonPopup = new PopupMenu(SW_RES(MN_ANNOTATION_BUTTON)); + mpButtonPopup = VclPtr<PopupMenu>::Create(SW_RES(MN_ANNOTATION_BUTTON)); OUString aText = mpButtonPopup->GetItemText( FN_DELETE_NOTE_AUTHOR ); SwRewriter aRewriter; aRewriter.AddRule(UndoArg1,GetAuthor()); diff --git a/sw/source/uibase/docvw/HeaderFooterWin.cxx b/sw/source/uibase/docvw/HeaderFooterWin.cxx index b2c33e004b00..b170140fb26b 100644 --- a/sw/source/uibase/docvw/HeaderFooterWin.cxx +++ b/sw/source/uibase/docvw/HeaderFooterWin.cxx @@ -144,7 +144,7 @@ SwHeaderFooterWin::SwHeaderFooterWin( SwEditWin* pEditWin, const SwFrame *pFrame m_pLine->SetZOrder(this, ZOrderFlags::Before); // Create and set the PopupMenu - m_pPopupMenu = new PopupMenu(SW_RES(MN_HEADERFOOTER_BUTTON)); + m_pPopupMenu = VclPtr<PopupMenu>::Create(SW_RES(MN_HEADERFOOTER_BUTTON)); // Rewrite the menu entries' text if (m_bIsHeader) @@ -171,7 +171,7 @@ SwHeaderFooterWin::~SwHeaderFooterWin( ) void SwHeaderFooterWin::dispose() { - delete m_pPopupMenu; + m_pPopupMenu.disposeAndClear(); m_pLine.disposeAndClear(); SwFrameMenuButtonBase::dispose(); } diff --git a/sw/source/uibase/docvw/PageBreakWin.cxx b/sw/source/uibase/docvw/PageBreakWin.cxx index 2070b4c787c0..c556a7b1bde3 100644 --- a/sw/source/uibase/docvw/PageBreakWin.cxx +++ b/sw/source/uibase/docvw/PageBreakWin.cxx @@ -108,7 +108,7 @@ SwPageBreakWin::SwPageBreakWin( SwEditWin* pEditWin, const SwFrame *pFrame ) : m_pLine = VclPtr<SwBreakDashedLine>::Create( GetEditWin(), &SwViewOption::GetPageBreakColor, this ); // Create the popup menu - m_pPopupMenu = new PopupMenu( SW_RES( MN_PAGEBREAK_BUTTON ) ); + m_pPopupMenu = VclPtr<PopupMenu>::Create( SW_RES( MN_PAGEBREAK_BUTTON ) ); m_pPopupMenu->SetDeactivateHdl( LINK( this, SwPageBreakWin, HideHandler ) ); SetPopupMenu( m_pPopupMenu ); @@ -127,8 +127,7 @@ void SwPageBreakWin::dispose() m_aFadeTimer.Stop(); m_pLine.disposeAndClear(); - delete m_pPopupMenu; - m_pPopupMenu = nullptr; + m_pPopupMenu.disposeAndClear(); delete m_pMousePt; m_pMousePt = nullptr; diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index b184da148c88..fedbd8bed1e1 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -5325,20 +5325,20 @@ void SwEditWin::Command( const CommandEvent& rCEvt ) if ( m_rView.GetDocShell()->IsReadOnly() ) { - std::unique_ptr<SwReadOnlyPopup> pROPopup(new SwReadOnlyPopup( aDocPos, m_rView )); + ScopedVclPtrInstance<SwReadOnlyPopup> pROPopup( aDocPos, m_rView ); ui::ContextMenuExecuteEvent aEvent; aEvent.SourceWindow = VCLUnoHelper::GetInterface( this ); aEvent.ExecutePosition.X = aPixPos.X(); aEvent.ExecutePosition.Y = aPixPos.Y(); - Menu* pMenu = nullptr; + VclPtr<Menu> pMenu; OUString sMenuName("private:resource/ReadonlyContextMenu"); if( GetView().TryContextMenuInterception( *pROPopup, sMenuName, pMenu, aEvent ) ) { if ( pMenu ) { - sal_uInt16 nExecId = static_cast<PopupMenu*>(pMenu)->Execute(this, aPixPos); - if( !::ExecuteMenuCommand( *static_cast<PopupMenu*>(pMenu), *m_rView.GetViewFrame(), nExecId )) + sal_uInt16 nExecId = static_cast<PopupMenu*>(pMenu.get())->Execute(this, aPixPos); + if( !::ExecuteMenuCommand( *static_cast<PopupMenu*>(pMenu.get()), *m_rView.GetViewFrame(), nExecId )) pROPopup->Execute(this, nExecId); } else diff --git a/sw/source/uibase/docvw/romenu.cxx b/sw/source/uibase/docvw/romenu.cxx index 3aef4866ede5..d8ebac8b8540 100644 --- a/sw/source/uibase/docvw/romenu.cxx +++ b/sw/source/uibase/docvw/romenu.cxx @@ -53,8 +53,14 @@ using namespace ::sfx2; SwReadOnlyPopup::~SwReadOnlyPopup() { + disposeOnce(); +} + +void SwReadOnlyPopup::dispose() +{ delete pImageMap; delete pTargetURL; + PopupMenu::dispose(); } void SwReadOnlyPopup::Check( sal_uInt16 nMID, sal_uInt16 nSID, SfxDispatcher &rDis ) diff --git a/sw/source/uibase/docvw/romenu.hxx b/sw/source/uibase/docvw/romenu.hxx index 07241c81425b..985cb679810f 100644 --- a/sw/source/uibase/docvw/romenu.hxx +++ b/sw/source/uibase/docvw/romenu.hxx @@ -52,6 +52,7 @@ class SwReadOnlyPopup : public PopupMenu public: SwReadOnlyPopup( const Point &rDPos, SwView &rV ); virtual ~SwReadOnlyPopup(); + virtual void dispose() override; void Execute( vcl::Window* pWin, const Point &rPPos ); void Execute( vcl::Window* pWin, sal_uInt16 nId ); diff --git a/sw/source/uibase/inc/HeaderFooterWin.hxx b/sw/source/uibase/inc/HeaderFooterWin.hxx index ec0980bfaeb0..d98a03238813 100644 --- a/sw/source/uibase/inc/HeaderFooterWin.hxx +++ b/sw/source/uibase/inc/HeaderFooterWin.hxx @@ -22,7 +22,7 @@ class SwHeaderFooterWin : public SwFrameMenuButtonBase { OUString m_sLabel; bool m_bIsHeader; - PopupMenu* m_pPopupMenu; + VclPtr<PopupMenu> m_pPopupMenu; VclPtr<vcl::Window> m_pLine; bool m_bIsAppearing; int m_nFadeRate; diff --git a/sw/source/uibase/inc/PageBreakWin.hxx b/sw/source/uibase/inc/PageBreakWin.hxx index 6ee987f3e333..c5bbfc5193a3 100644 --- a/sw/source/uibase/inc/PageBreakWin.hxx +++ b/sw/source/uibase/inc/PageBreakWin.hxx @@ -22,7 +22,7 @@ class SwPageFrame; */ class SwPageBreakWin : public SwFrameMenuButtonBase { - PopupMenu* m_pPopupMenu; + VclPtr<PopupMenu> m_pPopupMenu; VclPtr<vcl::Window> m_pLine; bool m_bIsAppearing; int m_nFadeRate; diff --git a/sw/source/uibase/inc/conttree.hxx b/sw/source/uibase/inc/conttree.hxx index e496137bf292..27b5469a2444 100644 --- a/sw/source/uibase/inc/conttree.hxx +++ b/sw/source/uibase/inc/conttree.hxx @@ -152,7 +152,7 @@ protected: void GotoContent(SwContent* pCnt); static void SetInDrag(bool bSet) {bIsInDrag = bSet;} - virtual std::unique_ptr<PopupMenu> CreateContextMenu() override; + virtual VclPtr<PopupMenu> CreateContextMenu() override; virtual void ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry ) override; public: @@ -326,7 +326,7 @@ protected: static void SetShowShell(const SfxObjectShell*pSet) {pShowShell = pSet;} DECL_STATIC_LINK_TYPED(SwGlobalTree, ShowFrameHdl, void*, void); - virtual std::unique_ptr<PopupMenu> CreateContextMenu() override; + virtual VclPtr<PopupMenu> CreateContextMenu() override; virtual void ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry ) override; public: diff --git a/sw/source/uibase/inc/inputwin.hxx b/sw/source/uibase/inc/inputwin.hxx index 78531cb08cb5..666a6ae8a5f6 100644 --- a/sw/source/uibase/inc/inputwin.hxx +++ b/sw/source/uibase/inc/inputwin.hxx @@ -49,8 +49,8 @@ friend class InputEdit; VclPtr<Edit> aPos; VclPtr<InputEdit> aEdit; - PopupMenu aPopMenu; - SwFieldMgr* pMgr; + ScopedVclPtrInstance<PopupMenu> aPopMenu; + SwFieldMgr* pMgr; SwWrtShell* pWrtShell; SwView* pView; OUString aAktTableName, sOldFormula; diff --git a/sw/source/uibase/inc/redlndlg.hxx b/sw/source/uibase/inc/redlndlg.hxx index ccf15226632a..c661ae22ff1b 100644 --- a/sw/source/uibase/inc/redlndlg.hxx +++ b/sw/source/uibase/inc/redlndlg.hxx @@ -66,7 +66,7 @@ class SW_DLLPUBLIC SwRedlineAcceptDlg SwRedlineDataChildArr m_RedlineChildren; SwRedlineDataParentSortArr m_aUsedSeqNo; VclPtr<SvxAcceptChgCtr> m_aTabPagesCTRL; - PopupMenu m_aPopup; + ScopedVclPtrInstance<PopupMenu> m_aPopup; Timer m_aDeselectTimer; Timer m_aSelectTimer; OUString m_sInserted; diff --git a/sw/source/uibase/inc/workctrl.hxx b/sw/source/uibase/inc/workctrl.hxx index 20b2314a334c..a90c936014cb 100644 --- a/sw/source/uibase/inc/workctrl.hxx +++ b/sw/source/uibase/inc/workctrl.hxx @@ -54,7 +54,7 @@ class SwView; class SwTbxAutoTextCtrl : public SfxToolBoxControl { - PopupMenu* pPopup; + VclPtr<PopupMenu> pPopup; void DelPopup(); public: diff --git a/sw/source/uibase/misc/redlndlg.cxx b/sw/source/uibase/misc/redlndlg.cxx index 48e342364fc0..eca8ac5fe9ee 100644 --- a/sw/source/uibase/misc/redlndlg.cxx +++ b/sw/source/uibase/misc/redlndlg.cxx @@ -1041,19 +1041,19 @@ IMPL_LINK_NOARG_TYPED(SwRedlineAcceptDlg, CommandHdl, SvSimpleTable*, void) } } - m_aPopup.EnableItem( MN_EDIT_COMMENT, pEntry && pRed && + m_aPopup->EnableItem( MN_EDIT_COMMENT, pEntry && pRed && !m_pTable->GetParent(pEntry) && !m_pTable->NextSelected(pEntry) //JP 27.9.2001: make no sense if we handle readonly sections // && pRed->HasReadonlySel() ); - m_aPopup.EnableItem( MN_SUB_SORT, m_pTable->First() != nullptr ); + m_aPopup->EnableItem( MN_SUB_SORT, m_pTable->First() != nullptr ); sal_uInt16 nColumn = m_pTable->GetSortedCol(); if (nColumn == 0xffff) nColumn = 4; - PopupMenu *pSubMenu = m_aPopup.GetPopupMenu(MN_SUB_SORT); + PopupMenu *pSubMenu = m_aPopup->GetPopupMenu(MN_SUB_SORT); if (pSubMenu) { for (sal_uInt16 i = MN_SORT_ACTION; i < MN_SORT_ACTION + 5; i++) @@ -1062,7 +1062,7 @@ IMPL_LINK_NOARG_TYPED(SwRedlineAcceptDlg, CommandHdl, SvSimpleTable*, void) pSubMenu->CheckItem(nColumn + MN_SORT_ACTION); } - sal_uInt16 nRet = m_aPopup.Execute(m_pTable, aCEvt.GetMousePosPixel()); + sal_uInt16 nRet = m_aPopup->Execute(m_pTable, aCEvt.GetMousePosPixel()); switch( nRet ) { diff --git a/sw/source/uibase/ribbar/inputwin.cxx b/sw/source/uibase/ribbar/inputwin.cxx index 90df5738262c..84acdb149e58 100644 --- a/sw/source/uibase/ribbar/inputwin.cxx +++ b/sw/source/uibase/ribbar/inputwin.cxx @@ -124,7 +124,7 @@ SwInputWindow::SwInputWindow(vcl::Window* pParent, SfxDispatcher* pDispatcher) aPos->SetPosSizePixel( aPosPos, aPosSize ); aEdit->SetPosSizePixel( aEditPos, aEditSize ); - aPopMenu.SetSelectHdl(LINK( this, SwInputWindow, MenuHdl )); + aPopMenu->SetSelectHdl(LINK( this, SwInputWindow, MenuHdl )); } SwInputWindow::~SwInputWindow() @@ -350,7 +350,7 @@ IMPL_LINK_NOARG_TYPED(SwInputWindow, DropdownClickHdl, ToolBox *, void) { case FN_FORMULA_CALC : { - aPopMenu.Execute( this, GetItemRect( FN_FORMULA_CALC ), PopupMenuFlags::NoMouseUpClose ); + aPopMenu->Execute( this, GetItemRect( FN_FORMULA_CALC ), PopupMenuFlags::NoMouseUpClose ); break; default: break; diff --git a/sw/source/uibase/ribbar/workctrl.cxx b/sw/source/uibase/ribbar/workctrl.cxx index 710b5c7c11ca..ad207523df3d 100644 --- a/sw/source/uibase/ribbar/workctrl.cxx +++ b/sw/source/uibase/ribbar/workctrl.cxx @@ -86,7 +86,7 @@ VclPtr<SfxPopupWindow> SwTbxAutoTextCtrl::CreatePopupWindow() { Link<Menu*,bool> aLnk = LINK(this, SwTbxAutoTextCtrl, PopupHdl); - pPopup = new PopupMenu; + pPopup = VclPtr<PopupMenu>::Create(); SwGlossaryList* pGlossaryList = ::GetGlossaryList(); const size_t nGroupCount = pGlossaryList->GetGroupCount(); for(size_t i = 1; i <= nGroupCount; ++i) @@ -98,7 +98,7 @@ VclPtr<SfxPopupWindow> SwTbxAutoTextCtrl::CreatePopupWindow() sal_uInt16 nIndex = static_cast<sal_uInt16>(100*i); // but insert without extension pPopup->InsertItem( i, sTitle); - PopupMenu* pSub = new PopupMenu; + PopupMenu* pSub = VclPtr<PopupMenu>::Create(); pSub->SetSelectHdl(aLnk); pPopup->SetPopupMenu(i, pSub); for(sal_uInt16 j = 0; j < nBlockCount; j++) @@ -164,11 +164,10 @@ void SwTbxAutoTextCtrl::DelPopup() { for( sal_uInt16 i = 0; i < pPopup->GetItemCount(); i ++ ) { - PopupMenu* pSubPopup = pPopup->GetPopupMenu(pPopup->GetItemId(i)); - delete pSubPopup; + VclPtr<PopupMenu> pSubPopup = pPopup->GetPopupMenu(pPopup->GetItemId(i)); + pSubPopup.disposeAndClear(); // NoelG: dodgy, this leaves a dangling pointer } - delete pPopup; - pPopup = nullptr; + pPopup.disposeAndClear(); } } diff --git a/sw/source/uibase/uiview/viewling.cxx b/sw/source/uibase/uiview/viewling.cxx index 905ceca86120..094377cc3ff8 100644 --- a/sw/source/uibase/uiview/viewling.cxx +++ b/sw/source/uibase/uiview/viewling.cxx @@ -703,22 +703,22 @@ bool SwView::ExecSpellPopup(const Point& rPt) bRet = true; m_pWrtShell->SttSelect(); - std::unique_ptr< SwSpellPopup > pPopup; + ScopedVclPtr< SwSpellPopup > pPopup; if (bUseGrammarContext) { sal_Int32 nPos = aPoint.nContent.GetIndex(); (void) nPos; - pPopup.reset(new SwSpellPopup( m_pWrtShell, aGrammarCheckRes, nErrorInResult, aSuggestions, aParaText )); + pPopup = VclPtr<SwSpellPopup>::Create( m_pWrtShell, aGrammarCheckRes, nErrorInResult, aSuggestions, aParaText ).get(); } else - pPopup.reset(new SwSpellPopup( m_pWrtShell, xAlt, aParaText )); + pPopup = VclPtr<SwSpellPopup>::Create( m_pWrtShell, xAlt, aParaText ).get(); ui::ContextMenuExecuteEvent aEvent; const Point aPixPos = GetEditWin().LogicToPixel( rPt ); aEvent.SourceWindow = VCLUnoHelper::GetInterface( m_pEditWin ); aEvent.ExecutePosition.X = aPixPos.X(); aEvent.ExecutePosition.Y = aPixPos.Y(); - Menu* pMenu = nullptr; + VclPtr<Menu> pMenu; OUString sMenuName = bUseGrammarContext ? OUString("private:resource/GrammarContextMenu") : OUString("private:resource/SpellContextMenu"); @@ -729,8 +729,8 @@ bool SwView::ExecSpellPopup(const Point& rPt) //! 'custom made' menu... *sigh* (code copied from sfx2 and framework) if ( pMenu ) { - const sal_uInt16 nId = static_cast<PopupMenu*>(pMenu)->Execute(m_pEditWin, aPixPos); - OUString aCommand = static_cast<PopupMenu*>(pMenu)->GetItemCommand(nId); + const sal_uInt16 nId = static_cast<PopupMenu*>(pMenu.get())->Execute(m_pEditWin, aPixPos); + OUString aCommand = static_cast<PopupMenu*>(pMenu.get())->GetItemCommand(nId); if (aCommand.isEmpty() ) { if(!ExecuteMenuCommand(dynamic_cast<PopupMenu&>(*pMenu), *GetViewFrame(), nId )) diff --git a/sw/source/uibase/utlui/bookctrl.cxx b/sw/source/uibase/utlui/bookctrl.cxx index 408181cc86a9..41f064150232 100644 --- a/sw/source/uibase/utlui/bookctrl.cxx +++ b/sw/source/uibase/utlui/bookctrl.cxx @@ -101,7 +101,7 @@ void SwBookmarkControl::Command( const CommandEvent& rCEvt ) if ( rCEvt.GetCommand() == CommandEventId::ContextMenu && !GetStatusBar().GetItemText( GetId() ).isEmpty() ) { - BookmarkPopup_Impl aPop; + ScopedVclPtrInstance<BookmarkPopup_Impl> aPop; SwWrtShell* pWrtShell = ::GetActiveWrtShell(); if( pWrtShell && pWrtShell->getIDocumentMarkAccess()->getAllMarksCount() > 0 ) { @@ -115,13 +115,13 @@ void SwBookmarkControl::Command( const CommandEvent& rCEvt ) { if(IDocumentMarkAccess::MarkType::BOOKMARK == IDocumentMarkAccess::GetType(**ppBookmark)) { - aPop.InsertItem( nPopupId, ppBookmark->get()->GetName() ); + aPop->InsertItem( nPopupId, ppBookmark->get()->GetName() ); aBookmarkIdx[nPopupId] = static_cast<sal_uInt16>(ppBookmark - ppBookmarkStart); nPopupId++; } } - aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel()); - sal_uInt16 nCurrId = aPop.GetCurId(); + aPop->Execute( &GetStatusBar(), rCEvt.GetMousePosPixel()); + sal_uInt16 nCurrId = aPop->GetCurId(); if( nCurrId != USHRT_MAX) { SfxUInt16Item aBookmark( FN_STAT_BOOKMARK, aBookmarkIdx[nCurrId] ); diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx index 85a65f4fcece..fa3c723f198b 100644 --- a/sw/source/uibase/utlui/content.cxx +++ b/sw/source/uibase/utlui/content.cxx @@ -1096,13 +1096,13 @@ sal_Int8 SwContentTree::ExecuteDrop( const ExecuteDropEvent& rEvt ) // Handler for Dragging and ContextMenu -std::unique_ptr<PopupMenu> SwContentTree::CreateContextMenu() +VclPtr<PopupMenu> SwContentTree::CreateContextMenu() { - std::unique_ptr<PopupMenu> pPop(new PopupMenu); - PopupMenu* pSubPop1 = new PopupMenu; - PopupMenu* pSubPop2 = new PopupMenu; - PopupMenu* pSubPop3 = new PopupMenu; - PopupMenu* pSubPop4 = new PopupMenu; // Edit + VclPtrInstance<PopupMenu> pPop; + VclPtrInstance<PopupMenu> pSubPop1; + VclPtrInstance<PopupMenu> pSubPop2; + VclPtrInstance<PopupMenu> pSubPop3; + VclPtrInstance<PopupMenu> pSubPop4; // Edit for(int i = 1; i <= MAXLEVEL; ++i) { diff --git a/sw/source/uibase/utlui/glbltree.cxx b/sw/source/uibase/utlui/glbltree.cxx index 9aaee86d7bbf..e8e47994680d 100644 --- a/sw/source/uibase/utlui/glbltree.cxx +++ b/sw/source/uibase/utlui/glbltree.cxx @@ -330,16 +330,16 @@ sal_Int8 SwGlobalTree::AcceptDrop( const AcceptDropEvent& rEvt ) return nRet; } -std::unique_ptr<PopupMenu> SwGlobalTree::CreateContextMenu() +VclPtr<PopupMenu> SwGlobalTree::CreateContextMenu() { - std::unique_ptr<PopupMenu> pPop; + VclPtr<PopupMenu> pPop; if(pActiveShell && !pActiveShell->GetView().GetDocShell()->IsReadOnly()) { const sal_uInt16 nEnableFlags = GetEnableFlags(); - pPop.reset(new PopupMenu); - PopupMenu* pSubPop1 = new PopupMenu; - PopupMenu* pSubPop2 = new PopupMenu; + pPop = VclPtr<PopupMenu>::Create(); + VclPtrInstance<PopupMenu> pSubPop1; + VclPtrInstance<PopupMenu> pSubPop2; for (sal_uInt16 i = CTX_UPDATE_SEL; i <= CTX_UPDATE_ALL; i++) { @@ -394,7 +394,7 @@ void SwGlobalTree::TbxMenuHdl(sal_uInt16 nTbxId, ToolBox* pBox) const sal_uInt16 nEnableFlags = GetEnableFlags(); if(FN_GLOBAL_OPEN == nTbxId) { - std::unique_ptr<PopupMenu> pMenu(new PopupMenu); + ScopedVclPtrInstance<PopupMenu> pMenu; for (sal_uInt16 i = CTX_INSERT_ANY_INDEX; i <= CTX_INSERT_TEXT; i++) { pMenu->InsertItem( i, aContextStrings[STR_INDEX - STR_GLOBAL_CONTEXT_FIRST - CTX_INSERT_ANY_INDEX + i] ); @@ -406,13 +406,13 @@ void SwGlobalTree::TbxMenuHdl(sal_uInt16 nTbxId, ToolBox* pBox) pMenu->EnableItem(CTX_INSERT_NEW_FILE, 0 != (nEnableFlags & ENABLE_INSERT_FILE)); pMenu->SetSelectHdl(LINK(this, SwGlobalTree, PopupHdl)); pMenu->Execute(pBox, pBox->GetItemRect(nTbxId)); - pMenu.reset(); + pMenu.disposeAndClear(); pBox->EndSelection(); pBox->Invalidate(); } else if(FN_GLOBAL_UPDATE == nTbxId) { - std::unique_ptr<PopupMenu> pMenu(new PopupMenu); + ScopedVclPtrInstance<PopupMenu> pMenu; for (sal_uInt16 i = CTX_UPDATE_SEL; i <= CTX_UPDATE_ALL; i++) { pMenu->InsertItem( i, aContextStrings[STR_UPDATE_SEL - STR_GLOBAL_CONTEXT_FIRST - CTX_UPDATE_SEL+ i] ); @@ -421,7 +421,7 @@ void SwGlobalTree::TbxMenuHdl(sal_uInt16 nTbxId, ToolBox* pBox) pMenu->EnableItem(CTX_UPDATE_SEL, 0 != (nEnableFlags & ENABLE_UPDATE_SEL)); pMenu->SetSelectHdl(LINK(this, SwGlobalTree, PopupHdl)); pMenu->Execute(pBox, pBox->GetItemRect(nTbxId)); - pMenu.reset(); + pMenu.disposeAndClear(); pBox->EndSelection(); pBox->Invalidate(); } diff --git a/sw/source/uibase/utlui/navipi.cxx b/sw/source/uibase/utlui/navipi.cxx index f87e656b6801..2d66ac1d083a 100644 --- a/sw/source/uibase/utlui/navipi.cxx +++ b/sw/source/uibase/utlui/navipi.cxx @@ -380,7 +380,7 @@ IMPL_LINK_TYPED( SwNavigationPI, ToolBoxDropdownClickHdl, ToolBox*, pBox, void ) HID_NAVI_DRAG_LINK, HID_NAVI_DRAG_COPY, }; - std::unique_ptr<PopupMenu> pMenu(new PopupMenu); + ScopedVclPtrInstance<PopupMenu> pMenu; for (sal_uInt16 i = 0; i <= static_cast<sal_uInt16>(RegionMode::EMBEDDED); i++) { pMenu->InsertItem( i + 1, m_aContextArr[i] ); @@ -394,13 +394,13 @@ IMPL_LINK_TYPED( SwNavigationPI, ToolBoxDropdownClickHdl, ToolBox*, pBox, void ) PopupMenuFlags::ExecuteDown ); pBox->SetItemDown( nCurrItemId, false ); pBox->EndSelection(); - pMenu.reset(); + pMenu.disposeAndClear(); pBox->Invalidate(); } break; case FN_OUTLINE_LEVEL: { - std::unique_ptr<PopupMenu> pMenu(new PopupMenu); + ScopedVclPtrInstance<PopupMenu> pMenu; for (sal_uInt16 i = 101; i <= 100 + MAXLEVEL; i++) { pMenu->InsertItem( i, OUString::number(i - 100) ); @@ -413,7 +413,7 @@ IMPL_LINK_TYPED( SwNavigationPI, ToolBoxDropdownClickHdl, ToolBox*, pBox, void ) pBox->GetItemRect(FN_OUTLINE_LEVEL), PopupMenuFlags::ExecuteDown ); pBox->SetItemDown( nCurrItemId, false ); - pMenu.reset(); + pMenu.disposeAndClear(); pBox->EndSelection(); pBox->Invalidate(); } diff --git a/sw/source/uibase/utlui/tmplctrl.cxx b/sw/source/uibase/utlui/tmplctrl.cxx index 6790276b5c57..f5f2e56968da 100644 --- a/sw/source/uibase/utlui/tmplctrl.cxx +++ b/sw/source/uibase/utlui/tmplctrl.cxx @@ -93,7 +93,7 @@ void SwTemplateControl::Command( const CommandEvent& rCEvt ) if ( rCEvt.GetCommand() == CommandEventId::ContextMenu && !GetStatusBar().GetItemText( GetId() ).isEmpty() ) { - SwTemplatePopup_Impl aPop; + ScopedVclPtrInstance<SwTemplatePopup_Impl> aPop; { SwView* pView = ::GetActiveView(); SwWrtShell* pWrtShell; @@ -111,12 +111,12 @@ void SwTemplateControl::Command( const CommandEvent& rCEvt ) SfxStyleSheetBase* pStyle = pPool->First(); while( pStyle ) { - aPop.InsertItem( ++nCount, pStyle->GetName() ); + aPop->InsertItem( ++nCount, pStyle->GetName() ); pStyle = pPool->Next(); } - aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel()); - const sal_uInt16 nCurrId = aPop.GetCurId(); + aPop->Execute( &GetStatusBar(), rCEvt.GetMousePosPixel()); + const sal_uInt16 nCurrId = aPop->GetCurId(); if( nCurrId != USHRT_MAX) { // looks a bit awkward, but another way is not possible diff --git a/sw/source/uibase/utlui/unotools.cxx b/sw/source/uibase/utlui/unotools.cxx index 5a43806c3c00..a4346b6785ed 100644 --- a/sw/source/uibase/utlui/unotools.cxx +++ b/sw/source/uibase/utlui/unotools.cxx @@ -448,18 +448,18 @@ static const sal_Int16 nZoomValues[] = void SwOneExampleFrame::CreatePopup(const Point& rPt) { - PopupMenu aPop; - PopupMenu aSubPop1; + ScopedVclPtrInstance<PopupMenu> aPop; + ScopedVclPtrInstance<PopupMenu> aSubPop1; ResStringArray& rArr = aMenuRes.GetMenuArray(); - aPop.InsertItem(ITEM_UP, rArr.GetString(rArr.FindIndex(ST_MENU_UP ))); - aPop.InsertItem(ITEM_DOWN, rArr.GetString(rArr.FindIndex(ST_MENU_DOWN ))); + aPop->InsertItem(ITEM_UP, rArr.GetString(rArr.FindIndex(ST_MENU_UP ))); + aPop->InsertItem(ITEM_DOWN, rArr.GetString(rArr.FindIndex(ST_MENU_DOWN ))); Link<Menu*,bool> aSelLk = LINK(this, SwOneExampleFrame, PopupHdl ); - aPop.SetSelectHdl(aSelLk); + aPop->SetSelectHdl(aSelLk); if(EX_SHOW_ONLINE_LAYOUT == nStyleFlags) { - aPop.InsertItem(ITEM_ZOOM, rArr.GetString(rArr.FindIndex(ST_MENU_ZOOM ))); + aPop->InsertItem(ITEM_ZOOM, rArr.GetString(rArr.FindIndex(ST_MENU_ZOOM ))); uno::Reference< view::XViewSettingsSupplier > xSettings(_xController, uno::UNO_QUERY); uno::Reference< beans::XPropertySet > xViewProps = xSettings->getViewSettings(); @@ -472,15 +472,14 @@ void SwOneExampleFrame::CreatePopup(const Point& rPt) { OUString sTemp = unicode::formatPercent(nZoomValues[i], Application::GetSettings().GetUILanguageTag()); - aSubPop1.InsertItem( ITEM_ZOOM + i + 1, sTemp); + aSubPop1->InsertItem( ITEM_ZOOM + i + 1, sTemp); if(nZoom == nZoomValues[i]) - aSubPop1.CheckItem(ITEM_ZOOM + i + 1); + aSubPop1->CheckItem(ITEM_ZOOM + i + 1); } - aPop.SetPopupMenu( ITEM_ZOOM, &aSubPop1 ); - aSubPop1.SetSelectHdl(aSelLk); + aPop->SetPopupMenu( ITEM_ZOOM, aSubPop1.get() ); + aSubPop1->SetSelectHdl(aSelLk); } - aPop.Execute( aTopWindow.get(), rPt ); - + aPop->Execute( aTopWindow.get(), rPt ); } IMPL_LINK_TYPED(SwOneExampleFrame, PopupHdl, Menu*, pMenu, bool ) |