sw/inc/IDocumentUndoRedo.hxx | 3 sw/inc/swtable.hxx | 4 sw/source/core/crsr/annotationmark.cxx | 2 sw/source/core/crsr/bookmrk.cxx | 4 sw/source/core/doc/DocumentContentOperationsManager.cxx | 99 ++++----- sw/source/core/doc/DocumentFieldsManager.cxx | 8 sw/source/core/doc/DocumentLayoutManager.cxx | 8 sw/source/core/doc/DocumentRedlineManager.cxx | 18 - sw/source/core/doc/doc.cxx | 13 - sw/source/core/doc/docbm.cxx | 2 sw/source/core/doc/doccomp.cxx | 23 +- sw/source/core/doc/docdesc.cxx | 10 sw/source/core/doc/docdraw.cxx | 21 -- sw/source/core/doc/docfly.cxx | 6 sw/source/core/doc/docfmt.cxx | 92 ++++---- sw/source/core/doc/docftn.cxx | 14 - sw/source/core/doc/doclay.cxx | 22 +- sw/source/core/doc/docnum.cxx | 53 ++--- sw/source/core/doc/docsort.cxx | 6 sw/source/core/doc/doctxm.cxx | 2 sw/source/core/doc/tblrwcl.cxx | 28 +- sw/source/core/docnode/ndsect.cxx | 4 sw/source/core/docnode/ndtbl.cxx | 167 ++++++---------- sw/source/core/docnode/ndtbl1.cxx | 14 - sw/source/core/edit/edfcol.cxx | 8 sw/source/core/inc/UndoAttribute.hxx | 2 sw/source/core/inc/UndoManager.hxx | 2 sw/source/core/inc/UndoSection.hxx | 4 sw/source/core/undo/docundo.cxx | 4 sw/source/core/undo/undraw.cxx | 2 sw/source/core/undo/unins.cxx | 2 sw/source/core/undo/unsect.cxx | 8 sw/source/core/undo/untbl.cxx | 11 - sw/source/filter/basflt/shellio.cxx | 8 sw/source/uibase/docvw/AnnotationWin.cxx | 4 35 files changed, 318 insertions(+), 360 deletions(-)
New commits: commit dbe85d6613f96192417059acb3274e981a57819d Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu Oct 4 13:57:28 2018 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Oct 5 08:08:09 2018 +0200 use std::unique_ptr in sw::IDocumentUndoRedo Change-Id: I504706ff1a3fc11a7a06ebe935f9dbc5323aefe8 Reviewed-on: https://gerrit.libreoffice.org/61369 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/IDocumentUndoRedo.hxx b/sw/inc/IDocumentUndoRedo.hxx index c8890b7b9345..b533a7e647c2 100644 --- a/sw/inc/IDocumentUndoRedo.hxx +++ b/sw/inc/IDocumentUndoRedo.hxx @@ -23,6 +23,7 @@ #include <sal/types.h> #include "swundo.hxx" +#include <memory> class SwRewriter; class SwNodes; @@ -193,7 +194,7 @@ public: @remark calls ClearRedo(), except for SwUndoId::START/SwUndoId::END. @remark does nothing if !DoesUndo(). */ - virtual void AppendUndo(SwUndo *const pUndo) = 0; + virtual void AppendUndo(std::unique_ptr<SwUndo> pUndo) = 0; /** Delete all Redo actions. */ diff --git a/sw/inc/swtable.hxx b/sw/inc/swtable.hxx index 84663b3ca3e4..890f44431638 100644 --- a/sw/inc/swtable.hxx +++ b/sw/inc/swtable.hxx @@ -328,9 +328,9 @@ public: void SetTableChgMode( TableChgMode eMode ) { m_eTableChgMode = eMode; } bool SetColWidth( SwTableBox& rCurrentBox, TableChgWidthHeightType eType, - SwTwips nAbsDiff, SwTwips nRelDiff, SwUndo** ppUndo ); + SwTwips nAbsDiff, SwTwips nRelDiff, std::unique_ptr<SwUndo>* ppUndo ); bool SetRowHeight( SwTableBox& rCurrentBox, TableChgWidthHeightType eType, - SwTwips nAbsDiff, SwTwips nRelDiff, SwUndo** ppUndo ); + SwTwips nAbsDiff, SwTwips nRelDiff, std::unique_ptr<SwUndo>* ppUndo ); void RegisterToFormat( SwFormat& rFormat ); #ifdef DBG_UTIL void CheckConsistency() const; diff --git a/sw/source/core/crsr/annotationmark.cxx b/sw/source/core/crsr/annotationmark.cxx index c427cba19067..24e413d34839 100644 --- a/sw/source/core/crsr/annotationmark.cxx +++ b/sw/source/core/crsr/annotationmark.cxx @@ -69,7 +69,7 @@ namespace sw { namespace mark if (io_pDoc->GetIDocumentUndoRedo().DoesUndo()) { - io_pDoc->GetIDocumentUndoRedo().AppendUndo( new SwUndoInsBookmark(*this) ); + io_pDoc->GetIDocumentUndoRedo().AppendUndo( o3tl::make_unique<SwUndoInsBookmark>(*this) ); } io_pDoc->getIDocumentState().SetModified(); } diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx index 98ebcdf632fc..827ac187185c 100644 --- a/sw/source/core/crsr/bookmrk.cxx +++ b/sw/source/core/crsr/bookmrk.cxx @@ -297,7 +297,7 @@ namespace sw { namespace mark if (io_pDoc->GetIDocumentUndoRedo().DoesUndo()) { io_pDoc->GetIDocumentUndoRedo().AppendUndo( - new SwUndoInsBookmark(*this)); + o3tl::make_unique<SwUndoInsBookmark>(*this)); } io_pDoc->getIDocumentState().SetModified(); } @@ -309,7 +309,7 @@ namespace sw { namespace mark if (io_pDoc->GetIDocumentUndoRedo().DoesUndo()) { io_pDoc->GetIDocumentUndoRedo().AppendUndo( - new SwUndoDeleteBookmark(*this)); + o3tl::make_unique<SwUndoDeleteBookmark>(*this)); } io_pDoc->getIDocumentState().SetModified(); } diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx index 7fa2ee18f161..679fd7d1f098 100644 --- a/sw/source/core/doc/DocumentContentOperationsManager.cxx +++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx @@ -1672,13 +1672,13 @@ DocumentContentOperationsManager::CopyRange( SwPaM& rPam, SwPosition& rPos, cons // (with start/end nodes clamped) and move them to // the desired position. - SwUndoCpyDoc* pUndo = nullptr; + std::unique_ptr<SwUndoCpyDoc> pUndo; // Save the Undo area SwPaM aPam( rPos ); if (pDoc->GetIDocumentUndoRedo().DoesUndo()) { pDoc->GetIDocumentUndoRedo().ClearRedo(); - pUndo = new SwUndoCpyDoc( aPam ); + pUndo.reset(new SwUndoCpyDoc( aPam )); } { @@ -1711,7 +1711,7 @@ DocumentContentOperationsManager::CopyRange( SwPaM& rPam, SwPosition& rPos, cons if (pDoc->GetIDocumentUndoRedo().DoesUndo()) { pUndo->SetInsertRange( aPam ); - pDoc->GetIDocumentUndoRedo().AppendUndo(pUndo); + pDoc->GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); } if( pRedlineRange ) @@ -1846,11 +1846,11 @@ bool DocumentContentOperationsManager::DelFullPara( SwPaM& rPam ) ::PaMCorrAbs( aDelPam, aTmpPos ); } - SwUndoDelete* pUndo = new SwUndoDelete( aDelPam, true ); + std::unique_ptr<SwUndoDelete> pUndo(new SwUndoDelete( aDelPam, true )); *rPam.GetPoint() = *aDelPam.GetPoint(); pUndo->SetPgBrkFlags( bSavePageBreak, bSavePageDesc ); - m_rDoc.GetIDocumentUndoRedo().AppendUndo(pUndo); + m_rDoc.GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); rPam.DeleteMark(); } else @@ -1955,11 +1955,11 @@ bool DocumentContentOperationsManager::MoveRange( SwPaM& rPaM, SwPosition& rPos, bool bUpdateFootnote = false; SwFootnoteIdxs aTmpFntIdx; - SwUndoMove * pUndoMove = nullptr; + std::unique_ptr<SwUndoMove> pUndoMove; if (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { m_rDoc.GetIDocumentUndoRedo().ClearRedo(); - pUndoMove = new SwUndoMove( rPaM, rPos ); + pUndoMove.reset(new SwUndoMove( rPaM, rPos )); pUndoMove->SetMoveRedlines( eMvFlags == SwMoveFlags::REDLINES ); } else @@ -2074,7 +2074,6 @@ bool DocumentContentOperationsManager::MoveRange( SwPaM& rPaM, SwPosition& rPos, // after a MoveRange() the Mark is deleted if ( rPaM.HasMark() ) // => no Move occurred! { - delete pUndoMove; return false; } } @@ -2136,7 +2135,7 @@ bool DocumentContentOperationsManager::MoveRange( SwPaM& rPaM, SwPosition& rPos, // The newly inserted range is now inbetween SPoint and GetMark. pUndoMove->SetDestRange( aSavePam, *rPaM.GetPoint(), bJoin, bCorrSavePam ); - m_rDoc.GetIDocumentUndoRedo().AppendUndo( pUndoMove ); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( std::move(pUndoMove) ); } else { @@ -2213,10 +2212,10 @@ bool DocumentContentOperationsManager::MoveNodeRange( SwNodeRange& rRange, SwNod bool bUpdateFootnote = false; SwFootnoteIdxs aTmpFntIdx; - SwUndoMove* pUndo = nullptr; + std::unique_ptr<SwUndoMove> pUndo; if ((SwMoveFlags::CREATEUNDOOBJ & eMvFlags ) && m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { - pUndo = new SwUndoMove( &m_rDoc, rRange, rPos ); + pUndo.reset(new SwUndoMove( &m_rDoc, rRange, rPos )); } else { @@ -2277,8 +2276,7 @@ bool DocumentContentOperationsManager::MoveNodeRange( SwNodeRange& rRange, SwNod else { aIdx = rRange.aStart; - delete pUndo; - pUndo = nullptr; + pUndo.reset(); } // move the Flys to the new position @@ -2312,7 +2310,7 @@ bool DocumentContentOperationsManager::MoveNodeRange( SwNodeRange& rRange, SwNod if( pUndo ) { pUndo->SetDestRange( aIdx, rPos, *pSaveInsPos ); - m_rDoc.GetIDocumentUndoRedo().AppendUndo(pUndo); + m_rDoc.GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); } pSaveInsPos.reset(); @@ -2418,8 +2416,8 @@ bool DocumentContentOperationsManager::Overwrite( const SwPaM &rRg, const OUStri } if (!bMerged) { - SwUndo *const pUndoOW( new SwUndoOverwrite(&m_rDoc, rPt, c) ); - m_rDoc.GetIDocumentUndoRedo().AppendUndo(pUndoOW); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoOverwrite>(&m_rDoc, rPt, c) ); } } else @@ -2503,9 +2501,9 @@ bool DocumentContentOperationsManager::InsertString( const SwPaM &rRg, const OUS OUString const ins(pNode->InsertText(rStr, rPos.nContent, nInsertMode)); if (bDoesUndo) { - SwUndoInsert * const pUndo( new SwUndoInsert(rPos.nNode, - rPos.nContent.GetIndex(), ins.getLength(), nInsertMode)); - m_rDoc.GetIDocumentUndoRedo().AppendUndo(pUndo); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoInsert>(rPos.nNode, + rPos.nContent.GetIndex(), ins.getLength(), nInsertMode)); } } else @@ -2531,7 +2529,7 @@ bool DocumentContentOperationsManager::InsertString( const SwPaM &rRg, const OUS { pUndo = new SwUndoInsert( rPos.nNode, nInsPos, 0, nInsertMode, !rCC.isLetterNumeric( rStr, 0 ) ); - m_rDoc.GetIDocumentUndoRedo().AppendUndo( pUndo ); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndo) ); } OUString const ins(pNode->InsertText(rStr, rPos.nContent, nInsertMode)); @@ -2544,7 +2542,7 @@ bool DocumentContentOperationsManager::InsertString( const SwPaM &rRg, const OUS { pUndo = new SwUndoInsert(rPos.nNode, nInsPos, 1, nInsertMode, !rCC.isLetterNumeric(ins, i)); - m_rDoc.GetIDocumentUndoRedo().AppendUndo( pUndo ); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndo) ); } } } @@ -2573,9 +2571,9 @@ void DocumentContentOperationsManager::TransliterateText( const SwPaM& rPaM, utl::TransliterationWrapper& rTrans ) { - SwUndoTransliterate *const pUndo = (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) - ? new SwUndoTransliterate( rPaM, rTrans ) - : nullptr; + std::unique_ptr<SwUndoTransliterate> pUndo; + if (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) + pUndo.reset(new SwUndoTransliterate( rPaM, rTrans )); const SwPosition* pStt = rPaM.Start(), * pEnd = rPaM.End(); @@ -2614,7 +2612,7 @@ void DocumentContentOperationsManager::TransliterateText( ++aIdx; if( pTNd ) pTNd->TransliterateText( - rTrans, nSttCnt, pTNd->GetText().getLength(), pUndo); + rTrans, nSttCnt, pTNd->GetText().getLength(), pUndo.get()); } for( ; aIdx.GetIndex() < nEndNd; ++aIdx ) @@ -2623,24 +2621,22 @@ void DocumentContentOperationsManager::TransliterateText( if (pTNd) { pTNd->TransliterateText( - rTrans, 0, pTNd->GetText().getLength(), pUndo); + rTrans, 0, pTNd->GetText().getLength(), pUndo.get()); } } if( nEndCnt && nullptr != ( pTNd = pEnd->nNode.GetNode().GetTextNode() )) - pTNd->TransliterateText( rTrans, 0, nEndCnt, pUndo ); + pTNd->TransliterateText( rTrans, 0, nEndCnt, pUndo.get() ); } else if( pTNd && nSttCnt < nEndCnt ) - pTNd->TransliterateText( rTrans, nSttCnt, nEndCnt, pUndo ); + pTNd->TransliterateText( rTrans, nSttCnt, nEndCnt, pUndo.get() ); if( pUndo ) { if( pUndo->HasData() ) { - m_rDoc.GetIDocumentUndoRedo().AppendUndo(pUndo); + m_rDoc.GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); } - else - delete pUndo; } m_rDoc.getIDocumentState().SetModified(); } @@ -2729,7 +2725,7 @@ void DocumentContentOperationsManager::ReRead( SwPaM& rPam, const OUString& rGrf { if (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { - m_rDoc.GetIDocumentUndoRedo().AppendUndo(new SwUndoReRead(rPam, *pGrfNd)); + m_rDoc.GetIDocumentUndoRedo().AppendUndo(o3tl::make_unique<SwUndoReRead>(rPam, *pGrfNd)); } // Because we don't know if we can mirror the graphic, the mirror attribute is always reset @@ -2846,7 +2842,7 @@ SwDrawFrameFormat* DocumentContentOperationsManager::InsertDrawObj( if (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { - m_rDoc.GetIDocumentUndoRedo().AppendUndo( new SwUndoInsLayFormat(pFormat, 0, 0) ); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( o3tl::make_unique<SwUndoInsLayFormat>(pFormat, 0, 0) ); } m_rDoc.getIDocumentState().SetModified(); @@ -2873,7 +2869,7 @@ bool DocumentContentOperationsManager::SplitNode( const SwPosition &rPos, bool b if( pNode->IsTextNode() ) { pUndo = new SwUndoSplitNode( &m_rDoc, rPos, bChkTableStart ); - m_rDoc.GetIDocumentUndoRedo().AppendUndo(pUndo); + m_rDoc.GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndo>(pUndo)); } } @@ -3014,7 +3010,7 @@ bool DocumentContentOperationsManager::AppendTextNode( SwPosition& rPos ) if (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { - m_rDoc.GetIDocumentUndoRedo().AppendUndo( new SwUndoInsert( rPos.nNode ) ); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( o3tl::make_unique<SwUndoInsert>( rPos.nNode ) ); } // To-Do - add 'SwExtraRedlineTable' also ? @@ -3120,20 +3116,20 @@ bool DocumentContentOperationsManager::InsertPoolItem( return false; SwDataChanged aTmp( rRg ); - SwUndoAttr* pUndoAttr = nullptr; + std::unique_ptr<SwUndoAttr> pUndoAttr; if (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { m_rDoc.GetIDocumentUndoRedo().ClearRedo(); - pUndoAttr = new SwUndoAttr( rRg, rHt, nFlags ); + pUndoAttr.reset(new SwUndoAttr( rRg, rHt, nFlags )); } SfxItemSet aSet( m_rDoc.GetAttrPool(), {{rHt.Which(), rHt.Which()}} ); aSet.Put( rHt ); - const bool bRet = lcl_InsAttr( &m_rDoc, rRg, aSet, nFlags, pUndoAttr, bExpandCharToPara ); + const bool bRet = lcl_InsAttr( &m_rDoc, rRg, aSet, nFlags, pUndoAttr.get(), bExpandCharToPara ); if (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { - m_rDoc.GetIDocumentUndoRedo().AppendUndo( pUndoAttr ); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( std::move(pUndoAttr) ); } if( bRet ) @@ -3147,18 +3143,18 @@ void DocumentContentOperationsManager::InsertItemSet ( const SwPaM &rRg, const S const SetAttrMode nFlags ) { SwDataChanged aTmp( rRg ); - SwUndoAttr* pUndoAttr = nullptr; + std::unique_ptr<SwUndoAttr> pUndoAttr; if (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { m_rDoc.GetIDocumentUndoRedo().ClearRedo(); - pUndoAttr = new SwUndoAttr( rRg, rSet, nFlags ); + pUndoAttr.reset(new SwUndoAttr( rRg, rSet, nFlags )); } - bool bRet = lcl_InsAttr( &m_rDoc, rRg, rSet, nFlags, pUndoAttr ); + bool bRet = lcl_InsAttr( &m_rDoc, rRg, rSet, nFlags, pUndoAttr.get() ); if (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { - m_rDoc.GetIDocumentUndoRedo().AppendUndo( pUndoAttr ); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( std::move(pUndoAttr) ); } if( bRet ) @@ -3665,7 +3661,7 @@ bool DocumentContentOperationsManager::DeleteAndJoinWithRedlineImpl( SwPaM & rPa && pUndoRedlineDel->CanGrouping(*undos.front()); if (!bMerged) { - m_rDoc.GetIDocumentUndoRedo().AppendUndo(undos.front().release()); + m_rDoc.GetIDocumentUndoRedo().AppendUndo(std::move(undos.front())); } undos.clear(); // prevent unmatched EndUndo } @@ -3674,11 +3670,11 @@ bool DocumentContentOperationsManager::DeleteAndJoinWithRedlineImpl( SwPaM & rPa m_rDoc.GetIDocumentUndoRedo().StartUndo(SwUndoId::DELETE, &aRewriter); for (auto& it : MarkUndos) { - m_rDoc.GetIDocumentUndoRedo().AppendUndo(it.release()); + m_rDoc.GetIDocumentUndoRedo().AppendUndo(std::move(it)); } for (auto & it : undos) { - m_rDoc.GetIDocumentUndoRedo().AppendUndo(it.release()); + m_rDoc.GetIDocumentUndoRedo().AppendUndo(std::move(it)); } } } @@ -3819,7 +3815,7 @@ bool DocumentContentOperationsManager::DeleteRangeImplImpl(SwPaM & rPam) } if (!bMerged) { - m_rDoc.GetIDocumentUndoRedo().AppendUndo( new SwUndoDelete( rPam ) ); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( o3tl::make_unique<SwUndoDelete>( rPam ) ); } m_rDoc.getIDocumentState().SetModified(); @@ -4059,9 +4055,8 @@ bool DocumentContentOperationsManager::ReplaceRangeImpl( SwPaM& rPam, const OUSt if (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { - SwUndo *const pUndoRD = - new SwUndoRedlineDelete( aDelPam, SwUndoId::REPLACE ); - m_rDoc.GetIDocumentUndoRedo().AppendUndo(pUndoRD); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoRedlineDelete>( aDelPam, SwUndoId::REPLACE )); } m_rDoc.getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline( nsRedlineType_t::REDLINE_DELETE, aDelPam ), true); @@ -4103,7 +4098,7 @@ bool DocumentContentOperationsManager::ReplaceRangeImpl( SwPaM& rPam, const OUSt if (bDoesUndo) { pUndoRpl = new SwUndoReplace(aDelPam, sRepl, bRegExReplace); - m_rDoc.GetIDocumentUndoRedo().AppendUndo(pUndoRpl); + m_rDoc.GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndo>(pUndoRpl)); } ::sw::UndoGuard const undoGuard(m_rDoc.GetIDocumentUndoRedo()); @@ -4292,7 +4287,7 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos, if (pDoc->GetIDocumentUndoRedo().DoesUndo()) { pUndo = new SwUndoCpyDoc(*pCopyPam); - pDoc->GetIDocumentUndoRedo().AppendUndo( pUndo ); + pDoc->GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndo) ); } RedlineFlags eOld = pDoc->getIDocumentRedlineAccess().GetRedlineFlags(); diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx index 208b467a41c0..d024ea9117fc 100644 --- a/sw/source/core/doc/DocumentFieldsManager.cxx +++ b/sw/source/core/doc/DocumentFieldsManager.cxx @@ -464,8 +464,8 @@ void DocumentFieldsManager::PutValueToField(const SwPosition & rPos, if (m_rDoc.GetIDocumentUndoRedo().DoesUndo() && pField->QueryValue(aOldVal, nWhich)) { - SwUndo *const pUndo(new SwUndoFieldFromAPI(rPos, aOldVal, rVal, nWhich)); - m_rDoc.GetIDocumentUndoRedo().AppendUndo(pUndo); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoFieldFromAPI>(rPos, aOldVal, rVal, nWhich)); } pField->PutValue(rVal, nWhich); @@ -492,8 +492,8 @@ bool DocumentFieldsManager::UpdateField(SwTextField * pDstTextField, SwField & r SwPosition aPosition( pDstTextField->GetTextNode() ); aPosition.nContent = pDstTextField->GetStart(); - SwUndo *const pUndo( new SwUndoFieldFromDoc( aPosition, *pDstField, rSrcField, pMsgHint, bUpdateFields) ); - m_rDoc.GetIDocumentUndoRedo().AppendUndo(pUndo); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoFieldFromDoc>( aPosition, *pDstField, rSrcField, pMsgHint, bUpdateFields) ); } pDstFormatField->SetField(rSrcField.CopyField()); diff --git a/sw/source/core/doc/DocumentLayoutManager.cxx b/sw/source/core/doc/DocumentLayoutManager.cxx index 41af5c59c46e..cf4333877032 100644 --- a/sw/source/core/doc/DocumentLayoutManager.cxx +++ b/sw/source/core/doc/DocumentLayoutManager.cxx @@ -163,7 +163,7 @@ SwFrameFormat *DocumentLayoutManager::MakeLayoutFormat( RndStdIds eRequest, cons if (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { m_rDoc.GetIDocumentUndoRedo().AppendUndo( - new SwUndoInsLayFormat(pFormat, 0, 0)); + o3tl::make_unique<SwUndoInsLayFormat>(pFormat, 0, 0)); } } break; @@ -233,7 +233,7 @@ void DocumentLayoutManager::DelLayoutFormat( SwFrameFormat *pFormat ) if (m_rDoc.GetIDocumentUndoRedo().DoesUndo() && (RES_FLYFRMFMT == nWh || RES_DRAWFRMFMT == nWh)) { - m_rDoc.GetIDocumentUndoRedo().AppendUndo( new SwUndoDelLayFormat( pFormat )); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( o3tl::make_unique<SwUndoDelLayFormat>( pFormat )); } else { @@ -416,7 +416,7 @@ SwFrameFormat *DocumentLayoutManager::CopyLayoutFormat( if (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { - m_rDoc.GetIDocumentUndoRedo().AppendUndo(new SwUndoInsLayFormat(pDest,0,0)); + m_rDoc.GetIDocumentUndoRedo().AppendUndo(o3tl::make_unique<SwUndoInsLayFormat>(pDest,0,0)); } // Make sure that FlyFrames in FlyFrames are copied @@ -446,7 +446,7 @@ SwFrameFormat *DocumentLayoutManager::CopyLayoutFormat( if (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { - m_rDoc.GetIDocumentUndoRedo().AppendUndo(new SwUndoInsLayFormat(pDest,0,0)); + m_rDoc.GetIDocumentUndoRedo().AppendUndo(o3tl::make_unique<SwUndoInsLayFormat>(pDest,0,0)); } } diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx index a5407a511def..5f94d27311c1 100644 --- a/sw/source/core/doc/DocumentRedlineManager.cxx +++ b/sw/source/core/doc/DocumentRedlineManager.cxx @@ -2060,13 +2060,11 @@ bool DocumentRedlineManager::DeleteRedline( const SwPaM& rRange, bool bSaveInUnd if (bSaveInUndo && m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { - SwUndoRedline* pUndo = new SwUndoRedline( SwUndoId::REDLINE, rRange ); + std::unique_ptr<SwUndoRedline> pUndo(new SwUndoRedline( SwUndoId::REDLINE, rRange )); if( pUndo->GetRedlSaveCount() ) { - m_rDoc.GetIDocumentUndoRedo().AppendUndo(pUndo); + m_rDoc.GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); } - else - delete pUndo; } const SwPosition* pStt = rRange.Start(), @@ -2297,8 +2295,8 @@ bool DocumentRedlineManager::AcceptRedline( SwRedlineTable::size_type nPos, bool if (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { - SwUndo *const pUndo( new SwUndoAcceptRedline(*pTmp) ); - m_rDoc.GetIDocumentUndoRedo().AppendUndo(pUndo); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoAcceptRedline>(*pTmp) ); } bRet |= lcl_AcceptRedline( *mpRedlineTable, nPos, bCallDelete ); @@ -2354,7 +2352,7 @@ bool DocumentRedlineManager::AcceptRedline( const SwPaM& rPam, bool bCallDelete if (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { m_rDoc.GetIDocumentUndoRedo().StartUndo( SwUndoId::ACCEPT_REDLINE, nullptr ); - m_rDoc.GetIDocumentUndoRedo().AppendUndo( new SwUndoAcceptRedline( aPam )); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( o3tl::make_unique<SwUndoAcceptRedline>( aPam )); } int nRet = lcl_AcceptRejectRedl( lcl_AcceptRedline, *mpRedlineTable, @@ -2436,8 +2434,8 @@ bool DocumentRedlineManager::RejectRedline( SwRedlineTable::size_type nPos, bool if (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { - SwUndo *const pUndo( new SwUndoRejectRedline( *pTmp ) ); - m_rDoc.GetIDocumentUndoRedo().AppendUndo(pUndo); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoRejectRedline>( *pTmp ) ); } bRet |= lcl_RejectRedline( *mpRedlineTable, nPos, bCallDelete ); @@ -2493,7 +2491,7 @@ bool DocumentRedlineManager::RejectRedline( const SwPaM& rPam, bool bCallDelete if (m_rDoc.GetIDocumentUndoRedo().DoesUndo()) { m_rDoc.GetIDocumentUndoRedo().StartUndo( SwUndoId::REJECT_REDLINE, nullptr ); - m_rDoc.GetIDocumentUndoRedo().AppendUndo( new SwUndoRejectRedline(aPam) ); + m_rDoc.GetIDocumentUndoRedo().AppendUndo( o3tl::make_unique<SwUndoRejectRedline>(aPam) ); } int nRet = lcl_AcceptRejectRedl( lcl_RejectRedline, *mpRedlineTable, diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx index be3f1947d9b9..66286f9bc971 100644 --- a/sw/source/core/doc/doc.cxx +++ b/sw/source/core/doc/doc.cxx @@ -1712,16 +1712,16 @@ void SwDoc::AppendUndoForInsertFromDB( const SwPaM& rPam, bool bIsTable ) const SwTableNode* pTableNd = rPam.GetPoint()->nNode.GetNode().FindTableNode(); if( pTableNd ) { - SwUndoCpyTable* pUndo = new SwUndoCpyTable(this); + std::unique_ptr<SwUndoCpyTable> pUndo(new SwUndoCpyTable(this)); pUndo->SetTableSttIdx( pTableNd->GetIndex() ); - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } } else if( rPam.HasMark() ) { - SwUndoCpyDoc* pUndo = new SwUndoCpyDoc( rPam ); + std::unique_ptr<SwUndoCpyDoc> pUndo(new SwUndoCpyDoc( rPam )); pUndo->SetInsertRange( rPam, false ); - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } } @@ -1731,9 +1731,8 @@ void SwDoc::ChgTOX(SwTOXBase & rTOX, const SwTOXBase & rNew) { GetIDocumentUndoRedo().DelAllUndoObj(); - SwUndo * pUndo = new SwUndoTOXChange(this, &rTOX, rNew); - - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoTOXChange>(this, &rTOX, rNew)); } rTOX = rNew; diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx index ac55e203a51c..7782dfe290f6 100644 --- a/sw/source/core/doc/docbm.cxx +++ b/sw/source/core/doc/docbm.cxx @@ -584,7 +584,7 @@ namespace sw { namespace mark if (m_pDoc->GetIDocumentUndoRedo().DoesUndo()) { m_pDoc->GetIDocumentUndoRedo().AppendUndo( - new SwUndoRenameBookmark(sOldName, rNewName, m_pDoc)); + o3tl::make_unique<SwUndoRenameBookmark>(sOldName, rNewName, m_pDoc)); } m_pDoc->getIDocumentState().SetModified(); } diff --git a/sw/source/core/doc/doccomp.cxx b/sw/source/core/doc/doccomp.cxx index 6d7bcff2b5b8..b322e36d7cba 100644 --- a/sw/source/core/doc/doccomp.cxx +++ b/sw/source/core/doc/doccomp.cxx @@ -1664,8 +1664,8 @@ void CompareData::SetRedlinesToDoc( bool bUseDocInfo ) if (rDoc.GetIDocumentUndoRedo().DoesUndo()) { - SwUndo *const pUndo(new SwUndoCompDoc( *pTmp, false )) ; - rDoc.GetIDocumentUndoRedo().AppendUndo(pUndo); + rDoc.GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoCompDoc>( *pTmp, false )); } rDoc.getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline( aRedlnData, *pTmp ), true ); @@ -1744,8 +1744,8 @@ void CompareData::SetRedlinesToDoc( bool bUseDocInfo ) new SwRangeRedline(aRedlnData, *pTmp), true) && rDoc.GetIDocumentUndoRedo().DoesUndo()) { - SwUndo *const pUndo(new SwUndoCompDoc( *pTmp, true )); - rDoc.GetIDocumentUndoRedo().AppendUndo(pUndo); + rDoc.GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoCompDoc>( *pTmp, true )); } } while( pInsRing.get() != ( pTmp = pTmp->GetNext()) ); } @@ -1984,15 +1984,15 @@ sal_uInt16 SaveMergeRedline::InsertRedline(SwPaM* pLastDestRedline) pCpyRedl->SetMark(); *pCpyRedl->GetPoint() = *pRStt; - SwUndoCompDoc *const pUndo = - (pDoc->GetIDocumentUndoRedo().DoesUndo()) - ? new SwUndoCompDoc( *pCpyRedl ) : nullptr; + std::unique_ptr<SwUndoCompDoc> pUndo; + if (pDoc->GetIDocumentUndoRedo().DoesUndo()) + pUndo.reset(new SwUndoCompDoc( *pCpyRedl )); // now modify doc: append redline, undo (and count) pDoc->getIDocumentRedlineAccess().AppendRedline( pCpyRedl, true ); if( pUndo ) { - pDoc->GetIDocumentUndoRedo().AppendUndo(pUndo); + pDoc->GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); } ++nIns; @@ -2020,15 +2020,16 @@ sal_uInt16 SaveMergeRedline::InsertRedline(SwPaM* pLastDestRedline) if( pDestRedl ) { - SwUndoCompDoc *const pUndo = (pDoc->GetIDocumentUndoRedo().DoesUndo()) - ? new SwUndoCompDoc( *pDestRedl ) : nullptr; + std::unique_ptr<SwUndoCompDoc> pUndo; + if (pDoc->GetIDocumentUndoRedo().DoesUndo()) + pUndo.reset(new SwUndoCompDoc( *pDestRedl )); // now modify doc: append redline, undo (and count) IDocumentRedlineAccess::AppendResult const result( pDoc->getIDocumentRedlineAccess().AppendRedline(pDestRedl, true)); if( pUndo ) { - pDoc->GetIDocumentUndoRedo().AppendUndo( pUndo ); + pDoc->GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } ++nIns; diff --git a/sw/source/core/doc/docdesc.cxx b/sw/source/core/doc/docdesc.cxx index 7ccfb2b58328..d64aeaccebc2 100644 --- a/sw/source/core/doc/docdesc.cxx +++ b/sw/source/core/doc/docdesc.cxx @@ -390,8 +390,8 @@ void SwDoc::ChgPageDesc( size_t i, const SwPageDesc &rChged ) if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo *const pUndo(new SwUndoPageDesc(rDesc, rChged, this)); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoPageDesc>(rDesc, rChged, this)); } ::sw::UndoGuard const undoGuard(GetIDocumentUndoRedo()); @@ -631,8 +631,8 @@ void SwDoc::DelPageDesc( size_t i, bool bBroadcast ) if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo *const pUndo(new SwUndoPageDescDelete(rDel, this)); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoPageDescDelete>(rDel, this)); } PreDelPageDesc(&rDel); // #i7983# @@ -681,7 +681,7 @@ SwPageDesc* SwDoc::MakePageDesc(const OUString &rName, const SwPageDesc *pCpy, if (GetIDocumentUndoRedo().DoesUndo()) { - GetIDocumentUndoRedo().AppendUndo(new SwUndoPageDescCreate(pNew, this)); + GetIDocumentUndoRedo().AppendUndo(o3tl::make_unique<SwUndoPageDescCreate>(pNew, this)); } getIDocumentState().SetModified(); diff --git a/sw/source/core/doc/docdraw.cxx b/sw/source/core/doc/docdraw.cxx index 07d024a3619e..18f59510ed43 100644 --- a/sw/source/core/doc/docdraw.cxx +++ b/sw/source/core/doc/docdraw.cxx @@ -213,9 +213,9 @@ SwDrawContact* SwDoc::GroupSelection( SdrView& rDrawView ) SwDrawContact *pMyContact = static_cast<SwDrawContact*>(GetUserCall(pObj)); const SwFormatAnchor aAnch( pMyContact->GetFormat()->GetAnchor() ); - SwUndoDrawGroup *const pUndo = (!GetIDocumentUndoRedo().DoesUndo()) - ? nullptr - : new SwUndoDrawGroup( static_cast<sal_uInt16>(rMrkList.GetMarkCount()) , this); + std::unique_ptr<SwUndoDrawGroup> pUndo; + if (GetIDocumentUndoRedo().DoesUndo()) + pUndo.reset(new SwUndoDrawGroup( static_cast<sal_uInt16>(rMrkList.GetMarkCount()) , this)); // #i53320# bool bGroupMembersNotPositioned( false ); @@ -282,7 +282,7 @@ SwDrawContact* SwDoc::GroupSelection( SdrView& rDrawView ) if( pUndo ) { pUndo->SetGroupFormat( pFormat ); - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } } else @@ -333,7 +333,7 @@ void SwDoc::UnGroupSelection( SdrView& rDrawView ) if( bUndo ) { pUndo = new SwUndoDrawUnGroup( static_cast<SdrObjGroup*>(pObj), this ); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndo>(pUndo)); } for ( size_t i2 = 0; i2 < pLst->GetObjCount(); ++i2 ) @@ -363,7 +363,7 @@ void SwDoc::UnGroupSelection( SdrView& rDrawView ) if( bUndo ) { pUndo = new SwUndoDrawUnGroupConnectToLayout(this); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndo>(pUndo)); } while ( pFormatsAndObjs[i].size() > 0 ) @@ -431,10 +431,9 @@ bool SwDoc::DeleteSelection( SwDrawView& rDrawView ) SdrObject *pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj(); if( !pObj->getParentSdrObjectFromSdrObject() ) { - SwUndoDrawDelete *const pUndo = - (!GetIDocumentUndoRedo().DoesUndo()) - ? nullptr - : new SwUndoDrawDelete( static_cast<sal_uInt16>(rMrkList.GetMarkCount()), this ); + std::unique_ptr<SwUndoDrawDelete> pUndo; + if (GetIDocumentUndoRedo().DoesUndo()) + pUndo.reset(new SwUndoDrawDelete( static_cast<sal_uInt16>(rMrkList.GetMarkCount()), this )); // Destroy ContactObjects, save formats. for( size_t i = 0; i < rMrkList.GetMarkCount(); ++i ) @@ -466,7 +465,7 @@ bool SwDoc::DeleteSelection( SwDrawView& rDrawView ) if( pUndo ) { - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } } bCallBase = true; diff --git a/sw/source/core/doc/docfly.cxx b/sw/source/core/doc/docfly.cxx index 404298868882..63d437e77f42 100644 --- a/sw/source/core/doc/docfly.cxx +++ b/sw/source/core/doc/docfly.cxx @@ -589,7 +589,7 @@ void SwDoc::SetFlyFrameTitle( SwFlyFrameFormat& rFlyFrameFormat, if (GetIDocumentUndoRedo().DoesUndo()) { - GetIDocumentUndoRedo().AppendUndo( new SwUndoFlyStrAttr( rFlyFrameFormat, + GetIDocumentUndoRedo().AppendUndo( o3tl::make_unique<SwUndoFlyStrAttr>( rFlyFrameFormat, SwUndoId::FLYFRMFMT_TITLE, rFlyFrameFormat.GetObjTitle(), sNewTitle ) ); @@ -612,7 +612,7 @@ void SwDoc::SetFlyFrameDescription( SwFlyFrameFormat& rFlyFrameFormat, if (GetIDocumentUndoRedo().DoesUndo()) { - GetIDocumentUndoRedo().AppendUndo( new SwUndoFlyStrAttr( rFlyFrameFormat, + GetIDocumentUndoRedo().AppendUndo( o3tl::make_unique<SwUndoFlyStrAttr>( rFlyFrameFormat, SwUndoId::FLYFRMFMT_DESCRIPTION, rFlyFrameFormat.GetObjDescription(), sNewDescription ) ); @@ -635,7 +635,7 @@ bool SwDoc::SetFrameFormatToFly( SwFrameFormat& rFormat, SwFrameFormat& rNewForm if (bUndo) { pUndo = new SwUndoSetFlyFormat( rFormat, rNewFormat ); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndo>(pUndo)); } // #i32968# Inserting columns in the section causes MakeFrameFormat to put diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx index 0300c658262f..b2f0a2de4add 100644 --- a/sw/source/core/doc/docfmt.cxx +++ b/sw/source/core/doc/docfmt.cxx @@ -230,9 +230,9 @@ void SwDoc::RstTextAttrs(const SwPaM &rRg, bool bInclRefToxMark, bool bExactRang SwDataChanged aTmp( rRg ); if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndoResetAttr* pUndo = new SwUndoResetAttr( rRg, RES_CHRFMT ); + std::unique_ptr<SwUndoResetAttr> pUndo(new SwUndoResetAttr( rRg, RES_CHRFMT )); pHst = &pUndo->GetHistory(); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); } const SwPosition *pStt = rRg.Start(), *pEnd = rRg.End(); sw::DocumentContentOperationsManager::ParaRstFormat aPara( pStt, pEnd, pHst ); @@ -307,14 +307,14 @@ void SwDoc::ResetAttrs( const SwPaM &rRg, SwHistory* pHst = nullptr; if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndoResetAttr* pUndo = new SwUndoResetAttr( rRg, - bTextAttr ? sal_uInt16(RES_CONDTXTFMTCOLL) : sal_uInt16(RES_TXTFMTCOLL) ); + std::unique_ptr<SwUndoResetAttr> pUndo(new SwUndoResetAttr( rRg, + bTextAttr ? sal_uInt16(RES_CONDTXTFMTCOLL) : sal_uInt16(RES_TXTFMTCOLL) )); if( !rAttrs.empty() ) { pUndo->SetAttrs( rAttrs ); } pHst = &pUndo->GetHistory(); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); } const SwPosition *pStt = pPam->Start(), *pEnd = pPam->End(); @@ -497,9 +497,9 @@ void SwDoc::SetAttr( const SfxItemSet& rSet, SwFormat& rFormat ) void SwDoc::ResetAttrAtFormat( const sal_uInt16 nWhichId, SwFormat& rChangedFormat ) { - SwUndo *const pUndo = (GetIDocumentUndoRedo().DoesUndo()) - ? new SwUndoFormatResetAttr( rChangedFormat, nWhichId ) - : nullptr; + std::unique_ptr<SwUndo> pUndo; + if (GetIDocumentUndoRedo().DoesUndo()) + pUndo.reset(new SwUndoFormatResetAttr( rChangedFormat, nWhichId )); const bool bAttrReset = rChangedFormat.ResetFormatAttr( nWhichId ); @@ -507,13 +507,11 @@ void SwDoc::ResetAttrAtFormat( const sal_uInt16 nWhichId, { if ( pUndo ) { - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } getIDocumentState().SetModified(); } - else - delete pUndo; } static bool lcl_SetNewDefTabStops( SwTwips nOldWidth, SwTwips nNewWidth, @@ -619,7 +617,7 @@ void SwDoc::SetDefault( const SfxItemSet& rSet ) { if (GetIDocumentUndoRedo().DoesUndo()) { - GetIDocumentUndoRedo().AppendUndo( new SwUndoDefaultAttr( aOld, this ) ); + GetIDocumentUndoRedo().AppendUndo( o3tl::make_unique<SwUndoDefaultAttr>( aOld, this ) ); } const SfxPoolItem* pTmpItem; @@ -684,10 +682,8 @@ void SwDoc::DelCharFormat(size_t nFormat, bool bBroadcast) if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo * pUndo = - new SwUndoCharFormatDelete(pDel, this); - - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoCharFormatDelete>(pDel, this)); } delete (*mpCharFormatTable)[nFormat]; @@ -723,9 +719,8 @@ void SwDoc::DelFrameFormat( SwFrameFormat *pFormat, bool bBroadcast ) if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo * pUndo = new SwUndoFrameFormatDelete(pFormat, this); - - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoFrameFormatDelete>(pFormat, this)); } mpFrameFormatTable->erase( pFormat ); @@ -834,9 +829,8 @@ SwFrameFormat *SwDoc::MakeFrameFormat(const OUString &rFormatName, if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo * pUndo = new SwUndoFrameFormatCreate(pFormat, pDerivedFrom, this); - - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoFrameFormatCreate>(pFormat, pDerivedFrom, this)); } if (bBroadcast) @@ -868,9 +862,8 @@ SwCharFormat *SwDoc::MakeCharFormat( const OUString &rFormatName, if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo * pUndo = new SwUndoCharFormatCreate(pFormat, pDerivedFrom, this); - - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoCharFormatCreate>(pFormat, pDerivedFrom, this)); } if (bBroadcast) @@ -904,9 +897,9 @@ SwTextFormatColl* SwDoc::MakeTextFormatColl( const OUString &rFormatName, if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo * pUndo = new SwUndoTextFormatCollCreate(pFormatColl, pDerivedFrom, - this); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoTextFormatCollCreate>(pFormatColl, pDerivedFrom, + this)); } if (bBroadcast) @@ -938,9 +931,9 @@ SwConditionTextFormatColl* SwDoc::MakeCondTextFormatColl( const OUString &rForma if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo * pUndo = new SwUndoCondTextFormatCollCreate(pFormatColl, pDerivedFrom, - this); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoCondTextFormatCollCreate>(pFormatColl, pDerivedFrom, + this)); } if (bBroadcast) @@ -978,17 +971,17 @@ void SwDoc::DelTextFormatColl(size_t nFormatColl, bool bBroadcast) if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndoTextFormatCollDelete * pUndo; + std::unique_ptr<SwUndoTextFormatCollDelete> pUndo; if (RES_CONDTXTFMTCOLL == pDel->Which()) { - pUndo = new SwUndoCondTextFormatCollDelete(pDel, this); + pUndo.reset(new SwUndoCondTextFormatCollDelete(pDel, this)); } else { - pUndo = new SwUndoTextFormatCollDelete(pDel, this); + pUndo.reset(new SwUndoTextFormatCollDelete(pDel, this)); } - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); } // Remove the FormatColl @@ -1087,11 +1080,11 @@ bool SwDoc::SetTextFormatColl(const SwPaM &rRg, if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndoFormatColl* pUndo = new SwUndoFormatColl( rRg, pFormat, + std::unique_ptr<SwUndoFormatColl> pUndo(new SwUndoFormatColl( rRg, pFormat, bReset, - bResetListAttrs ); + bResetListAttrs )); pHst = pUndo->GetHistory(); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); } sw::DocumentContentOperationsManager::ParaRstFormat aPara( pStt, pEnd, pHst ); @@ -1627,10 +1620,10 @@ void SwDoc::MoveLeftMargin( const SwPaM& rPam, bool bRight, bool bModulus ) SwHistory* pHistory = nullptr; if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndoMoveLeftMargin* pUndo = new SwUndoMoveLeftMargin( rPam, bRight, - bModulus ); + std::unique_ptr<SwUndoMoveLeftMargin> pUndo(new SwUndoMoveLeftMargin( rPam, bRight, + bModulus )); pHistory = &pUndo->GetHistory(); - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } const SvxTabStopItem& rTabItem = GetDefault( RES_PARATR_TABSTOP ); @@ -1692,7 +1685,7 @@ bool SwDoc::DontExpandFormat( const SwPosition& rPos, bool bFlag ) bRet = pTextNd->DontExpandFormat( rPos.nContent, bFlag ); if( bRet && GetIDocumentUndoRedo().DoesUndo() ) { - GetIDocumentUndoRedo().AppendUndo( new SwUndoDontExpandFormat(rPos) ); + GetIDocumentUndoRedo().AppendUndo( o3tl::make_unique<SwUndoDontExpandFormat>(rPos) ); } } return bRet; @@ -1870,9 +1863,8 @@ void SwDoc::ChgFormat(SwFormat & rFormat, const SfxItemSet & rSet) } } - SwUndo * pUndo = new SwUndoFormatAttr(aOldSet, rFormat, /*bSaveDrawPt*/true); - - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoFormatAttr>(aOldSet, rFormat, /*bSaveDrawPt*/true)); } rFormat.SetFormatAttr(rSet); @@ -1885,20 +1877,20 @@ void SwDoc::RenameFormat(SwFormat & rFormat, const OUString & sNewName, if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo * pUndo = nullptr; + std::unique_ptr<SwUndo> pUndo; switch (rFormat.Which()) { case RES_CHRFMT: - pUndo = new SwUndoRenameCharFormat(rFormat.GetName(), sNewName, this); + pUndo.reset(new SwUndoRenameCharFormat(rFormat.GetName(), sNewName, this)); eFamily = SfxStyleFamily::Char; break; case RES_TXTFMTCOLL: - pUndo = new SwUndoRenameFormatColl(rFormat.GetName(), sNewName, this); + pUndo.reset(new SwUndoRenameFormatColl(rFormat.GetName(), sNewName, this)); eFamily = SfxStyleFamily::Para; break; case RES_FRMFMT: - pUndo = new SwUndoRenameFrameFormat(rFormat.GetName(), sNewName, this); + pUndo.reset(new SwUndoRenameFrameFormat(rFormat.GetName(), sNewName, this)); eFamily = SfxStyleFamily::Frame; break; @@ -1908,7 +1900,7 @@ void SwDoc::RenameFormat(SwFormat & rFormat, const OUString & sNewName, if (pUndo) { - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); } } diff --git a/sw/source/core/doc/docftn.cxx b/sw/source/core/doc/docftn.cxx index ffbb49c35623..b2055f8afcdd 100644 --- a/sw/source/core/doc/docftn.cxx +++ b/sw/source/core/doc/docftn.cxx @@ -266,7 +266,7 @@ void SwDoc::SetFootnoteInfo(const SwFootnoteInfo& rInfo) if (GetIDocumentUndoRedo().DoesUndo()) { - GetIDocumentUndoRedo().AppendUndo( new SwUndoFootNoteInfo(rOld, this) ); + GetIDocumentUndoRedo().AppendUndo( o3tl::make_unique<SwUndoFootNoteInfo>(rOld, this) ); } bool bFootnotePos = rInfo.ePos != rOld.ePos; @@ -337,8 +337,8 @@ void SwDoc::SetEndNoteInfo(const SwEndNoteInfo& rInfo) if(GetIDocumentUndoRedo().DoesUndo()) { - SwUndo *const pUndo( new SwUndoEndNoteInfo( GetEndNoteInfo(), this ) ); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoEndNoteInfo>( GetEndNoteInfo(), this ) ); } bool bNumChg = rInfo.nFootnoteOffset != GetEndNoteInfo().nFootnoteOffset; @@ -413,11 +413,11 @@ bool SwDoc::SetCurFootnote( const SwPaM& rPam, const OUString& rNumStr, size_t nPos = 0; rFootnoteArr.SeekEntry( pStt->nNode, &nPos ); - SwUndoChangeFootNote* pUndo = nullptr; + std::unique_ptr<SwUndoChangeFootNote> pUndo; if (GetIDocumentUndoRedo().DoesUndo()) { GetIDocumentUndoRedo().ClearRedo(); // AppendUndo far below, so leave it - pUndo = new SwUndoChangeFootNote( rPam, rNumStr, nNumber, bIsEndNote ); + pUndo.reset(new SwUndoChangeFootNote( rPam, rNumStr, nNumber, bIsEndNote )); } SwTextFootnote* pTextFootnote; @@ -487,7 +487,7 @@ bool SwDoc::SetCurFootnote( const SwPaM& rPam, const OUString& rNumStr, { if( pUndo ) { - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); } if ( bTypeChgd ) @@ -504,8 +504,6 @@ bool SwDoc::SetCurFootnote( const SwPaM& rPam, const OUString& rNumStr, } getIDocumentState().SetModified(); } - else - delete pUndo; return bChg; } diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx index e6dba60efc3b..6cf904be43dc 100644 --- a/sw/source/core/doc/doclay.cxx +++ b/sw/source/core/doc/doclay.cxx @@ -290,7 +290,7 @@ SwFlyFrameFormat* SwDoc::MakeFlySection_( const SwPosition& rAnchPos, sal_uLong nNodeIdx = rAnchPos.nNode.GetIndex(); const sal_Int32 nCntIdx = rAnchPos.nContent.GetIndex(); GetIDocumentUndoRedo().AppendUndo( - new SwUndoInsLayFormat( pFormat, nNodeIdx, nCntIdx )); + o3tl::make_unique<SwUndoInsLayFormat>( pFormat, nNodeIdx, nCntIdx )); } getIDocumentState().SetModified(); @@ -975,21 +975,21 @@ SwDoc::InsertLabel( OUString const& rCharacterStyle, bool const bCpyBrd ) { - SwUndoInsertLabel * pUndo(nullptr); + std::unique_ptr<SwUndoInsertLabel> pUndo; if (GetIDocumentUndoRedo().DoesUndo()) { - pUndo = new SwUndoInsertLabel( + pUndo.reset(new SwUndoInsertLabel( eType, rText, rSeparator, rNumberingSeparator, - bBefore, nId, rCharacterStyle, bCpyBrd, this ); + bBefore, nId, rCharacterStyle, bCpyBrd, this )); } - SwFlyFrameFormat *const pNewFormat = lcl_InsertLabel(*this, mpTextFormatCollTable.get(), pUndo, + SwFlyFrameFormat *const pNewFormat = lcl_InsertLabel(*this, mpTextFormatCollTable.get(), pUndo.get(), eType, rText, rSeparator, rNumberingSeparator, bBefore, nId, nNdIdx, rCharacterStyle, bCpyBrd); if (pUndo) { - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); } else { @@ -1260,22 +1260,22 @@ SwFlyFrameFormat* SwDoc::InsertDrawLabel( if (!pOldFormat) return nullptr; - SwUndoInsertLabel * pUndo = nullptr; + std::unique_ptr<SwUndoInsertLabel> pUndo; if (GetIDocumentUndoRedo().DoesUndo()) { GetIDocumentUndoRedo().ClearRedo(); - pUndo = new SwUndoInsertLabel( + pUndo.reset(new SwUndoInsertLabel( LTYPE_DRAW, rText, rSeparator, rNumberSeparator, false, - nId, rCharacterStyle, false, this ); + nId, rCharacterStyle, false, this )); } SwFlyFrameFormat *const pNewFormat = lcl_InsertDrawLabel( - *this, mpTextFormatCollTable.get(), pUndo, pOldFormat, + *this, mpTextFormatCollTable.get(), pUndo.get(), pOldFormat, rText, rSeparator, rNumberSeparator, nId, rCharacterStyle, rSdrObj); if (pUndo) { - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } else { diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx index 4300f5a3c2c8..efd13d4fda10 100644 --- a/sw/source/core/doc/docnum.cxx +++ b/sw/source/core/doc/docnum.cxx @@ -363,8 +363,8 @@ bool SwDoc::OutlineUpDown( const SwPaM& rPam, short nOffset ) if (GetIDocumentUndoRedo().DoesUndo()) { GetIDocumentUndoRedo().StartUndo(SwUndoId::OUTLINE_LR, nullptr); - SwUndo *const pUndoOLR( new SwUndoOutlineLeftRight( rPam, nOffset ) ); - GetIDocumentUndoRedo().AppendUndo(pUndoOLR); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoOutlineLeftRight>( rPam, nOffset ) ); } // 2. Apply the new style to all Nodes @@ -834,7 +834,7 @@ OUString SwDoc::SetNumRule( const SwPaM& rPam, // Start/End for attributes! GetIDocumentUndoRedo().StartUndo( SwUndoId::INSNUM, nullptr ); pUndo = new SwUndoInsNum( rPam, rRule ); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndo>(pUndo)); } SwNumRule* pNewOrChangedNumRule = FindNumRulePtr( rRule.GetName() ); @@ -966,8 +966,8 @@ void SwDoc::SetNumRuleStart( const SwPosition& rPos, bool bFlag ) { if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo *const pUndo( new SwUndoNumRuleStart(rPos, bFlag) ); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoNumRuleStart>(rPos, bFlag) ); } pTextNd->SetListRestart(bFlag); @@ -988,8 +988,8 @@ void SwDoc::SetNodeNumStart( const SwPosition& rPos, sal_uInt16 nStt ) { if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo *const pUndo( new SwUndoNumRuleStart(rPos, nStt) ); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoNumRuleStart>(rPos, nStt) ); } pTextNd->SetAttrListRestartValue( nStt ); @@ -1016,9 +1016,8 @@ bool SwDoc::DelNumRule( const OUString& rName, bool bBroadcast ) { if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo * pUndo = - new SwUndoNumruleDelete(*(*mpNumRuleTable)[nPos], this); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoNumruleDelete>(*(*mpNumRuleTable)[nPos], this)); } if (bBroadcast) @@ -1050,7 +1049,7 @@ void SwDoc::ChgNumRuleFormats( const SwNumRule& rRule ) { pUndo = new SwUndoInsNum( *pRule, rRule, this ); pUndo->GetHistory(); - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndo) ); } ::lcl_ChgNumRule( *this, rRule ); if (pUndo) @@ -1074,8 +1073,8 @@ bool SwDoc::RenameNumRule(const OUString & rOldName, const OUString & rNewName, { if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo * pUndo = new SwUndoNumruleRename(rOldName, rNewName, this); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoNumruleRename>(rOldName, rNewName, this)); } SwNumRule::tTextNodeList aTextNodeList; @@ -1137,7 +1136,7 @@ bool SwDoc::ReplaceNumRule( const SwPosition& rPos, // Start/End for attributes! GetIDocumentUndoRedo().StartUndo( SwUndoId::START, nullptr ); pUndo = new SwUndoInsNum( rPos, *pNewRule, rOldRule ); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndo>(pUndo)); } SwNumRule::tTextNodeList aTextNodeList; @@ -1297,7 +1296,7 @@ void SwDoc::DelNumRules( const SwPaM& rPam ) if (GetIDocumentUndoRedo().DoesUndo()) { pUndo = new SwUndoDelNum( rPam ); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndo>(pUndo)); } else pUndo = nullptr; @@ -1666,8 +1665,8 @@ bool SwDoc::NumUpDown( const SwPaM& rPam, bool bDown ) { if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo *const pUndo( new SwUndoNumUpDown(rPam, nDiff) ); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoNumUpDown>(rPam, nDiff) ); } for(sal_uLong nTmp = nStt; nTmp <= nEnd; ++nTmp ) @@ -1969,8 +1968,8 @@ bool SwDoc::MoveParagraph( const SwPaM& rPam, long nOffset, bool bIsOutlMv ) // Still NEEDS to be optimized (even after 14 years) getIDocumentRedlineAccess().SetRedlineFlags( RedlineFlags::On | RedlineFlags::ShowInsert | RedlineFlags::ShowDelete ); - SwUndo *const pUndo(new SwUndoRedlineDelete(aPam, SwUndoId::DELETE)); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoRedlineDelete>(aPam, SwUndoId::DELETE)); } SwRangeRedline* pNewRedline = new SwRangeRedline( nsRedlineType_t::REDLINE_DELETE, aPam ); @@ -2006,11 +2005,11 @@ bool SwDoc::MoveParagraph( const SwPaM& rPam, long nOffset, bool bIsOutlMv ) nRedlEndNd = pREnd->nNode.GetIndex(); } - SwUndoMoveNum* pUndo = nullptr; + std::unique_ptr<SwUndoMoveNum> pUndo; sal_uLong nMoved = 0; if (GetIDocumentUndoRedo().DoesUndo()) { - pUndo = new SwUndoMoveNum( rPam, nOffset, bIsOutlMv ); + pUndo.reset(new SwUndoMoveNum( rPam, nOffset, bIsOutlMv )); nMoved = rPam.End()->nNode.GetIndex() - rPam.Start()->nNode.GetIndex() + 1; } @@ -2024,7 +2023,7 @@ bool SwDoc::MoveParagraph( const SwPaM& rPam, long nOffset, bool bIsOutlMv ) // number of moved paragraphs is nMoved, I know, where the new // position is. pUndo->SetStartNode( aIdx.GetIndex() - nMoved ); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); } if( pOwnRedl ) @@ -2067,10 +2066,8 @@ bool SwDoc::NumOrNoNum( const SwNodeIndex& rIdx, bool bDel ) if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndoNumOrNoNum * pUndo = - new SwUndoNumOrNoNum(rIdx, bOldNum, bNewNum); - - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoNumOrNoNum>(rIdx, bOldNum, bNewNum)); } } else if (bDel && pTextNd->GetNumRule(false) && @@ -2178,8 +2175,8 @@ sal_uInt16 SwDoc::MakeNumRule( const OUString &rName, if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo * pUndo = new SwUndoNumruleCreate(pNew, this); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoNumruleCreate>(pNew, this)); } if (bBroadcast) diff --git a/sw/source/core/doc/docsort.cxx b/sw/source/core/doc/docsort.cxx index e91c676a725f..d5cc122cc9f0 100644 --- a/sw/source/core/doc/docsort.cxx +++ b/sw/source/core/doc/docsort.cxx @@ -391,7 +391,7 @@ bool SwDoc::SortText(const SwPaM& rPaM, const SwSortOptions& rOpt) if( bUndo && !pRedlUndo ) { pUndoSort = new SwUndoSort(rPaM, rOpt); - GetIDocumentUndoRedo().AppendUndo(pUndoSort); + GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndo>(pUndoSort)); } GetIDocumentUndoRedo().DoUndo(false); @@ -425,7 +425,7 @@ bool SwDoc::SortText(const SwPaM& rPaM, const SwSortOptions& rOpt) pRedlUndo->SetSaveRange( *pRedlPam ); // UGLY: temp. enable Undo GetIDocumentUndoRedo().DoUndo(true); - GetIDocumentUndoRedo().AppendUndo( pRedlUndo ); + GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pRedlUndo) ); GetIDocumentUndoRedo().DoUndo(false); } @@ -548,7 +548,7 @@ bool SwDoc::SortTable(const SwSelBoxes& rBoxes, const SwSortOptions& rOpt) pUndoSort = new SwUndoSort( rBoxes[0]->GetSttIdx(), rBoxes.back()->GetSttIdx(), *pTableNd, rOpt, aFlatBox.HasItemSets() ); - GetIDocumentUndoRedo().AppendUndo(pUndoSort); + GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndo>(pUndoSort)); } ::sw::UndoGuard const undoGuard(GetIDocumentUndoRedo()); diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx index 1448ce84e663..9544f5ed90ed 100644 --- a/sw/source/core/doc/doctxm.cxx +++ b/sw/source/core/doc/doctxm.cxx @@ -172,7 +172,7 @@ void SwDoc::DeleteTOXMark( const SwTOXMark* pTOXMark ) SwUndoResetAttr* pUndo = new SwUndoResetAttr( SwPosition( rTextNd, SwIndex( &rTextNd, pTextTOXMark->GetStart() ) ), RES_TXTATR_TOXMARK ); - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndo) ); aRHst.reset(new SwRegHistory(rTextNd, &pUndo->GetHistory())); rTextNd.GetpSwpHints()->Register(aRHst.get()); diff --git a/sw/source/core/doc/tblrwcl.cxx b/sw/source/core/doc/tblrwcl.cxx index 25dd8454f071..710b693bfb7b 100644 --- a/sw/source/core/doc/tblrwcl.cxx +++ b/sw/source/core/doc/tblrwcl.cxx @@ -128,9 +128,10 @@ struct CR_SetBoxWidth { } - SwUndoTableNdsChg* CreateUndo( SwUndoId eUndoType ) + std::unique_ptr<SwUndoTableNdsChg> CreateUndo( SwUndoId eUndoType ) { - return pUndo = new SwUndoTableNdsChg( eUndoType, m_Boxes, *pTableNd ); + pUndo = new SwUndoTableNdsChg( eUndoType, m_Boxes, *pTableNd ); + return std::unique_ptr<SwUndoTableNdsChg>(pUndo); } void LoopClear() @@ -214,9 +215,10 @@ struct CR_SetLineHeight bBigger( rCpy.bBigger ), bTop( rCpy.bTop ) {} - SwUndoTableNdsChg* CreateUndo( SwUndoId nUndoType ) + std::unique_ptr<SwUndoTableNdsChg> CreateUndo( SwUndoId nUndoType ) { - return pUndo = new SwUndoTableNdsChg( nUndoType, m_Boxes, *pTableNd ); + pUndo = new SwUndoTableNdsChg( nUndoType, m_Boxes, *pTableNd ); + return std::unique_ptr<SwUndoTableNdsChg>(pUndo); } }; @@ -3321,7 +3323,7 @@ void CheckBoxWidth( const SwTableLine& rLine, SwTwips nSize ) } #endif -static FndBox_* lcl_SaveInsDelData( CR_SetBoxWidth& rParam, SwUndo** ppUndo, +static FndBox_* lcl_SaveInsDelData( CR_SetBoxWidth& rParam, std::unique_ptr<SwUndo>* ppUndo, SwTableSortBoxes& rTmpLst, SwTwips nDistStt ) { // Find all Boxes/Lines @@ -3370,7 +3372,7 @@ static FndBox_* lcl_SaveInsDelData( CR_SetBoxWidth& rParam, SwUndo** ppUndo, } bool SwTable::SetColWidth( SwTableBox& rCurrentBox, TableChgWidthHeightType eType, - SwTwips nAbsDiff, SwTwips nRelDiff, SwUndo** ppUndo ) + SwTwips nAbsDiff, SwTwips nRelDiff, std::unique_ptr<SwUndo>* ppUndo ) { SetHTMLTableLayout(std::shared_ptr<SwHTMLTableLayout>()); // Delete HTML Layout @@ -3497,7 +3499,7 @@ bool SwTable::SetColWidth( SwTableBox& rCurrentBox, TableChgWidthHeightType eTyp : SwUndoId::TABLE_INSCOL ); } else if( ppUndo ) - *ppUndo = new SwUndoAttrTable( *aParam.pTableNd, true ); + ppUndo->reset(new SwUndoAttrTable( *aParam.pTableNd, true )); long nFrameWidth = LONG_MAX; LockModify(); @@ -3692,7 +3694,7 @@ bool SwTable::SetColWidth( SwTableBox& rCurrentBox, TableChgWidthHeightType eTyp : SwUndoId::TABLE_INSCOL ); } else if( ppUndo ) - *ppUndo = new SwUndoAttrTable( *aParam.pTableNd, true ); + ppUndo->reset(new SwUndoAttrTable( *aParam.pTableNd, true )); if( bInsDel ? ( TableChgMode::FixedWidthChangeAbs == m_eTableChgMode ? (bBigger && bLeft) : bLeft ) @@ -3806,7 +3808,7 @@ bool SwTable::SetColWidth( SwTableBox& rCurrentBox, TableChgWidthHeightType eTyp : SwUndoId::TABLE_INSCOL ); } else if( ppUndo ) - *ppUndo = new SwUndoAttrTable( *aParam.pTableNd, true ); + ppUndo->reset(new SwUndoAttrTable( *aParam.pTableNd, true )); if( bInsDel ? ( TableChgMode::FixedWidthChangeAbs == m_eTableChgMode ? (bBigger && bLeft) : bLeft ) @@ -3861,7 +3863,7 @@ bool SwTable::SetColWidth( SwTableBox& rCurrentBox, TableChgWidthHeightType eTyp return bRet; } -static FndBox_* lcl_SaveInsDelData( CR_SetLineHeight& rParam, SwUndo** ppUndo, +static FndBox_* lcl_SaveInsDelData( CR_SetLineHeight& rParam, std::unique_ptr<SwUndo>* ppUndo, SwTableSortBoxes& rTmpLst ) { // Find all Boxes/Lines @@ -4105,7 +4107,7 @@ static bool lcl_InsDelSelLine( SwTableLine* pLine, CR_SetLineHeight& rParam, } bool SwTable::SetRowHeight( SwTableBox& rCurrentBox, TableChgWidthHeightType eType, - SwTwips nAbsDiff, SwTwips nRelDiff,SwUndo** ppUndo ) + SwTwips nAbsDiff, SwTwips nRelDiff, std::unique_ptr<SwUndo>* ppUndo ) { SwTableLine* pLine = rCurrentBox.GetUpper(); @@ -4190,7 +4192,7 @@ bool SwTable::SetRowHeight( SwTableBox& rCurrentBox, TableChgWidthHeightType eTy : SwUndoId::ROW_DELETE ); } else if( ppUndo ) - *ppUndo = new SwUndoAttrTable( *aParam.pTableNd, true ); + ppUndo->reset(new SwUndoAttrTable( *aParam.pTableNd, true )); (*fnSelLine)( (*pLines)[ nBaseLinePos ], aParam, nAbsDiff, false ); @@ -4274,7 +4276,7 @@ bool SwTable::SetRowHeight( SwTableBox& rCurrentBox, TableChgWidthHeightType eTy : SwUndoId::ROW_DELETE ); } else if( ppUndo ) - *ppUndo = new SwUndoAttrTable( *aParam.pTableNd, true ); + ppUndo->reset(new SwUndoAttrTable( *aParam.pTableNd, true )); CR_SetLineHeight aParam1( aParam ); diff --git a/sw/source/core/docnode/ndsect.cxx b/sw/source/core/docnode/ndsect.cxx index b96f31e7fff8..e37646e8822b 100644 --- a/sw/source/core/docnode/ndsect.cxx +++ b/sw/source/core/docnode/ndsect.cxx @@ -186,7 +186,7 @@ SwDoc::InsertSwSection(SwPaM const& rRange, SwSectionData & rNewData, if (bUndo) { pUndoInsSect = new SwUndoInsSection(rRange, rNewData, pAttr, pTOXBase); - GetIDocumentUndoRedo().AppendUndo( pUndoInsSect ); + GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndoInsSect) ); GetIDocumentUndoRedo().DoUndo(false); } @@ -536,7 +536,7 @@ void SwDoc::DelSectionFormat( SwSectionFormat *pFormat, bool bDelNodes ) { SwNodeIndex aUpdIdx( *pIdx ); SwPaM aPaM( *pSectNd->EndOfSectionNode(), *pSectNd ); - GetIDocumentUndoRedo().AppendUndo( new SwUndoDelete( aPaM )); + GetIDocumentUndoRedo().AppendUndo( o3tl::make_unique<SwUndoDelete>( aPaM )); if( pFootnoteEndAtTextEnd ) GetFootnoteIdxs().UpdateFootnote( aUpdIdx ); getIDocumentState().SetModified(); diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx index 408822f08779..2fb87340dad7 100644 --- a/sw/source/core/docnode/ndtbl.cxx +++ b/sw/source/core/docnode/ndtbl.cxx @@ -357,7 +357,7 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTableOpts, if( GetIDocumentUndoRedo().DoesUndo() ) { GetIDocumentUndoRedo().AppendUndo( - new SwUndoInsTable( rPos, nCols, nRows, static_cast<sal_uInt16>(eAdjust), + o3tl::make_unique<SwUndoInsTable>( rPos, nCols, nRows, static_cast<sal_uInt16>(eAdjust), rInsTableOpts, pTAFormat, pColArr, aTableName)); } @@ -647,7 +647,7 @@ const SwTable* SwDoc::TextToTable( const SwInsertTableOptions& rInsTableOpts, GetIDocumentUndoRedo().StartUndo( SwUndoId::TEXTTOTABLE, nullptr ); pUndo = new SwUndoTextToTable( aOriginal, rInsTableOpts, cCh, static_cast<sal_uInt16>(eAdjust), pTAFormat ); - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndo) ); // Do not add splitting the TextNode to the Undo history GetIDocumentUndoRedo().DoUndo( false ); @@ -1462,26 +1462,26 @@ bool SwDoc::TableToText( const SwTableNode* pTableNd, sal_Unicode cCh ) pESh->ClearMark(); SwNodeRange aRg( *pTableNd, 0, *pTableNd->EndOfSectionNode() ); - SwUndoTableToText* pUndo = nullptr; + std::unique_ptr<SwUndoTableToText> pUndo; SwNodeRange* pUndoRg = nullptr; if (GetIDocumentUndoRedo().DoesUndo()) { GetIDocumentUndoRedo().ClearRedo(); pUndoRg = new SwNodeRange( aRg.aStart, -1, aRg.aEnd, +1 ); - pUndo = new SwUndoTableToText( pTableNd->GetTable(), cCh ); + pUndo.reset(new SwUndoTableToText( pTableNd->GetTable(), cCh )); } SwTableFormulaUpdate aMsgHint( &pTableNd->GetTable() ); aMsgHint.m_eFlags = TBL_BOXNAME; getIDocumentFieldsAccess().UpdateTableFields( &aMsgHint ); - bool bRet = GetNodes().TableToText( aRg, cCh, pUndo ); + bool bRet = GetNodes().TableToText( aRg, cCh, pUndo.get() ); if( pUndoRg ) { ++pUndoRg->aStart; --pUndoRg->aEnd; pUndo->SetRange( *pUndoRg ); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); delete pUndoRg; } @@ -1724,11 +1724,11 @@ bool SwDoc::InsertCol( const SwSelBoxes& rBoxes, sal_uInt16 nCnt, bool bBehind ) return false; SwTableSortBoxes aTmpLst; - SwUndoTableNdsChg* pUndo = nullptr; + std::unique_ptr<SwUndoTableNdsChg> pUndo; if (GetIDocumentUndoRedo().DoesUndo()) { - pUndo = new SwUndoTableNdsChg( SwUndoId::TABLE_INSCOL, rBoxes, *pTableNd, - 0, 0, nCnt, bBehind, false ); + pUndo.reset(new SwUndoTableNdsChg( SwUndoId::TABLE_INSCOL, rBoxes, *pTableNd, + 0, 0, nCnt, bBehind, false )); aTmpLst.insert( rTable.GetTabSortBoxes() ); } @@ -1754,10 +1754,8 @@ bool SwDoc::InsertCol( const SwSelBoxes& rBoxes, sal_uInt16 nCnt, bool bBehind ) if( bRet ) { pUndo->SaveNewBoxes( *pTableNd, aTmpLst ); - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } - else - delete pUndo; } return bRet; } @@ -1784,11 +1782,11 @@ bool SwDoc::InsertRow( const SwSelBoxes& rBoxes, sal_uInt16 nCnt, bool bBehind ) return false; SwTableSortBoxes aTmpLst; - SwUndoTableNdsChg* pUndo = nullptr; + std::unique_ptr<SwUndoTableNdsChg> pUndo; if (GetIDocumentUndoRedo().DoesUndo()) { - pUndo = new SwUndoTableNdsChg( SwUndoId::TABLE_INSROW,rBoxes, *pTableNd, - 0, 0, nCnt, bBehind, false ); + pUndo.reset(new SwUndoTableNdsChg( SwUndoId::TABLE_INSROW,rBoxes, *pTableNd, + 0, 0, nCnt, bBehind, false )); aTmpLst.insert( rTable.GetTabSortBoxes() ); } @@ -1814,10 +1812,8 @@ bool SwDoc::InsertRow( const SwSelBoxes& rBoxes, sal_uInt16 nCnt, bool bBehind ) if( bRet ) { pUndo->SaveNewBoxes( *pTableNd, aTmpLst ); - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } - else - delete pUndo; } return bRet; @@ -2057,12 +2053,12 @@ bool SwDoc::DeleteRowCol( const SwSelBoxes& rBoxes, bool bColumn ) bSavePageBreak = true; } } - SwUndoDelete* pUndo = new SwUndoDelete( aPaM ); + std::unique_ptr<SwUndoDelete> pUndo(new SwUndoDelete( aPaM )); if( bNewTextNd ) pUndo->SetTableDelLastNd(); pUndo->SetPgBrkFlags( bSavePageBreak, bSavePageDesc ); pUndo->SetTableName(pTableNd->GetTable().GetFrameFormat()->GetName()); - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } else { @@ -2112,11 +2108,11 @@ bool SwDoc::DeleteRowCol( const SwSelBoxes& rBoxes, bool bColumn ) return true; } - SwUndoTableNdsChg* pUndo = nullptr; + std::unique_ptr<SwUndoTableNdsChg> pUndo; if (GetIDocumentUndoRedo().DoesUndo()) { - pUndo = new SwUndoTableNdsChg( SwUndoId::TABLE_DELBOX, aSelBoxes, *pTableNd, - nMin, nMax, 0, false, false ); + pUndo.reset(new SwUndoTableNdsChg( SwUndoId::TABLE_DELBOX, aSelBoxes, *pTableNd, + nMin, nMax, 0, false, false )); } bool bRet(false); @@ -2135,7 +2131,7 @@ bool SwDoc::DeleteRowCol( const SwSelBoxes& rBoxes, bool bColumn ) if (pUndo) pUndo->ReNewBoxes( aSelBoxes ); } - bRet = rTable.DeleteSel( this, aSelBoxes, nullptr, pUndo, true, true ); + bRet = rTable.DeleteSel( this, aSelBoxes, nullptr, pUndo.get(), true, true ); if (bRet) { GetDocShell()->GetFEShell()->UpdateTableStyleFormatting(); @@ -2149,10 +2145,8 @@ bool SwDoc::DeleteRowCol( const SwSelBoxes& rBoxes, bool bColumn ) { if( bRet ) { - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } - else - delete pUndo; } return bRet; @@ -2175,11 +2169,11 @@ bool SwDoc::SplitTable( const SwSelBoxes& rBoxes, bool bVert, sal_uInt16 nCnt, std::vector<sal_uLong> aNdsCnts; SwTableSortBoxes aTmpLst; - SwUndoTableNdsChg* pUndo = nullptr; + std::unique_ptr<SwUndoTableNdsChg> pUndo; if (GetIDocumentUndoRedo().DoesUndo()) { - pUndo = new SwUndoTableNdsChg( SwUndoId::TABLE_SPLIT, rBoxes, *pTableNd, 0, 0, - nCnt, bVert, bSameHeight ); + pUndo.reset(new SwUndoTableNdsChg( SwUndoId::TABLE_SPLIT, rBoxes, *pTableNd, 0, 0, + nCnt, bVert, bSameHeight )); aTmpLst.insert( rTable.GetTabSortBoxes() ); if( !bVert ) @@ -2223,10 +2217,8 @@ bool SwDoc::SplitTable( const SwSelBoxes& rBoxes, bool bVert, sal_uInt16 nCnt, pUndo->SaveNewBoxes( *pTableNd, aTmpLst ); else pUndo->SaveNewBoxes( *pTableNd, aTmpLst, rBoxes, aNdsCnts ); - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } - else - delete pUndo; } return bRet; @@ -2256,21 +2248,21 @@ TableMergeErr SwDoc::MergeTable( SwPaM& rPam ) RedlineFlags eOld = getIDocumentRedlineAccess().GetRedlineFlags(); getIDocumentRedlineAccess().SetRedlineFlags_intern(eOld | RedlineFlags::Ignore); - SwUndoTableMerge *const pUndo( (GetIDocumentUndoRedo().DoesUndo()) - ? new SwUndoTableMerge( rPam ) - : nullptr ); + std::unique_ptr<SwUndoTableMerge> pUndo; + if (GetIDocumentUndoRedo().DoesUndo()) + pUndo.reset(new SwUndoTableMerge( rPam )); // Find the Boxes via the Layout SwSelBoxes aBoxes; SwSelBoxes aMerged; SwTableBox* pMergeBox; - if( !rTable.PrepareMerge( rPam, aBoxes, aMerged, &pMergeBox, pUndo ) ) + if( !rTable.PrepareMerge( rPam, aBoxes, aMerged, &pMergeBox, pUndo.get() ) ) { // No cells found to merge getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld ); if( pUndo ) { - delete pUndo; + pUndo.reset(); SwUndoId nLastUndoId(SwUndoId::EMPTY); if (GetIDocumentUndoRedo().GetLastUndoInfo(nullptr, & nLastUndoId) && (SwUndoId::REDLINE == nLastUndoId)) @@ -2314,7 +2306,7 @@ TableMergeErr SwDoc::MergeTable( SwPaM& rPam ) aMsgHint.m_eFlags = TBL_BOXPTR; getIDocumentFieldsAccess().UpdateTableFields( &aMsgHint ); - if( pTableNd->GetTable().Merge( this, aBoxes, aMerged, pMergeBox, pUndo )) + if( pTableNd->GetTable().Merge( this, aBoxes, aMerged, pMergeBox, pUndo.get() )) { nRet = TableMergeErr::Ok; @@ -2322,11 +2314,9 @@ TableMergeErr SwDoc::MergeTable( SwPaM& rPam ) getIDocumentFieldsAccess().SetFieldsDirty( true, nullptr, 0 ); if( pUndo ) { - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } } - else - delete pUndo; rPam.GetPoint()->nNode = *pMergeBox->GetSttNd(); rPam.Move(); @@ -2883,7 +2873,7 @@ void SwDoc::SetTabCols(SwTable& rTab, const SwTabCols &rNew, const SwTabCols &rO if (GetIDocumentUndoRedo().DoesUndo()) { GetIDocumentUndoRedo().AppendUndo( - new SwUndoAttrTable( *rTab.GetTableNode(), true )); + o3tl::make_unique<SwUndoAttrTable>( *rTab.GetTableNode(), true )); } rTab.SetTabCols( rNew, rOld, pStart, bCurRowOnly ); ::ClearFEShellTabCols(*this, nullptr); @@ -2898,7 +2888,7 @@ void SwDoc::SetRowsToRepeat( SwTable &rTable, sal_uInt16 nSet ) if (GetIDocumentUndoRedo().DoesUndo()) { GetIDocumentUndoRedo().AppendUndo( - new SwUndoTableHeadline(rTable, rTable.GetRowsToRepeat(), nSet) ); + o3tl::make_unique<SwUndoTableHeadline>(rTable, rTable.GetRowsToRepeat(), nSet) ); } SwMsgPoolItem aChg( RES_TBLHEADLINECHG ); @@ -3154,7 +3144,7 @@ bool SwDoc::SplitTable( const SwPosition& rPos, SplitTable_HeadlineOption eHdlnM { pUndo = new SwUndoSplitTable( *pNew, std::move(pSaveRowSp), eHdlnMode, bCalcNewSize); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndo>(pUndo)); if( aHistory.Count() ) pUndo->SaveFormula( aHistory ); } @@ -3486,7 +3476,7 @@ bool SwDoc::MergeTable( const SwPosition& rPos, bool bWithPrev, sal_uInt16 nMode if (GetIDocumentUndoRedo().DoesUndo()) { pUndo = new SwUndoMergeTable( *pTableNd, *pDelTableNd, bWithPrev, nMode ); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndo>(pUndo)); pHistory = new SwHistory; } @@ -3744,7 +3734,7 @@ bool SwDoc::SetTableAutoFormat(const SwSelBoxes& rBoxes, const SwTableAutoFormat if (bUndo) { pUndo = new SwUndoTableAutoFormat( *pTableNd, rNew ); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndo>(pUndo)); GetIDocumentUndoRedo().DoUndo(false); } @@ -3960,7 +3950,7 @@ bool SwDoc::SetColRowWidthHeight( SwTableBox& rCurrentBox, TableChgWidthHeightTy SwTwips nAbsDiff, SwTwips nRelDiff ) { SwTableNode* pTableNd = const_cast<SwTableNode*>(rCurrentBox.GetSttNd()->FindTableNode()); - SwUndo* pUndo = nullptr; + std::unique_ptr<SwUndo> pUndo; if( (TableChgWidthHeightType::InsertDeleteMode & eType) && dynamic_cast<const SwDDETable*>( &pTableNd->GetTable()) != nullptr) return false; @@ -3996,7 +3986,7 @@ bool SwDoc::SetColRowWidthHeight( SwTableBox& rCurrentBox, TableChgWidthHeightTy GetIDocumentUndoRedo().DoUndo(bUndo); // SetColWidth can turn it off if( pUndo ) { - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } if( bRet ) @@ -4034,7 +4024,7 @@ void SwDoc::ChkBoxNumFormat( SwTableBox& rBox, bool bCallUpdate ) static_cast<const SwTableBoxNumFormat*>(pNumFormatItem)->GetValue() )) return ; - SwUndoTableNumFormat* pUndo = nullptr; + std::unique_ptr<SwUndoTableNumFormat> pUndo; bool bIsEmptyTextNd; bool bChgd = true; @@ -4049,7 +4039,7 @@ void SwDoc::ChkBoxNumFormat( SwTableBox& rBox, bool bCallUpdate ) if (GetIDocumentUndoRedo().DoesUndo()) { GetIDocumentUndoRedo().StartUndo( SwUndoId::TABLE_AUTOFMT, nullptr ); - pUndo = new SwUndoTableNumFormat( rBox ); + pUndo.reset(new SwUndoTableNumFormat( rBox )); pUndo->SetNumFormat( nFormatIdx, fNumber ); } @@ -4122,7 +4112,7 @@ void SwDoc::ChkBoxNumFormat( SwTableBox& rBox, bool bCallUpdate ) if (GetIDocumentUndoRedo().DoesUndo()) { GetIDocumentUndoRedo().StartUndo( SwUndoId::TABLE_AUTOFMT, nullptr ); - pUndo = new SwUndoTableNumFormat( rBox ); + pUndo.reset(new SwUndoTableNumFormat( rBox )); } pBoxFormat = static_cast<SwTableBoxFormat*>(rBox.ClaimFrameFormat()); @@ -4148,7 +4138,7 @@ void SwDoc::ChkBoxNumFormat( SwTableBox& rBox, bool bCallUpdate ) if( pUndo ) { pUndo->SetBox( rBox ); - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); GetIDocumentUndoRedo().EndUndo( SwUndoId::END, nullptr ); } @@ -4171,7 +4161,7 @@ void SwDoc::SetTableBoxFormulaAttrs( SwTableBox& rBox, const SfxItemSet& rSet ) { if (GetIDocumentUndoRedo().DoesUndo()) { - GetIDocumentUndoRedo().AppendUndo( new SwUndoTableNumFormat(rBox, &rSet) ); + GetIDocumentUndoRedo().AppendUndo( o3tl::make_unique<SwUndoTableNumFormat>(rBox, &rSet) ); } SwFrameFormat* pBoxFormat = rBox.ClaimFrameFormat(); @@ -4214,7 +4204,8 @@ void SwDoc::ClearLineNumAttrs( SwPosition const & rPos ) if( GetIDocumentUndoRedo().DoesUndo() ) { GetIDocumentUndoRedo().ClearRedo(); - GetIDocumentUndoRedo().AppendUndo( pUndo = new SwUndoDelNum( aPam ) ); + pUndo = new SwUndoDelNum( aPam ); + GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndo) ); } else pUndo = nullptr; @@ -4250,7 +4241,7 @@ void SwDoc::ClearBoxNumAttrs( const SwNodeIndex& rNode ) { if (GetIDocumentUndoRedo().DoesUndo()) { - GetIDocumentUndoRedo().AppendUndo(new SwUndoTableNumFormat(*pBox)); + GetIDocumentUndoRedo().AppendUndo(o3tl::make_unique<SwUndoTableNumFormat>(*pBox)); } SwFrameFormat* pBoxFormat = pBox->ClaimFrameFormat(); @@ -4292,11 +4283,11 @@ bool SwDoc::InsCopyOfTable( SwPosition& rInsPos, const SwSelBoxes& rBoxes, bool const bUndo( GetIDocumentUndoRedo().DoesUndo() ); if( !pCpyTable && !pInsTableNd ) { - SwUndoCpyTable* pUndo = nullptr; + std::unique_ptr<SwUndoCpyTable> pUndo; if (bUndo) { GetIDocumentUndoRedo().ClearRedo(); - pUndo = new SwUndoCpyTable(this); + pUndo.reset(new SwUndoCpyTable(this)); } { @@ -4307,17 +4298,12 @@ bool SwDoc::InsCopyOfTable( SwPosition& rInsPos, const SwSelBoxes& rBoxes, if( pUndo ) { - if( !bRet ) - { - delete pUndo; - pUndo = nullptr; - } - else + if( bRet ) { pInsTableNd = GetNodes()[ rInsPos.nNode.GetIndex() - 1 ]->FindTableNode(); pUndo->SetTableSttIdx( pInsTableNd->GetIndex() ); - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } } } @@ -4329,11 +4315,11 @@ bool SwDoc::InsCopyOfTable( SwPosition& rInsPos, const SwSelBoxes& rBoxes, RedlineFlags::ShowInsert | RedlineFlags::ShowDelete ); - SwUndoTableCpyTable* pUndo = nullptr; + std::unique_ptr<SwUndoTableCpyTable> pUndo; if (bUndo) { GetIDocumentUndoRedo().ClearRedo(); - pUndo = new SwUndoTableCpyTable(this); + pUndo.reset(new SwUndoTableCpyTable(this)); GetIDocumentUndoRedo().DoUndo(false); } @@ -4353,8 +4339,6 @@ bool SwDoc::InsCopyOfTable( SwPosition& rInsPos, const SwSelBoxes& rBoxes, if( pUndo ) { GetIDocumentUndoRedo().DoUndo(bUndo); - delete pUndo; - pUndo = nullptr; } return false; } @@ -4387,13 +4371,13 @@ bool SwDoc::InsCopyOfTable( SwPosition& rInsPos, const SwSelBoxes& rBoxes, // Copy Table to the selected Lines bRet = pInsTableNd->GetTable().InsTable( pSrcTableNd->GetTable(), - *pBoxes, pUndo ); + *pBoxes, pUndo.get() ); } else { SwNodeIndex aNdIdx( *pSttNd, 1 ); bRet = pInsTableNd->GetTable().InsTable( pSrcTableNd->GetTable(), - aNdIdx, pUndo ); + aNdIdx, pUndo.get() ); } xCpyDoc.clear(); @@ -4402,11 +4386,9 @@ bool SwDoc::InsCopyOfTable( SwPosition& rInsPos, const SwSelBoxes& rBoxes, { // If the Table could not be copied, delete the Undo object GetIDocumentUndoRedo().DoUndo(bUndo); - if( !bRet && pUndo->IsEmpty() ) - delete pUndo; - else + if( bRet || !pUndo->IsEmpty() ) { - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo(std::move(pUndo)); } } @@ -4429,9 +4411,9 @@ bool SwDoc::InsCopyOfTable( SwPosition& rInsPos, const SwSelBoxes& rBoxes, bool SwDoc::UnProtectTableCells( SwTable& rTable ) { bool bChgd = false; - SwUndoAttrTable *const pUndo = (GetIDocumentUndoRedo().DoesUndo()) - ? new SwUndoAttrTable( *rTable.GetTableNode() ) - : nullptr; + std::unique_ptr<SwUndoAttrTable> pUndo; + if (GetIDocumentUndoRedo().DoesUndo()) + pUndo.reset(new SwUndoAttrTable( *rTable.GetTableNode() )); SwTableSortBoxes& rSrtBox = rTable.GetTabSortBoxes(); for (size_t i = rSrtBox.size(); i; ) @@ -4448,10 +4430,8 @@ bool SwDoc::UnProtectTableCells( SwTable& rTable ) { if( bChgd ) { - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } - else - delete pUndo; } return bChgd; } @@ -4473,9 +4453,9 @@ bool SwDoc::UnProtectCells( const SwSelBoxes& rBoxes ) bool bChgd = false; if( !rBoxes.empty() ) { - SwUndoAttrTable *const pUndo = (GetIDocumentUndoRedo().DoesUndo()) - ? new SwUndoAttrTable( *rBoxes[0]->GetSttNd()->FindTableNode() ) - : nullptr; + std::unique_ptr<SwUndoAttrTable> pUndo; + if (GetIDocumentUndoRedo().DoesUndo()) + pUndo.reset(new SwUndoAttrTable( *rBoxes[0]->GetSttNd()->FindTableNode() )); std::map<SwFrameFormat*, SwTableBoxFormat*> aFormatsMap; for (size_t i = rBoxes.size(); i; ) @@ -4503,10 +4483,8 @@ bool SwDoc::UnProtectCells( const SwSelBoxes& rBoxes ) { if( bChgd ) { - GetIDocumentUndoRedo().AppendUndo( pUndo ); + GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) ); } - else - delete pUndo; } } return bChgd; @@ -4604,9 +4582,8 @@ SwTableAutoFormat* SwDoc::MakeTableStyle(const OUString& rName, bool bBroadcast) if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo * pUndo = new SwUndoTableStyleMake(rName, this); - - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoTableStyleMake>(rName, this)); } if (bBroadcast) @@ -4641,9 +4618,8 @@ std::unique_ptr<SwTableAutoFormat> SwDoc::DelTableStyle(const OUString& rName, b if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo * pUndo = new SwUndoTableStyleDelete(std::move(pReleasedFormat), vAffectedTables, this); - - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoTableStyleDelete>(std::move(pReleasedFormat), vAffectedTables, this)); } } @@ -4672,9 +4648,8 @@ void SwDoc::ChgTableStyle(const OUString& rName, const SwTableAutoFormat& rNewFo if (GetIDocumentUndoRedo().DoesUndo()) { - SwUndo * pUndo = new SwUndoTableStyleUpdate(*pFormat, aOldFormat, this); - - GetIDocumentUndoRedo().AppendUndo(pUndo); + GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoTableStyleUpdate>(*pFormat, aOldFormat, this)); } } } diff --git a/sw/source/core/docnode/ndtbl1.cxx b/sw/source/core/docnode/ndtbl1.cxx index 99a8ca078655..c6a6e0a19207 100644 --- a/sw/source/core/docnode/ndtbl1.cxx +++ b/sw/source/core/docnode/ndtbl1.cxx @@ -322,7 +322,7 @@ void SwDoc::SetRowSplit( const SwCursor& rCursor, const SwFormatRowSplit &rNew ) { if (GetIDocumentUndoRedo().DoesUndo()) { - GetIDocumentUndoRedo().AppendUndo(new SwUndoAttrTable(*pTableNd)); + GetIDocumentUndoRedo().AppendUndo(o3tl::make_unique<SwUndoAttrTable>(*pTableNd)); } std::vector<std::unique_ptr<SwTableFormatCmp>> aFormatCmp; @@ -394,7 +394,7 @@ void SwDoc::SetRowHeight( const SwCursor& rCursor, const SwFormatFrameSize &rNew { if (GetIDocumentUndoRedo().DoesUndo()) { - GetIDocumentUndoRedo().AppendUndo(new SwUndoAttrTable(*pTableNd)); + GetIDocumentUndoRedo().AppendUndo(o3tl::make_unique<SwUndoAttrTable>(*pTableNd)); } std::vector<std::unique_ptr<SwTableFormatCmp>> aFormatCmp; @@ -468,7 +468,7 @@ bool SwDoc::BalanceRowHeight( const SwCursor& rCursor, bool bTstOnly ) if (GetIDocumentUndoRedo().DoesUndo()) { GetIDocumentUndoRedo().AppendUndo( - new SwUndoAttrTable(*pTableNd)); + o3tl::make_unique<SwUndoAttrTable>(*pTableNd)); } std::vector<std::unique_ptr<SwTableFormatCmp>> aFormatCmp; @@ -496,7 +496,7 @@ void SwDoc::SetRowBackground( const SwCursor& rCursor, const SvxBrushItem &rNew { if (GetIDocumentUndoRedo().DoesUndo()) { - GetIDocumentUndoRedo().AppendUndo(new SwUndoAttrTable(*pTableNd)); + GetIDocumentUndoRedo().AppendUndo(o3tl::make_unique<SwUndoAttrTable>(*pTableNd)); } std::vector<std::unique_ptr<SwTableFormatCmp>> aFormatCmp; @@ -583,7 +583,7 @@ void SwDoc::SetTabBorders( const SwCursor& rCursor, const SfxItemSet& rSet ) SwTable& rTable = pTableNd->GetTable(); if (GetIDocumentUndoRedo().DoesUndo()) { - GetIDocumentUndoRedo().AppendUndo( new SwUndoAttrTable(*pTableNd) ); + GetIDocumentUndoRedo().AppendUndo( o3tl::make_unique<SwUndoAttrTable>(*pTableNd) ); } std::vector<std::unique_ptr<SwTableFormatCmp>> aFormatCmp; @@ -865,7 +865,7 @@ void SwDoc::SetTabLineStyle( const SwCursor& rCursor, SwTable& rTable = pTableNd->GetTable(); if (GetIDocumentUndoRedo().DoesUndo()) { - GetIDocumentUndoRedo().AppendUndo(new SwUndoAttrTable(*pTableNd)); + GetIDocumentUndoRedo().AppendUndo(o3tl::make_unique<SwUndoAttrTable>(*pTableNd)); } for( auto &rU : aUnions ) @@ -1151,7 +1151,7 @@ void SwDoc::SetBoxAttr( const SwCursor& rCursor, const SfxPoolItem &rNew ) SwTable& rTable = pTableNd->GetTable(); if (GetIDocumentUndoRedo().DoesUndo()) { - GetIDocumentUndoRedo().AppendUndo( new SwUndoAttrTable(*pTableNd) ); + GetIDocumentUndoRedo().AppendUndo( o3tl::make_unique<SwUndoAttrTable>(*pTableNd) ); } std::vector<std::unique_ptr<SwTableFormatCmp>> aFormatCmp; diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index 3e1d3a74c778..962c9f6773f4 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -666,8 +666,8 @@ void lcl_ValidateParagraphSignatures(SwDoc* pDoc, const uno::Reference<text::XTe else if (!lcl_MakeParagraphSignatureFieldText(xModel, xParagraph, xField, utf8Text).first) { pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::PARA_SIGN_ADD, nullptr); - SwUndoParagraphSigning* pUndo = new SwUndoParagraphSigning(pDoc, xField, xParagraph, false); - pDoc->GetIDocumentUndoRedo().AppendUndo(pUndo); + pDoc->GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoParagraphSigning>(pDoc, xField, xParagraph, false)); lcl_RemoveParagraphMetadataField(xField); pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::PARA_SIGN_ADD, nullptr); } @@ -1799,8 +1799,8 @@ void SwEditShell::SignParagraph() lcl_UpdateParagraphSignatureField(GetDoc(), xModel, xParagraph, xField, utf8Text); - SwUndoParagraphSigning* pUndo = new SwUndoParagraphSigning(GetDoc(), xField, xParagraph, true); - GetDoc()->GetIDocumentUndoRedo().AppendUndo(pUndo); + GetDoc()->GetIDocumentUndoRedo().AppendUndo( + o3tl::make_unique<SwUndoParagraphSigning>(GetDoc(), xField, xParagraph, true)); GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::PARA_SIGN_ADD, nullptr); } diff --git a/sw/source/core/inc/UndoAttribute.hxx b/sw/source/core/inc/UndoAttribute.hxx index 3bbebafe776d..3197a9107841 100644 --- a/sw/source/core/inc/UndoAttribute.hxx +++ b/sw/source/core/inc/UndoAttribute.hxx @@ -172,7 +172,7 @@ public: SwUndoFormatAttr* GetUndo() const { return m_pUndo.get(); } // release the undo object (so it is not deleted here), and return it - SwUndoFormatAttr* ReleaseUndo() { return m_pUndo.release(); } + std::unique_ptr<SwUndoFormatAttr> ReleaseUndo() { return std::move(m_pUndo); } }; class SwUndoMoveLeftMargin : public SwUndo, private SwUndRng diff --git a/sw/source/core/inc/UndoManager.hxx b/sw/source/core/inc/UndoManager.hxx index 901b5245cf68..29f8cd4a44c2 100644 --- a/sw/source/core/inc/UndoManager.hxx +++ b/sw/source/core/inc/UndoManager.hxx @@ -74,7 +74,7 @@ public: virtual bool Repeat(::sw::RepeatContext & rContext, sal_uInt16 const nRepeatCnt) override; virtual SwUndoId GetRepeatInfo(OUString *const o_pStr) const override; - virtual void AppendUndo(SwUndo *const pUndo) override; + virtual void AppendUndo(std::unique_ptr<SwUndo> pUndo) override; virtual void ClearRedo() override; virtual bool IsUndoNodes(SwNodes const& rNodes) const override; virtual size_t GetUndoActionCount(const bool bCurrentLevel = true) const override; diff --git a/sw/source/core/inc/UndoSection.hxx b/sw/source/core/inc/UndoSection.hxx index a3c3ea307233..c221d79b3145 100644 --- a/sw/source/core/inc/UndoSection.hxx +++ b/sw/source/core/inc/UndoSection.hxx @@ -61,9 +61,9 @@ public: void SetUpdateFootnoteFlag(bool const bFlag) { m_bUpdateFootnote = bFlag; } }; -SwUndo * MakeUndoDelSection(SwSectionFormat const&); +std::unique_ptr<SwUndo> MakeUndoDelSection(SwSectionFormat const&); -SwUndo * MakeUndoUpdateSection(SwSectionFormat const&, bool const); +std::unique_ptr<SwUndo> MakeUndoUpdateSection(SwSectionFormat const&, bool const); #endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOSECTION_HXX diff --git a/sw/source/core/undo/docundo.cxx b/sw/source/core/undo/docundo.cxx index 8181c5fe1589..9d46a6b7bcbf 100644 --- a/sw/source/core/undo/docundo.cxx +++ b/sw/source/core/undo/docundo.cxx @@ -242,9 +242,9 @@ SwUndo* UndoManager::GetLastUndo() return dynamic_cast<SwUndo*>(pAction); } -void UndoManager::AppendUndo(SwUndo *const pUndo) +void UndoManager::AppendUndo(std::unique_ptr<SwUndo> pUndo) { - AddUndoAction(pUndo); + AddUndoAction(pUndo.release()); } void UndoManager::ClearRedo() diff --git a/sw/source/core/undo/undraw.cxx b/sw/source/core/undo/undraw.cxx index 43cf4cd248eb..5b1195ff9846 100644 --- a/sw/source/core/undo/undraw.cxx +++ b/sw/source/core/undo/undraw.cxx @@ -65,7 +65,7 @@ void SwDoc::AddDrawUndo( std::unique_ptr<SdrUndoAction> pUndo ) if( pSh && pSh->HasDrawView() ) pMarkList = &pSh->GetDrawView()->GetMarkedObjectList(); - GetIDocumentUndoRedo().AppendUndo( new SwSdrUndo(std::move(pUndo), pMarkList, this) ); + GetIDocumentUndoRedo().AppendUndo( o3tl::make_unique<SwSdrUndo>(std::move(pUndo), pMarkList, this) ); } } diff --git a/sw/source/core/undo/unins.cxx b/sw/source/core/undo/unins.cxx index 0f600efedd4c..5db299b4e969 100644 --- a/sw/source/core/undo/unins.cxx +++ b/sw/source/core/undo/unins.cxx @@ -1045,7 +1045,7 @@ void SwUndoInsertLabel::SetFlys( SwFrameFormat& rOldFly, SfxItemSet const & rChg rOldFly.SetFormatAttr( rChgSet ); if ( aTmp.GetUndo() ) { - OBJECT.pUndoAttr = aTmp.ReleaseUndo(); + OBJECT.pUndoAttr = aTmp.ReleaseUndo().release(); } OBJECT.pUndoFly = new SwUndoInsLayFormat( &rNewFly,0,0 ); } diff --git a/sw/source/core/undo/unsect.cxx b/sw/source/core/undo/unsect.cxx index f17cae630316..de7fa973ca9e 100644 --- a/sw/source/core/undo/unsect.cxx +++ b/sw/source/core/undo/unsect.cxx @@ -293,9 +293,9 @@ public: virtual void RedoImpl( ::sw::UndoRedoContext & ) override; }; -SwUndo * MakeUndoDelSection(SwSectionFormat const& rFormat) +std::unique_ptr<SwUndo> MakeUndoDelSection(SwSectionFormat const& rFormat) { - return new SwUndoDelSection(rFormat, *rFormat.GetSection(), + return o3tl::make_unique<SwUndoDelSection>(rFormat, *rFormat.GetSection(), rFormat.GetContent().GetContentIdx()); } @@ -395,10 +395,10 @@ public: virtual void RedoImpl( ::sw::UndoRedoContext & ) override; }; -SwUndo * +std::unique_ptr<SwUndo> MakeUndoUpdateSection(SwSectionFormat const& rFormat, bool const bOnlyAttr) { - return new SwUndoUpdateSection(*rFormat.GetSection(), + return o3tl::make_unique<SwUndoUpdateSection>(*rFormat.GetSection(), rFormat.GetContent().GetContentIdx(), bOnlyAttr); } diff --git a/sw/source/core/undo/untbl.cxx b/sw/source/core/undo/untbl.cxx ... etc. - the rest is truncated _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits