sw/source/core/inc/UndoAttribute.hxx | 11 +++--- sw/source/core/undo/unattr.cxx | 56 ++++++++++++++++------------------- 2 files changed, 32 insertions(+), 35 deletions(-)
New commits: commit ad7558404ddf9de224c3cd28b6dccfefb0d0ea80 Author: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> AuthorDate: Fri Sep 11 23:30:37 2020 +0200 Commit: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> CommitDate: Sun Sep 13 10:51:15 2020 +0200 SwUndoFormatAttrHelper: tweak out some SwClient stuff ... - make it final for starters - dont use GetRegistered() variants to prepare removal of SwClient/SwModify - dont use CheckRegistration() as the observed format should never die Change-Id: I9bfb587e5e88896eb36d2da6edcf4f41a93195cd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102500 Tested-by: Jenkins Reviewed-by: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> diff --git a/sw/source/core/inc/UndoAttribute.hxx b/sw/source/core/inc/UndoAttribute.hxx index cc73197fd7c6..35247cf4d16f 100644 --- a/sw/source/core/inc/UndoAttribute.hxx +++ b/sw/source/core/inc/UndoAttribute.hxx @@ -160,19 +160,20 @@ public: }; // helper class to receive changed attribute sets -class SwUndoFormatAttrHelper : public SwClient +class SwUndoFormatAttrHelper final : public SwClient { + SwFormat& m_rFormat; std::unique_ptr<SwUndoFormatAttr> m_pUndo; const bool m_bSaveDrawPt; public: - SwUndoFormatAttrHelper( SwFormat& rFormat, bool bSaveDrawPt = true ); + SwUndoFormatAttrHelper(SwFormat& rFormat, bool bSaveDrawPt = true); - virtual void Modify( const SfxPoolItem*, const SfxPoolItem* ) override; + virtual void SwClientNotify(const SwModify&, const SfxHint&) override; - SwUndoFormatAttr* GetUndo() const { return m_pUndo.get(); } + SwUndoFormatAttr* GetUndo() const { return m_pUndo.get(); } // release the undo object (so it is not deleted here), and return it - std::unique_ptr<SwUndoFormatAttr> ReleaseUndo() { return std::move(m_pUndo); } + std::unique_ptr<SwUndoFormatAttr> ReleaseUndo() { return std::move(m_pUndo); } }; class SwUndoMoveLeftMargin : public SwUndo, private SwUndRng diff --git a/sw/source/core/undo/unattr.cxx b/sw/source/core/undo/unattr.cxx index 715de15ef295..905c55d97243 100644 --- a/sw/source/core/undo/unattr.cxx +++ b/sw/source/core/undo/unattr.cxx @@ -54,40 +54,36 @@ #include <calbck.hxx> #include <frameformats.hxx> -SwUndoFormatAttrHelper::SwUndoFormatAttrHelper( SwFormat& rFormat, bool bSvDrwPt ) - : SwClient( &rFormat ) - , m_bSaveDrawPt( bSvDrwPt ) +SwUndoFormatAttrHelper::SwUndoFormatAttrHelper(SwFormat& rFormat, bool bSvDrwPt) + : SwClient(&rFormat) + , m_rFormat(rFormat) + , m_bSaveDrawPt(bSvDrwPt) { } -void SwUndoFormatAttrHelper::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) +void SwUndoFormatAttrHelper::SwClientNotify(const SwModify&, const SfxHint& rHint) { - if( !pOld ) return; - - if ( pOld->Which() == RES_OBJECTDYING ) { - CheckRegistration( pOld ); - } else if ( pNew ) { - const SwDoc& rDoc = *static_cast<SwFormat*>(GetRegisteredInNonConst())->GetDoc(); - if( POOLATTR_END >= pOld->Which() ) { - if ( GetUndo() ) { - m_pUndo->PutAttr( *pOld, rDoc ); - } else { - m_pUndo.reset( new SwUndoFormatAttr( *pOld, - *static_cast<SwFormat*>(GetRegisteredInNonConst()), m_bSaveDrawPt ) ); - } - } else if ( RES_ATTRSET_CHG == pOld->Which() ) { - if ( GetUndo() ) { - SfxItemIter aIter( - *static_cast<const SwAttrSetChg*>(pOld)->GetChgSet() ); - for (auto pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem()) - { - m_pUndo->PutAttr( *pItem, rDoc ); - } - } else { - m_pUndo.reset( new SwUndoFormatAttr( - *static_cast<const SwAttrSetChg*>(pOld)->GetChgSet(), - *static_cast<SwFormat*>(GetRegisteredInNonConst()), m_bSaveDrawPt ) ); - } + auto pLegacy = dynamic_cast<const sw::LegacyModifyHint*>(&rHint); + if(!pLegacy || !pLegacy->m_pOld) + return; + assert(pLegacy->m_pOld->Which() != RES_OBJECTDYING); + if(!pLegacy->m_pNew) + return; + const SwDoc& rDoc = *m_rFormat.GetDoc(); + auto pOld = pLegacy->m_pOld; + if(POOLATTR_END >= pLegacy->m_pOld->Which()) { + if(!GetUndo()) + m_pUndo.reset(new SwUndoFormatAttr(*pOld, m_rFormat, m_bSaveDrawPt)); + else + m_pUndo->PutAttr(*pOld, rDoc); + } else if(RES_ATTRSET_CHG == pOld->Which()) { + auto& rChgSet = *static_cast<const SwAttrSetChg*>(pOld)->GetChgSet(); + if(!GetUndo()) + m_pUndo.reset(new SwUndoFormatAttr(rChgSet, m_rFormat, m_bSaveDrawPt)); + else { + SfxItemIter aIter(rChgSet); + for(auto pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem()) + m_pUndo->PutAttr(*pItem, rDoc); } } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits