From fcf0bcc0f98c25ccdd88d2897340a8e6281e095a Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 2 Sep 2026 15:01:59 +0200 Subject: [PATCH] Hold EditTextObject by value in OutlinerParaObjData, not by pointer OutlinerParaObjData is already ref-counted data, no need for further indirection. Unfortunately, this sets off a larger chain of changes than I would have preferred, but we end up storing EditTextObject on the stack much more than before, so that worked out well. Change-Id: Ie7d0ccfbfeec4e6935f2ed6b8ad48aadfe1bac20 Signed-off-by: Noel Grandin Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/10973 Tested-by: Jenkins CPCI Reviewed-by: Mike Kaganski (cherry picked from commit fbf7d1bc7142d3f0e4e5f959983dea065afc5ea3) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/210927 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- editeng/qa/unit/core-test.cxx | 47 ++++++----- editeng/source/editeng/editeng.cxx | 8 +- editeng/source/editeng/editobj.cxx | 3 + editeng/source/editeng/editundo.cxx | 4 +- editeng/source/editeng/editundo.hxx | 6 +- editeng/source/editeng/editview.cxx | 2 +- editeng/source/editeng/impedit.hxx | 11 ++- editeng/source/editeng/impedit4.cxx | 42 +++++----- editeng/source/outliner/outliner.cxx | 16 ++-- editeng/source/outliner/outlobj.cxx | 70 ++++++---------- editeng/source/uno/unofored.cxx | 4 +- forms/source/richtext/richtextengine.cxx | 6 +- include/editeng/editeng.hxx | 8 +- include/editeng/editobj.hxx | 3 + include/editeng/editview.hxx | 2 +- include/editeng/outlobj.hxx | 37 +-------- sc/inc/cellvalue.hxx | 3 +- sc/inc/column.hxx | 4 +- sc/inc/document.hxx | 3 +- sc/inc/editutil.hxx | 4 +- sc/inc/formulacell.hxx | 2 +- sc/inc/textuno.hxx | 2 +- sc/qa/unit/tiledrendering/SheetViewTest.cxx | 2 +- sc/source/core/data/attrib.cxx | 6 +- sc/source/core/data/cellvalue.cxx | 10 ++- sc/source/core/data/clipcontext.cxx | 4 +- sc/source/core/data/column.cxx | 8 +- sc/source/core/data/column2.cxx | 2 +- sc/source/core/data/column3.cxx | 21 +++++ sc/source/core/data/column4.cxx | 4 +- sc/source/core/data/documen2.cxx | 8 +- sc/source/core/data/document.cxx | 9 ++- sc/source/core/data/formulacell.cxx | 2 +- sc/source/core/data/stlpool.cxx | 33 ++++---- sc/source/core/data/table2.cxx | 2 +- sc/source/core/data/table6.cxx | 2 +- sc/source/core/tool/editutil.cxx | 13 ++- sc/source/filter/excel/xicontent.cxx | 2 +- sc/source/filter/excel/xiescher.cxx | 4 +- sc/source/filter/excel/xihelper.cxx | 16 ++-- sc/source/filter/inc/richstring.hxx | 2 +- sc/source/filter/inc/xihelper.hxx | 2 +- sc/source/filter/oox/revisionfragment.cxx | 11 +-- sc/source/filter/oox/richstring.cxx | 2 +- sc/source/filter/oox/worksheethelper.cxx | 4 +- sc/source/filter/orcus/interface.cxx | 3 +- sc/source/filter/rtf/eeimpars.cxx | 5 +- sc/source/filter/xml/xmlcelli.cxx | 2 +- .../TableFillingAndNavigationTools.cxx | 4 +- sc/source/ui/app/inputhdl.cxx | 13 ++- sc/source/ui/docshell/docfunc.cxx | 8 +- sc/source/ui/docshell/impex.cxx | 4 +- sc/source/ui/inc/tphfedit.hxx | 2 +- sc/source/ui/pagedlg/scuitphfedit.cxx | 79 ++++++++----------- sc/source/ui/pagedlg/tphfedit.cxx | 2 +- sc/source/ui/unoobj/fielduno.cxx | 4 +- sc/source/ui/unoobj/textuno.cxx | 6 +- sc/source/ui/view/gridwin.cxx | 10 +-- sc/source/ui/view/spelleng.cxx | 4 +- sc/source/ui/view/viewfun4.cxx | 15 ++-- svx/source/dialog/ClassificationDialog.cxx | 8 +- svx/source/dialog/weldeditview.cxx | 4 +- sw/source/filter/ww8/ww8graf.cxx | 4 +- 63 files changed, 296 insertions(+), 337 deletions(-) diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx index 0d3650b4c5e1..cf979e68f190 100644 --- a/editeng/qa/unit/core-test.cxx +++ b/editeng/qa/unit/core-test.cxx @@ -996,9 +996,9 @@ void Test::testBoldItalicCopyPaste() aEditEngine.QuickSetAttribs(*pSet, ESelection(0, 2, 0, 14)); // Assert changes - std::unique_ptr pEditText1(aEditEngine.CreateTextObject()); + EditTextObject aEditText1(aEditEngine.CreateTextObject()); std::vector aAttrs1; - pEditText1->GetAllSections(aAttrs1); + aEditText1.GetAllSections(aAttrs1); // There should be 3 sections - woBold - wBold - woBold (w - with, wo - without) CPPUNIT_ASSERT_EQUAL(size_t(3), aAttrs1.size()); @@ -1025,9 +1025,9 @@ void Test::testBoldItalicCopyPaste() aEditEngine.QuickSetAttribs(*pSet, ESelection(0, 8, 0, 18)); // Assert changes - std::unique_ptr pEditText2(aEditEngine.CreateTextObject()); + EditTextObject aEditText2(aEditEngine.CreateTextObject()); std::vector aAttrs2; - pEditText2->GetAllSections(aAttrs2); + aEditText2.GetAllSections(aAttrs2); // There should be 5 sections - woBold&woItalic - wBold&woItalic - wBold&wItalic - woBold&wItalic - woBold&woItalic (w - with, wo - without) CPPUNIT_ASSERT_EQUAL(size_t(5), aAttrs2.size()); @@ -1073,9 +1073,9 @@ void Test::testBoldItalicCopyPaste() rDoc.GetParaAsString(sal_Int32(0))); // Check updated text for appropriate Bold/Italics - std::unique_ptr pEditText3(aEditEngine.CreateTextObject()); + EditTextObject aEditText3(aEditEngine.CreateTextObject()); std::vector aAttrs3; - pEditText3->GetAllSections(aAttrs3); + aEditText3.GetAllSections(aAttrs3); // There should be 9 sections - woBold&woItalic - wBold&woItalic - wBold&wItalic - woBold&wItalic - woBold&woItalic - wBold&woItalic // - wBold&wItalic - woBold&wItalic - woBold&woItalic(w - with, wo - without) CPPUNIT_ASSERT_EQUAL(size_t(9), aAttrs3.size()); @@ -1173,9 +1173,9 @@ void Test::testUnderlineCopyPaste() aEditEngine.QuickSetAttribs(*pSet, ESelection(0, 6, 0, 18)); // Assert changes - std::unique_ptr pEditText1(aEditEngine.CreateTextObject()); + EditTextObject aEditText1(aEditEngine.CreateTextObject()); std::vector aAttrs1; - pEditText1->GetAllSections(aAttrs1); + aEditText1.GetAllSections(aAttrs1); // There should be 3 sections - woUnderline - wUnderline - woUnderline (w - with, wo - without) CPPUNIT_ASSERT_EQUAL(size_t(3), aAttrs1.size()); @@ -1209,9 +1209,9 @@ void Test::testUnderlineCopyPaste() CPPUNIT_ASSERT_EQUAL(OUString(aParaText + "textforunder"), rDoc.GetParaAsString(sal_Int32(0))); // Check updated text for appropriate Underline - std::unique_ptr pEditText2(aEditEngine.CreateTextObject()); + EditTextObject aEditText2(aEditEngine.CreateTextObject()); std::vector aAttrs2; - pEditText2->GetAllSections(aAttrs2); + aEditText2.GetAllSections(aAttrs2); // There should be 4 sections - woUnderline - wUnderline - woUnderline - wUnderline (w - with, wo - without) CPPUNIT_ASSERT_EQUAL(size_t(4), aAttrs2.size()); @@ -1330,9 +1330,9 @@ void Test::testParaBoldItalicCopyPaste() aEditEngine.QuickSetAttribs(*pSet, ESelection(1, 5, 1, 19)); // Assert changes - std::unique_ptr pEditText1(aEditEngine.CreateTextObject()); + EditTextObject aEditText1(aEditEngine.CreateTextObject()); std::vector aAttrs1; - pEditText1->GetAllSections(aAttrs1); + aEditText1.GetAllSections(aAttrs1); // There should be 7 sections - woB - wB - woB -woB -wB -woB -woB (w - with, wo - without, B - Bold, I - Italic) CPPUNIT_ASSERT_EQUAL(size_t(7), aAttrs1.size()); @@ -1380,9 +1380,9 @@ void Test::testParaBoldItalicCopyPaste() aEditEngine.QuickSetAttribs(*pSet, ESelection(0, 14, 1, 9)); // Assert changes - std::unique_ptr pEditText2(aEditEngine.CreateTextObject()); + EditTextObject aEditText2(aEditEngine.CreateTextObject()); std::vector aAttrs2; - pEditText2->GetAllSections(aAttrs2); + aEditText2.GetAllSections(aAttrs2); // There should be 9 sections - woB&woI - wB&woI - wB&wI -woB&wI - woB&wI - wB&wI - wB&woI - woB&woI - woB&woI (w - with, wo - without, B - Bold, I - Italic) CPPUNIT_ASSERT_EQUAL(size_t(9), aAttrs2.size()); @@ -1455,9 +1455,9 @@ void Test::testParaBoldItalicCopyPaste() CPPUNIT_ASSERT_EQUAL( u"This is second"_ustr, rDoc.GetParaAsString(sal_Int32(3)) ); // Check updated text for appropriate Bold/Italics - std::unique_ptr pEditText3(aEditEngine.CreateTextObject()); + EditTextObject aEditText3(aEditEngine.CreateTextObject()); std::vector aAttrs3; - pEditText3->GetAllSections(aAttrs3); + aEditText3.GetAllSections(aAttrs3); // There should be 15 sections - woB&woI - wB&woI - wB&wI -woB&wI - woB&wI - wB&wI - wB&woI - woB&woI - woB&woI // - wB&woI - wB&wI - woB&wI - -woB&wI - wB&wI - wB&woI (w - with, wo - without, B - Bold, I - Italic) CPPUNIT_ASSERT_EQUAL(size_t(15), aAttrs3.size()); @@ -1621,10 +1621,9 @@ void Test::testSectionAttributes() static_cast(1), pSet->Count()); aEngine.QuickSetAttribs(*pSet, ESelection(0, 3, 0, 9)); // 'bbbccc' - std::unique_ptr pEditText(aEngine.CreateTextObject()); - CPPUNIT_ASSERT_MESSAGE("Failed to create text object.", pEditText); + EditTextObject aEditText(aEngine.CreateTextObject()); std::vector aAttrs; - pEditText->GetAllSections(aAttrs); + aEditText.GetAllSections(aAttrs); // Now, we should have a total of 3 sections. CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be 3 sections.", static_cast(3), @@ -1670,10 +1669,9 @@ void Test::testSectionAttributes() aEngine.QuickSetAttribs(*pSet, ESelection(2, 0, 2, 3)); aEngine.QuickSetAttribs(*pSet, ESelection(4, 0, 4, 5)); - std::unique_ptr pEditText(aEngine.CreateTextObject()); - CPPUNIT_ASSERT_MESSAGE("Failed to create text object.", pEditText); + EditTextObject aEditText(aEngine.CreateTextObject()); std::vector aAttrs; - pEditText->GetAllSections(aAttrs); + aEditText.GetAllSections(aAttrs); CPPUNIT_ASSERT_EQUAL(size_t(5), aAttrs.size()); // 1st, 3rd and 5th sections should correspond with 1st, 3rd and 5th paragraphs. @@ -1725,10 +1723,9 @@ void Test::testSectionAttributes() aEngine.QuickDelete(ESelection(0, 0, 1, 3)); CPPUNIT_ASSERT_EQUAL(static_cast(1), aEngine.GetParagraphCount()); - std::unique_ptr pEditText(aEngine.CreateTextObject()); - CPPUNIT_ASSERT_MESSAGE("Failed to create text object.", pEditText); + EditTextObject aEditText(aEngine.CreateTextObject()); std::vector aAttrs; - pEditText->GetAllSections(aAttrs); + aEditText.GetAllSections(aAttrs); CPPUNIT_ASSERT_EQUAL(static_cast(1), aAttrs.size()); diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx index 4c0694f8f424..0abffe21478a 100644 --- a/editeng/source/editeng/editeng.cxx +++ b/editeng/source/editeng/editeng.cxx @@ -833,17 +833,17 @@ void EditEngine::Write( SvStream& rOutput, EETextFormat eFormat ) getImpl().Write(rOutput, eFormat); } -std::unique_ptr EditEngine::CreateTextObject() +EditTextObject EditEngine::CreateTextObject() { return getImpl().CreateTextObject(); } -std::unique_ptr EditEngine::CreateTextObject( const ESelection& rESelection ) +EditTextObject EditEngine::CreateTextObject( const ESelection& rESelection ) { return getImpl().CreateTextObject(CreateSelection(rESelection)); } -std::unique_ptr EditEngine::GetEmptyTextObject() +EditTextObject EditEngine::GetEmptyTextObject() { return getImpl().GetEmptyTextObject(); } @@ -920,7 +920,7 @@ void EditEngine::SetEndPasteOrDropHdl( const Link& rLink getImpl().maEndPasteOrDropHdl = rLink; } -std::unique_ptr EditEngine::CreateTextObject( sal_Int32 nPara, sal_Int32 nParas ) +EditTextObject EditEngine::CreateTextObject( sal_Int32 nPara, sal_Int32 nParas ) { return getImpl().CreateTextObject(nPara, nParas); } diff --git a/editeng/source/editeng/editobj.cxx b/editeng/source/editeng/editobj.cxx index e2af1b50afc4..2ecc95e4df83 100644 --- a/editeng/source/editeng/editobj.cxx +++ b/editeng/source/editeng/editobj.cxx @@ -297,6 +297,8 @@ EditTextObject::EditTextObject( const EditTextObject& r ) maContents.push_back(std::unique_ptr(new ContentInfo(*content, *mpPool))); } +EditTextObject::EditTextObject( EditTextObject&& ) noexcept = default; + EditTextObject::~EditTextObject() { ClearPortionInfo(); @@ -306,6 +308,7 @@ EditTextObject::~EditTextObject() maContents.clear(); } +EditTextObject& EditTextObject::operator=(EditTextObject&&) = default; void EditTextObject::SetUserType( OutlinerMode n ) { diff --git a/editeng/source/editeng/editundo.cxx b/editeng/source/editeng/editundo.cxx index 47f5ac5b246f..e728f4855e86 100644 --- a/editeng/source/editeng/editundo.cxx +++ b/editeng/source/editeng/editundo.cxx @@ -605,9 +605,9 @@ void EditUndoTransliteration::Undo() aDelSel.Max() = aSel.Min(); aDelSel.Max().GetNode()->GetCharAttribs().DeleteEmptyAttribs(); EditSelection aNewSel; - if ( pTxtObj ) + if ( moTxtObj ) { - aNewSel = pEE->InsertText( *pTxtObj, aSel ); + aNewSel = pEE->InsertText( *moTxtObj, aSel ); } else { diff --git a/editeng/source/editeng/editundo.hxx b/editeng/source/editeng/editundo.hxx index 72abafdec9d5..745672c835ab 100644 --- a/editeng/source/editeng/editundo.hxx +++ b/editeng/source/editeng/editundo.hxx @@ -253,8 +253,8 @@ private: TransliterationFlags nMode; - std::unique_ptr - pTxtObj; + std::optional + moTxtObj; OUString aText; public: @@ -262,7 +262,7 @@ public: virtual ~EditUndoTransliteration() override; void SetText( const OUString& rText ) { aText = rText; } - void SetText( std::unique_ptr pObj ) { pTxtObj = std::move( pObj ); } + void SetText( EditTextObject&& aObj ) { moTxtObj.emplace( std::move( aObj ) ); } void SetNewSelection( const ESelection& rSel ) { aNewESel = rSel; } virtual void Undo() override; diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx index 568b5fd11105..8a17d02bee45 100644 --- a/editeng/source/editeng/editview.cxx +++ b/editeng/source/editeng/editview.cxx @@ -834,7 +834,7 @@ EVControlBits EditView::GetControlWord() const return getImpl().mnControl; } -std::unique_ptr EditView::CreateTextObject() +EditTextObject EditView::CreateTextObject() { return getImpEditEngine().CreateTextObject( getImpl().GetEditSelection() ); } diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx index ace7a01fd21f..5880c10579bc 100644 --- a/editeng/source/editeng/impedit.hxx +++ b/editeng/source/editeng/impedit.hxx @@ -672,7 +672,7 @@ private: std::unique_ptr CreateAttribUndo( EditSelection aSel, const SfxItemSet& rSet ); - std::unique_ptr GetEmptyTextObject(); + EditTextObject GetEmptyTextObject(); std::tuple GetPortionAndLine(Point aDocPos); EditPaM GetPaM( Point aDocPos, bool bSmart = true ); @@ -685,8 +685,7 @@ private: void ParaAttribsToCharAttribs( ContentNode* pNode ); void GetCharAttribs( sal_Int32 nPara, std::vector& rLst ) const; - std::unique_ptr - CreateTextObject(EditSelection aSelection, SfxItemPool*, bool bAllowBigObjects = false, sal_Int32 nBigObjStart = 0); + EditTextObject CreateTextObject(EditSelection aSelection, SfxItemPool*, bool bAllowBigObjects = false, sal_Int32 nBigObjStart = 0); EditSelection InsertTextObject( const EditTextObject&, EditPaM aPaM ); EditSelection PasteText( css::uno::Reference< css::datatransfer::XTransferable > const & rxDataObj, const OUString& rBaseURL, const EditPaM& rPaM, bool bUseSpecial, SotClipboardFormatId format = SotClipboardFormatId::NONE); @@ -1037,9 +1036,9 @@ public: void Write(SvStream& rOutput, EETextFormat eFormat, const EditSelection& rSel); OString GetSimpleHtml() const; - std::unique_ptr CreateTextObject(sal_Int32 nPara, sal_Int32 nParas); - std::unique_ptr CreateTextObject(); - std::unique_ptr CreateTextObject(const EditSelection& rSel); + EditTextObject CreateTextObject(sal_Int32 nPara, sal_Int32 nParas); + EditTextObject CreateTextObject(); + EditTextObject CreateTextObject(const EditSelection& rSel); void SetText( const EditTextObject& rTextObject ); EditSelection InsertText( const EditTextObject& rTextObject, EditSelection aSel ); diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index 9cfb6a76aae2..e5da28b7d2a4 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -1146,7 +1146,7 @@ OString ImpEditEngine::GetSimpleHtml() const return aOutput.makeStringAndClear(); } -std::unique_ptr ImpEditEngine::GetEmptyTextObject() +EditTextObject ImpEditEngine::GetEmptyTextObject() { EditSelection aEmptySel; aEmptySel.Min() = maEditDoc.GetStartPaM(); @@ -1155,27 +1155,23 @@ std::unique_ptr ImpEditEngine::GetEmptyTextObject() return CreateTextObject( aEmptySel ); } -std::unique_ptr ImpEditEngine::CreateTextObject( sal_Int32 nPara, sal_Int32 nParas ) +EditTextObject ImpEditEngine::CreateTextObject( sal_Int32 nPara, sal_Int32 nParas ) { - DBG_ASSERT(0 <= nPara && nPara < maEditDoc.Count(), "CreateTextObject: Startpara out of Range"); - DBG_ASSERT(nParas <= maEditDoc.Count() - nPara, "CreateTextObject: Endpara out of Range"); + assert(0 <= nPara && nPara < maEditDoc.Count() && "CreateTextObject: Startpara out of Range"); + assert(nParas <= maEditDoc.Count() - nPara && "CreateTextObject: Endpara out of Range"); ContentNode* pStartNode = maEditDoc.GetObject(nPara); ContentNode* pEndNode = maEditDoc.GetObject(nPara + nParas - 1); - DBG_ASSERT( pStartNode, "Start-Paragraph does not exist: CreateTextObject" ); - DBG_ASSERT( pEndNode, "End-Paragraph does not exist: CreateTextObject" ); + assert( pStartNode && "Start-Paragraph does not exist: CreateTextObject" ); + assert( pEndNode && "End-Paragraph does not exist: CreateTextObject" ); - if ( pStartNode && pEndNode ) - { - EditSelection aTmpSel; - aTmpSel.Min() = EditPaM( pStartNode, 0 ); - aTmpSel.Max() = EditPaM( pEndNode, pEndNode->Len() ); - return CreateTextObject(aTmpSel); - } - return nullptr; + EditSelection aTmpSel; + aTmpSel.Min() = EditPaM( pStartNode, 0 ); + aTmpSel.Max() = EditPaM( pEndNode, pEndNode->Len() ); + return CreateTextObject(aTmpSel); } -std::unique_ptr ImpEditEngine::CreateTextObject() +EditTextObject ImpEditEngine::CreateTextObject() { EditSelection aCompleteSelection; aCompleteSelection.Min() = maEditDoc.GetStartPaM(); @@ -1184,12 +1180,12 @@ std::unique_ptr ImpEditEngine::CreateTextObject() return CreateTextObject( aCompleteSelection ); } -std::unique_ptr ImpEditEngine::CreateTextObject(const EditSelection& rSel) +EditTextObject ImpEditEngine::CreateTextObject(const EditSelection& rSel) { return CreateTextObject(rSel, &maEditDoc.GetItemPool(), maStatus.AllowBigObjects(), mnBigTextObjectStart); } -std::unique_ptr ImpEditEngine::CreateTextObject( EditSelection aSel, SfxItemPool* pPool, bool bAllowBigObjects, sal_Int32 nBigObjectStart ) +EditTextObject ImpEditEngine::CreateTextObject( EditSelection aSel, SfxItemPool* pPool, bool bAllowBigObjects, sal_Int32 nBigObjectStart ) { sal_Int32 nStartNode, nEndNode; sal_Int32 nTextPortions = 0; @@ -1205,8 +1201,8 @@ std::unique_ptr ImpEditEngine::CreateTextObject( EditSelection a // (Only the name and family, template itself must be in App!) const MapUnit eMapUnit = maEditDoc.GetItemPool().GetMetric(DEF_METRIC); - auto pTxtObj(std::make_unique(pPool, eMapUnit, GetVertical(), GetRotation(), - GetItemScriptType(aSel))); + EditTextObject aTxtObj(pPool, eMapUnit, GetVertical(), GetRotation(), + GetItemScriptType(aSel)); // iterate over the paragraphs ... sal_Int32 nNode; @@ -1231,7 +1227,7 @@ std::unique_ptr ImpEditEngine::CreateTextObject( EditSelection a nEndPos = aSel.Max().GetIndex(); - ContentInfo *pC = pTxtObj->CreateAndInsertContent(); + ContentInfo *pC = aTxtObj.CreateAndInsertContent(); // The paragraph attributes ... pC->GetParaAttribs().Set( pNode->GetContentAttribs().GetItems() ); @@ -1257,7 +1253,7 @@ std::unique_ptr ImpEditEngine::CreateTextObject( EditSelection a if ( bEmptyPara || ( ( pAttr->GetEnd() > nStartPos ) && ( pAttr->GetStart() < nEndPos ) ) ) { - XEditAttribute aX(*pTxtObj->GetPool(), *pAttr->GetItem(), pAttr->GetStart(), pAttr->GetEnd()); + XEditAttribute aX(*aTxtObj.GetPool(), *pAttr->GetItem(), pAttr->GetStart(), pAttr->GetEnd()); // Possibly Correct ... if ( ( nNode == nStartNode ) && ( nStartPos != 0 ) ) { @@ -1291,7 +1287,7 @@ std::unique_ptr ImpEditEngine::CreateTextObject( EditSelection a XParaPortionList* pXList = new XParaPortionList(GetRefDevice(), GetColumnWidth(maPaperSize), maScalingParameters.fFontX, maScalingParameters.fFontY, maScalingParameters.fSpacingX, maScalingParameters.fSpacingY); - pTxtObj->SetPortionInfo(std::unique_ptr(pXList)); + aTxtObj.SetPortionInfo(std::unique_ptr(pXList)); for ( nNode = nStartNode; nNode <= nEndNode; nNode++ ) { ParaPortion const& rParaPortion = GetParaPortions().getRef(nNode); @@ -1329,7 +1325,7 @@ std::unique_ptr ImpEditEngine::CreateTextObject( EditSelection a #endif } } - return pTxtObj; + return aTxtObj; } void ImpEditEngine::SetText( const EditTextObject& rTextObject ) diff --git a/editeng/source/outliner/outliner.cxx b/editeng/source/outliner/outliner.cxx index fe9fde964489..9d216af0ff3f 100644 --- a/editeng/source/outliner/outliner.cxx +++ b/editeng/source/outliner/outliner.cxx @@ -373,18 +373,18 @@ std::optional Outliner::CreateParaObject( sal_Int32 nStartPa if (nCount <= 0) return std::nullopt; - std::unique_ptr xText = pEditEngine->CreateTextObject( nStartPara, nCount ); + EditTextObject aText = pEditEngine->CreateTextObject( nStartPara, nCount ); const sal_Int32 nLastPara(nStartPara + nCount - 1); for(sal_Int32 nPara(nStartPara); nPara <= nLastPara; nPara++) { - xText->SetNumberingDepth(nPara - nStartPara, GetParagraph(nPara)->GetNumberingDepth()); - xText->SetNumberingStartValue(nPara - nStartPara, GetParagraph(nPara)->GetNumberingStartValue()); - xText->SetNumberingRestart(nPara - nStartPara, GetParagraph(nPara)->IsNumberingRestart()); + aText.SetNumberingDepth(nPara - nStartPara, GetParagraph(nPara)->GetNumberingDepth()); + aText.SetNumberingStartValue(nPara - nStartPara, GetParagraph(nPara)->GetNumberingStartValue()); + aText.SetNumberingRestart(nPara - nStartPara, GetParagraph(nPara)->IsNumberingRestart()); } - xText->ClearPortionInfo(); // tdf#147166 the PortionInfo is unwanted here - OutlinerParaObject aPObj(std::move(xText)); + aText.ClearPortionInfo(); // tdf#147166 the PortionInfo is unwanted here + OutlinerParaObject aPObj(std::move(aText)); aPObj.SetOutlinerMode(GetOutlinerMode()); return aPObj; @@ -1996,8 +1996,8 @@ std::optional Outliner::GetNonOverflowingText() const OutlinerParaObject Outliner::GetEmptyParaObject() const { - std::unique_ptr pEmptyText = pEditEngine->GetEmptyTextObject(); - OutlinerParaObject aPObj( std::move(pEmptyText) ); + EditTextObject aEmptyText = pEditEngine->GetEmptyTextObject(); + OutlinerParaObject aPObj( std::move(aEmptyText) ); aPObj.SetOutlinerMode(GetOutlinerMode()); return aPObj; } diff --git a/editeng/source/outliner/outlobj.cxx b/editeng/source/outliner/outlobj.cxx index 58d1f6074236..e7abd91063ef 100644 --- a/editeng/source/outliner/outlobj.cxx +++ b/editeng/source/outliner/outlobj.cxx @@ -27,32 +27,10 @@ #include #include -OutlinerParaObjData::OutlinerParaObjData( std::unique_ptr pEditTextObject ) : - mpEditTextObject(std::move(pEditTextObject)) -{ -} -OutlinerParaObjData::OutlinerParaObjData( const OutlinerParaObjData& r ): - mpEditTextObject(new EditTextObject(*r.mpEditTextObject)) -{ -} -OutlinerParaObjData::~OutlinerParaObjData() -{ -} - -bool OutlinerParaObjData::operator==(const OutlinerParaObjData& rCandidate) const -{ - return *mpEditTextObject == *rCandidate.mpEditTextObject; -} - -bool OutlinerParaObjData::isWrongListEqual(const OutlinerParaObjData& rCompare) const -{ - return mpEditTextObject->isWrongListEqual(*rCompare.mpEditTextObject); -} - -OutlinerParaObject::OutlinerParaObject( std::unique_ptr xTextObj ) : - mpImpl(OutlinerParaObjData(std::move(xTextObj))) +OutlinerParaObject::OutlinerParaObject( EditTextObject&& aTextObj ) : + mpImpl(std::move(aTextObj)) { } @@ -100,56 +78,56 @@ bool OutlinerParaObject::isWrongListEqual( const OutlinerParaObject& r ) const OutlinerMode OutlinerParaObject::GetOutlinerMode() const { - return mpImpl->mpEditTextObject->GetUserType(); + return mpImpl->GetUserType(); } void OutlinerParaObject::SetOutlinerMode(OutlinerMode nNew) { // create a const pointer to avoid an early call to // make_unique() in the dereference of mpImpl - const ::o3tl::cow_wrapper< OutlinerParaObjData >* pImpl = &mpImpl; - if ( ( *pImpl )->mpEditTextObject->GetUserType() != nNew ) + const ::o3tl::cow_wrapper< EditTextObject >* pImpl = &mpImpl; + if ( ( *pImpl )->GetUserType() != nNew ) { - mpImpl->mpEditTextObject->SetUserType(nNew); + mpImpl->SetUserType(nNew); } } bool OutlinerParaObject::IsEffectivelyVertical() const { - return mpImpl->mpEditTextObject->IsEffectivelyVertical(); + return mpImpl->IsEffectivelyVertical(); } bool OutlinerParaObject::GetVertical() const { - return mpImpl->mpEditTextObject->GetVertical(); + return mpImpl->GetVertical(); } bool OutlinerParaObject::IsTopToBottom() const { - return mpImpl->mpEditTextObject->IsTopToBottom(); + return mpImpl->IsTopToBottom(); } void OutlinerParaObject::SetVertical(bool bNew) { - const ::o3tl::cow_wrapper< OutlinerParaObjData >* pImpl = &mpImpl; - if ( ( *pImpl )->mpEditTextObject->IsEffectivelyVertical() != bNew) + const ::o3tl::cow_wrapper< EditTextObject >* pImpl = &mpImpl; + if ( ( *pImpl )->IsEffectivelyVertical() != bNew) { - mpImpl->mpEditTextObject->SetVertical(bNew); + mpImpl->SetVertical(bNew); } } void OutlinerParaObject::SetRotation(TextRotation nRotation) { - mpImpl->mpEditTextObject->SetRotation(nRotation); + mpImpl->SetRotation(nRotation); } TextRotation OutlinerParaObject::GetRotation() const { - return mpImpl->mpEditTextObject->GetRotation(); + return mpImpl->GetRotation(); } sal_Int32 OutlinerParaObject::Count() const { - size_t nSize = mpImpl->mpEditTextObject->GetParagraphCount(); + size_t nSize = mpImpl->GetParagraphCount(); if (nSize > o3tl::make_unsigned(EE_PARA_MAX)) { SAL_WARN( "editeng", "OutlinerParaObject::Count - overflow " << nSize); @@ -160,39 +138,39 @@ sal_Int32 OutlinerParaObject::Count() const sal_Int16 OutlinerParaObject::GetNumberingDepth(sal_Int32 nPara) const { - return mpImpl->mpEditTextObject->GetNumberingDepth(nPara); + return mpImpl->GetNumberingDepth(nPara); } sal_Int16 OutlinerParaObject::GetNumberingStartValue(sal_Int32 nPara) const { - return mpImpl->mpEditTextObject->GetNumberingStartValue(nPara); + return mpImpl->GetNumberingStartValue(nPara); } bool OutlinerParaObject::IsNumberingRestart(sal_Int32 nPara) const { - return mpImpl->mpEditTextObject->IsNumberingRestart(nPara); + return mpImpl->IsNumberingRestart(nPara); } const EditTextObject& OutlinerParaObject::GetTextObject() const { - return *mpImpl->mpEditTextObject; + return *mpImpl; } void OutlinerParaObject::ClearPortionInfo() { - mpImpl->mpEditTextObject->ClearPortionInfo(); + mpImpl->ClearPortionInfo(); } bool OutlinerParaObject::ChangeStyleSheets(std::u16string_view rOldName, SfxStyleFamily eOldFamily, const OUString& rNewName, SfxStyleFamily eNewFamily) { - return mpImpl->mpEditTextObject->ChangeStyleSheets(rOldName, eOldFamily, rNewName, eNewFamily); + return mpImpl->ChangeStyleSheets(rOldName, eOldFamily, rNewName, eNewFamily); } void OutlinerParaObject::ChangeStyleSheetName(SfxStyleFamily eFamily, std::u16string_view rOldName, const OUString& rNewName) { - mpImpl->mpEditTextObject->ChangeStyleSheetName(eFamily, rOldName, rNewName); + mpImpl->ChangeStyleSheetName(eFamily, rOldName, rNewName); } void OutlinerParaObject::SetStyleSheets(sal_uInt16 nLevel, const OUString& rNewName, @@ -208,7 +186,7 @@ void OutlinerParaObject::SetStyleSheets(sal_uInt16 nLevel, const OUString& rNewN { if(GetNumberingDepth(--nDecrementer) == nLevel) { - mpImpl->mpEditTextObject->SetStyleSheet(nDecrementer, rNewName, rNewFamily); + mpImpl->SetStyleSheet(nDecrementer, rNewName, rNewFamily); } } } @@ -218,7 +196,7 @@ void OutlinerParaObject::dumpAsXml(xmlTextWriterPtr pWriter) const { (void)xmlTextWriterStartElement(pWriter, BAD_CAST("OutlinerParaObject")); (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this); - mpImpl->mpEditTextObject->dumpAsXml(pWriter); + mpImpl->dumpAsXml(pWriter); (void)xmlTextWriterEndElement(pWriter); } diff --git a/editeng/source/uno/unofored.cxx b/editeng/source/uno/unofored.cxx index c8728c6255a5..11bc4f42d2f2 100644 --- a/editeng/source/uno/unofored.cxx +++ b/editeng/source/uno/unofored.cxx @@ -513,8 +513,8 @@ void SvxEditEngineForwarder::CopyText(const SvxTextForwarder& rSource) const SvxEditEngineForwarder* pSourceForwarder = dynamic_cast< const SvxEditEngineForwarder* >( &rSource ); if( !pSourceForwarder ) return; - std::unique_ptr pNewTextObject = pSourceForwarder->rEditEngine.CreateTextObject(); - rEditEngine.SetText( *pNewTextObject ); + EditTextObject aNewTextObject = pSourceForwarder->rEditEngine.CreateTextObject(); + rEditEngine.SetText( aNewTextObject ); } diff --git a/forms/source/richtext/richtextengine.cxx b/forms/source/richtext/richtextengine.cxx index 325d27c9bd29..8c56a6207d8d 100644 --- a/forms/source/richtext/richtextengine.cxx +++ b/forms/source/richtext/richtextengine.cxx @@ -78,13 +78,11 @@ namespace frm RichTextEngine* pClone( nullptr ); { SolarMutexGuard aGuard; - std::unique_ptr pMyText(CreateTextObject()); - OSL_ENSURE( pMyText, "RichTextEngine::Clone: CreateTextObject returned nonsense!" ); + EditTextObject aMyText(CreateTextObject()); pClone = Create(); - if ( pMyText ) - pClone->SetText( *pMyText ); + pClone->SetText( aMyText ); } return pClone; diff --git a/include/editeng/editeng.hxx b/include/editeng/editeng.hxx index 7d74d4f4f191..5b48537e18b0 100644 --- a/include/editeng/editeng.hxx +++ b/include/editeng/editeng.hxx @@ -306,10 +306,10 @@ public: void Clear(); void SetText( const OUString& rStr ); - std::unique_ptr CreateTextObject(); - SAL_DLLPRIVATE std::unique_ptr GetEmptyTextObject(); - std::unique_ptr CreateTextObject( sal_Int32 nPara, sal_Int32 nParas = 1 ); - std::unique_ptr CreateTextObject( const ESelection& rESelection ); + EditTextObject CreateTextObject(); + SAL_DLLPRIVATE EditTextObject GetEmptyTextObject(); + EditTextObject CreateTextObject( sal_Int32 nPara, sal_Int32 nParas = 1 ); + EditTextObject CreateTextObject( const ESelection& rESelection ); void SetText( const EditTextObject& rTextObject ); SAL_DLLPRIVATE void RemoveParagraph(sal_Int32 nPara); diff --git a/include/editeng/editobj.hxx b/include/editeng/editobj.hxx index ba57e614463c..2cee547b57e8 100644 --- a/include/editeng/editobj.hxx +++ b/include/editeng/editobj.hxx @@ -63,8 +63,11 @@ public: EditTextObject(SfxItemPool* pPool, MapUnit eDefaultMetric, bool bVertical, TextRotation eRotation, SvtScriptType eScriptType); EditTextObject( const EditTextObject& r ); + EditTextObject( EditTextObject&& r ) noexcept; ~EditTextObject(); + EditTextObject& operator=(EditTextObject&&); + /** * Set paragraph strings to the shared string pool. * diff --git a/include/editeng/editview.hxx b/include/editeng/editview.hxx index e77cea8c56b1..cb2fa7947c77 100644 --- a/include/editeng/editview.hxx +++ b/include/editeng/editview.hxx @@ -301,7 +301,7 @@ public: void SetControlWord( EVControlBits nWord ); EVControlBits GetControlWord() const; - std::unique_ptr CreateTextObject(); + EditTextObject CreateTextObject(); void InsertText( const EditTextObject& rTextObject ); void InsertText( css::uno::Reference< css::datatransfer::XTransferable > const & xDataObj, const OUString& rBaseURL, bool bUseSpecial ); diff --git a/include/editeng/outlobj.hxx b/include/editeng/outlobj.hxx index 3ccfb4e32fcc..bb3fbd41124a 100644 --- a/include/editeng/outlobj.hxx +++ b/include/editeng/outlobj.hxx @@ -20,6 +20,7 @@ #pragma once #include +#include #include #include #include @@ -27,42 +28,10 @@ #include #include -class EditTextObject; -enum class OutlinerMode; -enum class TextRotation; - -/** - * This is the guts of OutlinerParaObject, refcounted and shared among - * multiple instances of OutlinerParaObject. - */ -struct EDITENG_DLLPUBLIC OutlinerParaObjData -{ - // data members - std::unique_ptr mpEditTextObject; - - // constructor - OutlinerParaObjData( std::unique_ptr pEditTextObject ); - - OutlinerParaObjData( const OutlinerParaObjData& r ); - - OutlinerParaObjData( OutlinerParaObjData&& r ) = default; - - // assignment operator - OutlinerParaObjData& operator=(const OutlinerParaObjData& rCandidate) = delete; - - // destructor - ~OutlinerParaObjData(); - - bool operator==(const OutlinerParaObjData& rCandidate) const; - - // #i102062# - bool isWrongListEqual(const OutlinerParaObjData& rCompare) const; -}; - class EDITENG_DLLPUBLIC OutlinerParaObject { friend class std::optional; - ::o3tl::cow_wrapper< OutlinerParaObjData > mpImpl; + ::o3tl::cow_wrapper< EditTextObject > mpImpl; OutlinerParaObject(std::nullopt_t) noexcept : mpImpl(std::nullopt) {} @@ -71,7 +40,7 @@ friend class std::optional; public: // constructors/destructor - OutlinerParaObject(std::unique_ptr); + OutlinerParaObject(EditTextObject&&); OutlinerParaObject( const OutlinerParaObject&); OutlinerParaObject(OutlinerParaObject&&) noexcept; ~OutlinerParaObject(); diff --git a/sc/inc/cellvalue.hxx b/sc/inc/cellvalue.hxx index b618efa31a4d..fbd4a7b07ceb 100644 --- a/sc/inc/cellvalue.hxx +++ b/sc/inc/cellvalue.hxx @@ -51,7 +51,8 @@ public: SC_DLLPUBLIC void set( double fValue ); SC_DLLPUBLIC void set( const svl::SharedString& rStr ); - void set( const EditTextObject& rEditText ); + SC_DLLPUBLIC void set( const EditTextObject& rEditText ); + SC_DLLPUBLIC void set( EditTextObject&& rEditText ); SC_DLLPUBLIC void set( std::unique_ptr ); SC_DLLPUBLIC void set( ScFormulaCell* pFormula ); diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 86079e1508f2..5ffa042b0a71 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -390,9 +390,11 @@ public: SCROW nRow, SCTAB nTab, const OUString& rString, formula::FormulaGrammar::AddressConvention eConv, const ScSetStringParam* pParam = nullptr ); - void SetEditText( SCROW nRow, std::unique_ptr pEditText ); + void SetEditText( SCROW nRow, std::unique_ptr aEditText ); + void SetEditText( SCROW nRow, EditTextObject aEditText ); void SetEditText( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, std::unique_ptr pEditText ); void SetEditText( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, const EditTextObject& rEditText ); + void SetEditText( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, EditTextObject&& rEditText ); void SetEditText( SCROW nRow, const EditTextObject& rEditText, const SfxItemPool* pEditPool ); void SetFormula( SCROW nRow, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram ); void SetFormula( SCROW nRow, const OUString& rFormula, formula::FormulaGrammar::Grammar eGram ); diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 5b79fb1fcc6a..7689fe40a990 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1328,6 +1328,7 @@ public: * This is very important.

