sw/source/core/undo/SwUndoFmt.cxx | 26 +- sw/source/core/undo/SwUndoPageDesc.cxx | 84 ++++---- sw/source/core/undo/rolbck.cxx | 326 ++++++++++++++++----------------- sw/source/core/undo/unattr.cxx | 72 +++---- sw/source/core/undo/undel.cxx | 66 +++--- sw/source/core/undo/undobj.cxx | 256 ++++++++++++------------- sw/source/core/undo/undobj1.cxx | 156 +++++++-------- sw/source/core/undo/undraw.cxx | 100 +++++----- sw/source/core/undo/unovwr.cxx | 36 +-- sw/source/core/undo/unsect.cxx | 62 +++--- sw/source/core/undo/unspnd.cxx | 54 ++--- sw/source/core/undo/untbl.cxx | 32 +-- sw/source/core/undo/untblk.cxx | 98 ++++----- 13 files changed, 684 insertions(+), 684 deletions(-)
New commits: commit 3b7daa4d28feaf2747c763a177e510b17d58ecb8 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu Jul 30 10:36:37 2020 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Jul 31 12:54:15 2020 +0200 loplugin:flatten in sw/core/undo Change-Id: I34662fd439578fc6f446c5216c5c1b735b79718d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99860 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/core/undo/SwUndoFmt.cxx b/sw/source/core/undo/SwUndoFmt.cxx index d0e3798aab82..bb9ffa75df98 100644 --- a/sw/source/core/undo/SwUndoFmt.cxx +++ b/sw/source/core/undo/SwUndoFmt.cxx @@ -43,22 +43,22 @@ SwUndoFormatCreate::~SwUndoFormatCreate() void SwUndoFormatCreate::UndoImpl(::sw::UndoRedoContext &) { - if (m_pNew) - { - if (m_sNewName.isEmpty()) - m_sNewName = m_pNew->GetName(); + if (!m_pNew) + return; + + if (m_sNewName.isEmpty()) + m_sNewName = m_pNew->GetName(); - if (!m_sNewName.isEmpty()) - m_pNew = Find(m_sNewName); + if (!m_sNewName.isEmpty()) + m_pNew = Find(m_sNewName); - if (m_pNew) - { - m_pNewSet = new SfxItemSet(m_pNew->GetAttrSet()); - m_nId = m_pNew->GetPoolFormatId() & COLL_GET_RANGE_BITS; - m_bAuto = m_pNew->IsAuto(); + if (m_pNew) + { + m_pNewSet = new SfxItemSet(m_pNew->GetAttrSet()); + m_nId = m_pNew->GetPoolFormatId() & COLL_GET_RANGE_BITS; + m_bAuto = m_pNew->IsAuto(); - Delete(); - } + Delete(); } } diff --git a/sw/source/core/undo/SwUndoPageDesc.cxx b/sw/source/core/undo/SwUndoPageDesc.cxx index 1ca66f9fb760..888f51328b62 100644 --- a/sw/source/core/undo/SwUndoPageDesc.cxx +++ b/sw/source/core/undo/SwUndoPageDesc.cxx @@ -69,56 +69,56 @@ SwUndoPageDesc::SwUndoPageDesc(const SwPageDesc & _aOld, m_bExchange = false; if( ( rOldHead.IsActive() || rOldFoot.IsActive() ) && ( rOldDesc.IsFirstShared() != rNewDesc.IsFirstShared() ) ) m_bExchange = false; - if( m_bExchange ) + if( !m_bExchange ) + return; + + if( rNewHead.IsActive() ) { - if( rNewHead.IsActive() ) + SwFrameFormat* pFormat = new SwFrameFormat( *rNewHead.GetHeaderFormat() ); + // The Ctor of this object will remove the duplicate! + SwFormatHeader aFormatHeader(pFormat); + (void)aFormatHeader; + if (!rNewDesc.IsHeaderShared()) { - SwFrameFormat* pFormat = new SwFrameFormat( *rNewHead.GetHeaderFormat() ); + pFormat = new SwFrameFormat( *rNewDesc.GetLeft().GetHeader().GetHeaderFormat() ); // The Ctor of this object will remove the duplicate! - SwFormatHeader aFormatHeader(pFormat); - (void)aFormatHeader; - if (!rNewDesc.IsHeaderShared()) - { - pFormat = new SwFrameFormat( *rNewDesc.GetLeft().GetHeader().GetHeaderFormat() ); - // The Ctor of this object will remove the duplicate! - SwFormatHeader aLeftHeader(pFormat); - (void)aLeftHeader; - } - if (!rNewDesc.IsFirstShared()) - { - pFormat = new SwFrameFormat( *rNewDesc.GetFirstMaster().GetHeader().GetHeaderFormat() ); - // The Ctor of this object will remove the duplicate! - SwFormatHeader aFirstHeader(pFormat); - (void)aFirstHeader; - } + SwFormatHeader aLeftHeader(pFormat); + (void)aLeftHeader; } - // Same procedure for footers... - if( rNewFoot.IsActive() ) + if (!rNewDesc.IsFirstShared()) { - SwFrameFormat* pFormat = new SwFrameFormat( *rNewFoot.GetFooterFormat() ); + pFormat = new SwFrameFormat( *rNewDesc.GetFirstMaster().GetHeader().GetHeaderFormat() ); // The Ctor of this object will remove the duplicate! - SwFormatFooter aFormatFooter(pFormat); - (void)aFormatFooter; - if (!rNewDesc.IsFooterShared()) - { - pFormat = new SwFrameFormat( *rNewDesc.GetLeft().GetFooter().GetFooterFormat() ); - // The Ctor of this object will remove the duplicate! - SwFormatFooter aLeftFooter(pFormat); - (void)aLeftFooter; - } - if (!rNewDesc.IsFirstShared()) - { - pFormat = new SwFrameFormat( *rNewDesc.GetFirstMaster().GetFooter().GetFooterFormat() ); - // The Ctor of this object will remove the duplicate! - SwFormatFooter aFirstFooter(pFormat); - (void)aFirstFooter; - } + SwFormatHeader aFirstHeader(pFormat); + (void)aFirstHeader; } - - // After this exchange method the old page description will point to zero, - // the new one will point to the node position of the original content nodes. - ExchangeContentNodes( m_aOld.m_PageDesc, m_aNew.m_PageDesc ); } + // Same procedure for footers... + if( rNewFoot.IsActive() ) + { + SwFrameFormat* pFormat = new SwFrameFormat( *rNewFoot.GetFooterFormat() ); + // The Ctor of this object will remove the duplicate! + SwFormatFooter aFormatFooter(pFormat); + (void)aFormatFooter; + if (!rNewDesc.IsFooterShared()) + { + pFormat = new SwFrameFormat( *rNewDesc.GetLeft().GetFooter().GetFooterFormat() ); + // The Ctor of this object will remove the duplicate! + SwFormatFooter aLeftFooter(pFormat); + (void)aLeftFooter; + } + if (!rNewDesc.IsFirstShared()) + { + pFormat = new SwFrameFormat( *rNewDesc.GetFirstMaster().GetFooter().GetFooterFormat() ); + // The Ctor of this object will remove the duplicate! + SwFormatFooter aFirstFooter(pFormat); + (void)aFirstFooter; + } + } + + // After this exchange method the old page description will point to zero, + // the new one will point to the node position of the original content nodes. + ExchangeContentNodes( m_aOld.m_PageDesc, m_aNew.m_PageDesc ); } SwUndoPageDesc::~SwUndoPageDesc() diff --git a/sw/source/core/undo/rolbck.cxx b/sw/source/core/undo/rolbck.cxx index 8806f4f690c3..dbc6675f568b 100644 --- a/sw/source/core/undo/rolbck.cxx +++ b/sw/source/core/undo/rolbck.cxx @@ -261,21 +261,21 @@ void SwHistorySetText::SetInDoc( SwDoc* pDoc, bool ) SwTextNode * pTextNd = pDoc->GetNodes()[ m_nNodeIndex ]->GetTextNode(); OSL_ENSURE( pTextNd, "SwHistorySetText::SetInDoc: not a TextNode" ); - if ( pTextNd ) + if ( !pTextNd ) + return; + + SwTextAttr *const pAttr = pTextNd->InsertItem(*m_pAttr, m_nStart, m_nEnd, + SetAttrMode::NOTXTATRCHR | + SetAttrMode::NOHINTADJUST ); + // shouldn't be possible to hit any error/merging path from here + assert(pAttr); + if (m_bFormatIgnoreStart) { - SwTextAttr *const pAttr = pTextNd->InsertItem(*m_pAttr, m_nStart, m_nEnd, - SetAttrMode::NOTXTATRCHR | - SetAttrMode::NOHINTADJUST ); - // shouldn't be possible to hit any error/merging path from here - assert(pAttr); - if (m_bFormatIgnoreStart) - { - pAttr->SetFormatIgnoreStart(true); - } - if (m_bFormatIgnoreEnd) - { - pAttr->SetFormatIgnoreEnd(true); - } + pAttr->SetFormatIgnoreStart(true); + } + if (m_bFormatIgnoreEnd) + { + pAttr->SetFormatIgnoreEnd(true); } } @@ -545,20 +545,20 @@ void SwHistoryChangeFormatColl::SetInDoc( SwDoc* pDoc, bool ) // before setting the format, check if it is still available in the // document. if it has been deleted, there is no undo! - if ( pContentNd && m_nNodeType == pContentNd->GetNodeType() ) + if ( !(pContentNd && m_nNodeType == pContentNd->GetNodeType()) ) + return; + + if ( SwNodeType::Text == m_nNodeType ) { - if ( SwNodeType::Text == m_nNodeType ) - { - if (pDoc->GetTextFormatColls()->IsAlive(static_cast<SwTextFormatColl *>(m_pColl))) - { - pContentNd->ChgFormatColl( m_pColl ); - } - } - else if (pDoc->GetGrfFormatColls()->IsAlive(static_cast<SwGrfFormatColl *>(m_pColl))) + if (pDoc->GetTextFormatColls()->IsAlive(static_cast<SwTextFormatColl *>(m_pColl))) { pContentNd->ChgFormatColl( m_pColl ); } } + else if (pDoc->GetGrfFormatColls()->IsAlive(static_cast<SwGrfFormatColl *>(m_pColl))) + { + pContentNd->ChgFormatColl( m_pColl ); + } } SwHistoryTextFlyCnt::SwHistoryTextFlyCnt( SwFrameFormat* const pFlyFormat ) @@ -615,19 +615,19 @@ SwHistoryBookmark::SwHistoryBookmark( , m_eBkmkType(IDocumentMarkAccess::GetType(rBkmk)) { const ::sw::mark::IBookmark* const pBookmark = dynamic_cast< const ::sw::mark::IBookmark* >(&rBkmk); - if(pBookmark) - { - m_aKeycode = pBookmark->GetKeyCode(); - m_aShortName = pBookmark->GetShortName(); - m_bHidden = pBookmark->IsHidden(); - m_aHideCondition = pBookmark->GetHideCondition(); + if(!pBookmark) + return; - ::sfx2::Metadatable const*const pMetadatable( - dynamic_cast< ::sfx2::Metadatable const* >(pBookmark)); - if (pMetadatable) - { - m_pMetadataUndo = pMetadatable->CreateUndo(); - } + m_aKeycode = pBookmark->GetKeyCode(); + m_aShortName = pBookmark->GetShortName(); + m_bHidden = pBookmark->IsHidden(); + m_aHideCondition = pBookmark->GetHideCondition(); + + ::sfx2::Metadatable const*const pMetadatable( + dynamic_cast< ::sfx2::Metadatable const* >(pBookmark)); + if (pMetadatable) + { + m_pMetadataUndo = pMetadatable->CreateUndo(); } } @@ -682,32 +682,32 @@ void SwHistoryBookmark::SetInDoc( SwDoc* pDoc, bool ) *pPam->GetMark() = pMark->GetOtherMarkPos(); } - if (pPam) + if (!pPam) + return; + + if ( pMark != nullptr ) { - if ( pMark != nullptr ) - { - pMarkAccess->deleteMark( pMark ); - } - ::sw::mark::IBookmark* const pBookmark = - dynamic_cast<::sw::mark::IBookmark*>( - pMarkAccess->makeMark(*pPam, m_aName, m_eBkmkType, sw::mark::InsertMode::New)); - if ( pBookmark != nullptr ) - { - pBookmark->SetKeyCode(m_aKeycode); - pBookmark->SetShortName(m_aShortName); - pBookmark->Hide(m_bHidden); - pBookmark->SetHideCondition(m_aHideCondition); + pMarkAccess->deleteMark( pMark ); + } + ::sw::mark::IBookmark* const pBookmark = + dynamic_cast<::sw::mark::IBookmark*>( + pMarkAccess->makeMark(*pPam, m_aName, m_eBkmkType, sw::mark::InsertMode::New)); + if ( pBookmark == nullptr ) + return; - if (m_pMetadataUndo) - { - ::sfx2::Metadatable * const pMeta( - dynamic_cast< ::sfx2::Metadatable* >(pBookmark)); - OSL_ENSURE(pMeta, "metadata undo, but not metadatable?"); - if (pMeta) - { - pMeta->RestoreMetadata(m_pMetadataUndo); - } - } + pBookmark->SetKeyCode(m_aKeycode); + pBookmark->SetShortName(m_aShortName); + pBookmark->Hide(m_bHidden); + pBookmark->SetHideCondition(m_aHideCondition); + + if (m_pMetadataUndo) + { + ::sfx2::Metadatable * const pMeta( + dynamic_cast< ::sfx2::Metadatable* >(pBookmark)); + OSL_ENSURE(pMeta, "metadata undo, but not metadatable?"); + if (pMeta) + { + pMeta->RestoreMetadata(m_pMetadataUndo); } } } @@ -929,31 +929,31 @@ void SwHistoryChangeFlyAnchor::SetInDoc( SwDoc* pDoc, bool ) { ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo()); - if (pDoc->GetSpzFrameFormats()->IsAlive(&m_rFormat)) // Format does still exist - { - SwFormatAnchor aTmp( m_rFormat.GetAnchor() ); + if (!pDoc->GetSpzFrameFormats()->IsAlive(&m_rFormat)) // Format does still exist + return; - SwNode* pNd = pDoc->GetNodes()[ m_nOldNodeIndex ]; - SwContentNode* pCNd = pNd->GetContentNode(); - SwPosition aPos( *pNd ); - if ( COMPLETE_STRING != m_nOldContentIndex ) - { - OSL_ENSURE(pCNd, "SwHistoryChangeFlyAnchor: no ContentNode"); - if (pCNd) - { - aPos.nContent.Assign( pCNd, m_nOldContentIndex ); - } - } - aTmp.SetAnchor( &aPos ); + SwFormatAnchor aTmp( m_rFormat.GetAnchor() ); - // so the Layout does not get confused - if (!pCNd || !pCNd->getLayoutFrame(pDoc->getIDocumentLayoutAccess().GetCurrentLayout(), nullptr, nullptr)) + SwNode* pNd = pDoc->GetNodes()[ m_nOldNodeIndex ]; + SwContentNode* pCNd = pNd->GetContentNode(); + SwPosition aPos( *pNd ); + if ( COMPLETE_STRING != m_nOldContentIndex ) + { + OSL_ENSURE(pCNd, "SwHistoryChangeFlyAnchor: no ContentNode"); + if (pCNd) { - m_rFormat.DelFrames(); + aPos.nContent.Assign( pCNd, m_nOldContentIndex ); } + } + aTmp.SetAnchor( &aPos ); - m_rFormat.SetFormatAttr( aTmp ); + // so the Layout does not get confused + if (!pCNd || !pCNd->getLayoutFrame(pDoc->getIDocumentLayoutAccess().GetCurrentLayout(), nullptr, nullptr)) + { + m_rFormat.DelFrames(); } + + m_rFormat.SetFormatAttr( aTmp ); } SwHistoryChangeFlyChain::SwHistoryChangeFlyChain( SwFlyFrameFormat& rFormat, @@ -967,32 +967,32 @@ SwHistoryChangeFlyChain::SwHistoryChangeFlyChain( SwFlyFrameFormat& rFormat, void SwHistoryChangeFlyChain::SetInDoc( SwDoc* pDoc, bool ) { - if (pDoc->GetSpzFrameFormats()->IsAlive(m_pFlyFormat)) - { - SwFormatChain aChain; + if (!pDoc->GetSpzFrameFormats()->IsAlive(m_pFlyFormat)) + return; - if (m_pPrevFormat && - pDoc->GetSpzFrameFormats()->IsAlive(m_pPrevFormat)) - { - aChain.SetPrev( m_pPrevFormat ); - SwFormatChain aTmp( m_pPrevFormat->GetChain() ); - aTmp.SetNext( m_pFlyFormat ); - m_pPrevFormat->SetFormatAttr( aTmp ); - } + SwFormatChain aChain; - if (m_pNextFormat && - pDoc->GetSpzFrameFormats()->IsAlive(m_pNextFormat)) - { - aChain.SetNext( m_pNextFormat ); - SwFormatChain aTmp( m_pNextFormat->GetChain() ); - aTmp.SetPrev( m_pFlyFormat ); - m_pNextFormat->SetFormatAttr( aTmp ); - } + if (m_pPrevFormat && + pDoc->GetSpzFrameFormats()->IsAlive(m_pPrevFormat)) + { + aChain.SetPrev( m_pPrevFormat ); + SwFormatChain aTmp( m_pPrevFormat->GetChain() ); + aTmp.SetNext( m_pFlyFormat ); + m_pPrevFormat->SetFormatAttr( aTmp ); + } - if ( aChain.GetNext() || aChain.GetPrev() ) - { - m_pFlyFormat->SetFormatAttr( aChain ); - } + if (m_pNextFormat && + pDoc->GetSpzFrameFormats()->IsAlive(m_pNextFormat)) + { + aChain.SetNext( m_pNextFormat ); + SwFormatChain aTmp( m_pNextFormat->GetChain() ); + aTmp.SetPrev( m_pFlyFormat ); + m_pNextFormat->SetFormatAttr( aTmp ); + } + + if ( aChain.GetNext() || aChain.GetPrev() ) + { + m_pFlyFormat->SetFormatAttr( aChain ); } } @@ -1265,21 +1265,21 @@ void SwHistory::CopyFormatAttr( const SfxItemSet& rSet, sal_uLong nNodeIdx) { - if(rSet.Count()) + if(!rSet.Count()) + return; + + SfxItemIter aIter(rSet); + const SfxPoolItem* pItem = aIter.GetCurItem(); + do { - SfxItemIter aIter(rSet); - const SfxPoolItem* pItem = aIter.GetCurItem(); - do + if(!IsInvalidItem(pItem)) { - if(!IsInvalidItem(pItem)) - { - Add(pItem, pItem, nNodeIdx); - } + Add(pItem, pItem, nNodeIdx); + } - pItem = aIter.NextItem(); + pItem = aIter.NextItem(); - } while(pItem); - } + } while(pItem); } void SwHistory::dumpAsXml(xmlTextWriterPtr pWriter) const @@ -1380,49 +1380,49 @@ SwRegHistory::SwRegHistory( const SwNode& rNd, SwHistory* pHst ) void SwRegHistory::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) { - if ( m_pHistory && pNew && pOld != pNew ) + if ( !(m_pHistory && pNew && pOld != pNew) ) + return; + + if ( pNew->Which() < POOLATTR_END ) { - if ( pNew->Which() < POOLATTR_END ) + if(RES_UPDATE_ATTR == pNew->Which()) { - if(RES_UPDATE_ATTR == pNew->Which()) - { - // const SfxItemPool& rPool = static_cast< const SwUpdateAttr* >(pNew)->GetSfxItemPool(); + // const SfxItemPool& rPool = static_cast< const SwUpdateAttr* >(pNew)->GetSfxItemPool(); - m_pHistory->Add( - // rPool, - pOld, - pNew, - m_nNodeIndex); - } - else - { - OSL_ENSURE(false, "Unexpected update attribute (!)"); - } + m_pHistory->Add( + // rPool, + pOld, + pNew, + m_nNodeIndex); } - else if (pOld && RES_ATTRSET_CHG == pNew->Which()) + else { - std::unique_ptr<SwHistoryHint> pNewHstr; - const SfxItemSet& rSet = *static_cast< const SwAttrSetChg* >(pOld)->GetChgSet(); + OSL_ENSURE(false, "Unexpected update attribute (!)"); + } + } + else if (pOld && RES_ATTRSET_CHG == pNew->Which()) + { + std::unique_ptr<SwHistoryHint> pNewHstr; + const SfxItemSet& rSet = *static_cast< const SwAttrSetChg* >(pOld)->GetChgSet(); - if ( 1 < rSet.Count() ) + if ( 1 < rSet.Count() ) + { + pNewHstr.reset( new SwHistorySetAttrSet( rSet, m_nNodeIndex, m_WhichIdSet ) ); + } + else if (const SfxPoolItem* pItem = SfxItemIter(rSet).GetCurItem()) + { + if ( m_WhichIdSet.count( pItem->Which() ) ) { - pNewHstr.reset( new SwHistorySetAttrSet( rSet, m_nNodeIndex, m_WhichIdSet ) ); + pNewHstr.reset( new SwHistorySetFormat( pItem, m_nNodeIndex ) ); } - else if (const SfxPoolItem* pItem = SfxItemIter(rSet).GetCurItem()) + else { - if ( m_WhichIdSet.count( pItem->Which() ) ) - { - pNewHstr.reset( new SwHistorySetFormat( pItem, m_nNodeIndex ) ); - } - else - { - pNewHstr.reset( new SwHistoryResetFormat( pItem, m_nNodeIndex ) ); - } + pNewHstr.reset( new SwHistoryResetFormat( pItem, m_nNodeIndex ) ); } - - if (pNewHstr) - m_pHistory->m_SwpHstry.push_back( std::move(pNewHstr) ); } + + if (pNewHstr) + m_pHistory->m_SwpHstry.push_back( std::move(pNewHstr) ); } } @@ -1511,27 +1511,27 @@ void SwRegHistory::MakeSetWhichIds() m_WhichIdSet.clear(); - if( GetRegisteredIn() ) + if( !GetRegisteredIn() ) + return; + + const SfxItemSet* pSet = nullptr; + if( dynamic_cast< const SwContentNode *>( GetRegisteredIn() ) != nullptr ) { - const SfxItemSet* pSet = nullptr; - if( dynamic_cast< const SwContentNode *>( GetRegisteredIn() ) != nullptr ) - { - pSet = static_cast<SwContentNode*>( - GetRegisteredIn())->GetpSwAttrSet(); - } - else if ( dynamic_cast< const SwFormat *>( GetRegisteredIn() ) != nullptr ) - { - pSet = &static_cast<SwFormat*>( - GetRegisteredIn())->GetAttrSet(); - } - if( pSet && pSet->Count() ) + pSet = static_cast<SwContentNode*>( + GetRegisteredIn())->GetpSwAttrSet(); + } + else if ( dynamic_cast< const SwFormat *>( GetRegisteredIn() ) != nullptr ) + { + pSet = &static_cast<SwFormat*>( + GetRegisteredIn())->GetAttrSet(); + } + if( pSet && pSet->Count() ) + { + SfxItemIter aIter( *pSet ); + for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem()) { - SfxItemIter aIter( *pSet ); - for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem()) - { - sal_uInt16 nW = pItem->Which(); - m_WhichIdSet.insert( nW ); - } + sal_uInt16 nW = pItem->Which(); + m_WhichIdSet.insert( nW ); } } } diff --git a/sw/source/core/undo/unattr.cxx b/sw/source/core/undo/unattr.cxx index efc6999fb7c4..715de15ef295 100644 --- a/sw/source/core/undo/unattr.cxx +++ b/sw/source/core/undo/unattr.cxx @@ -62,31 +62,31 @@ SwUndoFormatAttrHelper::SwUndoFormatAttrHelper( SwFormat& rFormat, bool bSvDrwPt void SwUndoFormatAttrHelper::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) { - if( pOld ) { - 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 ) ); + 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 ) ); } } } @@ -180,19 +180,19 @@ void SwUndoFormatAttr::UndoImpl(::sw::UndoRedoContext & rContext) } } - if ( !bAnchorAttrRestored ) { - SwUndoFormatAttrHelper aTmp( *pFormat, m_bSaveDrawPt ); - pFormat->SetFormatAttr( *m_pOldSet ); - if ( aTmp.GetUndo() ) { - // transfer ownership of helper object's old set - m_pOldSet = std::move(aTmp.GetUndo()->m_pOldSet); - } else { - m_pOldSet->ClearItem(); - } + if ( bAnchorAttrRestored ) return; - if ( RES_FLYFRMFMT == m_nFormatWhich || RES_DRAWFRMFMT == m_nFormatWhich ) { - rContext.SetSelections(static_cast<SwFrameFormat*>(pFormat), nullptr); - } + SwUndoFormatAttrHelper aTmp( *pFormat, m_bSaveDrawPt ); + pFormat->SetFormatAttr( *m_pOldSet ); + if ( aTmp.GetUndo() ) { + // transfer ownership of helper object's old set + m_pOldSet = std::move(aTmp.GetUndo()->m_pOldSet); + } else { + m_pOldSet->ClearItem(); + } + + if ( RES_FLYFRMFMT == m_nFormatWhich || RES_DRAWFRMFMT == m_nFormatWhich ) { + rContext.SetSelections(static_cast<SwFrameFormat*>(pFormat), nullptr); } } diff --git a/sw/source/core/undo/undel.cxx b/sw/source/core/undo/undel.cxx index e8d01b94376a..075a306506d8 100644 --- a/sw/source/core/undo/undel.cxx +++ b/sw/source/core/undo/undel.cxx @@ -120,28 +120,28 @@ static void DelFullParaMoveFrames(SwDoc & rDoc, SwUndRng const& rRange, SwTextNode * pFirstMergedDeletedTextNode(nullptr); SwTextNode *const pNextNode = FindFirstAndNextNode(rDoc, rRange, rRedlineSaveData, pFirstMergedDeletedTextNode); - if (pNextNode) + if (!pNextNode) + return; + + std::vector<SwTextFrame*> frames; + SwIterator<SwTextFrame, SwTextNode, sw::IteratorMode::UnwrapMulti> aIter(*pFirstMergedDeletedTextNode); + for (SwTextFrame* pFrame = aIter.First(); pFrame; pFrame = aIter.Next()) { - std::vector<SwTextFrame*> frames; - SwIterator<SwTextFrame, SwTextNode, sw::IteratorMode::UnwrapMulti> aIter(*pFirstMergedDeletedTextNode); - for (SwTextFrame* pFrame = aIter.First(); pFrame; pFrame = aIter.Next()) - { - if (pFrame->getRootFrame()->IsHideRedlines()) - { - assert(pFrame->GetMergedPara()); - assert(pFrame->GetMergedPara()->pFirstNode == pFirstMergedDeletedTextNode); - assert(pNextNode->GetIndex() <= pFrame->GetMergedPara()->pLastNode->GetIndex()); - frames.push_back(pFrame); - } - } - for (SwTextFrame *const pFrame : frames) + if (pFrame->getRootFrame()->IsHideRedlines()) { - // sw_redlinehide: don't need FrameMode::Existing here - // because everything from pNextNode onwards is already - // correctly hidden - pFrame->RegisterToNode(*pNextNode, true); + assert(pFrame->GetMergedPara()); + assert(pFrame->GetMergedPara()->pFirstNode == pFirstMergedDeletedTextNode); + assert(pNextNode->GetIndex() <= pFrame->GetMergedPara()->pLastNode->GetIndex()); + frames.push_back(pFrame); } } + for (SwTextFrame *const pFrame : frames) + { + // sw_redlinehide: don't need FrameMode::Existing here + // because everything from pNextNode onwards is already + // correctly hidden + pFrame->RegisterToNode(*pNextNode, true); + } } // SwUndoDelete has to perform a deletion and to record anything that is needed @@ -818,24 +818,24 @@ SwRewriter SwUndoDelete::GetRewriter() const // Every object, anchored "AtContent" will be reanchored at rPos static void lcl_ReAnchorAtContentFlyFrames( const SwFrameFormats& rSpzArr, SwPosition &rPos, sal_uLong nOldIdx ) { - if( !rSpzArr.empty() ) + if( rSpzArr.empty() ) + return; + + SwFlyFrameFormat* pFormat; + const SwFormatAnchor* pAnchor; + const SwPosition* pAPos; + for( size_t n = 0; n < rSpzArr.size(); ++n ) { - SwFlyFrameFormat* pFormat; - const SwFormatAnchor* pAnchor; - const SwPosition* pAPos; - for( size_t n = 0; n < rSpzArr.size(); ++n ) + pFormat = static_cast<SwFlyFrameFormat*>(rSpzArr[n]); + pAnchor = &pFormat->GetAnchor(); + if (pAnchor->GetAnchorId() == RndStdIds::FLY_AT_PARA) { - pFormat = static_cast<SwFlyFrameFormat*>(rSpzArr[n]); - pAnchor = &pFormat->GetAnchor(); - if (pAnchor->GetAnchorId() == RndStdIds::FLY_AT_PARA) + pAPos = pAnchor->GetContentAnchor(); + if( pAPos && nOldIdx == pAPos->nNode.GetIndex() ) { - pAPos = pAnchor->GetContentAnchor(); - if( pAPos && nOldIdx == pAPos->nNode.GetIndex() ) - { - SwFormatAnchor aAnch( *pAnchor ); - aAnch.SetAnchor( &rPos ); - pFormat->SetFormatAttr( aAnch ); - } + SwFormatAnchor aAnch( *pAnchor ); + aAnch.SetAnchor( &rPos ); + pFormat->SetFormatAttr( aAnch ); } } } diff --git a/sw/source/core/undo/undobj.cxx b/sw/source/core/undo/undobj.cxx index f0ed41377a35..268e0ea5e3d6 100644 --- a/sw/source/core/undo/undobj.cxx +++ b/sw/source/core/undo/undobj.cxx @@ -1066,127 +1066,127 @@ void SwUndoSaveContent::DelContentIndex( const SwPosition& rMark, } // 3. Bookmarks - if( DelContentType::Bkm & nDelContentType ) + if( !(DelContentType::Bkm & nDelContentType) ) + return; + + IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess(); + if( !pMarkAccess->getAllMarksCount() ) + return; + + for( sal_Int32 n = 0; n < pMarkAccess->getAllMarksCount(); ++n ) { - IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess(); - if( pMarkAccess->getAllMarksCount() ) + // #i81002# + bool bSavePos = false; + bool bSaveOtherPos = false; + const ::sw::mark::IMark *const pBkmk = pMarkAccess->getAllMarksBegin()[n]; + auto const type(IDocumentMarkAccess::GetType(*pBkmk)); + + if( DelContentType::CheckNoCntnt & nDelContentType ) + { + if ( pStt->nNode <= pBkmk->GetMarkPos().nNode + && pBkmk->GetMarkPos().nNode < pEnd->nNode ) + { + bSavePos = true; + } + if ( pBkmk->IsExpanded() + && pStt->nNode <= pBkmk->GetOtherMarkPos().nNode + && pBkmk->GetOtherMarkPos().nNode < pEnd->nNode ) + { + bSaveOtherPos = true; + } + } + else { - for( sal_Int32 n = 0; n < pMarkAccess->getAllMarksCount(); ++n ) + // #i92125# + // keep cross-reference bookmarks, if content inside one paragraph is deleted. + if ( rMark.nNode == rPoint.nNode + && ( type == IDocumentMarkAccess::MarkType::CROSSREF_HEADING_BOOKMARK + || type == IDocumentMarkAccess::MarkType::CROSSREF_NUMITEM_BOOKMARK)) { - // #i81002# - bool bSavePos = false; - bool bSaveOtherPos = false; - const ::sw::mark::IMark *const pBkmk = pMarkAccess->getAllMarksBegin()[n]; - auto const type(IDocumentMarkAccess::GetType(*pBkmk)); + continue; + } - if( DelContentType::CheckNoCntnt & nDelContentType ) + bool bMaybe = false; + if ( *pStt <= pBkmk->GetMarkPos() && pBkmk->GetMarkPos() <= *pEnd ) + { + if ( pBkmk->GetMarkPos() == *pEnd + || ( *pStt == pBkmk->GetMarkPos() && pBkmk->IsExpanded() ) ) + bMaybe = true; + else + bSavePos = true; + } + if( pBkmk->IsExpanded() && + *pStt <= pBkmk->GetOtherMarkPos() && pBkmk->GetOtherMarkPos() <= *pEnd ) + { + if ( bSavePos || bSaveOtherPos + || (*pStt < pBkmk->GetOtherMarkPos() && pBkmk->GetOtherMarkPos() < *pEnd) + || type == IDocumentMarkAccess::MarkType::TEXT_FIELDMARK + || type == IDocumentMarkAccess::MarkType::CHECKBOX_FIELDMARK + || type == IDocumentMarkAccess::MarkType::DROPDOWN_FIELDMARK + || type == IDocumentMarkAccess::MarkType::DATE_FIELDMARK) { - if ( pStt->nNode <= pBkmk->GetMarkPos().nNode - && pBkmk->GetMarkPos().nNode < pEnd->nNode ) - { + if( bMaybe ) bSavePos = true; - } - if ( pBkmk->IsExpanded() - && pStt->nNode <= pBkmk->GetOtherMarkPos().nNode - && pBkmk->GetOtherMarkPos().nNode < pEnd->nNode ) - { - bSaveOtherPos = true; - } + bSaveOtherPos = true; } - else - { - // #i92125# - // keep cross-reference bookmarks, if content inside one paragraph is deleted. - if ( rMark.nNode == rPoint.nNode - && ( type == IDocumentMarkAccess::MarkType::CROSSREF_HEADING_BOOKMARK - || type == IDocumentMarkAccess::MarkType::CROSSREF_NUMITEM_BOOKMARK)) - { - continue; - } - - bool bMaybe = false; - if ( *pStt <= pBkmk->GetMarkPos() && pBkmk->GetMarkPos() <= *pEnd ) - { - if ( pBkmk->GetMarkPos() == *pEnd - || ( *pStt == pBkmk->GetMarkPos() && pBkmk->IsExpanded() ) ) - bMaybe = true; - else - bSavePos = true; - } - if( pBkmk->IsExpanded() && - *pStt <= pBkmk->GetOtherMarkPos() && pBkmk->GetOtherMarkPos() <= *pEnd ) - { - if ( bSavePos || bSaveOtherPos - || (*pStt < pBkmk->GetOtherMarkPos() && pBkmk->GetOtherMarkPos() < *pEnd) - || type == IDocumentMarkAccess::MarkType::TEXT_FIELDMARK - || type == IDocumentMarkAccess::MarkType::CHECKBOX_FIELDMARK - || type == IDocumentMarkAccess::MarkType::DROPDOWN_FIELDMARK - || type == IDocumentMarkAccess::MarkType::DATE_FIELDMARK) - { - if( bMaybe ) - bSavePos = true; - bSaveOtherPos = true; - } - } + } - if ( !bSavePos && !bSaveOtherPos - && dynamic_cast< const ::sw::mark::CrossRefBookmark* >(pBkmk) ) + if ( !bSavePos && !bSaveOtherPos + && dynamic_cast< const ::sw::mark::CrossRefBookmark* >(pBkmk) ) + { + // certain special handling for cross-reference bookmarks + const bool bDifferentTextNodesAtMarkAndPoint = + rMark.nNode != rPoint.nNode + && rMark.nNode.GetNode().GetTextNode() + && rPoint.nNode.GetNode().GetTextNode(); + if ( bDifferentTextNodesAtMarkAndPoint ) + { + // delete cross-reference bookmark at <pStt>, if only part of + // <pEnd> text node content is deleted. + if( pStt->nNode == pBkmk->GetMarkPos().nNode + && pEnd->nContent.GetIndex() != pEnd->nNode.GetNode().GetTextNode()->Len() ) { - // certain special handling for cross-reference bookmarks - const bool bDifferentTextNodesAtMarkAndPoint = - rMark.nNode != rPoint.nNode - && rMark.nNode.GetNode().GetTextNode() - && rPoint.nNode.GetNode().GetTextNode(); - if ( bDifferentTextNodesAtMarkAndPoint ) - { - // delete cross-reference bookmark at <pStt>, if only part of - // <pEnd> text node content is deleted. - if( pStt->nNode == pBkmk->GetMarkPos().nNode - && pEnd->nContent.GetIndex() != pEnd->nNode.GetNode().GetTextNode()->Len() ) - { - bSavePos = true; - bSaveOtherPos = false; // cross-reference bookmarks are not expanded - } - // delete cross-reference bookmark at <pEnd>, if only part of - // <pStt> text node content is deleted. - else if( pEnd->nNode == pBkmk->GetMarkPos().nNode && - pStt->nContent.GetIndex() != 0 ) - { - bSavePos = true; - bSaveOtherPos = false; // cross-reference bookmarks are not expanded - } - } + bSavePos = true; + bSaveOtherPos = false; // cross-reference bookmarks are not expanded } - else if (type == IDocumentMarkAccess::MarkType::ANNOTATIONMARK) + // delete cross-reference bookmark at <pEnd>, if only part of + // <pStt> text node content is deleted. + else if( pEnd->nNode == pBkmk->GetMarkPos().nNode && + pStt->nContent.GetIndex() != 0 ) { - // delete annotation marks, if its end position is covered by the deletion - const SwPosition& rAnnotationEndPos = pBkmk->GetMarkEnd(); - if ( *pStt < rAnnotationEndPos && rAnnotationEndPos <= *pEnd ) - { - bSavePos = true; - bSaveOtherPos = pBkmk->IsExpanded(); //tdf#90138, only save the other pos if there is one - } + bSavePos = true; + bSaveOtherPos = false; // cross-reference bookmarks are not expanded } } - - if ( bSavePos || bSaveOtherPos ) + } + else if (type == IDocumentMarkAccess::MarkType::ANNOTATIONMARK) + { + // delete annotation marks, if its end position is covered by the deletion + const SwPosition& rAnnotationEndPos = pBkmk->GetMarkEnd(); + if ( *pStt < rAnnotationEndPos && rAnnotationEndPos <= *pEnd ) { - if (type != IDocumentMarkAccess::MarkType::UNO_BOOKMARK) - { - if( !m_pHistory ) - m_pHistory.reset( new SwHistory ); - m_pHistory->Add( *pBkmk, bSavePos, bSaveOtherPos ); - } - if ( bSavePos - && ( bSaveOtherPos - || !pBkmk->IsExpanded() ) ) - { - pMarkAccess->deleteMark(pMarkAccess->getAllMarksBegin()+n); - n--; - } + bSavePos = true; + bSaveOtherPos = pBkmk->IsExpanded(); //tdf#90138, only save the other pos if there is one } } } + + if ( bSavePos || bSaveOtherPos ) + { + if (type != IDocumentMarkAccess::MarkType::UNO_BOOKMARK) + { + if( !m_pHistory ) + m_pHistory.reset( new SwHistory ); + m_pHistory->Add( *pBkmk, bSavePos, bSaveOtherPos ); + } + if ( bSavePos + && ( bSaveOtherPos + || !pBkmk->IsExpanded() ) ) + { + pMarkAccess->deleteMark(pMarkAccess->getAllMarksBegin()+n); + n--; + } + } } } @@ -1265,40 +1265,40 @@ void SwUndoSaveSection::SaveSection( void SwUndoSaveSection::RestoreSection( SwDoc* pDoc, SwNodeIndex* pIdx, sal_uInt16 nSectType ) { - if( ULONG_MAX != m_nStartPos ) // was there any content? - { - // check if the content is at the old position - SwNodeIndex aSttIdx( pDoc->GetNodes(), m_nStartPos ); + if( ULONG_MAX == m_nStartPos ) // was there any content? + return; - // move the content from UndoNodes array into Fly - SwStartNode* pSttNd = SwNodes::MakeEmptySection( aSttIdx, - static_cast<SwStartNodeType>(nSectType) ); + // check if the content is at the old position + SwNodeIndex aSttIdx( pDoc->GetNodes(), m_nStartPos ); - RestoreSection( pDoc, SwNodeIndex( *pSttNd->EndOfSectionNode() )); + // move the content from UndoNodes array into Fly + SwStartNode* pSttNd = SwNodes::MakeEmptySection( aSttIdx, + static_cast<SwStartNodeType>(nSectType) ); - if( pIdx ) - *pIdx = *pSttNd; - } + RestoreSection( pDoc, SwNodeIndex( *pSttNd->EndOfSectionNode() )); + + if( pIdx ) + *pIdx = *pSttNd; } void SwUndoSaveSection::RestoreSection( SwDoc *const pDoc, const SwNodeIndex& rInsPos, bool bForceCreateFrames) { - if( ULONG_MAX != m_nStartPos ) // was there any content? - { - SwPosition aInsPos( rInsPos ); - sal_uLong nEnd = m_pMovedStart->GetIndex() + m_nMoveLen - 1; - MoveFromUndoNds(*pDoc, m_pMovedStart->GetIndex(), aInsPos, &nEnd, bForceCreateFrames); + if( ULONG_MAX == m_nStartPos ) // was there any content? + return; - // destroy indices again, content was deleted from UndoNodes array - m_pMovedStart.reset(); - m_nMoveLen = 0; + SwPosition aInsPos( rInsPos ); + sal_uLong nEnd = m_pMovedStart->GetIndex() + m_nMoveLen - 1; + MoveFromUndoNds(*pDoc, m_pMovedStart->GetIndex(), aInsPos, &nEnd, bForceCreateFrames); - if( m_pRedlineSaveData ) - { - SwUndo::SetSaveData( *pDoc, *m_pRedlineSaveData ); - m_pRedlineSaveData.reset(); - } + // destroy indices again, content was deleted from UndoNodes array + m_pMovedStart.reset(); + m_nMoveLen = 0; + + if( m_pRedlineSaveData ) + { + SwUndo::SetSaveData( *pDoc, *m_pRedlineSaveData ); + m_pRedlineSaveData.reset(); } } diff --git a/sw/source/core/undo/undobj1.cxx b/sw/source/core/undo/undobj1.cxx index b9757d267850..ea0f0f850d39 100644 --- a/sw/source/core/undo/undobj1.cxx +++ b/sw/source/core/undo/undobj1.cxx @@ -555,68 +555,68 @@ void SwUndoSetFlyFormat::UndoImpl(::sw::UndoRedoContext & rContext) // Is the new Format still existent? SwFrameFormat* pDerivedFromFrameFormat = rDoc.FindFrameFormatByName(m_DerivedFromFormatName); - if (pDerivedFromFrameFormat) - { - if( m_bAnchorChanged ) - m_pFrameFormat->DelFrames(); + if (!pDerivedFromFrameFormat) + return; - if( m_pFrameFormat->DerivedFrom() != pDerivedFromFrameFormat) - m_pFrameFormat->SetDerivedFrom(pDerivedFromFrameFormat); + if( m_bAnchorChanged ) + m_pFrameFormat->DelFrames(); - SfxItemIter aIter( *m_pItemSet ); - for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem()) - { - if( IsInvalidItem( pItem )) - m_pFrameFormat->ResetFormatAttr( m_pItemSet->GetWhichByPos( - aIter.GetCurPos() )); - else - m_pFrameFormat->SetFormatAttr( *pItem ); - } + if( m_pFrameFormat->DerivedFrom() != pDerivedFromFrameFormat) + m_pFrameFormat->SetDerivedFrom(pDerivedFromFrameFormat); - if( m_bAnchorChanged ) - { - const SwFormatAnchor& rOldAnch = m_pFrameFormat->GetAnchor(); - if (RndStdIds::FLY_AS_CHAR == rOldAnch.GetAnchorId()) - { - // With InContents it's tricky: the text attribute needs to be - // deleted. Unfortunately, this not only destroys the Frames but - // also the format. To prevent that, first detach the - // connection between attribute and format. - const SwPosition *pPos = rOldAnch.GetContentAnchor(); - SwTextNode *pTextNode = pPos->nNode.GetNode().GetTextNode(); - OSL_ENSURE( pTextNode->HasHints(), "Missing FlyInCnt-Hint." ); - const sal_Int32 nIdx = pPos->nContent.GetIndex(); - SwTextAttr * pHint = pTextNode->GetTextAttrForCharAt( - nIdx, RES_TXTATR_FLYCNT ); - assert(pHint && "Missing Hint."); - OSL_ENSURE( pHint->Which() == RES_TXTATR_FLYCNT, - "Missing FlyInCnt-Hint." ); - OSL_ENSURE( pHint->GetFlyCnt().GetFrameFormat() == m_pFrameFormat, - "Wrong TextFlyCnt-Hint." ); - const_cast<SwFormatFlyCnt&>(pHint->GetFlyCnt()).SetFlyFormat(); - - // Connection is now detached, therefore the attribute can be - // deleted - pTextNode->DeleteAttributes( RES_TXTATR_FLYCNT, nIdx, nIdx ); - } + SfxItemIter aIter( *m_pItemSet ); + for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem()) + { + if( IsInvalidItem( pItem )) + m_pFrameFormat->ResetFormatAttr( m_pItemSet->GetWhichByPos( + aIter.GetCurPos() )); + else + m_pFrameFormat->SetFormatAttr( *pItem ); + } - // reposition anchor - SwFormatAnchor aNewAnchor( m_nOldAnchorType ); - GetAnchor( aNewAnchor, m_nOldNode, m_nOldContent ); - m_pFrameFormat->SetFormatAttr( aNewAnchor ); + if( m_bAnchorChanged ) + { + const SwFormatAnchor& rOldAnch = m_pFrameFormat->GetAnchor(); + if (RndStdIds::FLY_AS_CHAR == rOldAnch.GetAnchorId()) + { + // With InContents it's tricky: the text attribute needs to be + // deleted. Unfortunately, this not only destroys the Frames but + // also the format. To prevent that, first detach the + // connection between attribute and format. + const SwPosition *pPos = rOldAnch.GetContentAnchor(); + SwTextNode *pTextNode = pPos->nNode.GetNode().GetTextNode(); + OSL_ENSURE( pTextNode->HasHints(), "Missing FlyInCnt-Hint." ); + const sal_Int32 nIdx = pPos->nContent.GetIndex(); + SwTextAttr * pHint = pTextNode->GetTextAttrForCharAt( + nIdx, RES_TXTATR_FLYCNT ); + assert(pHint && "Missing Hint."); + OSL_ENSURE( pHint->Which() == RES_TXTATR_FLYCNT, + "Missing FlyInCnt-Hint." ); + OSL_ENSURE( pHint->GetFlyCnt().GetFrameFormat() == m_pFrameFormat, + "Wrong TextFlyCnt-Hint." ); + const_cast<SwFormatFlyCnt&>(pHint->GetFlyCnt()).SetFlyFormat(); + + // Connection is now detached, therefore the attribute can be + // deleted + pTextNode->DeleteAttributes( RES_TXTATR_FLYCNT, nIdx, nIdx ); + } - if (RndStdIds::FLY_AS_CHAR == aNewAnchor.GetAnchorId()) - { - const SwPosition* pPos = aNewAnchor.GetContentAnchor(); - SwFormatFlyCnt aFormat( m_pFrameFormat ); - pPos->nNode.GetNode().GetTextNode()->InsertItem( aFormat, - m_nOldContent, 0 ); - } + // reposition anchor + SwFormatAnchor aNewAnchor( m_nOldAnchorType ); + GetAnchor( aNewAnchor, m_nOldNode, m_nOldContent ); + m_pFrameFormat->SetFormatAttr( aNewAnchor ); - m_pFrameFormat->MakeFrames(); + if (RndStdIds::FLY_AS_CHAR == aNewAnchor.GetAnchorId()) + { + const SwPosition* pPos = aNewAnchor.GetContentAnchor(); + SwFormatFlyCnt aFormat( m_pFrameFormat ); + pPos->nNode.GetNode().GetTextNode()->InsertItem( aFormat, + m_nOldContent, 0 ); } - rContext.SetSelections(m_pFrameFormat, nullptr); + + m_pFrameFormat->MakeFrames(); } + rContext.SetSelections(m_pFrameFormat, nullptr); } void SwUndoSetFlyFormat::RedoImpl(::sw::UndoRedoContext & rContext) @@ -625,21 +625,21 @@ void SwUndoSetFlyFormat::RedoImpl(::sw::UndoRedoContext & rContext) // Is the new Format still existent? SwFrameFormat* pNewFrameFormat = rDoc.FindFrameFormatByName(m_NewFormatName); - if (pNewFrameFormat) - { - if( m_bAnchorChanged ) - { - SwFormatAnchor aNewAnchor( m_nNewAnchorType ); - GetAnchor( aNewAnchor, m_nNewNode, m_nNewContent ); - SfxItemSet aSet( rDoc.GetAttrPool(), aFrameFormatSetRange ); - aSet.Put( aNewAnchor ); - rDoc.SetFrameFormatToFly( *m_pFrameFormat, *pNewFrameFormat, &aSet ); - } - else - rDoc.SetFrameFormatToFly( *m_pFrameFormat, *pNewFrameFormat); + if (!pNewFrameFormat) + return; - rContext.SetSelections(m_pFrameFormat, nullptr); + if( m_bAnchorChanged ) + { + SwFormatAnchor aNewAnchor( m_nNewAnchorType ); + GetAnchor( aNewAnchor, m_nNewNode, m_nNewContent ); + SfxItemSet aSet( rDoc.GetAttrPool(), aFrameFormatSetRange ); + aSet.Put( aNewAnchor ); + rDoc.SetFrameFormatToFly( *m_pFrameFormat, *pNewFrameFormat, &aSet ); } + else + rDoc.SetFrameFormatToFly( *m_pFrameFormat, *pNewFrameFormat); + + rContext.SetSelections(m_pFrameFormat, nullptr); } void SwUndoSetFlyFormat::PutAttr( sal_uInt16 nWhich, const SfxPoolItem* pItem ) @@ -697,19 +697,19 @@ void SwUndoSetFlyFormat::PutAttr( sal_uInt16 nWhich, const SfxPoolItem* pItem ) void SwUndoSetFlyFormat::Modify( const SfxPoolItem* pOld, const SfxPoolItem* ) { - if( pOld ) - { - sal_uInt16 nWhich = pOld->Which(); + if( !pOld ) + return; + + sal_uInt16 nWhich = pOld->Which(); - if( nWhich < POOLATTR_END ) - PutAttr( nWhich, pOld ); - else if( RES_ATTRSET_CHG == nWhich ) + if( nWhich < POOLATTR_END ) + PutAttr( nWhich, pOld ); + else if( RES_ATTRSET_CHG == nWhich ) + { + SfxItemIter aIter( *static_cast<const SwAttrSetChg*>(pOld)->GetChgSet() ); + for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem()) { - SfxItemIter aIter( *static_cast<const SwAttrSetChg*>(pOld)->GetChgSet() ); - for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem()) - { - PutAttr( pItem->Which(), pItem ); - } + PutAttr( pItem->Which(), pItem ); } } } diff --git a/sw/source/core/undo/undraw.cxx b/sw/source/core/undo/undraw.cxx index b6c8bd521ba4..e66e325d23ee 100644 --- a/sw/source/core/undo/undraw.cxx +++ b/sw/source/core/undo/undraw.cxx @@ -105,72 +105,72 @@ static void lcl_SendRemoveToUno( SwFormat& rFormat ) static void lcl_SaveAnchor( SwFrameFormat* pFormat, sal_uLong& rNodePos ) { const SwFormatAnchor& rAnchor = pFormat->GetAnchor(); - if ((RndStdIds::FLY_AT_PARA == rAnchor.GetAnchorId()) || + if (!((RndStdIds::FLY_AT_PARA == rAnchor.GetAnchorId()) || (RndStdIds::FLY_AT_CHAR == rAnchor.GetAnchorId()) || (RndStdIds::FLY_AT_FLY == rAnchor.GetAnchorId()) || - (RndStdIds::FLY_AS_CHAR == rAnchor.GetAnchorId())) - { - rNodePos = rAnchor.GetContentAnchor()->nNode.GetIndex(); - sal_Int32 nContentPos = 0; + (RndStdIds::FLY_AS_CHAR == rAnchor.GetAnchorId()))) + return; - if (RndStdIds::FLY_AS_CHAR == rAnchor.GetAnchorId()) - { - nContentPos = rAnchor.GetContentAnchor()->nContent.GetIndex(); - - // destroy TextAttribute - SwTextNode *pTextNd = pFormat->GetDoc()->GetNodes()[ rNodePos ]->GetTextNode(); - OSL_ENSURE( pTextNd, "No text node found!" ); - SwTextFlyCnt* pAttr = static_cast<SwTextFlyCnt*>( - pTextNd->GetTextAttrForCharAt( nContentPos, RES_TXTATR_FLYCNT )); - // attribute still in text node, delete - if( pAttr && pAttr->GetFlyCnt().GetFrameFormat() == pFormat ) - { - // just set pointer to 0, don't delete - const_cast<SwFormatFlyCnt&>(pAttr->GetFlyCnt()).SetFlyFormat(); - SwIndex aIdx( pTextNd, nContentPos ); - pTextNd->EraseText( aIdx, 1 ); - } - } - else if (RndStdIds::FLY_AT_CHAR == rAnchor.GetAnchorId()) + rNodePos = rAnchor.GetContentAnchor()->nNode.GetIndex(); + sal_Int32 nContentPos = 0; + + if (RndStdIds::FLY_AS_CHAR == rAnchor.GetAnchorId()) + { + nContentPos = rAnchor.GetContentAnchor()->nContent.GetIndex(); + + // destroy TextAttribute + SwTextNode *pTextNd = pFormat->GetDoc()->GetNodes()[ rNodePos ]->GetTextNode(); + OSL_ENSURE( pTextNd, "No text node found!" ); + SwTextFlyCnt* pAttr = static_cast<SwTextFlyCnt*>( + pTextNd->GetTextAttrForCharAt( nContentPos, RES_TXTATR_FLYCNT )); + // attribute still in text node, delete + if( pAttr && pAttr->GetFlyCnt().GetFrameFormat() == pFormat ) { - nContentPos = rAnchor.GetContentAnchor()->nContent.GetIndex(); + // just set pointer to 0, don't delete + const_cast<SwFormatFlyCnt&>(pAttr->GetFlyCnt()).SetFlyFormat(); + SwIndex aIdx( pTextNd, nContentPos ); + pTextNd->EraseText( aIdx, 1 ); } - - pFormat->SetFormatAttr( SwFormatAnchor( rAnchor.GetAnchorId(), nContentPos ) ); } + else if (RndStdIds::FLY_AT_CHAR == rAnchor.GetAnchorId()) + { + nContentPos = rAnchor.GetContentAnchor()->nContent.GetIndex(); + } + + pFormat->SetFormatAttr( SwFormatAnchor( rAnchor.GetAnchorId(), nContentPos ) ); } static void lcl_RestoreAnchor( SwFrameFormat* pFormat, sal_uLong nNodePos ) { const SwFormatAnchor& rAnchor = pFormat->GetAnchor(); - if ((RndStdIds::FLY_AT_PARA == rAnchor.GetAnchorId()) || + if (!((RndStdIds::FLY_AT_PARA == rAnchor.GetAnchorId()) || (RndStdIds::FLY_AT_CHAR == rAnchor.GetAnchorId()) || (RndStdIds::FLY_AT_FLY == rAnchor.GetAnchorId()) || - (RndStdIds::FLY_AS_CHAR == rAnchor.GetAnchorId())) - { - const sal_Int32 nContentPos = rAnchor.GetPageNum(); - SwNodes& rNds = pFormat->GetDoc()->GetNodes(); + (RndStdIds::FLY_AS_CHAR == rAnchor.GetAnchorId()))) + return; - SwNodeIndex aIdx( rNds, nNodePos ); - SwPosition aPos( aIdx ); + const sal_Int32 nContentPos = rAnchor.GetPageNum(); + SwNodes& rNds = pFormat->GetDoc()->GetNodes(); - SwFormatAnchor aTmp( rAnchor.GetAnchorId() ); - if ((RndStdIds::FLY_AS_CHAR == rAnchor.GetAnchorId()) || - (RndStdIds::FLY_AT_CHAR == rAnchor.GetAnchorId())) - { - aPos.nContent.Assign( aIdx.GetNode().GetContentNode(), nContentPos ); - } - aTmp.SetAnchor( &aPos ); - RndStdIds nAnchorId = rAnchor.GetAnchorId(); - pFormat->SetFormatAttr( aTmp ); + SwNodeIndex aIdx( rNds, nNodePos ); + SwPosition aPos( aIdx ); - if (RndStdIds::FLY_AS_CHAR == nAnchorId) - { - SwTextNode *pTextNd = aIdx.GetNode().GetTextNode(); - OSL_ENSURE( pTextNd, "no Text Node" ); - SwFormatFlyCnt aFormat( pFormat ); - pTextNd->InsertItem( aFormat, nContentPos, nContentPos ); - } + SwFormatAnchor aTmp( rAnchor.GetAnchorId() ); + if ((RndStdIds::FLY_AS_CHAR == rAnchor.GetAnchorId()) || + (RndStdIds::FLY_AT_CHAR == rAnchor.GetAnchorId())) + { + aPos.nContent.Assign( aIdx.GetNode().GetContentNode(), nContentPos ); + } + aTmp.SetAnchor( &aPos ); + RndStdIds nAnchorId = rAnchor.GetAnchorId(); + pFormat->SetFormatAttr( aTmp ); + + if (RndStdIds::FLY_AS_CHAR == nAnchorId) + { + SwTextNode *pTextNd = aIdx.GetNode().GetTextNode(); + OSL_ENSURE( pTextNd, "no Text Node" ); + SwFormatFlyCnt aFormat( pFormat ); + pTextNd->InsertItem( aFormat, nContentPos, nContentPos ); } } diff --git a/sw/source/core/undo/unovwr.cxx b/sw/source/core/undo/unovwr.cxx index 56fa55b35b4f..c3ac1ee27921 100644 --- a/sw/source/core/undo/unovwr.cxx +++ b/sw/source/core/undo/unovwr.cxx @@ -448,26 +448,26 @@ void SwUndoTransliterate::AddChanges( SwTextNode& rTNd, void UndoTransliterate_Data::SetChangeAtNode( SwDoc& rDoc ) { SwTextNode* pTNd = rDoc.GetNodes()[ nNdIdx ]->GetTextNode(); - if( pTNd ) + if( !pTNd ) + return; + + Sequence <sal_Int32> aOffsets( pOffsets ? pOffsets->getLength() : nLen ); + if( pOffsets ) + aOffsets = *pOffsets; + else { - Sequence <sal_Int32> aOffsets( pOffsets ? pOffsets->getLength() : nLen ); - if( pOffsets ) - aOffsets = *pOffsets; - else - { - sal_Int32* p = aOffsets.getArray(); - for( sal_Int32 n = 0; n < nLen; ++n, ++p ) - *p = n + nStart; - } - pTNd->ReplaceTextOnly( nStart, nLen, sText, aOffsets ); + sal_Int32* p = aOffsets.getArray(); + for( sal_Int32 n = 0; n < nLen; ++n, ++p ) + *p = n + nStart; + } + pTNd->ReplaceTextOnly( nStart, nLen, sText, aOffsets ); - if( pHistory ) - { - if( pTNd->GetpSwpHints() ) - pTNd->ClearSwpHintsArr( false ); - pHistory->TmpRollback( &rDoc, 0, false ); - pHistory->SetTmpEnd( pHistory->Count() ); - } + if( pHistory ) + { + if( pTNd->GetpSwpHints() ) + pTNd->ClearSwpHintsArr( false ); + pHistory->TmpRollback( &rDoc, 0, false ); + pHistory->SetTmpEnd( pHistory->Count() ); } } diff --git a/sw/source/core/undo/unsect.cxx b/sw/source/core/undo/unsect.cxx index db5deea3e57f..4d40d20fbc05 100644 --- a/sw/source/core/undo/unsect.cxx +++ b/sw/source/core/undo/unsect.cxx @@ -100,20 +100,20 @@ SwUndoInsSection::SwUndoInsSection( if( !FillSaveData( rPam, *m_pRedlineSaveData, false )) m_pRedlineSaveData.reset(); - if( !rPam.HasMark() ) + if( rPam.HasMark() ) + return; + + const SwContentNode* pCNd = rPam.GetPoint()->nNode.GetNode().GetContentNode(); + if( pCNd && pCNd->HasSwAttrSet() && ( + !rPam.GetPoint()->nContent.GetIndex() || + rPam.GetPoint()->nContent.GetIndex() == pCNd->Len() )) { - const SwContentNode* pCNd = rPam.GetPoint()->nNode.GetNode().GetContentNode(); - if( pCNd && pCNd->HasSwAttrSet() && ( - !rPam.GetPoint()->nContent.GetIndex() || - rPam.GetPoint()->nContent.GetIndex() == pCNd->Len() )) + SfxItemSet aBrkSet( rDoc.GetAttrPool(), aBreakSetRange ); + aBrkSet.Put( *pCNd->GetpSwAttrSet() ); + if( aBrkSet.Count() ) { - SfxItemSet aBrkSet( rDoc.GetAttrPool(), aBreakSetRange ); - aBrkSet.Put( *pCNd->GetpSwAttrSet() ); - if( aBrkSet.Count() ) - { - m_pHistory.reset( new SwHistory ); - m_pHistory->CopyFormatAttr( aBrkSet, pCNd->GetIndex() ); - } + m_pHistory.reset( new SwHistory ); + m_pHistory->CopyFormatAttr( aBrkSet, pCNd->GetIndex() ); } } } @@ -486,26 +486,26 @@ void SwUndoUpdateSection::UndoImpl(::sw::UndoRedoContext & rContext) } m_pAttrSet = std::move(pCur); - if (!m_bOnlyAttrChanged) + if (m_bOnlyAttrChanged) + return; + + const bool bUpdate = + (!rNdSect.IsLinkType() && m_pSectionData->IsLinkType()) + || ( !m_pSectionData->GetLinkFileName().isEmpty() + && (m_pSectionData->GetLinkFileName() != + rNdSect.GetLinkFileName())); + + // swap stored section data with live section data + SwSectionData *const pOld( new SwSectionData(rNdSect) ); + rNdSect.SetSectionData(*m_pSectionData); + m_pSectionData.reset(pOld); + + if( bUpdate ) + rNdSect.CreateLink( LinkCreateType::Update ); + else if( SectionType::Content == rNdSect.GetType() && rNdSect.IsConnected() ) { - const bool bUpdate = - (!rNdSect.IsLinkType() && m_pSectionData->IsLinkType()) - || ( !m_pSectionData->GetLinkFileName().isEmpty() - && (m_pSectionData->GetLinkFileName() != - rNdSect.GetLinkFileName())); - - // swap stored section data with live section data - SwSectionData *const pOld( new SwSectionData(rNdSect) ); - rNdSect.SetSectionData(*m_pSectionData); - m_pSectionData.reset(pOld); - - if( bUpdate ) - rNdSect.CreateLink( LinkCreateType::Update ); - else if( SectionType::Content == rNdSect.GetType() && rNdSect.IsConnected() ) - { - rNdSect.Disconnect(); - rDoc.getIDocumentLinksAdministration().GetLinkManager().Remove( &rNdSect.GetBaseLink() ); - } + rNdSect.Disconnect(); + rDoc.getIDocumentLinksAdministration().GetLinkManager().Remove( &rNdSect.GetBaseLink() ); } } diff --git a/sw/source/core/undo/unspnd.cxx b/sw/source/core/undo/unspnd.cxx index 54129f3c8363..be2d009ad7a1 100644 --- a/sw/source/core/undo/unspnd.cxx +++ b/sw/source/core/undo/unspnd.cxx @@ -153,39 +153,39 @@ void SwUndoSplitNode::RedoImpl(::sw::UndoRedoContext & rContext) rPam.GetPoint()->nNode = m_nNode; SwTextNode * pTNd = rPam.GetNode().GetTextNode(); OSL_ENSURE(pTNd, "SwUndoSplitNode::RedoImpl(): SwTextNode expected"); - if (pTNd) - { - rPam.GetPoint()->nContent.Assign( pTNd, m_nContent ); + if (!pTNd) + return; - SwDoc* pDoc = rPam.GetDoc(); - pDoc->getIDocumentContentOperations().SplitNode( *rPam.GetPoint(), m_bCheckTableStart ); + rPam.GetPoint()->nContent.Assign( pTNd, m_nContent ); - if (m_pHistory) - { - m_pHistory->SetTmpEnd(m_pHistory->Count()); - } + SwDoc* pDoc = rPam.GetDoc(); + pDoc->getIDocumentContentOperations().SplitNode( *rPam.GetPoint(), m_bCheckTableStart ); + + if (m_pHistory) + { + m_pHistory->SetTmpEnd(m_pHistory->Count()); + } - if( ( m_pRedlineData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() )) || - ( !( RedlineFlags::Ignore & GetRedlineFlags() ) && - !pDoc->getIDocumentRedlineAccess().GetRedlineTable().empty() )) + if( !(( m_pRedlineData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() )) || + ( !( RedlineFlags::Ignore & GetRedlineFlags() ) && + !pDoc->getIDocumentRedlineAccess().GetRedlineTable().empty() ))) + return; + + rPam.SetMark(); + if( rPam.Move( fnMoveBackward )) + { + if( m_pRedlineData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() )) { - rPam.SetMark(); - if( rPam.Move( fnMoveBackward )) - { - if( m_pRedlineData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() )) - { - RedlineFlags eOld = pDoc->getIDocumentRedlineAccess().GetRedlineFlags(); - pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern(eOld & ~RedlineFlags::Ignore); - pDoc->getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline( *m_pRedlineData, rPam ), true); - pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld ); - } - else - pDoc->getIDocumentRedlineAccess().SplitRedline( rPam ); - rPam.Exchange(); - } - rPam.DeleteMark(); + RedlineFlags eOld = pDoc->getIDocumentRedlineAccess().GetRedlineFlags(); + pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern(eOld & ~RedlineFlags::Ignore); + pDoc->getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline( *m_pRedlineData, rPam ), true); + pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld ); } + else + pDoc->getIDocumentRedlineAccess().SplitRedline( rPam ); + rPam.Exchange(); } + rPam.DeleteMark(); } void SwUndoSplitNode::RepeatImpl(::sw::RepeatContext & rContext) diff --git a/sw/source/core/undo/untbl.cxx b/sw/source/core/undo/untbl.cxx index 8cbf571b39e9..521284915384 100644 --- a/sw/source/core/undo/untbl.cxx +++ b/sw/source/core/undo/untbl.cxx @@ -316,26 +316,26 @@ void SwUndoInsTable::RedoImpl(::sw::UndoRedoContext & rContext) m_pDDEFieldType.reset(); } - if( (m_pRedlineData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() )) || + if( !((m_pRedlineData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() )) || ( !( RedlineFlags::Ignore & GetRedlineFlags() ) && - !rDoc.getIDocumentRedlineAccess().GetRedlineTable().empty() )) - { - SwPaM aPam( *pTableNode->EndOfSectionNode(), *pTableNode, 1 ); - SwContentNode* pCNd = aPam.GetContentNode( false ); - if( pCNd ) - aPam.GetMark()->nContent.Assign( pCNd, 0 ); + !rDoc.getIDocumentRedlineAccess().GetRedlineTable().empty() ))) + return; - if( m_pRedlineData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() ) ) - { - RedlineFlags eOld = rDoc.getIDocumentRedlineAccess().GetRedlineFlags(); - rDoc.getIDocumentRedlineAccess().SetRedlineFlags_intern(eOld & ~RedlineFlags::Ignore); + SwPaM aPam( *pTableNode->EndOfSectionNode(), *pTableNode, 1 ); + SwContentNode* pCNd = aPam.GetContentNode( false ); + if( pCNd ) + aPam.GetMark()->nContent.Assign( pCNd, 0 ); - rDoc.getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline( *m_pRedlineData, aPam ), true); - rDoc.getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld ); - } - else - rDoc.getIDocumentRedlineAccess().SplitRedline( aPam ); + if( m_pRedlineData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() ) ) + { + RedlineFlags eOld = rDoc.getIDocumentRedlineAccess().GetRedlineFlags(); + rDoc.getIDocumentRedlineAccess().SetRedlineFlags_intern(eOld & ~RedlineFlags::Ignore); + + rDoc.getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline( *m_pRedlineData, aPam ), true); + rDoc.getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld ); } + else + rDoc.getIDocumentRedlineAccess().SplitRedline( aPam ); } void SwUndoInsTable::RepeatImpl(::sw::RepeatContext & rContext) diff --git a/sw/source/core/undo/untblk.cxx b/sw/source/core/undo/untblk.cxx index f6e74518a8c3..8c706cd22836 100644 --- a/sw/source/core/undo/untblk.cxx +++ b/sw/source/core/undo/untblk.cxx @@ -135,31 +135,31 @@ void SwUndoInserts::SetInsertRange( const SwPaM& rPam, bool bScanFlys, // Fill m_FlyUndos with flys anchored to first and last paragraphs - if( bScanFlys) + if( !bScanFlys) + return; + + // than collect all new Flys + SwDoc* pDoc = rPam.GetDoc(); + const size_t nArrLen = pDoc->GetSpzFrameFormats()->size(); + for( size_t n = 0; n < nArrLen; ++n ) { - // than collect all new Flys - SwDoc* pDoc = rPam.GetDoc(); - const size_t nArrLen = pDoc->GetSpzFrameFormats()->size(); - for( size_t n = 0; n < nArrLen; ++n ) + SwFrameFormat* pFormat = (*pDoc->GetSpzFrameFormats())[n]; + SwFormatAnchor const*const pAnchor = &pFormat->GetAnchor(); + if (IsCreateUndoForNewFly(*pAnchor, m_nSttNode, m_nEndNode)) { - SwFrameFormat* pFormat = (*pDoc->GetSpzFrameFormats())[n]; - SwFormatAnchor const*const pAnchor = &pFormat->GetAnchor(); - if (IsCreateUndoForNewFly(*pAnchor, m_nSttNode, m_nEndNode)) + std::vector<SwFrameFormat*>::iterator it; + if( !m_pFrameFormats || + m_pFrameFormats->end() == ( it = std::find( m_pFrameFormats->begin(), m_pFrameFormats->end(), pFormat ) ) ) { - std::vector<SwFrameFormat*>::iterator it; - if( !m_pFrameFormats || - m_pFrameFormats->end() == ( it = std::find( m_pFrameFormats->begin(), m_pFrameFormats->end(), pFormat ) ) ) - { - std::shared_ptr<SwUndoInsLayFormat> const pFlyUndo = - std::make_shared<SwUndoInsLayFormat>(pFormat, 0, 0); - m_FlyUndos.push_back(pFlyUndo); - } - else - m_pFrameFormats->erase( it ); + std::shared_ptr<SwUndoInsLayFormat> const pFlyUndo = + std::make_shared<SwUndoInsLayFormat>(pFormat, 0, 0); + m_FlyUndos.push_back(pFlyUndo); } + else + m_pFrameFormats->erase( it ); } - m_pFrameFormats.reset(); } + m_pFrameFormats.reset(); } /** This is not the same as IsDestroyFrameAnchoredAtChar() @@ -323,46 +323,46 @@ void SwUndoInserts::UndoImpl(::sw::UndoRedoContext & rContext) SwNodeIndex& rIdx = rPam.GetPoint()->nNode; SwTextNode* pTextNode = rIdx.GetNode().GetTextNode(); - if( pTextNode ) + if( !pTextNode ) + return; + + if( !m_pTextFormatColl ) // if 0 than it's no TextNode -> delete { - if( !m_pTextFormatColl ) // if 0 than it's no TextNode -> delete + SwNodeIndex aDelIdx( rIdx ); + assert(0 < m_nDeleteTextNodes && m_nDeleteTextNodes < 3); + for (int i = 0; i < m_nDeleteTextNodes; ++i) { - SwNodeIndex aDelIdx( rIdx ); - assert(0 < m_nDeleteTextNodes && m_nDeleteTextNodes < 3); - for (int i = 0; i < m_nDeleteTextNodes; ++i) - { - rPam.Move(fnMoveForward, GoInNode); - } - rPam.DeleteMark(); - - for (int i = 0; i < m_nDeleteTextNodes; ++i) - { - RemoveIdxRel(aDelIdx.GetIndex() + i, *rPam.GetPoint()); - } + rPam.Move(fnMoveForward, GoInNode); + } + rPam.DeleteMark(); - rDoc.GetNodes().Delete( aDelIdx, m_nDeleteTextNodes ); + for (int i = 0; i < m_nDeleteTextNodes; ++i) + { + RemoveIdxRel(aDelIdx.GetIndex() + i, *rPam.GetPoint()); } - else + + rDoc.GetNodes().Delete( aDelIdx, m_nDeleteTextNodes ); + } + else + { + if( bJoinNext && pTextNode->CanJoinNext()) { - if( bJoinNext && pTextNode->CanJoinNext()) { - { - RemoveIdxRel( rIdx.GetIndex()+1, SwPosition( rIdx, - SwIndex( pTextNode, pTextNode->GetText().getLength() ))); - } - pTextNode->JoinNext(); + RemoveIdxRel( rIdx.GetIndex()+1, SwPosition( rIdx, + SwIndex( pTextNode, pTextNode->GetText().getLength() ))); } - // reset all text attributes in the paragraph! - pTextNode->RstTextAttr( SwIndex(pTextNode, 0), pTextNode->Len(), 0, nullptr, true ); + pTextNode->JoinNext(); + } + // reset all text attributes in the paragraph! + pTextNode->RstTextAttr( SwIndex(pTextNode, 0), pTextNode->Len(), 0, nullptr, true ); - pTextNode->ResetAllAttr(); + pTextNode->ResetAllAttr(); - if (rDoc.GetTextFormatColls()->IsAlive(m_pTextFormatColl)) - m_pTextFormatColl = static_cast<SwTextFormatColl*>(pTextNode->ChgFormatColl( m_pTextFormatColl )) ; + if (rDoc.GetTextFormatColls()->IsAlive(m_pTextFormatColl)) + m_pTextFormatColl = static_cast<SwTextFormatColl*>(pTextNode->ChgFormatColl( m_pTextFormatColl )) ; - m_pHistory->SetTmpEnd( m_nSetPos ); - m_pHistory->TmpRollback(&rDoc, 0, false); - } + m_pHistory->SetTmpEnd( m_nSetPos ); + m_pHistory->TmpRollback(&rDoc, 0, false); } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits