diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-04-10 16:07:49 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-04-11 08:42:59 +0200 |
commit | ff8442fd85f2e281a564e3dc832a751a3a9c3072 (patch) | |
tree | 05d4a59e914d53a357f99a8ce6146cb3e35f47c3 /sc | |
parent | 672660031e4ca38205e2068b1e321268a844a68b (diff) |
pass EditTextObject around using std::unique_ptr
Change-Id: I71f4529c2e02fd0ac2561191e4cb35e18e206037
Reviewed-on: https://gerrit.libreoffice.org/52682
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
47 files changed, 142 insertions, 141 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 07bcdc15f855..9a10e90a9c61 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -327,8 +327,8 @@ public: SCROW nRow, SCTAB nTab, const OUString& rString, formula::FormulaGrammar::AddressConvention eConv, const ScSetStringParam* pParam = nullptr ); - void SetEditText( SCROW nRow, EditTextObject* pEditText ); - void SetEditText( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, EditTextObject* pEditText ); + void SetEditText( SCROW nRow, std::unique_ptr<EditTextObject> pEditText ); + void SetEditText( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, std::unique_ptr<EditTextObject> pEditText ); void SetEditText( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, const EditTextObject& rEditText ); void SetEditText( SCROW nRow, const EditTextObject& rEditText, const SfxItemPool* pEditPool ); void SetFormula( SCROW nRow, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram ); diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 4ed169e10152..69302890958c 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1053,7 +1053,7 @@ public: * SfxItemPool instance returned from ScDocument::GetEditPool()</i>. * This is very important.</p> */ - SC_DLLPUBLIC bool SetEditText( const ScAddress& rPos, EditTextObject* pEditText ); + SC_DLLPUBLIC bool SetEditText( const ScAddress& rPos, std::unique_ptr<EditTextObject> pEditText ); void SetEditText( const ScAddress& rPos, const EditTextObject& rEditText, const SfxItemPool* pEditPool ); SC_DLLPUBLIC void SetEditText( const ScAddress& rPos, const OUString& rStr ); SC_DLLPUBLIC SCROW GetFirstEditTextRow( const ScRange& rRange ) const; diff --git a/sc/inc/documentimport.hxx b/sc/inc/documentimport.hxx index d881da37cf2d..917b2398bfbb 100644 --- a/sc/inc/documentimport.hxx +++ b/sc/inc/documentimport.hxx @@ -95,7 +95,7 @@ public: const ScSetStringParam* pStringParam = nullptr); void setNumericCell(const ScAddress& rPos, double fVal); void setStringCell(const ScAddress& rPos, const OUString& rStr); - void setEditCell(const ScAddress& rPos, EditTextObject* pEditText); + void setEditCell(const ScAddress& rPos, std::unique_ptr<EditTextObject> pEditText); void setFormulaCell( const ScAddress& rPos, const OUString& rFormula, formula::FormulaGrammar::Grammar eGrammar, diff --git a/sc/inc/editdataarray.hxx b/sc/inc/editdataarray.hxx index 37fd1f93407d..810e75e95b54 100644 --- a/sc/inc/editdataarray.hxx +++ b/sc/inc/editdataarray.hxx @@ -36,7 +36,9 @@ public: public: Item() = delete; explicit Item(SCTAB nTab, SCCOL nCol, SCROW nRow, - EditTextObject* pOldData, EditTextObject* pNewData); + std::unique_ptr<EditTextObject> pOldData, std::unique_ptr<EditTextObject> pNewData); + Item(Item const &) = default; + Item(Item&&) = default; ~Item(); const EditTextObject* GetOldData() const; @@ -46,8 +48,8 @@ public: SCROW GetRow() const { return mnRow;} private: - std::shared_ptr<EditTextObject> mpOldData; - std::shared_ptr<EditTextObject> mpNewData; + std::unique_ptr<EditTextObject> mpOldData; + std::unique_ptr<EditTextObject> mpNewData; SCTAB mnTab; SCCOL mnCol; SCROW mnRow; @@ -58,7 +60,7 @@ public: ~ScEditDataArray(); void AddItem(SCTAB nTab, SCCOL nCol, SCROW nRow, - EditTextObject* pOldData, EditTextObject* pNewData); + std::unique_ptr<EditTextObject> pOldData, std::unique_ptr<EditTextObject> pNewData); const Item* First(); const Item* Next(); diff --git a/sc/inc/editutil.hxx b/sc/inc/editutil.hxx index cc96945dfd67..f70453bdec40 100644 --- a/sc/inc/editutil.hxx +++ b/sc/inc/editutil.hxx @@ -67,12 +67,12 @@ public: */ SC_DLLPUBLIC static OUString GetString( const EditTextObject& rEditText, const ScDocument* pDoc ); - static EditTextObject* CreateURLObjectFromURL( + static std::unique_ptr<EditTextObject> CreateURLObjectFromURL( ScDocument& rDoc, const OUString& rURL, const OUString& rText ); static void RemoveCharAttribs( EditTextObject& rEditText, const ScPatternAttr& rAttr ); - static EditTextObject* Clone( const EditTextObject& rSrc, ScDocument& rDestDoc ); + static std::unique_ptr<EditTextObject> Clone( const EditTextObject& rSrc, ScDocument& rDestDoc ); static OUString GetCellFieldValue( const SvxFieldData& rFieldData, const ScDocument* pDoc, Color** ppTextColor ); diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx index 52d5d9cfc7a6..376b0d0fbf5a 100644 --- a/sc/inc/formulacell.hxx +++ b/sc/inc/formulacell.hxx @@ -398,7 +398,7 @@ public: void SetResultError( FormulaError n ); bool IsHyperLinkCell() const; - EditTextObject* CreateURLObject(); + std::unique_ptr<EditTextObject> CreateURLObject(); void GetURLResult( OUString& rURL, OUString& rCellText ); /** Determines whether or not the result string contains more than one paragraph */ diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index cb98a23f94af..d310d998abc7 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -408,7 +408,7 @@ public: bool SetString( SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString& rString, const ScSetStringParam * pParam = nullptr ); - bool SetEditText( SCCOL nCol, SCROW nRow, EditTextObject* pEditText ); + bool SetEditText( SCCOL nCol, SCROW nRow, std::unique_ptr<EditTextObject> pEditText ); void SetEditText( SCCOL nCol, SCROW nRow, const EditTextObject& rEditText, const SfxItemPool* pEditPool ); SCROW GetFirstEditTextRow( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ) const; diff --git a/sc/inc/textuno.hxx b/sc/inc/textuno.hxx index 0ffbcc483949..b31894c253f4 100644 --- a/sc/inc/textuno.hxx +++ b/sc/inc/textuno.hxx @@ -315,7 +315,7 @@ public: virtual ~ScEditEngineTextObj() throw() override; void SetText( const EditTextObject& rTextObject ); - EditTextObject* CreateTextObject(); + std::unique_ptr<EditTextObject> CreateTextObject(); }; // ScCellTextData: shared data between sub objects of a cell text object diff --git a/sc/qa/unit/ucalc_column.cxx b/sc/qa/unit/ucalc_column.cxx index 4a64f695a414..dcf188b11c25 100644 --- a/sc/qa/unit/ucalc_column.cxx +++ b/sc/qa/unit/ucalc_column.cxx @@ -10,6 +10,7 @@ #include "ucalc.hxx" #include <editutil.hxx> #include <cellvalue.hxx> +#include <editeng/editobj.hxx> #include <svl/languageoptions.hxx> void Test::testColumnFindEditCells() diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx index 5b9aafbcb4da..83f101e53750 100644 --- a/sc/source/core/data/attarray.cxx +++ b/sc/source/core/data/attarray.cxx @@ -389,7 +389,7 @@ void ScAttrArray::RemoveCellCharAttribs( SCROW nStartRow, SCROW nEndRow, if (aCell.meType != CELLTYPE_EDIT || !aCell.mpEditText) continue; - EditTextObject* pOldData = nullptr; + std::unique_ptr<EditTextObject> pOldData; if (pDataArray) pOldData = aCell.mpEditText->Clone(); @@ -399,8 +399,8 @@ void ScAttrArray::RemoveCellCharAttribs( SCROW nStartRow, SCROW nEndRow, if (pDataArray) { - EditTextObject* pNewData = aCell.mpEditText->Clone(); - pDataArray->AddItem(nTab, nCol, nRow, pOldData, pNewData); + std::unique_ptr<EditTextObject> pNewData = aCell.mpEditText->Clone(); + pDataArray->AddItem(nTab, nCol, nRow, std::move(pOldData), std::move(pNewData)); } } } diff --git a/sc/source/core/data/attrib.cxx b/sc/source/core/data/attrib.cxx index ee104e0cc08c..4dd0b2218726 100644 --- a/sc/source/core/data/attrib.cxx +++ b/sc/source/core/data/attrib.cxx @@ -389,11 +389,11 @@ ScPageHFItem::ScPageHFItem( const ScPageHFItem& rItem ) pRightArea ( nullptr ) { if ( rItem.pLeftArea ) - pLeftArea.reset(rItem.pLeftArea->Clone()); + pLeftArea = rItem.pLeftArea->Clone(); if ( rItem.pCenterArea ) - pCenterArea.reset(rItem.pCenterArea->Clone()); + pCenterArea = rItem.pCenterArea->Clone(); if ( rItem.pRightArea ) - pRightArea.reset(rItem.pRightArea->Clone()); + pRightArea = rItem.pRightArea->Clone(); } ScPageHFItem::~ScPageHFItem() @@ -425,24 +425,30 @@ bool ScPageHFItem::PutValue( const uno::Any& rVal, sal_uInt8 /* nMemberId */ ) if (pImp.is()) { const EditTextObject* pImpLeft = pImp->GetLeftEditObject(); - pLeftArea.reset( pImpLeft ? pImpLeft->Clone() : nullptr ); + pLeftArea.reset(); + if (pImpLeft) + pLeftArea = pImpLeft->Clone(); const EditTextObject* pImpCenter = pImp->GetCenterEditObject(); - pCenterArea.reset( pImpCenter ? pImpCenter->Clone() : nullptr ); + pCenterArea.reset(); + if (pImpCenter) + pCenterArea = pImpCenter->Clone(); const EditTextObject* pImpRight = pImp->GetRightEditObject(); - pRightArea.reset( pImpRight ? pImpRight->Clone() : nullptr ); + pRightArea.reset(); + if (pImpRight) + pRightArea = pImpRight->Clone(); if ( !pLeftArea || !pCenterArea || !pRightArea ) { // no Text with Null are left ScEditEngineDefaulter aEngine( EditEngine::CreatePool(), true ); if (!pLeftArea) - pLeftArea.reset( aEngine.CreateTextObject() ); + pLeftArea = aEngine.CreateTextObject(); if (!pCenterArea) - pCenterArea.reset( aEngine.CreateTextObject() ); + pCenterArea = aEngine.CreateTextObject(); if (!pRightArea) - pRightArea.reset( aEngine.CreateTextObject() ); + pRightArea = aEngine.CreateTextObject(); } bRet = true; @@ -476,17 +482,17 @@ SfxPoolItem* ScPageHFItem::Clone( SfxItemPool* ) const void ScPageHFItem::SetLeftArea( const EditTextObject& rNew ) { - pLeftArea.reset( rNew.Clone() ); + pLeftArea = rNew.Clone(); } void ScPageHFItem::SetCenterArea( const EditTextObject& rNew ) { - pCenterArea.reset( rNew.Clone() ); + pCenterArea = rNew.Clone(); } void ScPageHFItem::SetRightArea( const EditTextObject& rNew ) { - pRightArea.reset( rNew.Clone() ); + pRightArea = rNew.Clone(); } /** diff --git a/sc/source/core/data/cellvalue.cxx b/sc/source/core/data/cellvalue.cxx index 200b9b3c5282..b131debdb7a2 100644 --- a/sc/source/core/data/cellvalue.cxx +++ b/sc/source/core/data/cellvalue.cxx @@ -212,7 +212,7 @@ ScCellValue::ScCellValue( const ScRefCellValue& rCell ) : meType(rCell.meType), mpString = new svl::SharedString(*rCell.mpString); break; case CELLTYPE_EDIT: - mpEditText = rCell.mpEditText->Clone(); + mpEditText = rCell.mpEditText->Clone().release(); break; case CELLTYPE_FORMULA: mpFormula = rCell.mpFormula->Clone(); @@ -234,7 +234,7 @@ ScCellValue::ScCellValue( const ScCellValue& r ) : meType(r.meType), mfValue(r.m mpString = new svl::SharedString(*r.mpString); break; case CELLTYPE_EDIT: - mpEditText = r.mpEditText->Clone(); + mpEditText = r.mpEditText->Clone().release(); break; case CELLTYPE_FORMULA: mpFormula = r.mpFormula->Clone(); @@ -310,7 +310,7 @@ void ScCellValue::set( const EditTextObject& rEditText ) { clear(); meType = CELLTYPE_EDIT; - mpEditText = rEditText.Clone(); + mpEditText = rEditText.Clone().release(); } void ScCellValue::set( EditTextObject* pEditText ) @@ -341,7 +341,7 @@ void ScCellValue::assign( const ScDocument& rDoc, const ScAddress& rPos ) break; case CELLTYPE_EDIT: if (aRefVal.mpEditText) - mpEditText = aRefVal.mpEditText->Clone(); + mpEditText = aRefVal.mpEditText->Clone().release(); break; case CELLTYPE_VALUE: mfValue = aRefVal.mfValue; @@ -376,14 +376,14 @@ void ScCellValue::assign(const ScCellValue& rOther, ScDocument& rDestDoc, ScClon if (bNewControl) rEngine.SetControlWord(nControl | nSpellControl); rEngine.SetText(*rOther.mpEditText); - mpEditText = rEngine.CreateTextObject(); + mpEditText = rEngine.CreateTextObject().release(); if (bNewControl) rEngine.SetControlWord(nControl); } else { rEngine.SetText(*rOther.mpEditText); - mpEditText = rEngine.CreateTextObject(); + mpEditText = rEngine.CreateTextObject().release(); } } break; @@ -444,7 +444,7 @@ void ScCellValue::release( ScDocument& rDoc, const ScAddress& rPos ) break; case CELLTYPE_EDIT: // Cell takes the ownership of the text object. - rDoc.SetEditText(rPos, mpEditText); + rDoc.SetEditText(rPos, std::unique_ptr<EditTextObject>(mpEditText)); break; case CELLTYPE_VALUE: rDoc.SetValue(rPos, mfValue); @@ -474,7 +474,7 @@ void ScCellValue::release( ScColumn& rColumn, SCROW nRow, sc::StartListeningType break; case CELLTYPE_EDIT: // Cell takes the ownership of the text object. - rColumn.SetEditText(nRow, mpEditText); + rColumn.SetEditText(nRow, std::unique_ptr<EditTextObject>(mpEditText)); break; case CELLTYPE_VALUE: rColumn.SetValue(nRow, mfValue); diff --git a/sc/source/core/data/cellvalues.cxx b/sc/source/core/data/cellvalues.cxx index 4b3842b74b03..459322e39608 100644 --- a/sc/source/core/data/cellvalues.cxx +++ b/sc/source/core/data/cellvalues.cxx @@ -194,7 +194,7 @@ void CellValues::copyCellsTo( ScColumn& rCol, SCROW nRow ) const for (; it != itEnd; ++it) { const EditTextObject* p = *it; - aVals.push_back(p->Clone()); + aVals.push_back(p->Clone().release()); } itPos = rDest.set(itPos, nCurRow, aVals.begin(), aVals.end()); } diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index 3a1ab1803de3..ae6813988293 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -936,7 +936,7 @@ public: std::vector<EditTextObject*> aCloned; aCloned.reserve(nDataSize); for (; it != itEnd; ++it) - aCloned.push_back(ScEditUtil::Clone(**it, *mrDestCol.GetDoc())); + aCloned.push_back(ScEditUtil::Clone(**it, *mrDestCol.GetDoc()).release()); maDestPos.miCellPos = mrDestCol.GetCellStore().set( maDestPos.miCellPos, nTopRow, aCloned.begin(), aCloned.end()); @@ -1182,9 +1182,9 @@ void ScColumn::CopyCellToDocument( SCROW nSrcRow, SCROW nDestRow, ScColumn& rDes { EditTextObject* p = sc::edittext_block::at(*it->data, aPos.second); if (pDocument == rDestCol.GetDoc()) - rDestCol.maCells.set(nDestRow, p->Clone()); + rDestCol.maCells.set(nDestRow, p->Clone().release()); else - rDestCol.maCells.set(nDestRow, ScEditUtil::Clone(*p, *rDestCol.GetDoc())); + rDestCol.maCells.set(nDestRow, ScEditUtil::Clone(*p, *rDestCol.GetDoc()).release()); } break; case sc::element_type_formula: @@ -1483,7 +1483,7 @@ class CopyByCloneHandler EditEngine& rEngine = mrDestCol.GetDoc()->GetEditEngine(); rEngine.SetText(aStr.getString()); maDestPos.miCellPos = - mrDestCol.GetCellStore().set(maDestPos.miCellPos, nRow, rEngine.CreateTextObject()); + mrDestCol.GetCellStore().set(maDestPos.miCellPos, nRow, rEngine.CreateTextObject().release()); } else { @@ -1627,7 +1627,7 @@ public: std::vector<EditTextObject*> aCloned; aCloned.reserve(nDataSize); for (; it != itEnd; ++it) - aCloned.push_back(ScEditUtil::Clone(**it, *mrDestCol.GetDoc())); + aCloned.push_back(ScEditUtil::Clone(**it, *mrDestCol.GetDoc()).release()); maDestPos.miCellPos = mrDestCol.GetCellStore().set( maDestPos.miCellPos, nRow, aCloned.begin(), aCloned.end()); diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index 415c1203c821..ba3896ddcc35 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -1107,7 +1107,7 @@ public: // Overwrite the existing object. delete pObj; - pObj = mpEngine->CreateTextObject(); + pObj = mpEngine->CreateTextObject().release(); } else // create String { diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 2907532f961e..114b132d797f 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -1359,7 +1359,7 @@ public: void operator() (size_t nRow, const EditTextObject* p) { - miNewCellsPos = maNewCells.set(miNewCellsPos, nRow-mnRowOffset, p->Clone()); + miNewCellsPos = maNewCells.set(miNewCellsPos, nRow-mnRowOffset, p->Clone().release()); } void operator() (size_t nRow, const ScFormulaCell* p) @@ -1475,7 +1475,7 @@ public: { EditTextObject* pObj = sc::edittext_block::at(*aPos.first->data, aPos.second); miNewCellsPos = maNewCells.set( - miNewCellsPos, nDestRow-mnRowOffset, pObj->Clone()); + miNewCellsPos, nDestRow-mnRowOffset, pObj->Clone().release()); } break; case sc::element_type_formula: @@ -1877,22 +1877,22 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const OUString& rString, return bNumFmtSet; } -void ScColumn::SetEditText( SCROW nRow, EditTextObject* pEditText ) +void ScColumn::SetEditText( SCROW nRow, std::unique_ptr<EditTextObject> pEditText ) { pEditText->NormalizeString(GetDoc()->GetSharedStringPool()); sc::CellStoreType::iterator it = GetPositionToInsert(nRow); - maCells.set(it, nRow, pEditText); + maCells.set(it, nRow, pEditText.release()); maCellTextAttrs.set(nRow, sc::CellTextAttr()); CellStorageModified(); BroadcastNewCell(nRow); } -void ScColumn::SetEditText( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, EditTextObject* pEditText ) +void ScColumn::SetEditText( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, std::unique_ptr<EditTextObject> pEditText ) { pEditText->NormalizeString(GetDoc()->GetSharedStringPool()); rBlockPos.miCellPos = GetPositionToInsert(rBlockPos.miCellPos, nRow); - rBlockPos.miCellPos = maCells.set(rBlockPos.miCellPos, nRow, pEditText); + rBlockPos.miCellPos = maCells.set(rBlockPos.miCellPos, nRow, pEditText.release()); rBlockPos.miCellTextAttrPos = maCellTextAttrs.set( rBlockPos.miCellTextAttrPos, nRow, sc::CellTextAttr()); diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx index 3c8871f7b111..832351d275a7 100644 --- a/sc/source/core/data/column4.cxx +++ b/sc/source/core/data/column4.cxx @@ -261,7 +261,7 @@ void ScColumn::CopyOneCellFromClip( sc::CopyFromClipContext& rCxt, SCROW nRow1, std::vector<EditTextObject*> aStrs; aStrs.reserve(nDestSize); for (size_t i = 0; i < nDestSize; ++i) - aStrs.push_back(rSrcCell.mpEditText->Clone()); + aStrs.push_back(rSrcCell.mpEditText->Clone().release()); pBlockPos->miCellPos = maCells.set(pBlockPos->miCellPos, nRow1, aStrs.begin(), aStrs.end()); diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx index f292d4bd6197..8f42651d2a6f 100644 --- a/sc/source/core/data/dociter.cxx +++ b/sc/source/core/data/dociter.cxx @@ -987,7 +987,7 @@ ScCellValue ScCellIterator::getCellValue() const aRet.mpString = new svl::SharedString(*maCurCell.mpString); break; case CELLTYPE_EDIT: - aRet.mpEditText = maCurCell.mpEditText->Clone(); + aRet.mpEditText = maCurCell.mpEditText->Clone().release(); break; case CELLTYPE_VALUE: aRet.mfValue = maCurCell.mfValue; diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 9bf363cec196..ace7ed8f0f7a 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -3393,15 +3393,14 @@ bool ScDocument::SetString( return SetString(rPos.Col(), rPos.Row(), rPos.Tab(), rString, pParam); } -bool ScDocument::SetEditText( const ScAddress& rPos, EditTextObject* pEditText ) +bool ScDocument::SetEditText( const ScAddress& rPos, std::unique_ptr<EditTextObject> pEditText ) { if (!TableExists(rPos.Tab())) { - delete pEditText; return false; } - return maTabs[rPos.Tab()]->SetEditText(rPos.Col(), rPos.Row(), pEditText); + return maTabs[rPos.Tab()]->SetEditText(rPos.Col(), rPos.Row(), std::move(pEditText)); } void ScDocument::SetEditText( const ScAddress& rPos, const EditTextObject& rEditText, const SfxItemPool* pEditPool ) diff --git a/sc/source/core/data/documentimport.cxx b/sc/source/core/data/documentimport.cxx index 3db030880f1b..55aaadae1ce7 100644 --- a/sc/source/core/data/documentimport.cxx +++ b/sc/source/core/data/documentimport.cxx @@ -258,7 +258,7 @@ void ScDocumentImport::setStringCell(const ScAddress& rPos, const OUString& rStr pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), aSS); } -void ScDocumentImport::setEditCell(const ScAddress& rPos, EditTextObject* pEditText) +void ScDocumentImport::setEditCell(const ScAddress& rPos, std::unique_ptr<EditTextObject> pEditText) { ScTable* pTab = mpImpl->mrDoc.FetchTable(rPos.Tab()); if (!pTab) @@ -271,7 +271,7 @@ void ScDocumentImport::setEditCell(const ScAddress& rPos, EditTextObject* pEditT pEditText->NormalizeString(mpImpl->mrDoc.GetSharedStringPool()); sc::CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells; - pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), pEditText); + pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), pEditText.release()); } void ScDocumentImport::setFormulaCell( diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index ec230436ac26..a8c697f50630 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -49,6 +49,7 @@ #include <tokenarray.hxx> #include <comphelper/threadpool.hxx> +#include <editeng/editobj.hxx> #include <tools/cpuid.hxx> #include <formula/errorcodes.hxx> #include <formula/vectortoken.hxx> @@ -2589,7 +2590,7 @@ bool ScFormulaCell::IsHyperLinkCell() const return pCode && pCode->IsHyperLink(); } -EditTextObject* ScFormulaCell::CreateURLObject() +std::unique_ptr<EditTextObject> ScFormulaCell::CreateURLObject() { OUString aCellText; OUString aURL; diff --git a/sc/source/core/data/stlpool.cxx b/sc/source/core/data/stlpool.cxx index e82566b8d6b5..acd8b90bbaf4 100644 --- a/sc/source/core/data/stlpool.cxx +++ b/sc/source/core/data/stlpool.cxx @@ -222,8 +222,8 @@ void ScStyleSheetPool::CreateStandardStyles() SvxSetItem* pHFSetItem = nullptr; std::unique_ptr<ScEditEngineDefaulter> pEdEngine(new ScEditEngineDefaulter( EditEngine::CreatePool(), true )); pEdEngine->SetUpdateMode( false ); - EditTextObject* pEmptyTxtObj = pEdEngine->CreateTextObject(); - EditTextObject* pTxtObj = nullptr; + std::unique_ptr<EditTextObject> pEmptyTxtObj = pEdEngine->CreateTextObject(); + std::unique_ptr<EditTextObject> pTxtObj; std::unique_ptr<ScPageHFItem> pHeaderItem(new ScPageHFItem( ATTR_PAGE_HEADERRIGHT )); std::unique_ptr<ScPageHFItem> pFooterItem(new ScPageHFItem( ATTR_PAGE_FOOTERRIGHT )); ScStyleSheet* pSheet = nullptr; @@ -296,7 +296,6 @@ void ScStyleSheetPool::CreateStandardStyles() pHeaderItem->SetCenterArea( *pTxtObj ); pHeaderItem->SetRightArea ( *pEmptyTxtObj ); pSet->Put( *pHeaderItem ); - delete pTxtObj; // Footer: // [empty][Page \STR_PAGE\][empty] @@ -310,7 +309,6 @@ void ScStyleSheetPool::CreateStandardStyles() pFooterItem->SetCenterArea( *pTxtObj ); pFooterItem->SetRightArea ( *pEmptyTxtObj ); pSet->Put( *pFooterItem ); - delete pTxtObj; // 2. Report @@ -356,7 +354,6 @@ void ScStyleSheetPool::CreateStandardStyles() pTxtObj = pEdEngine->CreateTextObject(); pHeaderItem->SetLeftArea( *pTxtObj ); pHeaderItem->SetCenterArea( *pEmptyTxtObj ); - delete pTxtObj; aStr = ", "; pEdEngine->SetText( aStr ); pEdEngine->QuickInsertField( SvxFieldItem(SvxTimeField(), EE_FEATURE_FIELD), ESelection(0,2,0,2) ); @@ -364,7 +361,6 @@ void ScStyleSheetPool::CreateStandardStyles() ESelection() ); pTxtObj = pEdEngine->CreateTextObject(); pHeaderItem->SetRightArea( *pTxtObj ); - delete pTxtObj; pSet->Put( *pHeaderItem ); // Footer: @@ -382,9 +378,6 @@ void ScStyleSheetPool::CreateStandardStyles() pFooterItem->SetCenterArea( *pTxtObj ); pFooterItem->SetRightArea ( *pEmptyTxtObj ); pSet->Put( *pFooterItem ); - delete pTxtObj; - - delete pEmptyTxtObj; bHasStandardStyles = true; } diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 340e087bb927..ccbadd6c0f51 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -1409,15 +1409,14 @@ bool ScTable::SetString( SCCOL nCol, SCROW nRow, SCTAB nTabP, const OUString& rS return false; } -bool ScTable::SetEditText( SCCOL nCol, SCROW nRow, EditTextObject* pEditText ) +bool ScTable::SetEditText( SCCOL nCol, SCROW nRow, std::unique_ptr<EditTextObject> pEditText ) { if (!ValidColRow(nCol, nRow)) { - delete pEditText; return false; } - aCol[nCol].SetEditText(nRow, pEditText); + aCol[nCol].SetEditText(nRow, std::move(pEditText)); return true; } diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index 84f6f964a2dd..c8b4ae8124a7 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -718,7 +718,7 @@ void fillSortedColumnArray( break; case CELLTYPE_EDIT: assert(rCell.mpAttr); - rCellStore.push_back(rCell.maCell.mpEditText->Clone()); + rCellStore.push_back(rCell.maCell.mpEditText->Clone().release()); break; case CELLTYPE_FORMULA: { diff --git a/sc/source/core/tool/editdataarray.cxx b/sc/source/core/tool/editdataarray.cxx index 5a794326836e..00a2b6c71dd1 100644 --- a/sc/source/core/tool/editdataarray.cxx +++ b/sc/source/core/tool/editdataarray.cxx @@ -28,9 +28,9 @@ ScEditDataArray::~ScEditDataArray() } void ScEditDataArray::AddItem(SCTAB nTab, SCCOL nCol, SCROW nRow, - EditTextObject* pOldData, EditTextObject* pNewData) + std::unique_ptr<EditTextObject> pOldData, std::unique_ptr<EditTextObject> pNewData) { - maArray.emplace_back(nTab, nCol, nRow, pOldData, pNewData); + maArray.emplace_back(nTab, nCol, nRow, std::move(pOldData), std::move(pNewData)); } const ScEditDataArray::Item* ScEditDataArray::First() @@ -49,13 +49,13 @@ const ScEditDataArray::Item* ScEditDataArray::Next() } ScEditDataArray::Item::Item(SCTAB nTab, SCCOL nCol, SCROW nRow, - EditTextObject* pOldData, EditTextObject* pNewData) : + std::unique_ptr<EditTextObject> pOldData, std::unique_ptr<EditTextObject> pNewData) : + mpOldData(std::move(pOldData)), + mpNewData(std::move(pNewData)), mnTab(nTab), mnCol(nCol), mnRow(nRow) { - mpOldData.reset(pOldData); - mpNewData.reset(pNewData); } ScEditDataArray::Item::~Item() diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx index 3906dd06fbd7..6e4881eb1eab 100644 --- a/sc/source/core/tool/editutil.cxx +++ b/sc/source/core/tool/editutil.cxx @@ -131,7 +131,7 @@ OUString ScEditUtil::GetString( const EditTextObject& rEditText, const ScDocumen } } -EditTextObject* ScEditUtil::CreateURLObjectFromURL( ScDocument& rDoc, const OUString& rURL, const OUString& rText ) +std::unique_ptr<EditTextObject> ScEditUtil::CreateURLObjectFromURL( ScDocument& rDoc, const OUString& rURL, const OUString& rText ) { SvxURLField aUrlField( rURL, rText, SvxURLFormat::AppDefault); EditEngine& rEE = rDoc.GetEditEngine(); @@ -163,9 +163,9 @@ void ScEditUtil::RemoveCharAttribs( EditTextObject& rEditText, const ScPatternAt } } -EditTextObject* ScEditUtil::Clone( const EditTextObject& rObj, ScDocument& rDestDoc ) +std::unique_ptr<EditTextObject> ScEditUtil::Clone( const EditTextObject& rObj, ScDocument& rDestDoc ) { - EditTextObject* pNew = nullptr; + std::unique_ptr<EditTextObject> pNew; EditEngine& rEngine = rDestDoc.GetEditEngine(); if (rObj.HasOnlineSpellErrors()) diff --git a/sc/source/filter/excel/xihelper.cxx b/sc/source/filter/excel/xihelper.cxx index c2b65d12745d..862d9629104d 100644 --- a/sc/source/filter/excel/xihelper.cxx +++ b/sc/source/filter/excel/xihelper.cxx @@ -139,10 +139,10 @@ void XclImpAddressConverter::ConvertRangeList( ScRangeList& rScRanges, namespace { -EditTextObject* lclCreateTextObject( const XclImpRoot& rRoot, +std::unique_ptr<EditTextObject> lclCreateTextObject( const XclImpRoot& rRoot, const XclImpString& rString, XclFontItemType eType, sal_uInt16 nXFIndex ) { - EditTextObject* pTextObj = nullptr; + std::unique_ptr<EditTextObject> pTextObj; const XclImpXFBuffer& rXFBuffer = rRoot.GetXFBuffer(); const XclImpFont* pFirstFont = rXFBuffer.GetFont( nXFIndex ); @@ -215,7 +215,7 @@ EditTextObject* lclCreateTextObject( const XclImpRoot& rRoot, } // namespace -EditTextObject* XclImpStringHelper::CreateTextObject( +std::unique_ptr<EditTextObject> XclImpStringHelper::CreateTextObject( const XclImpRoot& rRoot, const XclImpString& rString ) { return lclCreateTextObject( rRoot, rString, XclFontItemType::Editeng, 0 ); @@ -232,7 +232,7 @@ void XclImpStringHelper::SetToDocument( if (pTextObj.get()) { - rDoc.setEditCell(rPos, pTextObj.release()); + rDoc.setEditCell(rPos, std::move(pTextObj)); } else { @@ -567,7 +567,7 @@ void XclImpHFConverter::CreateCurrObject() { InsertText(); SetAttribs(); - GetCurrObj().reset( mrEE.CreateTextObject() ); + GetCurrObj() = mrEE.CreateTextObject(); } void XclImpHFConverter::SetNewPortion( XclImpHFPortion eNew ) diff --git a/sc/source/filter/inc/richstring.hxx b/sc/source/filter/inc/richstring.hxx index d22aa6d2e2b3..69598b62d362 100644 --- a/sc/source/filter/inc/richstring.hxx +++ b/sc/source/filter/inc/richstring.hxx @@ -235,7 +235,7 @@ public: @param rxText The XText interface of the target object. */ void convert( const css::uno::Reference< css::text::XText >& rxText ) const; - ::EditTextObject* convert( ScEditEngineDefaulter& rEE, const oox::xls::Font* pFont ) const; + std::unique_ptr<EditTextObject> convert( ScEditEngineDefaulter& rEE, const oox::xls::Font* pFont ) const; private: /** Creates, appends, and returns a new empty string portion. */ diff --git a/sc/source/filter/inc/xihelper.hxx b/sc/source/filter/inc/xihelper.hxx index 09a1f698257f..a4e8c2527103 100644 --- a/sc/source/filter/inc/xihelper.hxx +++ b/sc/source/filter/inc/xihelper.hxx @@ -116,7 +116,7 @@ public: XclImpStringHelper() = delete; /** Returns a new edit engine text object. @param nXFIndex Index to XF for first text portion (for escapement). */ - static EditTextObject* CreateTextObject( + static std::unique_ptr<EditTextObject> CreateTextObject( const XclImpRoot& rRoot, const XclImpString& rString ); diff --git a/sc/source/filter/oox/revisionfragment.cxx b/sc/source/filter/oox/revisionfragment.cxx index bd38fb4ffb0d..e63487b0c1db 100644 --- a/sc/source/filter/oox/revisionfragment.cxx +++ b/sc/source/filter/oox/revisionfragment.cxx @@ -141,12 +141,12 @@ protected: { // The value is a rich text string. ScDocument& rDoc = getScDocument(); - EditTextObject* pTextObj = mxRichString->convert(rDoc.GetEditEngine(), nullptr); + std::unique_ptr<EditTextObject> pTextObj = mxRichString->convert(rDoc.GetEditEngine(), nullptr); if (pTextObj) { svl::SharedStringPool& rPool = rDoc.GetSharedStringPool(); pTextObj->NormalizeString(rPool); - mrCellValue.set(pTextObj); + mrCellValue.set(pTextObj.release()); } } } diff --git a/sc/source/filter/oox/richstring.cxx b/sc/source/filter/oox/richstring.cxx index 69a51051c13f..19b2c5531012 100644 --- a/sc/source/filter/oox/richstring.cxx +++ b/sc/source/filter/oox/richstring.cxx @@ -391,7 +391,7 @@ void RichString::convert( const Reference< XText >& rxText ) const } } -::EditTextObject* RichString::convert( ScEditEngineDefaulter& rEE, const oox::xls::Font* pFirstPortionFont ) const +std::unique_ptr<EditTextObject> RichString::convert( ScEditEngineDefaulter& rEE, const oox::xls::Font* pFirstPortionFont ) const { ESelection aSelection; diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx index e553df1130ff..3f7803f8a536 100644 --- a/sc/source/filter/rtf/eeimpars.cxx +++ b/sc/source/filter/rtf/eeimpars.cxx @@ -412,10 +412,10 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu mpDoc->SetString(nCol, nRow, nTab, aStr, &aParam); } } - else if (EditTextObject* pTextObject = IsValidSel(*mpEngine, pE->aSel) ? mpEngine->CreateTextObject(pE->aSel) : nullptr) + else if (std::unique_ptr<EditTextObject> pTextObject = IsValidSel(*mpEngine, pE->aSel) ? mpEngine->CreateTextObject(pE->aSel) : nullptr) { // The cell will own the text object instance. - mpDoc->SetEditText(ScAddress(nCol,nRow,nTab), pTextObject); + mpDoc->SetEditText(ScAddress(nCol,nRow,nTab), std::move(pTextObject)); } if ( !pE->maImageList.empty() ) bHasGraphics |= GraphicSize( nCol, nRow, pE ); diff --git a/sc/source/filter/xml/XMLTrackedChangesContext.cxx b/sc/source/filter/xml/XMLTrackedChangesContext.cxx index 86e1dcba2efc..9710415925c7 100644 --- a/sc/source/filter/xml/XMLTrackedChangesContext.cxx +++ b/sc/source/filter/xml/XMLTrackedChangesContext.cxx @@ -26,6 +26,7 @@ #include <textuno.hxx> #include <editutil.hxx> #include <document.hxx> +#include <editeng/editobj.hxx> #include <xmloff/xmltoken.hxx> #include <xmloff/xmlnmspe.hxx> #include <xmloff/nmspmap.hxx> @@ -930,7 +931,7 @@ void SAL_CALL ScXMLChangeCellContext::endFastElement( sal_Int32 /*nElement*/ ) // The cell will own the text object instance. mrOldCell.meType = CELLTYPE_EDIT; - mrOldCell.mpEditText = mpEditTextObj->CreateTextObject(); + mrOldCell.mpEditText = mpEditTextObj->CreateTextObject().release(); GetScImport().GetTextImport()->ResetCursor(); mpEditTextObj.clear(); } diff --git a/sc/source/ui/Accessibility/AccessiblePageHeaderArea.cxx b/sc/source/ui/Accessibility/AccessiblePageHeaderArea.cxx index 3eb0b30fde23..2bd2d38664e6 100644 --- a/sc/source/ui/Accessibility/AccessiblePageHeaderArea.cxx +++ b/sc/source/ui/Accessibility/AccessiblePageHeaderArea.cxx @@ -53,7 +53,7 @@ ScAccessiblePageHeaderArea::ScAccessiblePageHeaderArea( bool bHeader, SvxAdjust eAdjust) : ScAccessibleContextBase(rxParent, AccessibleRole::TEXT), - mpEditObj(pEditObj->Clone()), + mpEditObj(pEditObj->Clone().release()), mpTextHelper(nullptr), mpViewShell(pViewShell), mbHeader(bHeader), diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx index b78a2a18c1c4..5ac088044ac6 100644 --- a/sc/source/ui/app/inputhdl.cxx +++ b/sc/source/ui/app/inputhdl.cxx @@ -2821,7 +2821,7 @@ void ScInputHandler::EnterHandler( ScEnterMode nBlockMode ) if (bAttrib) { mpEditEngine->ClearSpellErrors(); - pObject.reset(mpEditEngine->CreateTextObject()); + pObject = mpEditEngine->CreateTextObject(); } else if (bAutoComplete) // Adjust Upper/Lower case { @@ -3890,9 +3890,9 @@ bool ScInputHandler::GetTextAndFields( ScEditEngineDefaulter& rDestEngine ) if ( eFieldState == SfxItemState::DONTCARE || eFieldState == SfxItemState::SET ) { // Copy content - EditTextObject* pObj = mpEditEngine->CreateTextObject(); + std::unique_ptr<EditTextObject> pObj = mpEditEngine->CreateTextObject(); rDestEngine.SetText(*pObj); - delete pObj; + pObj.reset(); // Delete attributes for (sal_Int32 i=0; i<nParCnt; i++) @@ -4055,7 +4055,9 @@ ScInputHdlState& ScInputHdlState::operator=( const ScInputHdlState& r ) aStartPos = r.aStartPos; aEndPos = r.aEndPos; aString = r.aString; - pEditData.reset( r.pEditData ? r.pEditData->Clone() : nullptr ); + pEditData.reset(); + if (r.pEditData) + pEditData = r.pEditData->Clone(); return *this; } diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index d6372e89ab0c..b517bab9911e 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -58,6 +58,7 @@ #include <unotools/configmgr.hxx> #include <vcl/svapp.hxx> #include <vcl/weld.hxx> +#include <editeng/editobj.hxx> #include <memory> #include <osl/endian.h> diff --git a/sc/source/ui/inc/tphfedit.hxx b/sc/source/ui/inc/tphfedit.hxx index 3d1f9d20c09c..741f432d95bc 100644 --- a/sc/source/ui/inc/tphfedit.hxx +++ b/sc/source/ui/inc/tphfedit.hxx @@ -59,7 +59,7 @@ public: void SetFont( const ScPatternAttr& rPattern ); using Control::SetText; void SetText( const EditTextObject& rTextObject ); - EditTextObject* CreateTextObject(); + std::unique_ptr<EditTextObject> CreateTextObject(); void SetCharAttributes(); void InsertField( const SvxFieldItem& rFld ); diff --git a/sc/source/ui/inc/undocell.hxx b/sc/source/ui/inc/undocell.hxx index cbdd78a7c4b9..67306e5d6e71 100644 --- a/sc/source/ui/inc/undocell.hxx +++ b/sc/source/ui/inc/undocell.hxx @@ -61,7 +61,7 @@ public: /** once the objects are passed to this class, their life-cycle is managed by this class; the calling function must pass new'ed objects to this method. */ - void SetEditData( EditTextObject* pOld, EditTextObject* pNew ); + void SetEditData( std::unique_ptr<EditTextObject> pOld, std::unique_ptr<EditTextObject> pNew ); private: SCCOL nCol; @@ -70,10 +70,10 @@ private: ScPatternAttr* pOldPattern; ScPatternAttr* pNewPattern; ScPatternAttr* pApplyPattern; - std::shared_ptr<EditTextObject> pOldEditData; - std::shared_ptr<EditTextObject> pNewEditData; + std::unique_ptr<EditTextObject> pOldEditData; + std::unique_ptr<EditTextObject> pNewEditData; - void DoChange( const ScPatternAttr* pWhichPattern, const std::shared_ptr<EditTextObject>& pEditData ) const; + void DoChange( const ScPatternAttr* pWhichPattern, const std::unique_ptr<EditTextObject>& pEditData ) const; }; class ScUndoEnterData: public ScSimpleUndo @@ -94,7 +94,7 @@ public: ScUndoEnterData( ScDocShell* pNewDocShell, const ScAddress& rPos, - ValuesType& rOldValues, const OUString& rNewStr, EditTextObject* pObj ); + ValuesType& rOldValues, const OUString& rNewStr, std::unique_ptr<EditTextObject> pObj ); virtual void Undo() override; virtual void Redo() override; diff --git a/sc/source/ui/pagedlg/scuitphfedit.cxx b/sc/source/ui/pagedlg/scuitphfedit.cxx index 671012b2395a..04691a62f84b 100644 --- a/sc/source/ui/pagedlg/scuitphfedit.cxx +++ b/sc/source/ui/pagedlg/scuitphfedit.cxx @@ -216,16 +216,13 @@ void ScHFEditPage::Reset( const SfxItemSet* rCoreSet ) bool ScHFEditPage::FillItemSet( SfxItemSet* rCoreSet ) { ScPageHFItem aItem( nWhich ); - EditTextObject* pLeft = m_pWndLeft->CreateTextObject(); - EditTextObject* pCenter = m_pWndCenter->CreateTextObject(); - EditTextObject* pRight = m_pWndRight->CreateTextObject(); + std::unique_ptr<EditTextObject> pLeft = m_pWndLeft->CreateTextObject(); + std::unique_ptr<EditTextObject> pCenter = m_pWndCenter->CreateTextObject(); + std::unique_ptr<EditTextObject> pRight = m_pWndRight->CreateTextObject(); aItem.SetLeftArea ( *pLeft ); aItem.SetCenterArea( *pCenter ); aItem.SetRightArea ( *pRight ); - delete pLeft; - delete pCenter; - delete pRight; rCoreSet->Put( aItem ); @@ -316,9 +313,9 @@ void ScHFEditPage::SetSelectDefinedList() OUString aCenterEntry; OUString aRightEntry; - pLeftObj.reset(m_pWndLeft->GetEditEngine()->CreateTextObject()); - pCenterObj.reset(m_pWndCenter->GetEditEngine()->CreateTextObject()); - pRightObj.reset(m_pWndRight->GetEditEngine()->CreateTextObject()); + pLeftObj = m_pWndLeft->GetEditEngine()->CreateTextObject(); + pCenterObj = m_pWndCenter->GetEditEngine()->CreateTextObject(); + pRightObj = m_pWndRight->GetEditEngine()->CreateTextObject(); bool bFound = false; @@ -505,8 +502,7 @@ bool ScHFEditPage::IsPageEntry(EditEngine*pEngine, const EditTextObject* pTextOb { aSel.nStartPos = aSel.nEndPos; aSel.nEndPos++; - std::unique_ptr< EditTextObject > pPageObj; - pPageObj.reset(pEngine->CreateTextObject(aSel)); + std::unique_ptr< EditTextObject > pPageObj = pEngine->CreateTextObject(aSel); if(pPageObj.get() && pPageObj->IsFieldObject() ) { const SvxFieldItem* pFieldItem = pPageObj->GetField(); @@ -598,7 +594,7 @@ void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling) m_pWndCenter->GetEditEngine()->QuickInsertText(aPageOfEntry,ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos)); aSel.nEndPos = aSel.nEndPos + aPageOfEntry.getLength(); m_pWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos)); - pTextObj.reset(m_pWndCenter->GetEditEngine()->CreateTextObject()); + pTextObj = m_pWndCenter->GetEditEngine()->CreateTextObject(); m_pWndCenter->SetText(*pTextObj); if(!bTravelling) m_pWndCenter->GrabFocus(); @@ -638,7 +634,7 @@ void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling) aSel.nStartPos = aSel.nEndPos; aSel.nEndPos = aSel.nEndPos + aPageEntry.getLength(); m_pWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos)); - pTextObj.reset(m_pWndCenter->GetEditEngine()->CreateTextObject()); + pTextObj = m_pWndCenter->GetEditEngine()->CreateTextObject(); m_pWndCenter->SetText(*pTextObj); if(!bTravelling) m_pWndCenter->GrabFocus(); @@ -667,7 +663,7 @@ void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling) m_pWndCenter->GetEditEngine()->QuickInsertText(aCommaSpace,ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos)); aSel.nEndPos = aSel.nEndPos + aCommaSpace.getLength(); m_pWndCenter->GetEditEngine()->QuickInsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos)); - pTextObj.reset(m_pWndCenter->GetEditEngine()->CreateTextObject()); + pTextObj = m_pWndCenter->GetEditEngine()->CreateTextObject(); m_pWndCenter->SetText(*pTextObj); if(!bTravelling) m_pWndCenter->GrabFocus(); @@ -687,7 +683,7 @@ void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling) m_pWndCenter->GetEditEngine()->QuickInsertText(aCommaSpace,ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos)); aSel.nEndPos = aSel.nEndPos + aCommaSpace.getLength(); m_pWndCenter->GetEditEngine()->QuickInsertField( SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos)); - pTextObj.reset(m_pWndCenter->GetEditEngine()->CreateTextObject()); + pTextObj = m_pWndCenter->GetEditEngine()->CreateTextObject(); m_pWndCenter->SetText(*pTextObj); if(!bTravelling) m_pWndCenter->GrabFocus(); diff --git a/sc/source/ui/pagedlg/tphfedit.cxx b/sc/source/ui/pagedlg/tphfedit.cxx index d3bc68faabbb..819a16f26f18 100644 --- a/sc/source/ui/pagedlg/tphfedit.cxx +++ b/sc/source/ui/pagedlg/tphfedit.cxx @@ -141,7 +141,7 @@ void ScEditWindow::SetNumType(SvxNumType eNumType) pEdEngine->UpdateFields(); } -EditTextObject* ScEditWindow::CreateTextObject() +std::unique_ptr<EditTextObject> ScEditWindow::CreateTextObject() { // reset paragraph attributes // (GetAttribs at creation of format dialog always returns the set items) diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx index 0af818eb34c4..16e022bfaea9 100644 --- a/sc/source/ui/undo/undocell.cxx +++ b/sc/source/ui/undo/undocell.cxx @@ -100,13 +100,13 @@ OUString ScUndoCursorAttr::GetComment() const return ScGlobal::GetRscString( STR_UNDO_CURSORATTR ); // "Attribute" } -void ScUndoCursorAttr::SetEditData( EditTextObject* pOld, EditTextObject* pNew ) +void ScUndoCursorAttr::SetEditData( std::unique_ptr<EditTextObject> pOld, std::unique_ptr<EditTextObject> pNew ) { - pOldEditData.reset(pOld); - pNewEditData.reset(pNew); + pOldEditData = std::move(pOld); + pNewEditData = std::move(pNew); } -void ScUndoCursorAttr::DoChange( const ScPatternAttr* pWhichPattern, const shared_ptr<EditTextObject>& pEditData ) const +void ScUndoCursorAttr::DoChange( const ScPatternAttr* pWhichPattern, const std::unique_ptr<EditTextObject>& pEditData ) const { ScDocument& rDoc = pDocShell->GetDocument(); ScAddress aPos(nCol, nRow, nTab); @@ -165,10 +165,10 @@ ScUndoEnterData::Value::Value() : mnTab(-1), mbHasFormat(false), mnFormat(0) {} ScUndoEnterData::ScUndoEnterData( ScDocShell* pNewDocShell, const ScAddress& rPos, ValuesType& rOldValues, - const OUString& rNewStr, EditTextObject* pObj ) : + const OUString& rNewStr, std::unique_ptr<EditTextObject> pObj ) : ScSimpleUndo( pNewDocShell ), maNewString(rNewStr), - mpNewEditData(pObj), + mpNewEditData(std::move(pObj)), mnEndChangeAction(0), maPos(rPos) { diff --git a/sc/source/ui/unoobj/editsrc.cxx b/sc/source/ui/unoobj/editsrc.cxx index a333bcde08df..b30fb6909b23 100644 --- a/sc/source/ui/unoobj/editsrc.cxx +++ b/sc/source/ui/unoobj/editsrc.cxx @@ -178,9 +178,9 @@ void ScAnnotationEditSource::UpdateData() if( SdrObject* pObj = GetCaptionObj() ) { - EditTextObject* pEditObj = pEditEngine->CreateTextObject(); + std::unique_ptr<EditTextObject> pEditObj = pEditEngine->CreateTextObject(); OutlinerParaObject* pOPO = new OutlinerParaObject( *pEditObj ); - delete pEditObj; + pEditObj.reset(); pOPO->SetOutlinerMode( OutlinerMode::TextObject ); pObj->NbcSetOutlinerParaObject( pOPO ); pObj->ActionChanged(); diff --git a/sc/source/ui/unoobj/fielduno.cxx b/sc/source/ui/unoobj/fielduno.cxx index afc4fb7e3cde..6b00a69097e6 100644 --- a/sc/source/ui/unoobj/fielduno.cxx +++ b/sc/source/ui/unoobj/fielduno.cxx @@ -197,9 +197,8 @@ ScUnoEditEngine::ScUnoEditEngine(ScEditEngineDefaulter* pSource) , nFieldPos(0) , nFieldIndex(0) { - EditTextObject* pData = pSource->CreateTextObject(); + std::unique_ptr<EditTextObject> pData = pSource->CreateTextObject(); SetText( *pData ); - delete pData; } OUString ScUnoEditEngine::CalcFieldValue( const SvxFieldItem& rField, diff --git a/sc/source/ui/unoobj/textuno.cxx b/sc/source/ui/unoobj/textuno.cxx index 5d4576636105..c1071f85d57c 100644 --- a/sc/source/ui/unoobj/textuno.cxx +++ b/sc/source/ui/unoobj/textuno.cxx @@ -253,13 +253,13 @@ void ScHeaderFooterTextData::UpdateData() { if (pEditEngine) { - mpTextObj.reset(pEditEngine->CreateTextObject()); + mpTextObj = pEditEngine->CreateTextObject(); } } void ScHeaderFooterTextData::UpdateData(EditEngine& rEditEngine) { - mpTextObj.reset(rEditEngine.CreateTextObject()); + mpTextObj = rEditEngine.CreateTextObject(); bDataValid = false; } @@ -859,7 +859,7 @@ void ScEditEngineTextObj::SetText( const EditTextObject& rTextObject ) SetSelection( aSel ); } -EditTextObject* ScEditEngineTextObj::CreateTextObject() +std::unique_ptr<EditTextObject> ScEditEngineTextObj::CreateTextObject() { return GetEditEngine()->CreateTextObject(); } diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index 309ef81bb842..e6d9ad63a164 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -5180,9 +5180,9 @@ bool ScGridWindow::GetEditUrl( const Point& rPos, // cell ( or other type ? ) with a hyperlink associated with it. { if (sURL.isEmpty()) - pTextObj.reset(aCell.mpFormula->CreateURLObject()); + pTextObj = aCell.mpFormula->CreateURLObject(); else - pTextObj.reset(ScEditUtil::CreateURLObjectFromURL(rDoc, sURL, sURL)); + pTextObj = ScEditUtil::CreateURLObjectFromURL(rDoc, sURL, sURL); if (pTextObj.get()) pEngine->SetText(*pTextObj); diff --git a/sc/source/ui/view/viewfun4.cxx b/sc/source/ui/view/viewfun4.cxx index e0de8ce0383a..4312e4616e88 100644 --- a/sc/source/ui/view/viewfun4.cxx +++ b/sc/source/ui/view/viewfun4.cxx @@ -412,9 +412,10 @@ void ScViewFunc::DoThesaurus() if (aOldText.meType == CELLTYPE_EDIT) { // The cell will own the text object instance. - EditTextObject* pText = pThesaurusEngine->CreateTextObject(); - if (rDoc.SetEditText(ScAddress(nCol,nRow,nTab), pText)) - aNewText.set(*pText); + std::unique_ptr<EditTextObject> pText = pThesaurusEngine->CreateTextObject(); + auto tmp = pText.get(); + if (rDoc.SetEditText(ScAddress(nCol,nRow,nTab), std::move(pText))) + aNewText.set(*tmp); } else { diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index 8e516e358593..a9cb736e67bd 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -684,7 +684,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab, // undo - EditTextObject* pUndoData = nullptr; + std::unique_ptr<EditTextObject> pUndoData; ScUndoEnterData::ValuesType aOldValues; if (bRecord && !bSimple) @@ -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, pUndoData)); + new ScUndoEnterData(pDocSh, ScAddress(nCol,nRow,nTab), aOldValues, aString, std::move(pUndoData))); } HideAllCursors(); @@ -1212,8 +1212,8 @@ void ScViewFunc::ApplySelectionPattern( const ScPatternAttr& rAttr, bool bCursor SCROW nRow = rViewData.GetCurY(); SCTAB nTab = rViewData.GetTabNo(); - EditTextObject* pOldEditData = nullptr; - EditTextObject* pNewEditData = nullptr; + std::unique_ptr<EditTextObject> pOldEditData; + std::unique_ptr<EditTextObject> pNewEditData; ScAddress aPos(nCol, nRow, nTab); ScRefCellValue aCell(rDoc, aPos); if (aCell.meType == CELLTYPE_EDIT) @@ -1236,7 +1236,7 @@ void ScViewFunc::ApplySelectionPattern( const ScPatternAttr& rAttr, bool bCursor { ScUndoCursorAttr* pUndo = new ScUndoCursorAttr( pDocSh, nCol, nRow, nTab, pOldPat.get(), pNewPat, &rAttr ); - pUndo->SetEditData(pOldEditData, pNewEditData); + pUndo->SetEditData(std::move(pOldEditData), std::move(pNewEditData)); pDocSh->GetUndoManager()->AddUndoAction(pUndo); } pOldPat.reset(); // is copied in undo (Pool) |