diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-05-06 11:22:05 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-05-06 18:38:22 +0200 |
commit | a7ff945ca031324f060b0d989f7a89594fcfe9fe (patch) | |
tree | ee502330c3e52c59aa2a4c5d97b6307c5a6babe5 | |
parent | 6668b112b341edd24ca77ba88b834108d67b0602 (diff) |
add SfxItemPoolDeleter utility
add use so we can hold the pool with std::unique_ptr
Change-Id: I685fbc37c0ae145a5b48a66a88eab9fb29a0fc0b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115174
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
27 files changed, 84 insertions, 100 deletions
diff --git a/dbaccess/source/ui/misc/UITools.cxx b/dbaccess/source/ui/misc/UITools.cxx index b134c9fdcf3e..f22c9198ca69 100644 --- a/dbaccess/source/ui/misc/UITools.cxx +++ b/dbaccess/source/ui/misc/UITools.cxx @@ -788,7 +788,7 @@ bool callColumnFormatDialog(weld::Widget* _pParent, new SvxNumberInfoItem(SID_ATTR_NUMBERFORMAT_INFO) }; - SfxItemPool* pPool = new SfxItemPool("GridBrowserProperties", SBA_DEF_RANGEFORMAT, SBA_ATTR_ALIGN_HOR_JUSTIFY, aItemInfos, &pDefaults); + std::unique_ptr<SfxItemPool, SfxItemPoolDeleter> pPool(new SfxItemPool("GridBrowserProperties", SBA_DEF_RANGEFORMAT, SBA_ATTR_ALIGN_HOR_JUSTIFY, aItemInfos, &pDefaults)); pPool->SetDefaultMetric( MapUnit::MapTwip ); // ripped, don't understand why pPool->FreezeIdRanges(); // the same @@ -855,7 +855,7 @@ bool callColumnFormatDialog(weld::Widget* _pParent, } pFormatDescriptor.reset(); - SfxItemPool::Free(pPool); + pPool.reset(); for (SfxPoolItem* pDefault : pDefaults) delete pDefault; diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx index 1b9e6b9e5cdd..55481862430e 100644 --- a/editeng/source/editeng/editeng.cxx +++ b/editeng/source/editeng/editeng.cxx @@ -83,16 +83,7 @@ static bool bDebugPaint = false; #endif -namespace { -struct PoolDeleter -{ - void operator()(SfxItemPool* pPool) - { - SfxItemPool::Free(pPool); - }; -}; -} -static std::unique_ptr<SfxItemPool, PoolDeleter> pGlobalPool; +static std::unique_ptr<SfxItemPool, SfxItemPoolDeleter> pGlobalPool; EditEngine::EditEngine( SfxItemPool* pItemPool ) { diff --git a/include/svl/itempool.hxx b/include/svl/itempool.hxx index 10dbd3252c9e..12e525722d6a 100644 --- a/include/svl/itempool.hxx +++ b/include/svl/itempool.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_SVL_ITEMPOOL_HXX -#define INCLUDED_SVL_ITEMPOOL_HXX +#pragma once #include <svl/poolitem.hxx> #include <svl/svldllapi.h> @@ -233,6 +232,14 @@ inline sal_uInt32 SfxItemPool::ReleaseRef(const SfxPoolItem& rItem, sal_uInt32 n return rItem.ReleaseRef(n); } -#endif +// Utility class for using SfxItemPool with std::unique_ptr +struct SfxItemPoolDeleter +{ + void operator()(SfxItemPool* pPool) + { + SfxItemPool::Free(pPool); + } +}; + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/svx/unopool.hxx b/include/svx/unopool.hxx index ff6c83472b98..d7736c36f7c2 100644 --- a/include/svx/unopool.hxx +++ b/include/svx/unopool.hxx @@ -25,6 +25,7 @@ #include <comphelper/propertysethelper.hxx> #include <cppuhelper/weakagg.hxx> #include <svx/svxdllapi.h> +#include <svl/itempool.hxx> class SdrModel; class SfxItemPool; @@ -89,7 +90,7 @@ protected: protected: SdrModel* mpModel; - SfxItemPool* mpDefaultsPool; + std::unique_ptr<SfxItemPool, SfxItemPoolDeleter> mpDefaultsPool; }; #endif diff --git a/reportdesign/source/ui/misc/UITools.cxx b/reportdesign/source/ui/misc/UITools.cxx index 1981b229e567..afa270e60664 100644 --- a/reportdesign/source/ui/misc/UITools.cxx +++ b/reportdesign/source/ui/misc/UITools.cxx @@ -727,7 +727,7 @@ bool openCharDialog( const uno::Reference<report::XReportControlFormat >& _rxRep 0 }; - SfxItemPool* pPool( new SfxItemPool("ReportCharProperties", XATTR_FILL_FIRST,ITEMID_WEIGHT_COMPLEX, aItemInfos, &pDefaults) ); + std::unique_ptr<SfxItemPool, SfxItemPoolDeleter> pPool(new SfxItemPool("ReportCharProperties", XATTR_FILL_FIRST,ITEMID_WEIGHT_COMPLEX, aItemInfos, &pDefaults)); // not needed for font height pPool->SetDefaultMetric( MapUnit::Map100thMM ); // ripped, don't understand why pPool->FreezeIdRanges(); // the same bool bSuccess = false; @@ -755,7 +755,7 @@ bool openCharDialog( const uno::Reference<report::XReportControlFormat >& _rxRep DBG_UNHANDLED_EXCEPTION("reportdesign"); } - SfxItemPool::Free(pPool); + pPool.reset(); for (SfxPoolItem* pDefault : pDefaults) delete pDefault; diff --git a/reportdesign/source/ui/report/ReportController.cxx b/reportdesign/source/ui/report/ReportController.cxx index 475bef77a29f..6b7f10c377af 100644 --- a/reportdesign/source/ui/report/ReportController.cxx +++ b/reportdesign/source/ui/report/ReportController.cxx @@ -2369,7 +2369,7 @@ void OReportController::openPageDialog(const uno::Reference<report::XSection>& _ SID_ATTR_METRIC,SID_ATTR_METRIC, 0 }; - SfxItemPool* pPool( new SfxItemPool("ReportPageProperties", RPTUI_ID_LRSPACE, RPTUI_ID_METRIC, aItemInfos ) ); + std::unique_ptr<SfxItemPool, SfxItemPoolDeleter> pPool( new SfxItemPool("ReportPageProperties", RPTUI_ID_LRSPACE, RPTUI_ID_METRIC, aItemInfos ) ); const Graphic aNullGraphic; const ::Color aNullLineCol(COL_DEFAULT_SHAPE_STROKE); // #i121448# Use defined default color @@ -2513,7 +2513,7 @@ void OReportController::openPageDialog(const uno::Reference<report::XSection>& _ { DBG_UNHANDLED_EXCEPTION("reportdesign"); } - SfxItemPool::Free(pPool); + pPool.reset(); for (SfxPoolItem* pDefault : pDefaults) delete pDefault; @@ -4218,7 +4218,7 @@ void OReportController::openZoomDialog() SID_ATTR_ZOOM,SID_ATTR_ZOOM, 0 }; - SfxItemPool* pPool( new SfxItemPool("ZoomProperties", SID_ATTR_ZOOM,SID_ATTR_ZOOM, aItemInfos, &pDefaults) ); + std::unique_ptr<SfxItemPool, SfxItemPoolDeleter> pPool( new SfxItemPool("ZoomProperties", SID_ATTR_ZOOM,SID_ATTR_ZOOM, aItemInfos, &pDefaults) ); pPool->SetDefaultMetric( MapUnit::Map100thMM ); // ripped, don't understand why pPool->FreezeIdRanges(); // the same try @@ -4248,7 +4248,7 @@ void OReportController::openZoomDialog() { DBG_UNHANDLED_EXCEPTION("reportdesign"); } - SfxItemPool::Free(pPool); + pPool.reset(); for (SfxPoolItem* pDefault : pDefaults) delete pDefault; diff --git a/sc/inc/scmod.hxx b/sc/inc/scmod.hxx index c023290d4b76..6847142a09a9 100644 --- a/sc/inc/scmod.hxx +++ b/sc/inc/scmod.hxx @@ -23,6 +23,7 @@ #include <o3tl/deleter.hxx> #include <vcl/timer.hxx> #include <svl/lstner.hxx> +#include <svl/itempool.hxx> #include <sfx2/app.hxx> #include <sfx2/module.hxx> #include "global.hxx" @@ -81,7 +82,7 @@ class SAL_DLLPUBLIC_RTTI ScModule final : public SfxModule, public SfxListener, Timer m_aIdleTimer; std::unique_ptr<ScDragData> m_pDragData; ScSelectionTransferObj* m_pSelTransfer; - ScMessagePool* m_pMessagePool; + std::unique_ptr<ScMessagePool, SfxItemPoolDeleter> m_pMessagePool; // there is no global InputHandler anymore, each View has its own ScInputHandler* m_pRefInputHandler; std::unique_ptr<ScViewCfg, o3tl::default_delete<ScViewCfg>> m_pViewCfg; diff --git a/sc/source/core/data/poolhelp.cxx b/sc/source/core/data/poolhelp.cxx index 37b64c622d19..2091bf167d9c 100644 --- a/sc/source/core/data/poolhelp.cxx +++ b/sc/source/core/data/poolhelp.cxx @@ -27,11 +27,9 @@ #include <stlpool.hxx> ScPoolHelper::ScPoolHelper( ScDocument& rSourceDoc ) - : pEditPool(nullptr) - , pEnginePool(nullptr) + : pDocPool(new ScDocumentPool) , m_rSourceDoc(rSourceDoc) { - pDocPool = new ScDocumentPool; pDocPool->FreezeIdRanges(); mxStylePool = new ScStyleSheetPool( *pDocPool, &rSourceDoc ); @@ -39,31 +37,31 @@ ScPoolHelper::ScPoolHelper( ScDocument& rSourceDoc ) ScPoolHelper::~ScPoolHelper() { - SfxItemPool::Free(pEnginePool); - SfxItemPool::Free(pEditPool); + pEnginePool.reset(); + pEditPool.reset(); pFormTable.reset(); mxStylePool.clear(); - SfxItemPool::Free(pDocPool); + pDocPool.reset(); } SfxItemPool* ScPoolHelper::GetEditPool() const { if ( !pEditPool ) { - pEditPool = EditEngine::CreatePool(); + pEditPool.reset(EditEngine::CreatePool()); pEditPool->SetDefaultMetric( MapUnit::Map100thMM ); pEditPool->FreezeIdRanges(); } - return pEditPool; + return pEditPool.get(); } SfxItemPool* ScPoolHelper::GetEnginePool() const { if ( !pEnginePool ) { - pEnginePool = EditEngine::CreatePool(); + pEnginePool.reset(EditEngine::CreatePool()); pEnginePool->SetDefaultMetric( MapUnit::Map100thMM ); pEnginePool->FreezeIdRanges(); } // ifg ( pEnginePool ) - return pEnginePool; + return pEnginePool.get(); } SvNumberFormatter* ScPoolHelper::GetFormTable() const { diff --git a/sc/source/core/inc/poolhelp.hxx b/sc/source/core/inc/poolhelp.hxx index a1e3f92b7f8c..267d60ea8eeb 100644 --- a/sc/source/core/inc/poolhelp.hxx +++ b/sc/source/core/inc/poolhelp.hxx @@ -23,6 +23,7 @@ #include <salhelper/simplereferenceobject.hxx> #include <docoptio.hxx> #include <osl/mutex.hxx> +#include <svl/itempool.hxx> class ScDocument; class ScDocumentPool; @@ -35,11 +36,11 @@ class ScPoolHelper final : public salhelper::SimpleReferenceObject private: mutable osl::Mutex maMtxCreateNumFormatter; ScDocOptions aOpt; - ScDocumentPool* pDocPool; + std::unique_ptr<ScDocumentPool, SfxItemPoolDeleter> pDocPool; rtl::Reference< ScStyleSheetPool > mxStylePool; mutable std::unique_ptr<SvNumberFormatter> pFormTable; - mutable SfxItemPool* pEditPool; // EditTextObjectPool - mutable SfxItemPool* pEnginePool; // EditEnginePool + mutable std::unique_ptr<SfxItemPool, SfxItemPoolDeleter> pEditPool; // EditTextObjectPool + mutable std::unique_ptr<SfxItemPool, SfxItemPoolDeleter> pEnginePool; // EditEnginePool ScDocument& m_rSourceDoc; public: @@ -50,7 +51,7 @@ public: void SourceDocumentGone(); // access to pointers (are never 0): - ScDocumentPool* GetDocPool() const { return pDocPool; } + ScDocumentPool* GetDocPool() const { return pDocPool.get(); } ScStyleSheetPool* GetStylePool() const { return mxStylePool.get(); } SvNumberFormatter* GetFormTable() const; SfxItemPool* GetEditPool() const; diff --git a/sc/source/filter/inc/eeparser.hxx b/sc/source/filter/inc/eeparser.hxx index 6b988b0728ee..c691ca3abb9d 100644 --- a/sc/source/filter/inc/eeparser.hxx +++ b/sc/source/filter/inc/eeparser.hxx @@ -23,6 +23,7 @@ #include <vcl/errcode.hxx> #include <vcl/graph.hxx> #include <svl/itemset.hxx> +#include <svl/itempool.hxx> #include <editeng/editdata.hxx> #include <optional> #include <address.hxx> @@ -99,8 +100,8 @@ class ScEEParser { protected: EditEngine* pEdit; - SfxItemPool* pPool; - SfxItemPool* pDocPool; + std::unique_ptr<SfxItemPool, SfxItemPoolDeleter> pPool; + std::unique_ptr<SfxItemPool, SfxItemPoolDeleter> pDocPool; std::vector<std::shared_ptr<ScEEParseEntry>> maList; std::shared_ptr<ScEEParseEntry> mxActEntry; ColWidthsMap maColWidths; diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx index 14cdf76d7349..6511a806e295 100644 --- a/sc/source/filter/rtf/eeimpars.cxx +++ b/sc/source/filter/rtf/eeimpars.cxx @@ -625,7 +625,7 @@ ScEEParser::ScEEParser( EditEngine* pEditP ) : nRowMax(0) { // pPool is foisted on SvxRTFParser at RtfImportState::Start later on - pPool->SetSecondaryPool( pDocPool ); + pPool->SetSecondaryPool( pDocPool.get() ); pPool->FreezeIdRanges(); NewActEntry( nullptr ); } @@ -637,13 +637,13 @@ ScEEParser::~ScEEParser() // Don't delete Pool until the lists have been deleted pPool->SetSecondaryPool( nullptr ); - SfxItemPool::Free(pDocPool); - SfxItemPool::Free(pPool); + pDocPool.reset(); + pPool.reset(); } void ScEEParser::NewActEntry( const ScEEParseEntry* pE ) { // New free-flying mxActEntry - mxActEntry = std::make_shared<ScEEParseEntry>(pPool); + mxActEntry = std::make_shared<ScEEParseEntry>(pPool.get()); mxActEntry->aSel.nStartPara = (pE ? pE->aSel.nEndPara + 1 : 0); mxActEntry->aSel.nStartPos = 0; } diff --git a/sc/source/filter/rtf/rtfparse.cxx b/sc/source/filter/rtf/rtfparse.cxx index 1666992ef3cc..a758d394fabc 100644 --- a/sc/source/filter/rtf/rtfparse.cxx +++ b/sc/source/filter/rtf/rtfparse.cxx @@ -45,7 +45,7 @@ ScRTFParser::ScRTFParser( EditEngine* pEditP ) : tools::Long nMM = OutputDevice::LogicToLogic( 12, MapUnit::MapPoint, MapUnit::Map100thMM ); pPool->SetPoolDefaultItem( SvxFontHeightItem( nMM, 100, EE_CHAR_FONTHEIGHT ) ); // Free-flying pInsDefault - pInsDefault.reset( new ScRTFCellDefault( pPool ) ); + pInsDefault.reset( new ScRTFCellDefault( pPool.get() ) ); } ScRTFParser::~ScRTFParser() @@ -163,7 +163,7 @@ IMPL_LINK( ScRTFParser, RTFImportHdl, RtfImportInfo&, rInfo, void ) case RtfImportState::Start: { SvxRTFParser* pParser = static_cast<SvxRTFParser*>(rInfo.pParser); - pParser->SetAttrPool( pPool ); + pParser->SetAttrPool( pPool.get() ); RTFPardAttrMapIds& rMap = pParser->GetPardMap(); rMap.nBrush = ATTR_BACKGROUND; rMap.nBox = ATTR_BORDER; @@ -304,7 +304,7 @@ void ScRTFParser::ProcToken( RtfImportInfo* pInfo ) pInsDefault->nTwips = pInfo->nTokenValue; // Right cell border maDefaultList.push_back( std::move(pInsDefault) ); // New free-flying pInsDefault - pInsDefault.reset( new ScRTFCellDefault( pPool ) ); + pInsDefault.reset( new ScRTFCellDefault( pPool.get() ) ); if ( ++nColCnt > nColMax ) nColMax = nColCnt; nRtfLastToken = pInfo->nToken; diff --git a/sc/source/filter/xml/xmlfonte.cxx b/sc/source/filter/xml/xmlfonte.cxx index 1120ed9cfd09..9b2ee6286b01 100644 --- a/sc/source/filter/xml/xmlfonte.cxx +++ b/sc/source/filter/xml/xmlfonte.cxx @@ -36,13 +36,12 @@ class ScXMLFontAutoStylePool_Impl: public XMLFontAutoStylePool { private: // #i120077# remember owned pool - SfxItemPool* mpEditEnginePool; + std::unique_ptr<SfxItemPool, SfxItemPoolDeleter> mpEditEnginePool; void AddFontItems(const sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const bool bExportDefaults); public: ScXMLFontAutoStylePool_Impl( ScXMLExport& rExport, bool bEmbedFonts); - virtual ~ScXMLFontAutoStylePool_Impl() override; }; } @@ -72,7 +71,6 @@ void ScXMLFontAutoStylePool_Impl::AddFontItems(const sal_uInt16* pWhichIds, sal_ ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(ScXMLExport& rExportP, bool bEmbedFonts) : XMLFontAutoStylePool(rExportP, bEmbedFonts) - , mpEditEnginePool(nullptr) { sal_uInt16 const aWhichIds[] { ATTR_FONT, ATTR_CJK_FONT, ATTR_CTL_FONT }; @@ -103,8 +101,8 @@ ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(ScXMLExport& rExportP, // #i120077# remember the SfxItemPool in member variable before usage. The // local EditEngine will not take over ownership of the pool. - mpEditEnginePool = EditEngine::CreatePool(); - EditEngine aEditEngine(mpEditEnginePool); + mpEditEnginePool.reset(EditEngine::CreatePool()); + EditEngine aEditEngine(mpEditEnginePool.get()); while (pStyle) { @@ -119,19 +117,19 @@ ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(ScXMLExport& rExportP, if (pLeftArea) { aEditEngine.SetText(*pLeftArea); - AddFontItems(aEditWhichIds, 3, mpEditEnginePool, false); + AddFontItems(aEditWhichIds, 3, mpEditEnginePool.get(), false); } const EditTextObject* pCenterArea(pPageItem->GetCenterArea()); if (pCenterArea) { aEditEngine.SetText(*pCenterArea); - AddFontItems(aEditWhichIds, 3, mpEditEnginePool, false); + AddFontItems(aEditWhichIds, 3, mpEditEnginePool.get(), false); } const EditTextObject* pRightArea(pPageItem->GetRightArea()); if (pRightArea) { aEditEngine.SetText(*pRightArea); - AddFontItems(aEditWhichIds, 3, mpEditEnginePool, false); + AddFontItems(aEditWhichIds, 3, mpEditEnginePool.get(), false); } } } @@ -140,15 +138,6 @@ ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(ScXMLExport& rExportP, } } -ScXMLFontAutoStylePool_Impl::~ScXMLFontAutoStylePool_Impl() -{ - if(mpEditEnginePool) - { - // memory leak #i120077# - SfxItemPool::Free(mpEditEnginePool); - } -} - XMLFontAutoStylePool* ScXMLExport::CreateFontAutoStylePool() { bool blockFontEmbedding = false; diff --git a/sc/source/ui/app/msgpool.cxx b/sc/source/ui/app/msgpool.cxx index d8ae220bf6dc..58daba682830 100644 --- a/sc/source/ui/app/msgpool.cxx +++ b/sc/source/ui/app/msgpool.cxx @@ -69,7 +69,7 @@ ScMessagePool::ScMessagePool() SetDefaults( &mvPoolDefaults ); - SetSecondaryPool( pDocPool ); + SetSecondaryPool( pDocPool.get() ); } ScMessagePool::~ScMessagePool() @@ -79,8 +79,6 @@ ScMessagePool::~ScMessagePool() for ( sal_uInt16 i=0; i <= MSGPOOL_END-MSGPOOL_START; i++ ) ClearRefCount( *mvPoolDefaults[i] ); - - SfxItemPool::Free(pDocPool); } MapUnit ScMessagePool::GetMetric( sal_uInt16 nWhich ) const diff --git a/sc/source/ui/app/scmod.cxx b/sc/source/ui/app/scmod.cxx index 84b620fa2c19..59ac6be2b17d 100644 --- a/sc/source/ui/app/scmod.cxx +++ b/sc/source/ui/app/scmod.cxx @@ -118,7 +118,6 @@ ScModule::ScModule( SfxObjectFactory* pFact ) : m_aIdleTimer("sc ScModule IdleTimer"), m_pDragData(new ScDragData), m_pSelTransfer( nullptr ), - m_pMessagePool( nullptr ), m_pRefInputHandler( nullptr ), m_nCurRefDlgId( 0 ), m_bIsWaterCan( false ), @@ -146,10 +145,10 @@ ScModule::ScModule( SfxObjectFactory* pFact ) : m_aIdleTimer.SetInvokeHandler( LINK( this, ScModule, IdleHandler ) ); m_aIdleTimer.Start(); - m_pMessagePool = new ScMessagePool; + m_pMessagePool.reset(new ScMessagePool); m_pMessagePool->FreezeIdRanges(); - SetPool( m_pMessagePool ); - ScGlobal::InitTextHeight( m_pMessagePool ); + SetPool( m_pMessagePool.get() ); + ScGlobal::InitTextHeight( m_pMessagePool.get() ); StartListening( *SfxGetpApp() ); // for SfxHintId::Deinitializing } @@ -160,7 +159,7 @@ ScModule::~ScModule() // InputHandler does not need to be deleted (there's none in the App anymore) - SfxItemPool::Free(m_pMessagePool); + m_pMessagePool.reset(); m_pDragData.reset(); m_pErrorHdl.reset(); diff --git a/sc/source/ui/inc/msgpool.hxx b/sc/source/ui/inc/msgpool.hxx index fc23503cf3f0..b9a430d6ae4f 100644 --- a/sc/source/ui/inc/msgpool.hxx +++ b/sc/source/ui/inc/msgpool.hxx @@ -43,7 +43,7 @@ class ScMessagePool final : public SfxItemPool ScCondFormatDlgItem aCondFormatDlgItem; std::vector<SfxPoolItem*> mvPoolDefaults; - ScDocumentPool* pDocPool; + std::unique_ptr<ScDocumentPool, SfxItemPoolDeleter> pDocPool; public: ScMessagePool(); diff --git a/sd/source/ui/presenter/PresenterTextView.cxx b/sd/source/ui/presenter/PresenterTextView.cxx index 4a3301bbefc4..c55547c150d2 100644 --- a/sd/source/ui/presenter/PresenterTextView.cxx +++ b/sd/source/ui/presenter/PresenterTextView.cxx @@ -79,7 +79,7 @@ private: cppcanvas::CanvasSharedPtr mpCanvas; VclPtr<VirtualDevice> mpOutputDevice; std::unique_ptr<EditEngine> mpEditEngine; - SfxItemPool* mpEditEngineItemPool; + std::unique_ptr<SfxItemPool, SfxItemPoolDeleter> mpEditEngineItemPool; Size maSize; OUString msText; sal_Int32 mnTop; @@ -258,7 +258,7 @@ PresenterTextView::Implementation::Implementation() rFntDta.nFontInfoId)); } - mpEditEngine.reset( new EditEngine (mpEditEngineItemPool) ); + mpEditEngine.reset( new EditEngine (mpEditEngineItemPool.get()) ); mpEditEngine->EnableUndo (true); mpEditEngine->SetDefTab (sal_uInt16( @@ -279,7 +279,7 @@ PresenterTextView::Implementation::Implementation() PresenterTextView::Implementation::~Implementation() { mpEditEngine.reset(); - SfxItemPool::Free(mpEditEngineItemPool); + mpEditEngineItemPool.reset(); mpOutputDevice.disposeAndClear(); } diff --git a/starmath/inc/document.hxx b/starmath/inc/document.hxx index c7885c027019..cf52f4497e5b 100644 --- a/starmath/inc/document.hxx +++ b/starmath/inc/document.hxx @@ -23,6 +23,7 @@ #include <sfx2/docfac.hxx> #include <sfx2/objsh.hxx> #include <svl/lstner.hxx> +#include <svl/itempool.hxx> #include <sax/fshelper.hxx> #include <unotools/lingucfg.hxx> #include <oox/core/filterbase.hxx> @@ -80,7 +81,7 @@ class SM_DLLPUBLIC SmDocShell : public SfxObjectShell, public SfxListener OUString maAccText; SvtLinguOptions maLinguOptions; std::unique_ptr<SmTableNode> mpTree; - SfxItemPool *mpEditEngineItemPool; + std::unique_ptr<SfxItemPool, SfxItemPoolDeleter> mpEditEngineItemPool; std::unique_ptr<EditEngine> mpEditEngine; VclPtr<SfxPrinter> mpPrinter; //q.v. comment to SmPrinter Access! VclPtr<Printer> mpTmpPrinter; //ditto diff --git a/starmath/source/document.cxx b/starmath/source/document.cxx index 10fee0c6f39c..5dd69cf62944 100644 --- a/starmath/source/document.cxx +++ b/starmath/source/document.cxx @@ -353,12 +353,12 @@ EditEngine& SmDocShell::GetEditEngine() //! see also SmEditWindow::DataChanged ! //! - mpEditEngineItemPool = EditEngine::CreatePool(); + mpEditEngineItemPool.reset( EditEngine::CreatePool() ); const StyleSettings& rStyleSettings = Application::GetDefaultDevice()->GetSettings().GetStyleSettings(); UpdateEditEngineDefaultFonts(rStyleSettings.GetFieldTextColor()); - mpEditEngine.reset( new EditEngine( mpEditEngineItemPool ) ); + mpEditEngine.reset( new EditEngine( mpEditEngineItemPool.get() ) ); mpEditEngine->SetAddExtLeading(true); @@ -630,7 +630,6 @@ void SmDocShell::Repaint() SmDocShell::SmDocShell( SfxModelFlags i_nSfxCreationFlags ) : SfxObjectShell(i_nSfxCreationFlags) - , mpEditEngineItemPool(nullptr) , mpPrinter(nullptr) , mpTmpPrinter(nullptr) , mnModifyCount(0) @@ -660,7 +659,7 @@ SmDocShell::~SmDocShell() mpCursor.reset(); mpEditEngine.reset(); - SfxItemPool::Free(mpEditEngineItemPool); + mpEditEngineItemPool.reset(); mpPrinter.disposeAndClear(); } diff --git a/svx/source/dialog/imapwnd.cxx b/svx/source/dialog/imapwnd.cxx index 6a2c5ef91048..4d979da20849 100644 --- a/svx/source/dialog/imapwnd.cxx +++ b/svx/source/dialog/imapwnd.cxx @@ -55,14 +55,13 @@ IMapWindow::IMapWindow(const Reference< XFrame >& rxDocumentFrame, weld::Dialog* : GraphCtrl(pDialog) , mxDocumentFrame(rxDocumentFrame) { - pIMapPool = new SfxItemPool( "IMapItemPool", - SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, maItemInfos ); + pIMapPool.reset(new SfxItemPool( "IMapItemPool", + SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, maItemInfos )); pIMapPool->FreezeIdRanges(); } IMapWindow::~IMapWindow() { - SfxItemPool::Free(pIMapPool); } void IMapWindow::SetDrawingArea(weld::DrawingArea* pDrawingArea) diff --git a/svx/source/dialog/imapwnd.hxx b/svx/source/dialog/imapwnd.hxx index 62a49188e2ad..27fe177a9aca 100644 --- a/svx/source/dialog/imapwnd.hxx +++ b/svx/source/dialog/imapwnd.hxx @@ -83,7 +83,7 @@ class IMapWindow final : public GraphCtrl ImageMap aIMap; TargetList aTargetList; Link<IMapWindow&,void> aInfoLink; - SfxItemPool* pIMapPool; + std::unique_ptr<SfxItemPool, SfxItemPoolDeleter> pIMapPool; SfxItemInfo maItemInfos[1] = {}; css::uno::Reference< css::frame::XFrame > mxDocumentFrame; diff --git a/svx/source/form/fmtextcontrolshell.cxx b/svx/source/form/fmtextcontrolshell.cxx index 0818e9c7be8a..5d4080928d1b 100644 --- a/svx/source/form/fmtextcontrolshell.cxx +++ b/svx/source/form/fmtextcontrolshell.cxx @@ -621,7 +621,7 @@ namespace svx if ( !pFontList ) return; - SfxItemPool* pPool = EditEngine::CreatePool(); + std::unique_ptr<SfxItemPool, SfxItemPoolDeleter> pPool(EditEngine::CreatePool()); pPool->FreezeIdRanges(); std::unique_ptr< SfxItemSet > xPureItems( new SfxItemSet( *pPool ) ); @@ -722,7 +722,7 @@ namespace svx xDialog.reset(); xCurrentItems.reset(); xPureItems.reset(); - SfxItemPool::Free(pPool); + pPool.reset(); } diff --git a/svx/source/unodraw/unopool.cxx b/svx/source/unodraw/unopool.cxx index 79ca1c1f951e..90addf6e0732 100644 --- a/svx/source/unodraw/unopool.cxx +++ b/svx/source/unodraw/unopool.cxx @@ -57,18 +57,18 @@ SvxUnoDrawPool::~SvxUnoDrawPool() noexcept if (mpDefaultsPool) { SfxItemPool* pOutlPool = mpDefaultsPool->GetSecondaryPool(); - SfxItemPool::Free(mpDefaultsPool); + mpDefaultsPool.reset(); SfxItemPool::Free(pOutlPool); } } void SvxUnoDrawPool::init() { - mpDefaultsPool = new SdrItemPool(); + mpDefaultsPool.reset(new SdrItemPool()); SfxItemPool* pOutlPool=EditEngine::CreatePool(); mpDefaultsPool->SetSecondaryPool(pOutlPool); - SdrModel::SetTextDefaults( mpDefaultsPool, SdrEngineDefaults::GetFontHeight() ); + SdrModel::SetTextDefaults( mpDefaultsPool.get(), SdrEngineDefaults::GetFontHeight() ); mpDefaultsPool->SetDefaultMetric(SdrEngineDefaults::GetMapUnit()); mpDefaultsPool->FreezeIdRanges(); } @@ -82,7 +82,7 @@ SfxItemPool* SvxUnoDrawPool::getModelPool( bool bReadOnly ) noexcept else { if( bReadOnly ) - return mpDefaultsPool; + return mpDefaultsPool.get(); else return nullptr; } @@ -222,7 +222,7 @@ void SvxUnoDrawPool::_getPropertyStates( const comphelper::PropertyMapEntry** pp SfxItemPool* pPool = getModelPool( true ); - if( pPool && pPool != mpDefaultsPool ) + if( pPool && pPool != mpDefaultsPool.get() ) { while( *ppEntries ) { @@ -286,7 +286,7 @@ void SvxUnoDrawPool::_setPropertyToDefault( const comphelper::PropertyMapEntry* // Assure, that ID is a Which-ID (it could be a Slot-ID.) // Thus, convert handle to Which-ID. const sal_uInt16 nWhich = pPool->GetWhich( static_cast<sal_uInt16>(pEntry->mnHandle) ); - if ( pPool && pPool != mpDefaultsPool ) + if ( pPool && pPool != mpDefaultsPool.get() ) { // use method <ResetPoolDefaultItem(..)> instead of using probably incompatible item pool <mpDefaultsPool>. pPool->ResetPoolDefaultItem( nWhich ); diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index 287450821fc4..ecfaa837a1cc 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -193,7 +193,7 @@ class SW_DLLPUBLIC SwDoc final // private Member std::unique_ptr<SwNodes> m_pNodes; //< document content (Nodes Array) - SwAttrPool* mpAttrPool; //< the attribute pool + std::unique_ptr<SwAttrPool, SfxItemPoolDeleter> mpAttrPool; //< the attribute pool SwPageDescs m_PageDescs; //< PageDescriptors Link<bool,void> maOle2Link; //< OLE 2.0-notification /* @@@MAINTAINABILITY-HORROR@@@ diff --git a/sw/inc/swmodule.hxx b/sw/inc/swmodule.hxx index c4a53dcc3771..6ba75632843a 100644 --- a/sw/inc/swmodule.hxx +++ b/sw/inc/swmodule.hxx @@ -26,6 +26,7 @@ #include <o3tl/deleter.hxx> #include <tools/fldunit.hxx> #include <svl/lstner.hxx> +#include <svl/itempool.hxx> #include <unotools/options.hxx> #include <sfx2/module.hxx> #include <sfx2/app.hxx> @@ -94,7 +95,7 @@ class SW_DLLPUBLIC SwModule final : public SfxModule, public SfxListener, public std::unique_ptr<SfxErrorHandler> m_pErrorHandler; - SwAttrPool *m_pAttrPool; + std::unique_ptr<SwAttrPool, SfxItemPoolDeleter> m_pAttrPool; // Current view is held here in order to avoid one's being forced // to work via GetActiveView. diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx index 35306e3c292e..35a59e111406 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -597,8 +597,7 @@ SwDoc::~SwDoc() mpDfltCharFormat.reset(); mpDfltFrameFormat.reset(); mpLayoutCache.reset(); - - SfxItemPool::Free(mpAttrPool); + mpAttrPool.reset(); } void SwDoc::SetDocShell( SwDocShell* pDSh ) diff --git a/sw/source/uibase/app/swmodule.cxx b/sw/source/uibase/app/swmodule.cxx index f8e5c016db90..6d15fcf2ff06 100644 --- a/sw/source/uibase/app/swmodule.cxx +++ b/sw/source/uibase/app/swmodule.cxx @@ -129,7 +129,6 @@ SwModule::SwModule( SfxObjectFactory* pWebFact, SfxObjectFactory* pFact, SfxObjectFactory* pGlobalFact ) : SfxModule("sw", {pWebFact, pFact, pGlobalFact}), - m_pAttrPool(nullptr), m_pView(nullptr), m_bAuthorInitialised(false), m_bEmbeddedLoadSave( false ), @@ -332,14 +331,14 @@ void SwDLL::RegisterControls() void SwModule::InitAttrPool() { OSL_ENSURE(!m_pAttrPool, "Pool already exists!"); - m_pAttrPool = new SwAttrPool(nullptr); - SetPool(m_pAttrPool); + m_pAttrPool.reset(new SwAttrPool(nullptr)); + SetPool(m_pAttrPool.get()); } void SwModule::RemoveAttrPool() { SetPool(nullptr); - SfxItemPool::Free(m_pAttrPool); + m_pAttrPool.reset(); } std::unique_ptr<SfxStyleFamilies> SwModule::CreateStyleFamilies() |