diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-10-08 11:22:10 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-10-09 12:09:55 +0200 |
commit | f7ce839c7844f029c0a1ac83a5638e83356b4c4b (patch) | |
tree | c93a342a577133b384a3ccc088d7d0675d4fb9e3 | |
parent | 4ba06560e33f17ca1ed72ad722c80eae5ffd4277 (diff) |
use unique_ptr in SfxUndoManager::AddUndoAction
Change-Id: I11483e3cece12a7373f4276972b4c899edf1ce15
Reviewed-on: https://gerrit.libreoffice.org/61566
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
124 files changed, 667 insertions, 714 deletions
diff --git a/chart2/source/controller/main/ChartController_Tools.cxx b/chart2/source/controller/main/ChartController_Tools.cxx index d91807f1e593..b1310ae68550 100644 --- a/chart2/source/controller/main/ChartController_Tools.cxx +++ b/chart2/source/controller/main/ChartController_Tools.cxx @@ -417,7 +417,7 @@ void ChartController::impl_PasteShapes( SdrModel* pModel ) } pDestPage->InsertObject( pNewObj ); - m_pDrawViewWrapper->AddUndo( new SdrUndoInsertObj( *pNewObj ) ); + m_pDrawViewWrapper->AddUndo( o3tl::make_unique<SdrUndoInsertObj>( *pNewObj ) ); xSelShape = xShape; } } @@ -480,7 +480,7 @@ void ChartController::impl_PasteStringAsTextShape( const OUString& rString, cons if ( pObj ) { m_pDrawViewWrapper->BegUndo( SvxResId( RID_SVX_3D_UNDO_EXCHANGE_PASTE ) ); - m_pDrawViewWrapper->AddUndo( new SdrUndoInsertObj( *pObj ) ); + m_pDrawViewWrapper->AddUndo( o3tl::make_unique<SdrUndoInsertObj>( *pObj ) ); m_pDrawViewWrapper->EndUndo(); impl_switchDiagramPositioningToExcludingPositioning(); diff --git a/cui/source/dialogs/SpellDialog.cxx b/cui/source/dialogs/SpellDialog.cxx index d71f12a41ac6..c92ec7d4ee5b 100644 --- a/cui/source/dialogs/SpellDialog.cxx +++ b/cui/source/dialogs/SpellDialog.cxx @@ -577,11 +577,11 @@ IMPL_LINK_NOARG(SpellDialog, ChangeAllHdl, Button*, void) if(nAdded == DictionaryError::NONE) { - SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl( - SPELLUNDO_CHANGE_ADD_TO_DICTIONARY, aDialogUndoLink); + std::unique_ptr<SpellUndoAction_Impl> pAction(new SpellUndoAction_Impl( + SPELLUNDO_CHANGE_ADD_TO_DICTIONARY, aDialogUndoLink)); pAction->SetDictionary(aXDictionary); pAction->SetAddedWord(aOldWord); - m_pSentenceED->AddUndoAction(pAction); + m_pSentenceED->AddUndoAction(std::move(pAction)); } m_pSentenceED->ChangeMarkedWord(aString, eLang); @@ -623,11 +623,11 @@ IMPL_LINK( SpellDialog, IgnoreAllHdl, Button *, pButton, void ) OUString() ); if(nAdded == DictionaryError::NONE) { - SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl( - SPELLUNDO_CHANGE_ADD_TO_DICTIONARY, aDialogUndoLink); + std::unique_ptr<SpellUndoAction_Impl> pAction(new SpellUndoAction_Impl( + SPELLUNDO_CHANGE_ADD_TO_DICTIONARY, aDialogUndoLink)); pAction->SetDictionary(aXDictionary); pAction->SetAddedWord(sErrorText); - m_pSentenceED->AddUndoAction(pAction); + m_pSentenceED->AddUndoAction(std::move(pAction)); } } @@ -764,7 +764,7 @@ IMPL_LINK(SpellDialog, LanguageSelectHdl, ListBox&, rBox, void) SpellContinue_Impl(); } - m_pSentenceED->AddUndoAction(new SpellUndoAction_Impl(SPELLUNDO_CHANGE_LANGUAGE, aDialogUndoLink)); + m_pSentenceED->AddUndoAction(o3tl::make_unique<SpellUndoAction_Impl>(SPELLUNDO_CHANGE_LANGUAGE, aDialogUndoLink)); } SpellDialog::UpdateBoxes_Impl(); } @@ -889,11 +889,11 @@ void SpellDialog::AddToDictionaryExecute( sal_uInt16 nItemId, PopupMenu const *p if (nAddRes == DictionaryError::NONE) { - SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl( - SPELLUNDO_CHANGE_ADD_TO_DICTIONARY, aDialogUndoLink); + std::unique_ptr<SpellUndoAction_Impl> pAction(new SpellUndoAction_Impl( + SPELLUNDO_CHANGE_ADD_TO_DICTIONARY, aDialogUndoLink)); pAction->SetDictionary( xDic ); pAction->SetAddedWord( aNewWord ); - m_pSentenceED->AddUndoAction( pAction ); + m_pSentenceED->AddUndoAction( std::move(pAction) ); } // failed because there is already an entry? if (DictionaryError::NONE != nAddRes && xDic->getEntry( aNewWord ).is()) @@ -919,7 +919,7 @@ IMPL_LINK(SpellDialog, ModifyHdl, Edit&, rEd, void) m_pSuggestionLB->Disable(); OUString sNewText( m_pSentenceED->GetText() ); m_pAutoCorrPB->Enable( sNewText != m_pSentenceED->GetText() ); - SpellUndoAction_Impl* pSpellAction = new SpellUndoAction_Impl(SPELLUNDO_CHANGE_TEXTENGINE, aDialogUndoLink); + std::unique_ptr<SpellUndoAction_Impl> pSpellAction(new SpellUndoAction_Impl(SPELLUNDO_CHANGE_TEXTENGINE, aDialogUndoLink)); if(!m_pChangeAllPB->IsEnabled()) { m_pChangeAllPB->Enable(); @@ -930,7 +930,7 @@ IMPL_LINK(SpellDialog, ModifyHdl, Edit&, rEd, void) m_pChangePB->Enable(); pSpellAction->SetEnableChangePB(); } - m_pSentenceED->AddUndoAction(pSpellAction); + m_pSentenceED->AddUndoAction(std::move(pSpellAction)); } }; @@ -1598,15 +1598,15 @@ bool SentenceEditWindow_Impl::MarkNextError( bool bIgnoreCurrentError, const css MoveErrorMarkTo(aCursor.GetIndex(), pNextError->GetEnd(), bGrammarError); bRet = true; //add an undo action - SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl( - SPELLUNDO_CHANGE_NEXTERROR, GetSpellDialog()->aDialogUndoLink); + std::unique_ptr<SpellUndoAction_Impl> pAction(new SpellUndoAction_Impl( + SPELLUNDO_CHANGE_NEXTERROR, GetSpellDialog()->aDialogUndoLink)); pAction->SetErrorMove(nOldErrorStart, nOldErrorEnd); const SpellErrorAttrib* pOldAttrib = static_cast<const SpellErrorAttrib*>( pTextEngine->FindAttrib( TextPaM(0, nOldErrorStart), TEXTATTR_SPELL_ERROR )); pAction->SetErrorLanguageSelected(pOldAttrib && pOldAttrib->GetErrorDescription().aSuggestions.getLength() && LanguageTag( pOldAttrib->GetErrorDescription().aLocale).getLanguageType() == GetSpellDialog()->m_pLanguageLB->GetSelectedLanguage()); - AddUndoAction(pAction); + AddUndoAction(std::move(pAction)); } else m_nErrorStart = m_nErrorEnd = nTextLen; @@ -1688,10 +1688,10 @@ void SentenceEditWindow_Impl::ChangeMarkedWord(const OUString& rNewWord, Languag nEndTemp += nDiffLen; m_nErrorEnd = static_cast<sal_Int32>(nEndTemp); - SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl( - SPELLUNDO_MOVE_ERROREND, GetSpellDialog()->aDialogUndoLink); + std::unique_ptr<SpellUndoAction_Impl> pAction(new SpellUndoAction_Impl( + SPELLUNDO_MOVE_ERROREND, GetSpellDialog()->aDialogUndoLink)); pAction->SetOffset(nDiffLen); - AddUndoAction(pAction); + AddUndoAction(std::move(pAction)); if(pSpellErrorDescription) SetAttrib( SpellErrorAttrib(*pSpellErrorDescription), 0, m_nErrorStart, m_nErrorEnd ); SetAttrib( SpellLanguageAttrib(eLanguage), 0, m_nErrorStart, m_nErrorEnd ); @@ -1931,10 +1931,10 @@ void SentenceEditWindow_Impl::ResetUndo() } -void SentenceEditWindow_Impl::AddUndoAction( SfxUndoAction *pAction ) +void SentenceEditWindow_Impl::AddUndoAction( std::unique_ptr<SfxUndoAction> pAction ) { SfxUndoManager& rUndoMgr = GetTextEngine()->GetUndoManager(); - rUndoMgr.AddUndoAction(pAction); + rUndoMgr.AddUndoAction(std::move(pAction)); GetSpellDialog()->m_pUndoPB->Enable(); } @@ -2002,9 +2002,8 @@ void SentenceEditWindow_Impl::SetUndoEditMode(bool bSet) pTextEngine->RemoveAttribs( 0, sal_uInt16(TEXTATTR_FONTWEIGHT) ); //put the appropriate action on the Undo-stack - SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl( - SPELLUNDO_UNDO_EDIT_MODE, GetSpellDialog()->aDialogUndoLink); - AddUndoAction(pAction); + AddUndoAction( o3tl::make_unique<SpellUndoAction_Impl>( + SPELLUNDO_UNDO_EDIT_MODE, GetSpellDialog()->aDialogUndoLink) ); pSpellDialog->m_pChangePB->Enable(); } diff --git a/cui/source/inc/SpellDialog.hxx b/cui/source/inc/SpellDialog.hxx index 41d68d99ba68..ab7f22b79bd4 100644 --- a/cui/source/inc/SpellDialog.hxx +++ b/cui/source/inc/SpellDialog.hxx @@ -110,7 +110,7 @@ public: void ResetUndo(); void Undo(); - void AddUndoAction( SfxUndoAction *pAction ); + void AddUndoAction( std::unique_ptr<SfxUndoAction> pAction ); size_t GetUndoActionCount(); void UndoActionStart( sal_uInt16 nId ); void UndoActionEnd(); diff --git a/cui/source/tabpages/transfrm.cxx b/cui/source/tabpages/transfrm.cxx index 46c3d2570762..eac242eda649 100644 --- a/cui/source/tabpages/transfrm.cxx +++ b/cui/source/tabpages/transfrm.cxx @@ -526,10 +526,9 @@ bool SvxSlantTabPage::FillItemSet(SfxItemSet* rAttrs) static_cast< SdrObjCustomShape& >( *pView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj())); SdrModel& rModel(rSdrObjCustomShape.getSdrModelFromSdrObject()); - SdrUndoAction* pUndo( - rModel.IsUndoEnabled() - ? rModel.GetSdrUndoFactory().CreateUndoAttrObject(rSdrObjCustomShape) - : nullptr); + std::unique_ptr<SdrUndoAction> pUndo; + if (rModel.IsUndoEnabled()) + pUndo = rModel.GetSdrUndoFactory().CreateUndoAttrObject(rSdrObjCustomShape); if(pUndo) { @@ -561,7 +560,7 @@ bool SvxSlantTabPage::FillItemSet(SfxItemSet* rAttrs) if (pUndo) { - rModel.AddUndo(pUndo); + rModel.AddUndo(std::move(pUndo)); rModel.EndUndo(); } } diff --git a/dbaccess/source/ui/control/sqledit.cxx b/dbaccess/source/ui/control/sqledit.cxx index db774978ad60..c94c5335b8df 100644 --- a/dbaccess/source/ui/control/sqledit.cxx +++ b/dbaccess/source/ui/control/sqledit.cxx @@ -153,10 +153,10 @@ IMPL_LINK_NOARG(OSqlEdit, OnUndoActionTimer, Timer *, void) { OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController(); SfxUndoManager& rUndoMgr = rController.GetUndoManager(); - OSqlEditUndoAct* pUndoAct = new OSqlEditUndoAct( this ); + std::unique_ptr<OSqlEditUndoAct> pUndoAct(new OSqlEditUndoAct( this )); pUndoAct->SetOriginalText( m_strOrigText ); - rUndoMgr.AddUndoAction( pUndoAct ); + rUndoMgr.AddUndoAction( std::move(pUndoAct) ); rController.InvalidateFeature(SID_UNDO); rController.InvalidateFeature(SID_REDO); diff --git a/dbaccess/source/ui/inc/JoinTableView.hxx b/dbaccess/source/ui/inc/JoinTableView.hxx index b44aa22d7cab..ffa729812805 100644 --- a/dbaccess/source/ui/inc/JoinTableView.hxx +++ b/dbaccess/source/ui/inc/JoinTableView.hxx @@ -318,7 +318,7 @@ namespace dbaui modified @param _pAction a possible undo action to add at the controller */ - void invalidateAndModify(SfxUndoAction *_pAction); + void invalidateAndModify(std::unique_ptr<SfxUndoAction> _pAction); private: using Window::Scroll; diff --git a/dbaccess/source/ui/inc/singledoccontroller.hxx b/dbaccess/source/ui/inc/singledoccontroller.hxx index 018a69dd01f2..37cc6740063e 100644 --- a/dbaccess/source/ui/inc/singledoccontroller.hxx +++ b/dbaccess/source/ui/inc/singledoccontroller.hxx @@ -58,7 +58,7 @@ namespace dbaui additionally invalidates the UNDO and REDO slot @param pAction the undo action to add */ - void addUndoActionAndInvalidate( SfxUndoAction* pAction ); + void addUndoActionAndInvalidate( std::unique_ptr<SfxUndoAction> pAction ); // OGenericUnoController virtual FeatureState GetState( sal_uInt16 nId ) const override; diff --git a/dbaccess/source/ui/misc/singledoccontroller.cxx b/dbaccess/source/ui/misc/singledoccontroller.cxx index 0a0411bbb891..072a63eece79 100644 --- a/dbaccess/source/ui/misc/singledoccontroller.cxx +++ b/dbaccess/source/ui/misc/singledoccontroller.cxx @@ -77,10 +77,10 @@ namespace dbaui return m_pData->m_xUndoManager->GetSfxUndoManager(); } - void OSingleDocumentController::addUndoActionAndInvalidate(SfxUndoAction *_pAction) + void OSingleDocumentController::addUndoActionAndInvalidate(std::unique_ptr<SfxUndoAction> _pAction) { // add undo action - GetUndoManager().AddUndoAction( _pAction ); + GetUndoManager().AddUndoAction( std::move(_pAction) ); // when we add an undo action the controller was modified setModified( true ); diff --git a/dbaccess/source/ui/querydesign/JoinTableView.cxx b/dbaccess/source/ui/querydesign/JoinTableView.cxx index dda98512cb77..5e46b34afbca 100644 --- a/dbaccess/source/ui/querydesign/JoinTableView.cxx +++ b/dbaccess/source/ui/querydesign/JoinTableView.cxx @@ -42,6 +42,7 @@ #include <UITools.hxx> #include <cppuhelper/exc_hlp.hxx> #include <tools/diagnose_ex.h> +#include <o3tl/make_unique.hxx> #include <algorithm> #include <functional> @@ -1065,10 +1066,10 @@ IMPL_LINK_NOARG(OJoinTableView, OnDragScrollTimer, Timer *, void) ScrollWhileDragging(); } -void OJoinTableView::invalidateAndModify(SfxUndoAction *_pAction) +void OJoinTableView::invalidateAndModify(std::unique_ptr<SfxUndoAction> _pAction) { Invalidate(InvalidateFlags::NoChildren); - m_pView->getController().addUndoActionAndInvalidate(_pAction); + m_pView->getController().addUndoActionAndInvalidate(std::move(_pAction)); } void OJoinTableView::TabWinMoved(OTableWindow* ptWhich, const Point& ptOldPosition) @@ -1076,7 +1077,7 @@ void OJoinTableView::TabWinMoved(OTableWindow* ptWhich, const Point& ptOldPositi Point ptThumbPos(GetHScrollBar().GetThumbPos(), GetVScrollBar().GetThumbPos()); ptWhich->GetData()->SetPosition(ptWhich->GetPosPixel() + ptThumbPos); - invalidateAndModify(new OJoinMoveTabWinUndoAct(this, ptOldPosition, ptWhich)); + invalidateAndModify(o3tl::make_unique<OJoinMoveTabWinUndoAct>(this, ptOldPosition, ptWhich)); } void OJoinTableView::TabWinSized(OTableWindow* ptWhich, const Point& ptOldPosition, const Size& szOldSize) @@ -1084,7 +1085,7 @@ void OJoinTableView::TabWinSized(OTableWindow* ptWhich, const Point& ptOldPositi ptWhich->GetData()->SetSize(ptWhich->GetSizePixel()); ptWhich->GetData()->SetPosition(ptWhich->GetPosPixel()); - invalidateAndModify(new OJoinSizeTabWinUndoAct(this, ptOldPosition, szOldSize, ptWhich)); + invalidateAndModify(o3tl::make_unique<OJoinSizeTabWinUndoAct>(this, ptOldPosition, szOldSize, ptWhich)); } bool OJoinTableView::IsAddAllowed() diff --git a/dbaccess/source/ui/querydesign/QueryTableView.cxx b/dbaccess/source/ui/querydesign/QueryTableView.cxx index 81573f0498a7..2e462c444dac 100644 --- a/dbaccess/source/ui/querydesign/QueryTableView.cxx +++ b/dbaccess/source/ui/querydesign/QueryTableView.cxx @@ -49,6 +49,7 @@ #include <strings.hrc> #include <strings.hxx> #include <svtools/treelistentry.hxx> +#include <o3tl/make_unique.hxx> using namespace dbaui; using namespace ::com::sun::star::uno; @@ -67,13 +68,13 @@ namespace @param _bOwner is the undo action the owner */ void addUndoAction( OQueryTableView const * _pView, - OQueryTabConnUndoAction* _pUndoAction, + std::unique_ptr<OQueryTabConnUndoAction> _pUndoAction, OQueryTableConnection* _pConnection, bool _bOwner = false) { _pUndoAction->SetOwnership(_bOwner); _pUndoAction->SetConnection(_pConnection); - _pView->getDesignView()->getController().addUndoActionAndInvalidate(_pUndoAction); + _pView->getDesignView()->getController().addUndoActionAndInvalidate(std::move(_pUndoAction)); } /** openJoinDialog opens the join dialog with this connection data @param _pView the view which we use @@ -110,7 +111,7 @@ namespace // add an undo action if ( _bAddUndo ) addUndoAction( _pView, - new OQueryAddTabConnUndoAction(_pView), + o3tl::make_unique<OQueryAddTabConnUndoAction>(_pView), static_cast< OQueryTableConnection*>(_pConnection)); // redraw _pConnection->RecalcLines(); @@ -421,16 +422,14 @@ void OQueryTableView::AddTabWin(const OUString& _rComposedName, const OUString& // No need to initialize, as that happens in ShowTabWin // New UndoAction - OQueryTabWinShowUndoAct* pUndoAction = new OQueryTabWinShowUndoAct(this); + std::unique_ptr<OQueryTabWinShowUndoAct> pUndoAction(new OQueryTabWinShowUndoAct(this)); pUndoAction->SetTabWin(pNewTabWin); // Window - bool bSuccess = ShowTabWin(pNewTabWin, pUndoAction,bAppend); + bool bSuccess = ShowTabWin(pNewTabWin, pUndoAction.get(), bAppend); if(!bSuccess) { // reset table window pUndoAction->SetTabWin(nullptr); pUndoAction->SetOwnership(false); - - delete pUndoAction; return; } @@ -531,7 +530,7 @@ void OQueryTableView::AddTabWin(const OUString& _rComposedName, const OUString& } // My parent needs to be informed about the delete - m_pView->getController().addUndoActionAndInvalidate( pUndoAction ); + m_pView->getController().addUndoActionAndInvalidate( std::move(pUndoAction) ); } void OQueryTableView::AddConnection(const OJoinExchangeData& jxdSource, const OJoinExchangeData& jxdDest) @@ -631,7 +630,7 @@ bool OQueryTableView::RemoveConnection(VclPtr<OTableConnection>& rConnection, bo // add undo action addUndoAction(this, - new OQueryDelTabConnUndoAction(this), + o3tl::make_unique<OQueryDelTabConnUndoAction>(this), xConnection.get(), true); @@ -688,16 +687,16 @@ void OQueryTableView::RemoveTabWin(OTableWindow* pTabWin) rUndoMgr.EnterListAction(DBA_RES(STR_QUERY_UNDO_TABWINDELETE) , OUString(), 0, ViewShellId(-1)); // add the Undo-Action - OQueryTabWinDelUndoAct* pUndoAction = new OQueryTabWinDelUndoAct(this); + std::unique_ptr<OQueryTabWinDelUndoAct> pUndoAction(new OQueryTabWinDelUndoAct(this)); pUndoAction->SetTabWin(static_cast< OQueryTableWindow*>(pTabWin)); // and hide the window - HideTabWin(static_cast< OQueryTableWindow*>(pTabWin), pUndoAction); + HideTabWin(static_cast< OQueryTableWindow*>(pTabWin), pUndoAction.get()); // Undo Actions and delete the fields in SelectionBrowseBox pParent->TableDeleted( static_cast< OQueryTableWindowData*>(pTabWin->GetData().get())->GetAliasName() ); - m_pView->getController().addUndoActionAndInvalidate( pUndoAction ); + m_pView->getController().addUndoActionAndInvalidate( std::move(pUndoAction) ); rUndoMgr.LeaveListAction(); modified(); diff --git a/dbaccess/source/ui/querydesign/QueryTextView.cxx b/dbaccess/source/ui/querydesign/QueryTextView.cxx index 1b192ce1dcca..3ff1296c8579 100644 --- a/dbaccess/source/ui/querydesign/QueryTextView.cxx +++ b/dbaccess/source/ui/querydesign/QueryTextView.cxx @@ -75,10 +75,10 @@ OUString OQueryTextView::getStatement() void OQueryTextView::clear() { - OSqlEditUndoAct* pUndoAct = new OSqlEditUndoAct( m_pEdit ); + std::unique_ptr<OSqlEditUndoAct> pUndoAct(new OSqlEditUndoAct( m_pEdit )); pUndoAct->SetOriginalText( m_pEdit->GetText() ); - getContainerWindow()->getDesignView()->getController().addUndoActionAndInvalidate( pUndoAct ); + getContainerWindow()->getDesignView()->getController().addUndoActionAndInvalidate( std::move(pUndoAct) ); m_pEdit->SetText(OUString()); } diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx index 178f90991727..37475fb2d01b 100644 --- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx +++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx @@ -310,11 +310,11 @@ void OSelectionBrowseBox::ColumnMoved( sal_uInt16 nColId, bool _bCreateUndo ) // create the undo action if ( !m_bInUndoMode && _bCreateUndo ) { - OTabFieldMovedUndoAct* pUndoAct = new OTabFieldMovedUndoAct(this); + std::unique_ptr<OTabFieldMovedUndoAct> pUndoAct(new OTabFieldMovedUndoAct(this)); pUndoAct->SetColumnPosition( nOldPos + 1); pUndoAct->SetTabFieldDescr(pOldEntry); - getDesignView()->getController().addUndoActionAndInvalidate(pUndoAct); + getDesignView()->getController().addUndoActionAndInvalidate(std::move(pUndoAct)); } } } @@ -1289,10 +1289,10 @@ void OSelectionBrowseBox::RemoveField(sal_uInt16 nColumnId ) // trigger UndoAction if ( !m_bInUndoMode ) { - OTabFieldDelUndoAct* pUndoAction = new OTabFieldDelUndoAct( this ); + std::unique_ptr<OTabFieldDelUndoAct> pUndoAction(new OTabFieldDelUndoAct( this )); pUndoAction->SetTabFieldDescr(pDesc); pUndoAction->SetColumnPosition(nPos); - rController.addUndoActionAndInvalidate( pUndoAction ); + rController.addUndoActionAndInvalidate( std::move(pUndoAction) ); } RemoveColumn(nColumnId); @@ -1578,10 +1578,10 @@ OTableFieldDescRef OSelectionBrowseBox::InsertField(const OTableFieldDescRef& _r if ( !m_bInUndoMode ) { // trigger UndoAction - OTabFieldCreateUndoAct* pUndoAction = new OTabFieldCreateUndoAct( this ); + std::unique_ptr<OTabFieldCreateUndoAct> pUndoAction(new OTabFieldCreateUndoAct( this )); pUndoAction->SetTabFieldDescr( pEntry ); pUndoAction->SetColumnPosition(_nColumnPosition); - getDesignView()->getController().addUndoActionAndInvalidate( pUndoAction ); + getDesignView()->getController().addUndoActionAndInvalidate( std::move(pUndoAction) ); } return pEntry; @@ -2322,10 +2322,10 @@ void OSelectionBrowseBox::ColumnResized(sal_uInt16 nColId) if ( !m_bInUndoMode ) { // create the undo action - OTabFieldSizedUndoAct* pUndo = new OTabFieldSizedUndoAct(this); + std::unique_ptr<OTabFieldSizedUndoAct> pUndo(new OTabFieldSizedUndoAct(this)); pUndo->SetColumnPosition( nPos ); pUndo->SetOriginalWidth(pEntry->GetColWidth()); - getDesignView()->getController().addUndoActionAndInvalidate(pUndo); + getDesignView()->getController().addUndoActionAndInvalidate(std::move(pUndo)); } pEntry->SetColWidth(sal_uInt16(GetColumnWidth(nColId))); } @@ -2452,12 +2452,12 @@ void OSelectionBrowseBox::appendUndoAction(const OUString& _rOldValue,const OUSt { if ( !m_bInUndoMode && _rNewValue != _rOldValue ) { - OTabFieldCellModifiedUndoAct* pUndoAct = new OTabFieldCellModifiedUndoAct(this); + std::unique_ptr<OTabFieldCellModifiedUndoAct> pUndoAct(new OTabFieldCellModifiedUndoAct(this)); pUndoAct->SetCellIndex(_nRow); OSL_ENSURE(GetColumnPos(GetCurColumnId()) != BROWSER_INVALIDID,"Current position isn't valid!"); pUndoAct->SetColumnPosition( GetColumnPos(GetCurColumnId()) ); pUndoAct->SetCellContents(_rOldValue); - getDesignView()->getController().addUndoActionAndInvalidate(pUndoAct); + getDesignView()->getController().addUndoActionAndInvalidate(std::move(pUndoAct)); } } diff --git a/dbaccess/source/ui/tabledesign/TEditControl.cxx b/dbaccess/source/ui/tabledesign/TEditControl.cxx index 841ab7ba8161..03936e7611f6 100644 --- a/dbaccess/source/ui/tabledesign/TEditControl.cxx +++ b/dbaccess/source/ui/tabledesign/TEditControl.cxx @@ -41,6 +41,7 @@ #include <SqlNameEdit.hxx> #include <TableRowExchange.hxx> #include <sot/storage.hxx> +#include <o3tl/make_unique.hxx> #include <UITools.hxx> #include "TableFieldControl.hxx" #include <dsntypes.hxx> @@ -507,7 +508,7 @@ void OTableEditorCtrl::SaveData(long nRow, sal_uInt16 nColId) // If FieldDescr exists, the field is deleted and the old content restored if (pActFieldDescr) { - GetUndoManager().AddUndoAction(new OTableEditorTypeSelUndoAct(this, nRow, FIELD_TYPE, pActFieldDescr->getTypeInfo())); + GetUndoManager().AddUndoAction(o3tl::make_unique<OTableEditorTypeSelUndoAct>(this, nRow, FIELD_TYPE, pActFieldDescr->getTypeInfo())); SwitchType(TOTypeInfoSP()); pActFieldDescr = pActRow->GetActFieldDescr(); } @@ -658,14 +659,14 @@ void OTableEditorCtrl::CellModified( long nRow, sal_uInt16 nColId ) nInvalidateTypeEvent = Application::PostUserEvent( LINK(this, OTableEditorCtrl, InvalidateFieldType), nullptr, true ); pActFieldDescr = pActRow->GetActFieldDescr(); pDescrWin->DisplayData( pActFieldDescr ); - GetUndoManager().AddUndoAction( new OTableEditorTypeSelUndoAct(this, nRow, nColId+1, TOTypeInfoSP()) ); + GetUndoManager().AddUndoAction( o3tl::make_unique<OTableEditorTypeSelUndoAct>(this, nRow, nColId+1, TOTypeInfoSP()) ); } if( nColId != FIELD_TYPE ) - GetUndoManager().AddUndoAction( new OTableDesignCellUndoAct(this, nRow, nColId) ); + GetUndoManager().AddUndoAction( o3tl::make_unique<OTableDesignCellUndoAct>(this, nRow, nColId) ); else { - GetUndoManager().AddUndoAction(new OTableEditorTypeSelUndoAct(this, GetCurRow(), nColId, GetFieldDescr(GetCurRow())->getTypeInfo())); + GetUndoManager().AddUndoAction(o3tl::make_unique<OTableEditorTypeSelUndoAct>(this, GetCurRow(), nColId, GetFieldDescr(GetCurRow())->getTypeInfo())); resetType(); } @@ -799,7 +800,7 @@ void OTableEditorCtrl::InsertRows( long nRow ) RowInserted( nRow,vInsertedUndoRedoRows.size() ); // Create the Undo-Action - GetUndoManager().AddUndoAction( new OTableEditorInsUndoAct(this, nRow,vInsertedUndoRedoRows) ); + GetUndoManager().AddUndoAction( o3tl::make_unique<OTableEditorInsUndoAct>(this, nRow,vInsertedUndoRedoRows) ); GetView()->getController().setModified( true ); InvalidateFeatures(); } @@ -808,7 +809,7 @@ void OTableEditorCtrl::DeleteRows() { OSL_ENSURE(GetView()->getController().isDropAllowed(),"Call of DeleteRows not valid here. Please check isDropAllowed!"); // Create the Undo-Action - GetUndoManager().AddUndoAction( new OTableEditorDelUndoAct(this) ); + GetUndoManager().AddUndoAction( o3tl::make_unique<OTableEditorDelUndoAct>(this) ); // Delete all marked rows long nIndex = FirstSelectedRow(); @@ -845,7 +846,7 @@ void OTableEditorCtrl::InsertNewRows( long nRow ) long nInsertRows = GetSelectRowCount(); if( !nInsertRows ) nInsertRows = 1; - GetUndoManager().AddUndoAction( new OTableEditorInsNewUndoAct(this, nRow, nInsertRows) ); + GetUndoManager().AddUndoAction( o3tl::make_unique<OTableEditorInsNewUndoAct>(this, nRow, nInsertRows) ); // Insert the number of selected rows for( long i=nRow; i<(nRow+nInsertRows); i++ ) m_pRowList->insert( m_pRowList->begin()+i ,std::make_shared<OTableRow>()); @@ -1525,7 +1526,7 @@ void OTableEditorCtrl::SetPrimaryKey( bool bSet ) } } - GetUndoManager().AddUndoAction( new OPrimKeyUndoAct(this, aDeletedPrimKeys, aInsertedPrimKeys) ); + GetUndoManager().AddUndoAction( o3tl::make_unique<OPrimKeyUndoAct>(this, aDeletedPrimKeys, aInsertedPrimKeys) ); // Invalidate the handle-columns InvalidateHandleColumn(); diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx index 16deb64c85f2..4a5daed2c2bf 100644 --- a/editeng/source/editeng/impedit.hxx +++ b/editeng/source/editeng/impedit.hxx @@ -546,11 +546,11 @@ private: void TextModified(); void CalcHeight( ParaPortion* pPortion ); - void InsertUndo( EditUndo* pUndo, bool bTryMerge = false ); + void InsertUndo( std::unique_ptr<EditUndo> pUndo, bool bTryMerge = false ); void ResetUndoManager(); bool HasUndoManager() const { return pUndoManager != nullptr; } - EditUndoSetAttribs* CreateAttribUndo( EditSelection aSel, const SfxItemSet& rSet ); + std::unique_ptr<EditUndoSetAttribs> CreateAttribUndo( EditSelection aSel, const SfxItemSet& rSet ); std::unique_ptr<EditTextObject> GetEmptyTextObject(); diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx index e331006de1d3..c15f0fde7cbf 100644 --- a/editeng/source/editeng/impedit2.cxx +++ b/editeng/source/editeng/impedit2.cxx @@ -2088,12 +2088,11 @@ void ImpEditEngine::ImpRemoveChars( const EditPaM& rPaM, sal_Int32 nChars ) { EditSelection aSel( rPaM ); aSel.Max().SetIndex( aSel.Max().GetIndex() + nChars ); - EditUndoSetAttribs* pAttrUndo = CreateAttribUndo( aSel, GetEmptyItemSet() ); - InsertUndo( pAttrUndo ); + InsertUndo( CreateAttribUndo( aSel, GetEmptyItemSet() ) ); break; // for } } - InsertUndo(new EditUndoRemoveChars(pEditEngine, CreateEPaM(rPaM), aStr)); + InsertUndo(o3tl::make_unique<EditUndoRemoveChars>(pEditEngine, CreateEPaM(rPaM), aStr)); } aEditDoc.RemoveChars( rPaM, nChars ); @@ -2152,7 +2151,7 @@ EditSelection ImpEditEngine::ImpMoveParagraphs( Range aOldPositions, sal_Int32 n aBeginMovingParagraphsHdl.Call( aMoveParagraphsInfo ); if ( IsUndoEnabled() && !IsInUndo()) - InsertUndo(new EditUndoMoveParagraphs(pEditEngine, aOldPositions, nNewPos)); + InsertUndo(o3tl::make_unique<EditUndoMoveParagraphs>(pEditEngine, aOldPositions, nNewPos)); // do not lose sight of the Position ! ParaPortion* pDestPortion = GetParaPortions().SafeGetObject( nNewPos ); @@ -2238,7 +2237,7 @@ EditPaM ImpEditEngine::ImpConnectParagraphs( ContentNode* pLeft, ContentNode* pR if ( IsUndoEnabled() && !IsInUndo() ) { - InsertUndo( new EditUndoConnectParas(pEditEngine, + InsertUndo( o3tl::make_unique<EditUndoConnectParas>(pEditEngine, aEditDoc.GetPos( pLeft ), pLeft->Len(), pLeft->GetContentAttribs().GetItems(), pRight->GetContentAttribs().GetItems(), pLeft->GetStyleSheet(), pRight->GetStyleSheet(), bBackward ) ); @@ -2488,7 +2487,7 @@ void ImpEditEngine::ImpRemoveParagraph( sal_Int32 nPara ) ParaAttribsChanged( pNextNode ); if ( IsUndoEnabled() && !IsInUndo() ) - InsertUndo(new EditUndoDelContent(pEditEngine, pNode, nPara)); + InsertUndo(o3tl::make_unique<EditUndoDelContent>(pEditEngine, pNode, nPara)); else { aEditDoc.RemoveItemsFromPool(*pNode); @@ -2654,9 +2653,9 @@ EditPaM ImpEditEngine::InsertTextUserInput( const EditSelection& rCurSel, if ( IsUndoEnabled() && !IsInUndo() ) { - EditUndoInsertChars* pNewUndo = new EditUndoInsertChars(pEditEngine, CreateEPaM(aPaM), OUString(c)); + std::unique_ptr<EditUndoInsertChars> pNewUndo(new EditUndoInsertChars(pEditEngine, CreateEPaM(aPaM), OUString(c))); bool bTryMerge = !bDoOverwrite && ( c != ' ' ); - InsertUndo( pNewUndo, bTryMerge ); + InsertUndo( std::move(pNewUndo), bTryMerge ); } aEditDoc.InsertText( aPaM, OUString(c) ); @@ -2723,7 +2722,7 @@ EditPaM ImpEditEngine::ImpInsertText(const EditSelection& aCurSel, const OUStrin aLine = aLine.copy( 0, nMaxNewChars ); // Delete the Rest... } if ( IsUndoEnabled() && !IsInUndo() ) - InsertUndo(new EditUndoInsertChars(pEditEngine, CreateEPaM(aPaM), aLine)); + InsertUndo(o3tl::make_unique<EditUndoInsertChars>(pEditEngine, CreateEPaM(aPaM), aLine)); // Tabs ? if ( aLine.indexOf( '\t' ) == -1 ) aPaM = aEditDoc.InsertText( aPaM, aLine ); @@ -2781,7 +2780,7 @@ EditPaM ImpEditEngine::ImpFastInsertText( EditPaM aPaM, const OUString& rStr ) if ( ( aPaM.GetNode()->Len() + rStr.getLength() ) < MAXCHARSINPARA ) { if ( IsUndoEnabled() && !IsInUndo() ) - InsertUndo(new EditUndoInsertChars(pEditEngine, CreateEPaM(aPaM), rStr)); + InsertUndo(o3tl::make_unique<EditUndoInsertChars>(pEditEngine, CreateEPaM(aPaM), rStr)); aPaM = aEditDoc.InsertText( aPaM, rStr ); TextModified(); @@ -2806,7 +2805,7 @@ EditPaM ImpEditEngine::ImpInsertFeature(const EditSelection& rCurSel, const SfxP return aPaM; if ( IsUndoEnabled() && !IsInUndo() ) - InsertUndo(new EditUndoInsertFeature(pEditEngine, CreateEPaM(aPaM), rItem)); + InsertUndo(o3tl::make_unique<EditUndoInsertFeature>(pEditEngine, CreateEPaM(aPaM), rItem)); aPaM = aEditDoc.InsertFeature( aPaM, rItem ); UpdateFields(); @@ -2840,7 +2839,7 @@ EditPaM ImpEditEngine::ImpInsertParaBreak( EditPaM& rPaM, bool bKeepEndingAttrib } if ( IsUndoEnabled() && !IsInUndo() ) - InsertUndo(new EditUndoSplitPara(pEditEngine, aEditDoc.GetPos(rPaM.GetNode()), rPaM.GetIndex())); + InsertUndo(o3tl::make_unique<EditUndoSplitPara>(pEditEngine, aEditDoc.GetPos(rPaM.GetNode()), rPaM.GetIndex())); EditPaM aPaM( aEditDoc.InsertParaBreak( rPaM, bKeepEndingAttribs ) ); @@ -2899,10 +2898,10 @@ EditPaM ImpEditEngine::ImpFastInsertParagraph( sal_Int32 nPara ) if ( nPara ) { OSL_ENSURE( aEditDoc.GetObject( nPara-1 ), "FastInsertParagraph: Prev does not exist" ); - InsertUndo(new EditUndoSplitPara(pEditEngine, nPara-1, aEditDoc.GetObject( nPara-1 )->Len())); + InsertUndo(o3tl::make_unique<EditUndoSplitPara>(pEditEngine, nPara-1, aEditDoc.GetObject( nPara-1 )->Len())); } else - InsertUndo(new EditUndoSplitPara(pEditEngine, 0, 0)); + InsertUndo(o3tl::make_unique<EditUndoSplitPara>(pEditEngine, 0, 0)); } ContentNode* pNode = new ContentNode( aEditDoc.GetItemPool() ); diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index c57ba48bd237..66cd22344d0c 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -2686,7 +2686,7 @@ EditSelection ImpEditEngine::TransliterateText( const EditSelection& rSelection, bool bChanges = false; bool bLenChanged = false; - EditUndoTransliteration* pUndo = nullptr; + std::unique_ptr<EditUndoTransliteration> pUndo; utl::TransliterationWrapper aTransliterationWrapper( ::comphelper::getProcessComponentContext(), nTransliterationMode ); bool bConsiderLanguage = aTransliterationWrapper.needLanguageForTheMode(); @@ -2919,7 +2919,7 @@ EditSelection ImpEditEngine::TransliterateText( const EditSelection& rSelection, aNewSel = aSel; ESelection aESel( CreateESel( aSel ) ); - pUndo = new EditUndoTransliteration(pEditEngine, aESel, nTransliterationMode); + pUndo.reset(new EditUndoTransliteration(pEditEngine, aESel, nTransliterationMode)); const bool bSingleNode = aSel.Min().GetNode()== aSel.Max().GetNode(); const bool bHasAttribs = aSel.Min().GetNode()->GetCharAttribs().HasAttrib( aSel.Min().GetIndex(), aSel.Max().GetIndex() ); @@ -2959,7 +2959,7 @@ EditSelection ImpEditEngine::TransliterateText( const EditSelection& rSelection, { ESelection aESel( CreateESel( aNewSel ) ); pUndo->SetNewSelection( aESel ); - InsertUndo( pUndo ); + InsertUndo( std::move(pUndo) ); } if ( bChanges ) diff --git a/editeng/source/editeng/impedit5.cxx b/editeng/source/editeng/impedit5.cxx index aa34f0db573c..e9e7c67046ce 100644 --- a/editeng/source/editeng/impedit5.cxx +++ b/editeng/source/editeng/impedit5.cxx @@ -24,6 +24,7 @@ #include <svl/hint.hxx> #include <editeng/lrspitem.hxx> #include <sfx2/app.hxx> +#include <o3tl/make_unique.hxx> void ImpEditEngine::SetStyleSheetPool( SfxStyleSheetPool* pSPool ) { @@ -79,7 +80,7 @@ void ImpEditEngine::SetStyleSheet( sal_Int32 nPara, SfxStyleSheet* pStyle ) aNewStyleName = pStyle->GetName(); InsertUndo( - new EditUndoSetStyleSheet(pEditEngine, aEditDoc.GetPos( pNode ), + o3tl::make_unique<EditUndoSetStyleSheet>(pEditEngine, aEditDoc.GetPos( pNode ), aPrevStyleName, pCurStyle ? pCurStyle->GetFamily() : SfxStyleFamily::Para, aNewStyleName, pStyle ? pStyle->GetFamily() : SfxStyleFamily::Para, pNode->GetContentAttribs().GetItems() ) ); @@ -175,7 +176,7 @@ void ImpEditEngine::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) Dispose(); } -EditUndoSetAttribs* ImpEditEngine::CreateAttribUndo( EditSelection aSel, const SfxItemSet& rSet ) +std::unique_ptr<EditUndoSetAttribs> ImpEditEngine::CreateAttribUndo( EditSelection aSel, const SfxItemSet& rSet ) { DBG_ASSERT( !aSel.DbgIsBuggy( aEditDoc ), "CreateAttribUndo: Incorrect selection "); aSel.Adjust( aEditDoc ); @@ -187,16 +188,16 @@ EditUndoSetAttribs* ImpEditEngine::CreateAttribUndo( EditSelection aSel, const S DBG_ASSERT( nStartNode <= nEndNode, "CreateAttribUndo: Start > End ?!" ); - EditUndoSetAttribs* pUndo = nullptr; + std::unique_ptr<EditUndoSetAttribs> pUndo; if ( rSet.GetPool() != &aEditDoc.GetItemPool() ) { SfxItemSet aTmpSet( GetEmptyItemSet() ); aTmpSet.Put( rSet ); - pUndo = new EditUndoSetAttribs(pEditEngine, aESel, aTmpSet); + pUndo.reset( new EditUndoSetAttribs(pEditEngine, aESel, aTmpSet) ); } else { - pUndo = new EditUndoSetAttribs(pEditEngine, aESel, rSet); + pUndo.reset( new EditUndoSetAttribs(pEditEngine, aESel, rSet) ); } SfxItemPool* pPool = pUndo->GetNewAttribs().GetPool(); @@ -261,16 +262,15 @@ void ImpEditEngine::UndoActionEnd() } } -void ImpEditEngine::InsertUndo( EditUndo* pUndo, bool bTryMerge ) +void ImpEditEngine::InsertUndo( std::unique_ptr<EditUndo> pUndo, bool bTryMerge ) { DBG_ASSERT( !IsInUndo(), "InsertUndo in Undo mode!" ); if ( pUndoMarkSelection ) { - EditUndoMarkSelection* pU = new EditUndoMarkSelection(pEditEngine, *pUndoMarkSelection); - GetUndoManager().AddUndoAction( pU ); + GetUndoManager().AddUndoAction( o3tl::make_unique<EditUndoMarkSelection>(pEditEngine, *pUndoMarkSelection) ); pUndoMarkSelection.reset(); } - GetUndoManager().AddUndoAction( pUndo, bTryMerge ); + GetUndoManager().AddUndoAction( std::move(pUndo), bTryMerge ); mbLastTryMerge = bTryMerge; } @@ -501,9 +501,9 @@ void ImpEditEngine::SetAttribs( EditSelection aSel, const SfxItemSet& rSet, SetA if ( IsUndoEnabled() && !IsInUndo() && aStatus.DoUndoAttribs() ) { - EditUndoSetAttribs* pUndo = CreateAttribUndo( aSel, rSet ); + std::unique_ptr<EditUndoSetAttribs> pUndo = CreateAttribUndo( aSel, rSet ); pUndo->SetSpecial( nSpecial ); - InsertUndo( pUndo ); + InsertUndo( std::move(pUndo) ); } bool bCheckLanguage = false; @@ -593,11 +593,11 @@ void ImpEditEngine::RemoveCharAttribs( EditSelection aSel, bool bRemoveParaAttri if ( IsUndoEnabled() && !IsInUndo() && aStatus.DoUndoAttribs() ) { // Possibly a special Undo, or itemset* - EditUndoSetAttribs* pUndo = CreateAttribUndo( aSel, GetEmptyItemSet() ); + std::unique_ptr<EditUndoSetAttribs> pUndo = CreateAttribUndo( aSel, GetEmptyItemSet() ); pUndo->SetRemoveAttribs( true ); pUndo->SetRemoveParaAttribs( bRemoveParaAttribs ); pUndo->SetRemoveWhich( nWhich ); - InsertUndo( pUndo ); + InsertUndo( std::move(pUndo) ); } // iterate over the paragraphs ... @@ -691,11 +691,11 @@ void ImpEditEngine::SetParaAttribs( sal_Int32 nPara, const SfxItemSet& rSet ) { SfxItemSet aTmpSet( GetEmptyItemSet() ); aTmpSet.Put( rSet ); - InsertUndo(new EditUndoSetParaAttribs(pEditEngine, nPara, pNode->GetContentAttribs().GetItems(), aTmpSet)); + InsertUndo(o3tl::make_unique<EditUndoSetParaAttribs>(pEditEngine, nPara, pNode->GetContentAttribs().GetItems(), aTmpSet)); } else { - InsertUndo(new EditUndoSetParaAttribs(pEditEngine, nPara, pNode->GetContentAttribs().GetItems(), rSet)); + InsertUndo(o3tl::make_unique<EditUndoSetParaAttribs>(pEditEngine, nPara, pNode->GetContentAttribs().GetItems(), rSet)); } } diff --git a/editeng/source/outliner/outleeng.cxx b/editeng/source/outliner/outleeng.cxx index 8fb8f7ee7284..9eb6f792340e 100644 --- a/editeng/source/outliner/outleeng.cxx +++ b/editeng/source/outliner/outleeng.cxx @@ -33,6 +33,7 @@ #include <editeng/eeitem.hxx> #include <editeng/editstat.hxx> #include "outlundo.hxx" +#include <o3tl/make_unique.hxx> OutlinerEditEng::OutlinerEditEng( Outliner* pEngOwner, SfxItemPool* pPool ) : EditEngine( pPool ) @@ -96,7 +97,7 @@ void OutlinerEditEng::ParagraphConnected( sal_Int32 /*nLeftParagraph*/, sal_Int3 Paragraph* pPara = pOwner->GetParagraph( nRightParagraph ); if( pPara && Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE ) ) { - pOwner->InsertUndo( new OutlinerUndoChangeParaFlags( pOwner, nRightParagraph, ParaFlag::ISPAGE, ParaFlag::NONE ) ); + pOwner->InsertUndo( o3tl::make_unique<OutlinerUndoChangeParaFlags>( pOwner, nRightParagraph, ParaFlag::ISPAGE, ParaFlag::NONE ) ); } } } diff --git a/editeng/source/outliner/outlin2.cxx b/editeng/source/outliner/outlin2.cxx index bff245863eea..2e3e495a6c97 100644 --- a/editeng/source/outliner/outlin2.cxx +++ b/editeng/source/outliner/outlin2.cxx @@ -308,9 +308,9 @@ void Outliner::UndoActionEnd() pEditEngine->UndoActionEnd(); } -void Outliner::InsertUndo( EditUndo* pUndo ) +void Outliner::InsertUndo( std::unique_ptr<EditUndo> pUndo ) { - pEditEngine->GetUndoManager().AddUndoAction( pUndo ); + pEditEngine->GetUndoManager().AddUndoAction( std::move(pUndo) ); } bool Outliner::IsInUndo() diff --git a/editeng/source/outliner/outliner.cxx b/editeng/source/outliner/outliner.cxx index 01f4a218708a..42715dad0511 100644 --- a/editeng/source/outliner/outliner.cxx +++ b/editeng/source/outliner/outliner.cxx @@ -52,6 +52,7 @@ #include <svl/itempool.hxx> #include <libxml/xmlwriter.h> #include <sal/log.hxx> +#include <o3tl/make_unique.hxx> // calculate if it's RTL or not #include <unicode/ubidi.h> @@ -275,7 +276,7 @@ void Outliner::SetNumberingStartValue( sal_Int32 nPara, sal_Int16 nNumberingStar if( pPara && pPara->GetNumberingStartValue() != nNumberingStartValue ) { if( IsUndoEnabled() && !IsInUndo() ) - InsertUndo( new OutlinerUndoChangeParaNumberingRestart( this, nPara, + InsertUndo( o3tl::make_unique<OutlinerUndoChangeParaNumberingRestart>( this, nPara, pPara->GetNumberingStartValue(), nNumberingStartValue, pPara->IsParaIsNumberingRestart(), pPara->IsParaIsNumberingRestart() ) ); @@ -299,7 +300,7 @@ void Outliner::SetParaIsNumberingRestart( sal_Int32 nPara, bool bParaIsNumbering if( pPara && (pPara->IsParaIsNumberingRestart() != bParaIsNumberingRestart) ) { if( IsUndoEnabled() && !IsInUndo() ) - InsertUndo( new OutlinerUndoChangeParaNumberingRestart( this, nPara, + InsertUndo( o3tl::make_unique<OutlinerUndoChangeParaNumberingRestart>( this, nPara, pPara->GetNumberingStartValue(), pPara->GetNumberingStartValue(), pPara->IsParaIsNumberingRestart(), bParaIsNumberingRestart ) ); @@ -737,7 +738,7 @@ void Outliner::ImplInitDepth( sal_Int32 nPara, sal_Int16 nDepth, bool bCreateUnd if ( bUndo ) { - InsertUndo( new OutlinerUndoChangeDepth( this, nPara, nOldDepth, nDepth ) ); + InsertUndo( o3tl::make_unique<OutlinerUndoChangeDepth>( this, nPara, nOldDepth, nDepth ) ); } pEditEngine->SetUpdateMode( bUpdate ); @@ -759,19 +760,19 @@ bool Outliner::Expand( Paragraph const * pPara ) { if ( pParaList->HasHiddenChildren( pPara ) ) { - OLUndoExpand* pUndo = nullptr; + std::unique_ptr<OLUndoExpand> pUndo; bool bUndo = IsUndoEnabled() && !IsInUndo(); if( bUndo ) { UndoActionStart( OLUNDO_EXPAND ); - pUndo = new OLUndoExpand( this, OLUNDO_EXPAND ); + pUndo.reset( new OLUndoExpand( this, OLUNDO_EXPAND ) ); pUndo->nCount = pParaList->GetAbsPos( pPara ); } pParaList->Expand( pPara ); InvalidateBullet(pParaList->GetAbsPos(pPara)); if( bUndo ) { - InsertUndo( pUndo ); + InsertUndo( std::move(pUndo) ); UndoActionEnd(); } return true; @@ -783,7 +784,7 @@ bool Outliner::Collapse( Paragraph const * pPara ) { if ( pParaList->HasVisibleChildren( pPara ) ) // expanded { - OLUndoExpand* pUndo = nullptr; + std::unique_ptr<OLUndoExpand> pUndo; bool bUndo = false; if( !IsInUndo() && IsUndoEnabled() ) @@ -791,7 +792,7 @@ bool Outliner::Collapse( Paragraph const * pPara ) if( bUndo ) { UndoActionStart( OLUNDO_COLLAPSE ); - pUndo = new OLUndoExpand( this, OLUNDO_COLLAPSE ); + pUndo.reset( new OLUndoExpand( this, OLUNDO_COLLAPSE ) ); pUndo->nCount = pParaList->GetAbsPos( pPara ); } @@ -799,7 +800,7 @@ bool Outliner::Collapse( Paragraph const * pPara ) InvalidateBullet(pParaList->GetAbsPos(pPara)); if( bUndo ) { - InsertUndo( pUndo ); + InsertUndo( std::move(pUndo) ); UndoActionEnd(); } return true; @@ -1991,7 +1992,7 @@ void Outliner::SetParaFlag( Paragraph* pPara, ParaFlag nFlag ) if( pPara && !pPara->HasFlag( nFlag ) ) { if( IsUndoEnabled() && !IsInUndo() ) - InsertUndo( new OutlinerUndoChangeParaFlags( this, GetAbsPos( pPara ), pPara->nFlags, pPara->nFlags|nFlag ) ); + InsertUndo( o3tl::make_unique<OutlinerUndoChangeParaFlags>( this, GetAbsPos( pPara ), pPara->nFlags, pPara->nFlags|nFlag ) ); pPara->SetFlag( nFlag ); } diff --git a/editeng/source/outliner/outlvw.cxx b/editeng/source/outliner/outlvw.cxx index f86f707c4c35..f214ca3fe06d 100644 --- a/editeng/source/outliner/outlvw.cxx +++ b/editeng/source/outliner/outlvw.cxx @@ -45,6 +45,7 @@ #include <svl/eitem.hxx> #include <editeng/editstat.hxx> #include <sal/log.hxx> +#include <o3tl/make_unique.hxx> using namespace ::com::sun::star; @@ -403,7 +404,7 @@ void OutlinerView::SetAttribs( const SfxItemSet& rAttrs ) pOwner->ImplCalcBulletText( nPara, false, false ); if( !pOwner->IsInUndo() && pOwner->IsUndoEnabled() ) - pOwner->InsertUndo( new OutlinerUndoCheckPara( pOwner, nPara ) ); + pOwner->InsertUndo( o3tl::make_unique<OutlinerUndoCheckPara>( pOwner, nPara ) ); } if( !pOwner->IsInUndo() && pOwner->IsUndoEnabled() ) @@ -476,7 +477,7 @@ void OutlinerView::Indent( short nDiff ) pOwner->pEditEngine->QuickMarkInvalid( ESelection( nPara, 0, nPara, 0 ) ); if( bUndo ) - pOwner->InsertUndo( new OutlinerUndoChangeParaFlags( pOwner, nPara, nPrevFlags, pPara->nFlags ) ); + pOwner->InsertUndo( o3tl::make_unique<OutlinerUndoChangeParaFlags>( pOwner, nPara, nPrevFlags, pPara->nFlags ) ); continue; } diff --git a/framework/source/fwe/helper/undomanagerhelper.cxx b/framework/source/fwe/helper/undomanagerhelper.cxx index 656d1f05d26b..862d0a6c3a18 100644 --- a/framework/source/fwe/helper/undomanagerhelper.cxx +++ b/framework/source/fwe/helper/undomanagerhelper.cxx @@ -33,6 +33,7 @@ #include <svl/undo.hxx> #include <tools/diagnose_ex.h> #include <osl/conditn.hxx> +#include <o3tl/make_unique.hxx> #include <functional> #include <stack> @@ -655,7 +656,7 @@ namespace framework const bool bHadRedoActions = ( rUndoManager.GetRedoActionCount() > 0 ); { ::comphelper::FlagGuard aNotificationGuard( m_bAPIActionRunning ); - rUndoManager.AddUndoAction( new UndoActionWrapper( i_action ) ); + rUndoManager.AddUndoAction( o3tl::make_unique<UndoActionWrapper>( i_action ) ); } const bool bHasRedoActions = ( rUndoManager.GetRedoActionCount() > 0 ); diff --git a/include/editeng/outliner.hxx b/include/editeng/outliner.hxx index b6308599cfe3..e0d93e3323e4 100644 --- a/include/editeng/outliner.hxx +++ b/include/editeng/outliner.hxx @@ -738,7 +738,7 @@ public: bool IsUndoEnabled() const; void UndoActionStart( sal_uInt16 nId ); void UndoActionEnd(); - void InsertUndo( EditUndo* pUndo ); + void InsertUndo( std::unique_ptr<EditUndo> pUndo ); bool IsInUndo(); void ClearModifyFlag(); diff --git a/include/svl/undo.hxx b/include/svl/undo.hxx index 456a31f56b18..9451b9bd8e71 100644 --- a/include/svl/undo.hxx +++ b/include/svl/undo.hxx @@ -190,7 +190,7 @@ public: virtual ~SfxUndoManager(); void SetMaxUndoActionCount( size_t nMaxUndoActionCount ); - virtual void AddUndoAction( SfxUndoAction *pAction, bool bTryMerg=false ); + virtual void AddUndoAction( std::unique_ptr<SfxUndoAction> pAction, bool bTryMerg=false ); virtual size_t GetUndoActionCount( bool const i_currentLevel = CurrentLevel ) const; OUString GetUndoActionComment( size_t nNo=0, bool const i_currentLevel = CurrentLevel ) const; SfxUndoAction* GetUndoAction( size_t nNo=0 ) const; diff --git a/include/svx/svddrgmt.hxx b/include/svx/svddrgmt.hxx index 5bdd440e3409..0013da3284e3 100644 --- a/include/svx/svddrgmt.hxx +++ b/include/svx/svddrgmt.hxx @@ -155,7 +155,7 @@ protected: Point& Ref1() const { return mrSdrDragView.maRef1; } Point& Ref2() const { return mrSdrDragView.maRef2; } const SdrHdlList& GetHdlList() const { return getSdrDragView().GetHdlList(); } - void AddUndo(SdrUndoAction* pUndo) { getSdrDragView().AddUndo(pUndo); } + void AddUndo(std::unique_ptr<SdrUndoAction> pUndo) { getSdrDragView().AddUndo(std::move(pUndo)); } bool IsDragLimit() { return getSdrDragView().mbDragLimit; } const tools::Rectangle& GetDragLimitRect() { return getSdrDragView().maDragLimit; } const SdrMarkList& GetMarkedObjectList() { return getSdrDragView().GetMarkedObjectList(); } diff --git a/include/svx/svdedtv.hxx b/include/svx/svdedtv.hxx index 63d74b4bc74a..ba6b1172df6b 100644 --- a/include/svx/svdedtv.hxx +++ b/include/svx/svdedtv.hxx @@ -24,6 +24,7 @@ #include <svx/xpoly.hxx> #include <svx/svdmodel.hxx> #include <svx/svxdllapi.h> +#include <svx/svdundo.hxx> #include <o3tl/typed_flags_set.hxx> class SfxUndoAction; @@ -180,13 +181,13 @@ public: void BegUndo(const OUString& rComment) { mpModel->BegUndo(rComment); } // open undo-grouping void BegUndo(const OUString& rComment, const OUString& rObjDescr, SdrRepeatFunc eFunc=SdrRepeatFunc::NONE) { mpModel->BegUndo(rComment,rObjDescr,eFunc); } // open undo-grouping void EndUndo(); // close undo-grouping (incl. BroadcastEdges) - void AddUndo(SdrUndoAction* pUndo) { mpModel->AddUndo(pUndo); } // add action + void AddUndo(std::unique_ptr<SdrUndoAction> pUndo) { mpModel->AddUndo(std::move(pUndo)); } // add action // only after first BegUndo or before last EndUndo: void SetUndoComment(const OUString& rComment, const OUString& rObjDescr) { mpModel->SetUndoComment(rComment,rObjDescr); } bool IsUndoEnabled() const; - std::vector< SdrUndoAction* > CreateConnectorUndo( SdrObject& rO ); - void AddUndoActions( std::vector< SdrUndoAction* >& ); + std::vector< std::unique_ptr<SdrUndoAction> > CreateConnectorUndo( SdrObject& rO ); + void AddUndoActions( std::vector< std::unique_ptr<SdrUndoAction> > ); // Layermanagement with Undo. void InsertNewLayer(const OUString& rName, sal_uInt16 nPos); diff --git a/include/svx/svdmodel.hxx b/include/svx/svdmodel.hxx index 1cf73896c7b6..d08112592703 100644 --- a/include/svx/svdmodel.hxx +++ b/include/svx/svdmodel.hxx @@ -501,7 +501,7 @@ public: void BegUndo(const OUString& rComment); // open Undo group void BegUndo(const OUString& rComment, const OUString& rObjDescr, SdrRepeatFunc eFunc); // open Undo group void EndUndo(); // close Undo group - void AddUndo(SdrUndoAction* pUndo); + void AddUndo(std::unique_ptr<SdrUndoAction> pUndo); sal_uInt16 GetUndoBracketLevel() const { return nUndoLevel; } // only after the first BegUndo or before the last EndUndo: void SetUndoComment(const OUString& rComment); diff --git a/include/svx/svdundo.hxx b/include/svx/svdundo.hxx index c134fb986590..3efb4e75ab90 100644 --- a/include/svx/svdundo.hxx +++ b/include/svx/svdundo.hxx @@ -709,40 +709,40 @@ class SVX_DLLPUBLIC SdrUndoFactory public: // Shapes virtual ~SdrUndoFactory(); - virtual SdrUndoAction* CreateUndoMoveObject( SdrObject& rObject, const Size& rDist ); - virtual SdrUndoAction* CreateUndoGeoObject( SdrObject& rObject ); - virtual SdrUndoAction* CreateUndoAttrObject( SdrObject& rObject, bool bStyleSheet1 = false, bool bSaveText = false ); - virtual SdrUndoAction* CreateUndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect = false); - virtual SdrUndoAction* CreateUndoInsertObject( SdrObject& rObject, bool bOrdNumDirect = false); - virtual SdrUndoAction* CreateUndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect = false); - virtual SdrUndoAction* CreateUndoNewObject( SdrObject& rObject, bool bOrdNumDirect = false); - virtual SdrUndoAction* CreateUndoCopyObject( SdrObject& rObject, bool bOrdNumDirect = false); + virtual std::unique_ptr<SdrUndoAction> CreateUndoMoveObject( SdrObject& rObject, const Size& rDist ); + virtual std::unique_ptr<SdrUndoAction> CreateUndoGeoObject( SdrObject& rObject ); + virtual std::unique_ptr<SdrUndoAction> CreateUndoAttrObject( SdrObject& rObject, bool bStyleSheet1 = false, bool bSaveText = false ); + virtual std::unique_ptr<SdrUndoAction> CreateUndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect = false); + virtual std::unique_ptr<SdrUndoAction> CreateUndoInsertObject( SdrObject& rObject, bool bOrdNumDirect = false); + virtual std::unique_ptr<SdrUndoAction> CreateUndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect = false); + virtual std::unique_ptr<SdrUndoAction> CreateUndoNewObject( SdrObject& rObject, bool bOrdNumDirect = false); + virtual std::unique_ptr<SdrUndoAction> CreateUndoCopyObject( SdrObject& rObject, bool bOrdNumDirect = false); - virtual SdrUndoAction* CreateUndoObjectOrdNum( SdrObject& rObject, sal_uInt32 nOldOrdNum1, sal_uInt32 nNewOrdNum1); + virtual std::unique_ptr<SdrUndoAction> CreateUndoObjectOrdNum( SdrObject& rObject, sal_uInt32 nOldOrdNum1, sal_uInt32 nNewOrdNum1); - virtual SdrUndoAction* CreateUndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect = false ); - virtual SdrUndoAction* CreateUndoObjectLayerChange( SdrObject& rObject, SdrLayerID aOldLayer, SdrLayerID aNewLayer ); - virtual SdrUndoAction* CreateUndoObjectSetText( SdrObject& rNewObj, sal_Int32 nText ); + virtual std::unique_ptr<SdrUndoAction> CreateUndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect = false ); + virtual std::unique_ptr<SdrUndoAction> CreateUndoObjectLayerChange( SdrObject& rObject, SdrLayerID aOldLayer, SdrLayerID aNewLayer ); + virtual std::unique_ptr<SdrUndoAction> CreateUndoObjectSetText( SdrObject& rNewObj, sal_Int32 nText ); // Implement Title/Description Elements UI for Writer text frames, graphics and embedded objects (#i73249#) - static SdrUndoAction* CreateUndoObjectStrAttr( SdrObject& rObject, + static std::unique_ptr<SdrUndoAction> CreateUndoObjectStrAttr( SdrObject& rObject, SdrUndoObjStrAttr::ObjStrAttrType eObjStrAttrType, const OUString& sOldStr, const OUString& sNewStr ); // Layer - virtual SdrUndoAction* CreateUndoNewLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel); - virtual SdrUndoAction* CreateUndoDeleteLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel); + virtual std::unique_ptr<SdrUndoAction> CreateUndoNewLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel); + virtual std::unique_ptr<SdrUndoAction> CreateUndoDeleteLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel); // Page - virtual SdrUndoAction* CreateUndoDeletePage(SdrPage& rPage); - virtual SdrUndoAction* CreateUndoNewPage(SdrPage& rPage); - virtual SdrUndoAction* CreateUndoCopyPage(SdrPage& rPage); - virtual SdrUndoAction* CreateUndoSetPageNum(SdrPage& rNewPg, sal_uInt16 nOldPageNum1, sal_uInt16 nNewPageNum1); + virtual std::unique_ptr<SdrUndoAction> CreateUndoDeletePage(SdrPage& rPage); + virtual std::unique_ptr<SdrUndoAction> CreateUndoNewPage(SdrPage& rPage); + virtual std::unique_ptr<SdrUndoAction> CreateUndoCopyPage(SdrPage& rPage); + virtual std::unique_ptr<SdrUndoAction> CreateUndoSetPageNum(SdrPage& rNewPg, sal_uInt16 nOldPageNum1, sal_uInt16 nNewPageNum1); // Master page - virtual SdrUndoAction* CreateUndoPageRemoveMasterPage(SdrPage& rChangedPage); - virtual SdrUndoAction* CreateUndoPageChangeMasterPage(SdrPage& rChangedPage); + virtual std::unique_ptr<SdrUndoAction> CreateUndoPageRemoveMasterPage(SdrPage& rChangedPage); + virtual std::unique_ptr<SdrUndoAction> CreateUndoPageChangeMasterPage(SdrPage& rChangedPage); }; #endif // INCLUDED_SVX_SVDUNDO_HXX diff --git a/include/vcl/texteng.hxx b/include/vcl/texteng.hxx index 97a370747ce8..749146eb40d8 100644 --- a/include/vcl/texteng.hxx +++ b/include/vcl/texteng.hxx @@ -265,7 +265,7 @@ public: SfxUndoManager& GetUndoManager(); void UndoActionStart( sal_uInt16 nId = 0 ); void UndoActionEnd(); - void InsertUndo( TextUndo* pUndo, bool bTryMerge = false ); + void InsertUndo( std::unique_ptr<TextUndo> pUndo, bool bTryMerge = false ); bool IsInUndo() { return mbIsInUndo; } void SetIsInUndo( bool bInUndo ) { mbIsInUndo = bInUndo; } void ResetUndo(); diff --git a/reportdesign/source/core/inc/ReportUndoFactory.hxx b/reportdesign/source/core/inc/ReportUndoFactory.hxx index 9334372d1056..501bf68140b3 100644 --- a/reportdesign/source/core/inc/ReportUndoFactory.hxx +++ b/reportdesign/source/core/inc/ReportUndoFactory.hxx @@ -35,34 +35,34 @@ namespace rptui virtual ~OReportUndoFactory() override; // shapes - virtual SdrUndoAction* CreateUndoMoveObject( SdrObject& rObject, const Size& rDist ) override; - virtual SdrUndoAction* CreateUndoGeoObject( SdrObject& rObject ) override; - virtual SdrUndoAction* CreateUndoAttrObject( SdrObject& rObject, bool bStyleSheet1 = false, bool bSaveText = false ) override; - virtual SdrUndoAction* CreateUndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect = false) override; - virtual SdrUndoAction* CreateUndoInsertObject( SdrObject& rObject, bool bOrdNumDirect = false) override; - virtual SdrUndoAction* CreateUndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect = false) override; - virtual SdrUndoAction* CreateUndoNewObject( SdrObject& rObject, bool bOrdNumDirect = false) override; - virtual SdrUndoAction* CreateUndoCopyObject( SdrObject& rObject, bool bOrdNumDirect = false) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoMoveObject( SdrObject& rObject, const Size& rDist ) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoGeoObject( SdrObject& rObject ) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoAttrObject( SdrObject& rObject, bool bStyleSheet1 = false, bool bSaveText = false ) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect = false) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoInsertObject( SdrObject& rObject, bool bOrdNumDirect = false) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect = false) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoNewObject( SdrObject& rObject, bool bOrdNumDirect = false) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoCopyObject( SdrObject& rObject, bool bOrdNumDirect = false) override; - virtual SdrUndoAction* CreateUndoObjectOrdNum( SdrObject& rObject, sal_uInt32 nOldOrdNum1, sal_uInt32 nNewOrdNum1) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoObjectOrdNum( SdrObject& rObject, sal_uInt32 nOldOrdNum1, sal_uInt32 nNewOrdNum1) override; - virtual SdrUndoAction* CreateUndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect = false ) override; - virtual SdrUndoAction* CreateUndoObjectLayerChange( SdrObject& rObject, SdrLayerID aOldLayer, SdrLayerID aNewLayer ) override; - virtual SdrUndoAction* CreateUndoObjectSetText( SdrObject& rNewObj, sal_Int32 nText ) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect = false ) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoObjectLayerChange( SdrObject& rObject, SdrLayerID aOldLayer, SdrLayerID aNewLayer ) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoObjectSetText( SdrObject& rNewObj, sal_Int32 nText ) override; // layer - virtual SdrUndoAction* CreateUndoNewLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel) override; - virtual SdrUndoAction* CreateUndoDeleteLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoNewLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoDeleteLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel) override; // page - virtual SdrUndoAction* CreateUndoDeletePage(SdrPage& rPage) override; - virtual SdrUndoAction* CreateUndoNewPage(SdrPage& rPage) override; - virtual SdrUndoAction* CreateUndoCopyPage(SdrPage& rPage) override; - virtual SdrUndoAction* CreateUndoSetPageNum(SdrPage& rNewPg, sal_uInt16 nOldPageNum1, sal_uInt16 nNewPageNum1) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoDeletePage(SdrPage& rPage) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoNewPage(SdrPage& rPage) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoCopyPage(SdrPage& rPage) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoSetPageNum(SdrPage& rNewPg, sal_uInt16 nOldPageNum1, sal_uInt16 nNewPageNum1) override; // master page - virtual SdrUndoAction* CreateUndoPageRemoveMasterPage(SdrPage& rChangedPage) override; - virtual SdrUndoAction* CreateUndoPageChangeMasterPage(SdrPage& rChangedPage) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoPageRemoveMasterPage(SdrPage& rChangedPage) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoPageChangeMasterPage(SdrPage& rChangedPage) override; }; diff --git a/reportdesign/source/core/sdr/ReportUndoFactory.cxx b/reportdesign/source/core/sdr/ReportUndoFactory.cxx index 750b9b7572ec..1033a3eabc2d 100644 --- a/reportdesign/source/core/sdr/ReportUndoFactory.cxx +++ b/reportdesign/source/core/sdr/ReportUndoFactory.cxx @@ -20,12 +20,13 @@ #include <RptObject.hxx> #include <UndoActions.hxx> #include <strings.hrc> +#include <o3tl/make_unique.hxx> namespace rptui { using namespace ::com::sun::star; -static SdrUndoAction* lcl_createUndo(SdrObject& rObject, Action _eAction, const char* pCommentId) +static std::unique_ptr<SdrUndoAction> lcl_createUndo(SdrObject& rObject, Action _eAction, const char* pCommentId) { OObjectBase* pObj = dynamic_cast<OObjectBase*>(&rObject); if ( !pObj ) @@ -33,12 +34,10 @@ static SdrUndoAction* lcl_createUndo(SdrObject& rObject, Action _eAction, const uno::Reference< report::XReportComponent> xReportComponent = pObj->getReportComponent(); uno::Reference< report::XSection> xSection = pObj->getSection(); uno::Reference< report::XGroup> xGroup = xSection->getGroup(); - SdrUndoAction* pUndo = nullptr; if ( xGroup.is() ) - pUndo = new OUndoGroupSectionAction(rObject.getSdrModelFromSdrObject(),_eAction,OGroupHelper::getMemberFunction(xSection),xGroup,xReportComponent,pCommentId); + return o3tl::make_unique<OUndoGroupSectionAction>(rObject.getSdrModelFromSdrObject(),_eAction,OGroupHelper::getMemberFunction(xSection),xGroup,xReportComponent,pCommentId); else - pUndo = new OUndoReportSectionAction(rObject.getSdrModelFromSdrObject(),_eAction,OReportHelper::getMemberFunction(xSection),xSection->getReportDefinition(),xReportComponent,pCommentId); - return pUndo; + return o3tl::make_unique<OUndoReportSectionAction>(rObject.getSdrModelFromSdrObject(),_eAction,OReportHelper::getMemberFunction(xSection),xSection->getReportDefinition(),xReportComponent,pCommentId); } @@ -50,104 +49,104 @@ OReportUndoFactory::~OReportUndoFactory() { } -SdrUndoAction* OReportUndoFactory::CreateUndoMoveObject( SdrObject& rObject, const Size& rDist ) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoMoveObject( SdrObject& rObject, const Size& rDist ) { return m_pUndoFactory->CreateUndoMoveObject( rObject, rDist ); } -SdrUndoAction* OReportUndoFactory::CreateUndoGeoObject( SdrObject& rObject ) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoGeoObject( SdrObject& rObject ) { return m_pUndoFactory->CreateUndoGeoObject( rObject ); } -SdrUndoAction* OReportUndoFactory::CreateUndoAttrObject( SdrObject& rObject, bool bStyleSheet1, bool bSaveText ) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoAttrObject( SdrObject& rObject, bool bStyleSheet1, bool bSaveText ) { return m_pUndoFactory->CreateUndoAttrObject( rObject, bStyleSheet1, bSaveText ); } -SdrUndoAction* OReportUndoFactory::CreateUndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect ) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect ) { return m_pUndoFactory->CreateUndoRemoveObject( rObject, bOrdNumDirect ); } -SdrUndoAction* OReportUndoFactory::CreateUndoInsertObject( SdrObject& rObject, bool /*bOrdNumDirect*/ ) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoInsertObject( SdrObject& rObject, bool /*bOrdNumDirect*/ ) { return lcl_createUndo(rObject,rptui::Inserted,RID_STR_UNDO_INSERT_CONTROL); } -SdrUndoAction* OReportUndoFactory::CreateUndoDeleteObject( SdrObject& rObject, bool /*bOrdNumDirect*/ ) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoDeleteObject( SdrObject& rObject, bool /*bOrdNumDirect*/ ) { return lcl_createUndo(rObject,rptui::Removed,RID_STR_UNDO_DELETE_CONTROL); } -SdrUndoAction* OReportUndoFactory::CreateUndoNewObject( SdrObject& rObject, bool /*bOrdNumDirect*/ ) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoNewObject( SdrObject& rObject, bool /*bOrdNumDirect*/ ) { return lcl_createUndo(rObject,rptui::Inserted,RID_STR_UNDO_INSERT_CONTROL); } -SdrUndoAction* OReportUndoFactory::CreateUndoCopyObject( SdrObject& rObject, bool bOrdNumDirect ) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoCopyObject( SdrObject& rObject, bool bOrdNumDirect ) { return m_pUndoFactory->CreateUndoCopyObject( rObject, bOrdNumDirect ); } -SdrUndoAction* OReportUndoFactory::CreateUndoObjectOrdNum( SdrObject& rObject, sal_uInt32 nOldOrdNum1, sal_uInt32 nNewOrdNum1) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoObjectOrdNum( SdrObject& rObject, sal_uInt32 nOldOrdNum1, sal_uInt32 nNewOrdNum1) { return m_pUndoFactory->CreateUndoObjectOrdNum( rObject, nOldOrdNum1, nNewOrdNum1 ); } -SdrUndoAction* OReportUndoFactory::CreateUndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect ) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect ) { return m_pUndoFactory->CreateUndoReplaceObject( rOldObject, rNewObject, bOrdNumDirect ); } -SdrUndoAction* OReportUndoFactory::CreateUndoObjectLayerChange( SdrObject& rObject, SdrLayerID aOldLayer, SdrLayerID aNewLayer ) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoObjectLayerChange( SdrObject& rObject, SdrLayerID aOldLayer, SdrLayerID aNewLayer ) { return m_pUndoFactory->CreateUndoObjectLayerChange( rObject, aOldLayer, aNewLayer ); } -SdrUndoAction* OReportUndoFactory::CreateUndoObjectSetText( SdrObject& rNewObj, sal_Int32 nText ) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoObjectSetText( SdrObject& rNewObj, sal_Int32 nText ) { return m_pUndoFactory->CreateUndoObjectSetText( rNewObj, nText ); } // layer -SdrUndoAction* OReportUndoFactory::CreateUndoNewLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoNewLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel) { return m_pUndoFactory->CreateUndoNewLayer( nLayerNum, rNewLayerAdmin, rNewModel ); } -SdrUndoAction* OReportUndoFactory::CreateUndoDeleteLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoDeleteLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel) { return m_pUndoFactory->CreateUndoDeleteLayer( nLayerNum, rNewLayerAdmin, rNewModel ); } // page -SdrUndoAction* OReportUndoFactory::CreateUndoDeletePage(SdrPage& rPage) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoDeletePage(SdrPage& rPage) { return m_pUndoFactory->CreateUndoDeletePage(rPage); } -SdrUndoAction* OReportUndoFactory::CreateUndoNewPage(SdrPage& rPage) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoNewPage(SdrPage& rPage) { return m_pUndoFactory->CreateUndoNewPage( rPage ); } -SdrUndoAction* OReportUndoFactory::CreateUndoCopyPage(SdrPage& rPage) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoCopyPage(SdrPage& rPage) { return m_pUndoFactory->CreateUndoCopyPage( rPage ); } -SdrUndoAction* OReportUndoFactory::CreateUndoSetPageNum(SdrPage& rNewPg, sal_uInt16 nOldPageNum1, sal_uInt16 nNewPageNum1) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoSetPageNum(SdrPage& rNewPg, sal_uInt16 nOldPageNum1, sal_uInt16 nNewPageNum1) { return m_pUndoFactory->CreateUndoSetPageNum( rNewPg, nOldPageNum1, nNewPageNum1 ); } // master page -SdrUndoAction* OReportUndoFactory::CreateUndoPageRemoveMasterPage(SdrPage& rChangedPage) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoPageRemoveMasterPage(SdrPage& rChangedPage) { return m_pUndoFactory->CreateUndoPageRemoveMasterPage( rChangedPage ); } -SdrUndoAction* OReportUndoFactory::CreateUndoPageChangeMasterPage(SdrPage& rChangedPage) +std::unique_ptr<SdrUndoAction> OReportUndoFactory::CreateUndoPageChangeMasterPage(SdrPage& rChangedPage) { return m_pUndoFactory->CreateUndoPageChangeMasterPage(rChangedPage); } diff --git a/reportdesign/source/core/sdr/UndoEnv.cxx b/reportdesign/source/core/sdr/UndoEnv.cxx index cb42c8d086fb..db5398ffd7dc 100644 --- a/reportdesign/source/core/sdr/UndoEnv.cxx +++ b/reportdesign/source/core/sdr/UndoEnv.cxx @@ -44,6 +44,7 @@ #include <dbaccess/dbsubcomponentcontroller.hxx> #include <svx/unoshape.hxx> #include <osl/mutex.hxx> +#include <o3tl/make_unique.hxx> namespace rptui { @@ -310,7 +311,7 @@ void SAL_CALL OXUndoEnvironment::propertyChange( const PropertyChangeEvent& _rEv // add their undo actions out-of-order SolarMutexGuard aSolarGuard; - ORptUndoPropertyAction* pUndo = nullptr; + std::unique_ptr<ORptUndoPropertyAction> pUndo; try { uno::Reference< report::XSection> xSection( xSet, uno::UNO_QUERY ); @@ -318,9 +319,9 @@ void SAL_CALL OXUndoEnvironment::propertyChange( const PropertyChangeEvent& _rEv { uno::Reference< report::XGroup> xGroup = xSection->getGroup(); if ( xGroup.is() ) - pUndo = new OUndoPropertyGroupSectionAction( m_pImpl->m_rModel, _rEvent, OGroupHelper::getMemberFunction( xSection ), xGroup ); + pUndo.reset(new OUndoPropertyGroupSectionAction( m_pImpl->m_rModel, _rEvent, OGroupHelper::getMemberFunction( xSection ), xGroup )); else - pUndo = new OUndoPropertyReportSectionAction( m_pImpl->m_rModel, _rEvent, OReportHelper::getMemberFunction( xSection ), xSection->getReportDefinition() ); + pUndo.reset(new OUndoPropertyReportSectionAction( m_pImpl->m_rModel, _rEvent, OReportHelper::getMemberFunction( xSection ), xSection->getReportDefinition() )); } } catch(const Exception&) @@ -329,9 +330,9 @@ void SAL_CALL OXUndoEnvironment::propertyChange( const PropertyChangeEvent& _rEv } if ( pUndo == nullptr ) - pUndo = new ORptUndoPropertyAction( m_pImpl->m_rModel, _rEvent ); + pUndo.reset(new ORptUndoPropertyAction( m_pImpl->m_rModel, _rEvent )); - m_pImpl->m_rModel.GetSdrUndoManager()->AddUndoAction( pUndo ); + m_pImpl->m_rModel.GetSdrUndoManager()->AddUndoAction( std::move(pUndo) ); pController->InvalidateAll(); } @@ -391,7 +392,7 @@ void SAL_CALL OXUndoEnvironment::elementInserted(const ContainerEvent& evt) if ( xContainer.is() ) { m_pImpl->m_rModel.GetSdrUndoManager()->AddUndoAction( - new OUndoContainerAction( m_pImpl->m_rModel, rptui::Inserted, xContainer.get(), + o3tl::make_unique<OUndoContainerAction>( m_pImpl->m_rModel, rptui::Inserted, xContainer.get(), xIface, RID_STR_UNDO_ADDFUNCTION ) ); } } @@ -457,7 +458,7 @@ void SAL_CALL OXUndoEnvironment::elementRemoved(const ContainerEvent& evt) uno::Reference< report::XFunctions> xFunctions(evt.Source,uno::UNO_QUERY); if ( xFunctions.is() ) { - m_pImpl->m_rModel.GetSdrUndoManager()->AddUndoAction( new OUndoContainerAction( + m_pImpl->m_rModel.GetSdrUndoManager()->AddUndoAction( o3tl::make_unique<OUndoContainerAction>( m_pImpl->m_rModel, rptui::Removed, xFunctions.get(), xIface, RID_STR_UNDO_ADDFUNCTION ) ); } } diff --git a/reportdesign/source/ui/inc/ReportController.hxx b/reportdesign/source/ui/inc/ReportController.hxx index 3cca358adc0b..e956cb434c97 100644 --- a/reportdesign/source/ui/inc/ReportController.hxx +++ b/reportdesign/source/ui/inc/ReportController.hxx @@ -455,7 +455,7 @@ namespace rptui SfxUndoManager& getUndoManager() const; void clearUndoManager() const; - void addUndoAction( SfxUndoAction* i_pAction ); + void addUndoAction( std::unique_ptr<SfxUndoAction> i_pAction ); }; } #endif // INCLUDED_REPORTDESIGN_SOURCE_UI_INC_REPORTCONTROLLER_HXX diff --git a/reportdesign/source/ui/report/ReportController.cxx b/reportdesign/source/ui/report/ReportController.cxx index 085160518c63..e79d4c6a361f 100644 --- a/reportdesign/source/ui/report/ReportController.cxx +++ b/reportdesign/source/ui/report/ReportController.cxx @@ -3771,13 +3771,13 @@ void OReportController::switchReportSection(const sal_Int16 _nId) const OUString sUndoAction(RptResId(bSwitchOn ? RID_STR_UNDO_ADD_REPORTHEADERFOOTER : RID_STR_UNDO_REMOVE_REPORTHEADERFOOTER)); pUndoContext.reset( new UndoContext( getUndoManager(), sUndoAction ) ); - addUndoAction(new OReportSectionUndo(*(m_aReportModel),SID_REPORTHEADER_WITHOUT_UNDO + addUndoAction(o3tl::make_unique<OReportSectionUndo>(*(m_aReportModel),SID_REPORTHEADER_WITHOUT_UNDO ,::std::mem_fn(&OReportHelper::getReportHeader) ,m_xReportDefinition ,bSwitchOn ? Inserted : Removed )); - addUndoAction(new OReportSectionUndo(*(m_aReportModel),SID_REPORTFOOTER_WITHOUT_UNDO + addUndoAction(o3tl::make_unique<OReportSectionUndo>(*(m_aReportModel),SID_REPORTFOOTER_WITHOUT_UNDO ,::std::mem_fn(&OReportHelper::getReportFooter) ,m_xReportDefinition ,bSwitchOn ? Inserted : Removed @@ -3818,14 +3818,14 @@ void OReportController::switchPageSection(const sal_Int16 _nId) const OUString sUndoAction(RptResId(bSwitchOn ? RID_STR_UNDO_ADD_REPORTHEADERFOOTER : RID_STR_UNDO_REMOVE_REPORTHEADERFOOTER)); pUndoContext.reset( new UndoContext( getUndoManager(), sUndoAction ) ); - addUndoAction(new OReportSectionUndo(*m_aReportModel + addUndoAction(o3tl::make_unique<OReportSectionUndo>(*m_aReportModel ,SID_PAGEHEADER_WITHOUT_UNDO ,::std::mem_fn(&OReportHelper::getPageHeader) ,m_xReportDefinition ,bSwitchOn ? Inserted : Removed )); - addUndoAction(new OReportSectionUndo(*m_aReportModel + addUndoAction(o3tl::make_unique<OReportSectionUndo>(*m_aReportModel ,SID_PAGEFOOTER_WITHOUT_UNDO ,::std::mem_fn(&OReportHelper::getPageFooter) ,m_xReportDefinition @@ -3872,7 +3872,7 @@ void OReportController::modifyGroup(const bool _bAppend, const Sequence< Propert rUndoEnv.AddElement( xGroup->getFunctions() ); } - addUndoAction( new OGroupUndo( + addUndoAction( o3tl::make_unique<OGroupUndo>( *m_aReportModel, _bAppend ? RID_STR_UNDO_APPEND_GROUP : RID_STR_UNDO_REMOVE_GROUP, _bAppend ? Inserted : Removed, @@ -3906,7 +3906,7 @@ void OReportController::createGroupSection(const bool _bUndo,const bool _bHeader { const OXUndoEnvironment::OUndoEnvLock aLock(m_aReportModel->GetUndoEnv()); if ( _bUndo ) - addUndoAction(new OGroupSectionUndo(*m_aReportModel + addUndoAction(o3tl::make_unique<OGroupSectionUndo>(*m_aReportModel ,_bHeader ? SID_GROUPHEADER_WITHOUT_UNDO : SID_GROUPFOOTER_WITHOUT_UNDO ,_bHeader ? ::std::mem_fn(&OGroupHelper::getHeader) : ::std::mem_fn(&OGroupHelper::getFooter) ,xGroup @@ -4362,9 +4362,9 @@ void OReportController::clearUndoManager() const } -void OReportController::addUndoAction( SfxUndoAction* i_pAction ) +void OReportController::addUndoAction( std::unique_ptr<SfxUndoAction> i_pAction ) { - getUndoManager().AddUndoAction( i_pAction ); + getUndoManager().AddUndoAction( std::move(i_pAction) ); InvalidateFeature( SID_UNDO ); InvalidateFeature( SID_REDO ); diff --git a/reportdesign/source/ui/report/SectionView.cxx b/reportdesign/source/ui/report/SectionView.cxx index ea01291b81f6..c1c3c48bd853 100644 --- a/reportdesign/source/ui/report/SectionView.cxx +++ b/reportdesign/source/ui/report/SectionView.cxx @@ -29,6 +29,7 @@ #include <strings.hxx> #include <tools/debug.hxx> #include <tools/diagnose_ex.h> +#include <o3tl/make_unique.hxx> namespace rptui { @@ -176,7 +177,7 @@ void OSectionView::SetMarkedToLayer( SdrLayerID _nLayerNo ) SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj(); if ( dynamic_cast< const OCustomShape *>( pObj ) != nullptr ) { - AddUndo( new SdrUndoObjectLayerChange( *pObj, pObj->GetLayer(), _nLayerNo) ); + AddUndo( o3tl::make_unique<SdrUndoObjectLayerChange>( *pObj, pObj->GetLayer(), _nLayerNo) ); pObj->SetLayer( _nLayerNo ); OObjectBase& rBaseObj = dynamic_cast<OObjectBase&>(*pObj); try diff --git a/sc/source/ui/docshell/arealink.cxx b/sc/source/ui/docshell/arealink.cxx index d0797a453873..6461f802c126 100644 --- a/sc/source/ui/docshell/arealink.cxx +++ b/sc/source/ui/docshell/arealink.cxx @@ -140,7 +140,7 @@ void ScAreaLink::Closed() bool bUndo (rDoc.IsUndoEnabled()); if (bAddUndo && bUndo) { - m_pDocSh->GetUndoManager()->AddUndoAction( new ScUndoRemoveAreaLink( m_pDocSh, + m_pDocSh->GetUndoManager()->AddUndoAction( o3tl::make_unique<ScUndoRemoveAreaLink>( m_pDocSh, aFileName, aFilterName, aOptions, aSourceArea, aDestArea, GetRefreshDelay() ) ); @@ -417,7 +417,7 @@ bool ScAreaLink::Refresh( const OUString& rNewFile, const OUString& rNewFilter, rDoc.CopyToDocument(aNewRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, *pRedoDoc); m_pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoUpdateAreaLink( m_pDocSh, + o3tl::make_unique<ScUndoUpdateAreaLink>( m_pDocSh, aFileName, aFilterName, aOptions, aSourceArea, aOldRange, GetRefreshDelay(), aNewUrl, rNewFilter, aNewOpt, diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx index d82ce8b2ca39..b374d94cd34e 100644 --- a/sc/source/ui/docshell/dbdocfun.cxx +++ b/sc/source/ui/docshell/dbdocfun.cxx @@ -106,7 +106,7 @@ bool ScDBDocFunc::AddDBRange( const OUString& rName, const ScRange& rRange ) if (bUndo) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDBData( &rDocShell, std::move(pUndoColl), + o3tl::make_unique<ScUndoDBData>( &rDocShell, std::move(pUndoColl), o3tl::make_unique<ScDBCollection>( *pDocColl ) ) ); } @@ -139,7 +139,7 @@ bool ScDBDocFunc::DeleteDBRange(const OUString& rName) if (bUndo) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDBData( &rDocShell, std::move(pUndoColl), + o3tl::make_unique<ScUndoDBData>( &rDocShell, std::move(pUndoColl), o3tl::make_unique<ScDBCollection>( *pDocColl ) ) ); } @@ -183,7 +183,7 @@ bool ScDBDocFunc::RenameDBRange( const OUString& rOld, const OUString& rNew ) if (bUndo) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDBData( &rDocShell, std::move(pUndoColl), + o3tl::make_unique<ScUndoDBData>( &rDocShell, std::move(pUndoColl), o3tl::make_unique<ScDBCollection>( *pDocColl ) ) ); } else @@ -234,7 +234,7 @@ void ScDBDocFunc::ModifyDBData( const ScDBData& rNewData ) if (bUndo) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDBData( &rDocShell, std::move(pUndoColl), + o3tl::make_unique<ScUndoDBData>( &rDocShell, std::move(pUndoColl), o3tl::make_unique<ScDBCollection>( *pDocColl ) ) ); } @@ -276,7 +276,7 @@ void ScDBDocFunc::ModifyAllDBData( const ScDBCollection& rNewColl, const std::ve if (bRecord) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDBData(&rDocShell, std::move(pUndoColl), + o3tl::make_unique<ScUndoDBData>(&rDocShell, std::move(pUndoColl), o3tl::make_unique<ScDBCollection>(rNewColl))); } } @@ -443,7 +443,7 @@ bool ScDBDocFunc::RepeatDB( const OUString& rDBName, bool bApi, bool bIsUnnamed, } rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoRepeatDB( &rDocShell, nTab, + o3tl::make_unique<ScUndoRepeatDB>( &rDocShell, nTab, nStartCol, nStartRow, nEndCol, nEndRow, nNewEndRow, //nCurX, nCurY, @@ -571,8 +571,8 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam, if (bRecord) { // Set up an undo object. - sc::UndoSort* pUndoAction = new sc::UndoSort(&rDocShell, aUndoParam); - rDocShell.GetUndoManager()->AddUndoAction(pUndoAction); + rDocShell.GetUndoManager()->AddUndoAction( + o3tl::make_unique<sc::UndoSort>(&rDocShell, aUndoParam)); } pDBData->SetSortParam(rSortParam); @@ -930,7 +930,7 @@ bool ScDBDocFunc::Query( SCTAB nTab, const ScQueryParam& rQueryParam, { // create undo action after executing, because of drawing layer undo rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoQuery( &rDocShell, nTab, rQueryParam, std::move(pUndoDoc), std::move(pUndoDB), + o3tl::make_unique<ScUndoQuery>( &rDocShell, nTab, rQueryParam, std::move(pUndoDoc), std::move(pUndoDB), pOld, bDoSize, pAdvSource ) ); } @@ -1108,7 +1108,7 @@ void ScDBDocFunc::DoSubTotals( SCTAB nTab, const ScSubTotalParam& rParam, { // ScDBData* pUndoDBData = pDBData ? new ScDBData( *pDBData ) : NULL; rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoSubTotals( &rDocShell, nTab, + o3tl::make_unique<ScUndoSubTotals>( &rDocShell, nTab, rParam, aNewParam.nRow2, std::move(pUndoDoc), std::move(pUndoTab), // pUndoDBData, std::move(pUndoRange), std::move(pUndoDB) ) ); @@ -1325,7 +1325,7 @@ bool ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb if (bRecord) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDataPilot( + o3tl::make_unique<ScUndoDataPilot>( &rDocShell, std::move(pOldUndoDoc), std::move(pNewUndoDoc), &aUndoDPObj, pOldObj, bAllowMove)); } @@ -1370,7 +1370,7 @@ bool ScDBDocFunc::RemovePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi) for (SdrOle2Obj* pChartObject : aListOfObjects) { rDoc.GetChartListenerCollection()->removeByName(pChartObject->GetName()); - pModel->AddUndo(new SdrUndoDelObj(*pChartObject)); + pModel->AddUndo(o3tl::make_unique<SdrUndoDelObj>(*pChartObject)); pChartObject->getSdrPageFromSdrObject()->RemoveObject(pChartObject->GetOrdNum()); } } @@ -1409,7 +1409,7 @@ bool ScDBDocFunc::RemovePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi) if (bRecord) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDataPilot( + o3tl::make_unique<ScUndoDataPilot>( &rDocShell, std::move(pOldUndoDoc), nullptr, pUndoDPObj.get(), nullptr, false)); // pUndoDPObj is copied @@ -1522,7 +1522,7 @@ bool ScDBDocFunc::CreatePivotTable(const ScDPObject& rDPObj, bool bRecord, bool if (bRecord) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDataPilot(&rDocShell, nullptr, std::move(pNewUndoDoc), nullptr, &rDestObj, false)); + o3tl::make_unique<ScUndoDataPilot>(&rDocShell, nullptr, std::move(pNewUndoDoc), nullptr, &rDestObj, false)); } // notify API objects @@ -1597,7 +1597,7 @@ bool ScDBDocFunc::UpdatePivotTable(ScDPObject& rDPObj, bool bRecord, bool bApi) if (bRecord) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDataPilot( + o3tl::make_unique<ScUndoDataPilot>( &rDocShell, std::move(pOldUndoDoc), std::move(pNewUndoDoc), &aUndoDPObj, &rDPObj, false)); } diff --git a/sc/source/ui/docshell/dbdocimp.cxx b/sc/source/ui/docshell/dbdocimp.cxx index 49c1cf8d542b..a83b0c376ab5 100644 --- a/sc/source/ui/docshell/dbdocimp.cxx +++ b/sc/source/ui/docshell/dbdocimp.cxx @@ -583,7 +583,7 @@ bool ScDBDocFunc::DoImport( SCTAB nTab, const ScImportParam& rParam, std::unique_ptr<ScDBData> pRedoDBData(pDBData ? new ScDBData( *pDBData ) : nullptr); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoImportData( &rDocShell, nTab, + o3tl::make_unique<ScUndoImportData>( &rDocShell, nTab, rParam, nUndoEndCol, nUndoEndRow, nFormulaCols, std::move(pUndoDoc), std::move(pRedoDoc), diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 58b6c92b4ba3..0d25a473db1a 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -110,7 +110,7 @@ void ScDocFunc::NotifyDrawUndo( std::unique_ptr<SdrUndoAction> pUndoAction) if( pDrawLayer && pDrawLayer->IsRecording() ) pDrawLayer->AddCalcUndo( std::move(pUndoAction) ); else - rDocShell.GetUndoManager()->AddUndoAction( new ScUndoDraw( std::move(pUndoAction), &rDocShell ) ); + rDocShell.GetUndoManager()->AddUndoAction( o3tl::make_unique<ScUndoDraw>( std::move(pUndoAction), &rDocShell ) ); rDocShell.SetDrawModified(); // the affected sheet isn't known, so all stream positions are invalidated @@ -191,7 +191,7 @@ bool ScDocFunc::DetectiveAddPred(const ScAddress& rPos) if (bUndo) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDetective( &rDocShell, std::move(pUndo), &aOperation ) ); + o3tl::make_unique<ScUndoDetective>( &rDocShell, std::move(pUndo), &aOperation ) ); } aModificator.SetDocumentModified(); SfxBindings* pBindings = rDocShell.GetViewBindings(); @@ -230,7 +230,7 @@ bool ScDocFunc::DetectiveDelPred(const ScAddress& rPos) if (bUndo) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDetective( &rDocShell, std::move(pUndo), &aOperation ) ); + o3tl::make_unique<ScUndoDetective>( &rDocShell, std::move(pUndo), &aOperation ) ); } aModificator.SetDocumentModified(); SfxBindings* pBindings = rDocShell.GetViewBindings(); @@ -267,7 +267,7 @@ bool ScDocFunc::DetectiveAddSucc(const ScAddress& rPos) if (bUndo) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDetective( &rDocShell, std::move(pUndo), &aOperation ) ); + o3tl::make_unique<ScUndoDetective>( &rDocShell, std::move(pUndo), &aOperation ) ); } aModificator.SetDocumentModified(); SfxBindings* pBindings = rDocShell.GetViewBindings(); @@ -306,7 +306,7 @@ bool ScDocFunc::DetectiveDelSucc(const ScAddress& rPos) if (bUndo) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDetective( &rDocShell, std::move(pUndo), &aOperation ) ); + o3tl::make_unique<ScUndoDetective>( &rDocShell, std::move(pUndo), &aOperation ) ); } aModificator.SetDocumentModified(); SfxBindings* pBindings = rDocShell.GetViewBindings(); @@ -343,7 +343,7 @@ bool ScDocFunc::DetectiveAddError(const ScAddress& rPos) if (bUndo) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDetective( &rDocShell, std::move(pUndo), &aOperation ) ); + o3tl::make_unique<ScUndoDetective>( &rDocShell, std::move(pUndo), &aOperation ) ); } aModificator.SetDocumentModified(); SfxBindings* pBindings = rDocShell.GetViewBindings(); @@ -381,7 +381,7 @@ bool ScDocFunc::DetectiveMarkInvalid(SCTAB nTab) if (pUndo && bUndo) { pUndo->SetComment( ScResId( STR_UNDO_DETINVALID ) ); - rDocShell.GetUndoManager()->AddUndoAction( pUndo.release() ); + rDocShell.GetUndoManager()->AddUndoAction( std::move(pUndo) ); } aModificator.SetDocumentModified(); if ( bOverflow ) @@ -425,7 +425,7 @@ bool ScDocFunc::DetectiveDelAll(SCTAB nTab) if (bUndo) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDetective( &rDocShell, std::move(pUndo), nullptr, std::move(pUndoList) ) ); + o3tl::make_unique<ScUndoDetective>( &rDocShell, std::move(pUndo), nullptr, std::move(pUndoList) ) ); } aModificator.SetDocumentModified(); SfxBindings* pBindings = rDocShell.GetViewBindings(); @@ -496,8 +496,8 @@ bool ScDocFunc::DetectiveRefresh( bool bAutomatic ) pUndo->SetComment( ScResId( STR_UNDO_DETREFRESH ) ); // associate with the last action rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDraw( std::move(pUndo), &rDocShell ), - bAutomatic ); + o3tl::make_unique<ScUndoDraw>( std::move(pUndo), &rDocShell ), + bAutomatic ); } } rDocShell.SetDrawModified(); @@ -745,7 +745,7 @@ bool ScDocFunc::TransliterateText( const ScMarkData& rMark, TransliterationFlags rDoc.CopyToDocument(aCopyRange, InsertDeleteFlags::CONTENTS, true, *pUndoDoc, &aMultiMark); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoTransliterate( &rDocShell, aMultiMark, std::move(pUndoDoc), nType ) ); + o3tl::make_unique<ScUndoTransliterate>( &rDocShell, aMultiMark, std::move(pUndoDoc), nType ) ); } rDoc.TransliterateText( aMultiMark, nType ); @@ -802,7 +802,7 @@ bool ScDocFunc::SetNormalString( bool& o_rbNumFmtSet, const ScAddress& rPos, con { // because of ChangeTracking, UndoAction can be created only after SetString was called rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoEnterData(&rDocShell, rPos, aOldValues, rText, nullptr)); + o3tl::make_unique<ScUndoEnterData>(&rDocShell, rPos, aOldValues, rText, nullptr)); } if ( bEditDeleted || rDoc.HasAttrib( ScRange(rPos), HasAttrFlags::NeedHeight ) ) @@ -837,7 +837,7 @@ bool ScDocFunc::SetValueCell( const ScAddress& rPos, double fVal, bool bInteract SfxUndoManager* pUndoMgr = rDocShell.GetUndoManager(); ScCellValue aNewVal; aNewVal.assign(rDoc, rPos); - pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, aOldVal, aNewVal)); + pUndoMgr->AddUndoAction(o3tl::make_unique<ScUndoSetCell>(&rDocShell, rPos, aOldVal, aNewVal)); } if (bHeight) @@ -869,11 +869,11 @@ void ScDocFunc::SetValueCells( const ScAddress& rPos, const std::vector<double>& if (rDoc.IsUndoEnabled()) { - sc::UndoSetCells* pUndoObj = new sc::UndoSetCells(&rDocShell, rPos); + std::unique_ptr<sc::UndoSetCells> pUndoObj(new sc::UndoSetCells(&rDocShell, rPos)); rDoc.TransferCellValuesTo(rPos, aVals.size(), pUndoObj->GetOldValues()); pUndoObj->SetNewValues(aVals); SfxUndoManager* pUndoMgr = rDocShell.GetUndoManager(); - pUndoMgr->AddUndoAction(pUndoObj); + pUndoMgr->AddUndoAction(std::move(pUndoObj)); } rDoc.SetValues(rPos, aVals); @@ -907,7 +907,7 @@ bool ScDocFunc::SetStringCell( const ScAddress& rPos, const OUString& rStr, bool SfxUndoManager* pUndoMgr = rDocShell.GetUndoManager(); ScCellValue aNewVal; aNewVal.assign(rDoc, rPos); - pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, aOldVal, aNewVal)); + pUndoMgr->AddUndoAction(o3tl::make_unique<ScUndoSetCell>(&rDocShell, rPos, aOldVal, aNewVal)); } if (bHeight) @@ -942,7 +942,7 @@ bool ScDocFunc::SetEditCell( const ScAddress& rPos, const EditTextObject& rStr, SfxUndoManager* pUndoMgr = rDocShell.GetUndoManager(); ScCellValue aNewVal; aNewVal.assign(rDoc, rPos); - pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, aOldVal, aNewVal)); + pUndoMgr->AddUndoAction(o3tl::make_unique<ScUndoSetCell>(&rDocShell, rPos, aOldVal, aNewVal)); } if (bHeight) @@ -1006,7 +1006,7 @@ bool ScDocFunc::SetFormulaCell( const ScAddress& rPos, ScFormulaCell* pCell, boo SfxUndoManager* pUndoMgr = rDocShell.GetUndoManager(); ScCellValue aNewVal; aNewVal.assign(rDoc, rPos); - pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, aOldVal, aNewVal)); + pUndoMgr->AddUndoAction(o3tl::make_unique<ScUndoSetCell>(&rDocShell, rPos, aOldVal, aNewVal)); } if (bHeight) @@ -1198,7 +1198,7 @@ bool ScDocFunc::ShowNote( const ScAddress& rPos, bool bShow ) // move the caption to internal or hidden layer and create undo action pNote->ShowCaption( rPos, bShow ); if( rDoc.IsUndoEnabled() ) - rDocShell.GetUndoManager()->AddUndoAction( new ScUndoShowHideNote( rDocShell, rPos, bShow ) ); + rDocShell.GetUndoManager()->AddUndoAction( o3tl::make_unique<ScUndoShowHideNote>( rDocShell, rPos, bShow ) ); rDoc.SetStreamValid(rPos.Tab(), false); @@ -1284,7 +1284,7 @@ void ScDocFunc::ReplaceNote( const ScAddress& rPos, const OUString& rNoteText, c // create the undo action if( pUndoMgr && (aOldData.m_pCaption || aNewData.m_pCaption) ) - pUndoMgr->AddUndoAction( new ScUndoReplaceNote( rDocShell, rPos, aOldData, aNewData, pDrawLayer->GetCalcUndo() ) ); + pUndoMgr->AddUndoAction( o3tl::make_unique<ScUndoReplaceNote>( rDocShell, rPos, aOldData, aNewData, pDrawLayer->GetCalcUndo() ) ); // repaint cell (to make note marker visible) rDocShell.PostPaintCell( rPos ); @@ -1344,7 +1344,7 @@ bool ScDocFunc::ApplyAttributes( const ScMarkData& rMark, const ScPatternAttr& r rDoc.CopyToDocument(aMultiRange, InsertDeleteFlags::ATTRIB, bMulti, *pUndoDoc, &rMark); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoSelectionAttr( + o3tl::make_unique<ScUndoSelectionAttr>( &rDocShell, rMark, aMultiRange.aStart.Col(), aMultiRange.aStart.Row(), aMultiRange.aStart.Tab(), aMultiRange.aEnd.Col(), aMultiRange.aEnd.Row(), aMultiRange.aEnd.Tab(), @@ -1426,7 +1426,7 @@ bool ScDocFunc::ApplyStyle( const ScMarkData& rMark, const OUString& rStyleName, rDoc.CopyToDocument( aCopyRange, InsertDeleteFlags::ATTRIB, bMulti, *pUndoDoc, &rMark ); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoSelectionStyle( + o3tl::make_unique<ScUndoSelectionStyle>( &rDocShell, rMark, aMultiRange, rStyleName, std::move(pUndoDoc) ) ); } @@ -1960,7 +1960,7 @@ bool ScDocFunc::InsertCells( const ScRange& rRange, const ScMarkData* pTabMark, if (bRecord && pUndoRemoveMerge) { - rDocShell.GetUndoManager()->AddUndoAction( pUndoRemoveMerge.release()); + rDocShell.GetUndoManager()->AddUndoAction( std::move(pUndoRemoveMerge)); } switch (eCmd) @@ -2021,7 +2021,7 @@ bool ScDocFunc::InsertCells( const ScRange& rRange, const ScMarkData* pTabMark, rDocShell.GetUndoManager()->LeaveListAction(); } - rDocShell.GetUndoManager()->AddUndoAction( new ScUndoInsertCells( + rDocShell.GetUndoManager()->AddUndoAction( o3tl::make_unique<ScUndoInsertCells>( &rDocShell, ScRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab ), nUndoPos, std::move(pTabs), std::move(pScenarios), eCmd, std::move(pRefUndoDoc), std::move(pUndoData), bPartOfPaste ) ); } @@ -2441,7 +2441,7 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark, if (bRecord && pUndoRemoveMerge) { - rDocShell.GetUndoManager()->AddUndoAction( pUndoRemoveMerge.release()); + rDocShell.GetUndoManager()->AddUndoAction( std::move(pUndoRemoveMerge)); } // do it @@ -2553,7 +2553,7 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark, rDocShell.GetUndoManager()->LeaveListAction(); } - rDocShell.GetUndoManager()->AddUndoAction( new ScUndoDeleteCells( + rDocShell.GetUndoManager()->AddUndoAction( o3tl::make_unique<ScUndoDeleteCells>( &rDocShell, ScRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab ), nUndoPos, std::move(pTabs), std::move(pScenarios), eCmd, std::move(pUndoDoc), std::move(pUndoData) ) ); @@ -2930,7 +2930,7 @@ bool ScDocFunc::MoveBlock( const ScRange& rSource, const ScAddress& rDestPos, ScAddress aDestPos(nDestCol, nDestRow, nDestTab); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDragDrop( + o3tl::make_unique<ScUndoDragDrop>( &rDocShell, aUndoRange, aDestPos, bCut, std::move(pUndoDoc), bScenariosAdded)); } @@ -3144,7 +3144,7 @@ bool ScDocFunc::InsertTable( SCTAB nTab, const OUString& rName, bool bRecord, bo { if (bRecord) rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoInsertTab( &rDocShell, nTab, bAppend, rName)); + o3tl::make_unique<ScUndoInsertTab>( &rDocShell, nTab, bAppend, rName)); // Update views: // Only insert vba modules if vba mode ( and not currently importing XML ) if( bInsertDocModule ) @@ -3227,7 +3227,7 @@ bool ScDocFunc::DeleteTable( SCTAB nTab, bool bRecord ) vector<SCTAB> theTabs; theTabs.push_back(nTab); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDeleteTab( &rDocShell, theTabs, std::move(pUndoDoc), std::move(pUndoData) )); + o3tl::make_unique<ScUndoDeleteTab>( &rDocShell, theTabs, std::move(pUndoDoc), std::move(pUndoData) )); } // Update views: if( bVbaEnabled ) @@ -3300,7 +3300,7 @@ void ScDocFunc::SetTableVisible( SCTAB nTab, bool bVisible, bool bApi ) { std::vector<SCTAB> undoTabs; undoTabs.push_back(nTab); - rDocShell.GetUndoManager()->AddUndoAction( new ScUndoShowHideTab( &rDocShell, undoTabs, bVisible ) ); + rDocShell.GetUndoManager()->AddUndoAction( o3tl::make_unique<ScUndoShowHideTab>( &rDocShell, undoTabs, bVisible ) ); } // update views @@ -3327,7 +3327,7 @@ bool ScDocFunc::SetLayoutRTL( SCTAB nTab, bool bRTL ) if (bUndo) { - rDocShell.GetUndoManager()->AddUndoAction( new ScUndoLayoutRTL( &rDocShell, nTab, bRTL ) ); + rDocShell.GetUndoManager()->AddUndoAction( o3tl::make_unique<ScUndoLayoutRTL>( &rDocShell, nTab, bRTL ) ); } rDocShell.PostPaint( 0,0,0,MAXCOL,MAXROW,MAXTAB, PaintPartFlags::All ); @@ -3365,7 +3365,7 @@ bool ScDocFunc::RenameTable( SCTAB nTab, const OUString& rName, bool bRecord, bo if (bRecord) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoRenameTab( &rDocShell, nTab, sOldName, rName)); + o3tl::make_unique<ScUndoRenameTab>( &rDocShell, nTab, sOldName, rName)); } rDocShell.PostPaintExtras(); aModificator.SetDocumentModified(); @@ -3401,7 +3401,7 @@ bool ScDocFunc::SetTabBgColor( SCTAB nTab, const Color& rColor, bool bRecord, bo if (bRecord) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoTabColor( &rDocShell, nTab, aOldTabBgColor, rColor)); + o3tl::make_unique<ScUndoTabColor>( &rDocShell, nTab, aOldTabBgColor, rColor)); } rDocShell.PostPaintExtras(); ScDocShellModificator aModificator( rDocShell ); @@ -3466,7 +3466,7 @@ bool ScDocFunc::SetTabBgColor( if (bRecord) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoTabColor( &rDocShell, rUndoTabColorList)); + o3tl::make_unique<ScUndoTabColor>( &rDocShell, rUndoTabColorList)); } rDocShell.PostPaintExtras(); ScDocShellModificator aModificator( rDocShell ); @@ -3649,7 +3649,7 @@ bool ScDocFunc::SetWidthOrHeight( ScMarkData aMark; aMark.SelectOneTable( nTab ); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoWidthOrHeight( + o3tl::make_unique<ScUndoWidthOrHeight>( &rDocShell, aMark, nStart, nTab, nEnd, nTab, std::move(pUndoDoc), aUndoRanges, std::move(pUndoTab), eMode, nSizeTwips, bWidth)); } @@ -3690,7 +3690,7 @@ bool ScDocFunc::InsertPageBreak( bool bColumn, const ScAddress& rPos, if (bRecord) rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoPageBreak( &rDocShell, rPos.Col(), rPos.Row(), nTab, bColumn, true ) ); + o3tl::make_unique<ScUndoPageBreak>( &rDocShell, rPos.Col(), rPos.Row(), nTab, bColumn, true ) ); if (bColumn) rDoc.SetColBreak(static_cast<SCCOL>(nPos), nTab, false, true); @@ -3754,7 +3754,7 @@ bool ScDocFunc::RemovePageBreak( bool bColumn, const ScAddress& rPos, if (bRecord) rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoPageBreak( &rDocShell, rPos.Col(), rPos.Row(), nTab, bColumn, false ) ); + o3tl::make_unique<ScUndoPageBreak>( &rDocShell, rPos.Col(), rPos.Row(), nTab, bColumn, false ) ); if (bColumn) rDoc.RemoveColBreak(static_cast<SCCOL>(nPos), nTab, false, true); @@ -3806,7 +3806,7 @@ void ScDocFunc::ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect ) ::std::unique_ptr<ScTableProtection> p(new ScTableProtection(*pProtect)); p->setProtected(true); // just in case ... rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoTabProtect(&rDocShell, nTab, std::move(p)) ); + o3tl::make_unique<ScUndoTabProtect>(&rDocShell, nTab, std::move(p)) ); // ownership of unique_ptr now transferred to ScUndoTabProtect. } @@ -3836,7 +3836,7 @@ bool ScDocFunc::Protect( SCTAB nTab, const OUString& rPassword ) ::std::unique_ptr<ScDocProtection> p(new ScDocProtection(*pProtect)); p->setProtected(true); // just in case ... rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDocProtect(&rDocShell, std::move(p)) ); + o3tl::make_unique<ScUndoDocProtect>(&rDocShell, std::move(p)) ); // ownership of unique_ptr is transferred to ScUndoDocProtect. } } @@ -3859,7 +3859,7 @@ bool ScDocFunc::Protect( SCTAB nTab, const OUString& rPassword ) ::std::unique_ptr<ScTableProtection> p(new ScTableProtection(*pProtect)); p->setProtected(true); // just in case ... rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoTabProtect(&rDocShell, nTab, std::move(p)) ); + o3tl::make_unique<ScUndoTabProtect>(&rDocShell, nTab, std::move(p)) ); // ownership of unique_ptr now transferred to ScUndoTabProtect. } } @@ -3906,7 +3906,7 @@ bool ScDocFunc::Unprotect( SCTAB nTab, const OUString& rPassword, bool bApi ) { pProtectCopy->setProtected(false); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDocProtect(&rDocShell, std::move(pProtectCopy)) ); + o3tl::make_unique<ScUndoDocProtect>(&rDocShell, std::move(pProtectCopy)) ); // ownership of unique_ptr now transferred to ScUndoDocProtect. } } @@ -3941,7 +3941,7 @@ bool ScDocFunc::Unprotect( SCTAB nTab, const OUString& rPassword, bool bApi ) { pProtectCopy->setProtected(false); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoTabProtect(&rDocShell, nTab, std::move(pProtectCopy)) ); + o3tl::make_unique<ScUndoTabProtect>(&rDocShell, nTab, std::move(pProtectCopy)) ); // ownership of unique_ptr now transferred to ScUndoTabProtect. } } @@ -3987,7 +3987,7 @@ void ScDocFunc::ClearItems( const ScMarkData& rMark, const sal_uInt16* pWhich, b rDoc.CopyToDocument( aMarkRange, InsertDeleteFlags::ATTRIB, true, *pUndoDoc, &aMultiMark ); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoClearItems( &rDocShell, aMultiMark, std::move(pUndoDoc), pWhich ) ); + o3tl::make_unique<ScUndoClearItems>( &rDocShell, aMultiMark, std::move(pUndoDoc), pWhich ) ); } rDoc.ClearSelectionItems( pWhich, aMultiMark ); @@ -4033,7 +4033,7 @@ bool ScDocFunc::ChangeIndent( const ScMarkData& rMark, bool bIncrement, bool bAp rDoc.CopyToDocument( aCopyRange, InsertDeleteFlags::ATTRIB, true, *pUndoDoc, &rMark ); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoIndent( &rDocShell, rMark, std::move(pUndoDoc), bIncrement ) ); + o3tl::make_unique<ScUndoIndent>( &rDocShell, rMark, std::move(pUndoDoc), bIncrement ) ); } rDoc.ChangeSelectionIndent( bIncrement, rMark ); @@ -4157,7 +4157,7 @@ bool ScDocFunc::AutoFormat( const ScRange& rRange, const ScMarkData* pTabMark, if ( bRecord ) // only now is Draw-Undo available { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoAutoFormat( &rDocShell, rRange, std::move(pUndoDoc), aMark, bSize, nFormatNo ) ); + o3tl::make_unique<ScUndoAutoFormat>( &rDocShell, rRange, std::move(pUndoDoc), aMark, bSize, nFormatNo ) ); } aModificator.SetDocumentModified(); @@ -4242,7 +4242,7 @@ bool ScDocFunc::EnterMatrix( const ScRange& rRange, const ScMarkData* pTabMark, { //! take selected sheets into account also when undoing rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoEnterMatrix( &rDocShell, rRange, std::move(pUndoDoc), rString ) ); + o3tl::make_unique<ScUndoEnterMatrix>( &rDocShell, rRange, std::move(pUndoDoc), rString ) ); } // Err522 painting of DDE-Formulas will be intercepted during interpreting @@ -4296,7 +4296,7 @@ bool ScDocFunc::TabOp( const ScRange& rRange, const ScMarkData* pTabMark, rDoc.CopyToDocument( rRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, *pUndoDoc ); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoTabOp( &rDocShell, + o3tl::make_unique<ScUndoTabOp>( &rDocShell, nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab, std::move(pUndoDoc), rParam.aRefFormulaCell, @@ -4492,7 +4492,7 @@ bool ScDocFunc::FillSimple( const ScRange& rRange, const ScMarkData* pTabMark, if ( bRecord ) // only now is Draw-Undo available { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoAutoFill( &rDocShell, aDestArea, aSourceArea, std::move(pUndoDoc), aMark, + o3tl::make_unique<ScUndoAutoFill>( &rDocShell, aDestArea, aSourceArea, std::move(pUndoDoc), aMark, eDir, FILL_SIMPLE, FILL_DAY, MAXDOUBLE, 1.0, 1e307) ); } @@ -4623,7 +4623,7 @@ bool ScDocFunc::FillSeries( const ScRange& rRange, const ScMarkData* pTabMark, if ( bRecord ) // only now is Draw-Undo available { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoAutoFill( &rDocShell, aDestArea, aSourceArea, std::move(pUndoDoc), aMark, + o3tl::make_unique<ScUndoAutoFill>( &rDocShell, aDestArea, aSourceArea, std::move(pUndoDoc), aMark, eDir, eCmd, eDateCmd, fStart, fStep, fMax) ); } @@ -4762,7 +4762,7 @@ bool ScDocFunc::FillAuto( ScRange& rRange, const ScMarkData* pTabMark, FillDir e if ( bRecord ) // only now is Draw-Undo available { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoAutoFill( &rDocShell, aDestArea, aSourceArea, std::move(pUndoDoc), aMark, + o3tl::make_unique<ScUndoAutoFill>( &rDocShell, aDestArea, aSourceArea, std::move(pUndoDoc), aMark, eDir, eCmd, eDateCmd, MAXDOUBLE, fStep, fMax) ); } @@ -4876,7 +4876,7 @@ bool ScDocFunc::MergeCells( const ScCellMergeOption& rOption, bool bContents, bo { std::unique_ptr<SdrUndoGroup> pDrawUndo = rDoc.GetDrawLayer() ? rDoc.GetDrawLayer()->GetCalcUndo() : nullptr; rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoMerge(&rDocShell, rOption, bNeedContentsUndo, std::move(pUndoDoc), std::move(pDrawUndo)) ); + o3tl::make_unique<ScUndoMerge>(&rDocShell, rOption, bNeedContentsUndo, std::move(pUndoDoc), std::move(pDrawUndo)) ); } aModificator.SetDocumentModified(); @@ -4969,7 +4969,7 @@ bool ScDocFunc::UnmergeCells( const ScCellMergeOption& rOption, bool bRecord, Sc else { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoRemoveMerge( &rDocShell, rOption, ScDocumentUniquePtr(pUndoDoc) ) ); + o3tl::make_unique<ScUndoRemoveMerge>( &rDocShell, rOption, ScDocumentUniquePtr(pUndoDoc) ) ); } } aModificator.SetDocumentModified(); @@ -5004,7 +5004,7 @@ void ScDocFunc::SetNewRangeNames( std::unique_ptr<ScRangeName> pNewRanges, bool std::unique_ptr<ScRangeName> pUndoRanges(new ScRangeName(*pOld)); std::unique_ptr<ScRangeName> pRedoRanges(new ScRangeName(*pNewRanges)); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoRangeNames( &rDocShell, std::move(pUndoRanges), std::move(pRedoRanges), nTab ) ); + o3tl::make_unique<ScUndoRangeNames>( &rDocShell, std::move(pUndoRanges), std::move(pRedoRanges), nTab ) ); } // #i55926# While loading XML, formula cells only have a single string token, @@ -5038,7 +5038,7 @@ void ScDocFunc::ModifyAllRangeNames(const std::map<OUString, std::unique_ptr<ScR std::map<OUString, ScRangeName*> aOldRangeMap; rDoc.GetRangeNameMap(aOldRangeMap); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoAllRangeNames(&rDocShell, aOldRangeMap, rRangeMap)); + o3tl::make_unique<ScUndoAllRangeNames>(&rDocShell, aOldRangeMap, rRangeMap)); } rDoc.PreprocessAllRangeNamesUpdate(rRangeMap); @@ -5301,7 +5301,7 @@ bool ScDocFunc::InsertNameList( const ScAddress& rStartPos, bool bApi ) InsertDeleteFlags::ALL, false, *pRedoDoc); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoListNames( &rDocShell, + o3tl::make_unique<ScUndoListNames>( &rDocShell, ScRange( nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab ), std::move(pUndoDoc), std::move(pRedoDoc) ) ); } @@ -5398,7 +5398,7 @@ void ScDocFunc::InsertAreaLink( const OUString& rFile, const OUString& rFilter, ScAreaLink* pOldArea = static_cast<ScAreaLink*>(pBase); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoRemoveAreaLink( &rDocShell, + o3tl::make_unique<ScUndoRemoveAreaLink>( &rDocShell, pOldArea->GetFile(), pOldArea->GetFilter(), pOldArea->GetOptions(), pOldArea->GetSource(), pOldArea->GetDestArea(), pOldArea->GetRefreshDelay() ) ); } @@ -5428,7 +5428,7 @@ void ScDocFunc::InsertAreaLink( const OUString& rFile, const OUString& rFilter, if (bUndo) { - rDocShell.GetUndoManager()->AddUndoAction( new ScUndoInsertAreaLink( &rDocShell, + rDocShell.GetUndoManager()->AddUndoAction( o3tl::make_unique<ScUndoInsertAreaLink>( &rDocShell, rFile, aFilterName, aNewOptions, rSource, rDestRange, nRefresh ) ); if ( nRemoved ) @@ -5516,7 +5516,7 @@ void ScDocFunc::ReplaceConditionalFormat( sal_uLong nOldFormat, ScConditionalFor aCompleteRange.aEnd.Col(),aCompleteRange.aEnd.Row(),nTab, InsertDeleteFlags::ALL, false, *pRedoDoc); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoConditionalFormat(&rDocShell, std::move(pUndoDoc), std::move(pRedoDoc), aCompleteRange)); + o3tl::make_unique<ScUndoConditionalFormat>(&rDocShell, std::move(pUndoDoc), std::move(pRedoDoc), aCompleteRange)); } if(pRepaintRange) @@ -5566,7 +5566,7 @@ void ScDocFunc::SetConditionalFormatList( ScConditionalFormatList* pList, SCTAB pRedoDoc->SetCondFormList(new ScConditionalFormatList(pRedoDoc.get(), *pList), nTab); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoConditionalFormatList(&rDocShell, std::move(pUndoDoc), std::move(pRedoDoc), nTab)); + o3tl::make_unique<ScUndoConditionalFormatList>(&rDocShell, std::move(pUndoDoc), std::move(pRedoDoc), nTab)); } rDoc.SetStreamValid(nTab, false); @@ -5598,7 +5598,7 @@ void ScDocFunc::ConvertFormulaToValue( const ScRange& rRange, bool bInteraction if (bRecord && pUndoVals) { rDocShell.GetUndoManager()->AddUndoAction( - new sc::UndoFormulaToValue(&rDocShell, *pUndoVals)); + o3tl::make_unique<sc::UndoFormulaToValue>(&rDocShell, *pUndoVals)); } rDocShell.PostPaint(rRange, PaintPartFlags::Grid); diff --git a/sc/source/ui/docshell/docfuncutil.cxx b/sc/source/ui/docshell/docfuncutil.cxx index 0ee0805ee905..6e469c5c7e88 100644 --- a/sc/source/ui/docshell/docfuncutil.cxx +++ b/sc/source/ui/docshell/docfuncutil.cxx @@ -85,7 +85,7 @@ void DocFuncUtil::addDeleteContentsUndo( pDocSh, rMark, rRange, std::move(pUndoDoc), bMulti, nFlags, bDrawUndo)); pUndo->SetDataSpans(pSpans); - pUndoMgr->AddUndoAction(pUndo.release()); + pUndoMgr->AddUndoAction(std::move(pUndo)); } std::unique_ptr<ScSimpleUndo::DataSpansType> DocFuncUtil::getNonEmptyCellSpans( diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx index 1fab2b481f6f..b09254aeb764 100644 --- a/sc/source/ui/docshell/docsh4.cxx +++ b/sc/source/ui/docshell/docsh4.cxx @@ -388,7 +388,7 @@ void ScDocShell::Execute( SfxRequest& rReq ) if (bUndo) { GetUndoManager()->AddUndoAction( - new ScUndoChartData( this, aChartName, aRangeListRef, + o3tl::make_unique<ScUndoChartData>( this, aChartName, aRangeListRef, bColHeaders, bRowHeaders, bAddRange ) ); } m_aDocument.UpdateChartArea( aChartName, aRangeListRef, @@ -400,7 +400,7 @@ void ScDocShell::Execute( SfxRequest& rReq ) if (bUndo) { GetUndoManager()->AddUndoAction( - new ScUndoChartData( this, aChartName, aNewRange, + o3tl::make_unique<ScUndoChartData>( this, aChartName, aNewRange, bColHeaders, bRowHeaders, bAddRange ) ); } m_aDocument.UpdateChartArea( aChartName, aNewRange, @@ -1524,7 +1524,7 @@ void ScDocShell::SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages { sal_uInt16 nOldScale = rSet.Get(ATTR_PAGE_SCALE).GetValue(); sal_uInt16 nOldPages = rSet.Get(ATTR_PAGE_SCALETOPAGES).GetValue(); - GetUndoManager()->AddUndoAction( new ScUndoPrintZoom( + GetUndoManager()->AddUndoAction( o3tl::make_unique<ScUndoPrintZoom>( this, nTab, nOldScale, nOldPages, nScale, nPages ) ); } @@ -1726,7 +1726,7 @@ void ScDocShell::ExecutePageStyle( const SfxViewShell& rCaller, if (bUndo) { GetUndoManager()->AddUndoAction( - new ScUndoModifyStyle( this, SfxStyleFamily::Page, + o3tl::make_unique<ScUndoModifyStyle>( this, SfxStyleFamily::Page, aOldData, aNewData ) ); } diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx index f94be4468f18..01a6fe6a906b 100644 --- a/sc/source/ui/docshell/docsh5.cxx +++ b/sc/source/ui/docshell/docsh5.cxx @@ -324,7 +324,7 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe { m_aDocument.CompileHybridFormula(); - GetUndoManager()->AddUndoAction( new ScUndoDBData( this, + GetUndoManager()->AddUndoAction( o3tl::make_unique<ScUndoDBData>( this, std::move(pUndoColl), o3tl::make_unique<ScDBCollection>( *pColl ) ) ); } @@ -598,7 +598,7 @@ void ScDocShell::DoConsolidate( const ScConsolidateParam& rParam, bool bRecord ) m_aDocument.CopyToDocument(aOldDest, InsertDeleteFlags::ALL, false, *pUndoDoc); GetUndoManager()->AddUndoAction( - new ScUndoConsolidate( this, aDestArea, rParam, std::move(pUndoDoc), + o3tl::make_unique<ScUndoConsolidate>( this, aDestArea, rParam, std::move(pUndoDoc), true, nInsertCount, std::move(pUndoTab), std::move(pUndoData) ) ); } else @@ -615,7 +615,7 @@ void ScDocShell::DoConsolidate( const ScConsolidateParam& rParam, bool bRecord ) m_aDocument.CopyToDocument(aOldDest, InsertDeleteFlags::ALL, false, *pUndoDoc); GetUndoManager()->AddUndoAction( - new ScUndoConsolidate( this, aDestArea, rParam, std::move(pUndoDoc), + o3tl::make_unique<ScUndoConsolidate>( this, aDestArea, rParam, std::move(pUndoDoc), false, 0, nullptr, std::move(pUndoData) ) ); } } @@ -716,7 +716,7 @@ void ScDocShell::UseScenario( SCTAB nTab, const OUString& rName, bool bRecord ) } GetUndoManager()->AddUndoAction( - new ScUndoUseScenario( this, aScenMark, + o3tl::make_unique<ScUndoUseScenario>( this, aScenMark, ScArea( nTab,nStartCol,nStartRow,nEndCol,nEndRow ), std::move(pUndoDoc), rName ) ); } @@ -766,7 +766,7 @@ void ScDocShell::ModifyScenario( SCTAB nTab, const OUString& rName, const OUStri ScScenarioFlags nOldFlags; m_aDocument.GetScenarioData( nTab, aOldComment, aOldColor, nOldFlags ); GetUndoManager()->AddUndoAction( - new ScUndoScenarioFlags(this, nTab, + o3tl::make_unique<ScUndoScenarioFlags>(this, nTab, aOldName, rName, aOldComment, rComment, aOldColor, rColor, nOldFlags, nFlags) ); @@ -811,7 +811,7 @@ SCTAB ScDocShell::MakeScenario( SCTAB nTab, const OUString& rName, const OUStrin if (bRecord) { GetUndoManager()->AddUndoAction( - new ScUndoMakeScenario( this, nTab, nNewTab, + o3tl::make_unique<ScUndoMakeScenario>( this, nTab, nNewTab, rName, rComment, rColor, nFlags, rMark )); } @@ -937,7 +937,7 @@ bool ScDocShell::MoveTable( SCTAB nSrcTab, SCTAB nDestTab, bool bCopy, bool bRec unique_ptr< vector<SCTAB> > pSrcList(new vector<SCTAB>(1, nSrcTab)); unique_ptr< vector<SCTAB> > pDestList(new vector<SCTAB>(1, nDestTab)); GetUndoManager()->AddUndoAction( - new ScUndoCopyTab(this, std::move(pSrcList), std::move(pDestList))); + o3tl::make_unique<ScUndoCopyTab>(this, std::move(pSrcList), std::move(pDestList))); } bool bVbaEnabled = m_aDocument.IsInVBAMode(); @@ -1004,7 +1004,7 @@ bool ScDocShell::MoveTable( SCTAB nSrcTab, SCTAB nDestTab, bool bCopy, bool bRec unique_ptr< vector<SCTAB> > pSrcList(new vector<SCTAB>(1, nSrcTab)); unique_ptr< vector<SCTAB> > pDestList(new vector<SCTAB>(1, nDestTab)); GetUndoManager()->AddUndoAction( - new ScUndoMoveTab(this, std::move(pSrcList), std::move(pDestList))); + o3tl::make_unique<ScUndoMoveTab>(this, std::move(pSrcList), std::move(pDestList))); } Broadcast( ScTablesHint( SC_TAB_MOVED, nSrcTab, nDestTab ) ); diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index 0e80e499411d..f82630e600b1 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -263,7 +263,7 @@ void ScImportExport::EndPaste(bool bAutoRowHeight) ScMarkData aDestMark; aDestMark.SetMarkArea(aRange); pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoPaste(pDocSh, aRange, aDestMark, std::move(pUndoDoc), std::move(pRedoDoc), InsertDeleteFlags::ALL, nullptr)); + o3tl::make_unique<ScUndoPaste>(pDocSh, aRange, aDestMark, std::move(pUndoDoc), std::move(pRedoDoc), InsertDeleteFlags::ALL, nullptr)); } pUndoDoc.reset(); if( pDocSh ) diff --git a/sc/source/ui/docshell/olinefun.cxx b/sc/source/ui/docshell/olinefun.cxx index b63de2cf27a4..23a8f846af35 100644 --- a/sc/source/ui/docshell/olinefun.cxx +++ b/sc/source/ui/docshell/olinefun.cxx @@ -111,7 +111,7 @@ void ScOutlineDocFunc::MakeOutline( const ScRange& rRange, bool bColumns, bool b if (bRecord) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoMakeOutline( &rDocShell, + o3tl::make_unique<ScUndoMakeOutline>( &rDocShell, nStartCol,nStartRow,nTab,nEndCol,nEndRow,nTab, std::move(pUndoTab), bColumns, true ) ); } @@ -172,7 +172,7 @@ void ScOutlineDocFunc::RemoveOutline( const ScRange& rRange, bool bColumns, bool if (bRecord) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoMakeOutline( &rDocShell, + o3tl::make_unique<ScUndoMakeOutline>( &rDocShell, nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab, std::move(pUndoTab), bColumns, false ) ); } @@ -228,7 +228,7 @@ bool ScOutlineDocFunc::RemoveAllOutlines( SCTAB nTab, bool bRecord ) std::unique_ptr<ScOutlineTable> pUndoTab(new ScOutlineTable( *pTable )); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoRemoveAllOutlines( &rDocShell, + o3tl::make_unique<ScUndoRemoveAllOutlines>( &rDocShell, nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab, std::move(pUndoDoc), std::move(pUndoTab) ) ); @@ -300,7 +300,7 @@ void ScOutlineDocFunc::AutoOutline( const ScRange& rRange, bool bRecord ) if (bRecord) { rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoAutoOutline( &rDocShell, + o3tl::make_unique<ScUndoAutoOutline>( &rDocShell, nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab, std::move(pUndoDoc), std::move(pUndoTab) ) ); @@ -348,7 +348,7 @@ bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, bool bColumns, sal_uInt16 nLevel } rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoOutlineLevel( &rDocShell, + o3tl::make_unique<ScUndoOutlineLevel>( &rDocShell, nStart, nEnd, nTab, //! calculate start and end std::move(pUndoDoc), std::move(pUndoTab), bColumns, nLevel ) ); @@ -461,7 +461,7 @@ bool ScOutlineDocFunc::ShowMarkedOutlines( const ScRange& rRange, bool bRecord ) rDoc.CopyToDocument(0, nStartRow, nTab, MAXCOL, nEndRow, nTab, InsertDeleteFlags::NONE, false, *pUndoDoc); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoOutlineBlock( &rDocShell, + o3tl::make_unique<ScUndoOutlineBlock>( &rDocShell, nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab, std::move(pUndoDoc), std::move(pUndoTab), true ) ); } @@ -589,7 +589,7 @@ bool ScOutlineDocFunc::HideMarkedOutlines( const ScRange& rRange, bool bRecord ) rDoc.CopyToDocument(0, nEffStartRow, nTab, MAXCOL, nEffEndRow, nTab, InsertDeleteFlags::NONE, false, *pUndoDoc); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoOutlineBlock( &rDocShell, + o3tl::make_unique<ScUndoOutlineBlock>( &rDocShell, nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab, std::move(pUndoDoc), std::move(pUndoTab), false ) ); } @@ -666,7 +666,7 @@ void ScOutlineDocFunc::ShowOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel } rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDoOutline( &rDocShell, + o3tl::make_unique<ScUndoDoOutline>( &rDocShell, nStart, nEnd, nTab, std::move(pUndoDoc), //! calc start and end bColumns, nLevel, nEntry, true ) ); } @@ -758,7 +758,7 @@ bool ScOutlineDocFunc::HideOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel } rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDoOutline( &rDocShell, + o3tl::make_unique<ScUndoDoOutline>( &rDocShell, nStart, nEnd, nTab, std::move(pUndoDoc), bColumns, nLevel, nEntry, false ) ); } diff --git a/sc/source/ui/docshell/tablink.cxx b/sc/source/ui/docshell/tablink.cxx index 4b1ebb5928ed..1644c6eba5c6 100644 --- a/sc/source/ui/docshell/tablink.cxx +++ b/sc/source/ui/docshell/tablink.cxx @@ -145,7 +145,7 @@ void ScTableLink::Closed() if (bAddUndo && bUndo) { pImpl->m_pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoRemoveLink( pImpl->m_pDocSh, aFileName ) ); + o3tl::make_unique<ScUndoRemoveLink>( pImpl->m_pDocSh, aFileName ) ); bAddUndo = false; // only once } @@ -384,7 +384,7 @@ bool ScTableLink::Refresh(const OUString& rNewFile, const OUString& rNewFilter, if (bAddUndo && bUndo) pImpl->m_pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoRefreshLink( pImpl->m_pDocSh, std::move(pUndoDoc) ) ); + o3tl::make_unique<ScUndoRefreshLink>( pImpl->m_pDocSh, std::move(pUndoDoc) ) ); // Paint (may be several tables) diff --git a/sc/source/ui/drawfunc/drawsh5.cxx b/sc/source/ui/drawfunc/drawsh5.cxx index 8cd59b32e9ff..cc036a2bd5e4 100644 --- a/sc/source/ui/drawfunc/drawsh5.cxx +++ b/sc/source/ui/drawfunc/drawsh5.cxx @@ -522,7 +522,7 @@ void ScDrawShell::ExecDrawFunc( SfxRequest& rReq ) if(!aPersistName.isEmpty()) { pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoRenameObject(pDocSh, aPersistName, pSelected->GetName(), aName)); + o3tl::make_unique<ScUndoRenameObject>(pDocSh, aPersistName, pSelected->GetName(), aName)); } } diff --git a/sc/source/ui/drawfunc/fuins2.cxx b/sc/source/ui/drawfunc/fuins2.cxx index 2ea92dec0858..6ac928a06401 100644 --- a/sc/source/ui/drawfunc/fuins2.cxx +++ b/sc/source/ui/drawfunc/fuins2.cxx @@ -564,7 +564,7 @@ FuInsertChart::FuInsertChart(ScTabViewShell& rViewSh, vcl::Window* pWin, ScDrawV if (bUndo) { pScDocSh->GetUndoManager()->AddUndoAction( - new ScUndoInsertTab( pScDocSh, nNewTab, + o3tl::make_unique<ScUndoInsertTab>( pScDocSh, nNewTab, true/*bAppend*/, aTabName ) ); } @@ -727,7 +727,7 @@ FuInsertChart::FuInsertChart(ScTabViewShell& rViewSh, vcl::Window* pWin, ScDrawV { // add undo action the same way as in SdrEditView::InsertObjectAtView // (using UndoActionHdl etc.) - pView->AddUndo(new SdrUndoNewObj(*pObj)); + pView->AddUndo(o3tl::make_unique<SdrUndoNewObj>(*pObj)); } // BM/IHA -- diff --git a/sc/source/ui/drawfunc/futext3.cxx b/sc/source/ui/drawfunc/futext3.cxx index a6ffeb93e4ec..6f7431056b9f 100644 --- a/sc/source/ui/drawfunc/futext3.cxx +++ b/sc/source/ui/drawfunc/futext3.cxx @@ -92,9 +92,9 @@ void FuText::StopEditMode() // create a "insert note" undo action if needed if( bNewNote ) - pUndoMgr->AddUndoAction( new ScUndoReplaceNote( *pDocShell, aNotePos, pNote->GetNoteData(), true, std::move(pCalcUndo) ) ); + pUndoMgr->AddUndoAction( o3tl::make_unique<ScUndoReplaceNote>( *pDocShell, aNotePos, pNote->GetNoteData(), true, std::move(pCalcUndo) ) ); else - pUndoMgr->AddUndoAction( pCalcUndo.release() ); + pUndoMgr->AddUndoAction( std::move(pCalcUndo) ); } } @@ -143,7 +143,7 @@ void FuText::StopEditMode() // delete note from document (removes caption, but does not delete it) rDoc.ReleaseNote(aNotePos); // create undo action for removed note - pUndoMgr->AddUndoAction( new ScUndoReplaceNote( *pDocShell, aNotePos, aNoteData, false, pDrawLayer->GetCalcUndo() ) ); + pUndoMgr->AddUndoAction( o3tl::make_unique<ScUndoReplaceNote>( *pDocShell, aNotePos, aNoteData, false, pDrawLayer->GetCalcUndo() ) ); } else { diff --git a/sc/source/ui/namedlg/namedefdlg.cxx b/sc/source/ui/namedlg/namedefdlg.cxx index d88f368d8a28..ff226ef9a471 100644 --- a/sc/source/ui/namedlg/namedefdlg.cxx +++ b/sc/source/ui/namedlg/namedefdlg.cxx @@ -258,7 +258,7 @@ void ScNameDefDlg::AddPushed() assert( pNewEntry); // undo of no insertion smells fishy if (pNewEntry) mpDocShell->GetUndoManager()->AddUndoAction( - new ScUndoAddRangeData( mpDocShell, pNewEntry, nTab) ); + o3tl::make_unique<ScUndoAddRangeData>( mpDocShell, pNewEntry, nTab) ); // set table stream invalid, otherwise RangeName won't be saved if no other // call invalidates the stream diff --git a/sc/source/ui/unoobj/TablePivotCharts.cxx b/sc/source/ui/unoobj/TablePivotCharts.cxx index 7f150e228572..22c3b2bbc6d1 100644 --- a/sc/source/ui/unoobj/TablePivotCharts.cxx +++ b/sc/source/ui/unoobj/TablePivotCharts.cxx @@ -164,7 +164,7 @@ void SAL_CALL TablePivotCharts::addNewByName(OUString const & rName, xObject->setVisualAreaSize(nAspect, aAwtSize); pPage->InsertObject(pObject); - pModel->AddUndo(new SdrUndoInsertObj(*pObject)); + pModel->AddUndo(o3tl::make_unique<SdrUndoInsertObj>(*pObject)); } } @@ -177,7 +177,7 @@ void SAL_CALL TablePivotCharts::removeByName(const OUString& rName) ScDocument& rDoc = m_pDocShell->GetDocument(); ScDrawLayer* pModel = rDoc.GetDrawLayer(); SdrPage* pPage = pModel->GetPage(sal_uInt16(m_nTab)); - pModel->AddUndo(new SdrUndoDelObj(*pObject)); + pModel->AddUndo(o3tl::make_unique<SdrUndoDelObj>(*pObject)); pPage->RemoveObject(pObject->GetOrdNum()); } } diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index bb877953a05c..3107100af06b 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -1086,7 +1086,7 @@ void ScHelperFunctions::ApplyBorder( ScDocShell* pDocShell, const ScRangeList& r if (bUndo) { pDocShell->GetUndoManager()->AddUndoAction( - new ScUndoBorder( pDocShell, rRanges, std::move(pUndoDoc), rOuter, rInner ) ); + o3tl::make_unique<ScUndoBorder>( pDocShell, rRanges, std::move(pUndoDoc), rOuter, rInner ) ); } for (size_t i = 0; i < nCount; ++i ) @@ -1223,7 +1223,7 @@ static bool lcl_PutDataArray( ScDocShell& rDocShell, const ScRange& rRange, ScMarkData aDestMark; aDestMark.SelectOneTable( nTab ); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoPaste( + o3tl::make_unique<ScUndoPaste>( &rDocShell, ScRange(nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab), aDestMark, std::move(pUndoDoc), nullptr, InsertDeleteFlags::CONTENTS, nullptr, false)); } @@ -1324,7 +1324,7 @@ static bool lcl_PutFormulaArray( ScDocShell& rDocShell, const ScRange& rRange, ScMarkData aDestMark; aDestMark.SelectOneTable( nTab ); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoPaste( &rDocShell, + o3tl::make_unique<ScUndoPaste>( &rDocShell, ScRange(nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab), aDestMark, std::move(pUndoDoc), nullptr, InsertDeleteFlags::CONTENTS, nullptr, false)); } @@ -4047,7 +4047,7 @@ sal_Int32 SAL_CALL ScCellRangesBase::replaceAll( const uno::Reference<util::XSea nReplaced = pUndoDoc->GetCellCount(); pDocShell->GetUndoManager()->AddUndoAction( - new ScUndoReplace( pDocShell, *pUndoMark, nCol, nRow, nTab, + o3tl::make_unique<ScUndoReplace>( pDocShell, *pUndoMark, nCol, nRow, nTab, aUndoStr, std::move(pUndoDoc), pSearchItem ) ); pDocShell->PostPaintGridAll(); @@ -7015,7 +7015,7 @@ void SAL_CALL ScTableSheetObj::removeAllManualPageBreaks() pUndoDoc->InitUndo( &rDoc, nTab, nTab, true, true ); rDoc.CopyToDocument(0,0,nTab, MAXCOL,MAXROW,nTab, InsertDeleteFlags::NONE, false, *pUndoDoc); pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoRemoveBreaks( pDocSh, nTab, std::move(pUndoDoc) ) ); + o3tl::make_unique<ScUndoRemoveBreaks>( pDocSh, nTab, std::move(pUndoDoc) ) ); } rDoc.RemoveManualBreaks(nTab); @@ -7182,7 +7182,7 @@ void ScTableSheetObj::PrintAreaUndo_Impl( std::unique_ptr<ScPrintRangeSaver> pOl if(bUndo) { pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoPrintRange( + o3tl::make_unique<ScUndoPrintRange>( pDocSh, nTab, std::move(pOldRanges), diff --git a/sc/source/ui/unoobj/chartuno.cxx b/sc/source/ui/unoobj/chartuno.cxx index 61670c1b86fa..d3be0afbf05f 100644 --- a/sc/source/ui/unoobj/chartuno.cxx +++ b/sc/source/ui/unoobj/chartuno.cxx @@ -261,7 +261,7 @@ void SAL_CALL ScChartsObj::addNewByName( const OUString& rName, // ChartHelper::AdaptDefaultsForChart( xObj ); pPage->InsertObject( pObj ); - pModel->AddUndo( new SdrUndoInsertObj( *pObj ) ); + pModel->AddUndo( o3tl::make_unique<SdrUndoInsertObj>( *pObj ) ); } } @@ -276,7 +276,7 @@ void SAL_CALL ScChartsObj::removeByName( const OUString& aName ) ScDrawLayer* pModel = rDoc.GetDrawLayer(); // is not zero SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(nTab)); // is not zero - pModel->AddUndo( new SdrUndoDelObj( *pObj ) ); + pModel->AddUndo( o3tl::make_unique<SdrUndoDelObj>( *pObj ) ); pPage->RemoveObject( pObj->GetOrdNum() ); //! Notify etc.??? @@ -508,7 +508,7 @@ void ScChartObj::Update_Impl( const ScRangeListRef& rRanges, bool bColHeaders, b if (bUndo) { pDocShell->GetUndoManager()->AddUndoAction( - new ScUndoChartData( pDocShell, aChartName, rRanges, bColHeaders, bRowHeaders, false ) ); + o3tl::make_unique<ScUndoChartData>( pDocShell, aChartName, rRanges, bColHeaders, bRowHeaders, false ) ); } rDoc.UpdateChartArea( aChartName, rRanges, bColHeaders, bRowHeaders, false ); } diff --git a/sc/source/ui/view/dbfunc.cxx b/sc/source/ui/view/dbfunc.cxx index 24e2d194f537..03c5f5f4fcef 100644 --- a/sc/source/ui/view/dbfunc.cxx +++ b/sc/source/ui/view/dbfunc.cxx @@ -315,7 +315,7 @@ void ScDBFunc::ToggleAutoFilter() ScRange aRange; pDBData->GetArea( aRange ); pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoAutoFilter( pDocSh, aRange, pDBData->GetName(), false ) ); + o3tl::make_unique<ScUndoAutoFilter>( pDocSh, aRange, pDBData->GetName(), false ) ); pDBData->SetAutoFilter(false); @@ -354,7 +354,7 @@ void ScDBFunc::ToggleAutoFilter() ScRange aRange; pDBData->GetArea( aRange ); pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoAutoFilter( pDocSh, aRange, pDBData->GetName(), true ) ); + o3tl::make_unique<ScUndoAutoFilter>( pDocSh, aRange, pDBData->GetName(), true ) ); pDBData->SetAutoFilter(true); @@ -413,7 +413,7 @@ void ScDBFunc::HideAutoFilter() ScRange aRange; pDBData->GetArea( aRange ); pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoAutoFilter( pDocSh, aRange, pDBData->GetName(), false ) ); + o3tl::make_unique<ScUndoAutoFilter>( pDocSh, aRange, pDBData->GetName(), false ) ); pDBData->SetAutoFilter(false); diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx index 72f36dbeabb3..a74bb99e49b2 100644 --- a/sc/source/ui/view/dbfunc3.cxx +++ b/sc/source/ui/view/dbfunc3.cxx @@ -524,7 +524,7 @@ void ScDBFunc::DoSubTotals( const ScSubTotalParam& rParam, bool bRecord, if (bRecord) { pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoSubTotals( pDocSh, nTab, + o3tl::make_unique<ScUndoSubTotals>( pDocSh, nTab, rParam, aNewParam.nRow2, std::move(pUndoDoc), std::move(pUndoTab), // pUndoDBData, std::move(pUndoRange), std::move(pUndoDB) ) ); @@ -611,7 +611,7 @@ bool ScDBFunc::MakePivotTable( if (bUndo) { pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoInsertTab( pDocSh, nNewTab, bAppend, lcl_MakePivotTabName( aName, i ) )); + o3tl::make_unique<ScUndoInsertTab>( pDocSh, nNewTab, bAppend, lcl_MakePivotTabName( aName, i ) )); } GetViewData().InsertTab( nNewTab ); @@ -2231,7 +2231,7 @@ void ScDBFunc::RepeatDB( bool bRecord ) } GetViewData().GetDocShell()->GetUndoManager()->AddUndoAction( - new ScUndoRepeatDB( GetViewData().GetDocShell(), nTab, + o3tl::make_unique<ScUndoRepeatDB>( GetViewData().GetDocShell(), nTab, nStartCol, nStartRow, nEndCol, nEndRow, nNewEndRow, nCurX, nCurY, diff --git a/sc/source/ui/view/drawvie3.cxx b/sc/source/ui/view/drawvie3.cxx index f6538789b5d6..aeae719ae3c3 100644 --- a/sc/source/ui/view/drawvie3.cxx +++ b/sc/source/ui/view/drawvie3.cxx @@ -67,7 +67,7 @@ void ScDrawView::SetPageAnchored() for( size_t i=0; i<nCount; ++i ) { SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj(); - AddUndo (new ScUndoAnchorData( pObj, pDoc, nTab )); + AddUndo (o3tl::make_unique<ScUndoAnchorData>( pObj, pDoc, nTab )); ScDrawLayer::SetPageAnchored( *pObj ); } EndUndo(); @@ -95,7 +95,7 @@ void ScDrawView::SetCellAnchored(bool bResizeWithCell) for( size_t i=0; i<nCount; ++i ) { SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj(); - AddUndo (new ScUndoAnchorData( pObj, pDoc, nTab )); + AddUndo (o3tl::make_unique<ScUndoAnchorData>( pObj, pDoc, nTab )); ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *pDoc, nTab, bResizeWithCell); } EndUndo(); diff --git a/sc/source/ui/view/drawvie4.cxx b/sc/source/ui/view/drawvie4.cxx index f884429f6ad1..b3cb3e660f2a 100644 --- a/sc/source/ui/view/drawvie4.cxx +++ b/sc/source/ui/view/drawvie4.cxx @@ -444,7 +444,7 @@ void ScDrawView::CalcNormScale( Fraction& rFractX, Fraction& rFractY ) const void ScDrawView::SetMarkedOriginalSize() { - SdrUndoGroup* pUndoGroup = new SdrUndoGroup(*GetModel()); + std::unique_ptr<SdrUndoGroup> pUndoGroup(new SdrUndoGroup(*GetModel())); const SdrMarkList& rMarkList = GetMarkedObjectList(); long nDone = 0; @@ -529,11 +529,9 @@ void ScDrawView::SetMarkedOriginalSize() { pUndoGroup->SetComment(ScResId( STR_UNDO_ORIGINALSIZE )); ScDocShell* pDocSh = pViewData->GetDocShell(); - pDocSh->GetUndoManager()->AddUndoAction(pUndoGroup); + pDocSh->GetUndoManager()->AddUndoAction(std::move(pUndoGroup)); pDocSh->SetDrawModified(); } - else - delete pUndoGroup; } void ScDrawView::FitToCellSize() @@ -562,7 +560,7 @@ void ScDrawView::FitToCellSize() return; } - SdrUndoGroup* pUndoGroup = new SdrUndoGroup(*GetModel()); + std::unique_ptr<SdrUndoGroup> pUndoGroup(new SdrUndoGroup(*GetModel())); tools::Rectangle aGraphicRect = pObj->GetSnapRect(); tools::Rectangle aCellRect = ScDrawLayer::GetCellRect( *pDoc, pObjData->maStart, true); @@ -587,7 +585,7 @@ void ScDrawView::FitToCellSize() pUndoGroup->SetComment(ScResId( STR_UNDO_FITCELLSIZE )); ScDocShell* pDocSh = pViewData->GetDocShell(); - pDocSh->GetUndoManager()->AddUndoAction(pUndoGroup); + pDocSh->GetUndoManager()->AddUndoAction(std::move(pUndoGroup)); } diff --git a/sc/source/ui/view/drawview.cxx b/sc/source/ui/view/drawview.cxx index 670dba85023c..dc13c9192493 100644 --- a/sc/source/ui/view/drawview.cxx +++ b/sc/source/ui/view/drawview.cxx @@ -220,7 +220,7 @@ void ScDrawView::SetMarkedToLayer( SdrLayerID nLayerNo ) SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj(); if ( dynamic_cast<const SdrUnoObj*>( pObj) == nullptr && (pObj->GetLayer() != SC_LAYER_INTERN) ) { - AddUndo( new SdrUndoObjectLayerChange( *pObj, pObj->GetLayer(), nLayerNo) ); + AddUndo( o3tl::make_unique<SdrUndoObjectLayerChange>( *pObj, pObj->GetLayer(), nLayerNo) ); pObj->SetLayer( nLayerNo ); } } @@ -870,7 +870,7 @@ void ScDrawView::DeleteMarked() delete pNote; // add the undo action for the note if( bUndo ) - pUndoMgr->AddUndoAction( new ScUndoReplaceNote( *pDocShell, pCaptData->maStart, aNoteData, false, pDrawLayer->GetCalcUndo() ) ); + pUndoMgr->AddUndoAction( o3tl::make_unique<ScUndoReplaceNote>( *pDocShell, pCaptData->maStart, aNoteData, false, pDrawLayer->GetCalcUndo() ) ); // repaint the cell to get rid of the note marker if( pDocShell ) pDocShell->PostPaintCell( pCaptData->maStart ); @@ -988,7 +988,7 @@ SdrObject* ScDrawView::ApplyGraphicToObject( } else if(rHitObject.IsClosedObj() && !dynamic_cast< SdrOle2Obj* >(&rHitObject)) { - AddUndo(new SdrUndoAttrObj(rHitObject)); + AddUndo(o3tl::make_unique<SdrUndoAttrObj>(rHitObject)); SfxItemSet aSet(GetModel()->GetItemPool(), svl::Items<XATTR_FILLSTYLE, XATTR_FILLBITMAP>{}); diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx index 7c54228e83ef..cd52cbd4aaf9 100644 --- a/sc/source/ui/view/formatsh.cxx +++ b/sc/source/ui/view/formatsh.cxx @@ -701,7 +701,7 @@ void ScFormatShell::ExecuteStyle( SfxRequest& rReq ) nRetMask = sal_uInt16( nullptr != pStyleSheet ); if ( pStyleSheet && !pScMod->GetIsWaterCan() ) { - ScUndoApplyPageStyle* pUndoAction = nullptr; + std::unique_ptr<ScUndoApplyPageStyle> pUndoAction; SCTAB nTabCount = rDoc.GetTableCount(); ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end(); for (; itr != itrEnd && *itr < nTabCount; ++itr) @@ -712,13 +712,13 @@ void ScFormatShell::ExecuteStyle( SfxRequest& rReq ) rDoc.SetPageStyle( *itr, aStyleName ); ScPrintFunc( pDocSh, pTabViewShell->GetPrinter(true), *itr ).UpdatePages(); if( !pUndoAction ) - pUndoAction = new ScUndoApplyPageStyle( pDocSh, aStyleName ); + pUndoAction.reset(new ScUndoApplyPageStyle( pDocSh, aStyleName )); pUndoAction->AddSheetAction( *itr, aOldName ); } } if( pUndoAction ) { - pDocSh->GetUndoManager()->AddUndoAction( pUndoAction ); + pDocSh->GetUndoManager()->AddUndoAction( std::move(pUndoAction) ); pDocSh->SetDocumentModified(); rBindings.Invalidate( SID_STYLE_FAMILY4 ); rBindings.Invalidate( SID_STATUS_PAGESTYLE ); @@ -933,7 +933,7 @@ void ScFormatShell::ExecuteStyle( SfxRequest& rReq ) if ( bAddUndo && bUndo) pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoModifyStyle( pDocSh, eFamily, aOldData, aNewData ) ); + o3tl::make_unique<ScUndoModifyStyle>( pDocSh, eFamily, aOldData, aNewData ) ); if ( bStyleToMarked ) { diff --git a/sc/source/ui/view/preview.cxx b/sc/source/ui/view/preview.cxx index d5c3e6e7f3d8..304be3fc5f1f 100644 --- a/sc/source/ui/view/preview.cxx +++ b/sc/source/ui/view/preview.cxx @@ -1112,7 +1112,7 @@ void ScPreview::MouseButtonUp( const MouseEvent& rMEvt ) if( bUndo ) { pDocShell->GetUndoManager()->AddUndoAction( - new ScUndoModifyStyle( pDocShell, SfxStyleFamily::Page, + o3tl::make_unique<ScUndoModifyStyle>( pDocShell, SfxStyleFamily::Page, aOldData, aNewData ) ); } @@ -1214,7 +1214,7 @@ void ScPreview::MouseButtonUp( const MouseEvent& rMEvt ) if( bUndo ) { pDocShell->GetUndoManager()->AddUndoAction( - new ScUndoModifyStyle( pDocShell, SfxStyleFamily::Page, + o3tl::make_unique<ScUndoModifyStyle>( pDocShell, SfxStyleFamily::Page, aOldData, aNewData ) ); } diff --git a/sc/source/ui/view/spelldialog.cxx b/sc/source/ui/view/spelldialog.cxx index 0678f8aea6b1..4e8ca58965e9 100644 --- a/sc/source/ui/view/spelldialog.cxx +++ b/sc/source/ui/view/spelldialog.cxx @@ -124,7 +124,7 @@ void ScSpellDialogChildWindow::Reset() SCROW nOldRow = rCursor.Row(); SCCOL nNewCol = mpViewData->GetCurX(); SCROW nNewRow = mpViewData->GetCurY(); - mpDocShell->GetUndoManager()->AddUndoAction( new ScUndoConversion( + mpDocShell->GetUndoManager()->AddUndoAction( o3tl::make_unique<ScUndoConversion>( mpDocShell, mpViewData->GetMarkData(), nOldCol, nOldRow, nTab, std::move(mxUndoDoc), nNewCol, nNewRow, nTab, std::move(mxRedoDoc), diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index 38533736a681..a60715eba83f 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -912,7 +912,7 @@ void ScViewFunc::RemoveManualBreaks() pUndoDoc->InitUndo( &rDoc, nTab, nTab, true, true ); rDoc.CopyToDocument( 0,0,nTab, MAXCOL,MAXROW,nTab, InsertDeleteFlags::NONE, false, *pUndoDoc ); pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoRemoveBreaks( pDocSh, nTab, std::move(pUndoDoc) ) ); + o3tl::make_unique<ScUndoRemoveBreaks>( pDocSh, nTab, std::move(pUndoDoc) ) ); } rDoc.RemoveManualBreaks(nTab); @@ -1032,7 +1032,7 @@ void ScViewFunc::SetPrintRanges( bool bEntireSheet, const OUString* pPrint, SCTAB nCurTab = GetViewData().GetTabNo(); std::unique_ptr<ScPrintRangeSaver> pNewRanges = rDoc.CreatePrintRangeSaver(); pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoPrintRange( pDocSh, nCurTab, std::move(pOldRanges), std::move(pNewRanges) ) ); + o3tl::make_unique<ScUndoPrintRange>( pDocSh, nCurTab, std::move(pOldRanges), std::move(pNewRanges) ) ); } else pOldRanges.reset(); @@ -1589,7 +1589,7 @@ void ScViewFunc::FillTab( InsertDeleteFlags nFlags, ScPasteFunc nFunction, bool if (bUndo) { //! for ChangeTrack not until the end pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoFillTable( pDocSh, rMark, + o3tl::make_unique<ScUndoFillTable>( pDocSh, rMark, aMarkRange.aStart.Col(), aMarkRange.aStart.Row(), nTab, aMarkRange.aEnd.Col(), aMarkRange.aEnd.Row(), nTab, std::move(pUndoDoc), bMulti, nTab, nFlags, nFunction, bSkipEmpty, bAsLink ) ); @@ -1839,7 +1839,7 @@ bool ScViewFunc::SearchAndReplace( const SvxSearchItem* pSearchItem, if (bAddUndo) { GetViewData().GetDocShell()->GetUndoManager()->AddUndoAction( - new ScUndoReplace( GetViewData().GetDocShell(), *pUndoMark, + o3tl::make_unique<ScUndoReplace>( GetViewData().GetDocShell(), *pUndoMark, nCol, nRow, nTab, aUndoStr, std::move(pUndoDoc), pSearchItem ) ); } @@ -2216,7 +2216,7 @@ void ScViewFunc::InsertTables(std::vector<OUString>& aNames, SCTAB nTab, { if (bRecord) pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoInsertTables( pDocSh, nTab, aNames)); + o3tl::make_unique<ScUndoInsertTables>( pDocSh, nTab, aNames)); // Update views @@ -2244,7 +2244,7 @@ bool ScViewFunc::AppendTable( const OUString& rName, bool bRecord ) SCTAB nTab = rDoc.GetTableCount()-1; if (bRecord) pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoInsertTab( pDocSh, nTab, true, rName)); + o3tl::make_unique<ScUndoInsertTab>( pDocSh, nTab, true, rName)); GetViewData().InsertTab( nTab ); SetTabNo( nTab, true ); pDocSh->PostPaintExtras(); @@ -2410,7 +2410,7 @@ bool ScViewFunc::DeleteTables(const vector<SCTAB> &TheTabs, bool bRecord ) if (bRecord) { pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoDeleteTab( GetViewData().GetDocShell(), TheTabs, + o3tl::make_unique<ScUndoDeleteTab>( GetViewData().GetDocShell(), TheTabs, std::move(pUndoDoc), std::move(pUndoData) )); } @@ -2614,7 +2614,7 @@ void ScViewFunc::ImportTables( ScDocShell* pSrcShell, if (bUndo) { pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoImportTab( pDocSh, nTab, nCount ) ); + o3tl::make_unique<ScUndoImportTab>( pDocSh, nTab, nCount ) ); } for (i=0; i<nInsCount; i++) @@ -2775,7 +2775,7 @@ void ScViewFunc::MoveTable( { pDestDoc->GetName(nDestTab, sName); pDestShell->GetUndoManager()->AddUndoAction( - new ScUndoImportTab( pDestShell, nDestTab, + o3tl::make_unique<ScUndoImportTab>( pDestShell, nDestTab, static_cast<SCTAB>(TheTabs.size()))); } @@ -2965,13 +2965,13 @@ void ScViewFunc::MoveTable( if (bCopy) { pDocShell->GetUndoManager()->AddUndoAction( - new ScUndoCopyTab( + o3tl::make_unique<ScUndoCopyTab>( pDocShell, std::move(pSrcTabs), std::move(pDestTabs), std::move(pDestNames))); } else { pDocShell->GetUndoManager()->AddUndoAction( - new ScUndoMoveTab( + o3tl::make_unique<ScUndoMoveTab>( pDocShell, std::move(pSrcTabs), std::move(pDestTabs), std::move(pTabNames), std::move(pDestNames))); } } @@ -3020,7 +3020,7 @@ void ScViewFunc::ShowTable( const std::vector<OUString>& rNames ) { if (bUndo) { - pDocSh->GetUndoManager()->AddUndoAction( new ScUndoShowHideTab( pDocSh, undoTabs, true ) ); + pDocSh->GetUndoManager()->AddUndoAction( o3tl::make_unique<ScUndoShowHideTab>( pDocSh, undoTabs, true ) ); } pDocSh->PostPaint(0,0,0,MAXCOL,MAXROW,MAXTAB, PaintPartFlags::Extras); pDocSh->SetDocumentModified(); @@ -3065,7 +3065,7 @@ void ScViewFunc::HideTable( const ScMarkData& rMark ) } if (bUndo) { - pDocSh->GetUndoManager()->AddUndoAction( new ScUndoShowHideTab( pDocSh, undoTabs, false ) ); + pDocSh->GetUndoManager()->AddUndoAction( o3tl::make_unique<ScUndoShowHideTab>( pDocSh, undoTabs, false ) ); } // Update views diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx index e02a4d44a1d4..6565b0a7b042 100644 --- a/sc/source/ui/view/viewfun3.cxx +++ b/sc/source/ui/view/viewfun3.cxx @@ -139,7 +139,7 @@ void ScViewFunc::CutToClip() if ( bRecord ) // Draw-Undo now available pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoCut( pDocSh, aRange, aOldEnd, rMark, std::move(pUndoDoc) ) ); + o3tl::make_unique<ScUndoCut>( pDocSh, aRange, aOldEnd, rMark, std::move(pUndoDoc) ) ); aModificator.SetDocumentModified(); pDocSh->UpdateOle(&GetViewData()); @@ -1421,10 +1421,10 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc, // Merge the paste undo action into the insert action. // Use ScUndoWrapper so the ScUndoPaste pointer can be stored in the insert action. - pUndoMgr->AddUndoAction( new ScUndoWrapper( std::move(pUndo) ), true ); + pUndoMgr->AddUndoAction( o3tl::make_unique<ScUndoWrapper>( std::move(pUndo) ), true ); } else - pUndoMgr->AddUndoAction( pUndo.release() ); + pUndoMgr->AddUndoAction( std::move(pUndo) ); pUndoMgr->LeaveListAction(); } @@ -1614,9 +1614,9 @@ bool ScViewFunc::PasteMultiRangesFromClip( aMarkedRange, aMark, std::move(pUndoDoc), nullptr, nFlags|nUndoFlags, nullptr, false, &aOptions)); if (bInsertCells) - pUndoMgr->AddUndoAction(new ScUndoWrapper(std::move(pUndo)), true); + pUndoMgr->AddUndoAction(o3tl::make_unique<ScUndoWrapper>(std::move(pUndo)), true); else - pUndoMgr->AddUndoAction(pUndo.release()); + pUndoMgr->AddUndoAction(std::move(pUndo)); pUndoMgr->LeaveListAction(); } @@ -1775,10 +1775,10 @@ bool ScViewFunc::PasteFromClipToMultiRanges( aOptions.bAsLink = bAsLink; aOptions.eMoveMode = eMoveMode; - ScUndoPaste* pUndo = new ScUndoPaste( - pDocSh, aRanges, aMark, std::move(pUndoDoc), nullptr, nFlags|nUndoFlags, nullptr, false, &aOptions); - pUndoMgr->AddUndoAction(pUndo); + pUndoMgr->AddUndoAction( + o3tl::make_unique<ScUndoPaste>( + pDocSh, aRanges, aMark, std::move(pUndoDoc), nullptr, nFlags|nUndoFlags, nullptr, false, &aOptions)); pUndoMgr->LeaveListAction(); } @@ -1999,7 +1999,7 @@ void ScViewFunc::DataFormPutData( SCROW nCurrentRow , nUndoEndCol, nUndoEndRow, nEndTab, rMark, std::move(pUndoDoc), std::move(pRedoDoc), std::move(pUndoData) ) ); - pUndoMgr->AddUndoAction( new ScUndoWrapper( std::move(pUndo) ), true ); + pUndoMgr->AddUndoAction( o3tl::make_unique<ScUndoWrapper>( std::move(pUndo) ), true ); PaintPartFlags nPaint = PaintPartFlags::Grid; if (bColInfo) diff --git a/sc/source/ui/view/viewfun4.cxx b/sc/source/ui/view/viewfun4.cxx index daa553c1d204..25e8fb0b18cf 100644 --- a/sc/source/ui/view/viewfun4.cxx +++ b/sc/source/ui/view/viewfun4.cxx @@ -145,7 +145,7 @@ void ScViewFunc::PasteRTF( SCCOL nStartCol, SCROW nStartRow, ScMarkData aDestMark; aDestMark.SetMarkArea( aMarkRange ); pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoPaste( pDocSh, aMarkRange, aDestMark, + o3tl::make_unique<ScUndoPaste>( pDocSh, aMarkRange, aDestMark, std::move(pUndoDoc), std::move(pRedoDoc), InsertDeleteFlags::ALL, nullptr)); } } @@ -300,7 +300,7 @@ void ScViewFunc::DoRefConversion() pDoc->CopyToDocument( aCopyRange, InsertDeleteFlags::ALL, bMulti, *pRedoDoc, &rMark ); pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoRefConversion( pDocSh, + o3tl::make_unique<ScUndoRefConversion>( pDocSh, aMarkRange, rMark, std::move(pUndoDoc), std::move(pRedoDoc), bMulti) ); } @@ -430,7 +430,7 @@ void ScViewFunc::DoThesaurus() if (bRecord) { GetViewData().GetDocShell()->GetUndoManager()->AddUndoAction( - new ScUndoThesaurus( + o3tl::make_unique<ScUndoThesaurus>( GetViewData().GetDocShell(), nCol, nRow, nTab, aOldText, aNewText)); } } @@ -556,7 +556,7 @@ void ScViewFunc::DoSheetConversion( const ScConversionParam& rConvParam ) SCCOL nNewCol = rViewData.GetCurX(); SCROW nNewRow = rViewData.GetCurY(); rViewData.GetDocShell()->GetUndoManager()->AddUndoAction( - new ScUndoConversion( + o3tl::make_unique<ScUndoConversion>( pDocSh, rMark, nCol, nRow, nTab, std::move(pUndoDoc), nNewCol, nNewRow, nTab, std::move(pRedoDoc), rConvParam ) ); diff --git a/sc/source/ui/view/viewfun7.cxx b/sc/source/ui/view/viewfun7.cxx index 4258b3338bd7..512477711a28 100644 --- a/sc/source/ui/view/viewfun7.cxx +++ b/sc/source/ui/view/viewfun7.cxx @@ -167,7 +167,7 @@ void ScViewFunc::PasteDraw( const Point& rLogicPos, SdrModel* pModel, pNewObj->NbcMove(Size(nDiffX,nDiffY)); if (pDestPage) pDestPage->InsertObject( pNewObj ); - pScDrawView->AddUndo(new SdrUndoInsertObj( *pNewObj )); + pScDrawView->AddUndo(o3tl::make_unique<SdrUndoInsertObj>( *pNewObj )); if (ScDrawLayer::IsCellAnchored(*pNewObj)) ScDrawLayer::SetCellAnchoredFromPosition(*pNewObj, *GetViewData().GetDocument(), nTab, diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index 9361c9b5cc9e..b1171ef2573e 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -618,7 +618,7 @@ void ScViewFunc::EnterValue( SCCOL nCol, SCROW nRow, SCTAB nTab, const double& r if (bUndo) { pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoEnterValue(pDocSh, aPos, aUndoCell, rValue)); + o3tl::make_unique<ScUndoEnterValue>(pDocSh, aPos, aUndoCell, rValue)); } pDocSh->PostPaintCell( aPos ); @@ -725,7 +725,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab, if ( bRecord ) { // because of ChangeTrack current first pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoEnterData(pDocSh, ScAddress(nCol,nRow,nTab), aOldValues, aString, std::move(pUndoData))); + o3tl::make_unique<ScUndoEnterData>(pDocSh, ScAddress(nCol,nRow,nTab), aOldValues, aString, std::move(pUndoData))); } HideAllCursors(); @@ -1081,7 +1081,7 @@ void ScViewFunc::ApplyPatternLines( const ScPatternAttr& rAttr, const SvxBoxItem pDoc->CopyToDocument( aCopyRange, InsertDeleteFlags::ATTRIB, bCopyOnlyMarked, *pUndoDoc, &aFuncMark ); pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoSelectionAttr( + o3tl::make_unique<ScUndoSelectionAttr>( pDocSh, aFuncMark, aMarkRange.aStart.Col(), aMarkRange.aStart.Row(), aMarkRange.aStart.Tab(), aMarkRange.aEnd.Col(), aMarkRange.aEnd.Row(), aMarkRange.aEnd.Tab(), @@ -1193,7 +1193,7 @@ void ScViewFunc::ApplySelectionPattern( const ScPatternAttr& rAttr, bool bCursor pUndoAttr = new ScUndoSelectionAttr( pDocSh, aFuncMark, nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab, std::move(pUndoDoc), bMulti, &rAttr ); - pDocSh->GetUndoManager()->AddUndoAction(pUndoAttr); + pDocSh->GetUndoManager()->AddUndoAction(std::unique_ptr<ScUndoSelectionAttr>(pUndoAttr)); pEditDataArray = pUndoAttr->GetDataArray(); } @@ -1234,10 +1234,10 @@ void ScViewFunc::ApplySelectionPattern( const ScPatternAttr& rAttr, bool bCursor if (bRecord) { - ScUndoCursorAttr* pUndo = new ScUndoCursorAttr( - pDocSh, nCol, nRow, nTab, pOldPat.get(), pNewPat, &rAttr ); + std::unique_ptr<ScUndoCursorAttr> pUndo(new ScUndoCursorAttr( + pDocSh, nCol, nRow, nTab, pOldPat.get(), pNewPat, &rAttr )); pUndo->SetEditData(std::move(pOldEditData), std::move(pNewEditData)); - pDocSh->GetUndoManager()->AddUndoAction(pUndo); + pDocSh->GetUndoManager()->AddUndoAction(std::move(pUndo)); } pOldPat.reset(); // is copied in undo (Pool) @@ -1368,7 +1368,7 @@ void ScViewFunc::SetStyleSheetToMarked( const SfxStyleSheet* pStyleSheet ) OUString aName = pStyleSheet->GetName(); pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoSelectionStyle( pDocSh, aFuncMark, aMarkRange, aName, std::move(pUndoDoc) ) ); + o3tl::make_unique<ScUndoSelectionStyle>( pDocSh, aFuncMark, aMarkRange, aName, std::move(pUndoDoc) ) ); } rDoc.ApplySelectionStyle( static_cast<const ScStyleSheet&>(*pStyleSheet), aFuncMark ); @@ -1402,7 +1402,7 @@ void ScViewFunc::SetStyleSheetToMarked( const SfxStyleSheet* pStyleSheet ) OUString aName = pStyleSheet->GetName(); pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoSelectionStyle( pDocSh, aUndoMark, aMarkRange, aName, std::move(pUndoDoc) ) ); + o3tl::make_unique<ScUndoSelectionStyle>( pDocSh, aUndoMark, aMarkRange, aName, std::move(pUndoDoc) ) ); } ScMarkData::iterator itr = aFuncMark.begin(), itrEnd = aFuncMark.end(); @@ -1876,7 +1876,7 @@ void ScViewFunc::DeleteMulti( bool bRows ) if (bRecord) { pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoDeleteMulti( + o3tl::make_unique<ScUndoDeleteMulti>( pDocSh, bRows, bNeedRefresh, nTab, aSpans, std::move(pUndoDoc), std::move(pUndoData))); } @@ -2230,7 +2230,7 @@ void ScViewFunc::SetWidthOrHeight( if (bRecord) { pDocSh->GetUndoManager()->AddUndoAction( - new ScUndoWidthOrHeight( + o3tl::make_unique<ScUndoWidthOrHeight>( pDocSh, aMarkData, nStart, nCurTab, nEnd, nCurTab, std::move(pUndoDoc), aUndoRanges, std::move(pUndoTab), eMode, nSizeTwips, bWidth)); } diff --git a/sd/inc/Annotation.hxx b/sd/inc/Annotation.hxx index 68c343866913..2c83e8cb9135 100644 --- a/sd/inc/Annotation.hxx +++ b/sd/inc/Annotation.hxx @@ -37,7 +37,7 @@ enum class CommentNotificationType { Add, Modify, Remove }; void createAnnotation( css::uno::Reference< css::office::XAnnotation >& xAnnotation, SdPage* pPage ); -SdrUndoAction* CreateUndoInsertOrRemoveAnnotation( const css::uno::Reference< css::office::XAnnotation >& xAnnotation, bool bInsert ); +std::unique_ptr<SdrUndoAction> CreateUndoInsertOrRemoveAnnotation( const css::uno::Reference< css::office::XAnnotation >& xAnnotation, bool bInsert ); void CreateChangeUndo(const css::uno::Reference< css::office::XAnnotation >& xAnnotation); diff --git a/sd/inc/undo/undofactory.hxx b/sd/inc/undo/undofactory.hxx index 3995df536216..742d0b358e76 100644 --- a/sd/inc/undo/undofactory.hxx +++ b/sd/inc/undo/undofactory.hxx @@ -28,12 +28,12 @@ namespace sd class UndoFactory : public SdrUndoFactory { public: - virtual SdrUndoAction* CreateUndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect = false) override; - virtual SdrUndoAction* CreateUndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect = false) override; - virtual SdrUndoAction* CreateUndoObjectSetText( SdrObject& rNewObj, sal_Int32 nText ) override; - virtual SdrUndoAction* CreateUndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect = false ) override; - virtual SdrUndoAction* CreateUndoGeoObject( SdrObject& rObject ) override; - virtual SdrUndoAction* CreateUndoAttrObject( SdrObject& rObject, bool bStyleSheet1 = false, bool bSaveText = false ) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect = false) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect = false) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoObjectSetText( SdrObject& rNewObj, sal_Int32 nText ) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect = false ) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoGeoObject( SdrObject& rObject ) override; + virtual std::unique_ptr<SdrUndoAction> CreateUndoAttrObject( SdrObject& rObject, bool bStyleSheet1 = false, bool bSaveText = false ) override; }; } diff --git a/sd/inc/undo/undomanager.hxx b/sd/inc/undo/undomanager.hxx index 45fb8fd6a6ac..84a0e5394a4a 100644 --- a/sd/inc/undo/undomanager.hxx +++ b/sd/inc/undo/undomanager.hxx @@ -33,7 +33,7 @@ public: virtual void EnterListAction(const OUString &rComment, const OUString& rRepeatComment, sal_uInt16 nId, ViewShellId nViewShellId) override; - virtual void AddUndoAction( SfxUndoAction *pAction, bool bTryMerg=false ) override; + virtual void AddUndoAction( std::unique_ptr<SfxUndoAction> pAction, bool bTryMerg=false ) override; /** Set or reset the undo manager linked with the called undo manager. */ diff --git a/sd/source/core/annotations/Annotation.cxx b/sd/source/core/annotations/Annotation.cxx index e2190d35c3a3..6a80ef841429 100644 --- a/sd/source/core/annotations/Annotation.cxx +++ b/sd/source/core/annotations/Annotation.cxx @@ -351,7 +351,7 @@ void Annotation::createChangeUndo() { SdrModel* pModel = GetModel(); // TTTT should use reference if( pModel && pModel->IsUndoEnabled() ) - pModel->AddUndo( new UndoAnnotation( *this ) ); + pModel->AddUndo( o3tl::make_unique<UndoAnnotation>( *this ) ); if( pModel ) { @@ -374,12 +374,12 @@ Reference< XText > SAL_CALL Annotation::getTextRange() return Reference< XText >( m_TextRange.get() ); } -SdrUndoAction* CreateUndoInsertOrRemoveAnnotation( const Reference< XAnnotation >& xAnnotation, bool bInsert ) +std::unique_ptr<SdrUndoAction> CreateUndoInsertOrRemoveAnnotation( const Reference< XAnnotation >& xAnnotation, bool bInsert ) { Annotation* pAnnotation = dynamic_cast< Annotation* >( xAnnotation.get() ); if( pAnnotation ) { - return new UndoInsertOrRemoveAnnotation( *pAnnotation, bInsert ); + return o3tl::make_unique< UndoInsertOrRemoveAnnotation >( *pAnnotation, bInsert ); } else { diff --git a/sd/source/core/drawdoc3.cxx b/sd/source/core/drawdoc3.cxx index 97e8d0b6a533..298fc125f6f1 100644 --- a/sd/source/core/drawdoc3.cxx +++ b/sd/source/core/drawdoc3.cxx @@ -514,8 +514,7 @@ bool SdDrawDocument::InsertBookmarkAsPage( { if( pUndoMgr ) { - SdMoveStyleSheetsUndoAction* pMovStyles = new SdMoveStyleSheetsUndoAction(this, aCreatedStyles, true); - pUndoMgr->AddUndoAction(pMovStyles); + pUndoMgr->AddUndoAction(o3tl::make_unique<SdMoveStyleSheetsUndoAction>(this, aCreatedStyles, true)); } } } @@ -954,10 +953,10 @@ bool SdDrawDocument::InsertBookmarkAsPage( // styles, so it cannot be used after this point lcl_removeUnusedStyles(GetStyleSheetPool(), aNewGraphicStyles); if (!aNewGraphicStyles.empty() && pUndoMgr) - pUndoMgr->AddUndoAction(new SdMoveStyleSheetsUndoAction(this, aNewGraphicStyles, true)); + pUndoMgr->AddUndoAction(o3tl::make_unique<SdMoveStyleSheetsUndoAction>(this, aNewGraphicStyles, true)); lcl_removeUnusedStyles(GetStyleSheetPool(), aNewCellStyles); if (!aNewCellStyles.empty() && pUndoMgr) - pUndoMgr->AddUndoAction(new SdMoveStyleSheetsUndoAction(this, aNewCellStyles, true)); + pUndoMgr->AddUndoAction(o3tl::make_unique<SdMoveStyleSheetsUndoAction>(this, aNewCellStyles, true)); if( bUndo ) EndUndo(); @@ -1307,11 +1306,9 @@ void SdDrawDocument::RemoveUnnecessaryMasterPages(SdPage* pMasterPage, bool bOnl aUndoRemove.reserve(aRemove.size()); for (const auto& a : aRemove) aUndoRemove.emplace_back(a.get(), true); - // This list belongs to UndoAction - SdMoveStyleSheetsUndoAction* pMovStyles = new SdMoveStyleSheetsUndoAction(this, aUndoRemove, false); if (pUndoMgr) - pUndoMgr->AddUndoAction(pMovStyles); + pUndoMgr->AddUndoAction(o3tl::make_unique<SdMoveStyleSheetsUndoAction>(this, aUndoRemove, false)); } for( SdStyleSheetVector::iterator iter = aRemove.begin(); iter != aRemove.end(); ++iter ) @@ -1567,9 +1564,8 @@ void SdDrawDocument::SetMasterPage(sal_uInt16 nSdPageNum, if (bUndo) { - StyleSheetUndoAction* pUndoChStyle = new StyleSheetUndoAction(this, - pMySheet, &pHisSheet->GetItemSet()); - pUndoMgr->AddUndoAction(pUndoChStyle); + pUndoMgr->AddUndoAction(o3tl::make_unique<StyleSheetUndoAction>(this, + pMySheet, &pHisSheet->GetItemSet())); } pMySheet->GetItemSet().Put(pHisSheet->GetItemSet()); pMySheet->Broadcast(SfxHint(SfxHintId::DataChanged)); @@ -1643,8 +1639,7 @@ void SdDrawDocument::SetMasterPage(sal_uInt16 nSdPageNum, { // Add UndoAction for creating and inserting the stylesheets to // the top of the UndoManager - SdMoveStyleSheetsUndoAction* pMovStyles = new SdMoveStyleSheetsUndoAction( this, aCreatedStyles, true); - pUndoMgr->AddUndoAction(pMovStyles); + pUndoMgr->AddUndoAction(o3tl::make_unique<SdMoveStyleSheetsUndoAction>( this, aCreatedStyles, true)); } } @@ -1731,13 +1726,11 @@ void SdDrawDocument::SetMasterPage(sal_uInt16 nSdPageNum, if( bUndo ) { - SdPresentationLayoutUndoAction * pPLUndoAction = - new SdPresentationLayoutUndoAction + pUndoMgr->AddUndoAction(o3tl::make_unique<SdPresentationLayoutUndoAction> (this, pPage->IsMasterPage() ? aLayoutName : aOldLayoutName, aLayoutName, - eAutoLayout, eAutoLayout, false, *pIter); - pUndoMgr->AddUndoAction(pPLUndoAction); + eAutoLayout, eAutoLayout, false, *pIter)); } pPage->SetPresentationLayout(aLayoutName); pPage->SetAutoLayout(eAutoLayout); @@ -1799,8 +1792,7 @@ void SdDrawDocument::SetMasterPage(sal_uInt16 nSdPageNum, aUndoInsert.reserve(aCreatedStyles.size()); for (const auto& a : aCreatedStyles) aUndoInsert.emplace_back(a.get(), true); - SdMoveStyleSheetsUndoAction* pMovStyles = new SdMoveStyleSheetsUndoAction(this, aUndoInsert, true); - pUndoMgr->AddUndoAction(pMovStyles); + pUndoMgr->AddUndoAction(o3tl::make_unique<SdMoveStyleSheetsUndoAction>(this, aUndoInsert, true)); } // Generate new master pages and register them with the document @@ -1869,12 +1861,10 @@ void SdDrawDocument::SetMasterPage(sal_uInt16 nSdPageNum, if( bUndo ) { - SdPresentationLayoutUndoAction * pPLUndoAction = - new SdPresentationLayoutUndoAction + pUndoMgr->AddUndoAction(o3tl::make_unique<SdPresentationLayoutUndoAction> (this, aOldLayoutName, aName, eOldAutoLayout, eNewAutoLayout, true, - *pIter); - pUndoMgr->AddUndoAction(pPLUndoAction); + *pIter)); } (*pIter)->SetPresentationLayout(aName); diff --git a/sd/source/core/sdpage.cxx b/sd/source/core/sdpage.cxx index dc6c85dc20d8..7646a6063d8d 100644 --- a/sd/source/core/sdpage.cxx +++ b/sd/source/core/sdpage.cxx @@ -575,8 +575,8 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t if( bUndo ) { - pUndoManager->AddUndoAction( new UndoObjectPresentationKind( *pSdrObj ) ); - pUndoManager->AddUndoAction( new UndoObjectUserCall(*pSdrObj) ); + pUndoManager->AddUndoAction( o3tl::make_unique<UndoObjectPresentationKind>( *pSdrObj ) ); + pUndoManager->AddUndoAction( o3tl::make_unique<UndoObjectUserCall>(*pSdrObj) ); } InsertPresObj(pSdrObj, eObjKind); @@ -738,7 +738,7 @@ void SdPage::Changed(const SdrObject& rObj, SdrUserCallType eType, const ::tools const bool bUndo = pUndoManager && pUndoManager->IsInListAction() && IsInserted(); if( bUndo ) - pUndoManager->AddUndoAction( new UndoObjectUserCall(*pObj) ); + pUndoManager->AddUndoAction( o3tl::make_unique<UndoObjectUserCall>(*pObj) ); // Object was resized by user and does not listen to its slide anymore pObj->SetUserCall(nullptr); @@ -2228,7 +2228,7 @@ SdrObject* SdPage::InsertAutoLayoutShape(SdrObject* pObj, PresObjKind eObjKind, { pUndoManager->AddUndoAction( getSdrModelFromSdrPage().GetSdrUndoFactory().CreateUndoGeoObject( *pObj ) ); pUndoManager->AddUndoAction( getSdrModelFromSdrPage().GetSdrUndoFactory().CreateUndoAttrObject( *pObj, true, true ) ); - pUndoManager->AddUndoAction( new UndoObjectUserCall( *pObj ) ); + pUndoManager->AddUndoAction( o3tl::make_unique<UndoObjectUserCall>( *pObj ) ); } pObj->AdjustToMaxRect(rRect); @@ -2291,7 +2291,7 @@ SdrObject* SdPage::InsertAutoLayoutShape(SdrObject* pObj, PresObjKind eObjKind, if( !IsPresObj( pObj ) ) { if( bUndo ) - pUndoManager->AddUndoAction( new UndoObjectPresentationKind( *pObj ) ); + pUndoManager->AddUndoAction( o3tl::make_unique<UndoObjectPresentationKind>( *pObj ) ); InsertPresObj( pObj, eObjKind ); } diff --git a/sd/source/core/sdpage2.cxx b/sd/source/core/sdpage2.cxx index 15ba777f578c..93d56c50b36c 100644 --- a/sd/source/core/sdpage2.cxx +++ b/sd/source/core/sdpage2.cxx @@ -25,6 +25,7 @@ #include <editeng/outliner.hxx> #include <sfx2/linkmgr.hxx> #include <svx/svdotext.hxx> +#include <svx/svdundo.hxx> #include <editeng/outlobj.hxx> #include <svl/urihelper.hxx> #include <editeng/xmlcnitm.hxx> @@ -571,9 +572,9 @@ void SdPage::addAnnotation( const Reference< XAnnotation >& xAnnotation, int nIn if( getSdrModelFromSdrPage().IsUndoEnabled() ) { - SdrUndoAction* pAction = CreateUndoInsertOrRemoveAnnotation( xAnnotation, true ); + std::unique_ptr<SdrUndoAction> pAction = CreateUndoInsertOrRemoveAnnotation( xAnnotation, true ); if( pAction ) - getSdrModelFromSdrPage().AddUndo( pAction ); + getSdrModelFromSdrPage().AddUndo( std::move(pAction) ); } SetChanged(); @@ -588,9 +589,9 @@ void SdPage::removeAnnotation( const Reference< XAnnotation >& xAnnotation ) { if( getSdrModelFromSdrPage().IsUndoEnabled() ) { - SdrUndoAction* pAction = CreateUndoInsertOrRemoveAnnotation( xAnnotation, false ); + std::unique_ptr<SdrUndoAction> pAction = CreateUndoInsertOrRemoveAnnotation( xAnnotation, false ); if( pAction ) - getSdrModelFromSdrPage().AddUndo( pAction ); + getSdrModelFromSdrPage().AddUndo( std::move(pAction) ); } AnnotationVector::iterator iter = std::find( maAnnotations.begin(), maAnnotations.end(), xAnnotation ); diff --git a/sd/source/core/text/textapi.cxx b/sd/source/core/text/textapi.cxx index 584a84dd3207..75a106814378 100644 --- a/sd/source/core/text/textapi.cxx +++ b/sd/source/core/text/textapi.cxx @@ -160,7 +160,7 @@ void TextApiObject::SetText( OutlinerParaObject const & rText ) { SdrModel* pModel = mpSource->GetDoc(); if( pModel && pModel->IsUndoEnabled() ) - pModel->AddUndo( new UndoTextAPIChanged( *pModel, this ) ); + pModel->AddUndo( o3tl::make_unique<UndoTextAPIChanged>( *pModel, this ) ); mpSource->SetText( rText ); maSelection.nStartPara = EE_PARA_MAX_COUNT; diff --git a/sd/source/core/undo/undofactory.cxx b/sd/source/core/undo/undofactory.cxx index 27ae3fd68633..ecad2629fe64 100644 --- a/sd/source/core/undo/undofactory.cxx +++ b/sd/source/core/undo/undofactory.cxx @@ -19,37 +19,38 @@ #include <undo/undofactory.hxx> #include <undo/undoobjects.hxx> +#include <o3tl/make_unique.hxx> using namespace sd; -SdrUndoAction* UndoFactory::CreateUndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect ) +std::unique_ptr<SdrUndoAction> UndoFactory::CreateUndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect ) { - return new UndoRemoveObject( rObject, bOrdNumDirect ); + return o3tl::make_unique<UndoRemoveObject>( rObject, bOrdNumDirect ); } -SdrUndoAction* UndoFactory::CreateUndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect ) +std::unique_ptr<SdrUndoAction> UndoFactory::CreateUndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect ) { - return new UndoDeleteObject( rObject, bOrdNumDirect ); + return o3tl::make_unique<UndoDeleteObject>( rObject, bOrdNumDirect ); } -SdrUndoAction* UndoFactory::CreateUndoObjectSetText( SdrObject& rNewObj, sal_Int32 nText ) +std::unique_ptr<SdrUndoAction> UndoFactory::CreateUndoObjectSetText( SdrObject& rNewObj, sal_Int32 nText ) { - return new UndoObjectSetText( rNewObj, nText ); + return o3tl::make_unique<UndoObjectSetText>( rNewObj, nText ); } -SdrUndoAction* UndoFactory::CreateUndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect ) +std::unique_ptr<SdrUndoAction> UndoFactory::CreateUndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect ) { - return new UndoReplaceObject( rOldObject, rNewObject, bOrdNumDirect ); + return o3tl::make_unique<UndoReplaceObject>( rOldObject, rNewObject, bOrdNumDirect ); } -SdrUndoAction* UndoFactory::CreateUndoGeoObject( SdrObject& rObject ) +std::unique_ptr<SdrUndoAction> UndoFactory::CreateUndoGeoObject( SdrObject& rObject ) { - return new UndoGeoObject( rObject ); + return o3tl::make_unique<UndoGeoObject>( rObject ); } -SdrUndoAction* UndoFactory::CreateUndoAttrObject( SdrObject& rObject, bool bStyleSheet1, bool bSaveText ) +std::unique_ptr<SdrUndoAction> UndoFactory::CreateUndoAttrObject( SdrObject& rObject, bool bStyleSheet1, bool bSaveText ) { - return new UndoAttrObject( rObject, bStyleSheet1, bSaveText ); + return o3tl::make_unique<UndoAttrObject>( rObject, bStyleSheet1, bSaveText ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/core/undo/undomanager.cxx b/sd/source/core/undo/undomanager.cxx index 950747bc8d20..bf1e926a0f8b 100644 --- a/sd/source/core/undo/undomanager.cxx +++ b/sd/source/core/undo/undomanager.cxx @@ -36,16 +36,12 @@ void UndoManager::EnterListAction(const OUString &rComment, const OUString& rRep } } -void UndoManager::AddUndoAction( SfxUndoAction *pAction, bool bTryMerg /* = sal_False */ ) +void UndoManager::AddUndoAction( std::unique_ptr<SfxUndoAction> pAction, bool bTryMerg /* = sal_False */ ) { if( !IsDoing() ) { ClearLinkedRedoActions(); - SdrUndoManager::AddUndoAction( pAction, bTryMerg ); - } - else - { - delete pAction; + SdrUndoManager::AddUndoAction( std::move(pAction), bTryMerg ); } } diff --git a/sd/source/ui/animations/CustomAnimationPane.cxx b/sd/source/ui/animations/CustomAnimationPane.cxx index 418e006f3ff7..a1837725974c 100644 --- a/sd/source/ui/animations/CustomAnimationPane.cxx +++ b/sd/source/ui/animations/CustomAnimationPane.cxx @@ -296,7 +296,7 @@ void CustomAnimationPane::addUndo() { SdPage* pPage = SdPage::getImplementation( mxCurrentPage ); if( pPage ) - pManager->AddUndoAction( new UndoAnimation( mrBase.GetDocShell()->GetDoc(), pPage ) ); + pManager->AddUndoAction( o3tl::make_unique<UndoAnimation>( mrBase.GetDocShell()->GetDoc(), pPage ) ); } } @@ -2527,7 +2527,7 @@ void CustomAnimationPane::updatePathFromMotionPathTag( const rtl::Reference< Mot { SdPage* pPage = SdPage::getImplementation( mxCurrentPage ); if( pPage ) - pManager->AddUndoAction( new UndoAnimationPath( mrBase.GetDocShell()->GetDoc(), pPage, pEffect->getNode() ) ); + pManager->AddUndoAction( o3tl::make_unique<UndoAnimationPath>( mrBase.GetDocShell()->GetDoc(), pPage, pEffect->getNode() ) ); } pEffect->updatePathFromSdrPathObj( *pPathObj ); diff --git a/sd/source/ui/animations/SlideTransitionPane.cxx b/sd/source/ui/animations/SlideTransitionPane.cxx index a1be17fa8449..58e6781dd5b1 100644 --- a/sd/source/ui/animations/SlideTransitionPane.cxx +++ b/sd/source/ui/animations/SlideTransitionPane.cxx @@ -250,7 +250,7 @@ void lcl_CreateUndoForPages( OUString aComment( SdResId(STR_UNDO_SLIDE_PARAMS) ); pManager->EnterListAction(aComment, aComment, 0, rBase.GetViewShellId()); - SdUndoGroup* pUndoGroup = new SdUndoGroup( pDoc ); + std::unique_ptr<SdUndoGroup> pUndoGroup(new SdUndoGroup( pDoc )); pUndoGroup->SetComment( aComment ); ::std::vector< SdPage * >::const_iterator aIt( rpPages->begin()); @@ -260,7 +260,7 @@ void lcl_CreateUndoForPages( pUndoGroup->AddAction( new sd::UndoTransition( pDoc, (*aIt) ) ); } - pManager->AddUndoAction( pUndoGroup ); + pManager->AddUndoAction( std::move(pUndoGroup) ); pManager->LeaveListAction(); } diff --git a/sd/source/ui/dlg/LayerTabBar.cxx b/sd/source/ui/dlg/LayerTabBar.cxx index fdd45ddcee68..a7f38302e4ab 100644 --- a/sd/source/ui/dlg/LayerTabBar.cxx +++ b/sd/source/ui/dlg/LayerTabBar.cxx @@ -215,7 +215,7 @@ void LayerTabBar::MouseButtonDown(const MouseEvent& rMEvt) if(pDrView) { SfxUndoManager* pManager = rDoc.GetDocSh()->GetUndoManager(); - SdLayerModifyUndoAction* pAction = new SdLayerModifyUndoAction( + std::unique_ptr<SdLayerModifyUndoAction> pAction(new SdLayerModifyUndoAction( &rDoc, pLayer, aName, @@ -230,8 +230,8 @@ void LayerTabBar::MouseButtonDown(const MouseEvent& rMEvt) bNewVisible, bNewLocked, bNewPrintable - ); - pManager->AddUndoAction(pAction); + )); + pManager->AddUndoAction(std::move(pAction)); } } @@ -383,7 +383,7 @@ void LayerTabBar::EndRenaming() if( pDrView ) { SfxUndoManager* pManager = rDoc.GetDocSh()->GetUndoManager(); - SdLayerModifyUndoAction* pAction = new SdLayerModifyUndoAction( + std::unique_ptr<SdLayerModifyUndoAction> pAction(new SdLayerModifyUndoAction( &rDoc, pLayer, aLayerName, @@ -398,8 +398,8 @@ void LayerTabBar::EndRenaming() pDrView->IsLayerVisible(aLayerName), pDrView->IsLayerLocked(aLayerName), pDrView->IsLayerPrintable(aLayerName) - ); - pManager->AddUndoAction( pAction ); + )); + pManager->AddUndoAction( std::move(pAction) ); } // First notify View since SetName() calls ResetActualLayer() and diff --git a/sd/source/ui/dlg/headerfooterdlg.cxx b/sd/source/ui/dlg/headerfooterdlg.cxx index 3fa82c9f2f9e..1be962aa96e4 100644 --- a/sd/source/ui/dlg/headerfooterdlg.cxx +++ b/sd/source/ui/dlg/headerfooterdlg.cxx @@ -303,7 +303,7 @@ void HeaderFooterDialog::Apply() void HeaderFooterDialog::apply( bool bToAll, bool bForceSlides ) { - SdUndoGroup* pUndoGroup = new SdUndoGroup(mpDoc); + std::unique_ptr<SdUndoGroup> pUndoGroup(new SdUndoGroup(mpDoc)); OUString aComment( GetText() ); pUndoGroup->SetComment( aComment ); @@ -326,7 +326,7 @@ void HeaderFooterDialog::apply( bool bToAll, bool bForceSlides ) for( nPage = 0; nPage < nPageCount; nPage++ ) { SdPage* pPage = mpDoc->GetSdPage( static_cast<sal_uInt16>(nPage), PageKind::Standard ); - change( pUndoGroup, pPage, aNewSettings ); + change( pUndoGroup.get(), pPage, aNewSettings ); } } else @@ -335,7 +335,7 @@ void HeaderFooterDialog::apply( bool bToAll, bool bForceSlides ) DBG_ASSERT( mpCurrentPage && mpCurrentPage->GetPageKind() == PageKind::Standard, "no current page to apply to!" ); if( mpCurrentPage && (mpCurrentPage->GetPageKind() == PageKind::Standard) ) { - change( pUndoGroup, mpCurrentPage, aNewSettings ); + change( pUndoGroup.get(), mpCurrentPage, aNewSettings ); } } } @@ -350,7 +350,7 @@ void HeaderFooterDialog::apply( bool bToAll, bool bForceSlides ) aTempSettings.mbSlideNumberVisible = false; aTempSettings.mbDateTimeVisible = false; - change( pUndoGroup, mpDoc->GetSdPage( 0, PageKind::Standard ), aTempSettings ); + change( pUndoGroup.get(), mpDoc->GetSdPage( 0, PageKind::Standard ), aTempSettings ); } // now notes settings @@ -368,15 +368,15 @@ void HeaderFooterDialog::apply( bool bToAll, bool bForceSlides ) { SdPage* pPage = mpDoc->GetSdPage( static_cast<sal_uInt16>(nPage), PageKind::Notes ); - change( pUndoGroup, pPage, aNewSettings ); + change( pUndoGroup.get(), pPage, aNewSettings ); } // and last but not least to the handout page - change( pUndoGroup, mpDoc->GetMasterSdPage( 0, PageKind::Handout ), aNewSettings ); + change( pUndoGroup.get(), mpDoc->GetMasterSdPage( 0, PageKind::Handout ), aNewSettings ); } // give the undo group to the undo manager - mpViewShell->GetViewFrame()->GetObjectShell()->GetUndoManager()->AddUndoAction(pUndoGroup); + mpViewShell->GetViewFrame()->GetObjectShell()->GetUndoManager()->AddUndoAction(std::move(pUndoGroup)); } void HeaderFooterDialog::change( SdUndoGroup* pUndoGroup, SdPage* pPage, const HeaderFooterSettings& rNewSettings ) diff --git a/sd/source/ui/func/fuoaprms.cxx b/sd/source/ui/func/fuoaprms.cxx index 07888644c720..a525c837b156 100644 --- a/sd/source/ui/func/fuoaprms.cxx +++ b/sd/source/ui/func/fuoaprms.cxx @@ -620,7 +620,7 @@ void FuObjectAnimationParameters::DoExecute( SfxRequest& rReq ) pUndoMgr->EnterListAction(aComment, aComment, 0, mpViewShell->GetViewShellBase().GetViewShellId()); // create undo group - SdUndoGroup* pUndoGroup = new SdUndoGroup(mpDoc); + std::unique_ptr<SdUndoGroup> pUndoGroup(new SdUndoGroup(mpDoc)); pUndoGroup->SetComment(aComment); // for the path effect, remember some stuff @@ -789,7 +789,7 @@ void FuObjectAnimationParameters::DoExecute( SfxRequest& rReq ) } } // Set the Undo Group in of the Undo Manager - pUndoMgr->AddUndoAction(pUndoGroup); + pUndoMgr->AddUndoAction(std::move(pUndoGroup)); pUndoMgr->LeaveListAction(); // Model changed diff --git a/sd/source/ui/func/fupage.cxx b/sd/source/ui/func/fupage.cxx index a514f84be3cd..8c9c47f5aff3 100644 --- a/sd/source/ui/func/fupage.cxx +++ b/sd/source/ui/func/fupage.cxx @@ -387,8 +387,8 @@ const SfxItemSet* FuPage::ExecuteDialog(weld::Window* pParent) if( mbMasterPage ) { - StyleSheetUndoAction* pAction = new StyleSheetUndoAction(mpDoc, static_cast<SfxStyleSheet*>(pStyleSheet), &(*pTempSet.get())); - mpDocSh->GetUndoManager()->AddUndoAction(pAction); + mpDocSh->GetUndoManager()->AddUndoAction( + o3tl::make_unique<StyleSheetUndoAction>(mpDoc, static_cast<SfxStyleSheet*>(pStyleSheet), &(*pTempSet.get()))); pStyleSheet->GetItemSet().Put( *(pTempSet.get()) ); sdr::properties::CleanupFillProperties( pStyleSheet->GetItemSet() ); pStyleSheet->Broadcast(SfxHint(SfxHintId::DataChanged)); @@ -552,7 +552,7 @@ void FuPage::ApplyItemSet( const SfxItemSet* pArgs ) if( mpBackgroundObjUndoAction ) { // set merge flag, because a SdUndoGroupAction could have been inserted before - mpDocSh->GetUndoManager()->AddUndoAction( mpBackgroundObjUndoAction.release(), true ); + mpDocSh->GetUndoManager()->AddUndoAction( std::move(mpBackgroundObjUndoAction), true ); } // Objects can not be bigger than ViewSize diff --git a/sd/source/ui/func/fuprobjs.cxx b/sd/source/ui/func/fuprobjs.cxx index e66471390533..018d0e0bb559 100644 --- a/sd/source/ui/func/fuprobjs.cxx +++ b/sd/source/ui/func/fuprobjs.cxx @@ -142,9 +142,8 @@ void FuPresentationObjects::DoExecute( SfxRequest& ) { const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); // Undo-Action - StyleSheetUndoAction* pAction = new StyleSheetUndoAction - (mpDoc, static_cast<SfxStyleSheet*>(pStyleSheet), pOutSet); - mpDocSh->GetUndoManager()->AddUndoAction(pAction); + mpDocSh->GetUndoManager()->AddUndoAction( + o3tl::make_unique<StyleSheetUndoAction>(mpDoc, static_cast<SfxStyleSheet*>(pStyleSheet), pOutSet)); pStyleSheet->GetItemSet().Put( *pOutSet ); static_cast<SfxStyleSheet*>( pStyleSheet )->Broadcast( SfxHint( SfxHintId::DataChanged ) ); diff --git a/sd/source/ui/func/fusel.cxx b/sd/source/ui/func/fusel.cxx index c934d50c3b6f..02cc7b941b7f 100644 --- a/sd/source/ui/func/fusel.cxx +++ b/sd/source/ui/func/fusel.cxx @@ -792,10 +792,10 @@ bool FuSelection::MouseButtonUp(const MouseEvent& rMEvt) { // Added UNDOs for the WaterCan mode. This was never done in // the past, thus it was missing all the time. - SdrUndoAction* pUndoAttr = mpDoc->GetSdrUndoFactory().CreateUndoAttrObject(*pWaterCanCandidate, true, true); + std::unique_ptr<SdrUndoAction> pUndoAttr = mpDoc->GetSdrUndoFactory().CreateUndoAttrObject(*pWaterCanCandidate, true, true); mpView->BegUndo(pUndoAttr->GetComment()); mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoGeoObject(*pWaterCanCandidate)); - mpView->AddUndo(pUndoAttr); + mpView->AddUndo(std::move(pUndoAttr)); pWaterCanCandidate->SetStyleSheet (pStyleSheet, false); diff --git a/sd/source/ui/sidebar/DocumentHelper.cxx b/sd/source/ui/sidebar/DocumentHelper.cxx index c9fd9cbba780..f48065ca6923 100644 --- a/sd/source/ui/sidebar/DocumentHelper.cxx +++ b/sd/source/ui/sidebar/DocumentHelper.cxx @@ -272,12 +272,11 @@ void DocumentHelper::ProvideStyles ( SfxUndoManager* pUndoManager = rTargetDocument.GetDocSh()->GetUndoManager(); if (pUndoManager != nullptr) { - SdMoveStyleSheetsUndoAction* pMovStyles = - new SdMoveStyleSheetsUndoAction ( + pUndoManager->AddUndoAction ( + o3tl::make_unique<SdMoveStyleSheetsUndoAction>( &rTargetDocument, aCreatedStyles, - true); - pUndoManager->AddUndoAction (pMovStyles); + true)); } } } @@ -408,9 +407,9 @@ void DocumentHelper::AssignMasterPageToPage ( // not override the new master page) and assign the master page to // the regular slide. rDocument.GetDocSh()->GetUndoManager()->AddUndoAction( - new SdBackgroundObjUndoAction( + o3tl::make_unique<SdBackgroundObjUndoAction>( rDocument, *pPage, pPage->getSdrPageProperties().GetItemSet()), - true); + true); pPage->getSdrPageProperties().PutItem(XFillStyleItem(drawing::FillStyle_NONE)); rDocument.SetMasterPage ( diff --git a/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx b/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx index 11b222d0a0d1..0ff831453faf 100644 --- a/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx +++ b/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx @@ -946,11 +946,11 @@ bool SlotManager::RenameSlideFromDrawViewShell( sal_uInt16 nPageId, const OUStri SdrLayerIDSet aVisibleLayers = pPageToRename->TRG_GetMasterPageVisibleLayers(); // (#67720#) - ModifyPageUndoAction* pAction = new ModifyPageUndoAction( - pDocument, pUndoPage, rName, pUndoPage->GetAutoLayout(), - aVisibleLayers.IsSet( nBackground ), - aVisibleLayers.IsSet( nBgObj )); - pManager->AddUndoAction( pAction ); + pManager->AddUndoAction( + o3tl::make_unique<ModifyPageUndoAction>( + pDocument, pUndoPage, rName, pUndoPage->GetAutoLayout(), + aVisibleLayers.IsSet( nBackground ), + aVisibleLayers.IsSet( nBgObj ))); // rename pPageToRename->SetName( rName ); @@ -968,7 +968,7 @@ bool SlotManager::RenameSlideFromDrawViewShell( sal_uInt16 nPageId, const OUStri if (pPageToRename != nullptr) { const OUString aOldLayoutName( pPageToRename->GetLayoutName() ); - pManager->AddUndoAction( new RenameLayoutTemplateUndoAction( pDocument, aOldLayoutName, rName ) ); + pManager->AddUndoAction( o3tl::make_unique<RenameLayoutTemplateUndoAction>( pDocument, aOldLayoutName, rName ) ); pDocument->RenameLayoutTemplate( aOldLayoutName, rName ); } } diff --git a/sd/source/ui/view/ViewShellImplementation.cxx b/sd/source/ui/view/ViewShellImplementation.cxx index df2fbaeaeda8..110e752b389b 100644 --- a/sd/source/ui/view/ViewShellImplementation.cxx +++ b/sd/source/ui/view/ViewShellImplementation.cxx @@ -170,9 +170,9 @@ void ViewShell::Implementation::ProcessModifyPageSlot ( { OUString aComment( SdResId(STR_UNDO_MODIFY_PAGE) ); pUndoManager->EnterListAction(aComment, aComment, 0, mrViewShell.GetViewShellBase().GetViewShellId()); - ModifyPageUndoAction* pAction = new ModifyPageUndoAction( - pDocument, pUndoPage, aNewName, aNewAutoLayout, bBVisible, bBObjsVisible); - pUndoManager->AddUndoAction(pAction); + pUndoManager->AddUndoAction( + o3tl::make_unique<ModifyPageUndoAction>( + pDocument, pUndoPage, aNewName, aNewAutoLayout, bBVisible, bBObjsVisible)); // Clear the selection because the selected object may be removed as // a result of the assignment of the layout. @@ -216,7 +216,7 @@ void ViewShell::Implementation::ProcessModifyPageSlot ( bSetModified = static_cast<const SfxBoolItem&>(pArgs->Get(SID_MODIFYPAGE)).GetValue(); } - pUndoManager->AddUndoAction( new UndoAutoLayoutPosAndSize( *pUndoPage ) ); + pUndoManager->AddUndoAction( o3tl::make_unique<UndoAutoLayoutPosAndSize>( *pUndoPage ) ); pUndoManager->LeaveListAction(); pDocument->SetChanged(bSetModified); diff --git a/sd/source/ui/view/drawview.cxx b/sd/source/ui/view/drawview.cxx index 49618a222d7a..f93c67a2fb97 100644 --- a/sd/source/ui/view/drawview.cxx +++ b/sd/source/ui/view/drawview.cxx @@ -167,8 +167,8 @@ bool DrawView::SetAttributes(const SfxItemSet& rSet, aTempSet.ClearInvalidItems(); // Undo-Action - StyleSheetUndoAction* pAction = new StyleSheetUndoAction(&mrDoc, pSheet, &aTempSet); - mpDocSh->GetUndoManager()->AddUndoAction(pAction); + mpDocSh->GetUndoManager()->AddUndoAction( + o3tl::make_unique<StyleSheetUndoAction>(&mrDoc, pSheet, &aTempSet)); pSheet->GetItemSet().Put(aTempSet); pSheet->Broadcast(SfxHint(SfxHintId::DataChanged)); @@ -218,8 +218,8 @@ bool DrawView::SetAttributes(const SfxItemSet& rSet, } // Undo-Action - StyleSheetUndoAction* pAction = new StyleSheetUndoAction(&mrDoc, pSheet, &aTempSet); - mpDocSh->GetUndoManager()->AddUndoAction(pAction); + mpDocSh->GetUndoManager()->AddUndoAction( + o3tl::make_unique<StyleSheetUndoAction>(&mrDoc, pSheet, &aTempSet)); pSheet->GetItemSet().Put(aTempSet); pSheet->Broadcast(SfxHint(SfxHintId::DataChanged)); @@ -294,8 +294,8 @@ bool DrawView::SetAttributes(const SfxItemSet& rSet, aTempSet.ClearInvalidItems(); // Undo-Action - StyleSheetUndoAction* pAction = new StyleSheetUndoAction(&mrDoc, pSheet, &aTempSet); - mpDocSh->GetUndoManager()->AddUndoAction(pAction); + mpDocSh->GetUndoManager()->AddUndoAction( + o3tl::make_unique<StyleSheetUndoAction>(&mrDoc, pSheet, &aTempSet)); pSheet->GetItemSet().Put(aTempSet,false); pSheet->Broadcast(SfxHint(SfxHintId::DataChanged)); @@ -337,8 +337,8 @@ bool DrawView::SetAttributes(const SfxItemSet& rSet, aTempSet.ClearInvalidItems(); // Undo-Action - StyleSheetUndoAction* pAction = new StyleSheetUndoAction(&mrDoc, pSheet, &aTempSet); - mpDocSh->GetUndoManager()->AddUndoAction(pAction); + mpDocSh->GetUndoManager()->AddUndoAction( + o3tl::make_unique<StyleSheetUndoAction>(&mrDoc, pSheet, &aTempSet)); pSheet->GetItemSet().Set(aTempSet,false); pSheet->Broadcast(SfxHint(SfxHintId::DataChanged)); diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx index 7ccdb99ea046..a18a6049059d 100644 --- a/sd/source/ui/view/drviews2.cxx +++ b/sd/source/ui/view/drviews2.cxx @@ -2022,7 +2022,7 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq) } SfxUndoManager* pManager = GetDoc()->GetDocSh()->GetUndoManager(); - SdLayerModifyUndoAction* pAction = new SdLayerModifyUndoAction( + std::unique_ptr<SdLayerModifyUndoAction> pAction( new SdLayerModifyUndoAction( GetDoc(), pLayer, // old values @@ -2039,8 +2039,8 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq) bIsVisible, bIsLocked, bIsPrintable - ); - pManager->AddUndoAction( pAction ); + ) ); + pManager->AddUndoAction( std::move(pAction) ); ModifyLayer( pLayer, aLayerName, aLayerTitle, aLayerDesc, bIsVisible, bIsLocked, bIsPrintable ); diff --git a/sd/source/ui/view/drviews3.cxx b/sd/source/ui/view/drviews3.cxx index de0d97335ec0..b2ab0cbbb573 100644 --- a/sd/source/ui/view/drviews3.cxx +++ b/sd/source/ui/view/drviews3.cxx @@ -494,7 +494,7 @@ void DrawViewShell::ExecRuler(SfxRequest& rReq) case SID_ATTR_LONG_LRSPACE: if (pArgs) { - SdUndoGroup* pUndoGroup = new SdUndoGroup(GetDoc()); + std::unique_ptr<SdUndoGroup> pUndoGroup(new SdUndoGroup(GetDoc())); pUndoGroup->SetComment(SdResId(STR_UNDO_CHANGE_PAGEBORDER)); const SvxLongLRSpaceItem& rLRSpace = static_cast<const SvxLongLRSpaceItem&>( @@ -553,13 +553,13 @@ void DrawViewShell::ExecRuler(SfxRequest& rReq) // give the undo group to the undo manager GetViewFrame()->GetObjectShell()->GetUndoManager()-> - AddUndoAction(pUndoGroup); + AddUndoAction(std::move(pUndoGroup)); } break; case SID_ATTR_LONG_ULSPACE: if (pArgs) { - SdUndoGroup* pUndoGroup = new SdUndoGroup(GetDoc()); + std::unique_ptr<SdUndoGroup> pUndoGroup(new SdUndoGroup(GetDoc())); pUndoGroup->SetComment(SdResId(STR_UNDO_CHANGE_PAGEBORDER)); const SvxLongULSpaceItem& rULSpace = static_cast<const SvxLongULSpaceItem&>( @@ -619,7 +619,7 @@ void DrawViewShell::ExecRuler(SfxRequest& rReq) // give the undo group to the undo manager GetViewFrame()->GetObjectShell()->GetUndoManager()-> - AddUndoAction(pUndoGroup); + AddUndoAction(std::move(pUndoGroup)); } break; case SID_RULER_OBJECT: diff --git a/sd/source/ui/view/drviewsb.cxx b/sd/source/ui/view/drviewsb.cxx index 540cc6e006fb..3c628a7eaa2a 100644 --- a/sd/source/ui/view/drviewsb.cxx +++ b/sd/source/ui/view/drviewsb.cxx @@ -83,11 +83,11 @@ bool DrawViewShell::RenameSlide( sal_uInt16 nPageId, const OUString & rName ) SdrLayerIDSet aVisibleLayers = mpActualPage->TRG_GetMasterPageVisibleLayers(); SfxUndoManager* pManager = GetDoc()->GetDocSh()->GetUndoManager(); - ModifyPageUndoAction* pAction = new ModifyPageUndoAction( - GetDoc(), pUndoPage, rName, pUndoPage->GetAutoLayout(), - aVisibleLayers.IsSet( nBackground ), - aVisibleLayers.IsSet( nBgObj )); - pManager->AddUndoAction( pAction ); + pManager->AddUndoAction( + o3tl::make_unique<ModifyPageUndoAction>( + GetDoc(), pUndoPage, rName, pUndoPage->GetAutoLayout(), + aVisibleLayers.IsSet( nBackground ), + aVisibleLayers.IsSet( nBgObj ))); // rename pPageToRename->SetName( rName ); diff --git a/sd/source/ui/view/drviewse.cxx b/sd/source/ui/view/drviewse.cxx index ca96961b0fcb..91a10f0aa275 100644 --- a/sd/source/ui/view/drviewse.cxx +++ b/sd/source/ui/view/drviewse.cxx @@ -783,7 +783,7 @@ void DrawViewShell::FuSupport(SfxRequest& rReq) mpDrawView->UnmarkAllPoints(); if( bUndo ) - mpDrawView->AddUndo(new SdrUndoGeoObj(*pPathObj)); + mpDrawView->AddUndo(o3tl::make_unique<SdrUndoGeoObj>(*pPathObj)); pPathObj->ToggleClosed(); diff --git a/sd/source/ui/view/sdview.cxx b/sd/source/ui/view/sdview.cxx index bd5411a88157..258d5d6d05ee 100644 --- a/sd/source/ui/view/sdview.cxx +++ b/sd/source/ui/view/sdview.cxx @@ -843,7 +843,7 @@ bool View::RestoreDefaultText( SdrTextObj* pTextObj ) */ void View::SetMarkedOriginalSize() { - SdrUndoGroup* pUndoGroup = new SdrUndoGroup(mrDoc); + std::unique_ptr<SdrUndoGroup> pUndoGroup(new SdrUndoGroup(mrDoc)); const size_t nCount = GetMarkedObjectCount(); bool bOK = false; @@ -886,7 +886,7 @@ void View::SetMarkedOriginalSize() { ::tools::Rectangle aDrawRect( pObj->GetLogicRect() ); - pUndoGroup->AddAction( std::unique_ptr<SdrUndoAction>(mrDoc.GetSdrUndoFactory().CreateUndoGeoObject( *pObj )) ); + pUndoGroup->AddAction( mrDoc.GetSdrUndoFactory().CreateUndoGeoObject( *pObj ) ); pObj->Resize( aDrawRect.TopLeft(), Fraction( aOleSize.Width(), aDrawRect.GetWidth() ), Fraction( aOleSize.Height(), aDrawRect.GetHeight() ) ); } @@ -896,7 +896,7 @@ void View::SetMarkedOriginalSize() { const SdrGrafObj* pSdrGrafObj = static_cast< const SdrGrafObj* >(pObj); const Size aSize = pSdrGrafObj->getOriginalSize( ); - pUndoGroup->AddAction( std::unique_ptr<SdrUndoAction>(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj )) ); + pUndoGroup->AddAction( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj ) ); ::tools::Rectangle aRect( pObj->GetLogicRect() ); aRect.SetSize( aSize ); pObj->SetLogicRect( aRect ); @@ -908,10 +908,8 @@ void View::SetMarkedOriginalSize() if( bOK ) { pUndoGroup->SetComment(SdResId(STR_UNDO_ORIGINALSIZE)); - mpDocSh->GetUndoManager()->AddUndoAction(pUndoGroup); + mpDocSh->GetUndoManager()->AddUndoAction(std::move(pUndoGroup)); } - else - delete pUndoGroup; } /** @@ -1292,7 +1290,7 @@ void View::ChangeMarkedObjectsBulletsNumbering( return; const bool bUndoEnabled = pSdrModel->IsUndoEnabled(); - SdrUndoGroup* pUndoGroup = bUndoEnabled ? new SdrUndoGroup(*pSdrModel) : nullptr; + std::unique_ptr<SdrUndoGroup> pUndoGroup(bUndoEnabled ? new SdrUndoGroup(*pSdrModel) : nullptr); const bool bToggleOn = ShouldToggleOn( bToggle, bHandleBullets ); @@ -1334,7 +1332,7 @@ void View::ChangeMarkedObjectsBulletsNumbering( pOutliner->SetText(*(pText->GetOutlinerParaObject())); if (bUndoEnabled) { - pUndoGroup->AddAction(std::unique_ptr<SdrUndoAction>(pSdrModel->GetSdrUndoFactory().CreateUndoObjectSetText(*pTextObj, nCellIndex))); + pUndoGroup->AddAction(pSdrModel->GetSdrUndoFactory().CreateUndoObjectSetText(*pTextObj, nCellIndex)); } if ( !bToggleOn ) { @@ -1365,7 +1363,7 @@ void View::ChangeMarkedObjectsBulletsNumbering( if (bUndoEnabled) { pUndoGroup->AddAction( - std::unique_ptr<SdrUndoAction>(pSdrModel->GetSdrUndoFactory().CreateUndoObjectSetText(*pTextObj, 0))); + pSdrModel->GetSdrUndoFactory().CreateUndoObjectSetText(*pTextObj, 0)); } if ( !bToggleOn ) { @@ -1384,11 +1382,9 @@ void View::ChangeMarkedObjectsBulletsNumbering( if ( bUndoEnabled && pUndoGroup->GetActionCount() > 0 ) { pSdrModel->BegUndo(); - pSdrModel->AddUndo(pUndoGroup); + pSdrModel->AddUndo(std::move(pUndoGroup)); pSdrModel->EndUndo(); } - else - delete pUndoGroup; } } // end of namespace sd diff --git a/sd/source/ui/view/sdview2.cxx b/sd/source/ui/view/sdview2.cxx index 4c8733eebb1c..16e083a2f8a8 100644 --- a/sd/source/ui/view/sdview2.cxx +++ b/sd/source/ui/view/sdview2.cxx @@ -743,7 +743,7 @@ sal_Int8 View::ExecuteDrop( const ExecuteDropEvent& rEvt, } // create undo action with old and new sizes - SdAnimationPrmsUndoAction* pAction = new SdAnimationPrmsUndoAction(&mrDoc, pPickObj, bCreated); + std::unique_ptr<SdAnimationPrmsUndoAction> pAction(new SdAnimationPrmsUndoAction(&mrDoc, pPickObj, bCreated)); pAction->SetActive(pInfo->mbActive, pInfo->mbActive); pAction->SetEffect(pInfo->meEffect, pInfo->meEffect); pAction->SetTextEffect(pInfo->meTextEffect, pInfo->meTextEffect); @@ -764,7 +764,7 @@ sal_Int8 View::ExecuteDrop( const ExecuteDropEvent& rEvt, OUString aString(SdResId(STR_UNDO_ANIMATION)); pAction->SetComment(aString); - mpDocSh->GetUndoManager()->AddUndoAction(pAction); + mpDocSh->GetUndoManager()->AddUndoAction(std::move(pAction)); pInfo->meClickAction = eClickAction; pInfo->SetBookmark( aBookmark ); mrDoc.SetChanged(); diff --git a/sd/source/ui/view/sdview3.cxx b/sd/source/ui/view/sdview3.cxx index 1506542b30c8..06d66260dd7a 100644 --- a/sd/source/ui/view/sdview3.cxx +++ b/sd/source/ui/view/sdview3.cxx @@ -799,7 +799,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, if( bUndo ) AddUndo( - new E3dAttributesUndoAction( + o3tl::make_unique<E3dAttributesUndoAction>( *static_cast< E3dObject* >(pPickObj), aNewSet, aOldSet)); diff --git a/sd/source/ui/view/viewshe2.cxx b/sd/source/ui/view/viewshe2.cxx index fafde8c53584..6d1ce78e86ec 100644 --- a/sd/source/ui/view/viewshe2.cxx +++ b/sd/source/ui/view/viewshe2.cxx @@ -479,11 +479,11 @@ void ViewShell::SetPageSizeAndBorder(PageKind ePageKind, const Size& rNewSize, return; } - SdUndoGroup* pUndoGroup(nullptr); + std::unique_ptr<SdUndoGroup> pUndoGroup; SfxViewShell* pViewShell(GetViewShell()); if (pViewShell) { - pUndoGroup = new SdUndoGroup(GetDoc()); + pUndoGroup.reset(new SdUndoGroup(GetDoc())); pUndoGroup->SetComment(SdResId(STR_UNDO_CHANGE_PAGEFORMAT)); } Broadcast (ViewShellHint(ViewShellHint::HINT_PAGE_RESIZE_START)); @@ -492,7 +492,7 @@ void ViewShell::SetPageSizeAndBorder(PageKind ePageKind, const Size& rNewSize, GetDoc()->AdaptPageSizeForAllPages( rNewSize, ePageKind, - pUndoGroup, + pUndoGroup.get(), nLeft, nRight, nUpper, @@ -511,7 +511,7 @@ void ViewShell::SetPageSizeAndBorder(PageKind ePageKind, const Size& rNewSize, // handed over undo group to undo manager if (pViewShell) { - pViewShell->GetViewFrame()->GetObjectShell()->GetUndoManager()->AddUndoAction(pUndoGroup); + pViewShell->GetViewFrame()->GetObjectShell()->GetUndoManager()->AddUndoAction(std::move(pUndoGroup)); } // calculate View-Sizes diff --git a/starmath/source/document.cxx b/starmath/source/document.cxx index 1e9ec6f25d60..1b5a9bfe9c33 100644 --- a/starmath/source/document.cxx +++ b/starmath/source/document.cxx @@ -901,7 +901,7 @@ void SmDocShell::Execute(SfxRequest& rReq) SfxUndoManager *pTmpUndoMgr = GetUndoManager(); if (pTmpUndoMgr) pTmpUndoMgr->AddUndoAction( - new SmFormatAction(this, aOldFormat, aNewFormat)); + o3tl::make_unique<SmFormatAction>(this, aOldFormat, aNewFormat)); SetFormat( aNewFormat ); Repaint(); @@ -944,7 +944,7 @@ void SmDocShell::Execute(SfxRequest& rReq) SfxUndoManager *pTmpUndoMgr = GetUndoManager(); if (pTmpUndoMgr) pTmpUndoMgr->AddUndoAction( - new SmFormatAction(this, aOldFormat, aNewFormat)); + o3tl::make_unique<SmFormatAction>(this, aOldFormat, aNewFormat)); SetFormat( aNewFormat ); Repaint(); @@ -967,7 +967,7 @@ void SmDocShell::Execute(SfxRequest& rReq) SfxUndoManager *pTmpUndoMgr = GetUndoManager(); if (pTmpUndoMgr) pTmpUndoMgr->AddUndoAction( - new SmFormatAction(this, aOldFormat, aNewFormat)); + o3tl::make_unique<SmFormatAction>(this, aOldFormat, aNewFormat)); SetFormat( aNewFormat ); Repaint(); @@ -990,7 +990,7 @@ void SmDocShell::Execute(SfxRequest& rReq) SfxUndoManager *pTmpUndoMgr = GetUndoManager(); if (pTmpUndoMgr) pTmpUndoMgr->AddUndoAction( - new SmFormatAction(this, aOldFormat, aNewFormat)); + o3tl::make_unique<SmFormatAction>(this, aOldFormat, aNewFormat)); SetFormat( aNewFormat ); Repaint(); @@ -1018,7 +1018,7 @@ void SmDocShell::Execute(SfxRequest& rReq) SfxUndoManager *pTmpUndoMgr = GetUndoManager(); if (pTmpUndoMgr) pTmpUndoMgr->AddUndoAction( - new SmFormatAction(this, aOldFormat, aNewFormat)); + o3tl::make_unique<SmFormatAction>(this, aOldFormat, aNewFormat)); SetFormat( aNewFormat ); Repaint(); diff --git a/svl/source/undo/undo.cxx b/svl/source/undo/undo.cxx index 3b2085108126..ec0f280145c4 100644 --- a/svl/source/undo/undo.cxx +++ b/svl/source/undo/undo.cxx @@ -595,15 +595,16 @@ bool SfxUndoManager::ImplAddUndoAction_NoNotify( SfxUndoAction *pAction, bool bT } -void SfxUndoManager::AddUndoAction( SfxUndoAction *pAction, bool bTryMerge ) +void SfxUndoManager::AddUndoAction( std::unique_ptr<SfxUndoAction> pAction, bool bTryMerge ) { UndoManagerGuard aGuard( *m_xData ); // add - if ( ImplAddUndoAction_NoNotify( pAction, bTryMerge, true, aGuard ) ) + auto pActionTmp = pAction.get(); + if ( ImplAddUndoAction_NoNotify( pAction.release(), bTryMerge, true, aGuard ) ) { // notify listeners - aGuard.scheduleNotification( &SfxUndoListener::undoActionAdded, pAction->GetComment() ); + aGuard.scheduleNotification( &SfxUndoListener::undoActionAdded, pActionTmp->GetComment() ); } } diff --git a/svx/source/engine3d/dragmt3d.cxx b/svx/source/engine3d/dragmt3d.cxx index f03ef825a3c5..94d2bd213fbd 100644 --- a/svx/source/engine3d/dragmt3d.cxx +++ b/svx/source/engine3d/dragmt3d.cxx @@ -33,6 +33,7 @@ #include <svx/sdr/contact/viewcontactofe3dscene.hxx> #include <drawinglayer/geometry/viewinformation3d.hxx> #include <svx/e3dsceneupdater.hxx> +#include <o3tl/make_unique.hxx> E3dDragMethod::E3dDragMethod ( @@ -161,7 +162,7 @@ bool E3dDragMethod::EndSdrDrag(bool /*bCopy*/) if( bUndo ) { getSdrDragView().AddUndo( - new E3dRotateUndoAction( + o3tl::make_unique<E3dRotateUndoAction>( rCandidate.mr3DObj, rCandidate.maInitTransform, rCandidate.maTransform)); diff --git a/svx/source/form/fmpgeimp.cxx b/svx/source/form/fmpgeimp.cxx index bf43eec8379f..3b03050ddb52 100644 --- a/svx/source/form/fmpgeimp.cxx +++ b/svx/source/form/fmpgeimp.cxx @@ -47,6 +47,7 @@ #include <comphelper/types.hxx> #include <unotools/streamwrap.hxx> #include <connectivity/dbtools.hxx> +#include <o3tl/make_unique.hxx> using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; @@ -419,7 +420,7 @@ Reference< XForm > FmFormPageImpl::getDefaultForm() if( rModel.IsUndoEnabled() ) { rModel.AddUndo( - new FmUndoContainerAction( + o3tl::make_unique<FmUndoContainerAction>( static_cast< FmFormModel& >(rModel), FmUndoContainerAction::Inserted, xForms, @@ -516,7 +517,7 @@ Reference< css::form::XForm > FmFormPageImpl::findPlaceInFormComponentHierarchy { Reference< css::container::XIndexContainer > xContainer( getForms(), UNO_QUERY ); rModel.AddUndo( - new FmUndoContainerAction( + o3tl::make_unique<FmUndoContainerAction>( static_cast< FmFormModel& >(rModel), FmUndoContainerAction::Inserted, xContainer, diff --git a/svx/source/form/fmshimp.cxx b/svx/source/form/fmshimp.cxx index ef234e200590..0eb340933404 100644 --- a/svx/source/form/fmshimp.cxx +++ b/svx/source/form/fmshimp.cxx @@ -1268,7 +1268,7 @@ bool FmXFormShell::executeControlConversionSlot_Lock(const Reference<XFormCompon DBG_ASSERT(pModel != nullptr, "FmXFormShell::executeControlConversionSlot: my shell has no model !"); if (pModel && pModel->IsUndoEnabled() ) { - pModel->AddUndo(new FmUndoModelReplaceAction(*pModel, pFormObject, xOldModel)); + pModel->AddUndo(o3tl::make_unique<FmUndoModelReplaceAction>(*pModel, pFormObject, xOldModel)); } else { diff --git a/svx/source/form/fmundo.cxx b/svx/source/form/fmundo.cxx index 024f8a60f8af..971671888437 100644 --- a/svx/source/form/fmundo.cxx +++ b/svx/source/form/fmundo.cxx @@ -54,6 +54,7 @@ #include <comphelper/property.hxx> #include <comphelper/types.hxx> #include <connectivity/dbtools.hxx> +#include <o3tl/make_unique.hxx> using namespace ::com::sun::star::uno; using namespace ::com::sun::star::awt; @@ -702,7 +703,7 @@ void SAL_CALL FmXUndoEnvironment::propertyChange(const PropertyChangeEvent& evt) // add their undo actions out-of-order SolarMutexGuard aSolarGuard; - rModel.AddUndo(new FmUndoPropertyAction(rModel, evt)); + rModel.AddUndo(o3tl::make_unique<FmUndoPropertyAction>(rModel, evt)); } } else diff --git a/svx/source/form/navigatortree.cxx b/svx/source/form/navigatortree.cxx index 63d8cdac73b2..1a9291bf55a0 100644 --- a/svx/source/form/navigatortree.cxx +++ b/svx/source/form/navigatortree.cxx @@ -1065,7 +1065,7 @@ namespace svxform // UndoAction for removal if ( bUndo && GetNavModel()->m_pPropChangeList->CanUndo()) { - pFormModel->AddUndo(new FmUndoContainerAction(*pFormModel, FmUndoContainerAction::Removed, + pFormModel->AddUndo(o3tl::make_unique<FmUndoContainerAction>(*pFormModel, FmUndoContainerAction::Removed, xContainer, xCurrentChild, nIndex)); } else if( !GetNavModel()->m_pPropChangeList->CanUndo() ) @@ -1097,7 +1097,7 @@ namespace svxform // UndoAction for insertion if ( bUndo && GetNavModel()->m_pPropChangeList->CanUndo()) - pFormModel->AddUndo(new FmUndoContainerAction(*pFormModel, FmUndoContainerAction::Inserted, + pFormModel->AddUndo(o3tl::make_unique<FmUndoContainerAction>(*pFormModel, FmUndoContainerAction::Inserted, xContainer, xCurrentChild, nIndex)); // insert in new container diff --git a/svx/source/form/navigatortreemodel.cxx b/svx/source/form/navigatortreemodel.cxx index 3e20a734582a..d7354712e7af 100644 --- a/svx/source/form/navigatortreemodel.cxx +++ b/svx/source/form/navigatortreemodel.cxx @@ -287,7 +287,7 @@ namespace svxform // UndoAction if ( bUndo && m_pPropChangeList->CanUndo()) { - m_pFormModel->AddUndo(new FmUndoContainerAction(*m_pFormModel, + m_pFormModel->AddUndo(o3tl::make_unique<FmUndoContainerAction>(*m_pFormModel, FmUndoContainerAction::Inserted, xContainer, xElement, @@ -396,7 +396,7 @@ namespace svxform { if ( bUndo && m_pPropChangeList->CanUndo()) { - m_pFormModel->AddUndo(new FmUndoContainerAction(*m_pFormModel, + m_pFormModel->AddUndo(o3tl::make_unique<FmUndoContainerAction>(*m_pFormModel, FmUndoContainerAction::Removed, xContainer, xElement, nContainerIndex )); diff --git a/svx/source/svdraw/svddrgmt.cxx b/svx/source/svdraw/svddrgmt.cxx index a9c60d9d91c6..32a945f956bc 100644 --- a/svx/source/svdraw/svddrgmt.cxx +++ b/svx/source/svdraw/svddrgmt.cxx @@ -1318,14 +1318,14 @@ void SdrDragObjOwn::MoveSdrDrag(const Point& rNoSnapPnt) bool SdrDragObjOwn::EndSdrDrag(bool /*bCopy*/) { Hide(); - std::vector< SdrUndoAction* > vConnectorUndoActions; + std::vector< std::unique_ptr<SdrUndoAction> > vConnectorUndoActions; bool bRet = false; SdrObject* pObj = GetDragObj(); if(pObj) { - SdrUndoAction* pUndo = nullptr; - SdrUndoAction* pUndo2 = nullptr; + std::unique_ptr<SdrUndoAction> pUndo; + std::unique_ptr<SdrUndoAction> pUndo2; const bool bUndo = getSdrDragView().IsUndoEnabled(); if( bUndo ) @@ -1375,7 +1375,7 @@ bool SdrDragObjOwn::EndSdrDrag(bool /*bCopy*/) bRet = pObj->applySpecialDrag(DragStat()); if (DragStat().IsEndDragChangesLayout()) { - auto pGeoUndo = dynamic_cast<SdrUndoGeoObj*>(pUndo); + auto pGeoUndo = dynamic_cast<SdrUndoGeoObj*>(pUndo.get()); if (pGeoUndo) pGeoUndo->SetSkipChangeLayout(true); } @@ -1391,34 +1391,19 @@ bool SdrDragObjOwn::EndSdrDrag(bool /*bCopy*/) { if( bUndo ) { - getSdrDragView().AddUndoActions( vConnectorUndoActions ); + getSdrDragView().AddUndoActions( std::move(vConnectorUndoActions) ); if ( pUndo ) { - getSdrDragView().AddUndo(pUndo); + getSdrDragView().AddUndo(std::move(pUndo)); } if ( pUndo2 ) { - getSdrDragView().AddUndo(pUndo2); + getSdrDragView().AddUndo(std::move(pUndo2)); } } } - else - { - if( bUndo ) - { - std::vector< SdrUndoAction* >::iterator vConnectorUndoIter( vConnectorUndoActions.begin() ); - - while( vConnectorUndoIter != vConnectorUndoActions.end() ) - { - delete *vConnectorUndoIter++; - } - - delete pUndo; - delete pUndo2; - } - } if( bUndo ) getSdrDragView().EndUndo(); diff --git a/svx/source/svdraw/svddrgv.cxx b/svx/source/svdraw/svddrgv.cxx index 6c7ccedbb4dc..46bc158c742e 100644 --- a/svx/source/svdraw/svddrgv.cxx +++ b/svx/source/svdraw/svddrgv.cxx @@ -532,7 +532,7 @@ bool SdrDragView::EndDragObj(bool bCopy) if (IsInsertGluePoint() && bUndo) { BegUndo(maInsPointUndoStr); - AddUndo(mpInsPointUndo); + AddUndo(std::unique_ptr<SdrUndoAction>(mpInsPointUndo)); } bRet = mpCurrentSdrDragMethod->EndSdrDrag(bCopy); @@ -557,7 +557,7 @@ bool SdrDragView::EndDragObj(bool bCopy) if( bUndo ) { BegUndo(maInsPointUndoStr); - AddUndo(mpInsPointUndo); + AddUndo(std::unique_ptr<SdrUndoAction>(mpInsPointUndo)); EndUndo(); } } @@ -627,7 +627,7 @@ bool SdrDragView::ImpBegInsObjPoint(bool bIdxZwang, const Point& rPnt, bool bNew if(auto pMarkedPath = dynamic_cast<SdrPathObj*>( mpMarkedObj)) { BrkAction(); - mpInsPointUndo = dynamic_cast< SdrUndoGeoObj* >( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*mpMarkedObj) ); + mpInsPointUndo = dynamic_cast< SdrUndoGeoObj* >( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*mpMarkedObj).release() ); DBG_ASSERT( mpInsPointUndo, "svx::SdrDragView::BegInsObjPoint(), could not create correct undo object!" ); OUString aStr(SvxResId(STR_DragInsertPoint)); @@ -725,7 +725,7 @@ bool SdrDragView::BegInsGluePoint(const Point& rPnt) { BrkAction(); UnmarkAllGluePoints(); - mpInsPointUndo= dynamic_cast< SdrUndoGeoObj* >( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj) ); + mpInsPointUndo= dynamic_cast< SdrUndoGeoObj* >( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj).release() ); DBG_ASSERT( mpInsPointUndo, "svx::SdrDragView::BegInsObjPoint(), could not create correct undo object!" ); OUString aStr(SvxResId(STR_DragInsertGluePoint)); diff --git a/svx/source/svdraw/svdedtv.cxx b/svx/source/svdraw/svdedtv.cxx index 1b5720af2536..b74dde640e4e 100644 --- a/svx/source/svdraw/svdedtv.cxx +++ b/svx/source/svdraw/svdedtv.cxx @@ -712,8 +712,7 @@ std::vector<SdrObject*> SdrEditView::DeleteMarkedList(SdrMarkList const& rMark) SdrObject* pObj = pM->GetMarkedSdrObj(); // extra undo actions for changed connector which now may hold its laid out path (SJ) - std::vector< SdrUndoAction* > vConnectorUndoActions( CreateConnectorUndo( *pObj ) ); - AddUndoActions( vConnectorUndoActions ); + AddUndoActions(CreateConnectorUndo( *pObj )); AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoDeleteObject(*pObj)); } diff --git a/svx/source/svdraw/svdedtv1.cxx b/svx/source/svdraw/svdedtv1.cxx index 0dd66b0f14e2..433fbef97928 100644 --- a/svx/source/svdraw/svdedtv1.cxx +++ b/svx/source/svdraw/svdedtv1.cxx @@ -137,9 +137,9 @@ void SdrEditView::SetMarkedObjRect(const tools::Rectangle& rRect) EndUndo(); } -std::vector< SdrUndoAction* > SdrEditView::CreateConnectorUndo( SdrObject& rO ) +std::vector< std::unique_ptr<SdrUndoAction> > SdrEditView::CreateConnectorUndo( SdrObject& rO ) { - std::vector< SdrUndoAction* > vUndoActions; + std::vector< std::unique_ptr<SdrUndoAction> > vUndoActions; if ( rO.GetBroadcaster() ) { @@ -164,11 +164,10 @@ std::vector< SdrUndoAction* > SdrEditView::CreateConnectorUndo( SdrObject& rO ) return vUndoActions; } -void SdrEditView::AddUndoActions( std::vector< SdrUndoAction* >& rUndoActions ) +void SdrEditView::AddUndoActions( std::vector< std::unique_ptr<SdrUndoAction> > aUndoActions ) { - std::vector< SdrUndoAction* >::iterator aUndoActionIter( rUndoActions.begin() ); - while( aUndoActionIter != rUndoActions.end() ) - AddUndo( *aUndoActionIter++ ); + for (auto & rAction : aUndoActions) + AddUndo( std::move(rAction) ); } void SdrEditView::MoveMarkedObj(const Size& rSiz, bool bCopy) @@ -194,8 +193,7 @@ void SdrEditView::MoveMarkedObj(const Size& rSiz, bool bCopy) SdrObject* pO=pM->GetMarkedSdrObj(); if( bUndo ) { - std::vector< SdrUndoAction* > vConnectorUndoActions( CreateConnectorUndo( *pO ) ); - AddUndoActions( vConnectorUndoActions ); + AddUndoActions( CreateConnectorUndo( *pO ) ); AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoMoveObject(*pO,rSiz)); } pO->Move(rSiz); @@ -226,8 +224,7 @@ void SdrEditView::ResizeMarkedObj(const Point& rRef, const Fraction& xFact, cons SdrObject* pO=pM->GetMarkedSdrObj(); if( bUndo ) { - std::vector< SdrUndoAction* > vConnectorUndoActions( CreateConnectorUndo( *pO ) ); - AddUndoActions( vConnectorUndoActions ); + AddUndoActions( CreateConnectorUndo( *pO ) ); AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pO)); } pO->Resize(rRef,xFact,yFact); @@ -255,8 +252,7 @@ void SdrEditView::ResizeMultMarkedObj(const Point& rRef, SdrObject* pO=pM->GetMarkedSdrObj(); if( bUndo ) { - std::vector< SdrUndoAction* > vConnectorUndoActions( CreateConnectorUndo( *pO ) ); - AddUndoActions( vConnectorUndoActions ); + AddUndoActions( CreateConnectorUndo( *pO ) ); AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pO)); } @@ -330,8 +326,7 @@ void SdrEditView::RotateMarkedObj(const Point& rRef, long nAngle, bool bCopy) if( bUndo ) { // extra undo actions for changed connector which now may hold its laid out path (SJ) - std::vector< SdrUndoAction* > vConnectorUndoActions( CreateConnectorUndo( *pO ) ); - AddUndoActions( vConnectorUndoActions ); + AddUndoActions( CreateConnectorUndo( *pO ) ); AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pO)); } @@ -394,8 +389,7 @@ void SdrEditView::MirrorMarkedObj(const Point& rRef1, const Point& rRef2, bool b if( bUndo ) { // extra undo actions for changed connector which now may hold its laid out path (SJ) - std::vector< SdrUndoAction* > vConnectorUndoActions( CreateConnectorUndo( *pO ) ); - AddUndoActions( vConnectorUndoActions ); + AddUndoActions( CreateConnectorUndo( *pO ) ); AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pO)); } @@ -480,8 +474,7 @@ void SdrEditView::ShearMarkedObj(const Point& rRef, long nAngle, bool bVShear, b SdrObject* pO=pM->GetMarkedSdrObj(); if( bUndo ) { - std::vector< SdrUndoAction* > vConnectorUndoActions( CreateConnectorUndo( *pO ) ); - AddUndoActions( vConnectorUndoActions ); + AddUndoActions( CreateConnectorUndo( *pO ) ); AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pO)); } pO->Shear(rRef,nAngle,nTan,bVShear); @@ -1040,14 +1033,11 @@ void SdrEditView::SetAttrToMarked(const SfxItemSet& rAttr, bool bReplaceAll) if( bUndo ) { - std::vector< SdrUndoAction* > vConnectorUndoActions; SdrEdgeObj* pEdgeObj = dynamic_cast< SdrEdgeObj* >( pObj ); if ( pEdgeObj ) bPossibleGeomChange = true; else - vConnectorUndoActions = CreateConnectorUndo( *pObj ); - - AddUndoActions( vConnectorUndoActions ); + AddUndoActions( CreateConnectorUndo( *pObj ) ); } // new geometry undo diff --git a/svx/source/svdraw/svdedtv2.cxx b/svx/source/svdraw/svdedtv2.cxx index 1151fc460dcb..2ee701195876 100644 --- a/svx/source/svdraw/svdedtv2.cxx +++ b/svx/source/svdraw/svdedtv2.cxx @@ -1732,8 +1732,7 @@ void SdrEditView::GroupMarked() --nm; SdrMark* pM=GetSdrMarkByIndex(nm); SdrObject* pObj = pM->GetMarkedSdrObj(); - std::vector< SdrUndoAction* > vConnectorUndoActions( CreateConnectorUndo( *pObj ) ); - AddUndoActions( vConnectorUndoActions ); + AddUndoActions( CreateConnectorUndo( *pObj ) ); AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoRemoveObject( *pObj )); } } diff --git a/svx/source/svdraw/svdedxv.cxx b/svx/source/svdraw/svdedxv.cxx index a10fe457c4a2..4a058ad961d6 100644 --- a/svx/source/svdraw/svdedxv.cxx +++ b/svx/source/svdraw/svdedxv.cxx @@ -905,8 +905,10 @@ void SdrObjEditView::ImpChainingEventHdl() const int nText = 0; // XXX: hardcoded index (SdrTextObj::getText handles only 0) const bool bUndoEnabled = GetModel() && IsUndoEnabled(); - SdrUndoObjSetText *pTxtUndo = bUndoEnabled ? dynamic_cast< SdrUndoObjSetText* > - ( GetModel()->GetSdrUndoFactory().CreateUndoObjectSetText(*pTextObj, nText ) ) : nullptr; + std::unique_ptr<SdrUndoObjSetText> pTxtUndo; + if (bUndoEnabled) + pTxtUndo.reset(dynamic_cast< SdrUndoObjSetText* > + ( GetModel()->GetSdrUndoFactory().CreateUndoObjectSetText(*pTextObj, nText ).release() )); // trigger actual chaining pTextObj->onChainingEvent(); @@ -916,13 +918,12 @@ void SdrObjEditView::ImpChainingEventHdl() pTxtUndo->AfterSetText(); if (!pTxtUndo->IsDifferent()) { - delete pTxtUndo; - pTxtUndo=nullptr; + pTxtUndo.reset(); } } if (pTxtUndo) - AddUndo(pTxtUndo); + AddUndo(std::move(pTxtUndo)); //maCursorEvent = new CursorChainingEvent(pTextChain->GetCursorEvent(pTextObj)); //SdrTextObj *pNextLink = pTextObj->GetNextLinkInChain(); @@ -1435,7 +1436,7 @@ SdrEndTextEditKind SdrObjEditView::SdrEndTextEdit(bool bDontDeleteReally) { pTEOutliner->CompleteOnlineSpelling(); - SdrUndoObjSetText* pTxtUndo = nullptr; + std::unique_ptr<SdrUndoObjSetText> pTxtUndo; if( bModified ) { @@ -1444,7 +1445,7 @@ SdrEndTextEditKind SdrObjEditView::SdrEndTextEdit(bool bDontDeleteReally) if( pTEObj->getText( nText ) == pTEObj->getActiveText() ) break; - pTxtUndo = dynamic_cast< SdrUndoObjSetText* >( GetModel()->GetSdrUndoFactory().CreateUndoObjectSetText(*pTEObj, nText ) ); + pTxtUndo.reset( dynamic_cast< SdrUndoObjSetText* >( GetModel()->GetSdrUndoFactory().CreateUndoObjectSetText(*pTEObj, nText ).release() ) ); } DBG_ASSERT( !bModified || pTxtUndo, "svx::SdrObjEditView::EndTextEdit(), could not create undo action!" ); // Set old CalcFieldValue-Handler again, this @@ -1472,12 +1473,11 @@ SdrEndTextEditKind SdrObjEditView::SdrEndTextEdit(bool bDontDeleteReally) pTxtUndo->AfterSetText(); if (!pTxtUndo->IsDifferent()) { - delete pTxtUndo; - pTxtUndo=nullptr; + pTxtUndo.reset(); } } // check deletion of entire TextObj - SdrUndoAction* pDelUndo=nullptr; + std::unique_ptr<SdrUndoAction> pDelUndo; bool bDelObj=false; if (pTEObj!=nullptr && bTextEditNewObj) { @@ -1496,21 +1496,17 @@ SdrEndTextEditKind SdrObjEditView::SdrEndTextEdit(bool bDontDeleteReally) } } } - if (pTxtUndo!=nullptr) + if (pTxtUndo) { if( bUndo ) - AddUndo(pTxtUndo); + AddUndo(std::move(pTxtUndo)); eRet=SdrEndTextEditKind::Changed; } if (pDelUndo!=nullptr) { if( bUndo ) { - AddUndo(pDelUndo); - } - else - { - delete pDelUndo; + AddUndo(std::move(pDelUndo)); } eRet=SdrEndTextEditKind::Deleted; DBG_ASSERT(pTEObj->getParentSdrObjListFromSdrObject()!=nullptr,"SdrObjEditView::SdrEndTextEdit(): Fatal: Object edited doesn't have an ObjList!"); diff --git a/svx/source/svdraw/svdmodel.cxx b/svx/source/svdraw/svdmodel.cxx index 9f83988fc7b6..0a838238e23e 100644 --- a/svx/source/svdraw/svdmodel.cxx +++ b/svx/source/svdraw/svdmodel.cxx @@ -560,25 +560,21 @@ void SdrModel::SetUndoComment(const OUString& rComment, const OUString& rObjDesc } } -void SdrModel::AddUndo(SdrUndoAction* pUndo) +void SdrModel::AddUndo(std::unique_ptr<SdrUndoAction> pUndo) { if( mpImpl->mpUndoManager ) { - mpImpl->mpUndoManager->AddUndoAction( pUndo ); + mpImpl->mpUndoManager->AddUndoAction( std::move(pUndo) ); } - else if( !IsUndoEnabled() ) - { - delete pUndo; - } - else + else if( IsUndoEnabled() ) { if (pCurrentUndoGroup) { - pCurrentUndoGroup->AddAction(std::unique_ptr<SdrUndoAction>(pUndo)); + pCurrentUndoGroup->AddAction(std::move(pUndo)); } else { - ImpPostUndoAction(std::unique_ptr<SdrUndoAction>(pUndo)); + ImpPostUndoAction(std::move(pUndo)); } } } diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx index e56e0d9e5888..f57376e7c3e9 100644 --- a/svx/source/svdraw/svdobj.cxx +++ b/svx/source/svdraw/svdobj.cxx @@ -687,14 +687,14 @@ void SdrObject::SetName(const OUString& rStr) if ( getSdrModelFromSdrObject().IsUndoEnabled() ) { bUndo = true; - SdrUndoAction* pUndoAction = + std::unique_ptr<SdrUndoAction> pUndoAction = SdrUndoFactory::CreateUndoObjectStrAttr( *this, SdrUndoObjStrAttr::ObjStrAttrType::Name, GetName(), rStr ); getSdrModelFromSdrObject().BegUndo( pUndoAction->GetComment() ); - getSdrModelFromSdrObject().AddUndo( pUndoAction ); + getSdrModelFromSdrObject().AddUndo( std::move(pUndoAction) ); } pPlusData->aObjName = rStr; // Undo/Redo for setting object's name (#i73249#) @@ -731,14 +731,14 @@ void SdrObject::SetTitle(const OUString& rStr) if ( getSdrModelFromSdrObject().IsUndoEnabled() ) { bUndo = true; - SdrUndoAction* pUndoAction = + std::unique_ptr<SdrUndoAction> pUndoAction = SdrUndoFactory::CreateUndoObjectStrAttr( *this, SdrUndoObjStrAttr::ObjStrAttrType::Title, GetTitle(), rStr ); getSdrModelFromSdrObject().BegUndo( pUndoAction->GetComment() ); - getSdrModelFromSdrObject().AddUndo( pUndoAction ); + getSdrModelFromSdrObject().AddUndo( std::move(pUndoAction) ); } pPlusData->aObjTitle = rStr; // Undo/Redo for setting object's title (#i73249#) @@ -775,14 +775,14 @@ void SdrObject::SetDescription(const OUString& rStr) if ( getSdrModelFromSdrObject().IsUndoEnabled() ) { bUndo = true; - SdrUndoAction* pUndoAction = + std::unique_ptr<SdrUndoAction> pUndoAction = SdrUndoFactory::CreateUndoObjectStrAttr( *this, SdrUndoObjStrAttr::ObjStrAttrType::Description, GetDescription(), rStr ); getSdrModelFromSdrObject().BegUndo( pUndoAction->GetComment() ); - getSdrModelFromSdrObject().AddUndo( pUndoAction ); + getSdrModelFromSdrObject().AddUndo( std::move(pUndoAction) ); } pPlusData->aObjDescription = rStr; // Undo/Redo for setting object's description (#i73249#) diff --git a/svx/source/svdraw/svdundo.cxx b/svx/source/svdraw/svdundo.cxx index e4b18f3c269e..3f92e07baa7d 100644 --- a/svx/source/svdraw/svdundo.cxx +++ b/svx/source/svdraw/svdundo.cxx @@ -1150,7 +1150,7 @@ void SdrUndoObjSetText::SdrRepeat(SdrView& rView) if (pTextObj!=nullptr) { if( bUndo ) - rView.AddUndo(new SdrUndoObjSetText(*pTextObj,0)); + rView.AddUndo(o3tl::make_unique<SdrUndoObjSetText>(*pTextObj,0)); std::unique_ptr<OutlinerParaObject> pText1; if (pNewText) @@ -1420,7 +1420,7 @@ SdrUndoDelPage::SdrUndoDelPage(SdrPage& rNewPg) pUndoGroup.reset( new SdrUndoGroup(rMod) ); } - pUndoGroup->AddAction(std::unique_ptr<SdrUndoAction>(rMod.GetSdrUndoFactory().CreateUndoPageRemoveMasterPage(*pDrawPage))); + pUndoGroup->AddAction(rMod.GetSdrUndoFactory().CreateUndoPageRemoveMasterPage(*pDrawPage)); } } } @@ -1690,115 +1690,115 @@ SdrUndoFactory::~SdrUndoFactory(){} // shapes -SdrUndoAction* SdrUndoFactory::CreateUndoMoveObject( SdrObject& rObject, const Size& rDist ) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoMoveObject( SdrObject& rObject, const Size& rDist ) { - return new SdrUndoMoveObj( rObject, rDist ); + return o3tl::make_unique<SdrUndoMoveObj>( rObject, rDist ); } -SdrUndoAction* SdrUndoFactory::CreateUndoGeoObject( SdrObject& rObject ) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoGeoObject( SdrObject& rObject ) { - return new SdrUndoGeoObj( rObject ); + return o3tl::make_unique<SdrUndoGeoObj>( rObject ); } -SdrUndoAction* SdrUndoFactory::CreateUndoAttrObject( SdrObject& rObject, bool bStyleSheet1, bool bSaveText ) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoAttrObject( SdrObject& rObject, bool bStyleSheet1, bool bSaveText ) { - return new SdrUndoAttrObj( rObject, bStyleSheet1, bSaveText ); + return o3tl::make_unique<SdrUndoAttrObj>( rObject, bStyleSheet1, bSaveText ); } -SdrUndoAction* SdrUndoFactory::CreateUndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect ) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect ) { - return new SdrUndoRemoveObj( rObject, bOrdNumDirect ); + return o3tl::make_unique<SdrUndoRemoveObj>( rObject, bOrdNumDirect ); } -SdrUndoAction* SdrUndoFactory::CreateUndoInsertObject( SdrObject& rObject, bool bOrdNumDirect ) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoInsertObject( SdrObject& rObject, bool bOrdNumDirect ) { - return new SdrUndoInsertObj( rObject, bOrdNumDirect ); + return o3tl::make_unique<SdrUndoInsertObj>( rObject, bOrdNumDirect ); } -SdrUndoAction* SdrUndoFactory::CreateUndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect ) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect ) { - return new SdrUndoDelObj( rObject, bOrdNumDirect ); + return o3tl::make_unique<SdrUndoDelObj>( rObject, bOrdNumDirect ); } -SdrUndoAction* SdrUndoFactory::CreateUndoNewObject( SdrObject& rObject, bool bOrdNumDirect ) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoNewObject( SdrObject& rObject, bool bOrdNumDirect ) { - return new SdrUndoNewObj( rObject, bOrdNumDirect ); + return o3tl::make_unique<SdrUndoNewObj>( rObject, bOrdNumDirect ); } -SdrUndoAction* SdrUndoFactory::CreateUndoCopyObject( SdrObject& rObject, bool bOrdNumDirect ) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoCopyObject( SdrObject& rObject, bool bOrdNumDirect ) { - return new SdrUndoCopyObj( rObject, bOrdNumDirect ); + return o3tl::make_unique<SdrUndoCopyObj>( rObject, bOrdNumDirect ); } -SdrUndoAction* SdrUndoFactory::CreateUndoObjectOrdNum( SdrObject& rObject, sal_uInt32 nOldOrdNum1, sal_uInt32 nNewOrdNum1) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoObjectOrdNum( SdrObject& rObject, sal_uInt32 nOldOrdNum1, sal_uInt32 nNewOrdNum1) { - return new SdrUndoObjOrdNum( rObject, nOldOrdNum1, nNewOrdNum1 ); + return o3tl::make_unique<SdrUndoObjOrdNum>( rObject, nOldOrdNum1, nNewOrdNum1 ); } -SdrUndoAction* SdrUndoFactory::CreateUndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect ) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect ) { - return new SdrUndoReplaceObj( rOldObject, rNewObject, bOrdNumDirect ); + return o3tl::make_unique<SdrUndoReplaceObj>( rOldObject, rNewObject, bOrdNumDirect ); } -SdrUndoAction* SdrUndoFactory::CreateUndoObjectLayerChange( SdrObject& rObject, SdrLayerID aOldLayer, SdrLayerID aNewLayer ) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoObjectLayerChange( SdrObject& rObject, SdrLayerID aOldLayer, SdrLayerID aNewLayer ) { - return new SdrUndoObjectLayerChange( rObject, aOldLayer, aNewLayer ); + return o3tl::make_unique<SdrUndoObjectLayerChange>( rObject, aOldLayer, aNewLayer ); } -SdrUndoAction* SdrUndoFactory::CreateUndoObjectSetText( SdrObject& rNewObj, sal_Int32 nText ) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoObjectSetText( SdrObject& rNewObj, sal_Int32 nText ) { - return new SdrUndoObjSetText( rNewObj, nText ); + return o3tl::make_unique<SdrUndoObjSetText>( rNewObj, nText ); } -SdrUndoAction* SdrUndoFactory::CreateUndoObjectStrAttr( SdrObject& rObject, +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoObjectStrAttr( SdrObject& rObject, SdrUndoObjStrAttr::ObjStrAttrType eObjStrAttrType, const OUString& sOldStr, const OUString& sNewStr ) { - return new SdrUndoObjStrAttr( rObject, eObjStrAttrType, sOldStr, sNewStr ); + return o3tl::make_unique<SdrUndoObjStrAttr>( rObject, eObjStrAttrType, sOldStr, sNewStr ); } // layer -SdrUndoAction* SdrUndoFactory::CreateUndoNewLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoNewLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel) { - return new SdrUndoNewLayer( nLayerNum, rNewLayerAdmin, rNewModel ); + return o3tl::make_unique<SdrUndoNewLayer>( nLayerNum, rNewLayerAdmin, rNewModel ); } -SdrUndoAction* SdrUndoFactory::CreateUndoDeleteLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoDeleteLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel) { - return new SdrUndoDelLayer( nLayerNum, rNewLayerAdmin, rNewModel ); + return o3tl::make_unique<SdrUndoDelLayer>( nLayerNum, rNewLayerAdmin, rNewModel ); } // page -SdrUndoAction* SdrUndoFactory::CreateUndoDeletePage(SdrPage& rPage) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoDeletePage(SdrPage& rPage) { - return new SdrUndoDelPage(rPage); + return o3tl::make_unique<SdrUndoDelPage>(rPage); } -SdrUndoAction* SdrUndoFactory::CreateUndoNewPage(SdrPage& rPage) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoNewPage(SdrPage& rPage) { - return new SdrUndoNewPage( rPage ); + return o3tl::make_unique<SdrUndoNewPage>( rPage ); } -SdrUndoAction* SdrUndoFactory::CreateUndoCopyPage(SdrPage& rPage) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoCopyPage(SdrPage& rPage) { - return new SdrUndoCopyPage( rPage ); + return o3tl::make_unique<SdrUndoCopyPage>( rPage ); } -SdrUndoAction* SdrUndoFactory::CreateUndoSetPageNum(SdrPage& rNewPg, sal_uInt16 nOldPageNum1, sal_uInt16 nNewPageNum1) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoSetPageNum(SdrPage& rNewPg, sal_uInt16 nOldPageNum1, sal_uInt16 nNewPageNum1) { - return new SdrUndoSetPageNum( rNewPg, nOldPageNum1, nNewPageNum1 ); + return o3tl::make_unique<SdrUndoSetPageNum>( rNewPg, nOldPageNum1, nNewPageNum1 ); } // master page -SdrUndoAction* SdrUndoFactory::CreateUndoPageRemoveMasterPage(SdrPage& rChangedPage) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoPageRemoveMasterPage(SdrPage& rChangedPage) { - return new SdrUndoPageRemoveMasterPage( rChangedPage ); + return o3tl::make_unique<SdrUndoPageRemoveMasterPage>( rChangedPage ); } -SdrUndoAction* SdrUndoFactory::CreateUndoPageChangeMasterPage(SdrPage& rChangedPage) +std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoPageChangeMasterPage(SdrPage& rChangedPage) { - return new SdrUndoPageChangeMasterPage(rChangedPage); + return o3tl::make_unique<SdrUndoPageChangeMasterPage>(rChangedPage); } diff --git a/svx/source/table/cell.cxx b/svx/source/table/cell.cxx index ba705359f118..bbddd24b76fa 100644 --- a/svx/source/table/cell.cxx +++ b/svx/source/table/cell.cxx @@ -821,7 +821,7 @@ void Cell::AddUndo() if( rObj.IsInserted() && rObj.getSdrModelFromSdrObject().IsUndoEnabled() ) { CellRef xCell( this ); - rObj.getSdrModelFromSdrObject().AddUndo( new CellUndo( &rObj, xCell ) ); + rObj.getSdrModelFromSdrObject().AddUndo( o3tl::make_unique<CellUndo>( &rObj, xCell ) ); // Undo action for the after-text-edit-ended stack. SdrTableObj* pTableObj = dynamic_cast<sdr::table::SdrTableObj*>(&rObj); diff --git a/svx/source/table/svdotable.cxx b/svx/source/table/svdotable.cxx index 88c58cff636b..8c0ec5bbdf28 100644 --- a/svx/source/table/svdotable.cxx +++ b/svx/source/table/svdotable.cxx @@ -1854,7 +1854,7 @@ void SdrTableObj::EndTextEdit(SdrOutliner& rOutl) { // These actions should be on the undo stack after text edit. for (std::unique_ptr<SdrUndoAction>& pAction : mpImpl->maUndos) - getSdrModelFromSdrObject().AddUndo(pAction.release()); + getSdrModelFromSdrObject().AddUndo( std::move(pAction)); mpImpl->maUndos.clear(); getSdrModelFromSdrObject().AddUndo(getSdrModelFromSdrObject().GetSdrUndoFactory().CreateUndoGeoObject(*this)); diff --git a/svx/source/table/tablecolumn.cxx b/svx/source/table/tablecolumn.cxx index 7cff0359a916..183659670256 100644 --- a/svx/source/table/tablecolumn.cxx +++ b/svx/source/table/tablecolumn.cxx @@ -212,7 +212,7 @@ void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& a { if( pUndo ) { - rModel.AddUndo( pUndo.release() ); + rModel.AddUndo( std::move(pUndo) ); } mxTableModel->setModified(true); } diff --git a/svx/source/table/tablecontroller.cxx b/svx/source/table/tablecontroller.cxx index 301829a20a37..4aa3dfbc3358 100644 --- a/svx/source/table/tablecontroller.cxx +++ b/svx/source/table/tablecontroller.cxx @@ -1070,7 +1070,7 @@ void SvxTableController::SetTableStyle( const SfxItemSet* pArgs ) if( bUndo ) { rModel.BegUndo(SvxResId(STR_TABLE_STYLE)); - rModel.AddUndo(new TableStyleUndo(rTableObj)); + rModel.AddUndo(o3tl::make_unique<TableStyleUndo>(rTableObj)); } rTableObj.setTableStyle( xNewTableStyle ); @@ -1164,7 +1164,7 @@ void SvxTableController::SetTableStyleSettings( const SfxItemSet* pArgs ) if( bUndo ) { rModel.BegUndo( SvxResId(STR_TABLE_STYLE_SETTINGS) ); - rModel.AddUndo(new TableStyleUndo(rTableObj)); + rModel.AddUndo(o3tl::make_unique<TableStyleUndo>(rTableObj)); } rTableObj.setTableStyleSettings( aSettings ); diff --git a/svx/source/table/tablemodel.cxx b/svx/source/table/tablemodel.cxx index 49eb7f2f9655..c35463b0c297 100644 --- a/svx/source/table/tablemodel.cxx +++ b/svx/source/table/tablemodel.cxx @@ -37,6 +37,7 @@ #include "tablecolumns.hxx" #include "tableundo.hxx" #include <o3tl/safeint.hxx> +#include <o3tl/make_unique.hxx> #include <svx/svdotable.hxx> #include <svx/svdmodel.hxx> #include <svx/strings.hrc> @@ -638,7 +639,7 @@ void TableModel::insertColumns( sal_Int32 nIndex, sal_Int32 nCount ) (*aCellIter++) = getCell( nIndex + nOffset, nRow ); } - rModel.AddUndo( new InsertColUndo( xThis, nIndex, aNewColumns, aNewCells ) ); + rModel.AddUndo( o3tl::make_unique<InsertColUndo>( xThis, nIndex, aNewColumns, aNewCells ) ); } const sal_Int32 nRowCount = getRowCountImpl(); @@ -713,7 +714,7 @@ void TableModel::removeColumns( sal_Int32 nIndex, sal_Int32 nCount ) (*aCellIter++) = getCell( nIndex + nOffset, nRow ); } - rModel.AddUndo( new RemoveColUndo( xThis, nIndex, aRemovedCols, aRemovedCells ) ); + rModel.AddUndo( o3tl::make_unique<RemoveColUndo>( xThis, nIndex, aRemovedCols, aRemovedCells ) ); } // only rows before and inside the removed rows are considered @@ -808,7 +809,7 @@ void TableModel::insertRows( sal_Int32 nIndex, sal_Int32 nCount ) rModel.BegUndo( SvxResId(STR_TABLE_INSROW) ); rModel.AddUndo( rModel.GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) ); TableModelRef xThis( this ); - rModel.AddUndo( new InsertRowUndo( xThis, nIndex, aNewRows ) ); + rModel.AddUndo( o3tl::make_unique<InsertRowUndo>( xThis, nIndex, aNewRows ) ); } // check if cells merge over new columns @@ -871,7 +872,7 @@ void TableModel::removeRows( sal_Int32 nIndex, sal_Int32 nCount ) for( sal_Int32 nOffset = 0; nOffset < nCount; ++nOffset ) aRemovedRows[nOffset] = maRows[nIndex+nOffset]; - rModel.AddUndo( new RemoveRowUndo( xThis, nIndex, aRemovedRows ) ); + rModel.AddUndo( o3tl::make_unique<RemoveRowUndo>( xThis, nIndex, aRemovedRows ) ); } // only rows before and inside the removed rows are considered diff --git a/svx/source/table/tablerow.cxx b/svx/source/table/tablerow.cxx index c3b4e03475ae..87cba24d12cd 100644 --- a/svx/source/table/tablerow.cxx +++ b/svx/source/table/tablerow.cxx @@ -286,7 +286,7 @@ void SAL_CALL TableRow::setFastPropertyValue( sal_Int32 nHandle, const Any& aVal { if( pUndo ) { - rModel.AddUndo( pUndo.release() ); + rModel.AddUndo( std::move(pUndo) ); } mxTableModel->setModified(true); } diff --git a/svx/source/unodraw/unopage.cxx b/svx/source/unodraw/unopage.cxx index 1e0fa47af5bb..894f058263a4 100644 --- a/svx/source/unodraw/unopage.cxx +++ b/svx/source/unodraw/unopage.cxx @@ -309,8 +309,7 @@ void SAL_CALL SvxDrawPage::remove( const Reference< drawing::XShape >& xShape ) mpModel->BegUndo(SvxResId(STR_EditDelete), pObj->TakeObjNameSingul(), SdrRepeatFunc::Delete); - SdrUndoAction * pAction = mpModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pObj); - mpModel->AddUndo(pAction); + mpModel->AddUndo(mpModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pObj)); } OSL_VERIFY( mpPage->RemoveObject( nNum ) == pObj ); diff --git a/sw/source/core/frmedt/fecopy.cxx b/sw/source/core/frmedt/fecopy.cxx index 1a40e6b401b1..e51fab869e2a 100644 --- a/sw/source/core/frmedt/fecopy.cxx +++ b/sw/source/core/frmedt/fecopy.cxx @@ -1567,7 +1567,7 @@ bool SwFEShell::Paste(const Graphic &rGrf, const OUString& rURL) } else { - pView->AddUndo(new SdrUndoAttrObj(*pObj)); + pView->AddUndo(o3tl::make_unique<SdrUndoAttrObj>(*pObj)); SfxItemSet aSet(pView->GetModel()->GetItemPool(), svl::Items<XATTR_FILLSTYLE, XATTR_FILLBITMAP>{}); diff --git a/sw/source/core/inc/UndoManager.hxx b/sw/source/core/inc/UndoManager.hxx index 29f8cd4a44c2..3f7d9b34f631 100644 --- a/sw/source/core/inc/UndoManager.hxx +++ b/sw/source/core/inc/UndoManager.hxx @@ -82,7 +82,7 @@ public: void SetView(SwView* pView) override; // SfxUndoManager - virtual void AddUndoAction(SfxUndoAction *pAction, + virtual void AddUndoAction(std::unique_ptr<SfxUndoAction> pAction, bool bTryMerg = false) override; virtual bool Undo() override; virtual bool Redo() override; diff --git a/sw/source/core/undo/docundo.cxx b/sw/source/core/undo/docundo.cxx index 9d46a6b7bcbf..f5720c7aad77 100644 --- a/sw/source/core/undo/docundo.cxx +++ b/sw/source/core/undo/docundo.cxx @@ -244,7 +244,7 @@ SwUndo* UndoManager::GetLastUndo() void UndoManager::AppendUndo(std::unique_ptr<SwUndo> pUndo) { - AddUndoAction(pUndo.release()); + AddUndoAction(std::move(pUndo)); } void UndoManager::ClearRedo() @@ -511,9 +511,9 @@ SwUndo * UndoManager::RemoveLastUndo() // SfxUndoManager -void UndoManager::AddUndoAction(SfxUndoAction *pAction, bool bTryMerge) +void UndoManager::AddUndoAction(std::unique_ptr<SfxUndoAction> pAction, bool bTryMerge) { - SwUndo *const pUndo( dynamic_cast<SwUndo *>(pAction) ); + SwUndo *const pUndo( dynamic_cast<SwUndo *>(pAction.get()) ); if (pUndo) { if (RedlineFlags::NONE == pUndo->GetRedlineFlags()) @@ -525,7 +525,7 @@ void UndoManager::AddUndoAction(SfxUndoAction *pAction, bool bTryMerge) pUndo->IgnoreRepeat(); } } - SdrUndoManager::AddUndoAction(pAction, bTryMerge); + SdrUndoManager::AddUndoAction(std::move(pAction), bTryMerge); // if the undo nodes array is too large, delete some actions while (UNDO_ACTION_LIMIT < GetUndoNodes().Count()) { diff --git a/sw/source/uibase/shells/drawsh.cxx b/sw/source/uibase/shells/drawsh.cxx index f9e461d8b8ba..baf3939e0282 100644 --- a/sw/source/uibase/shells/drawsh.cxx +++ b/sw/source/uibase/shells/drawsh.cxx @@ -163,7 +163,7 @@ void SwDrawShell::InsertPictureFromFile(SdrObject& rObject) } else // if(rObject.IsClosedObj() && !dynamic_cast< SdrOle2Obj* >(&rObject)) { - pSdrView->AddUndo(new SdrUndoAttrObj(rObject)); + pSdrView->AddUndo(o3tl::make_unique<SdrUndoAttrObj>(rObject)); SfxItemSet aSet(pSdrView->GetModel()->GetItemPool(), svl::Items<XATTR_FILLSTYLE, XATTR_FILLBITMAP>{}); diff --git a/vcl/source/edit/texteng.cxx b/vcl/source/edit/texteng.cxx index fb36cb6c3607..287b80c09710 100644 --- a/vcl/source/edit/texteng.cxx +++ b/vcl/source/edit/texteng.cxx @@ -489,7 +489,7 @@ void TextEngine::ImpRemoveChars( const TextPaM& rPaM, sal_Int32 nChars ) break; // for } } - InsertUndo( new TextUndoRemoveChars( this, rPaM, aStr ) ); + InsertUndo( o3tl::make_unique<TextUndoRemoveChars>( this, rPaM, aStr ) ); } mpDoc->RemoveChars( rPaM, nChars ); @@ -504,7 +504,7 @@ TextPaM TextEngine::ImpConnectParagraphs( sal_uInt32 nLeft, sal_uInt32 nRight ) TextNode* pRight = mpDoc->GetNodes()[ nRight ].get(); if ( IsUndoEnabled() && !IsInUndo() ) - InsertUndo( new TextUndoConnectParas( this, nLeft, pLeft->GetText().getLength() ) ); + InsertUndo( o3tl::make_unique<TextUndoConnectParas>( this, nLeft, pLeft->GetText().getLength() ) ); // first lookup Portions, as pRight is gone after ConnectParagraphs TEParaPortion* pLeftPortion = mpTEParaPortions->GetObject( nLeft ); @@ -599,7 +599,7 @@ void TextEngine::ImpRemoveParagraph( sal_uInt32 nPara ) // the Node is handled by Undo and is deleted if appropriate mpDoc->GetNodes().erase( mpDoc->GetNodes().begin() + nPara ); if ( IsUndoEnabled() && !IsInUndo() ) - InsertUndo( new TextUndoDelPara( this, pNode.release(), nPara ) ); + InsertUndo( o3tl::make_unique<TextUndoDelPara>( this, pNode.release(), nPara ) ); mpTEParaPortions->Remove( nPara ); @@ -721,9 +721,9 @@ TextPaM TextEngine::ImpInsertText( sal_Unicode c, const TextSelection& rCurSel, if ( IsUndoEnabled() && !IsInUndo() ) { - TextUndoInsertChars* pNewUndo = new TextUndoInsertChars( this, aPaM, OUString(c) ); + std::unique_ptr<TextUndoInsertChars> pNewUndo(new TextUndoInsertChars( this, aPaM, OUString(c) )); bool bTryMerge = !bDoOverwrite && ( c != ' ' ); - InsertUndo( pNewUndo, bTryMerge ); + InsertUndo( std::move(pNewUndo), bTryMerge ); } TEParaPortion* pPortion = mpTEParaPortions->GetObject( aPaM.GetPara() ); @@ -766,7 +766,7 @@ TextPaM TextEngine::ImpInsertText( const TextSelection& rCurSel, const OUString& { OUString aLine(aText.copy(nStart, nEnd-nStart)); if ( IsUndoEnabled() && !IsInUndo() ) - InsertUndo( new TextUndoInsertChars( this, aPaM, aLine ) ); + InsertUndo( o3tl::make_unique<TextUndoInsertChars>( this, aPaM, aLine ) ); TEParaPortion* pPortion = mpTEParaPortions->GetObject( aPaM.GetPara() ); pPortion->MarkInvalid( aPaM.GetIndex(), aLine.getLength() ); @@ -806,7 +806,7 @@ TextPaM TextEngine::ImpInsertParaBreak( const TextSelection& rCurSel ) TextPaM TextEngine::ImpInsertParaBreak( const TextPaM& rPaM ) { if ( IsUndoEnabled() && !IsInUndo() ) - InsertUndo( new TextUndoSplitPara( this, rPaM.GetPara(), rPaM.GetIndex() ) ); + InsertUndo( o3tl::make_unique<TextUndoSplitPara>( this, rPaM.GetPara(), rPaM.GetIndex() ) ); TextNode* pNode = mpDoc->GetNodes()[ rPaM.GetPara() ].get(); bool bFirstParaContentChanged = rPaM.GetIndex() < pNode->GetText().getLength(); @@ -1313,10 +1313,10 @@ void TextEngine::UndoActionEnd() GetUndoManager().LeaveListAction(); } -void TextEngine::InsertUndo( TextUndo* pUndo, bool bTryMerge ) +void TextEngine::InsertUndo( std::unique_ptr<TextUndo> pUndo, bool bTryMerge ) { SAL_WARN_IF( IsInUndo(), "vcl", "InsertUndo: in Undo mode!" ); - GetUndoManager().AddUndoAction( pUndo, bTryMerge ); + GetUndoManager().AddUndoAction( std::move(pUndo), bTryMerge ); } void TextEngine::ResetUndo() |