diff options
author | Bjoern Michaelsen <bjoern.michaelsen@libreoffice.org> | 2020-12-06 12:34:41 +0100 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@libreoffice.org> | 2020-12-07 11:38:51 +0100 |
commit | 96f88e5964604d0ae481dcbd0080a48241c707c8 (patch) | |
tree | 3bbc5a8818bd40627be08e95fe5b4d8228650087 | |
parent | 8bf24518fcd6fab000edf193e0591b9bf0b9c152 (diff) |
SwFormat: Modify no more
Change-Id: I028e173a7148dfce946189a94aed8b93ff3539b0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107318
Tested-by: Jenkins
Reviewed-by: Bjoern Michaelsen <bjoern.michaelsen@libreoffice.org>
-rw-r--r-- | sw/inc/format.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/attr/format.cxx | 103 | ||||
-rw-r--r-- | sw/source/core/layout/atrfrm.cxx | 4 |
3 files changed, 58 insertions, 51 deletions
diff --git a/sw/inc/format.hxx b/sw/inc/format.hxx index 8a64b121e76c..e596a26bb882 100644 --- a/sw/inc/format.hxx +++ b/sw/inc/format.hxx @@ -67,7 +67,7 @@ protected: SwFormat( SwAttrPool& rPool, const OUString &rFormatNm, const sal_uInt16* pWhichRanges, SwFormat *pDrvdFrame, sal_uInt16 nFormatWhich ); SwFormat( const SwFormat& rFormat ); - virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNewValue ) override; + virtual void SwClientNotify(const SwModify&, const SfxHint&) override; public: diff --git a/sw/source/core/attr/format.cxx b/sw/source/core/attr/format.cxx index 1af9e993a35a..ddcf20638356 100644 --- a/sw/source/core/attr/format.cxx +++ b/sw/source/core/attr/format.cxx @@ -242,85 +242,92 @@ SwFormat::~SwFormat() } } -void SwFormat::Modify( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue ) +void SwFormat::SwClientNotify(const SwModify&, const SfxHint& rHint) { + auto pLegacy = dynamic_cast<const sw::LegacyModifyHint*>(&rHint); + if(!pLegacy) + return; + std::unique_ptr<SwAttrSetChg> pOldClientChg, pNewClientChg; - auto aDependArgs = std::pair<const SfxPoolItem*, const SfxPoolItem*>(pOldValue, pNewValue); + auto aDependArgs = std::pair<const SfxPoolItem*, const SfxPoolItem*>(pLegacy->m_pOld, pLegacy->m_pNew); bool bPassToDepends = true; - const sal_uInt16 nWhich = pOldValue ? pOldValue->Which() - : pNewValue ? pNewValue->Which() - : 0; - switch( nWhich ) + const sal_uInt16 nWhich = pLegacy->GetWhich(); + switch(nWhich) { - case 0: break; // Which-Id of 0? - - case RES_OBJECTDYING: - // NB: this still notifies depends even if pNewValue is nullptr, which seems non-obvious - if (pNewValue) + case 0: + break; + case RES_OBJECTDYING: { + // NB: this still notifies depends even if pLegacy->m_pNew is nullptr, which seems non-obvious + if(!pLegacy->m_pNew) + break; // If the dying object is the parent format of this format so // attach this to the parent of the parent - SwFormat* pFormat = static_cast<SwFormat*>(static_cast<const SwPtrMsgPoolItem*>(pNewValue)->pObject); + SwFormat* pFormat = static_cast<SwFormat*>(static_cast<const SwPtrMsgPoolItem*>(pLegacy->m_pNew)->pObject); // do not move if this is the topmost format - if( GetRegisteredIn() && GetRegisteredIn() == pFormat ) + if(GetRegisteredIn() && GetRegisteredIn() == pFormat) { - if( pFormat->GetRegisteredIn() ) + if(pFormat->GetRegisteredIn()) { // if parent so register in new parent - pFormat->DerivedFrom()->Add( this ); - m_aSet.SetParent( &DerivedFrom()->m_aSet ); + pFormat->DerivedFrom()->Add(this); + m_aSet.SetParent(&DerivedFrom()->m_aSet); } else { // otherwise de-register at least from dying one EndListeningAll(); - m_aSet.SetParent( nullptr ); + m_aSet.SetParent(nullptr); } } + break; } - break; - case RES_ATTRSET_CHG: - // NB: this still notifies depends even if this condition is not met, which seems non-obvious - if (pOldValue && pNewValue && static_cast<const SwAttrSetChg*>(pOldValue)->GetTheChgdSet() != &m_aSet) + case RES_ATTRSET_CHG: { - // pass only those that are not set... - pNewClientChg.reset( new SwAttrSetChg(*static_cast<const SwAttrSetChg*>(pNewValue)) ); - pNewClientChg->GetChgSet()->Differentiate( m_aSet ); - if(pNewClientChg->Count()) // ... if any + // NB: this still notifies depends even if this condition is not met, which seems non-obvious + auto pOldAttrSetChg = static_cast<const SwAttrSetChg*>(pLegacy->m_pOld); + auto pNewAttrSetChg = static_cast<const SwAttrSetChg*>(pLegacy->m_pNew); + if (pOldAttrSetChg && pNewAttrSetChg && pOldAttrSetChg->GetTheChgdSet() != &m_aSet) { - pOldClientChg.reset( new SwAttrSetChg(*static_cast<const SwAttrSetChg*>(pOldValue)) ); - pOldClientChg->GetChgSet()->Differentiate( m_aSet ); - aDependArgs = std::pair<const SfxPoolItem*, const SfxPoolItem*>(pOldClientChg.get(), pNewClientChg.get()); + // pass only those that are not set... + pNewClientChg.reset(new SwAttrSetChg(*pNewAttrSetChg)); + pNewClientChg->GetChgSet()->Differentiate(m_aSet); + if(pNewClientChg->Count()) // ... if any + { + pOldClientChg.reset(new SwAttrSetChg(*pOldAttrSetChg)); + pOldClientChg->GetChgSet()->Differentiate(m_aSet); + aDependArgs = std::pair<const SfxPoolItem*, const SfxPoolItem*>(pOldClientChg.get(), pNewClientChg.get()); + } + else + bPassToDepends = false; } - else - bPassToDepends = false; + break; } - break; - case RES_FMT_CHG: - // if the format parent will be moved so register my attribute set at - // the new one - - // skip my own Modify - // NB: this still notifies depends even if this condition is not met, which seems non-obvious - if ( pOldValue && pNewValue && - static_cast<const SwFormatChg*>(pOldValue)->pChangedFormat != this && - static_cast<const SwFormatChg*>(pNewValue)->pChangedFormat == GetRegisteredIn() ) + case RES_FMT_CHG: { - // attach Set to new parent - m_aSet.SetParent( DerivedFrom() ? &DerivedFrom()->m_aSet : nullptr ); + // if the format parent will be moved so register my attribute set at + // the new one + + // skip my own Modify + // NB: this still notifies depends even if this condition is not met, which seems non-obvious + auto pOldFormatChg = static_cast<const SwFormatChg*>(pLegacy->m_pOld); + auto pNewFormatChg = static_cast<const SwFormatChg*>(pLegacy->m_pNew); + if(pOldFormatChg && pNewFormatChg && pOldFormatChg->pChangedFormat != this && pNewFormatChg->pChangedFormat == GetRegisteredIn()) + { + // attach Set to new parent + m_aSet.SetParent(DerivedFrom() ? &DerivedFrom()->m_aSet : nullptr); + } + break; } - break; - default: - { + default: // attribute is defined in this format - if( SfxItemState::SET == m_aSet.GetItemState( nWhich, false )) + if(SfxItemState::SET == m_aSet.GetItemState(nWhich, false)) { // DropCaps might come into this block - OSL_ENSURE( RES_PARATR_DROP == nWhich, "Modify was sent without sender" ); + SAL_WARN_IF(RES_PARATR_DROP != nWhich, "sw.core", "Hint was sent without sender"); bPassToDepends = false; } - } } if(bPassToDepends) NotifyClients(aDependArgs.first, aDependArgs.second); diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx index 5e3d0b89e75c..5d9ffa3e3254 100644 --- a/sw/source/core/layout/atrfrm.cxx +++ b/sw/source/core/layout/atrfrm.cxx @@ -2546,7 +2546,7 @@ bool SwFrameFormat::supportsFullDrawingLayerFillAttributeSet() const return true; } -void SwFrameFormat::SwClientNotify(const SwModify&, const SfxHint& rHint) +void SwFrameFormat::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) { auto pLegacy = dynamic_cast<const sw::LegacyModifyHint*>(&rHint); if(!pLegacy) @@ -2639,7 +2639,7 @@ void SwFrameFormat::SwClientNotify(const SwModify&, const SfxHint& rHint) SwFrameFormat* pFormat = GetDoc()->getIDocumentLayoutAccess().MakeLayoutFormat(RndStdIds::FOOTER, nullptr); const_cast<SwFormatFooter*>(pF)->RegisterToFormat(*pFormat); } - SwFormat::Modify(pLegacy->m_pOld, pLegacy->m_pNew); + SwFormat::SwClientNotify(rMod, rHint); if(pOldAnchorPosition != nullptr && (pNewAnchorPosition == nullptr || pOldAnchorPosition->nNode.GetIndex() != pNewAnchorPosition->nNode.GetIndex())) pOldAnchorPosition->nNode.GetNode().RemoveAnchoredFly(this); if(pNewAnchorPosition != nullptr && (pOldAnchorPosition == nullptr || pOldAnchorPosition->nNode.GetIndex() != pNewAnchorPosition->nNode.GetIndex())) |