include/svl/hint.hxx | 1 sw/inc/fchrfmt.hxx | 2 - sw/inc/fmtfld.hxx | 2 - sw/inc/format.hxx | 1 sw/inc/hintids.hxx | 2 - sw/inc/hints.hxx | 17 +++++---- sw/inc/txtatr.hxx | 4 +- sw/inc/txtinet.hxx | 2 - sw/source/core/attr/format.cxx | 13 ++++++- sw/source/core/attr/hints.cxx | 10 ++--- sw/source/core/doc/DocumentStylePoolManager.cxx | 28 +++++++--------- sw/source/core/doc/docfmt.cxx | 35 +++++--------------- sw/source/core/doc/fmtcol.cxx | 5 ++ sw/source/core/doc/poolfmt.cxx | 8 ++-- sw/source/core/docnode/node.cxx | 11 ++---- sw/source/core/fields/ddetbl.cxx | 2 - sw/source/core/fields/docufld.cxx | 5 +- sw/source/core/inc/flyfrm.hxx | 3 - sw/source/core/inc/pagefrm.hxx | 3 - sw/source/core/layout/atrfrm.cxx | 9 ++++- sw/source/core/layout/fly.cxx | 14 +++----- sw/source/core/layout/flyincnt.cxx | 6 +++ sw/source/core/layout/flylay.cxx | 6 +++ sw/source/core/layout/pagechg.cxx | 17 +++------ sw/source/core/layout/pagedesc.cxx | 7 ++++ sw/source/core/table/swtable.cxx | 10 ++--- sw/source/core/txtnode/atrfld.cxx | 16 +++------ sw/source/core/txtnode/fmtatr2.cxx | 11 +++--- sw/source/core/txtnode/ndtxt.cxx | 7 +++- sw/source/core/txtnode/txtatr2.cxx | 42 +++++++++++++++--------- sw/source/core/unocore/unocoll.cxx | 22 +++++------- sw/source/core/unocore/unostyle.cxx | 7 +--- sw/source/uibase/utlui/content.cxx | 6 +-- 33 files changed, 173 insertions(+), 161 deletions(-)
New commits: commit 140079362502408c75ceee67e86d779f61c0ac1b Author: Bjoern Michaelsen <[email protected]> AuthorDate: Wed Aug 9 11:34:00 2023 +0200 Commit: Bjoern Michaelsen <[email protected]> CommitDate: Fri Sep 1 00:05:28 2023 +0200 remove AUTOFMT_DOCNODE - remove obsolete GetInfo()s - introduce SwFormat::IsUsed() - move handling from GetInfo to SwClientNotify - make sure SwAutoFormatUsedHint is forwarded to clients where needed (e.g. SwTextFormatColl, SwDDETable, SwPageDesc, ...) Change-Id: I07d9e94ee791ca6e738b4eb3e597055ad8fbe755 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155504 Tested-by: Jenkins Reviewed-by: Bjoern Michaelsen <[email protected]> diff --git a/include/svl/hint.hxx b/include/svl/hint.hxx index ba230f92b817..91533d4ffdbb 100644 --- a/include/svl/hint.hxx +++ b/include/svl/hint.hxx @@ -153,6 +153,7 @@ enum class SfxHintId { SwDocPosUpdateAtIndex, SwTableHeadingChange, SwVirtPageNumHint, + SwAutoFormatUsedHint, ThisIsAnSdrHint }; diff --git a/sw/inc/fchrfmt.hxx b/sw/inc/fchrfmt.hxx index 87508596013b..2b5aec14278e 100644 --- a/sw/inc/fchrfmt.hxx +++ b/sw/inc/fchrfmt.hxx @@ -60,8 +60,6 @@ public: virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override; virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override; - virtual bool GetInfo( SfxPoolItem& rInfo ) const override; - void SetCharFormat( SwFormat* pFormat ) { assert(!pFormat->IsDefault()); // expose cases that lead to use-after-free diff --git a/sw/inc/fmtfld.hxx b/sw/inc/fmtfld.hxx index 4c4c1ea91293..ba23014a1f82 100644 --- a/sw/inc/fmtfld.hxx +++ b/sw/inc/fmtfld.hxx @@ -124,8 +124,6 @@ public: virtual bool operator==( const SfxPoolItem& ) const override; virtual SwFormatField* Clone( SfxItemPool* pPool = nullptr ) const override; - virtual bool GetInfo( SfxPoolItem& rInfo ) const override; - void InvalidateField(); const SwField* GetField() const diff --git a/sw/inc/format.hxx b/sw/inc/format.hxx index 9313b863dfbb..f420afcf512e 100644 --- a/sw/inc/format.hxx +++ b/sw/inc/format.hxx @@ -280,6 +280,7 @@ public: virtual drawinglayer::attribute::SdrAllFillAttributesHelperPtr getSdrAllFillAttributesHelper() const; virtual bool supportsFullDrawingLayerFillAttributeSet() const; void RemoveAllUnos(); + bool IsUsed() const; }; #endif // INCLUDED_SW_INC_FORMAT_HXX diff --git a/sw/inc/hintids.hxx b/sw/inc/hintids.hxx index 339a73068162..feb6299ee001 100644 --- a/sw/inc/hintids.hxx +++ b/sw/inc/hintids.hxx @@ -140,7 +140,6 @@ class SwTextGridItem; class SwTransparencyGrf; class SwFormatRuby; class SwTableFormulaUpdate; -class SwAutoFormatGetDocNode; class VirtPageNumHint; class SwFindNearestNode; class SwFltAnchor; @@ -431,7 +430,6 @@ constexpr TypedWhichId<SwPtrMsgPoolItem> RES_OBJECTDYING(RES_FORMAT_MSG_BEGIN); constexpr TypedWhichId<SwFormatChg> RES_FMT_CHG(168); constexpr TypedWhichId<SwAttrSetChg> RES_ATTRSET_CHG(169); constexpr TypedWhichId<SwUpdateAttr> RES_UPDATE_ATTR(170); -constexpr TypedWhichId<SwAutoFormatGetDocNode> RES_AUTOFMT_DOCNODE(176); constexpr TypedWhichId<SwMsgPoolItem> RES_HIDDENPARA_PRINT(178); constexpr TypedWhichId<SwPtrMsgPoolItem> RES_REMOVE_UNO_OBJECT(181); // empty diff --git a/sw/inc/hints.hxx b/sw/inc/hints.hxx index eb3ba5a2cdc2..b3d400e06286 100644 --- a/sw/inc/hints.hxx +++ b/sw/inc/hints.hxx @@ -287,6 +287,15 @@ public: bool IsFound() { return m_bFound; } }; +class AutoFormatUsedHint final : public SfxHint +{ + bool& m_isUsed; + const SwNodes& m_rNodes; +public: + AutoFormatUsedHint(bool& isUsed, const SwNodes& rNodes) : SfxHint(SfxHintId::SwAutoFormatUsedHint), m_isUsed(isUsed), m_rNodes(rNodes) {} + void SetUsed() const { m_isUsed = true; } + void CheckNode(const SwNode*) const; +}; } class SwUpdateAttr final : public SwMsgPoolItem @@ -347,14 +356,6 @@ public: SwTableFormulaUpdate( const SwTable* ); }; -class SwAutoFormatGetDocNode final : public SwMsgPoolItem -{ -public: - const SwNodes* pNodes; - - SwAutoFormatGetDocNode( const SwNodes* pNds ); -}; - /* * SwAttrSetChg is sent when something has changed in the SwAttrSet rTheChgdSet. * 2 Hints are always sent, the old and the new items in the rTheChgdSet. diff --git a/sw/inc/txtatr.hxx b/sw/inc/txtatr.hxx index 558ed937a724..b97501bb8dfd 100644 --- a/sw/inc/txtatr.hxx +++ b/sw/inc/txtatr.hxx @@ -28,6 +28,7 @@ class SwFormatMeta; namespace sw { class MetaFieldManager; + class AutoFormatUsedHint; } class SwTextCharFormat final : public SwTextAttrEnd @@ -47,6 +48,7 @@ public: void SetSortNumber( sal_uInt16 nSortNumber ) { m_nSortNumber = nSortNumber; } sal_uInt16 GetSortNumber() const { return m_nSortNumber; } + void HandleAutoFormatUsedHint(const sw::AutoFormatUsedHint&); }; @@ -78,8 +80,6 @@ public: SwTextRuby( SwFormatRuby& rAttr, sal_Int32 nStart, sal_Int32 nEnd ); virtual ~SwTextRuby() override; - virtual bool GetInfo( SfxPoolItem& rInfo ) const override; - SAL_DLLPRIVATE void InitRuby(SwTextNode & rNode); /// Get and set TextNode pointer. diff --git a/sw/inc/txtinet.hxx b/sw/inc/txtinet.hxx index 6459b84a3e59..33b8b96c6273 100644 --- a/sw/inc/txtinet.hxx +++ b/sw/inc/txtinet.hxx @@ -38,8 +38,6 @@ class SW_DLLPUBLIC SwTextINetFormat final: public SwTextAttrNesting, public SwCl SwTextINetFormat( SwFormatINetFormat& rAttr, sal_Int32 nStart, sal_Int32 nEnd ); virtual ~SwTextINetFormat() override; - virtual bool GetInfo( SfxPoolItem& rInfo ) const override; - SAL_DLLPRIVATE void InitINetFormat(SwTextNode & rNode); // get and set TextNode pointer diff --git a/sw/source/core/attr/format.cxx b/sw/source/core/attr/format.cxx index fe341f21b8da..6f2f076881e9 100644 --- a/sw/source/core/attr/format.cxx +++ b/sw/source/core/attr/format.cxx @@ -208,7 +208,7 @@ SwFormat::~SwFormat() return; m_bFormatInDTOR = true; - + if(!DerivedFrom()) { SwFormat::ResetFormatAttr(RES_PAGEDESC); @@ -760,6 +760,17 @@ void SwFormat::RemoveAllUnos() SwClientNotify(*this, sw::LegacyModifyHint(&aMsgHint, &aMsgHint)); } +bool SwFormat::IsUsed() const +{ + auto pDoc = GetDoc(); + if(!pDoc) + return false; + bool isUsed = false; + sw::AutoFormatUsedHint aHint(isUsed, pDoc->GetNodes()); + CallSwClientNotify(aHint); + return isUsed; +} + SwFormatsBase::~SwFormatsBase() {} diff --git a/sw/source/core/attr/hints.cxx b/sw/source/core/attr/hints.cxx index 279bf9725edc..7102ce7d7f5d 100644 --- a/sw/source/core/attr/hints.cxx +++ b/sw/source/core/attr/hints.cxx @@ -78,6 +78,11 @@ VirtPageNumHint::VirtPageNumHint(const SwPageFrame* pPg): { } +void AutoFormatUsedHint::CheckNode(const SwNode* pNode) const +{ + if(pNode && &pNode->GetNodes() == &m_rNodes) + SetUsed(); +} } // namespace sw SwUpdateAttr::SwUpdateAttr( sal_Int32 nS, sal_Int32 nE, sal_uInt16 nW ) @@ -100,11 +105,6 @@ SwTableFormulaUpdate::SwTableFormulaUpdate(const SwTable* pNewTable) OSL_ENSURE( m_pTable, "No Table pointer" ); } -SwAutoFormatGetDocNode::SwAutoFormatGetDocNode( const SwNodes* pNds ) - : SwMsgPoolItem( RES_AUTOFMT_DOCNODE ), pNodes( pNds ) -{ -} - SwAttrSetChg::SwAttrSetChg( const SwAttrSet& rTheSet, SwAttrSet& rSet ) : SwMsgPoolItem( RES_ATTRSET_CHG ), m_bDelSet( false ), diff --git a/sw/source/core/doc/DocumentStylePoolManager.cxx b/sw/source/core/doc/DocumentStylePoolManager.cxx index b67e34ade4cc..63c2720f7f64 100644 --- a/sw/source/core/doc/DocumentStylePoolManager.cxx +++ b/sw/source/core/doc/DocumentStylePoolManager.cxx @@ -2497,8 +2497,10 @@ bool DocumentStylePoolManager::IsPoolTextCollUsed( sal_uInt16 nId ) const if( !bFnd || !pNewColl->HasWriterListeners() ) return false; - SwAutoFormatGetDocNode aGetHt( &m_rDoc.GetNodes() ); - return !pNewColl->GetInfo( aGetHt ); + bool isUsed = false; + sw::AutoFormatUsedHint aHint(isUsed, m_rDoc.GetNodes()); + pNewColl->CallSwClientNotify(aHint); + return isUsed; } /// Check if this AutoCollection is already/still in use @@ -2540,17 +2542,11 @@ bool DocumentStylePoolManager::IsPoolFormatUsed( sal_uInt16 nId ) const } // Not found or no dependencies? - if( bFnd && pNewFormat->HasWriterListeners() ) - { - // Check if we have dependent ContentNodes in the Nodes array - // (also indirect ones for derived Formats) - SwAutoFormatGetDocNode aGetHt( &m_rDoc.GetNodes() ); - bFnd = !pNewFormat->GetInfo( aGetHt ); - } - else - bFnd = false; - - return bFnd; + if(!bFnd || !pNewFormat->HasWriterListeners() ) + return false; + // Check if we have dependent ContentNodes in the Nodes array + // (also indirect ones for derived Formats) + return pNewFormat->IsUsed(); } /// Check if this AutoCollection is already/still in use in this Document @@ -2573,8 +2569,10 @@ bool DocumentStylePoolManager::IsPoolPageDescUsed( sal_uInt16 nId ) const // Check if we have dependent ContentNodes in the Nodes array // (also indirect ones for derived Formats) - SwAutoFormatGetDocNode aGetHt( &m_rDoc.GetNodes() ); - return !pNewPgDsc->GetInfo( aGetHt ); + bool isUsed = false; + sw::AutoFormatUsedHint aHint(isUsed, m_rDoc.GetNodes()); + pNewPgDsc->CallSwClientNotify(aHint); + return isUsed; } DocumentStylePoolManager::~DocumentStylePoolManager() diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx index 5f7b6d9d6c10..edacd4455b70 100644 --- a/sw/source/core/doc/docfmt.cxx +++ b/sw/source/core/doc/docfmt.cxx @@ -78,6 +78,8 @@ #include <textboxhelper.hxx> #include <textcontentcontrol.hxx> #include <memory> +#include <algorithm> +#include <functional> using namespace ::com::sun::star::i18n; using namespace ::com::sun::star::lang; @@ -778,40 +780,23 @@ SwDrawFrameFormat *SwDoc::MakeDrawFrameFormat( const OUString &rFormatName, size_t SwDoc::GetTableFrameFormatCount(bool bUsed) const { if (!bUsed) - { return mpTableFrameFormatTable->size(); - } - - SwAutoFormatGetDocNode aGetHt(&GetNodes()); - size_t nCount = 0; - for (const SwTableFormat* pFormat: *mpTableFrameFormatTable) - { - if (!pFormat->GetInfo(aGetHt)) - nCount++; - } - return nCount; + return std::count_if(mpTableFrameFormatTable->begin(), mpTableFrameFormatTable->end(), + std::mem_fn(&SwFormat::IsUsed)); } SwTableFormat& SwDoc::GetTableFrameFormat(size_t nFormat, bool bUsed) const { if (!bUsed) - { return *const_cast<SwTableFormat*>((*mpTableFrameFormatTable)[nFormat]); - } - - SwAutoFormatGetDocNode aGetHt(&GetNodes()); - - size_t index = 0; - for(SwTableFormat* pFormat: *mpTableFrameFormatTable) { - if (!pFormat->GetInfo(aGetHt)) - { - if (index == nFormat) - return *pFormat; - else - index++; - } + if(!pFormat->IsUsed()) + continue; + if(nFormat) + --nFormat; + else + return *pFormat; } throw std::out_of_range("Format index out of range."); } diff --git a/sw/source/core/doc/fmtcol.cxx b/sw/source/core/doc/fmtcol.cxx index 734fd1312325..5561b882ee3f 100644 --- a/sw/source/core/doc/fmtcol.cxx +++ b/sw/source/core/doc/fmtcol.cxx @@ -127,6 +127,11 @@ SwTextFormatColl::~SwTextFormatColl() } void SwTextFormatColl::SwClientNotify(const SwModify& rModify, const SfxHint& rHint) { + if (rHint.GetId() == SfxHintId::SwAutoFormatUsedHint) + { + CallSwClientNotify(rHint); + return; + } if (rHint.GetId() != SfxHintId::SwLegacyModify) return; auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); diff --git a/sw/source/core/doc/poolfmt.cxx b/sw/source/core/doc/poolfmt.cxx index 5f25ea6b0f0e..97b4e4cce938 100644 --- a/sw/source/core/doc/poolfmt.cxx +++ b/sw/source/core/doc/poolfmt.cxx @@ -87,8 +87,10 @@ bool SwDoc::IsUsed( const sw::BroadcastingModify& rModify ) const { // Check if we have dependent ContentNodes in the Nodes array // (also indirect ones for derived Formats) - SwAutoFormatGetDocNode aGetHt( &GetNodes() ); - return !rModify.GetInfo( aGetHt ); + bool isUsed = false; + sw::AutoFormatUsedHint aHint(isUsed, GetNodes()); + rModify.CallSwClientNotify(aHint); + return isUsed; } // See if Table style is in use @@ -225,7 +227,7 @@ sal_uInt16 GetPoolParent( sal_uInt16 nId ) case RES_POOLCOLL_HEADERFOOTER: case RES_POOLCOLL_LABEL: case RES_POOLCOLL_COMMENT: - nRet = RES_POOLCOLL_STANDARD; break; + nRet = RES_POOLCOLL_STANDARD; break; case RES_POOLCOLL_HEADER: nRet = RES_POOLCOLL_HEADERFOOTER; break; case RES_POOLCOLL_HEADERL: diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx index 4304b875c4d7..c9abe227643a 100644 --- a/sw/source/core/docnode/node.cxx +++ b/sw/source/core/docnode/node.cxx @@ -1195,6 +1195,11 @@ void SwContentNode::SwClientNotify( const SwModify&, const SfxHint& rHint) static_cast<SwTextNode*>(this)->SetCalcHiddenCharFlags(); CallSwClientNotify(rHint); } + else if (rHint.GetId() == SfxHintId::SwAutoFormatUsedHint) + { + static_cast<const sw::AutoFormatUsedHint&>(rHint).CheckNode(this); + return; + } else if (auto pModifyChangedHint = dynamic_cast<const sw::ModifyChangedHint*>(&rHint)) { m_pCondColl = const_cast<SwFormatColl*>(static_cast<const SwFormatColl*>(pModifyChangedHint->m_pNew)); @@ -1572,12 +1577,6 @@ bool SwContentNode::GetInfo( SfxPoolItem& rInfo ) const if( GetAttr( RES_PAGEDESC ).GetPageDesc() ) static_cast<SwFindNearestNode&>(rInfo).CheckNode( *this ); return true; - case RES_AUTOFMT_DOCNODE: - if( &GetNodes() == static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes ) - { - return false; - } - break; } return sw::BroadcastingModify::GetInfo( rInfo ); } diff --git a/sw/source/core/fields/ddetbl.cxx b/sw/source/core/fields/ddetbl.cxx index 7324c24c5db9..816abd07cae7 100644 --- a/sw/source/core/fields/ddetbl.cxx +++ b/sw/source/core/fields/ddetbl.cxx @@ -85,7 +85,7 @@ SwDDETable::~SwDDETable() void SwDDETable::SwClientNotify(const SwModify& rModify, const SfxHint& rHint) { - if (rHint.GetId() == SfxHintId::SwLegacyModify) + if (rHint.GetId() == SfxHintId::SwLegacyModify || rHint.GetId() == SfxHintId::SwAutoFormatUsedHint) { SwTable::SwClientNotify(rModify, rHint); } diff --git a/sw/source/core/fields/docufld.cxx b/sw/source/core/fields/docufld.cxx index 4c3f928ec910..6ff655cfa4b6 100644 --- a/sw/source/core/fields/docufld.cxx +++ b/sw/source/core/fields/docufld.cxx @@ -157,8 +157,9 @@ void SwPageNumberFieldType::ChangeExpansion( SwDoc* pDoc, } else if( dynamic_cast< const SwFormat* >(pDesc->GetDefinedIn()) != nullptr) { - SwAutoFormatGetDocNode aGetHt( &pDoc->GetNodes() ); - m_bVirtual = !pDesc->GetDefinedIn()->GetInfo( aGetHt ); + m_bVirtual = false; + sw::AutoFormatUsedHint aHint(m_bVirtual, pDoc->GetNodes()); + pDesc->GetDefinedIn()->CallSwClientNotify(aHint); break; } } diff --git a/sw/source/core/inc/flyfrm.hxx b/sw/source/core/inc/flyfrm.hxx index 6083fd67d266..d1f14591bc2f 100644 --- a/sw/source/core/inc/flyfrm.hxx +++ b/sw/source/core/inc/flyfrm.hxx @@ -170,9 +170,6 @@ protected: public: // #i26791# - - // get client information - virtual bool GetInfo( SfxPoolItem& ) const override; virtual void PaintSwFrame( vcl::RenderContext& rRenderContext, SwRect const&, SwPrintData const*const pPrintData = nullptr ) const override; virtual Size ChgSize( const Size& aNewSize ) override; diff --git a/sw/source/core/inc/pagefrm.hxx b/sw/source/core/inc/pagefrm.hxx index 237544ec6e05..54458032f188 100644 --- a/sw/source/core/inc/pagefrm.hxx +++ b/sw/source/core/inc/pagefrm.hxx @@ -181,9 +181,6 @@ public: virtual bool GetModelPositionForViewPoint( SwPosition *, Point&, SwCursorMoveState* = nullptr, bool bTestBackground = false ) const override; - /// Get info from Client - virtual bool GetInfo( SfxPoolItem& ) const override; - virtual void Cut() override; virtual void Paste( SwFrame* pParent, SwFrame* pSibling = nullptr ) override; virtual void CheckDirection( bool bVert ) override; diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx index 5ee8ab91d2bb..3f8ed0d1833c 100644 --- a/sw/source/core/layout/atrfrm.cxx +++ b/sw/source/core/layout/atrfrm.cxx @@ -678,7 +678,12 @@ SwFormatPageDesc* SwFormatPageDesc::Clone( SfxItemPool* ) const void SwFormatPageDesc::SwClientNotify(const SwModify&, const SfxHint& rHint) { - if (const SwPageDescHint* pHint = dynamic_cast<const SwPageDescHint*>(&rHint)) + if(rHint.GetId() == SfxHintId::SwAutoFormatUsedHint) + { + if(GetRegisteredIn()) + static_cast<const sw::AutoFormatUsedHint&>(rHint).SetUsed(); //TODO: recheck if this is really the right way to check for use + } + else if (const SwPageDescHint* pHint = dynamic_cast<const SwPageDescHint*>(&rHint)) { // mba: shouldn't that be broadcasted also? SwFormatPageDesc aDfltDesc(pHint->GetPageDesc()); @@ -1760,7 +1765,7 @@ bool SwFormatAnchor::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) case text::TextContentAnchorType_AT_PARAGRAPH: eAnchor = RndStdIds::FLY_AT_PARA; break; - default: + default: eAnchor = RndStdIds::FLY_AT_PARA; // just to keep some compilers happy assert(false); } diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx index f00b97aa31e1..04fc8fb823d8 100644 --- a/sw/source/core/layout/fly.cxx +++ b/sw/source/core/layout/fly.cxx @@ -844,6 +844,12 @@ void SwFlyFrame::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) // #i87645# - reset flags for the layout process (only if something has been invalidated) ResetLayoutProcessBools(); } + else if (rHint.GetId() == SfxHintId::SwAutoFormatUsedHint) + { + // There's a FlyFrame, so use it + static_cast<const sw::AutoFormatUsedHint&>(rHint).SetUsed(); + return; + } else if (rHint.GetId() == SfxHintId::SwGetZOrder) { auto pGetZOrdnerHint = static_cast<const sw::GetZOrderHint*>(&rHint); @@ -1214,14 +1220,6 @@ void SwFlyFrame::UpdateAttr_( const SfxPoolItem *pOld, const SfxPoolItem *pNew, } } -/// Gets information from the Modify -bool SwFlyFrame::GetInfo( SfxPoolItem & rInfo ) const -{ - if( RES_AUTOFMT_DOCNODE == rInfo.Which() ) - return false; // There's a FlyFrame, so use it - return true; // Continue searching -} - void SwFlyFrame::Invalidate_( SwPageFrame const *pPage ) { InvalidatePage( pPage ); diff --git a/sw/source/core/layout/flyincnt.cxx b/sw/source/core/layout/flyincnt.cxx index 2455f7a6d130..7fb8f93f1635 100644 --- a/sw/source/core/layout/flyincnt.cxx +++ b/sw/source/core/layout/flyincnt.cxx @@ -94,6 +94,12 @@ void SwFlyInContentFrame::SetRefPoint( const Point& rPoint, void SwFlyInContentFrame::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) { + if (rHint.GetId() == SfxHintId::SwAutoFormatUsedHint) + { + // There's a FlyFrame, so use it + static_cast<const sw::AutoFormatUsedHint&>(rHint).SetUsed(); + return; + } if (rHint.GetId() != SfxHintId::SwLegacyModify) return; auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); diff --git a/sw/source/core/layout/flylay.cxx b/sw/source/core/layout/flylay.cxx index 8c40a22fe0cd..e507e92e6dcd 100644 --- a/sw/source/core/layout/flylay.cxx +++ b/sw/source/core/layout/flylay.cxx @@ -737,6 +737,12 @@ void SwFlyLayFrame::RegisterAtPage(SwPageFrame & rPageFrame) void SwFlyLayFrame::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) { + if (rHint.GetId() == SfxHintId::SwAutoFormatUsedHint) + { + // There's a FlyFrame, so use it + static_cast<const sw::AutoFormatUsedHint&>(rHint).SetUsed(); + return; + } if (rHint.GetId() != SfxHintId::SwLegacyModify) return; auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); diff --git a/sw/source/core/layout/pagechg.cxx b/sw/source/core/layout/pagechg.cxx index dd3132fdf206..e70cb6846981 100644 --- a/sw/source/core/layout/pagechg.cxx +++ b/sw/source/core/layout/pagechg.cxx @@ -526,6 +526,12 @@ void SwPageFrame::SwClientNotify(const SwModify& rModify, const SfxHint& rHint) // here, the page might be destroyed: static_cast<SwRootFrame*>(GetUpper())->RemoveFootnotes(nullptr, false, true); } + else if (rHint.GetId() == SfxHintId::SwAutoFormatUsedHint) + { + // a page frame exists, so use this one + static_cast<const sw::AutoFormatUsedHint&>(rHint).SetUsed(); + return; + } else if (rHint.GetId() == SfxHintId::SwLegacyModify) { auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); @@ -734,17 +740,6 @@ void SwPageFrame::UpdateAttr_( const SfxPoolItem *pOld, const SfxPoolItem *pNew, } } -/// get information from Modify -bool SwPageFrame::GetInfo( SfxPoolItem & rInfo ) const -{ - if( RES_AUTOFMT_DOCNODE == rInfo.Which() ) - { - // a page frame exists, so use this one - return false; - } - return true; // continue searching -} - void SwPageFrame::SetPageDesc( SwPageDesc *pNew, SwFrameFormat *pFormat ) { m_pDesc = pNew; diff --git a/sw/source/core/layout/pagedesc.cxx b/sw/source/core/layout/pagedesc.cxx index d93b47517e5b..edfee20aaef6 100644 --- a/sw/source/core/layout/pagedesc.cxx +++ b/sw/source/core/layout/pagedesc.cxx @@ -297,6 +297,13 @@ void SwPageDesc::SwClientNotify(const SwModify& rModify, const SfxHint& rHint) || (RES_PARATR_LINESPACING == nWhich)) RegisterChange(); } + else if(rHint.GetId() == SfxHintId::SwAutoFormatUsedHint) + { + m_Master.SwClientNotify(rModify, rHint); + m_Left.SwClientNotify(rModify, rHint); + m_FirstMaster.SwClientNotify(rModify, rHint); + m_FirstLeft.SwClientNotify(rModify, rHint); + } else if (auto pModifyChangedHint = dynamic_cast<const sw::ModifyChangedHint*>(&rHint)) { if(m_pTextFormatColl == &rModify) diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx index c111a86ccd58..f42b9ad95ce5 100644 --- a/sw/source/core/table/swtable.cxx +++ b/sw/source/core/table/swtable.cxx @@ -324,6 +324,11 @@ static void lcl_ModifyBoxes( SwTableBoxes &rBoxes, const tools::Long nOld, void SwTable::SwClientNotify(const SwModify&, const SfxHint& rHint) { + if(rHint.GetId() == SfxHintId::SwAutoFormatUsedHint) { + auto& rAutoFormatUsedHint = static_cast<const sw::AutoFormatUsedHint&>(rHint); + rAutoFormatUsedHint.CheckNode(GetTableNode()); + return; + } if (rHint.GetId() != SfxHintId::SwLegacyModify) return; auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); @@ -2279,11 +2284,6 @@ bool SwTable::GetInfo( SfxPoolItem& rInfo ) const { switch( rInfo.Which() ) { - case RES_AUTOFMT_DOCNODE: - { - const SwTableNode* pNode = GetTableNode(); - return !(pNode && &pNode->GetNodes() == static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes); - } case RES_FINDNEARESTNODE: if( GetFrameFormat() && GetFrameFormat()->GetFormatAttr( RES_PAGEDESC ).GetPageDesc() && diff --git a/sw/source/core/txtnode/atrfld.cxx b/sw/source/core/txtnode/atrfld.cxx index a9b98554f74b..47e78ce2c95d 100644 --- a/sw/source/core/txtnode/atrfld.cxx +++ b/sw/source/core/txtnode/atrfld.cxx @@ -222,7 +222,12 @@ void SwFormatField::InvalidateField() void SwFormatField::SwClientNotify( const SwModify& rModify, const SfxHint& rHint ) { SwClient::SwClientNotify(rModify, rHint); - if (rHint.GetId() == SfxHintId::SwField) + if (rHint.GetId() == SfxHintId::SwAutoFormatUsedHint) { + if(mpTextField) + static_cast<const sw::AutoFormatUsedHint&>(rHint).CheckNode(mpTextField->GetpTextNode()); + return; + } + else if (rHint.GetId() == SfxHintId::SwField) { const auto pFieldHint = static_cast<const SwFieldHint*>( &rHint ); // replace field content by text @@ -449,15 +454,6 @@ void SwFormatField::UpdateTextNode(const SfxHint& rHint) mpTextField->ExpandTextField(false); } -bool SwFormatField::GetInfo( SfxPoolItem& rInfo ) const -{ - if( RES_AUTOFMT_DOCNODE != rInfo.Which() || !mpTextField ) - return true; - const SwTextNode* pTextNd = mpTextField->GetpTextNode(); - return nullptr == pTextNd || - &pTextNd->GetNodes() != static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes; -} - bool SwFormatField::IsFieldInDoc() const { return mpTextField != nullptr diff --git a/sw/source/core/txtnode/fmtatr2.cxx b/sw/source/core/txtnode/fmtatr2.cxx index 2e5a562e0690..367658e84456 100644 --- a/sw/source/core/txtnode/fmtatr2.cxx +++ b/sw/source/core/txtnode/fmtatr2.cxx @@ -87,6 +87,12 @@ SwFormatCharFormat* SwFormatCharFormat::Clone( SfxItemPool* ) const // forward to the TextAttribute void SwFormatCharFormat::SwClientNotify(const SwModify&, const SfxHint& rHint) { + if(rHint.GetId() == SfxHintId::SwAutoFormatUsedHint) + { + if(m_pTextAttribute) + m_pTextAttribute->HandleAutoFormatUsedHint(static_cast<const sw::AutoFormatUsedHint&>(rHint)); + return; + } if (rHint.GetId() != SfxHintId::SwLegacyModify) return; auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); @@ -94,11 +100,6 @@ void SwFormatCharFormat::SwClientNotify(const SwModify&, const SfxHint& rHint) m_pTextAttribute->TriggerNodeUpdate(*pLegacy); } -// forward to the TextAttribute -bool SwFormatCharFormat::GetInfo( SfxPoolItem& rInfo ) const -{ - return m_pTextAttribute && m_pTextAttribute->GetInfo( rInfo ); -} bool SwFormatCharFormat::QueryValue( uno::Any& rVal, sal_uInt8 ) const { OUString sCharFormatName; diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index 19a2bffbf562..10a4209356a3 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -5514,7 +5514,12 @@ void SwTextNode::TriggerNodeUpdate(const sw::LegacyModifyHint& rHint) void SwTextNode::SwClientNotify( const SwModify& rModify, const SfxHint& rHint ) { - if (rHint.GetId() == SfxHintId::SwLegacyModify) + if(rHint.GetId() == SfxHintId::SwAutoFormatUsedHint) + { + static_cast<const sw::AutoFormatUsedHint&>(rHint).CheckNode(this); + return; + } + else if (rHint.GetId() == SfxHintId::SwLegacyModify) { auto pLegacyHint = static_cast<const sw::LegacyModifyHint*>(&rHint); TriggerNodeUpdate(*pLegacyHint); diff --git a/sw/source/core/txtnode/txtatr2.cxx b/sw/source/core/txtnode/txtatr2.cxx index 2b51b45ffbec..cc150fc1843a 100644 --- a/sw/source/core/txtnode/txtatr2.cxx +++ b/sw/source/core/txtnode/txtatr2.cxx @@ -34,6 +34,26 @@ #include <IDocumentStylePoolAccess.hxx> +namespace { + +bool lcl_CheckAutoFormatHint(const SfxHint& rHint) +{ + if (rHint.GetId() != SfxHintId::SwAutoFormatUsedHint) + return false; + auto& rAutoFormatUsed = static_cast<const sw::AutoFormatUsedHint&>(rHint); + rAutoFormatUsed.SetUsed(); + return true; +} +bool lcl_CheckAutoFormatHint(const SfxHint& rHint, const SwTextNode* pTextNode) +{ + if (rHint.GetId() != SfxHintId::SwAutoFormatUsedHint) + return false; + auto& rAutoFormatUsed = static_cast<const sw::AutoFormatUsedHint&>(rHint); + rAutoFormatUsed.CheckNode(pTextNode); + return true; +} +} + SwTextCharFormat::SwTextCharFormat( SwFormatCharFormat& rAttr, sal_Int32 nStt, sal_Int32 nEnd ) : SwTextAttr( rAttr, nStt ) @@ -68,10 +88,9 @@ void SwTextCharFormat::TriggerNodeUpdate(const sw::LegacyModifyHint& rHint) } } -bool SwTextCharFormat::GetInfo( SfxPoolItem const & rInfo ) const +void SwTextCharFormat::HandleAutoFormatUsedHint(const sw::AutoFormatUsedHint& rHint) { - return RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTextNode || - &m_pTextNode->GetNodes() != static_cast<SwAutoFormatGetDocNode const &>(rInfo).pNodes; + rHint.CheckNode(m_pTextNode); } SwTextAttrNesting::SwTextAttrNesting( SfxPoolItem & i_rAttr, @@ -151,6 +170,9 @@ SwCharFormat* SwTextINetFormat::GetCharFormat() void SwTextINetFormat::SwClientNotify(const SwModify&, const SfxHint& rHint) { + if(lcl_CheckAutoFormatHint(rHint)) + return; + if (rHint.GetId() != SfxHintId::SwLegacyModify) return; auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); @@ -165,12 +187,6 @@ void SwTextINetFormat::SwClientNotify(const SwModify&, const SfxHint& rHint) m_pTextNode->TriggerNodeUpdate(sw::LegacyModifyHint(&aUpdateAttr, &aUpdateAttr)); } -bool SwTextINetFormat::GetInfo( SfxPoolItem& rInfo ) const -{ - return RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTextNode || - &m_pTextNode->GetNodes() != static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes; -} - bool SwTextINetFormat::IsProtect( ) const { return m_pTextNode && m_pTextNode->IsProtect(); @@ -192,6 +208,8 @@ SwTextRuby::~SwTextRuby() void SwTextRuby::SwClientNotify(const SwModify&, const SfxHint& rHint) { + if(lcl_CheckAutoFormatHint(rHint, m_pTextNode)) + return; if (rHint.GetId() != SfxHintId::SwLegacyModify) return; auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); @@ -206,12 +224,6 @@ void SwTextRuby::SwClientNotify(const SwModify&, const SfxHint& rHint) m_pTextNode->TriggerNodeUpdate(sw::LegacyModifyHint(&aUpdateAttr, &aUpdateAttr)); } -bool SwTextRuby::GetInfo( SfxPoolItem& rInfo ) const -{ - return RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTextNode || - &m_pTextNode->GetNodes() != static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes; -} - SwCharFormat* SwTextRuby::GetCharFormat() { const SwFormatRuby& rFormat = SwTextAttrEnd::GetRuby(); diff --git a/sw/source/core/unocore/unocoll.cxx b/sw/source/core/unocore/unocoll.cxx index 65e70846470f..3f412181d470 100644 --- a/sw/source/core/unocore/unocoll.cxx +++ b/sw/source/core/unocore/unocoll.cxx @@ -863,29 +863,25 @@ sal_Int32 SwXTextTables::getCount() uno::Any SAL_CALL SwXTextTables::getByIndex(sal_Int32 nInputIndex) { SolarMutexGuard aGuard; - uno::Any aRet; if (!IsValid()) throw uno::RuntimeException(); if (nInputIndex < 0) throw IndexOutOfBoundsException(); - SwAutoFormatGetDocNode aGetHt( &GetDoc()->GetNodes() ); size_t nIndex = static_cast<size_t>(nInputIndex); - size_t nCurrentIndex = 0; - for(SwTableFormat* pFormat: *GetDoc()->GetTableFrameFormats()) { - if (!pFormat->GetInfo(aGetHt)) + if(!pFormat->IsUsed()) + continue; + if(nIndex) + --nIndex; + else { - if (nCurrentIndex == nIndex) - { - uno::Reference<XTextTable> xTable = SwXTextTables::GetObject(*pFormat); - aRet <<= xTable; - return aRet; - } - else - nCurrentIndex++; + uno::Reference<XTextTable> xTable = SwXTextTables::GetObject(*pFormat); + uno::Any aRet; + aRet <<= xTable; + return aRet; } } throw IndexOutOfBoundsException(); diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index e480d6fc1d07..184a931e798b 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -4457,18 +4457,15 @@ sal_Bool SAL_CALL SwXTextTableStyle::isInUse() if (!m_bPhysical) return false; - SwAutoFormatGetDocNode aGetHt( &m_pDocShell->GetDoc()->GetNodes() ); - for (const SwTableFormat* pFormat : *m_pDocShell->GetDoc()->GetTableFrameFormats()) { - if (!pFormat->GetInfo(aGetHt)) + if(pFormat->IsUsed()) { SwTable* pTable = SwTable::FindTable(pFormat); - if (pTable->GetTableStyleName() == m_pTableAutoFormat->GetName()) + if(pTable->GetTableStyleName() == m_pTableAutoFormat->GetName()) return true; } } - return false; } diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx index d2c69794e9e2..1bc5bfe2e4d8 100644 --- a/sw/source/uibase/utlui/content.cxx +++ b/sw/source/uibase/utlui/content.cxx @@ -497,11 +497,10 @@ void SwContentType::FillMemberList(bool* pbContentChanged) { const size_t nCount = m_pWrtShell->GetTableFrameFormatCount(true); const sw::TableFrameFormats* pFrameFormats = m_pWrtShell->GetDoc()->GetTableFrameFormats(); - SwAutoFormatGetDocNode aGetHt(&m_pWrtShell->GetNodes()); for(size_t n = 0, i = 0; i < nCount + n; ++i) { const SwTableFormat& rTableFormat = *(*pFrameFormats)[i]; - if (rTableFormat.GetInfo(aGetHt)) // skip deleted tables + if(!rTableFormat.IsUsed()) // skip deleted tables { n++; continue; @@ -5791,11 +5790,10 @@ void SwContentTree::BringEntryToAttention(const weld::TreeIter& rEntry) std::vector<const SwNode*> aNodesArr; const size_t nCount = m_pActiveShell->GetTableFrameFormatCount(false); const sw::TableFrameFormats& rTableFormats = *m_pActiveShell->GetDoc()->GetTableFrameFormats(); - SwAutoFormatGetDocNode aGetHt(&m_pActiveShell->GetNodes()); for(size_t i = 0; i < nCount; ++i) { if (const SwTableFormat* pTableFormat = rTableFormats[i]) - if (!pTableFormat->GetInfo(aGetHt)) // skip deleted tables + if(pTableFormat->IsUsed()) // skip deleted tables { SwTable* pTable = SwTable::FindTable(pTableFormat); if (pTable)
