summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorArmin Le Grand (allotropia) <armin.le.grand.extern@allotropia.de>2024-01-27 15:04:06 +0100
committerArmin Le Grand <Armin.Le.Grand@me.com>2024-01-27 19:02:54 +0100
commit4790ef5cb574650c418591566eeb0babc69db59e (patch)
treebdca4156b1da8bb3efc06cebcee77fa541866ca7 /include
parentd2d8f8bf82558d9aa548fb9f13bed410e0baf79b (diff)
ITEM: Cleanup some Pool stuff with Defaults
Sorted out some methods at ItemPool which process Defaults to make more clear what is going on and what which method is doing. Change-Id: I2568d3e03d0a56a14b6fe4e04521e1a8e22c000b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162643 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
Diffstat (limited to 'include')
-rw-r--r--include/svl/itempool.hxx69
-rw-r--r--include/svl/poolitem.hxx36
2 files changed, 65 insertions, 40 deletions
diff --git a/include/svl/itempool.hxx b/include/svl/itempool.hxx
index 8e971bde5a50..8dca5e89f11b 100644
--- a/include/svl/itempool.hxx
+++ b/include/svl/itempool.hxx
@@ -76,14 +76,11 @@ class SVL_DLLPUBLIC SfxItemPool : public salhelper::SimpleReferenceObject
friend SfxPoolItem const* implCreateItemEntry(SfxItemPool&, SfxPoolItem const*, bool);
friend void implCleanupItemEntry(SfxPoolItem const*);
- // unit testing
- friend class PoolItemTest;
-
const SfxItemInfo* pItemInfos;
SfxBroadcaster aBC;
OUString aName;
- std::vector<SfxPoolItem*> maPoolDefaults;
- std::vector<SfxPoolItem*>* mpStaticDefaults;
+ std::vector<SfxPoolItem*> maUserDefaults;
+ std::vector<SfxPoolItem*>* mpPoolDefaults;
SfxItemPool* mpMaster;
rtl::Reference<SfxItemPool> mpSecondary;
WhichRangesContainer mpPoolRanges;
@@ -132,18 +129,35 @@ public:
SfxBroadcaster& BC();
- void SetPoolDefaultItem( const SfxPoolItem& );
-
- const SfxPoolItem* GetPoolDefaultItem( sal_uInt16 nWhich ) const;
+ // UserDefaults: Every PoolDefault can be 'overloaded' with a user-defined
+ // default. This is then owned by the pool. The read access is limited
+ // to check the UserDefaults, so it *will* return nullptr if none is set
+ void SetUserDefaultItem( const SfxPoolItem& );
+ const SfxPoolItem* GetUserDefaultItem( sal_uInt16 nWhich ) const;
+ template<class T> const T* GetUserDefaultItem( TypedWhichId<T> nWhich ) const
+ { return static_cast<const T*>(GetUserDefaultItem(sal_uInt16(nWhich))); }
+ void ResetUserDefaultItem( sal_uInt16 nWhich );
+
+ // PoolDefaults: Owned by the pool. The read access will only return
+ // nullptr if the WhichID aske for is not in the range of the pool,
+ // making the request invalid.
+ void SetPoolDefaults(std::vector<SfxPoolItem*>* pDefaults);
+ void ClearPoolDefaults();
+ void ReleasePoolDefaults( bool bDelete = false );
+ static void ReleasePoolDefaults( std::vector<SfxPoolItem*> *pDefaults, bool bDelete = false );
+ const SfxPoolItem * GetPoolDefaultItem(sal_uInt16 nWhich) const;
template<class T> const T* GetPoolDefaultItem( TypedWhichId<T> nWhich ) const
{ return static_cast<const T*>(GetPoolDefaultItem(sal_uInt16(nWhich))); }
- void ResetPoolDefaultItem( sal_uInt16 nWhich );
-
- void SetDefaults(std::vector<SfxPoolItem*>* pDefaults);
- void ClearDefaults();
- void ReleaseDefaults( bool bDelete = false );
- static void ReleaseDefaults( std::vector<SfxPoolItem*> *pDefaults, bool bDelete = false );
+ // UserOrPoolDefaults: Combination of UserDefaults and PoolDefaults.
+ // UserDefaults will be preferred. If none is set for that WhichID,
+ // the PoolDefault will be returned.
+ // Note that read access will return a reference, but this will lead
+ // to an asserted error when the given WhichID is not in the range of
+ // the pool.
+ const SfxPoolItem& GetUserOrPoolDefaultItem( sal_uInt16 nWhich ) const;
+ template<class T> const T& GetUserOrPoolDefaultItem( TypedWhichId<T> nWhich ) const
+ { return static_cast<const T&>(GetUserOrPoolDefaultItem(sal_uInt16(nWhich))); }
virtual MapUnit GetMetric( sal_uInt16 nWhich ) const;
void SetDefaultMetric( MapUnit eNewMetric );
@@ -182,13 +196,6 @@ public:
virtual rtl::Reference<SfxItemPool> Clone() const;
const OUString& GetName() const;
- 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))); }
- const SfxPoolItem * GetItem2Default(sal_uInt16 nWhich) const;
- template<class T> const T* GetItem2Default( TypedWhichId<T> nWhich ) const
- { return static_cast<const T*>(GetItem2Default(sal_uInt16(nWhich))); }
-
public:
// SurrogateData callback helper for iterateItemSurrogates
class SurrogateData
@@ -227,7 +234,6 @@ public:
SfxItemPool* GetLastPoolInChain();
SfxItemPool* GetMasterPool() const;
void FreezeIdRanges();
-
void Delete();
// syntactical sugar: direct call to not have to use the flag define
@@ -240,14 +246,25 @@ public:
template<class T>
TypedWhichId<T> GetWhich( TypedWhichId<T> nSlot, bool bDeep = true ) const
{ return TypedWhichId<T>(GetWhich(sal_uInt16(nSlot), bDeep)); }
+
+ // get SlotID that may be registered in the SfxItemInfo for
+ // the given WhichID.
+ // If none is defined, return nWhich.
+ // If nWhich is not a WhichID, return nWhich.
sal_uInt16 GetSlotId( sal_uInt16 nWhich ) const;
+
+ // tries to translate back from SlotID to WhichID. That may be
+ // expensive, it needs to linerarly iterate over SfxItemInfo
+ // to evtl. find if a SlotID is defined for a WhichID
sal_uInt16 GetTrueWhich( sal_uInt16 nSlot, bool bDeep = true ) const;
+
+ // same as GetSlotId, but returns 0 in error cases, so:
+ // If none is defined, return 0.
+ // If nWhich is not a WhichID, return 0.
sal_uInt16 GetTrueSlotId( sal_uInt16 nWhich ) const;
- static bool IsWhich(sal_uInt16 nId) {
- return nId && nId <= SFX_WHICH_MAX; }
- static bool IsSlot(sal_uInt16 nId) {
- return nId && nId > SFX_WHICH_MAX; }
+ static bool IsWhich(sal_uInt16 nId) { return nId && nId <= SFX_WHICH_MAX; }
+ static bool IsSlot(sal_uInt16 nId) { return nId && nId > SFX_WHICH_MAX; }
private:
const SfxItemPool& operator=(const SfxItemPool &) = delete;
diff --git a/include/svl/poolitem.hxx b/include/svl/poolitem.hxx
index 10f0d024c75d..5cbbf4268cc6 100644
--- a/include/svl/poolitem.hxx
+++ b/include/svl/poolitem.hxx
@@ -116,7 +116,6 @@ class ItemInstanceManager;
class SVL_DLLPUBLIC SfxPoolItem
{
friend class SfxItemPool;
- friend class SfxItemDisruptor_Impl;
friend class SfxItemSet;
friend class InstanceManagerHelper;
@@ -141,37 +140,40 @@ class SVL_DLLPUBLIC SfxPoolItem
// Item is registered at some Pool as default.
// m_bStaticDefault: direct Pool Item (CAUTION:
// these are not really 'static', but should be)
- // -> needs cleanup
- // m_bPoolDefault: set by user using SetPoolDefaultItem
- // those should be better called 'UserDefault'
+ // m_bDynamicDefault: dynamic pool item, e.g.
+ // SfxSetItems which are Pool dependent
+ // m_bUserDefault: set by user using
+ // SetUserDefaultItem
bool m_bStaticDefault : 1; // bit 0
- bool m_bPoolDefault : 1; // bit 1
+ bool m_bDynamicDefault : 1; // bit 1
+ bool m_bUserDefault : 1; // bit 2
// Item is derived from SfxSetItem -> is Pool-dependent
- bool m_bIsSetItem : 1; // bit 2
+ bool m_bIsSetItem : 1; // bit 3
// Defines if the Item can be shared/RefCounted else it will be cloned.
// Default is true - as it should be for all Items. It is needed by some
// SW items, so protected to let them set it in constructor. If this could
// be fixed at that Items we may remove this again.
- bool m_bShareable : 1; // bit 3
+ bool m_bShareable : 1; // bit 4
protected:
#ifdef DBG_UTIL
// this flag will make debugging item stuff much simpler
- bool m_bDeleted : 1; // bit 4
+ bool m_bDeleted : 1; // bit 5
#endif
private:
inline void SetRefCount(sal_uInt32 n)
{
m_nRefCount = n;
- m_bStaticDefault = m_bPoolDefault = false;
+ m_bStaticDefault = m_bDynamicDefault = m_bUserDefault = false;
}
protected:
void setStaticDefault() { m_bStaticDefault = true; }
- void setPoolDefault() { m_bPoolDefault = true; }
+ void setDynamicDefault() { m_bDynamicDefault = true; }
+ void setUserDefault() { m_bUserDefault = true; }
void setIsSetItem() { m_bIsSetItem = true; }
void setNonShareable() { m_bShareable = false; }
@@ -196,7 +198,8 @@ public:
#endif
bool isStaticDefault() const { return m_bStaticDefault; }
- bool isPoolDefault() const { return m_bPoolDefault; }
+ bool isDynamicDefault() const { return m_bDynamicDefault; }
+ bool isUserDefault() const { return m_bUserDefault; }
bool isSetItem() const { return m_bIsSetItem; }
bool isShareable() const { return m_bShareable; }
@@ -346,9 +349,9 @@ private:
virtual void remove(const SfxPoolItem&) override;
};
-inline bool IsPoolDefaultItem(const SfxPoolItem *pItem )
+inline bool IsUserDefaultItem(const SfxPoolItem *pItem )
{
- return pItem && pItem->isPoolDefault();
+ return pItem && pItem->isUserDefault();
}
inline bool IsStaticDefaultItem(const SfxPoolItem *pItem )
@@ -356,9 +359,14 @@ inline bool IsStaticDefaultItem(const SfxPoolItem *pItem )
return pItem && pItem->isStaticDefault();
}
+inline bool IsDynamicDefaultItem(const SfxPoolItem *pItem )
+{
+ return pItem && pItem->isDynamicDefault();
+}
+
inline bool IsDefaultItem( const SfxPoolItem *pItem )
{
- return pItem && (pItem->isPoolDefault() || pItem->isStaticDefault());
+ return pItem && (pItem->isUserDefault() || pItem->isStaticDefault() || pItem->isDynamicDefault());
}
inline bool IsPooledItem( const SfxPoolItem *pItem )