cui/source/tabpages/tabarea.cxx | 64 ++++++++++------------------------------ include/svl/itempool.hxx | 25 +++++---------- svl/source/items/itempool.cxx | 41 ------------------------- vcl/source/app/svapp.cxx | 4 -- 4 files changed, 26 insertions(+), 108 deletions(-)
New commits: commit 5dd814f13d795b471b2c9b01998ced75b2845a05 Author: Armin Le Grand (allotropia) <armin.le.grand.ext...@allotropia.de> AuthorDate: Sat Jan 20 19:24:07 2024 +0100 Commit: Armin Le Grand <armin.le.gr...@me.com> CommitDate: Sun Jan 21 20:34:08 2024 +0100 ITEM: Remove Direct(Put|Remove)Item(In|From)Pool After some experiments I now can remove DirectPutItemInPool and DirectRemoveItemFromPool. With the changes done before it is now possible to get rid of this 'compromize'. Now there are no more Items held at the 'Pool' which now can be developed in the direction of ssth like 'SfxItemSupport' - what it really is. Some of the last usages of DirectPutItemInPool were in SvxAreaTabDialog::SavePalettes(), so I tried to trigger those cases with using LO and calling that Dialog in all situations I could possibly think about, but it was never used. Then I added asserts and run a UnitTests in the apps, also no luck. Thus I would guess these are not used. These put changed stuff from the Dialog 'directly' to the Pool (what is not really supported and is a hint for a 'compromize' that some functionality did not find/want to use the right spot in the model to save and hold that data). Thus it *would* be accessible using the SurrogateMechanism at the Pool (which is also a 'compromize', see some of my other commits), but I also found no hints at places where that is done. Thus I decided to create this change and let's see if that asserts ever get triggered in the builds or tests. Indeed did not trigger. I checked what other places do which use SfxObjectShell::Current() when they get no DocShell: Most avoid doing something, but none puts stuff to the Pool, so I go one step further and do what other places do: warn and return. Also simplified SvxAreaTabDialog::SavePalettes() as then feasible. Change-Id: I1c351eac4ada26288a56a69d57008a09f2d19121 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162340 Tested-by: Jenkins Reviewed-by: Armin Le Grand <armin.le.gr...@me.com> diff --git a/cui/source/tabpages/tabarea.cxx b/cui/source/tabpages/tabarea.cxx index b4ef7edb6791..a568eb08223b 100644 --- a/cui/source/tabpages/tabarea.cxx +++ b/cui/source/tabpages/tabarea.cxx @@ -75,55 +75,46 @@ SvxAreaTabDialog::SvxAreaTabDialog void SvxAreaTabDialog::SavePalettes() { - SfxObjectShell* pShell = SfxObjectShell::Current(); + SfxObjectShell* pShell(SfxObjectShell::Current()); + if (!pShell) + { + SAL_WARN("cui.dialogs", "SvxAreaTabDialog: No SfxObjectShell!"); + return; + } + if( mpNewColorList != mpDrawModel->GetColorList() ) { mpDrawModel->SetPropertyList( static_cast<XPropertyList *>(mpNewColorList.get()) ); SvxColorListItem aColorListItem( mpNewColorList, SID_COLOR_TABLE ); - if ( pShell ) - pShell->PutItem( aColorListItem ); - else - mpDrawModel->GetItemPool().DirectPutItemInPool(aColorListItem); + pShell->PutItem( aColorListItem ); mpColorList = mpDrawModel->GetColorList(); } if( mpNewGradientList != mpDrawModel->GetGradientList() ) { mpDrawModel->SetPropertyList( static_cast<XPropertyList *>(mpNewGradientList.get()) ); SvxGradientListItem aItem( mpNewGradientList, SID_GRADIENT_LIST ); - if ( pShell ) - pShell->PutItem( aItem ); - else - mpDrawModel->GetItemPool().DirectPutItemInPool(aItem); + pShell->PutItem( aItem ); mpGradientList = mpDrawModel->GetGradientList(); } if( mpNewHatchingList != mpDrawModel->GetHatchList() ) { mpDrawModel->SetPropertyList( static_cast<XPropertyList *>(mpNewHatchingList.get()) ); SvxHatchListItem aItem( mpNewHatchingList, SID_HATCH_LIST ); - if ( pShell ) - pShell->PutItem( aItem ); - else - mpDrawModel->GetItemPool().DirectPutItemInPool(aItem); + pShell->PutItem( aItem ); mpHatchingList = mpDrawModel->GetHatchList(); } if( mpNewBitmapList != mpDrawModel->GetBitmapList() ) { mpDrawModel->SetPropertyList( static_cast<XPropertyList *>(mpNewBitmapList.get()) ); SvxBitmapListItem aItem( mpNewBitmapList, SID_BITMAP_LIST ); - if ( pShell ) - pShell->PutItem( aItem ); - else - mpDrawModel->GetItemPool().DirectPutItemInPool(aItem); + pShell->PutItem( aItem ); mpBitmapList = mpDrawModel->GetBitmapList(); } if( mpNewPatternList != mpDrawModel->GetPatternList() ) { mpDrawModel->SetPropertyList( static_cast<XPropertyList *>(mpNewPatternList.get()) ); SvxPatternListItem aItem( mpNewPatternList, SID_PATTERN_LIST ); - if( pShell ) - pShell->PutItem( aItem ); - else - mpDrawModel->GetItemPool().DirectPutItemInPool(aItem); + pShell->PutItem( aItem ); mpPatternList = mpDrawModel->GetPatternList(); } @@ -145,10 +136,7 @@ void SvxAreaTabDialog::SavePalettes() SvxHatchListItem aItem( mpHatchingList, SID_HATCH_LIST ); // ToolBoxControls are informed: - if ( pShell ) - pShell->PutItem( aItem ); - else - mpDrawModel->GetItemPool().DirectPutItemInPool(aItem); + pShell->PutItem( aItem ); } if( mnBitmapListState & ChangeType::MODIFIED ) @@ -158,12 +146,7 @@ void SvxAreaTabDialog::SavePalettes() SvxBitmapListItem aItem( mpBitmapList, SID_BITMAP_LIST ); // ToolBoxControls are informed: - if ( pShell ) - pShell->PutItem( aItem ); - else - { - mpDrawModel->GetItemPool().DirectPutItemInPool(aItem); - } + pShell->PutItem( aItem ); } if( mnPatternListState & ChangeType::MODIFIED ) @@ -173,10 +156,7 @@ void SvxAreaTabDialog::SavePalettes() SvxPatternListItem aItem( mpPatternList, SID_PATTERN_LIST ); // ToolBoxControls are informed: - if( pShell ) - pShell->PutItem( aItem ); - else - mpDrawModel->GetItemPool().DirectPutItemInPool(aItem); + pShell->PutItem( aItem ); } if( mnGradientListState & ChangeType::MODIFIED ) @@ -186,24 +166,14 @@ void SvxAreaTabDialog::SavePalettes() SvxGradientListItem aItem( mpGradientList, SID_GRADIENT_LIST ); // ToolBoxControls are informed: - if ( pShell ) - pShell->PutItem( aItem ); - else - { - mpDrawModel->GetItemPool().DirectPutItemInPool(aItem); - } + pShell->PutItem( aItem ); } if (mnColorListState & ChangeType::MODIFIED && mpColorList.is()) { SvxColorListItem aItem( mpColorList, SID_COLOR_TABLE ); // ToolBoxControls are informed: - if ( pShell ) - pShell->PutItem( aItem ); - else - { - mpDrawModel->GetItemPool().DirectPutItemInPool(aItem); - } + pShell->PutItem( aItem ); } } diff --git a/include/svl/itempool.hxx b/include/svl/itempool.hxx index 83b22d068bd4..8e971bde5a50 100644 --- a/include/svl/itempool.hxx +++ b/include/svl/itempool.hxx @@ -31,12 +31,15 @@ #include <salhelper/simplereferenceobject.hxx> #include <svl/SfxBroadcaster.hxx> +// flag definitions to be used for _nItemInfoFlags +// in SfxItemInfo +#define SFX_ITEMINFOFLAG_NONE 0x0000 + // Defines if this Item needs to be registered at the pool // to make it accessible for the GetItemSurrogates call. It // will not be included when this flag is not set, but also // needs no registration. There are SAL_INFO calls in the // GetItemSurrogates impl that will mention that -#define SFX_ITEMINFOFLAG_NONE 0x0000 #define SFX_ITEMINFOFLAG_SUPPORT_SURROGATE 0x0001 struct SfxItemInfo @@ -51,15 +54,9 @@ struct SfxItemInfo sal_uInt16 _nItemInfoFlags; }; -#ifdef DBG_UTIL -SVL_DLLPUBLIC size_t getAllDirectlyPooledSfxPoolItemCount(); -SVL_DLLPUBLIC size_t getRemainingDirectlyPooledSfxPoolItemCount(); -#endif - typedef std::unordered_set<SfxItemSet*> registeredSfxItemSets; class SfxPoolItemHolder; typedef std::unordered_set<SfxPoolItemHolder*> registeredSfxPoolItemHolders; -typedef std::unordered_set<SfxPoolItemHolder*> directPutSfxPoolItemHolders; typedef std::vector<const SfxPoolItem*> ItemSurrogates; /** Base class for providers of defaults of SfxPoolItems. @@ -96,7 +93,6 @@ class SVL_DLLPUBLIC SfxItemPool : public salhelper::SimpleReferenceObject registeredSfxItemSets maRegisteredSfxItemSets; registeredSfxPoolItemHolders maRegisteredSfxPoolItemHolders; - directPutSfxPoolItemHolders maDirectPutItems; bool mbPreDeleteDone; private: @@ -186,9 +182,6 @@ public: virtual rtl::Reference<SfxItemPool> Clone() const; const OUString& GetName() const; - const SfxPoolItem& DirectPutItemInPool(const SfxPoolItem&); - void DirectRemoveItemFromPool(const SfxPoolItem&); - const SfxPoolItem& GetDefaultItem( sal_uInt16 nWhich ) const; template<class T> const T& GetDefaultItem( TypedWhichId<T> nWhich ) const { return static_cast<const T&>(GetDefaultItem(sal_uInt16(nWhich))); } @@ -213,15 +206,15 @@ public: }; // Iterate using a lambda/callback with read/write access to registered SfxPoolItems. - // If you use this, look for current usages, inside the callback you may - // return true; // to continue callback (like 'continue') - // return false; // to end callbacks (like 'break') + // If you use this (look for current usages) inside the callback you may + // return true; // to continue callback (like 'continue') + // return false; // to end callbacks (like 'break') void iterateItemSurrogates( sal_uInt16 nWhich, const std::function<bool(SfxItemPool::SurrogateData& rData)>& rItemCallback) const; - // read-only access to registered SfxPoolItems - // NOTE: In no case use static_cast and change those Items (!) + // Read-only access to registered SfxPoolItems + // NOTE: In *no* case use const_cast and change those Items (!) // Read commit text for more information void GetItemSurrogates(ItemSurrogates& rTarget, sal_uInt16 nWhich) const; diff --git a/svl/source/items/itempool.cxx b/svl/source/items/itempool.cxx index 32b1c0499cf4..cb70ecd95c0b 100644 --- a/svl/source/items/itempool.cxx +++ b/svl/source/items/itempool.cxx @@ -33,13 +33,6 @@ #include <cassert> #include <vector> -#ifdef DBG_UTIL -static size_t nAllDirectlyPooledSfxPoolItemCount(0); -static size_t nRemainingDirectlyPooledSfxPoolItemCount(0); -size_t getAllDirectlyPooledSfxPoolItemCount() { return nAllDirectlyPooledSfxPoolItemCount; } -size_t getRemainingDirectlyPooledSfxPoolItemCount() { return nRemainingDirectlyPooledSfxPoolItemCount; } -#endif - // WhichIDs that need to set SFX_ITEMINFOFLAG_SUPPORT_SURROGATE in SfxItemInfo // to true to allow a register of all items of that type/with that WhichID // to be accessible using SfxItemPool::GetItemSurrogates. Created by @@ -418,7 +411,6 @@ SfxItemPool::SfxItemPool , eDefMetric(MapUnit::MapCM) , maRegisteredSfxItemSets() , maRegisteredSfxPoolItemHolders() -, maDirectPutItems() , mbPreDeleteDone(false) { eDefMetric = MapUnit::MapTwip; @@ -471,7 +463,6 @@ SfxItemPool::SfxItemPool , eDefMetric(MapUnit::MapCM) , maRegisteredSfxItemSets() , maRegisteredSfxPoolItemHolders() -, maDirectPutItems() , mbPreDeleteDone(false) { eDefMetric = rPool.eDefMetric; @@ -698,11 +689,6 @@ void SfxItemPool::Delete() // Inform e.g. running Requests aBC.Broadcast( SfxHint( SfxHintId::Dying ) ); - // delete direct put items, may assert here when not empty - for (const auto& rCand : maDirectPutItems) - delete rCand; - maDirectPutItems.clear(); - // default items for (auto rItemPtr : maPoolDefaults) { @@ -770,33 +756,6 @@ void SfxItemPool::ResetPoolDefaultItem( sal_uInt16 nWhichId ) } } -const SfxPoolItem& SfxItemPool::DirectPutItemInPool(const SfxPoolItem& rItem) -{ -#ifdef DBG_UTIL - nAllDirectlyPooledSfxPoolItemCount++; - nRemainingDirectlyPooledSfxPoolItemCount++; -#endif - // use SfxPoolItemHolder now to secure lifetime - SfxPoolItemHolder* pHolder(new SfxPoolItemHolder(*GetMasterPool(), &rItem)); - GetMasterPool()->maDirectPutItems.insert(pHolder); - return *pHolder->getItem(); -} - -void SfxItemPool::DirectRemoveItemFromPool(const SfxPoolItem& rItem) -{ -#ifdef DBG_UTIL - nRemainingDirectlyPooledSfxPoolItemCount--; -#endif - directPutSfxPoolItemHolders& rDirects(GetMasterPool()->maDirectPutItems); - for (directPutSfxPoolItemHolders::iterator aIter(rDirects.begin()); aIter != rDirects.end(); aIter++) - if ((*aIter)->getItem() == &rItem) - { - delete *aIter; - rDirects.erase(aIter); - break; - } -} - const SfxPoolItem& SfxItemPool::GetDefaultItem( sal_uInt16 nWhich ) const { if ( !IsInRange(nWhich) ) diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx index e0055833bc45..e17e4533122f 100644 --- a/vcl/source/app/svapp.cxx +++ b/vcl/source/app/svapp.cxx @@ -204,10 +204,6 @@ Application::~Application() SAL_INFO("vcl.items", "ITEM: " << getAllocatedSfxPoolItemHolderCount() << " SfxPoolItemHolders still allocated at shutdown"); SAL_INFO("vcl.items", "ITEM: " << getUsedSfxPoolItemHolderCount() << " SfxPoolItemHolders were incarnated during runtime"); - // Same mechanism for SfxPoolItem(s)directly put to a Pool - SAL_INFO("vcl.items", "ITEM: " << getRemainingDirectlyPooledSfxPoolItemCount() << " SfxPoolItems still directly put in Pool at shutdown (deleted @Pool destruction)"); - SAL_INFO("vcl.items", "ITEM: " << getAllDirectlyPooledSfxPoolItemCount() << " SfxPoolItems directly put in Pool"); - // Additional call to list still incarnated SfxPoolItems (under 'svl.items') listAllocatedSfxPoolItems();