*/ SC_DLLPUBLIC bool SetEditText( const ScAddress& rPos, std::unique_ptr pEditText ); + SC_DLLPUBLIC bool SetEditText( const ScAddress& rPos, EditTextObject aEditText ); 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; @@ -2777,7 +2778,7 @@ public: SC_DLLPUBLIC ScFieldEditEngine& GetEditEngine(); SC_DLLPUBLIC ScNoteEditEngine& GetNoteEngine(); - std::unique_ptr CreateSharedStringTextObject( const svl::SharedString& rSS ); + EditTextObject CreateSharedStringTextObject( const svl::SharedString& rSS ); std::unique_ptr const & GetRefreshTimerControlAddress() const { return pRefreshTimerControl; } diff --git a/sc/inc/editutil.hxx b/sc/inc/editutil.hxx index a0f2c6ec9e97..a920502376c2 100644 --- a/sc/inc/editutil.hxx +++ b/sc/inc/editutil.hxx @@ -64,12 +64,12 @@ public: */ SC_DLLPUBLIC static OUString GetString( const EditTextObject& rEditText, const ScDocument& rDoc ); - static std::unique_ptr CreateURLObjectFromURL( + static EditTextObject CreateURLObjectFromURL( ScDocument& rDoc, const OUString& rURL, const OUString& rText ); static void RemoveCharAttribs( EditTextObject& rEditText, const ScPatternAttr& rAttr ); - static std::unique_ptr Clone( const EditTextObject& rSrc, ScDocument& rDestDoc ); + static EditTextObject Clone( const EditTextObject& rSrc, ScDocument& rDestDoc ); static OUString GetCellFieldValue( const SvxFieldData& rFieldData, const ScDocument* pDoc, std::optional* ppTextColor, std::optional* ppFldLineStyle ); diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx index 5730a1b9e45c..7538505d0180 100644 --- a/sc/inc/formulacell.hxx +++ b/sc/inc/formulacell.hxx @@ -475,7 +475,7 @@ public: void MarkAsSpilled(); SC_DLLPUBLIC bool IsHyperLinkCell() const; - std::unique_ptr CreateURLObject(); + EditTextObject CreateURLObject(); SC_DLLPUBLIC void GetURLResult( OUString& rURL, OUString& rCellText ); /** Determines whether or not the result string contains more than one paragraph */ diff --git a/sc/inc/textuno.hxx b/sc/inc/textuno.hxx index de9f40f81bcd..c14c9a631065 100644 --- a/sc/inc/textuno.hxx +++ b/sc/inc/textuno.hxx @@ -310,7 +310,7 @@ public: virtual ~ScEditEngineTextObj() noexcept override; void SetText( const EditTextObject& rTextObject ); - std::unique_ptr CreateTextObject(); + EditTextObject CreateTextObject(); }; // ScCellTextData: shared data between sub objects of a cell text object diff --git a/sc/qa/unit/tiledrendering/SheetViewTest.cxx b/sc/qa/unit/tiledrendering/SheetViewTest.cxx index 187117c5c935..d6fb307de829 100644 --- a/sc/qa/unit/tiledrendering/SheetViewTest.cxx +++ b/sc/qa/unit/tiledrendering/SheetViewTest.cxx @@ -4338,7 +4338,7 @@ CPPUNIT_TEST_FIXTURE(SyncTest, testSync_AutoFilterRangeExpansionFromSheetView) ScModelObj*) { ScFieldEditEngine& rEE = rDocument.GetEditEngine(); rEE.SetTextCurrentDefaults(u"6"_ustr); - rDocShell.GetDocFunc().SetEditCell(rPos, *rEE.CreateTextObject(), true); + rDocShell.GetDocFunc().SetEditCell(rPos, rEE.CreateTextObject(), true); }, true }, }); diff --git a/sc/source/core/data/attrib.cxx b/sc/source/core/data/attrib.cxx index f341a86458d9..8773d0804370 100644 --- a/sc/source/core/data/attrib.cxx +++ b/sc/source/core/data/attrib.cxx @@ -453,11 +453,11 @@ bool ScPageHFItem::PutValue( const uno::Any& rVal, sal_uInt8 /* nMemberId */ ) // no Text with Null are left ScEditEngineDefaulter aEngine( EditEngine::CreatePool().get(), true ); if (!pLeftArea) - pLeftArea = aEngine.CreateTextObject(); + pLeftArea = std::make_unique(aEngine.CreateTextObject()); if (!pCenterArea) - pCenterArea = aEngine.CreateTextObject(); + pCenterArea = std::make_unique(aEngine.CreateTextObject()); if (!pRightArea) - pRightArea = aEngine.CreateTextObject(); + pRightArea = std::make_unique(aEngine.CreateTextObject()); } bRet = true; diff --git a/sc/source/core/data/cellvalue.cxx b/sc/source/core/data/cellvalue.cxx index 02eec75bd88e..849fbf6826b5 100644 --- a/sc/source/core/data/cellvalue.cxx +++ b/sc/source/core/data/cellvalue.cxx @@ -345,6 +345,12 @@ void ScCellValue::set( const EditTextObject& rEditText ) maData = new EditTextObject(rEditText); } +void ScCellValue::set( EditTextObject&& rEditText ) +{ + clear(); + maData = new EditTextObject(std::move(rEditText)); +} + void ScCellValue::set( std::unique_ptr xEditText ) { clear(); @@ -402,14 +408,14 @@ void ScCellValue::assign(const ScCellValue& rOther, ScDocument& rDestDoc, ScClon if (bNewControl) rEngine.SetControlWord(nControl | nSpellControl); rEngine.SetTextCurrentDefaults(*rOther.getEditText()); - maData = rEngine.CreateTextObject().release(); + maData = new EditTextObject(rEngine.CreateTextObject()); if (bNewControl) rEngine.SetControlWord(nControl); } else { rEngine.SetTextCurrentDefaults(*rOther.getEditText()); - maData = rEngine.CreateTextObject().release(); + maData = new EditTextObject(rEngine.CreateTextObject()); } } break; diff --git a/sc/source/core/data/clipcontext.cxx b/sc/source/core/data/clipcontext.cxx index d1a439ba9ffa..b54f7c69b7bf 100644 --- a/sc/source/core/data/clipcontext.cxx +++ b/sc/source/core/data/clipcontext.cxx @@ -299,9 +299,9 @@ void CopyFromClipContext::setSingleCell( const ScAddress& rSrcPos, const ScColum // Turn this into a string or edit cell. if (rSrcCell.getFormula()->IsMultilineResult()) { - std::unique_ptr pObj(mrDestDoc.CreateSharedStringTextObject( + EditTextObject aObj(mrDestDoc.CreateSharedStringTextObject( rSrcCell.getFormula()->GetString())); - rSrcCell.set(*pObj); + rSrcCell.set(std::move(aObj)); } else rSrcCell.set(rSrcCell.getFormula()->GetString()); diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index 10e5a94cd69a..8bcb8f94bc23 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -785,7 +785,7 @@ public: std::vector aCloned; aCloned.reserve(nDataSize); for (; it != itEnd; ++it) - aCloned.push_back(ScEditUtil::Clone(**it, mrDestCol.GetDoc()).release()); + aCloned.push_back(new EditTextObject(ScEditUtil::Clone(**it, mrDestCol.GetDoc()))); maDestPos.miCellPos = mrDestCol.GetCellStore().set( maDestPos.miCellPos, nTopRow, aCloned.begin(), aCloned.end()); @@ -1040,7 +1040,7 @@ void ScColumn::CopyCellToDocument( SCROW nSrcRow, SCROW nDestRow, ScColumn& rDes if (&rDocument == &rDestCol.GetDoc()) rDestCol.maCells.set(nDestRow, new EditTextObject(*p)); else - rDestCol.maCells.set(nDestRow, ScEditUtil::Clone(*p, rDestCol.GetDoc()).release()); + rDestCol.maCells.set(nDestRow, new EditTextObject(ScEditUtil::Clone(*p, rDestCol.GetDoc()))); } break; case sc::element_type_formula: @@ -1340,7 +1340,7 @@ class CopyByCloneHandler EditEngine& rEngine = mrDestCol.GetDoc().GetEditEngine(); rEngine.SetText(aStr.getString()); maDestPos.miCellPos = - mrDestCol.GetCellStore().set(maDestPos.miCellPos, nRow, rEngine.CreateTextObject().release()); + mrDestCol.GetCellStore().set(maDestPos.miCellPos, nRow, new EditTextObject(rEngine.CreateTextObject())); } else { @@ -1483,7 +1483,7 @@ public: std::vector aCloned; aCloned.reserve(nDataSize); for (; it != itEnd; ++it) - aCloned.push_back(ScEditUtil::Clone(**it, mrDestCol.GetDoc()).release()); + aCloned.push_back(new EditTextObject(ScEditUtil::Clone(**it, mrDestCol.GetDoc()))); 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 4b174bcbc048..8357a0e2c44d 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -1249,7 +1249,7 @@ public: // Overwrite the existing object. delete pObj; - pObj = mpEngine->CreateTextObject().release(); + pObj = new EditTextObject(mpEngine->CreateTextObject()); } else // create String { diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 217d777ffcd7..cb7fff54a38e 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -2358,6 +2358,11 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const OUString& rString, return bNumFmtSet; } +void ScColumn::SetEditText( SCROW nRow, EditTextObject aEditText ) +{ + SetEditText(nRow, std::make_unique(std::move(aEditText))); +} + void ScColumn::SetEditText( SCROW nRow, std::unique_ptr pEditText ) { if (!pEditText) @@ -2409,6 +2414,22 @@ void ScColumn::SetEditText( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, cons SetEditText(rBlockPos, nRow, rEngine.CreateTextObject()); } +void ScColumn::SetEditText( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, EditTextObject&& rEditText ) +{ + if (GetDoc().GetEditEnginePool() == rEditText.GetPool()) + { + SetEditText(rBlockPos, nRow, std::make_unique(std::move(rEditText))); + return; + } + + // rats, yet another "spool" + // Sadly there is no other way to change the Pool than to + // "spool" the Object through a corresponding Engine + EditEngine& rEngine = GetDoc().GetEditEngine(); + rEngine.SetText(std::move(rEditText)); + SetEditText(rBlockPos, nRow, rEngine.CreateTextObject()); +} + void ScColumn::SetEditText( SCROW nRow, const EditTextObject& rEditText, const SfxItemPool* pEditPool ) { if (pEditPool && GetDoc().GetEditEnginePool() == pEditPool) diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx index 2d26a0e91412..fd754d4450d6 100644 --- a/sc/source/core/data/column4.cxx +++ b/sc/source/core/data/column4.cxx @@ -505,8 +505,8 @@ public: case sc::FormulaResultValue::String: if (aRes.mbMultiLine) { - std::unique_ptr pObj(mrDoc.CreateSharedStringTextObject(aRes.maString)); - maResValues.setValue(nRow, std::move(pObj)); + EditTextObject aObj(mrDoc.CreateSharedStringTextObject(aRes.maString)); + maResValues.setValue(nRow, std::make_unique(std::move(aObj))); } else { diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx index ac5b4fbd2dad..fbd1a36e7c58 100644 --- a/sc/source/core/data/documen2.cxx +++ b/sc/source/core/data/documen2.cxx @@ -544,15 +544,15 @@ ScNoteEditEngine& ScDocument::GetNoteEngine() return *mpNoteEngine; } -std::unique_ptr ScDocument::CreateSharedStringTextObject( const svl::SharedString& rSS ) +EditTextObject ScDocument::CreateSharedStringTextObject( const svl::SharedString& rSS ) { /* TODO: Add shared string support to the edit engine to make this process * simpler. */ ScFieldEditEngine& rEngine = GetEditEngine(); rEngine.SetTextCurrentDefaults( rSS.getString()); - std::unique_ptr pObj( rEngine.CreateTextObject()); - pObj->NormalizeString( GetSharedStringPool()); - return pObj; + EditTextObject aObj( rEngine.CreateTextObject()); + aObj.NormalizeString( GetSharedStringPool()); + return aObj; } void ScDocument::ResetClip( ScDocument* pSourceDoc, const ScMarkData* pMarks ) diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index f28576786db2..fca80ec24491 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -3718,6 +3718,11 @@ bool ScDocument::SetString( return SetString(rPos.Col(), rPos.Row(), rPos.Tab(), rString, pParam); } +bool ScDocument::SetEditText( const ScAddress& rPos, EditTextObject aEditText ) +{ + return SetEditText(rPos, std::make_unique(std::move(aEditText))); +} + bool ScDocument::SetEditText( const ScAddress& rPos, std::unique_ptr pEditText ) { if (ScTable* pTable = FetchTable(rPos.Tab())) @@ -3737,7 +3742,7 @@ void ScDocument::SetEditText( const ScAddress& rPos, const OUString& rStr ) { ScFieldEditEngine& rEngine = GetEditEngine(); rEngine.SetTextCurrentDefaults(rStr); - pTable->SetEditText(rPos.Col(), rPos.Row(), rEngine.CreateTextObject()); + pTable->SetEditText(rPos.Col(), rPos.Row(), std::make_unique(rEngine.CreateTextObject())); } } @@ -3758,7 +3763,7 @@ void ScDocument::SetTextCell(const ScAddress& rPos, const OUString& rStr, { ScFieldEditEngine& rEngine = GetEditEngine(); rEngine.SetTextCurrentDefaults(rStr); - pTable->SetEditText(rPos.Col(), rPos.Row(), rEngine.CreateTextObject()); + pTable->SetEditText(rPos.Col(), rPos.Row(), std::make_unique(rEngine.CreateTextObject())); } else { diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index 18b5eb9ba499..9096748d4566 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -3167,7 +3167,7 @@ bool ScFormulaCell::IsHyperLinkCell() const return pCode && pCode->IsHyperLink(); } -std::unique_ptr ScFormulaCell::CreateURLObject() +EditTextObject ScFormulaCell::CreateURLObject() { OUString aCellText; OUString aURL; diff --git a/sc/source/core/data/stlpool.cxx b/sc/source/core/data/stlpool.cxx index a193bdbbd30c..08403971d71a 100644 --- a/sc/source/core/data/stlpool.cxx +++ b/sc/source/core/data/stlpool.cxx @@ -267,8 +267,7 @@ void ScStyleSheetPool::CreateStandardStyles() SfxItemSet* pHFSet = nullptr; ScEditEngineDefaulter aEdEngine( pDoc->GetEditEnginePool(), true ); aEdEngine.SetUpdateLayout( false ); - std::unique_ptr pEmptyTxtObj = aEdEngine.CreateTextObject(); - std::unique_ptr pTxtObj; + EditTextObject aEmptyTxtObj = aEdEngine.CreateTextObject(); ScPageHFItem aHeaderItem( ATTR_PAGE_HEADERRIGHT ); ScPageHFItem aFooterItem( ATTR_PAGE_FOOTERRIGHT ); ScStyleSheet* pSheet = nullptr; @@ -334,10 +333,10 @@ void ScStyleSheetPool::CreateStandardStyles() aEdEngine.SetTextCurrentDefaults(OUString()); aEdEngine.QuickInsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), ESelection() ); - pTxtObj = aEdEngine.CreateTextObject(); - aHeaderItem.SetLeftArea ( *pEmptyTxtObj ); - aHeaderItem.SetCenterArea( *pTxtObj ); - aHeaderItem.SetRightArea ( *pEmptyTxtObj ); + EditTextObject aTxtObj = aEdEngine.CreateTextObject(); + aHeaderItem.SetLeftArea ( aEmptyTxtObj ); + aHeaderItem.SetCenterArea( aTxtObj ); + aHeaderItem.SetRightArea ( aEmptyTxtObj ); pSet->Put( aHeaderItem ); // Footer: @@ -347,10 +346,9 @@ void ScStyleSheetPool::CreateStandardStyles() aEdEngine.SetTextCurrentDefaults( aStr ); nStrLen = aStr.getLength(); aEdEngine.QuickInsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(0,nStrLen) ); - pTxtObj = aEdEngine.CreateTextObject(); - aFooterItem.SetLeftArea ( *pEmptyTxtObj ); - aFooterItem.SetCenterArea( *pTxtObj ); - aFooterItem.SetRightArea ( *pEmptyTxtObj ); + aFooterItem.SetLeftArea ( aEmptyTxtObj ); + aFooterItem.SetCenterArea( aEdEngine.CreateTextObject() ); + aFooterItem.SetRightArea ( aEmptyTxtObj ); pSet->Put( aFooterItem ); // 2. Report @@ -393,16 +391,14 @@ void ScStyleSheetPool::CreateStandardStyles() aEdEngine.SetTextCurrentDefaults( aStr ); aEdEngine.QuickInsertField( SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD), ESelection(0,2) ); aEdEngine.QuickInsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), ESelection() ); - pTxtObj = aEdEngine.CreateTextObject(); - aHeaderItem.SetLeftArea( *pTxtObj ); - aHeaderItem.SetCenterArea( *pEmptyTxtObj ); + aHeaderItem.SetLeftArea( aEdEngine.CreateTextObject() ); + aHeaderItem.SetCenterArea( aEmptyTxtObj ); aStr = ", "; aEdEngine.SetTextCurrentDefaults( aStr ); aEdEngine.QuickInsertField( SvxFieldItem(SvxTimeField(), EE_FEATURE_FIELD), ESelection(0,2) ); aEdEngine.QuickInsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SvxDateType::Var), EE_FEATURE_FIELD), ESelection() ); - pTxtObj = aEdEngine.CreateTextObject(); - aHeaderItem.SetRightArea( *pTxtObj ); + aHeaderItem.SetRightArea( aEdEngine.CreateTextObject() ); pSet->Put( aHeaderItem ); // Footer: @@ -415,10 +411,9 @@ void ScStyleSheetPool::CreateStandardStyles() aEdEngine.SetTextCurrentDefaults( aStr ); aEdEngine.QuickInsertField( SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD), ESelection(0,nStrLen2) ); aEdEngine.QuickInsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(0,nStrLen) ); - pTxtObj = aEdEngine.CreateTextObject(); - aFooterItem.SetLeftArea ( *pEmptyTxtObj ); - aFooterItem.SetCenterArea( *pTxtObj ); - aFooterItem.SetRightArea ( *pEmptyTxtObj ); + aFooterItem.SetLeftArea ( aEmptyTxtObj ); + aFooterItem.SetCenterArea( aEdEngine.CreateTextObject() ); + aFooterItem.SetRightArea ( aEmptyTxtObj ); pSet->Put( aFooterItem ); bHasStandardStyles = true; diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index cc432391a5d8..ff03d95d8ad1 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -954,7 +954,7 @@ public: } SCCOL nTransCol = mnCol1 + nRow - mnTopRow - mnFilteredRows + mnRowDestOffset; - mrClipTab.SetEditText(nTransCol, mnTransRow, ScEditUtil::Clone(*p, mrClipTab.GetDoc())); + mrClipTab.SetEditText(nTransCol, mnTransRow, std::make_unique(ScEditUtil::Clone(*p, mrClipTab.GetDoc()))); } void operator() (size_t nRow, const ScFormulaCell* p) diff --git a/sc/source/core/data/table6.cxx b/sc/source/core/data/table6.cxx index d7d47d36949d..9fbe4cbd2715 100644 --- a/sc/source/core/data/table6.cxx +++ b/sc/source/core/data/table6.cxx @@ -263,7 +263,7 @@ bool ScTable::SearchCell(const SvxSearchItem& rSearchItem, SCCOL nCol, sc::Colum { ScFieldEditEngine& rEngine = rDocument.GetEditEngine(); rEngine.SetTextCurrentDefaults(aString); - SetEditText(nCol, nRow, rEngine.CreateTextObject()); + SetEditText(nCol, nRow, std::make_unique(rEngine.CreateTextObject())); } else aCol[nCol].SetString(nRow, nTab, aString, rDocument.GetAddressConvention()); diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx index 433be6bb18be..a00a5f026964 100644 --- a/sc/source/core/tool/editutil.cxx +++ b/sc/source/core/tool/editutil.cxx @@ -136,7 +136,7 @@ OUString ScEditUtil::GetString( const EditTextObject& rEditText, const ScDocumen return GetMultilineString( rEE); } -std::unique_ptr ScEditUtil::CreateURLObjectFromURL( ScDocument& rDoc, const OUString& rURL, const OUString& rText ) +EditTextObject ScEditUtil::CreateURLObjectFromURL( ScDocument& rDoc, const OUString& rURL, const OUString& rText ) { SvxURLField aUrlField( rURL, rText, SvxURLFormat::AppDefault); EditEngine& rEE = rDoc.GetEditEngine(); @@ -180,10 +180,8 @@ void ScEditUtil::RemoveCharAttribs( EditTextObject& rEditText, const ScPatternAt } } -std::unique_ptr ScEditUtil::Clone( const EditTextObject& rObj, ScDocument& rDestDoc ) +EditTextObject ScEditUtil::Clone( const EditTextObject& rObj, ScDocument& rDestDoc ) { - std::unique_ptr pNew; - EditEngine& rEngine = rDestDoc.GetEditEngine(); if (rObj.HasOnlineSpellErrors()) { @@ -193,17 +191,16 @@ std::unique_ptr ScEditUtil::Clone( const EditTextObject& rObj, S if (bNewControl) rEngine.SetControlWord(nControl | nSpellControl); rEngine.SetText(rObj); - pNew = rEngine.CreateTextObject(); + EditTextObject aNew = rEngine.CreateTextObject(); if (bNewControl) rEngine.SetControlWord(nControl); + return aNew; } else { rEngine.SetText(rObj); - pNew = rEngine.CreateTextObject(); + return rEngine.CreateTextObject(); } - - return pNew; } OUString ScEditUtil::GetCellFieldValue( diff --git a/sc/source/filter/excel/xicontent.cxx b/sc/source/filter/excel/xicontent.cxx index 45624400065c..dcbcedff281b 100644 --- a/sc/source/filter/excel/xicontent.cxx +++ b/sc/source/filter/excel/xicontent.cxx @@ -194,7 +194,7 @@ void lclInsertUrl( XclImpRoot& rRoot, const OUString& rUrl, SCCOL nScCol, SCROW } // The cell will own the text object instance. - rDoc.setEditCell(aScPos, rEE.CreateTextObject()); + rDoc.setEditCell(aScPos, std::make_unique(rEE.CreateTextObject())); } break; diff --git a/sc/source/filter/excel/xiescher.cxx b/sc/source/filter/excel/xiescher.cxx index 1ad7e5c25739..48b14a234fcb 100644 --- a/sc/source/filter/excel/xiescher.cxx +++ b/sc/source/filter/excel/xiescher.cxx @@ -1517,9 +1517,9 @@ void XclImpTextObj::DoPreProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& if( maTextData.mxString->IsRich() ) { // rich text - std::unique_ptr< EditTextObject > xEditObj( + std::optional< EditTextObject > xEditObj( XclImpStringHelper::CreateTextObject( GetRoot(), *maTextData.mxString ) ); - OutlinerParaObject aOutlineObj(std::move(xEditObj)); + OutlinerParaObject aOutlineObj(std::move(*xEditObj)); aOutlineObj.SetOutlinerMode( OutlinerMode::TextObject ); pTextObj->NbcSetOutlinerParaObject( std::move(aOutlineObj) ); } diff --git a/sc/source/filter/excel/xihelper.cxx b/sc/source/filter/excel/xihelper.cxx index 3f6fd3f5a267..74d95b2479af 100644 --- a/sc/source/filter/excel/xihelper.cxx +++ b/sc/source/filter/excel/xihelper.cxx @@ -146,10 +146,10 @@ void XclImpAddressConverter::ConvertRangeList( ScRangeList& rScRanges, namespace { -std::unique_ptr lclCreateTextObject( const XclImpRoot& rRoot, +std::optional lclCreateTextObject( const XclImpRoot& rRoot, const XclImpString& rString, XclFontItemType eType, sal_uInt16 nXFIndex ) { - std::unique_ptr pTextObj; + std::optional pTextObj; const XclImpXFBuffer& rXFBuffer = rRoot.GetXFBuffer(); const XclImpFont* pFirstFont = rXFBuffer.GetFont( nXFIndex ); @@ -213,7 +213,7 @@ std::unique_ptr lclCreateTextObject( const XclImpRoot& rRoot, // send items of last text portion to edit engine rEE.QuickSetAttribs( aItemSet, aSelection ); - pTextObj = rEE.CreateTextObject(); + pTextObj.emplace(rEE.CreateTextObject()); } return pTextObj; @@ -221,7 +221,7 @@ std::unique_ptr lclCreateTextObject( const XclImpRoot& rRoot, } // namespace -std::unique_ptr XclImpStringHelper::CreateTextObject( +std::optional XclImpStringHelper::CreateTextObject( const XclImpRoot& rRoot, const XclImpString& rString ) { return lclCreateTextObject( rRoot, rString, XclFontItemType::Editeng, 0 ); @@ -234,11 +234,11 @@ void XclImpStringHelper::SetToDocument( if (rString.GetText().isEmpty()) return; - ::std::unique_ptr< EditTextObject > pTextObj( lclCreateTextObject( rRoot, rString, XclFontItemType::Editeng, nXFIndex ) ); + ::std::optional< EditTextObject > pTextObj( lclCreateTextObject( rRoot, rString, XclFontItemType::Editeng, nXFIndex ) ); if (pTextObj) { - rDoc.setEditCell(rPos, std::move(pTextObj)); + rDoc.setEditCell(rPos, std::make_unique(std::move(*pTextObj))); } else { @@ -253,7 +253,7 @@ void XclImpStringHelper::SetToDocument( ScFieldEditEngine& rEngine = rDoc.getDoc().GetEditEngine(); rEngine.SetSingleLine(bSingleLine); rEngine.SetTextCurrentDefaults(aStr); - rDoc.setEditCell(rPos, rEngine.CreateTextObject()); + rDoc.setEditCell(rPos, std::make_unique(rEngine.CreateTextObject())); rEngine.SetSingleLine(false); } else @@ -576,7 +576,7 @@ void XclImpHFConverter::CreateCurrObject() { InsertText(); SetAttribs(); - GetCurrObj() = mrEE.CreateTextObject(); + GetCurrObj() = std::make_shared(mrEE.CreateTextObject()); } void XclImpHFConverter::SetNewPortion( XclImpHFPortion eNew ) diff --git a/sc/source/filter/inc/richstring.hxx b/sc/source/filter/inc/richstring.hxx index a38701fbb6e3..855b2363be8a 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 ); - std::unique_ptr convert( ScEditEngineDefaulter& rEE, const oox::xls::Font* pFont ); + EditTextObject convert( ScEditEngineDefaulter& rEE, const oox::xls::Font* pFont ); RichStringPortion& getPortion(sal_Int32 nPortionIdx) { return maTextPortions[nPortionIdx]; } diff --git a/sc/source/filter/inc/xihelper.hxx b/sc/source/filter/inc/xihelper.hxx index 83bbadbb7e72..7f3c0e901790 100644 --- a/sc/source/filter/inc/xihelper.hxx +++ b/sc/source/filter/inc/xihelper.hxx @@ -120,7 +120,7 @@ public: XclImpStringHelper() = delete; /** Returns a new edit engine text object. @param nXFIndex Index to XF for first text portion (for escapement). */ - static std::unique_ptr CreateTextObject( + static std::optional CreateTextObject( const XclImpRoot& rRoot, const XclImpString& rString ); diff --git a/sc/source/filter/oox/revisionfragment.cxx b/sc/source/filter/oox/revisionfragment.cxx index d8dc26c89505..f6e8b07e8d2b 100644 --- a/sc/source/filter/oox/revisionfragment.cxx +++ b/sc/source/filter/oox/revisionfragment.cxx @@ -142,13 +142,10 @@ protected: { // The value is a rich text string. ScDocument& rDoc = getScDocument(); - std::unique_ptr pTextObj = mxRichString->convert(rDoc.GetEditEngine(), nullptr); - if (pTextObj) - { - svl::SharedStringPool& rPool = rDoc.GetSharedStringPool(); - pTextObj->NormalizeString(rPool); - mrCellValue.set(std::move(pTextObj)); - } + EditTextObject aTextObj = mxRichString->convert(rDoc.GetEditEngine(), nullptr); + svl::SharedStringPool& rPool = rDoc.GetSharedStringPool(); + aTextObj.NormalizeString(rPool); + mrCellValue.set(std::move(aTextObj)); } } break; diff --git a/sc/source/filter/oox/richstring.cxx b/sc/source/filter/oox/richstring.cxx index 6f2a75b5f721..6a810974c8c8 100644 --- a/sc/source/filter/oox/richstring.cxx +++ b/sc/source/filter/oox/richstring.cxx @@ -405,7 +405,7 @@ OUString RichString::getStringContent() const return sString.makeStringAndClear(); } -std::unique_ptr RichString::convert( ScEditEngineDefaulter& rEE, const oox::xls::Font* pFirstPortionFont ) +EditTextObject RichString::convert( ScEditEngineDefaulter& rEE, const oox::xls::Font* pFirstPortionFont ) { ESelection aSelection; diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx index 1c8d24e2bbad..4d64e556ac33 100644 --- a/sc/source/filter/oox/worksheethelper.cxx +++ b/sc/source/filter/oox/worksheethelper.cxx @@ -1074,7 +1074,7 @@ void WorksheetGlobals::insertHyperlink( const ScAddress& rAddress, const OUStrin SvxFieldItem aURLItem(aURLField, EE_FEATURE_FIELD); rEE.QuickInsertField(aURLItem, ESelection()); - rDoc.setEditCell(rAddress, rEE.CreateTextObject()); + rDoc.setEditCell(rAddress, std::make_unique(rEE.CreateTextObject())); } else { @@ -1611,7 +1611,7 @@ void WorksheetHelper::putRichString( const ScAddress& rAddress, RichString& rStr rEE.SetSingleLine(bSingleLine); // The cell will own the text object instance returned from convert(). - getDocImport().setEditCell(rAddress, rString.convert(rEE, pFirstPortionFont)); + getDocImport().setEditCell(rAddress, std::make_unique(rString.convert(rEE, pFirstPortionFont))); rEE.SetSingleLine(false); } diff --git a/sc/source/filter/orcus/interface.cxx b/sc/source/filter/orcus/interface.cxx index 3b257f5d9b66..0c3f1a07c56f 100644 --- a/sc/source/filter/orcus/interface.cxx +++ b/sc/source/filter/orcus/interface.cxx @@ -1600,7 +1600,8 @@ size_t ScOrcusSharedStrings::commit_segments() for (const auto & [ rSel, rFormat ] : maFormatSegments) mrEditEngine.QuickSetAttribs(rFormat, rSel); - auto nPos = mrFactory.appendFormattedString(mrEditEngine.CreateTextObject()); + auto nPos = mrFactory.appendFormattedString( + std::make_unique(mrEditEngine.CreateTextObject())); mrEditEngine.Clear(); maFormatSegments.clear(); return nPos; diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx index 025bab138519..981545445b17 100644 --- a/sc/source/filter/rtf/eeimpars.cxx +++ b/sc/source/filter/rtf/eeimpars.cxx @@ -413,10 +413,11 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu mrDoc.SetTextCell(ScAddress(nCol, nRow, nTab), aStr, &aParam); } } - else if (std::unique_ptr pTextObject = IsValidSel(*mpEngine, pE->aSel) ? mpEngine->CreateTextObject(pE->aSel) : nullptr) + else if (IsValidSel(*mpEngine, pE->aSel)) { + EditTextObject aTextObject = mpEngine->CreateTextObject(pE->aSel); // The cell will own the text object instance. - mrDoc.SetEditText(ScAddress(nCol,nRow,nTab), std::move(pTextObject)); + mrDoc.SetEditText(ScAddress(nCol,nRow,nTab), std::move(aTextObject)); } if ( !pE->maImageList.empty() ) bHasGraphics |= GraphicSize( nCol, nRow, pE ); diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx index ee3175cc58c8..76bea8d8e5a2 100644 --- a/sc/source/filter/xml/xmlcelli.cxx +++ b/sc/source/filter/xml/xmlcelli.cxx @@ -1138,7 +1138,7 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos, // This edit engine uses the SfxItemPool instance returned // from pDoc->GetEditPool() to create the text object, which // is a prerequisite for using this constructor of ScEditCell. - rDoc.setEditCell(rCurrentPos, mpEditEngine->CreateTextObject()); + rDoc.setEditCell(rCurrentPos, std::make_unique(mpEditEngine->CreateTextObject())); } } else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() ) diff --git a/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx b/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx index 4ed3cb2e0ecd..47764af60876 100644 --- a/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx +++ b/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx @@ -222,8 +222,8 @@ void AddressWalkerWriter::writeBoldString(const OUString& aString) aItemSet.Put(aWeight); aItemSet.Put(aJustify); rEngine.QuickSetAttribs(aItemSet, ESelection(0, 0, 0, aString.getLength()) ); - std::unique_ptr pEditText(rEngine.CreateTextObject()); - mpDocShell->GetDocFunc().SetEditCell(mCurrentAddress, *pEditText, true); + EditTextObject aEditText(rEngine.CreateTextObject()); + mpDocShell->GetDocFunc().SetEditCell(mCurrentAddress, aEditText, true); } void AddressWalkerWriter::writeValue(double aValue) diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx index 449370c5e4d1..9899ca5d348e 100644 --- a/sc/source/ui/app/inputhdl.cxx +++ b/sc/source/ui/app/inputhdl.cxx @@ -3333,7 +3333,7 @@ void ScInputHandler::EnterHandler( ScEnterMode nBlockMode, bool bBeforeSavingInL void ScInputHandler::EnterHandler2(ScEnterMode nBlockMode, bool bForget, OUString aString, const OUString& aPreAutoCorrectString) { - std::unique_ptr pObject; + std::optional oObject; std::unique_ptr pCellAttrs; bool bMatrix = (nBlockMode == ScEnterMode::MATRIX); SfxApplication* pSfxApp = SfxGetpApp(); @@ -3499,7 +3499,7 @@ void ScInputHandler::EnterHandler2(ScEnterMode nBlockMode, bool bForget, OUStrin if (bAttrib) { mpEditEngine->ClearSpellErrors(); - pObject = mpEditEngine->CreateTextObject(); + oObject.emplace(mpEditEngine->CreateTextObject()); } else if (ScModule::get()->GetAppOptions().GetAutoComplete()) // Adjust Upper/Lower case { @@ -3601,14 +3601,14 @@ void ScInputHandler::EnterHandler2(ScEnterMode nBlockMode, bool bForget, OUStrin { ScInputStatusItem aItem(FID_INPUTLINE_STATUS, aCursorPos, aCursorPos, aCursorPos, - aPreAutoCorrectString, pObject.get()); + aPreAutoCorrectString, oObject ? &*oObject : nullptr); aArgs[0] = &aItem; rBindings.Execute(nId, aArgs); } ScInputStatusItem aItemCorrected(FID_INPUTLINE_STATUS, aCursorPos, aCursorPos, aCursorPos, - aString, pObject.get()); + aString, oObject ? &*oObject : nullptr); sc::MisspellRangeResult aMisspellRangeResult; if ( !aMisspellRanges.empty() ) @@ -4739,9 +4739,8 @@ bool ScInputHandler::GetTextAndFields( ScEditEngineDefaulter& rDestEngine ) if ( eFieldState == SfxItemState::INVALID || eFieldState == SfxItemState::SET ) { // Copy content - std::unique_ptr pObj = mpEditEngine->CreateTextObject(); - rDestEngine.SetTextCurrentDefaults(*pObj); - pObj.reset(); + EditTextObject aObj = mpEditEngine->CreateTextObject(); + rDestEngine.SetTextCurrentDefaults(aObj); sal_Int32 nParCnt = mpEditEngine->GetParagraphCount(); // Delete attributes diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index cbf7842a9093..d3d5892cb490 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -730,8 +730,8 @@ bool ScDocFunc::SetStringOrEditCell( const ScAddress& rPos, const OUString& rStr { ScFieldEditEngine& rEngine = rDoc.GetEditEngine(); rEngine.SetTextCurrentDefaults(rStr); - std::unique_ptr pEditText(rEngine.CreateTextObject()); - return SetEditCell(rPos, *pEditText, bInteraction); + EditTextObject aEditText(rEngine.CreateTextObject()); + return SetEditCell(rPos, aEditText, bInteraction); } else return SetStringCell(rPos, rStr, bInteraction); @@ -869,8 +869,8 @@ void ScDocFunc::PutData( const ScAddress& rPos, ScEditEngineDefaulter& rEngine, } // A copy of pNewData will be stored in the cell. - std::unique_ptr pNewData(rEngine.CreateTextObject()); - bRet = SetEditCell(rPos, *pNewData, !bApi); + EditTextObject aNewData(rEngine.CreateTextObject()); + bRet = SetEditCell(rPos, aNewData, !bApi); // Set the paragraph attributes back to the EditEngine. for (const auto& rxItem : aRememberItems) diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index c09f3bf22b0b..f736420209ce 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -1069,7 +1069,7 @@ static bool lcl_PutString( { ScFieldEditEngine& rEngine = rDoc.GetEditEngine(); rEngine.SetTextCurrentDefaults(rStr); - rDocImport.setEditCell(ScAddress(nCol, nRow, nTab), rEngine.CreateTextObject()); + rDocImport.setEditCell(ScAddress(nCol, nRow, nTab), std::make_unique(rEngine.CreateTextObject())); return true; } else @@ -1480,7 +1480,7 @@ static bool lcl_PutString( ScFieldEditEngine& rEngine = rDoc.GetEditEngine(); rEngine.SetTextCurrentDefaults(rStr); if ( bUseDocImport ) - rDocImport.setEditCell(ScAddress(nCol, nRow, nTab), rEngine.CreateTextObject()); + rDocImport.setEditCell(ScAddress(nCol, nRow, nTab), std::make_unique(rEngine.CreateTextObject())); else rDoc.SetEditText( ScAddress( nCol, nRow, nTab ), rEngine.CreateTextObject() ); } diff --git a/sc/source/ui/inc/tphfedit.hxx b/sc/source/ui/inc/tphfedit.hxx index 11747452e0ff..de6ac2ff68b4 100644 --- a/sc/source/ui/inc/tphfedit.hxx +++ b/sc/source/ui/inc/tphfedit.hxx @@ -49,7 +49,7 @@ public: void SetFont( const ScPatternAttr& rPattern ); void SetText( const EditTextObject& rTextObject ); - std::unique_ptr CreateTextObject(); + EditTextObject CreateTextObject(); void SetCharAttributes(); void InsertField( const SvxFieldItem& rFld ); diff --git a/sc/source/ui/pagedlg/scuitphfedit.cxx b/sc/source/ui/pagedlg/scuitphfedit.cxx index c7525d3b0465..103fa489b460 100644 --- a/sc/source/ui/pagedlg/scuitphfedit.cxx +++ b/sc/source/ui/pagedlg/scuitphfedit.cxx @@ -229,13 +229,13 @@ void ScHFEditPage::Reset( const SfxItemSet* rCoreSet ) bool ScHFEditPage::FillItemSet( SfxItemSet* rCoreSet ) { ScPageHFItem aItem( nWhich ); - std::unique_ptr pLeft = m_xWndLeft->CreateTextObject(); - std::unique_ptr pCenter = m_xWndCenter->CreateTextObject(); - std::unique_ptr pRight = m_xWndRight->CreateTextObject(); + EditTextObject aLeft = m_xWndLeft->CreateTextObject(); + EditTextObject aCenter = m_xWndCenter->CreateTextObject(); + EditTextObject aRight = m_xWndRight->CreateTextObject(); - aItem.SetLeftArea ( *pLeft ); - aItem.SetCenterArea( *pCenter ); - aItem.SetRightArea ( *pRight ); + aItem.SetLeftArea ( aLeft ); + aItem.SetCenterArea( aCenter ); + aItem.SetRightArea ( aRight ); rCoreSet->Put( aItem ); @@ -341,17 +341,13 @@ void ScHFEditPage::SetSelectDefinedList() // default to customized ScHFEntryId eSelectEntry = eEntryCount; - std::unique_ptr< EditTextObject > pLeftObj; - std::unique_ptr< EditTextObject > pCenterObj; - std::unique_ptr< EditTextObject > pRightObj; - OUString aLeftEntry; OUString aCenterEntry; OUString aRightEntry; - pLeftObj = m_xWndLeft->GetEditEngine()->CreateTextObject(); - pCenterObj = m_xWndCenter->GetEditEngine()->CreateTextObject(); - pRightObj = m_xWndRight->GetEditEngine()->CreateTextObject(); + EditTextObject aLeftObj = m_xWndLeft->GetEditEngine()->CreateTextObject(); + EditTextObject aCenterObj = m_xWndCenter->GetEditEngine()->CreateTextObject(); + EditTextObject aRightObj = m_xWndRight->GetEditEngine()->CreateTextObject(); bool bFound = false; @@ -362,9 +358,9 @@ void ScHFEditPage::SetSelectDefinedList() { case eNoneEntry: { - aLeftEntry = pLeftObj->GetText(0); - aCenterEntry = pCenterObj->GetText(0); - aRightEntry = pRightObj->GetText(0); + aLeftEntry = aLeftObj.GetText(0); + aCenterEntry = aCenterObj.GetText(0); + aRightEntry = aRightObj.GetText(0); if(aLeftEntry.isEmpty() && aCenterEntry.isEmpty() && aRightEntry.isEmpty()) { @@ -376,11 +372,11 @@ void ScHFEditPage::SetSelectDefinedList() case ePageEntry: { - aLeftEntry = pLeftObj->GetText(0); - aRightEntry = pRightObj->GetText(0); + aLeftEntry = aLeftObj.GetText(0); + aRightEntry = aRightObj.GetText(0); if(aLeftEntry.isEmpty() && aRightEntry.isEmpty()) { - if(IsPageEntry(m_xWndCenter->GetEditEngine(), pCenterObj.get())) + if(IsPageEntry(m_xWndCenter->GetEditEngine(), &aCenterObj)) { eSelectEntry = ePageEntry; bFound = true; @@ -397,13 +393,13 @@ void ScHFEditPage::SetSelectDefinedList() case eSheetEntry: { - aLeftEntry = pLeftObj->GetText(0); - aRightEntry = pRightObj->GetText(0); + aLeftEntry = aLeftObj.GetText(0); + aRightEntry = aRightObj.GetText(0); if(aLeftEntry.isEmpty() && aRightEntry.isEmpty()) { - if(pCenterObj->IsFieldObject()) + if(aCenterObj.IsFieldObject()) { - const SvxFieldItem* pFieldItem = pCenterObj->GetField(); + const SvxFieldItem* pFieldItem = aCenterObj.GetField(); if(pFieldItem) { const SvxFieldData* pField = pFieldItem->GetField(); @@ -420,7 +416,7 @@ void ScHFEditPage::SetSelectDefinedList() case eConfidentialEntry: { - if(IsDateEntry(pCenterObj.get()) && IsPageEntry(m_xWndRight->GetEditEngine(), pRightObj.get())) + if(IsDateEntry(&aCenterObj) && IsPageEntry(m_xWndRight->GetEditEngine(), &aRightObj)) { OUString aConfidentialEntry(aUserOpt.GetCompany() + " " + m_xFtConfidential->get_label()); if(aConfidentialEntry == m_xWndLeft->GetEditEngine()->GetText(0)) @@ -440,9 +436,9 @@ void ScHFEditPage::SetSelectDefinedList() case eExtFileNameEntry: { - aLeftEntry = pLeftObj->GetText(0); - aRightEntry = pRightObj->GetText(0); - if(IsExtFileNameEntry(pCenterObj.get()) && aLeftEntry.isEmpty() + aLeftEntry = aLeftObj.GetText(0); + aRightEntry = aRightObj.GetText(0); + if(IsExtFileNameEntry(&aCenterObj) && aLeftEntry.isEmpty() && aRightEntry.isEmpty()) { eSelectEntry = eExtFileNameEntry; @@ -465,9 +461,9 @@ void ScHFEditPage::SetSelectDefinedList() case ePageExtFileNameEntry: { - aLeftEntry = pLeftObj->GetText(0); - if(IsPageEntry(m_xWndCenter->GetEditEngine(), pCenterObj.get()) && - IsExtFileNameEntry(pRightObj.get()) && aLeftEntry.isEmpty()) + aLeftEntry = aLeftObj.GetText(0); + if(IsPageEntry(m_xWndCenter->GetEditEngine(), &aCenterObj) && + IsExtFileNameEntry(&aRightObj) && aLeftEntry.isEmpty()) { eSelectEntry = ePageExtFileNameEntry; bFound = true; @@ -477,7 +473,7 @@ void ScHFEditPage::SetSelectDefinedList() case eUserNameEntry: { - if(IsDateEntry(pRightObj.get()) && IsPageEntry(m_xWndCenter->GetEditEngine(), pCenterObj.get())) + if(IsDateEntry(&aRightObj) && IsPageEntry(m_xWndCenter->GetEditEngine(), &aCenterObj)) { OUString aUserNameEntry(aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName()); @@ -492,7 +488,7 @@ void ScHFEditPage::SetSelectDefinedList() case eCreatedByEntry: { - if(IsDateEntry(pCenterObj.get()) && IsPageEntry(m_xWndRight->GetEditEngine(), pRightObj.get())) + if(IsDateEntry(&aCenterObj) && IsPageEntry(m_xWndRight->GetEditEngine(), &aRightObj)) { OUString aCreatedByEntry(m_xFtCreatedBy->get_label() + " " + aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName()); @@ -538,10 +534,10 @@ bool ScHFEditPage::IsPageEntry(EditEngine*pEngine, const EditTextObject* pTextOb { aSel.start.nIndex = aSel.end.nIndex; aSel.end.nIndex++; - std::unique_ptr< EditTextObject > pPageObj = pEngine->CreateTextObject(aSel); - if(pPageObj && pPageObj->IsFieldObject() ) + EditTextObject aPageObj = pEngine->CreateTextObject(aSel); + if(aPageObj.IsFieldObject() ) { - const SvxFieldItem* pFieldItem = pPageObj->GetField(); + const SvxFieldItem* pFieldItem = aPageObj.GetField(); if(pFieldItem) { const SvxFieldData* pField = pFieldItem->GetField(); @@ -595,7 +591,6 @@ bool ScHFEditPage::IsExtFileNameEntry(const EditTextObject* pTextObj) void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling) { SvtUserOptions aUserOpt; - std::unique_ptr< EditTextObject > pTextObj; switch(eSel) { @@ -630,8 +625,7 @@ void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling) m_xWndCenter->GetEditEngine()->QuickInsertText(aPageOfEntry,ESelection(aSel.end)); aSel.end.nIndex += aPageOfEntry.getLength(); m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD), ESelection(aSel.end)); - pTextObj = m_xWndCenter->GetEditEngine()->CreateTextObject(); - m_xWndCenter->SetText(*pTextObj); + m_xWndCenter->SetText(m_xWndCenter->GetEditEngine()->CreateTextObject()); if(!bTravelling) m_xWndCenter->GrabFocus(); } @@ -670,8 +664,7 @@ void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling) aSel.start.nIndex = aSel.end.nIndex; aSel.end.nIndex += aPageEntry.getLength(); m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.end)); - pTextObj = m_xWndCenter->GetEditEngine()->CreateTextObject(); - m_xWndCenter->SetText(*pTextObj); + m_xWndCenter->SetText(m_xWndCenter->GetEditEngine()->CreateTextObject()); if(!bTravelling) m_xWndCenter->GrabFocus(); } @@ -699,8 +692,7 @@ void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling) m_xWndCenter->GetEditEngine()->QuickInsertText(aCommaSpace,ESelection(aSel.end)); aSel.end.nIndex += aCommaSpace.getLength(); m_xWndCenter->GetEditEngine()->QuickInsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), ESelection(aSel.end)); - pTextObj = m_xWndCenter->GetEditEngine()->CreateTextObject(); - m_xWndCenter->SetText(*pTextObj); + m_xWndCenter->SetText(m_xWndCenter->GetEditEngine()->CreateTextObject()); if(!bTravelling) m_xWndCenter->GrabFocus(); } @@ -719,8 +711,7 @@ void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling) m_xWndCenter->GetEditEngine()->QuickInsertText(aCommaSpace,ESelection(aSel.end)); aSel.end.nIndex += aCommaSpace.getLength(); m_xWndCenter->GetEditEngine()->QuickInsertField( SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD), ESelection(aSel.end)); - pTextObj = m_xWndCenter->GetEditEngine()->CreateTextObject(); - m_xWndCenter->SetText(*pTextObj); + m_xWndCenter->SetText(m_xWndCenter->GetEditEngine()->CreateTextObject()); if(!bTravelling) m_xWndCenter->GrabFocus(); } diff --git a/sc/source/ui/pagedlg/tphfedit.cxx b/sc/source/ui/pagedlg/tphfedit.cxx index f69c790c19ff..b86f937ffafd 100644 --- a/sc/source/ui/pagedlg/tphfedit.cxx +++ b/sc/source/ui/pagedlg/tphfedit.cxx @@ -129,7 +129,7 @@ void ScEditWindow::SetNumType(SvxNumType eNumType) pEditEngine->UpdateFields(); } -std::unique_ptr ScEditWindow::CreateTextObject() +EditTextObject ScEditWindow::CreateTextObject() { // reset paragraph attributes // (GetAttribs at creation of format dialog always returns the set items) diff --git a/sc/source/ui/unoobj/fielduno.cxx b/sc/source/ui/unoobj/fielduno.cxx index 0adbee4fee03..a0f22e41911e 100644 --- a/sc/source/ui/unoobj/fielduno.cxx +++ b/sc/source/ui/unoobj/fielduno.cxx @@ -192,8 +192,8 @@ ScUnoEditEngine::ScUnoEditEngine(ScEditEngineDefaulter* pSource) , nFieldPos(0) , nFieldIndex(0) { - std::unique_ptr pData = pSource->CreateTextObject(); - SetTextCurrentDefaults( *pData ); + EditTextObject aData = pSource->CreateTextObject(); + SetTextCurrentDefaults( aData ); } OUString ScUnoEditEngine::CalcFieldValue( const SvxFieldItem& rField, diff --git a/sc/source/ui/unoobj/textuno.cxx b/sc/source/ui/unoobj/textuno.cxx index a2de724a4b1b..884990dce6ea 100644 --- a/sc/source/ui/unoobj/textuno.cxx +++ b/sc/source/ui/unoobj/textuno.cxx @@ -221,13 +221,13 @@ void ScHeaderFooterTextData::UpdateData() { if (pEditEngine) { - mpTextObj = pEditEngine->CreateTextObject(); + mpTextObj = std::make_unique(pEditEngine->CreateTextObject()); } } void ScHeaderFooterTextData::UpdateData(EditEngine& rEditEngine) { - mpTextObj = rEditEngine.CreateTextObject(); + mpTextObj = std::make_unique(rEditEngine.CreateTextObject()); bDataValid = false; } @@ -720,7 +720,7 @@ void ScEditEngineTextObj::SetText( const EditTextObject& rTextObject ) SetSelection( aSel ); } -std::unique_ptr ScEditEngineTextObj::CreateTextObject() +EditTextObject ScEditEngineTextObj::CreateTextObject() { return GetEditEngine()->CreateTextObject(); } diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index dee484a8af76..0e54fa6d1a99 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -5940,7 +5940,7 @@ bool extractURLInfo( const SvxFieldItem* pFieldItem, OUString* pName, OUString* static void lcl_SetEngineTextKeepingDefaults(const std::shared_ptr& pEngine, ScDocument& rDoc, ScRefCellValue& rCell, const OUString& rURL) { - std::unique_ptr pTextObj; + std::optional oTextObj; if (rCell.getType() == CELLTYPE_EDIT) { if (rCell.getEditText()) @@ -5951,7 +5951,7 @@ static void lcl_SetEngineTextKeepingDefaults(const std::shared_ptrCreateURLObject(); + oTextObj.emplace(rCell.getFormula()->CreateURLObject()); else { OUString aRepres = rURL; @@ -5962,11 +5962,11 @@ static void lcl_SetEngineTextKeepingDefaults(const std::shared_ptrGetString().getString(); - pTextObj = ScEditUtil::CreateURLObjectFromURL(rDoc, rURL, aRepres); + oTextObj.emplace(ScEditUtil::CreateURLObjectFromURL(rDoc, rURL, aRepres)); } - if (pTextObj) - pEngine->SetTextCurrentDefaults(*pTextObj); + if (oTextObj) + pEngine->SetTextCurrentDefaults(*oTextObj); } } diff --git a/sc/source/ui/view/spelleng.cxx b/sc/source/ui/view/spelleng.cxx index c60d1361b1e9..368178b9c7d1 100644 --- a/sc/source/ui/view/spelleng.cxx +++ b/sc/source/ui/view/spelleng.cxx @@ -126,8 +126,8 @@ bool ScConversionEngineBase::FindNextConversionCell() if (!bSimpleString || eCellType == CELLTYPE_EDIT) { - std::unique_ptr pEditObj(CreateTextObject()); - mrDoc.SetEditText(aPos, *pEditObj, GetItemPool()); + EditTextObject aEditObj(CreateTextObject()); + mrDoc.SetEditText(aPos, aEditObj, GetItemPool()); } else { diff --git a/sc/source/ui/view/viewfun4.cxx b/sc/source/ui/view/viewfun4.cxx index fecfb4db2b8e..9cce9a688bea 100644 --- a/sc/source/ui/view/viewfun4.cxx +++ b/sc/source/ui/view/viewfun4.cxx @@ -128,8 +128,8 @@ void ScViewFunc::PasteRTF( SCCOL nStartCol, SCROW nStartRow, rDoc.EnableUndo( false ); for( sal_Int32 n = 0; n < nParCnt; n++ ) { - std::unique_ptr pObject(pEngine->CreateTextObject(n)); - EnterData(nStartCol, nRow, nTab, *pObject, true); + EditTextObject aObject(pEngine->CreateTextObject(n)); + EnterData(nStartCol, nRow, nTab, aObject, true); if( ++nRow > rDoc.MaxRow() ) break; } @@ -406,10 +406,9 @@ void ScViewFunc::DoThesaurus() if (aOldText.getType() == CELLTYPE_EDIT) { // The cell will own the text object instance. - std::unique_ptr pText = pThesaurusEngine->CreateTextObject(); - auto tmp = pText.get(); - if (rDoc.SetEditText(ScAddress(nCol,nRow,nTab), std::move(pText))) - aNewText.set(*tmp); + EditTextObject* pText = new EditTextObject(pThesaurusEngine->CreateTextObject()); + if (rDoc.SetEditText(ScAddress(nCol,nRow,nTab), std::unique_ptr(pText))) + aNewText.set(*pText); } else { @@ -744,8 +743,8 @@ void ScViewFunc::InsertBookmark( const OUString& rDescription, const OUString& r aField.SetTargetFrame(*pTarget); aEngine.QuickInsertField( SvxFieldItem( aField, EE_FEATURE_FIELD ), aInsSel ); - std::unique_ptr pData(aEngine.CreateTextObject()); - EnterData(nPosX, nPosY, nTab, *pData); + EditTextObject aData(aEngine.CreateTextObject()); + EnterData(nPosX, nPosY, nTab, aData); } bool ScViewFunc::HasBookmarkAtCursor( SvxHyperlinkItem* pContent ) diff --git a/svx/source/dialog/ClassificationDialog.cxx b/svx/source/dialog/ClassificationDialog.cxx index 2164033f278b..e0bc4af21c2d 100644 --- a/svx/source/dialog/ClassificationDialog.cxx +++ b/svx/source/dialog/ClassificationDialog.cxx @@ -516,12 +516,12 @@ std::vector ClassificationDialog::getResult() std::vector aClassificationResults; ClassificationEditEngine& rEdEngine = m_xEditWindow->getEditEngine(); - std::unique_ptr pEditText(rEdEngine.CreateTextObject()); + EditTextObject aEditText(rEdEngine.CreateTextObject()); sal_Int32 nCurrentParagraph = -1; std::vector aSections; - pEditText->GetAllSections(aSections); + aEditText.GetAllSections(aSections); for (editeng::Section const & rSection : aSections) { while (nCurrentParagraph < rSection.mnParagraph) @@ -575,9 +575,9 @@ IMPL_LINK(ClassificationDialog, SelectClassificationHdl, weld::ComboBox&, rBox, if (nSelected < 0 || m_nCurrentSelectedCategory == nSelected) return; - std::unique_ptr pEditText(m_xEditWindow->getEditEngine().CreateTextObject()); + EditTextObject aEditText(m_xEditWindow->getEditEngine().CreateTextObject()); std::vector aSections; - pEditText->GetAllSections(aSections); + aEditText.GetAllSections(aSections); // if we are replacing an existing field bool bReplaceExisting = false; diff --git a/svx/source/dialog/weldeditview.cxx b/svx/source/dialog/weldeditview.cxx index 71b0e354095f..fc7e2428eb86 100644 --- a/svx/source/dialog/weldeditview.cxx +++ b/svx/source/dialog/weldeditview.cxx @@ -1472,8 +1472,8 @@ void WeldTextForwarder::CopyText(const SvxTextForwarder& rSource) EditEngine* pEditEngine = m_rEditAcc.GetEditEngine(); if (pEditEngine && pSourceEditEngine) { - std::unique_ptr pNewTextObject = pSourceEditEngine->CreateTextObject(); - pEditEngine->SetText(*pNewTextObject); + EditTextObject aNewTextObject = pSourceEditEngine->CreateTextObject(); + pEditEngine->SetText(aNewTextObject); } } diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx index dd14ca9131d7..ed67aaa3de94 100644 --- a/sw/source/filter/ww8/ww8graf.cxx +++ b/sw/source/filter/ww8/ww8graf.cxx @@ -1050,8 +1050,8 @@ std::optional SwWW8ImplReader::ImportAsOutliner(OUString &rS m_pDrawEditEngine->QuickDelete(aFirstChar); } - std::unique_ptr pTemporaryText = m_pDrawEditEngine->CreateTextObject(); - pRet.emplace( std::move(pTemporaryText) ); + EditTextObject aTemporaryText = m_pDrawEditEngine->CreateTextObject(); + pRet.emplace( std::move(aTemporaryText) ); pRet->SetOutlinerMode( OutlinerMode::TextObject ); m_pDrawEditEngine->SetText( OUString() );