diff options
author | Armin Le Grand (allotropia) <armin.le.grand.extern@allotropia.de> | 2024-01-08 18:58:11 +0100 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@me.com> | 2024-01-09 10:49:42 +0100 |
commit | 55e97eaabf6cce91f424e440af392143f11f3343 (patch) | |
tree | 814223e8e9c9909ad366739ee5a2398c478e9eed /sw/inc | |
parent | 24fc8b14ebe29c086292dc22ec332e114ef4e2f5 (diff) |
Decouple SwTextAttr from DirectPutItemInPool
SwTextAttr uses a 'const SfxPoolItem*' and the
mentioned DirectPutItemInPool/DirectRemoveItemFromPool
to force creation of a ref-counted SfxPoolItem to
work with. There is now tooling to do so, so changed
to using SfxPoolItemHolder. That works like a small
SfxItemSet - it transforms the Item to ref-count
form and takes over management. It is safe to
pass around, cheap to copy and it does not need manual
cleanup of SfxPoolItems (automatic -as in SfxItemPool).
Change-Id: I41401d5144c9cd59d5b10362ea17d63e35ab1eb3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161799
Tested-by: Jenkins
Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
Diffstat (limited to 'sw/inc')
-rw-r--r-- | sw/inc/textcontentcontrol.hxx | 4 | ||||
-rw-r--r-- | sw/inc/textlinebreak.hxx | 2 | ||||
-rw-r--r-- | sw/inc/txatbase.hxx | 72 | ||||
-rw-r--r-- | sw/inc/txtannotationfld.hxx | 2 | ||||
-rw-r--r-- | sw/inc/txtatr.hxx | 19 | ||||
-rw-r--r-- | sw/inc/txtflcnt.hxx | 4 | ||||
-rw-r--r-- | sw/inc/txtfld.hxx | 4 | ||||
-rw-r--r-- | sw/inc/txtftn.hxx | 4 | ||||
-rw-r--r-- | sw/inc/txtinet.hxx | 5 | ||||
-rw-r--r-- | sw/inc/txtrfmrk.hxx | 6 | ||||
-rw-r--r-- | sw/inc/txttxmrk.hxx | 6 |
11 files changed, 77 insertions, 51 deletions
diff --git a/sw/inc/textcontentcontrol.hxx b/sw/inc/textcontentcontrol.hxx index b3926bd25ce9..89a69970efcc 100644 --- a/sw/inc/textcontentcontrol.hxx +++ b/sw/inc/textcontentcontrol.hxx @@ -28,12 +28,12 @@ class SW_DLLPUBLIC SwTextContentControl final : public SwTextAttrNesting { SwContentControlManager* m_pManager; - SwTextContentControl(SwContentControlManager* pManager, SwFormatContentControl& rAttr, + SwTextContentControl(SwContentControlManager* pManager, const SfxPoolItemHolder& rAttr, sal_Int32 nStart, sal_Int32 nEnd); public: static SwTextContentControl* CreateTextContentControl(SwDoc& rDoc, SwTextNode* pTargetTextNode, - SwFormatContentControl& rAttr, + const SfxPoolItemHolder& rHolder, sal_Int32 nStart, sal_Int32 nEnd, bool bIsCopy); diff --git a/sw/inc/textlinebreak.hxx b/sw/inc/textlinebreak.hxx index 5b5e8c6854c3..57f6b3ecb60e 100644 --- a/sw/inc/textlinebreak.hxx +++ b/sw/inc/textlinebreak.hxx @@ -33,7 +33,7 @@ class SW_DLLPUBLIC SwTextLineBreak final : public SwTextAttr SwTextNode* m_pTextNode; public: - SwTextLineBreak(SwFormatLineBreak& rAttr, sal_Int32 nStart); + SwTextLineBreak(const SfxPoolItemHolder& rAttr, sal_Int32 nStart); ~SwTextLineBreak() override; diff --git a/sw/inc/txatbase.hxx b/sw/inc/txatbase.hxx index 00e2f9b51470..2b3595709bf1 100644 --- a/sw/inc/txatbase.hxx +++ b/sw/inc/txatbase.hxx @@ -44,7 +44,8 @@ class SW_DLLPUBLIC SwTextAttr { friend class SwpHints; private: - SfxPoolItem * const m_pAttr; + // use SfxPoolItemHolder for safe reference to 'const SfxPoolItem*' + SfxPoolItemHolder m_aAttr; sal_Int32 m_nStart; bool m_bDontExpand : 1; bool m_bLockExpandFlag : 1; @@ -66,7 +67,7 @@ private: protected: SwpHints * m_pHints = nullptr; // the SwpHints holds a pointer to this, and needs to be notified if the start/end changes - SwTextAttr( SfxPoolItem& rAttr, sal_Int32 nStart ); + SwTextAttr(const SfxPoolItemHolder& rAttr, sal_Int32 nStart ); virtual ~SwTextAttr() COVERITY_NOEXCEPT_FALSE; void SetLockExpandFlag( bool bFlag ) { m_bLockExpandFlag = bFlag; } @@ -81,7 +82,7 @@ protected: public: /// destroy instance - static void Destroy( SwTextAttr * pToDestroy, SfxItemPool& rPool ); + static void Destroy( SwTextAttr * pToDestroy ); /// start position void SetStart(sal_Int32 n) { m_nStart = n; if (m_pHints) m_pHints->StartPosChanged(); } @@ -138,7 +139,10 @@ protected: sal_Int32 m_nEnd; public: - SwTextAttrEnd( SfxPoolItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd ); + SwTextAttrEnd( + const SfxPoolItemHolder& rAttr, + sal_Int32 nStart, + sal_Int32 nEnd ); virtual const sal_Int32* GetEnd() const override; virtual void SetEnd(sal_Int32) override; @@ -148,8 +152,10 @@ public: class SAL_DLLPUBLIC_RTTI SwTextAttrNesting : public SwTextAttrEnd { protected: - SwTextAttrNesting( SfxPoolItem & i_rAttr, - const sal_Int32 i_nStart, const sal_Int32 i_nEnd ); + SwTextAttrNesting( + const SfxPoolItemHolder& rAttr, + const sal_Int32 i_nStart, + const sal_Int32 i_nEnd ); virtual ~SwTextAttrNesting() override; }; @@ -166,8 +172,8 @@ inline sal_Int32 SwTextAttr::GetAnyEnd() const inline const SfxPoolItem& SwTextAttr::GetAttr() const { - assert( m_pAttr ); - return *m_pAttr; + assert( m_aAttr ); + return *m_aAttr.getItem(); } inline SfxPoolItem& SwTextAttr::GetAttr() @@ -186,71 +192,71 @@ inline void SwTextAttr::SetDontExpand( bool bDontExpand ) inline const SwFormatCharFormat& SwTextAttr::GetCharFormat() const { - assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_CHARFMT ); - return static_cast<const SwFormatCharFormat&>(*m_pAttr); + assert( m_aAttr && m_aAttr.Which() == RES_TXTATR_CHARFMT ); + return static_cast<const SwFormatCharFormat&>(*m_aAttr.getItem()); } inline const SwFormatAutoFormat& SwTextAttr::GetAutoFormat() const { - assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_AUTOFMT ); - return static_cast<const SwFormatAutoFormat&>(*m_pAttr); + assert( m_aAttr && m_aAttr.Which() == RES_TXTATR_AUTOFMT ); + return static_cast<const SwFormatAutoFormat&>(*m_aAttr.getItem()); } inline const SwFormatField& SwTextAttr::GetFormatField() const { - assert( m_pAttr - && ( m_pAttr->Which() == RES_TXTATR_FIELD - || m_pAttr->Which() == RES_TXTATR_ANNOTATION - || m_pAttr->Which() == RES_TXTATR_INPUTFIELD )); - return static_cast<const SwFormatField&>(*m_pAttr); + assert( m_aAttr + && ( m_aAttr.Which() == RES_TXTATR_FIELD + || m_aAttr.Which() == RES_TXTATR_ANNOTATION + || m_aAttr.Which() == RES_TXTATR_INPUTFIELD )); + return static_cast<const SwFormatField&>(*m_aAttr.getItem()); } inline const SwFormatFootnote& SwTextAttr::GetFootnote() const { - assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_FTN ); - return static_cast<const SwFormatFootnote&>(*m_pAttr); + assert( m_aAttr && m_aAttr.Which() == RES_TXTATR_FTN ); + return static_cast<const SwFormatFootnote&>(*m_aAttr.getItem()); } inline const SwFormatLineBreak& SwTextAttr::GetLineBreak() const { - assert(m_pAttr && m_pAttr->Which() == RES_TXTATR_LINEBREAK); - return static_cast<const SwFormatLineBreak&>(*m_pAttr); + assert(m_aAttr && m_aAttr.Which() == RES_TXTATR_LINEBREAK); + return static_cast<const SwFormatLineBreak&>(*m_aAttr.getItem()); } inline const SwFormatContentControl& SwTextAttr::GetContentControl() const { - assert(m_pAttr && m_pAttr->Which() == RES_TXTATR_CONTENTCONTROL); - return static_cast<const SwFormatContentControl&>(*m_pAttr); + assert(m_aAttr && m_aAttr.Which() == RES_TXTATR_CONTENTCONTROL); + return static_cast<const SwFormatContentControl&>(*m_aAttr.getItem()); } inline const SwFormatFlyCnt& SwTextAttr::GetFlyCnt() const { - assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_FLYCNT ); - return static_cast<const SwFormatFlyCnt&>(*m_pAttr); + assert( m_aAttr && m_aAttr.Which() == RES_TXTATR_FLYCNT ); + return static_cast<const SwFormatFlyCnt&>(*m_aAttr.getItem()); } inline const SwTOXMark& SwTextAttr::GetTOXMark() const { - assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_TOXMARK ); - return static_cast<const SwTOXMark&>(*m_pAttr); + assert( m_aAttr && m_aAttr.Which() == RES_TXTATR_TOXMARK ); + return static_cast<const SwTOXMark&>(*m_aAttr.getItem()); } inline const SwFormatRefMark& SwTextAttr::GetRefMark() const { - assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_REFMARK ); - return static_cast<const SwFormatRefMark&>(*m_pAttr); + assert( m_aAttr && m_aAttr.Which() == RES_TXTATR_REFMARK ); + return static_cast<const SwFormatRefMark&>(*m_aAttr.getItem()); } inline const SwFormatINetFormat& SwTextAttr::GetINetFormat() const { - assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_INETFMT ); - return static_cast<const SwFormatINetFormat&>(*m_pAttr); + assert( m_aAttr && m_aAttr.Which() == RES_TXTATR_INETFMT ); + return static_cast<const SwFormatINetFormat&>(*m_aAttr.getItem()); } inline const SwFormatRuby& SwTextAttr::GetRuby() const { - assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_CJK_RUBY ); - return static_cast<const SwFormatRuby&>(*m_pAttr); + assert( m_aAttr && m_aAttr.Which() == RES_TXTATR_CJK_RUBY ); + return static_cast<const SwFormatRuby&>(*m_aAttr.getItem()); } // these should be static_casts but with virtual inheritance it's not possible diff --git a/sw/inc/txtannotationfld.hxx b/sw/inc/txtannotationfld.hxx index f45e0c5b9b35..b1d35b33ea25 100644 --- a/sw/inc/txtannotationfld.hxx +++ b/sw/inc/txtannotationfld.hxx @@ -28,7 +28,7 @@ class SwTextAnnotationField final : public SwTextField { public: SwTextAnnotationField( - SwFormatField & rAttr, + const SfxPoolItemHolder& rAttr, sal_Int32 const nStart, bool const bInClipboard ); diff --git a/sw/inc/txtatr.hxx b/sw/inc/txtatr.hxx index cb96256fcb10..cf1b77073676 100644 --- a/sw/inc/txtatr.hxx +++ b/sw/inc/txtatr.hxx @@ -37,7 +37,10 @@ class SwTextCharFormat final : public SwTextAttrEnd sal_uInt16 m_nSortNumber; public: - SwTextCharFormat( SwFormatCharFormat& rAttr, sal_Int32 nStart, sal_Int32 nEnd ); + SwTextCharFormat( + const SfxPoolItemHolder& rAttr, + sal_Int32 nStart, + sal_Int32 nEnd ); virtual ~SwTextCharFormat( ) override; void TriggerNodeUpdate(const sw::LegacyModifyHint&); @@ -54,14 +57,17 @@ public: class SwTextMeta final : public SwTextAttrNesting { private: - SwTextMeta( SwFormatMeta & i_rAttr, - const sal_Int32 i_nStart, const sal_Int32 i_nEnd ); + SwTextMeta( + const SfxPoolItemHolder& rAttr, + const sal_Int32 i_nStart, + const sal_Int32 i_nEnd ); public: static SwTextMeta * CreateTextMeta( ::sw::MetaFieldManager & i_rTargetDocManager, SwTextNode *const i_pTargetTextNode, - SwFormatMeta & i_rAttr, + const SfxPoolItemHolder& rAttr, + // SwFormatMeta & i_rAttr, sal_Int32 const i_nStart, sal_Int32 const i_nEnd, bool const i_bIsCopy); @@ -76,7 +82,10 @@ class SW_DLLPUBLIC SwTextRuby final: public SwTextAttrNesting, public SwClient SwTextNode* m_pTextNode; virtual void SwClientNotify(const SwModify&, const SfxHint&) override; public: - SwTextRuby( SwFormatRuby& rAttr, sal_Int32 nStart, sal_Int32 nEnd ); + SwTextRuby( + const SfxPoolItemHolder& rAttr, + sal_Int32 nStart, + sal_Int32 nEnd ); virtual ~SwTextRuby() override; SAL_DLLPRIVATE void InitRuby(SwTextNode & rNode); diff --git a/sw/inc/txtflcnt.hxx b/sw/inc/txtflcnt.hxx index a4a0de1d609b..73f422116bc3 100644 --- a/sw/inc/txtflcnt.hxx +++ b/sw/inc/txtflcnt.hxx @@ -31,7 +31,9 @@ class SwTextFlyCnt final : public SwTextAttr { SwFlyInContentFrame *GetFlyFrame_( const SwFrame *pCurrFrame ); public: - SwTextFlyCnt( SwFormatFlyCnt& rAttr, sal_Int32 nStart ); + SwTextFlyCnt( + const SfxPoolItemHolder& rAttr, + sal_Int32 nStart ); // Sets anchor in pFormat and void SetAnchor( const SwTextNode *pNode ); diff --git a/sw/inc/txtfld.hxx b/sw/inc/txtfld.hxx index 8055b337b0cb..5e812f8682d9 100644 --- a/sw/inc/txtfld.hxx +++ b/sw/inc/txtfld.hxx @@ -35,7 +35,7 @@ class SAL_DLLPUBLIC_RTTI SwTextField : public virtual SwTextAttr public: SwTextField( - SwFormatField & rAttr, + const SfxPoolItemHolder& rAttr, sal_Int32 const nStart, bool const bInClipboard ); @@ -80,7 +80,7 @@ class SwTextInputField final { public: SwTextInputField( - SwFormatField & rAttr, + const SfxPoolItemHolder& rAttr, sal_Int32 const nStart, sal_Int32 const nEnd, bool const bInClipboard ); diff --git a/sw/inc/txtftn.hxx b/sw/inc/txtftn.hxx index 2d86bf217e64..6c8ca41bc8c6 100644 --- a/sw/inc/txtftn.hxx +++ b/sw/inc/txtftn.hxx @@ -37,7 +37,9 @@ class SW_DLLPUBLIC SwTextFootnote final : public SwTextAttr sal_uInt16 m_nSeqNo; public: - SwTextFootnote( SwFormatFootnote& rAttr, sal_Int32 nStart ); + SwTextFootnote( + const SfxPoolItemHolder& rAttr, + sal_Int32 nStart ); virtual ~SwTextFootnote() override; const SwNodeIndex *GetStartNode() const { return m_oStartNode ? &*m_oStartNode : nullptr; } diff --git a/sw/inc/txtinet.hxx b/sw/inc/txtinet.hxx index 33b8b96c6273..ae430d59ac42 100644 --- a/sw/inc/txtinet.hxx +++ b/sw/inc/txtinet.hxx @@ -35,7 +35,10 @@ class SW_DLLPUBLIC SwTextINetFormat final: public SwTextAttrNesting, public SwCl virtual void SwClientNotify(const SwModify&, const SfxHint&) override; public: - SwTextINetFormat( SwFormatINetFormat& rAttr, sal_Int32 nStart, sal_Int32 nEnd ); + SwTextINetFormat( + const SfxPoolItemHolder& rAttr, + sal_Int32 nStart, + sal_Int32 nEnd ); virtual ~SwTextINetFormat() override; SAL_DLLPRIVATE void InitINetFormat(SwTextNode & rNode); diff --git a/sw/inc/txtrfmrk.hxx b/sw/inc/txtrfmrk.hxx index c01387998392..4f68b9ef0201 100644 --- a/sw/inc/txtrfmrk.hxx +++ b/sw/inc/txtrfmrk.hxx @@ -32,8 +32,10 @@ class SwTextRefMark final : public SwTextAttrEnd sal_Int32 * m_pEnd; // end is optional (point reference) public: - SwTextRefMark( SwFormatRefMark& rAttr, - sal_Int32 const nStart, sal_Int32 const*const pEnd = nullptr); + SwTextRefMark( + const SfxPoolItemHolder& rAttr, + sal_Int32 const nStart, + sal_Int32 const*const pEnd = nullptr); ~SwTextRefMark(); diff --git a/sw/inc/txttxmrk.hxx b/sw/inc/txttxmrk.hxx index 96239e947e3b..202eae21a5f5 100644 --- a/sw/inc/txttxmrk.hxx +++ b/sw/inc/txttxmrk.hxx @@ -31,8 +31,10 @@ class SAL_DLLPUBLIC_RTTI SwTextTOXMark final : public SwTextAttrEnd sal_Int32 * m_pEnd; // 0 if SwTOXMark without AlternativeText public: - SwTextTOXMark( SwTOXMark& rAttr, - sal_Int32 const nStart, sal_Int32 const*const pEnd); + SwTextTOXMark( + const SfxPoolItemHolder& rAttr, + sal_Int32 const nStart, + sal_Int32 const*const pEnd); virtual ~SwTextTOXMark() override; virtual const sal_Int32 *GetEnd() const override; // SwTextAttr |