compilerplugins/clang/unusedmethods.results | 2 include/svl/hint.hxx | 1 svl/source/items/poolitem.cxx | 1 sw/inc/hintids.hxx | 2 sw/inc/hints.hxx | 16 +- sw/inc/ndtxt.hxx | 8 + sw/source/core/attr/hints.cxx | 9 - sw/source/core/text/txtfrm.cxx | 62 +++++----- sw/source/core/txtnode/ndtxt.cxx | 161 ++++++++++++++++------------ sw/source/core/txtnode/txtedt.cxx | 3 10 files changed, 148 insertions(+), 117 deletions(-)
New commits: commit aace38f9bf702ecbe8de7cafc0979754eaa178c1 Author: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> AuthorDate: Sun Sep 18 12:46:01 2022 +0200 Commit: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> CommitDate: Sat Sep 24 18:28:07 2022 +0200 unwrap SwDelText to a plain SfxHint Change-Id: I559f8f1e837830426e820dace6226618c5e0fc62 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140210 Tested-by: Jenkins Reviewed-by: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> diff --git a/compilerplugins/clang/unusedmethods.results b/compilerplugins/clang/unusedmethods.results index 98c1d36bd64a..2624f69422ef 100644 --- a/compilerplugins/clang/unusedmethods.results +++ b/compilerplugins/clang/unusedmethods.results @@ -1594,8 +1594,6 @@ include/svl/typedwhich.hxx:31 TypedWhichId::TypedWhichId(TypedWhichId<type-parameter-?-?>,typename enable_if<std::is_base_of_v<SwCropGrf, derived_type>, int>::type) include/svl/typedwhich.hxx:31 TypedWhichId::TypedWhichId(TypedWhichId<type-parameter-?-?>,typename enable_if<std::is_base_of_v<SwDelChr, derived_type>, int>::type) -include/svl/typedwhich.hxx:31 - TypedWhichId::TypedWhichId(TypedWhichId<type-parameter-?-?>,typename enable_if<std::is_base_of_v<SwDelText, derived_type>, int>::type) include/svl/typedwhich.hxx:31 TypedWhichId::TypedWhichId(TypedWhichId<type-parameter-?-?>,typename enable_if<std::is_base_of_v<SwDocDisplayItem, derived_type>, int>::type) include/svl/typedwhich.hxx:31 diff --git a/include/svl/hint.hxx b/include/svl/hint.hxx index a5cbc1913e2e..b22e9c789f3f 100644 --- a/include/svl/hint.hxx +++ b/include/svl/hint.hxx @@ -140,6 +140,7 @@ enum class SfxHintId { SwGatherRefFields, SwGatherFields, SwNameChanged, // this can possibly be replaced by the generic NameChanged above + SwDeleteText, ThisIsAnSdrHint }; diff --git a/svl/source/items/poolitem.cxx b/svl/source/items/poolitem.cxx index 205f75b89bcd..5aada9d9d08b 100644 --- a/svl/source/items/poolitem.cxx +++ b/svl/source/items/poolitem.cxx @@ -436,7 +436,6 @@ // class SwFormatChg: public SwMsgPoolItem // class SwInsText: public SwMsgPoolItem // class SwDelChr: public SwMsgPoolItem -// class SwDelText: public SwMsgPoolItem // class SwUpdateAttr : public SwMsgPoolItem // class SwRefMarkFieldUpdate : public SwMsgPoolItem // class SwDocPosUpdate : public SwMsgPoolItem diff --git a/sw/inc/hintids.hxx b/sw/inc/hintids.hxx index b4fddf911179..a2529f935d00 100644 --- a/sw/inc/hintids.hxx +++ b/sw/inc/hintids.hxx @@ -135,7 +135,6 @@ class SwTransparencyGrf; class SwFormatRuby; class SwInsText; class SwDelChr; -class SwDelText; class SwRefMarkFieldUpdate; class SwTableFormulaUpdate; class SwAutoFormatGetDocNode; @@ -426,7 +425,6 @@ constexpr TypedWhichId<SwFormatChg> RES_FMT_CHG(162); constexpr TypedWhichId<SwAttrSetChg> RES_ATTRSET_CHG(163); constexpr TypedWhichId<SwInsText> RES_INS_TXT(164); constexpr TypedWhichId<SwDelChr> RES_DEL_CHR(165); -constexpr TypedWhichId<SwDelText> RES_DEL_TXT(166); constexpr TypedWhichId<SwUpdateAttr> RES_UPDATE_ATTR(167); constexpr TypedWhichId<SwRefMarkFieldUpdate> RES_REFMARKFLD_UPDATE(168); constexpr TypedWhichId<SwDocPosUpdate> RES_DOCPOS_UPDATE(169); diff --git a/sw/inc/hints.hxx b/sw/inc/hints.hxx index 8c15ed64ced6..63c25b90b4e0 100644 --- a/sw/inc/hints.hxx +++ b/sw/inc/hints.hxx @@ -95,14 +95,6 @@ public: SwDelChr( sal_Int32 nP ); }; -class SwDelText final : public SwMsgPoolItem -{ -public: - sal_Int32 nStart; - sal_Int32 nLen; - - SwDelText( sal_Int32 nS, sal_Int32 nL ); -}; namespace sw { @@ -118,6 +110,14 @@ public: MoveText(SwTextNode *pD, sal_Int32 nD, sal_Int32 nS, sal_Int32 nL); }; +class DeleteText final : public SfxHint +{ +public: + sal_Int32 nStart; + sal_Int32 nLen; + + DeleteText( sal_Int32 nS, sal_Int32 nL ); +}; /// new delete redline is created class RedlineDelText final : public SfxHint { diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx index feaa6c4c1bc2..3a2b4d65e41d 100644 --- a/sw/inc/ndtxt.hxx +++ b/sw/inc/ndtxt.hxx @@ -68,7 +68,11 @@ enum class ExpandMode; enum class SwFieldIds : sal_uInt16; class SwField; -namespace sw::mark { enum class RestoreMode; } +namespace sw { + class TextNodeNotificationSuppressor; + class DeleteText; + namespace mark { enum class RestoreMode; } +} namespace com::sun::star { namespace uno { @@ -90,6 +94,7 @@ class SW_DLLPUBLIC SwTextNode final friend class SwNodes; friend class SwTextFrame; friend class SwScriptInfo; + friend class sw::TextNodeNotificationSuppressor; /** May be 0. It is only then not 0 if it contains hard attributes. Therefore: never access directly! */ @@ -216,6 +221,7 @@ public: public: using SwContentNode::GetAttr; + void HandleDeleteText(const sw::DeleteText&); /// for hanging TextFormatCollections somewhere else (Outline-Numbering!) void TriggerNodeUpdate(const sw::LegacyModifyHint&); diff --git a/sw/source/core/attr/hints.cxx b/sw/source/core/attr/hints.cxx index abcdd54fe076..bc686196a254 100644 --- a/sw/source/core/attr/hints.cxx +++ b/sw/source/core/attr/hints.cxx @@ -45,10 +45,6 @@ SwDelChr::SwDelChr( sal_Int32 nP ) { } -SwDelText::SwDelText( sal_Int32 nS, sal_Int32 nL ) - : SwMsgPoolItem( RES_DEL_TXT ), nStart( nS ), nLen( nL ) -{ -} namespace sw { @@ -57,6 +53,11 @@ MoveText::MoveText(SwTextNode *const pD, sal_Int32 const nD, sal_Int32 const nS, { } +DeleteText::DeleteText( sal_Int32 nS, sal_Int32 nL ) + : SfxHint( SfxHintId::SwDeleteText ), nStart( nS ), nLen( nL ) +{ +} + RedlineDelText::RedlineDelText(sal_Int32 const nS, sal_Int32 const nL) : nStart(nS), nLen(nL) { diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx index a34c57fbde5f..9eaad2150aac 100644 --- a/sw/source/core/text/txtfrm.cxx +++ b/sw/source/core/text/txtfrm.cxx @@ -1975,6 +1975,7 @@ void SwTextFrame::SwClientNotify(SwModify const& rModify, SfxHint const& rHint) SfxPoolItem const* pOld(nullptr); SfxPoolItem const* pNew(nullptr); sw::MoveText const* pMoveText(nullptr); + sw::DeleteText const* pDeleteText(nullptr); sw::RedlineDelText const* pRedlineDelText(nullptr); sw::RedlineUnDelText const* pRedlineUnDelText(nullptr); @@ -1986,6 +1987,10 @@ void SwTextFrame::SwClientNotify(SwModify const& rModify, SfxHint const& rHint) pNew = pHint->m_pNew; nWhich = pHint->GetWhich(); } + else if (rHint.GetId() == SfxHintId::SwDeleteText) + { + pDeleteText = static_cast<const sw::DeleteText*>(&rHint); + } else if (auto const pHt = dynamic_cast<sw::MoveText const*>(&rHint)) { pMoveText = pHt; @@ -2132,6 +2137,33 @@ void SwTextFrame::SwClientNotify(SwModify const& rModify, SfxHint const& rHint) // assert(!m_pMergedPara || !getRootFrame()->IsHideRedlines() || !pMoveText->pDestNode->getLayoutFrame(getRootFrame())); } } + else if (pDeleteText) + { + nPos = MapModelToView(&rNode, pDeleteText->nStart); + if (m_pMergedPara) + { // update merged before doing anything else + nLen = UpdateMergedParaForDelete(*m_pMergedPara, true, rNode, pDeleteText->nStart, pDeleteText->nLen); + } + else + { + nLen = TextFrameIndex(pDeleteText->nLen); + } + const sal_Int32 m = -pDeleteText->nLen; + if ((!m_pMergedPara || nLen) && IsIdxInside(nPos, nLen)) + { + if( !nLen ) + InvalidateSize(); + else + InvalidateRange( SwCharRange(nPos, TextFrameIndex(1)), m ); + } + lcl_SetWrong( *this, rNode, pDeleteText->nStart, m, true ); + if (nLen) + { + lcl_SetScriptInval( *this, nPos ); + bSetFieldsDirty = bRecalcFootnoteFlag = true; + lcl_ModifyOfst(*this, nPos, nLen, &o3tl::operator-<sal_Int32, Tag_TextFrameIndex>); + } + } else switch (nWhich) { case RES_LINENUMBER: @@ -2207,36 +2239,6 @@ void SwTextFrame::SwClientNotify(SwModify const& rModify, SfxHint const& rHint) } } break; - case RES_DEL_TXT: - { - sal_Int32 const nNPos = static_cast<const SwDelText*>(pNew)->nStart; - sal_Int32 const nNLen = static_cast<const SwDelText*>(pNew)->nLen; - nPos = MapModelToView(&rNode, nNPos); - if (m_pMergedPara) - { // update merged before doing anything else - nLen = UpdateMergedParaForDelete(*m_pMergedPara, true, rNode, nNPos, nNLen); - } - else - { - nLen = TextFrameIndex(nNLen); - } - const sal_Int32 m = -nNLen; - if ((!m_pMergedPara || nLen) && IsIdxInside(nPos, nLen)) - { - if( !nLen ) - InvalidateSize(); - else - InvalidateRange( SwCharRange(nPos, TextFrameIndex(1)), m ); - } - lcl_SetWrong( *this, rNode, nNPos, m, true ); - if (nLen) - { - lcl_SetScriptInval( *this, nPos ); - bSetFieldsDirty = bRecalcFootnoteFlag = true; - lcl_ModifyOfst(*this, nPos, nLen, &o3tl::operator-<sal_Int32, Tag_TextFrameIndex>); - } - } - break; case RES_UPDATE_ATTR: { const SwUpdateAttr* pNewUpdate = static_cast<const SwUpdateAttr*>(pNew); diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index b7e777ddb444..9e64257d3e3e 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -86,6 +86,23 @@ using namespace ::com::sun::star; typedef std::vector<SwTextAttr*> SwpHts; +namespace sw { + class TextNodeNotificationSuppressor { + SwTextNode& m_rNode; + bool m_bWasNotifiable; + public: + TextNodeNotificationSuppressor(SwTextNode& rNode) + : m_rNode(rNode) + , m_bWasNotifiable(rNode.m_bNotifiable) + { + m_rNode.m_bNotifiable = false; + } + ~TextNodeNotificationSuppressor() + { + m_rNode.m_bNotifiable = m_bWasNotifiable; + } + }; +} // unfortunately everyone can change Hints without ensuring order or the linking between them #ifdef DBG_UTIL @@ -189,34 +206,35 @@ SwTextNode::SwTextNode( SwNode& rWhere, SwTextFormatColl *pTextColl, const SfxIt m_bHiddenCharsHidePara(false), m_bRecalcHiddenCharFlags(false), m_bLastOutlineState( false ), - m_bNotifiable( false ), + m_bNotifiable( true ), mbEmptyListStyleSetDueToSetOutlineLevelAttr( false ), mbInSetOrResetAttr( false ), m_bInUndo(false) { - InitSwParaStatistics( true ); + { + sw::TextNodeNotificationSuppressor(*this); + InitSwParaStatistics( true ); - if( pAutoAttr ) - SetAttr( *pAutoAttr ); + if( pAutoAttr ) + SetAttr( *pAutoAttr ); - if (!IsInList() && GetNumRule() && !GetListId().isEmpty()) - { - // #i101516# - // apply paragraph style's assigned outline style list level as - // list level of the paragraph, if it has none set already. - if ( !HasAttrListLevel() && - pTextColl && pTextColl->IsAssignedToListLevelOfOutlineStyle() ) + if (!IsInList() && GetNumRule() && !GetListId().isEmpty()) { - SetAttrListLevel( pTextColl->GetAssignedOutlineStyleLevel() ); + // #i101516# + // apply paragraph style's assigned outline style list level as + // list level of the paragraph, if it has none set already. + if ( !HasAttrListLevel() && + pTextColl && pTextColl->IsAssignedToListLevelOfOutlineStyle() ) + { + SetAttrListLevel( pTextColl->GetAssignedOutlineStyleLevel() ); + } + AddToList(); } - AddToList(); - } - - // call method <UpdateOutlineNode(..)> only for the document nodes array - if (GetNodes().IsDocNodes()) - GetNodes().UpdateOutlineNode(*this); - m_bNotifiable = true; + // call method <UpdateOutlineNode(..)> only for the document nodes array + if (GetNodes().IsDocNodes()) + GetNodes().UpdateOutlineNode(*this); + } m_bContainsHiddenChars = m_bHiddenCharsHidePara = false; m_bRecalcHiddenCharFlags = true; @@ -2572,8 +2590,7 @@ void SwTextNode::CutImpl( SwTextNode * const pDest, const SwContentIndex & rDest pDest->TriggerNodeUpdate(sw::LegacyModifyHint(nullptr, &aInsHint)); const sw::MoveText aMoveHint(pDest, nDestStart, nTextStartIdx, nLen); CallSwClientNotify(aMoveHint); - const SwDelText aDelHint(nTextStartIdx, nLen); - TriggerNodeUpdate(sw::LegacyModifyHint(nullptr, &aDelHint)); + HandleDeleteText(sw::DeleteText(nTextStartIdx, nLen)); // 2. move attributes // Iterate over attribute array until the start of the attribute @@ -2808,8 +2825,7 @@ void SwTextNode::EraseText(const SwContentIndex &rIdx, const sal_Int32 nCount, } else { - SwDelText aHint( nStartIdx, nCnt ); - CallSwClientNotify(sw::LegacyModifyHint(nullptr, &aHint)); + CallSwClientNotify(sw::DeleteText(nStartIdx, nCnt)); } OSL_ENSURE(rIdx.GetIndex() == nStartIdx, "huh? start index has changed?"); @@ -3815,8 +3831,7 @@ void SwTextNode::ReplaceText( const SwContentIndex& rStart, const sal_Int32 nDel } SetIgnoreDontExpand( bOldExpFlg ); - SwDelText aDelHint( nStartPos, nDelLen ); - CallSwClientNotify(sw::LegacyModifyHint(nullptr, &aDelHint)); + CallSwClientNotify(sw::DeleteText(nStartPos, nDelLen)); if (sInserted.getLength()) { @@ -5366,67 +5381,79 @@ bool SwTextNode::IsInContent() const return !GetDoc().IsInHeaderFooter( *this ); } -void SwTextNode::TriggerNodeUpdate(const sw::LegacyModifyHint& rHint) +void SwTextNode::HandleDeleteText(const sw::DeleteText& rHint) { - const auto pOldValue = rHint.m_pOld; - const auto pNewValue = rHint.m_pNew; - bool bWasNotifiable = m_bNotifiable; - m_bNotifiable = false; + sw::TextNodeNotificationSuppressor(*this); + CallSwClientNotify(rHint); - // Override Modify so that deleting styles works properly (outline - // numbering!). - // Never call ChgTextCollUpdateNum for Nodes in Undo. - if( pOldValue - && pNewValue - && RES_FMT_CHG == pOldValue->Which() - && GetRegisteredIn() == static_cast<const SwFormatChg*>(pNewValue)->pChangedFormat - && GetNodes().IsDocNodes() ) + SwDoc& rDoc = GetDoc(); + // #125329# - assure that text node is in document nodes array + if ( !rDoc.IsInDtor() && &rDoc.GetNodes() == &GetNodes() ) { - assert(dynamic_cast<SwTextFormatColl const*>(static_cast<const SwFormatChg*>(pOldValue)->pChangedFormat)); - assert(dynamic_cast<SwTextFormatColl const*>(static_cast<const SwFormatChg*>(pNewValue)->pChangedFormat)); - ChgTextCollUpdateNum( - static_cast<const SwTextFormatColl*>(static_cast<const SwFormatChg*>(pOldValue)->pChangedFormat), - static_cast<const SwTextFormatColl*>(static_cast<const SwFormatChg*>(pNewValue)->pChangedFormat) ); + rDoc.GetNodes().UpdateOutlineNode(*this); } +} - // reset fill information - if (maFillAttributes && pNewValue) +void SwTextNode::TriggerNodeUpdate(const sw::LegacyModifyHint& rHint) +{ + const auto pOldValue = rHint.m_pOld; + const auto pNewValue = rHint.m_pNew; { - const sal_uInt16 nWhich = pNewValue->Which(); - bool bReset(RES_FMT_CHG == nWhich); // ..on format change (e.g. style changed) + sw::TextNodeNotificationSuppressor(*this); - if(!bReset && RES_ATTRSET_CHG == nWhich) // ..on ItemChange from DrawingLayer FillAttributes + // Override Modify so that deleting styles works properly (outline + // numbering!). + // Never call ChgTextCollUpdateNum for Nodes in Undo. + if( pOldValue + && pNewValue + && RES_FMT_CHG == pOldValue->Which() + && GetRegisteredIn() == static_cast<const SwFormatChg*>(pNewValue)->pChangedFormat + && GetNodes().IsDocNodes() ) { - SfxItemIter aIter(*static_cast<const SwAttrSetChg*>(pNewValue)->GetChgSet()); + assert(dynamic_cast<SwTextFormatColl const*>(static_cast<const SwFormatChg*>(pOldValue)->pChangedFormat)); + assert(dynamic_cast<SwTextFormatColl const*>(static_cast<const SwFormatChg*>(pNewValue)->pChangedFormat)); + ChgTextCollUpdateNum( + static_cast<const SwTextFormatColl*>(static_cast<const SwFormatChg*>(pOldValue)->pChangedFormat), + static_cast<const SwTextFormatColl*>(static_cast<const SwFormatChg*>(pNewValue)->pChangedFormat) ); + } - for(const SfxPoolItem* pItem = aIter.GetCurItem(); pItem && !bReset; pItem = aIter.NextItem()) + // reset fill information + if (maFillAttributes && pNewValue) + { + const sal_uInt16 nWhich = pNewValue->Which(); + bool bReset(RES_FMT_CHG == nWhich); // ..on format change (e.g. style changed) + + if(!bReset && RES_ATTRSET_CHG == nWhich) // ..on ItemChange from DrawingLayer FillAttributes { - bReset = !IsInvalidItem(pItem) && pItem->Which() >= XATTR_FILL_FIRST && pItem->Which() <= XATTR_FILL_LAST; + SfxItemIter aIter(*static_cast<const SwAttrSetChg*>(pNewValue)->GetChgSet()); + + for(const SfxPoolItem* pItem = aIter.GetCurItem(); pItem && !bReset; pItem = aIter.NextItem()) + { + bReset = !IsInvalidItem(pItem) && pItem->Which() >= XATTR_FILL_FIRST && pItem->Which() <= XATTR_FILL_LAST; + } + } + + if(bReset) + { + maFillAttributes.reset(); } } - if(bReset) + if ( !mbInSetOrResetAttr ) { - maFillAttributes.reset(); + HandleModifyAtTextNode( *this, pOldValue, pNewValue ); } - } - if ( !mbInSetOrResetAttr ) - { - HandleModifyAtTextNode( *this, pOldValue, pNewValue ); - } + SwContentNode::SwClientNotify(*this, rHint); - SwContentNode::SwClientNotify(*this, rHint); - - SwDoc& rDoc = GetDoc(); - // #125329# - assure that text node is in document nodes array - if ( !rDoc.IsInDtor() && &rDoc.GetNodes() == &GetNodes() ) - { - rDoc.GetNodes().UpdateOutlineNode(*this); + SwDoc& rDoc = GetDoc(); + // #125329# - assure that text node is in document nodes array + if ( !rDoc.IsInDtor() && &rDoc.GetNodes() == &GetNodes() ) + { + rDoc.GetNodes().UpdateOutlineNode(*this); + } } - m_bNotifiable = bWasNotifiable; - if (pOldValue && (RES_REMOVE_UNO_OBJECT == pOldValue->Which())) { // invalidate cached uno object SetXParagraph(nullptr); diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx index 90bca7705239..97ae80b3d34e 100644 --- a/sw/source/core/txtnode/txtedt.cxx +++ b/sw/source/core/txtnode/txtedt.cxx @@ -2014,8 +2014,7 @@ void SwTextNode::ReplaceTextOnly( sal_Int32 nPos, sal_Int32 nLen, Update(SwContentIndex(this, nMyOff), nLen - nMyOff, UpdateMode::Negative); // notify the layout! - SwDelText aDelHint( nPos, nTLen ); - CallSwClientNotify(sw::LegacyModifyHint(nullptr, &aDelHint)); + CallSwClientNotify(sw::DeleteText(nPos, nTLen)); SwInsText const aHint(sw::MakeSwInsText(*this, nPos, nTLen)); CallSwClientNotify(sw::LegacyModifyHint(nullptr, &aHint));