diff options
26 files changed, 174 insertions, 192 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index bc05e844812e..4ed169e10152 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -613,7 +613,7 @@ public: SC_DLLPUBLIC void GetRangeNameMap(std::map<OUString, ScRangeName*>& rRangeName); SC_DLLPUBLIC ScRangeName* GetRangeName(SCTAB nTab) const; SC_DLLPUBLIC ScRangeName* GetRangeName() const; - void SetRangeName(SCTAB nTab, ScRangeName* pNew); + void SetRangeName(SCTAB nTab, std::unique_ptr<ScRangeName> pNew); void SetRangeName( std::unique_ptr<ScRangeName> pNewRangeName ); bool IsAddressInRangeName( RangeNameScope eScope, ScAddress& rAddress); @@ -818,7 +818,7 @@ public: OUString GetCopyTabName(SCTAB nTab) const; - SC_DLLPUBLIC void SetAnonymousDBData(SCTAB nTab, ScDBData* pDBData); + SC_DLLPUBLIC void SetAnonymousDBData(SCTAB nTab, std::unique_ptr<ScDBData> pDBData); SC_DLLPUBLIC ScDBData* GetAnonymousDBData(SCTAB nTab); /** One document global anonymous database range for temporary operations, @@ -1016,7 +1016,7 @@ public: bool HasAnyDraw( SCTAB nTab, const tools::Rectangle& rMMRect ) const; const ScSheetEvents* GetSheetEvents( SCTAB nTab ) const; - void SetSheetEvents( SCTAB nTab, const ScSheetEvents* pNew ); + void SetSheetEvents( SCTAB nTab, std::unique_ptr<ScSheetEvents> pNew ); bool HasSheetEventScript( SCTAB nTab, ScSheetEventId nEvent, bool bWithVbaEvents = false ) const; bool HasAnySheetEventScript( ScSheetEventId nEvent, bool bWithVbaEvents = false ) const; // on any sheet @@ -1929,8 +1929,8 @@ public: SC_DLLPUBLIC void AddPrintRange( SCTAB nTab, const ScRange& rNew ); /** Marks the specified sheet to be printed completely. Deletes old print ranges on the sheet! */ SC_DLLPUBLIC void SetPrintEntireSheet( SCTAB nTab ); - SC_DLLPUBLIC void SetRepeatColRange( SCTAB nTab, const ScRange* pNew ); - SC_DLLPUBLIC void SetRepeatRowRange( SCTAB nTab, const ScRange* pNew ); + SC_DLLPUBLIC void SetRepeatColRange( SCTAB nTab, std::unique_ptr<ScRange> pNew ); + SC_DLLPUBLIC void SetRepeatRowRange( SCTAB nTab, std::unique_ptr<ScRange> pNew ); ScPrintRangeSaver* CreatePrintRangeSaver() const; void RestorePrintRanges( const ScPrintRangeSaver& rSaver ); diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 08ddea363fbf..cb98a23f94af 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -183,7 +183,7 @@ private: std::unique_ptr<ScFlatUInt16RowSegments> mpRowHeights; std::unique_ptr<ScBitMaskCompressedArray<SCCOL, CRFlags>> mpColFlags; - ScBitMaskCompressedArray< SCROW, CRFlags>* pRowFlags; + std::unique_ptr<ScBitMaskCompressedArray< SCROW, CRFlags>> pRowFlags; std::unique_ptr<ScFlatBoolColSegments> mpHiddenCols; std::unique_ptr<ScFlatBoolRowSegments> mpHiddenRows; std::unique_ptr<ScFlatBoolColSegments> mpFilteredCols; @@ -194,16 +194,16 @@ private: ::std::set<SCCOL> maColPageBreaks; ::std::set<SCCOL> maColManualBreaks; - ScOutlineTable* pOutlineTable; + std::unique_ptr<ScOutlineTable> pOutlineTable; - ScSheetEvents* pSheetEvents; + std::unique_ptr<ScSheetEvents> pSheetEvents; mutable SCCOL nTableAreaX; mutable SCROW nTableAreaY; SCTAB nTab; ScDocument* pDocument; - utl::TextSearch* pSearchText; + std::unique_ptr<utl::TextSearch> pSearchText; mutable OUString aUpperName; // #i62977# filled only on demand, reset in SetName @@ -213,17 +213,17 @@ private: ScRangeVec aPrintRanges; - ScRange* pRepeatColRange; - ScRange* pRepeatRowRange; + std::unique_ptr<ScRange> pRepeatColRange; + std::unique_ptr<ScRange> pRepeatRowRange; sal_uInt16 nLockCount; - ScRangeList* pScenarioRanges; + std::unique_ptr<ScRangeList> pScenarioRanges; Color aScenarioColor; Color aTabBgColor; ScScenarioFlags nScenarioFlags; - ScDBData* pDBDataNoName; - mutable ScRangeName* mpRangeName; + std::unique_ptr<ScDBData> pDBDataNoName; + mutable std::unique_ptr<ScRangeName> mpRangeName; std::unique_ptr<ScConditionalFormatList> mpCondFormatList; @@ -275,7 +275,7 @@ public: const ScDocument& GetDoc() const { return *pDocument;} SCTAB GetTab() const { return nTab; } - ScOutlineTable* GetOutlineTable() { return pOutlineTable; } + ScOutlineTable* GetOutlineTable() { return pOutlineTable.get(); } ScColumn& CreateColumnIfNotExists( const SCCOL nScCol ) { @@ -307,8 +307,8 @@ public: void RemoveSubTotals( ScSubTotalParam& rParam ); bool DoSubTotals( ScSubTotalParam& rParam ); - const ScSheetEvents* GetSheetEvents() const { return pSheetEvents; } - void SetSheetEvents( const ScSheetEvents* pNew ); + const ScSheetEvents* GetSheetEvents() const { return pSheetEvents.get(); } + void SetSheetEvents( std::unique_ptr<ScSheetEvents> pNew ); bool IsVisible() const { return bVisible; } void SetVisible( bool bVis ); @@ -369,8 +369,8 @@ public: void GetName( OUString& rName ) const; void SetName( const OUString& rNewName ); - void SetAnonymousDBData(ScDBData* pDBData); - ScDBData* GetAnonymousDBData() { return pDBDataNoName;} + void SetAnonymousDBData(std::unique_ptr<ScDBData> pDBData); + ScDBData* GetAnonymousDBData() { return pDBDataNoName.get();} void GetCodeName( OUString& rName ) const { rName = aCodeName; } void SetCodeName( const OUString& rNewName ) { aCodeName = rNewName; } @@ -749,10 +749,10 @@ public: void ClearSelectionItems( const sal_uInt16* pWhich, const ScMarkData& rMark ); void ChangeSelectionIndent( bool bIncrement, const ScMarkData& rMark ); - const ScRange* GetRepeatColRange() const { return pRepeatColRange; } - const ScRange* GetRepeatRowRange() const { return pRepeatRowRange; } - void SetRepeatColRange( const ScRange* pNew ); - void SetRepeatRowRange( const ScRange* pNew ); + const ScRange* GetRepeatColRange() const { return pRepeatColRange.get(); } + const ScRange* GetRepeatRowRange() const { return pRepeatRowRange.get(); } + void SetRepeatColRange( std::unique_ptr<ScRange> pNew ); + void SetRepeatRowRange( std::unique_ptr<ScRange> pNew ); sal_uInt16 GetPrintRangeCount() const { return static_cast< sal_uInt16 >( aPrintRanges.size() ); } const ScRange* GetPrintRange(sal_uInt16 nPos) const; @@ -854,7 +854,7 @@ public: CRFlags GetRowFlags( SCROW nRow ) const; const ScBitMaskCompressedArray< SCROW, CRFlags> * GetRowFlagsArray() const - { return pRowFlags; } + { return pRowFlags.get(); } bool UpdateOutlineCol( SCCOL nStartCol, SCCOL nEndCol, bool bShow ); bool UpdateOutlineRow( SCROW nStartRow, SCROW nEndRow, bool bShow ); @@ -961,7 +961,7 @@ public: void DestroySortCollator(); void SetDrawPageSize( bool bResetStreamValid = true, bool bUpdateNoteCaptionPos = true ); - void SetRangeName(ScRangeName* pNew); + void SetRangeName(std::unique_ptr<ScRangeName> pNew); ScRangeName* GetRangeName() const; void PreprocessRangeNameUpdate( diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx index 24250db69aed..0c4eeb808145 100644 --- a/sc/qa/unit/filters-test.cxx +++ b/sc/qa/unit/filters-test.cxx @@ -608,8 +608,8 @@ void ScFiltersTest::testSortWithSharedFormulasODS() // Set A1:E17 as an anonymous database range to sheet, or else Calc would // refuse to sort the range. - ScDBData* pDBData = new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 4, 16, true, true); - rDoc.SetAnonymousDBData(0, pDBData); + std::unique_ptr<ScDBData> pDBData(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 4, 16, true, true)); + rDoc.SetAnonymousDBData(0, std::move(pDBData)); // Sort ascending by Column E. @@ -722,8 +722,8 @@ void ScFiltersTest::testSortWithSheetExternalReferencesODS_Impl( ScDocShellRef c } // Set as an anonymous database range to sort. - ScDBData* pDBData = new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, nRow1, 3, nRow2, true, true); - rDoc.SetAnonymousDBData(0, pDBData); + std::unique_ptr<ScDBData> pDBData(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, nRow1, 3, nRow2, true, true)); + rDoc.SetAnonymousDBData(0, std::move(pDBData)); // Sort descending by Column A. ScSortParam aSortData; diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 59b9d51824a1..eff48bfd5581 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -1553,12 +1553,12 @@ void Test::testNamedRange() ScRangeData* pLocal2 = new ScRangeData( m_pDoc, "local2", "$Sheet1.$A$1"); ScRangeData* pLocal3 = new ScRangeData( m_pDoc, "local3", "Sheet1.$A$1"); ScRangeData* pLocal4 = new ScRangeData( m_pDoc, "local4", "$A$1"); // implicit relative sheet reference - ScRangeName* pLocalRangeName1 = new ScRangeName; + std::unique_ptr<ScRangeName> pLocalRangeName1(new ScRangeName); pLocalRangeName1->insert(pLocal1); pLocalRangeName1->insert(pLocal2); pLocalRangeName1->insert(pLocal3); pLocalRangeName1->insert(pLocal4); - m_pDoc->SetRangeName(0, pLocalRangeName1); + m_pDoc->SetRangeName(0, std::move(pLocalRangeName1)); CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet", m_pDoc->InsertTab (1, "Sheet2")); @@ -3045,7 +3045,7 @@ void Test::testAutofilter() m_pDoc->SetString(j, i, 0, OUString::createFromAscii(aData[i][j])); ScDBData* pDBData = new ScDBData(aDBName, 0, 0, 0, nCols-1, nRows-1); - m_pDoc->SetAnonymousDBData(0,pDBData); + m_pDoc->SetAnonymousDBData(0, std::unique_ptr<ScDBData>(pDBData)); pDBData->SetAutoFilter(true); ScRange aRange; @@ -3121,7 +3121,7 @@ void Test::testAutoFilterTimeValue() m_pDoc->SetValue(ScAddress(0,2,0), 265); ScDBData* pDBData = new ScDBData(STR_DB_GLOBAL_NONAME, 0, 0, 0, 0, 2); - m_pDoc->SetAnonymousDBData(0, pDBData); + m_pDoc->SetAnonymousDBData(0, std::unique_ptr<ScDBData>(pDBData)); // Apply the "hour:minute:second" format to A2:A3. SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable(); @@ -3196,7 +3196,7 @@ void Test::testAdvancedFilter() } ScDBData* pDBData = new ScDBData(STR_DB_GLOBAL_NONAME, 0, 0, 0, 1, 10); - m_pDoc->SetAnonymousDBData(0, pDBData); + m_pDoc->SetAnonymousDBData(0, std::unique_ptr<ScDBData>(pDBData)); ScRange aDataRange(0,0,0,1,10,0); ScRange aFilterRuleRange(0,12,0,1,13,0); @@ -3285,14 +3285,14 @@ void Test::testCopyPaste() std::unique_ptr<ScRangeName> pGlobalRangeName(new ScRangeName()); pGlobalRangeName->insert(pGlobal); pGlobalRangeName->insert(pGlobal2); - ScRangeName* pLocalRangeName1 = new ScRangeName(); + std::unique_ptr<ScRangeName> pLocalRangeName1(new ScRangeName()); pLocalRangeName1->insert(pLocal1); pLocalRangeName1->insert(pLocal2); pLocalRangeName1->insert(pLocal3); pLocalRangeName1->insert(pLocal4); pLocalRangeName1->insert(pLocal5); m_pDoc->SetRangeName(std::move(pGlobalRangeName)); - m_pDoc->SetRangeName(0, pLocalRangeName1); + m_pDoc->SetRangeName(0, std::move(pLocalRangeName1)); // Add formula to B1. OUString aFormulaString("=local1+global+SUM($C$1:$D$4)+local3+local4+local5"); diff --git a/sc/qa/unit/ucalc_sort.cxx b/sc/qa/unit/ucalc_sort.cxx index 2aa4a441ab0c..048b53b33969 100644 --- a/sc/qa/unit/ucalc_sort.cxx +++ b/sc/qa/unit/ucalc_sort.cxx @@ -156,7 +156,7 @@ void Test::testSortHorizontal() // Define A1:D4 as sheet-local anonymous database range. m_pDoc->SetAnonymousDBData( - 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 3, 3)); + 0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 3, 3))); // Sort A1:D4 horizontally, ascending by row 1. ScDBDocFunc aFunc(getDocShell()); @@ -223,7 +223,7 @@ void Test::testSortHorizontalWholeColumn() // Define C:G as sheet-local anonymous database range. m_pDoc->SetAnonymousDBData( - 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, nCol1, nRow1, nCol2, nRow2, false, false)); + 0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, nCol1, nRow1, nCol2, nRow2, false, false))); // Sort C:G horizontally ascending by row 1. ScDBDocFunc aFunc(getDocShell()); @@ -284,7 +284,7 @@ void Test::testSortSingleRow() // Define A1:B1 as sheet-local anonymous database range. m_pDoc->SetAnonymousDBData( - 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 1, 0)); + 0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 1, 0))); // Sort A1:B1 horizontally, ascending by row 1. ScDBDocFunc aFunc(getDocShell()); @@ -319,7 +319,7 @@ void Test::testSortSingleRow() // Define A1:G1 as sheet-local anonymous database range. m_pDoc->SetAnonymousDBData( - 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 6, 0, false, true)); + 0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 6, 0, false, true))); // Update the sort data. aSortData.nCol1 = 0; @@ -660,7 +660,7 @@ void Test::testSortWithCellFormats() // Define A1:A4 as sheet-local anonymous database range, else sort wouldn't run. m_pDoc->SetAnonymousDBData( - 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 0, 3)); + 0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 0, 3))); // Sort A1:A4 ascending with cell formats. ScDBDocFunc aFunc(getDocShell()); @@ -732,7 +732,7 @@ void Test::testSortRefUpdate() // Define A1:A10 as sheet-local anonymous database range, else sort wouldn't run. m_pDoc->SetAnonymousDBData( - 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 0, 9)); + 0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 0, 9))); // Sort A1:A10 (with a header row). ScSortParam aSortData; @@ -883,7 +883,7 @@ void Test::testSortRefUpdate2() // Define A1:B5 as sheet-local anonymous database range, else sort wouldn't run. m_pDoc->SetAnonymousDBData( - 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 1, 4)); + 0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 1, 4))); // Sort A1:B5 by column A (with a row header). ScSortParam aSortData; @@ -968,7 +968,7 @@ void Test::testSortRefUpdate3() // Sort A1:A6. m_pDoc->SetAnonymousDBData( - 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 0, 5)); + 0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 0, 5))); // Sort A1:A6 by column A (with a row header). ScSortParam aSortData; @@ -1111,8 +1111,8 @@ void Test::testSortRefUpdate4_Impl() aSortData.maKeyState[0].nField = 3; // Average aSortData.maKeyState[0].bAscending = false; // descending - m_pDoc->SetAnonymousDBData( 0, new ScDBData( STR_DB_LOCAL_NONAME, aSortRange.aStart.Tab(), - aSortData.nCol1, aSortData.nRow1, aSortData.nCol2, aSortData.nRow2)); + m_pDoc->SetAnonymousDBData( 0, std::unique_ptr<ScDBData>(new ScDBData( STR_DB_LOCAL_NONAME, aSortRange.aStart.Tab(), + aSortData.nCol1, aSortData.nRow1, aSortData.nCol2, aSortData.nRow2))); bool bSorted = aFunc.Sort(0, aSortData, true, true, true); CPPUNIT_ASSERT(bSorted); @@ -1182,8 +1182,8 @@ void Test::testSortRefUpdate4_Impl() aSortData.maKeyState[0].nField = 0; // Name aSortData.maKeyState[0].bAscending = false; // descending - m_pDoc->SetAnonymousDBData( 0, new ScDBData( STR_DB_LOCAL_NONAME, aSortRange.aStart.Tab(), - aSortData.nCol1, aSortData.nRow1, aSortData.nCol2, aSortData.nRow2)); + m_pDoc->SetAnonymousDBData( 0, std::unique_ptr<ScDBData>(new ScDBData( STR_DB_LOCAL_NONAME, aSortRange.aStart.Tab(), + aSortData.nCol1, aSortData.nRow1, aSortData.nCol2, aSortData.nRow2))); bool bSorted = aFunc.Sort(0, aSortData, true, true, true); CPPUNIT_ASSERT(bSorted); @@ -1273,8 +1273,8 @@ void Test::testSortRefUpdate5() ScDBDocFunc aFunc(getDocShell()); // Sort A1:B5. - m_pDoc->SetAnonymousDBData( 0, new ScDBData( STR_DB_LOCAL_NONAME, aSortRange.aStart.Tab(), - aSortRange.aStart.Col(), aSortRange.aStart.Row(), aSortRange.aEnd.Col(), aSortRange.aEnd.Row())); + m_pDoc->SetAnonymousDBData( 0, std::unique_ptr<ScDBData>(new ScDBData( STR_DB_LOCAL_NONAME, aSortRange.aStart.Tab(), + aSortRange.aStart.Col(), aSortRange.aStart.Row(), aSortRange.aEnd.Col(), aSortRange.aEnd.Row()))); // Sort by column A. ScSortParam aSortData; @@ -1369,7 +1369,7 @@ void Test::testSortRefUpdate6() // Sort A1:C4. m_pDoc->SetAnonymousDBData( - 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 2, 3)); + 0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 2, 3))); // Sort A1:A6 by column A (with a row header). ScSortParam aSortData; @@ -1502,7 +1502,7 @@ void Test::testSortBroadcaster() // Sort A1:B2. m_pDoc->SetAnonymousDBData( - 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 1, 1)); + 0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 1, 1))); ScDBDocFunc aFunc(getDocShell()); @@ -1599,7 +1599,7 @@ void Test::testSortBroadcaster() // Sort A5:B6. m_pDoc->SetAnonymousDBData( - 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 4, 1, 5)); + 0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 4, 1, 5))); ScDBDocFunc aFunc(getDocShell()); @@ -1702,7 +1702,7 @@ void Test::testSortBroadcastBroadcaster() // Sort A1:A2. m_pDoc->SetAnonymousDBData( - 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 0, 1)); + 0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 0, 1))); ScDBDocFunc aFunc(getDocShell()); @@ -1772,7 +1772,7 @@ void Test::testSortOutOfPlaceResult() // Sort A1:A6, and set the result to C2:C7 m_pDoc->SetAnonymousDBData( - 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 0, 5)); + 0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 0, 5))); ScSortParam aSortData; aSortData.nCol1 = 0; @@ -1851,7 +1851,7 @@ void Test::testSortPartialFormulaGroup() // Sort only B2:B4. This caused crash at one point (c.f. fdo#81617). - m_pDoc->SetAnonymousDBData(0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 1, 1, 1, 3)); + m_pDoc->SetAnonymousDBData(0, std::unique_ptr<ScDBData>(new ScDBData(STR_DB_LOCAL_NONAME, 0, 1, 1, 1, 3))); ScSortParam aSortData; aSortData.nCol1 = 1; diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx index 4dc59a8127e7..5ef81ccde30e 100644 --- a/sc/source/core/data/documen3.cxx +++ b/sc/source/core/data/documen3.cxx @@ -114,7 +114,7 @@ void ScDocument::GetAllTabRangeNames(ScRangeName::TabNameCopyMap& rNames) const // no more tables to iterate through. break; - const ScRangeName* p = maTabs[i]->mpRangeName; + const ScRangeName* p = maTabs[i]->mpRangeName.get(); if (!p || p->empty()) // ignore empty ones. continue; @@ -145,7 +145,7 @@ void ScDocument::SetAllRangeNames(const std::map<OUString, std::unique_ptr<ScRan if (pName->empty()) SetRangeName( nTab, nullptr ); else - SetRangeName( nTab, new ScRangeName( *pName ) ); + SetRangeName( nTab, std::unique_ptr<ScRangeName>(new ScRangeName( *pName )) ); } } } @@ -160,7 +160,7 @@ void ScDocument::GetRangeNameMap(std::map<OUString, ScRangeName*>& aRangeNameMap if (!p ) { p = new ScRangeName(); - SetRangeName(i, p); + SetRangeName(i, std::unique_ptr<ScRangeName>(p)); } OUString aTableName; maTabs[i]->GetName(aTableName); @@ -189,12 +189,12 @@ ScRangeName* ScDocument::GetRangeName() const return pRangeName.get(); } -void ScDocument::SetRangeName(SCTAB nTab, ScRangeName* pNew) +void ScDocument::SetRangeName(SCTAB nTab, std::unique_ptr<ScRangeName> pNew) { if (!ValidTab(nTab) || nTab >= static_cast<SCTAB>(maTabs.size()) || !maTabs[nTab]) return; - return maTabs[nTab]->SetRangeName(pNew); + return maTabs[nTab]->SetRangeName(std::move(pNew)); } void ScDocument::SetRangeName( std::unique_ptr<ScRangeName> pNewRangeName ) @@ -654,10 +654,10 @@ const ScSheetEvents* ScDocument::GetSheetEvents( SCTAB nTab ) const return nullptr; } -void ScDocument::SetSheetEvents( SCTAB nTab, const ScSheetEvents* pNew ) +void ScDocument::SetSheetEvents( SCTAB nTab, std::unique_ptr<ScSheetEvents> pNew ) { if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab]) - maTabs[nTab]->SetSheetEvents( pNew ); + maTabs[nTab]->SetSheetEvents( std::move(pNew) ); } bool ScDocument::HasSheetEventScript( SCTAB nTab, ScSheetEventId nEvent, bool bWithVbaEvents ) const diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index f9de8433ed13..878887211ccb 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -313,10 +313,10 @@ SCTAB ScDocument::GetTableCount() const return static_cast<SCTAB>(maTabs.size()); } -void ScDocument::SetAnonymousDBData(SCTAB nTab, ScDBData* pDBData) +void ScDocument::SetAnonymousDBData(SCTAB nTab, std::unique_ptr<ScDBData> pDBData) { if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab]) - maTabs[nTab]->SetAnonymousDBData(pDBData); + maTabs[nTab]->SetAnonymousDBData(std::move(pDBData)); } void ScDocument::SetAnonymousDBData( std::unique_ptr<ScDBData> pDBData ) @@ -6256,16 +6256,16 @@ void ScDocument::SetPrintEntireSheet( SCTAB nTab ) maTabs[nTab]->SetPrintEntireSheet(); } -void ScDocument::SetRepeatColRange( SCTAB nTab, const ScRange* pNew ) +void ScDocument::SetRepeatColRange( SCTAB nTab, std::unique_ptr<ScRange> pNew ) { if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab]) - maTabs[nTab]->SetRepeatColRange( pNew ); + maTabs[nTab]->SetRepeatColRange( std::move(pNew) ); } -void ScDocument::SetRepeatRowRange( SCTAB nTab, const ScRange* pNew ) +void ScDocument::SetRepeatRowRange( SCTAB nTab, std::unique_ptr<ScRange> pNew ) { if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab]) - maTabs[nTab]->SetRepeatRowRange( pNew ); + maTabs[nTab]->SetRepeatRowRange( std::move(pNew) ); } ScPrintRangeSaver* ScDocument::CreatePrintRangeSaver() const diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index 3cb2301f2cc1..17f3b037166d 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -296,7 +296,7 @@ ScTable::ScTable( ScDocument* pDoc, SCTAB nNewTab, const OUString& rNewName, if (bRowInfo) { mpRowHeights.reset(new ScFlatUInt16RowSegments(ScGlobal::nStdRowHeight)); - pRowFlags = new ScBitMaskCompressedArray<SCROW, CRFlags>( MAXROW, CRFlags::NONE); + pRowFlags.reset(new ScBitMaskCompressedArray<SCROW, CRFlags>( MAXROW, CRFlags::NONE)); } if ( pDocument->IsDocVisible() ) @@ -339,15 +339,15 @@ ScTable::~ScTable() COVERITY_NOEXCEPT_FALSE pDrawLayer->ScRemovePage( nTab ); } - delete pRowFlags; - delete pSheetEvents; - delete pOutlineTable; - delete pSearchText; - delete pRepeatColRange; - delete pRepeatRowRange; - delete pScenarioRanges; - delete mpRangeName; - delete pDBDataNoName; + pRowFlags.reset(); + pSheetEvents.reset(); + pOutlineTable.reset(); + pSearchText.reset(); + pRepeatColRange.reset(); + pRepeatRowRange.reset(); + pScenarioRanges.reset(); + mpRangeName.reset(); + pDBDataNoName.reset(); DestroySortCollator(); } @@ -488,7 +488,7 @@ bool ScTable::SetOptimalHeight( rCxt.getHeightArray().enableTreeSearch(true); SetRowHeightRangeFunc aFunc(this, rCxt.getPPTY()); - bool bChanged = SetOptimalHeightsToRows(rCxt, aFunc, pRowFlags, nStartRow, nEndRow); + bool bChanged = SetOptimalHeightsToRows(rCxt, aFunc, pRowFlags.get(), nStartRow, nEndRow); if ( pProgress != pOuterProgress ) delete pProgress; @@ -515,7 +515,7 @@ void ScTable::SetOptimalHeightOnly( SetRowHeightOnlyFunc aFunc(this); rCxt.getHeightArray().enableTreeSearch(true); - SetOptimalHeightsToRows(rCxt, aFunc, pRowFlags, nStartRow, nEndRow); + SetOptimalHeightsToRows(rCxt, aFunc, pRowFlags.get(), nStartRow, nEndRow); if ( pProgress != pOuterProgress ) delete pProgress; @@ -2005,19 +2005,6 @@ public: } }; -void setPrintRange(ScRange*& pRange1, const ScRange* pRange2) -{ - if (pRange2) - { - if (pRange1) - *pRange1 = *pRange2; - else - pRange1 = new ScRange(*pRange2); - } - else - DELETEZ(pRange1); -} - } void ScTable::CopyPrintRange(const ScTable& rTable) @@ -2030,37 +2017,35 @@ void ScTable::CopyPrintRange(const ScTable& rTable) bPrintEntireSheet = rTable.bPrintEntireSheet; - delete pRepeatColRange; - pRepeatColRange = nullptr; + pRepeatColRange.reset(); if (rTable.pRepeatColRange) { - pRepeatColRange = new ScRange(*rTable.pRepeatColRange); + pRepeatColRange.reset(new ScRange(*rTable.pRepeatColRange)); pRepeatColRange->aStart.SetTab(nTab); pRepeatColRange->aEnd.SetTab(nTab); } - delete pRepeatRowRange; - pRepeatRowRange = nullptr; + pRepeatRowRange.reset(); if (rTable.pRepeatRowRange) { - pRepeatRowRange = new ScRange(*rTable.pRepeatRowRange); + pRepeatRowRange.reset(new ScRange(*rTable.pRepeatRowRange)); pRepeatRowRange->aStart.SetTab(nTab); pRepeatRowRange->aEnd.SetTab(nTab); } } -void ScTable::SetRepeatColRange( const ScRange* pNew ) +void ScTable::SetRepeatColRange( std::unique_ptr<ScRange> pNew ) { - setPrintRange( pRepeatColRange, pNew ); + pRepeatColRange = std::move(pNew); SetStreamValid(false); InvalidatePageBreaks(); } -void ScTable::SetRepeatRowRange( const ScRange* pNew ) +void ScTable::SetRepeatRowRange( std::unique_ptr<ScRange> pNew ) { - setPrintRange( pRepeatRowRange, pNew ); + pRepeatRowRange = std::move(pNew); SetStreamValid(false); @@ -2105,15 +2090,17 @@ const ScRange* ScTable::GetPrintRange(sal_uInt16 nPos) const void ScTable::FillPrintSaver( ScPrintSaverTab& rSaveTab ) const { rSaveTab.SetAreas( aPrintRanges, bPrintEntireSheet ); - rSaveTab.SetRepeat( pRepeatColRange, pRepeatRowRange ); + rSaveTab.SetRepeat( pRepeatColRange.get(), pRepeatRowRange.get() ); } void ScTable::RestorePrintRanges( const ScPrintSaverTab& rSaveTab ) { aPrintRanges = rSaveTab.GetPrintRanges(); bPrintEntireSheet = rSaveTab.IsEntireSheet(); - SetRepeatColRange( rSaveTab.GetRepeatCol() ); - SetRepeatRowRange( rSaveTab.GetRepeatRow() ); + auto p = rSaveTab.GetRepeatCol(); + SetRepeatColRange( std::unique_ptr<ScRange>(p ? new ScRange(*p) : nullptr) ); + p = rSaveTab.GetRepeatRow(); + SetRepeatRowRange( std::unique_ptr<ScRange>(p ? new ScRange(*p) : nullptr) ); InvalidatePageBreaks(); // #i117952# forget page breaks for an old print range UpdatePageBreaks(nullptr); @@ -2213,10 +2200,9 @@ ScRefCellValue ScTable::VisibleDataCellIterator::next() return ScRefCellValue(); } -void ScTable::SetAnonymousDBData(ScDBData* pDBData) +void ScTable::SetAnonymousDBData(std::unique_ptr<ScDBData> pDBData) { - delete pDBDataNoName; - pDBDataNoName = pDBData; + pDBDataNoName = std::move(pDBData); } sal_uLong ScTable::AddCondFormat( ScConditionalFormat* pNew ) diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 4e51b19b345e..340e087bb927 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -101,17 +101,15 @@ bool ScTable::SetOutlineTable( const ScOutlineTable* pNewOutline ) { nOldSizeX = pOutlineTable->GetColArray().GetDepth(); nOldSizeY = pOutlineTable->GetRowArray().GetDepth(); - delete pOutlineTable; + pOutlineTable.reset(); } if (pNewOutline) { - pOutlineTable = new ScOutlineTable( *pNewOutline ); + pOutlineTable.reset(new ScOutlineTable( *pNewOutline )); nNewSizeX = pOutlineTable->GetColArray().GetDepth(); nNewSizeY = pOutlineTable->GetRowArray().GetDepth(); } - else - pOutlineTable = nullptr; return ( nNewSizeX != nOldSizeX || nNewSizeY != nOldSizeY ); // changed size? } @@ -119,16 +117,12 @@ bool ScTable::SetOutlineTable( const ScOutlineTable* pNewOutline ) void ScTable::StartOutlineTable() { if (!pOutlineTable) - pOutlineTable = new ScOutlineTable; + pOutlineTable.reset(new ScOutlineTable); } -void ScTable::SetSheetEvents( const ScSheetEvents* pNew ) +void ScTable::SetSheetEvents( std::unique_ptr<ScSheetEvents> pNew ) { - delete pSheetEvents; - if (pNew) - pSheetEvents = new ScSheetEvents(*pNew); - else - pSheetEvents = nullptr; + pSheetEvents = std::move(pNew); SetCalcNotification( false ); // discard notifications before the events were set @@ -494,7 +488,7 @@ void ScTable::CopyToClip( // copy content //local range names need to be copied first for formula cells if (!pTable->mpRangeName && mpRangeName) - pTable->mpRangeName = new ScRangeName(*mpRangeName); + pTable->mpRangeName.reset( new ScRangeName(*mpRangeName) ); SCCOL i; @@ -510,7 +504,7 @@ void ScTable::CopyToClip( pTable->CopyColHidden(*this, 0, nCol2); pTable->CopyColFiltered(*this, 0, nCol2); if (pDBDataNoName) - pTable->SetAnonymousDBData(new ScDBData(*pDBDataNoName)); + pTable->SetAnonymousDBData(std::unique_ptr<ScDBData>(new ScDBData(*pDBDataNoName))); if (pRowFlags && pTable->pRowFlags && mpRowHeights && pTable->mpRowHeights) { @@ -1150,13 +1144,13 @@ void ScTable::CopyToTable( if (pDBDataNoName) { - ScDBData* pNewDBData = new ScDBData(*pDBDataNoName); + std::unique_ptr<ScDBData> pNewDBData(new ScDBData(*pDBDataNoName)); SCCOL aCol1, aCol2; SCROW aRow1, aRow2; SCTAB aTab; pNewDBData->GetArea(aTab, aCol1, aRow1, aCol2, aRow2); pNewDBData->MoveTo(pDestTab->nTab, aCol1, aRow1, aCol2, aRow2); - pDestTab->SetAnonymousDBData(pNewDBData); + pDestTab->SetAnonymousDBData(std::move(pNewDBData)); } // Charts have to be adjusted when hide/show ScChartListenerCollection* pCharts = pDestTab->pDocument->GetChartListenerCollection(); @@ -1249,7 +1243,7 @@ void ScTable::CopyToTable( } if(nFlags & InsertDeleteFlags::OUTLINE) // also only when bColRowFlags - pDestTab->SetOutlineTable( pOutlineTable ); + pDestTab->SetOutlineTable( pOutlineTable.get() ); if (bCopyCaptions && (nFlags & (InsertDeleteFlags::NOTE | InsertDeleteFlags::ADDNOTES))) { @@ -1375,8 +1369,7 @@ bool ScTable::HasScenarioRange( const ScRange& rRange ) const void ScTable::InvalidateScenarioRanges() { - delete pScenarioRanges; - pScenarioRanges = nullptr; + pScenarioRanges.reset(); } const ScRangeList* ScTable::GetScenarioRanges() const @@ -1385,12 +1378,12 @@ const ScRangeList* ScTable::GetScenarioRanges() const if (!pScenarioRanges) { - const_cast<ScTable*>(this)->pScenarioRanges = new ScRangeList; + const_cast<ScTable*>(this)->pScenarioRanges.reset(new ScRangeList); ScMarkData aMark; MarkScenarioIn( aMark, ScScenarioFlags::NONE ); // always - aMark.FillRangeListWithMarks( pScenarioRanges, false ); + aMark.FillRangeListWithMarks( pScenarioRanges.get(), false ); } - return pScenarioRanges; + return pScenarioRanges.get(); } bool ScTable::TestCopyScenarioTo( const ScTable* pDestTab ) const @@ -3790,10 +3783,9 @@ void ScTable::SetDrawPageSize(bool bResetStreamValid, bool bUpdateNoteCaptionPos SetStreamValid(false); } -void ScTable::SetRangeName(ScRangeName* pNew) +void ScTable::SetRangeName(std::unique_ptr<ScRangeName> pNew) { - delete mpRangeName; - mpRangeName = pNew; + mpRangeName = std::move(pNew); //fdo#39792: mark stream as invalid, otherwise new ScRangeName will not be written to file SetStreamValid(false); @@ -3802,8 +3794,8 @@ void ScTable::SetRangeName(ScRangeName* pNew) ScRangeName* ScTable::GetRangeName() const { if (!mpRangeName) - mpRangeName = new ScRangeName; - return mpRangeName; + mpRangeName.reset(new ScRangeName); + return mpRangeName.get(); } sal_uLong ScTable::GetRowOffset( SCROW nRow, bool bHiddenAsZero ) const diff --git a/sc/source/core/data/table5.cxx b/sc/source/core/data/table5.cxx index c39fb3816c94..85f62b7ecc87 100644 --- a/sc/source/core/data/table5.cxx +++ b/sc/source/core/data/table5.cxx @@ -1033,8 +1033,8 @@ void ScTable::SyncColRowFlags() } // Hidden flags. - lcl_syncFlags(*mpHiddenCols, *mpHiddenRows, mpColFlags.get(), pRowFlags, CRFlags::Hidden); - lcl_syncFlags(*mpFilteredCols, *mpFilteredRows, mpColFlags.get(), pRowFlags, CRFlags::Filtered); + lcl_syncFlags(*mpHiddenCols, *mpHiddenRows, mpColFlags.get(), pRowFlags.get(), CRFlags::Hidden); + lcl_syncFlags(*mpFilteredCols, *mpFilteredRows, mpColFlags.get(), pRowFlags.get(), CRFlags::Filtered); } void ScTable::SetPageSize( const Size& rSize ) diff --git a/sc/source/core/data/table6.cxx b/sc/source/core/data/table6.cxx index efdb51803935..5a4f36fe3d70 100644 --- a/sc/source/core/data/table6.cxx +++ b/sc/source/core/data/table6.cxx @@ -815,7 +815,7 @@ bool ScTable::SearchAndReplace( ( TransliterationFlags::IGNORE_CASE | TransliterationFlags::IGNORE_WIDTH ); - pSearchText = new utl::TextSearch( aSearchOptions ); + pSearchText.reset( new utl::TextSearch( aSearchOptions ) ); if (nCommand == SvxSearchCmd::FIND) bFound = Search(rSearchItem, rCol, rRow, rMark, rUndoStr, pUndoDoc); @@ -826,8 +826,7 @@ bool ScTable::SearchAndReplace( else if (nCommand == SvxSearchCmd::REPLACE_ALL) bFound = ReplaceAll(rSearchItem, rMark, rMatchedRanges, rUndoStr, pUndoDoc); - delete pSearchText; - pSearchText = nullptr; + pSearchText.reset(); } } return bFound; diff --git a/sc/source/filter/excel/excimp8.cxx b/sc/source/filter/excel/excimp8.cxx index aa3e630f5d09..2cf116b9ee4d 100644 --- a/sc/source/filter/excel/excimp8.cxx +++ b/sc/source/filter/excel/excimp8.cxx @@ -794,7 +794,7 @@ void XclImpAutoFilterData::Apply() } else pCurrDBData->SetAdvancedQuerySource(nullptr); - rDoc.SetAnonymousDBData(Tab(), pCurrDBData); + rDoc.SetAnonymousDBData(Tab(), std::unique_ptr<ScDBData>(pCurrDBData)); } if( bActive ) diff --git a/sc/source/filter/excel/impop.cxx b/sc/source/filter/excel/impop.cxx index 56b2de54f441..136904fa87c4 100644 --- a/sc/source/filter/excel/impop.cxx +++ b/sc/source/filter/excel/impop.cxx @@ -1348,13 +1348,13 @@ void ImportExcel::PostDocLoad() { if( p->aStart.Col() == 0 && p->aEnd.Col() == MAXCOL && bRowVirgin ) { - pD->SetRepeatRowRange( n, p ); + pD->SetRepeatRowRange( n, std::unique_ptr<ScRange>(new ScRange(*p)) ); bRowVirgin = false; } if( p->aStart.Row() == 0 && p->aEnd.Row() == MAXROW && bColVirgin ) { - pD->SetRepeatColRange( n, p ); + pD->SetRepeatColRange( n, std::unique_ptr<ScRange>(new ScRange(*p)) ); bColVirgin = false; } diff --git a/sc/source/filter/oox/workbookhelper.cxx b/sc/source/filter/oox/workbookhelper.cxx index b37638da99cb..ce72e708e029 100644 --- a/sc/source/filter/oox/workbookhelper.cxx +++ b/sc/source/filter/oox/workbookhelper.cxx @@ -455,10 +455,10 @@ Reference< XDatabaseRange > WorkbookGlobals::createUnnamedDatabaseRangeObject( c ScDocument& rDoc = getScDocument(); if( rDoc.GetTableCount() <= aDestRange.aStart.Tab() ) throw css::lang::IndexOutOfBoundsException(); - ScDBData* pNewDBData = new ScDBData( STR_DB_LOCAL_NONAME, aDestRange.aStart.Tab(), + std::unique_ptr<ScDBData> pNewDBData(new ScDBData( STR_DB_LOCAL_NONAME, aDestRange.aStart.Tab(), aDestRange.aStart.Col(), aDestRange.aStart.Row(), - aDestRange.aEnd.Col(), aDestRange.aEnd.Row() ); - rDoc.SetAnonymousDBData( aDestRange.aStart.Tab() , pNewDBData ); + aDestRange.aEnd.Col(), aDestRange.aEnd.Row() )); + rDoc.SetAnonymousDBData( aDestRange.aStart.Tab() , std::move(pNewDBData) ); ScDocShell* pDocSh = static_cast< ScDocShell* >(rDoc.GetDocumentShell()); xDatabaseRange.set(new ScDatabaseRangeObj(pDocSh, aDestRange.aStart.Tab())); } diff --git a/sc/source/filter/xml/xmldrani.cxx b/sc/source/filter/xml/xmldrani.cxx index 721f7f946a8f..d71a07e51769 100644 --- a/sc/source/filter/xml/xmldrani.cxx +++ b/sc/source/filter/xml/xmldrani.cxx @@ -417,7 +417,7 @@ void SAL_CALL ScXMLDatabaseRangeContext::endFastElement( sal_Int32 /*nElement*/ pData->GetArea(aRange); setAutoFilterFlags(*pDoc, *pData); - pDoc->SetAnonymousDBData(aRange.aStart.Tab(), pData.release()); + pDoc->SetAnonymousDBData(aRange.aStart.Tab(), std::move(pData)); } return; } @@ -431,7 +431,7 @@ void SAL_CALL ScXMLDatabaseRangeContext::endFastElement( sal_Int32 /*nElement*/ pData->GetArea(aRange); if (setAutoFilterFlags(*pDoc, *pData)) - pDoc->SetAnonymousDBData(aRange.aStart.Tab(), pData.release()); + pDoc->SetAnonymousDBData(aRange.aStart.Tab(), std::move(pData)); else pDoc->GetDBCollection()->getAnonDBs().insert(pData.release()); } diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx index 3a8a5d28de06..555101ec5602 100644 --- a/sc/source/ui/docshell/dbdocfun.cxx +++ b/sc/source/ui/docshell/dbdocfun.cxx @@ -71,9 +71,9 @@ bool ScDBDocFunc::AddDBRange( const OUString& rName, const ScRange& rRange ) if (bUndo) pUndoColl = new ScDBCollection( *pDocColl ); - ScDBData* pNew = new ScDBData( rName, rRange.aStart.Tab(), + std::unique_ptr<ScDBData> pNew(new ScDBData( rName, rRange.aStart.Tab(), rRange.aStart.Col(), rRange.aStart.Row(), - rRange.aEnd.Col(), rRange.aEnd.Row() ); + rRange.aEnd.Col(), rRange.aEnd.Row() )); // #i55926# While loading XML, formula cells only have a single string token, // so CompileDBFormula would never find any name (index) tokens, and would @@ -84,12 +84,12 @@ bool ScDBDocFunc::AddDBRange( const OUString& rName, const ScRange& rRange ) rDoc.PreprocessDBDataUpdate(); if ( rName == STR_DB_LOCAL_NONAME ) { - rDoc.SetAnonymousDBData(rRange.aStart.Tab() , pNew); + rDoc.SetAnonymousDBData(rRange.aStart.Tab(), std::move(pNew)); bOk = true; } else { - bOk = pDocColl->getNamedDBs().insert(pNew); + bOk = pDocColl->getNamedDBs().insert(pNew.release()); } if ( bCompile ) rDoc.CompileHybridFormula(); diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 55913db5f4c9..78b36aec755c 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -91,6 +91,7 @@ #include <cellvalues.hxx> #include <undoconvert.hxx> #include <docfuncutil.hxx> +#include <sheetevents.hxx> #include <memory> #include <utility> @@ -3213,7 +3214,8 @@ bool ScDocFunc::DeleteTable( SCTAB nTab, bool bRecord ) } pUndoDoc->SetVisible( nTab, rDoc.IsVisible( nTab ) ); pUndoDoc->SetTabBgColor( nTab, rDoc.GetTabBgColor(nTab) ); - pUndoDoc->SetSheetEvents( nTab, rDoc.GetSheetEvents( nTab ) ); + auto pSheetEvents = rDoc.GetSheetEvents( nTab ); + pUndoDoc->SetSheetEvents( nTab, std::unique_ptr<ScSheetEvents>(pSheetEvents ? new ScSheetEvents(*pSheetEvents) : nullptr) ); // Drawing-Layer has to take care of its own undo!!! rDoc.BeginDrawUndo(); // DeleteTab generates SdrUndoDelPage @@ -4985,10 +4987,10 @@ bool ScDocFunc::UnmergeCells( const ScCellMergeOption& rOption, bool bRecord, Sc void ScDocFunc::ModifyRangeNames( const ScRangeName& rNewRanges, SCTAB nTab ) { - SetNewRangeNames( new ScRangeName(rNewRanges), true, nTab ); + SetNewRangeNames( std::unique_ptr<ScRangeName>(new ScRangeName(rNewRanges)), true, nTab ); } -void ScDocFunc::SetNewRangeNames( ScRangeName* pNewRanges, bool bModifyDoc, SCTAB nTab ) // takes ownership of pNewRanges +void ScDocFunc::SetNewRangeNames( std::unique_ptr<ScRangeName> pNewRanges, bool bModifyDoc, SCTAB nTab ) // takes ownership of pNewRanges { ScDocShellModificator aModificator( rDocShell ); @@ -5021,9 +5023,9 @@ void ScDocFunc::SetNewRangeNames( ScRangeName* pNewRanges, bool bModifyDoc, SCTA if ( bCompile ) rDoc.PreprocessRangeNameUpdate(); if (nTab >= 0) - rDoc.SetRangeName( nTab, pNewRanges ); // takes ownership + rDoc.SetRangeName( nTab, std::move(pNewRanges) ); // takes ownership else - rDoc.SetRangeName( std::unique_ptr<ScRangeName>(pNewRanges) ); // takes ownership + rDoc.SetRangeName( std::move(pNewRanges) ); // takes ownership if ( bCompile ) rDoc.CompileHybridFormula(); diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx index 3eae94341395..935220d02c66 100644 --- a/sc/source/ui/docshell/docsh5.cxx +++ b/sc/source/ui/docshell/docsh5.cxx @@ -316,7 +316,7 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe pNoNameData = new ScDBData(STR_DB_LOCAL_NONAME, nTab, nStartCol,nStartRow, nEndCol,nEndRow, true, bHasHeader ); - aDocument.SetAnonymousDBData(nTab, pNoNameData); + aDocument.SetAnonymousDBData(nTab, std::unique_ptr<ScDBData>(pNoNameData)); } if ( pUndoColl ) diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx index 00e48f29b9eb..7252612c5b35 100644 --- a/sc/source/ui/inc/docfunc.hxx +++ b/sc/source/ui/inc/docfunc.hxx @@ -194,7 +194,7 @@ public: bool UnmergeCells( const ScCellMergeOption& rOption, bool bRecord, ScUndoRemoveMerge* pUndoRemoveMerge ); // takes ownership of pNewRanges, nTab = -1 for local range names - void SetNewRangeNames( ScRangeName* pNewRanges, bool bModifyDoc, SCTAB nTab ); + void SetNewRangeNames( std::unique_ptr<ScRangeName> pNewRanges, bool bModifyDoc, SCTAB nTab ); void ModifyRangeNames( const ScRangeName& rNewRanges, SCTAB nTab = -1 ); /** * Modify all range names, global scope names as well as sheet local ones, diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx index 9e8e09a1bb6f..0af818eb34c4 100644 --- a/sc/source/ui/undo/undocell.cxx +++ b/sc/source/ui/undo/undocell.cxx @@ -996,17 +996,19 @@ void ScUndoRangeNames::DoChange( bool bUndo ) if ( bUndo ) { + auto p = std::unique_ptr<ScRangeName>(new ScRangeName( *pOldRanges )); if (mnTab >= 0) - rDoc.SetRangeName( mnTab, new ScRangeName( *pOldRanges ) ); + rDoc.SetRangeName( mnTab, std::move(p) ); else - rDoc.SetRangeName( std::unique_ptr<ScRangeName>(new ScRangeName( *pOldRanges )) ); + rDoc.SetRangeName( std::move(p) ); } else { + auto p = std::unique_ptr<ScRangeName>(new ScRangeName( *pNewRanges )); if (mnTab >= 0) - rDoc.SetRangeName( mnTab, new ScRangeName( *pNewRanges ) ); + rDoc.SetRangeName( mnTab, std::move(p) ); else - rDoc.SetRangeName( std::unique_ptr<ScRangeName>(new ScRangeName( *pNewRanges )) ); + rDoc.SetRangeName( std::move(p) ); } rDoc.CompileHybridFormula(); diff --git a/sc/source/ui/undo/undotab.cxx b/sc/source/ui/undo/undotab.cxx index d99555e6a277..a92a2270e59d 100644 --- a/sc/source/ui/undo/undotab.cxx +++ b/sc/source/ui/undo/undotab.cxx @@ -47,6 +47,7 @@ #include <svx/svdpage.hxx> #include <drwlayer.hxx> #include <scresid.hxx> +#include <sheetevents.hxx> #include <memory> #include <utility> @@ -335,7 +336,8 @@ void ScUndoDeleteTab::Undo() } rDoc.SetVisible( nTab, pRefUndoDoc->IsVisible( nTab ) ); rDoc.SetTabBgColor( nTab, pRefUndoDoc->GetTabBgColor(nTab) ); - rDoc.SetSheetEvents( nTab, pRefUndoDoc->GetSheetEvents( nTab ) ); + auto pSheetEvents = pRefUndoDoc->GetSheetEvents( nTab ); + rDoc.SetSheetEvents( nTab, std::unique_ptr<ScSheetEvents>(pSheetEvents ? new ScSheetEvents(*pSheetEvents) : nullptr) ); rDoc.SetLayoutRTL( nTab, pRefUndoDoc->IsLayoutRTL( nTab ) ); if ( pRefUndoDoc->IsTabProtected( nTab ) ) diff --git a/sc/source/ui/undo/undoutil.cxx b/sc/source/ui/undo/undoutil.cxx index dce4612ce60d..e60431d6d99f 100644 --- a/sc/source/ui/undo/undoutil.cxx +++ b/sc/source/ui/undo/undoutil.cxx @@ -87,7 +87,7 @@ ScDBData* ScUndoUtil::GetOldDBData( const ScDBData* pUndoData, ScDocument* pDoc, pRet = new ScDBData( STR_DB_LOCAL_NONAME, nTab, nCol1,nRow1, nCol2,nRow2, true, pDoc->HasColHeader( nCol1,nRow1,nCol2,nRow2,nTab ) ); - pDoc->SetAnonymousDBData(nTab,pRet); + pDoc->SetAnonymousDBData(nTab, std::unique_ptr<ScDBData>(pRet)); } } diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index c5830ce06c56..c4cdf2f8b43d 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -7311,8 +7311,7 @@ void SAL_CALL ScTableSheetObj::setPrintTitleColumns( sal_Bool bPrintTitleColumns { if ( !rDoc.GetRepeatColRange( nTab ) ) // do not change existing area { - ScRange aNew( 0, 0, nTab, 0, 0, nTab ); - rDoc.SetRepeatColRange( nTab, &aNew ); // enable + rDoc.SetRepeatColRange( nTab, std::unique_ptr<ScRange>(new ScRange( 0, 0, nTab, 0, 0, nTab )) ); // enable } } else @@ -7354,9 +7353,9 @@ void SAL_CALL ScTableSheetObj::setTitleColumns( const table::CellRangeAddress& a ScPrintRangeSaver* pOldRanges = rDoc.CreatePrintRangeSaver(); - ScRange aNew; - ScUnoConversion::FillScRange( aNew, aTitleColumns ); - rDoc.SetRepeatColRange( nTab, &aNew ); // also always enable + std::unique_ptr<ScRange> pNew(new ScRange); + ScUnoConversion::FillScRange( *pNew, aTitleColumns ); + rDoc.SetRepeatColRange( nTab, std::move(pNew) ); // also always enable PrintAreaUndo_Impl( pOldRanges ); // undo, page breaks, modified etc. } @@ -7390,8 +7389,8 @@ void SAL_CALL ScTableSheetObj::setPrintTitleRows( sal_Bool bPrintTitleRows ) { if ( !rDoc.GetRepeatRowRange( nTab ) ) // do not change existing area { - ScRange aNew( 0, 0, nTab, 0, 0, nTab ); - rDoc.SetRepeatRowRange( nTab, &aNew ); // enable + std::unique_ptr<ScRange> pNew( new ScRange(0, 0, nTab, 0, 0, nTab) ); + rDoc.SetRepeatRowRange( nTab, std::move(pNew) ); // enable } } else @@ -7433,9 +7432,9 @@ void SAL_CALL ScTableSheetObj::setTitleRows( const table::CellRangeAddress& aTit ScPrintRangeSaver* pOldRanges = rDoc.CreatePrintRangeSaver(); - ScRange aNew; - ScUnoConversion::FillScRange( aNew, aTitleRows ); - rDoc.SetRepeatRowRange( nTab, &aNew ); // also always enable + std::unique_ptr<ScRange> pNew(new ScRange); + ScUnoConversion::FillScRange( *pNew, aTitleRows ); + rDoc.SetRepeatRowRange( nTab, std::move(pNew) ); // also always enable PrintAreaUndo_Impl( pOldRanges ); // Undo, page breaks, modified etc. } diff --git a/sc/source/ui/unoobj/eventuno.cxx b/sc/source/ui/unoobj/eventuno.cxx index 6d33ea9c74c5..4de0597dc809 100644 --- a/sc/source/ui/unoobj/eventuno.cxx +++ b/sc/source/ui/unoobj/eventuno.cxx @@ -74,10 +74,10 @@ void SAL_CALL ScSheetEventsObj::replaceByName( const OUString& aName, const uno: if (nEvent == ScSheetEventId::NOTFOUND) throw container::NoSuchElementException(); - ScSheetEvents aNewEvents; + std::unique_ptr<ScSheetEvents> pNewEvents(new ScSheetEvents); const ScSheetEvents* pOldEvents = mpDocShell->GetDocument().GetSheetEvents(mnTab); if (pOldEvents) - aNewEvents = *pOldEvents; + *pNewEvents = *pOldEvents; OUString aScript; if ( aElement.hasValue() ) // empty Any -> reset event @@ -105,11 +105,11 @@ void SAL_CALL ScSheetEventsObj::replaceByName( const OUString& aName, const uno: } } if (!aScript.isEmpty()) - aNewEvents.SetScript( nEvent, &aScript ); + pNewEvents->SetScript( nEvent, &aScript ); else - aNewEvents.SetScript( nEvent, nullptr ); // reset + pNewEvents->SetScript( nEvent, nullptr ); // reset - mpDocShell->GetDocument().SetSheetEvents( mnTab, &aNewEvents ); + mpDocShell->GetDocument().SetSheetEvents( mnTab, std::move(pNewEvents) ); mpDocShell->SetDocumentModified(); } diff --git a/sc/source/ui/unoobj/nameuno.cxx b/sc/source/ui/unoobj/nameuno.cxx index e1e7d1478c28..5e5ad772c0fe 100644 --- a/sc/source/ui/unoobj/nameuno.cxx +++ b/sc/source/ui/unoobj/nameuno.cxx @@ -169,7 +169,7 @@ void ScNamedRangeObj::Modify_Impl( const OUString* pNewName, const ScTokenArray* if (!pOld) return; - ScRangeName* pNewRanges = new ScRangeName(*pNames); + std::unique_ptr<ScRangeName> pNewRanges(new ScRangeName(*pNames)); OUString aInsName = pOld->GetName(); if (pNewName) @@ -199,14 +199,13 @@ void ScNamedRangeObj::Modify_Impl( const OUString* pNewName, const ScTokenArray* pNewRanges->erase(*pOld); if (pNewRanges->insert(pNew)) { - pDocShell->GetDocFunc().SetNewRangeNames(pNewRanges, mxParent->IsModifyAndBroadcast(), nTab); + pDocShell->GetDocFunc().SetNewRangeNames(std::move(pNewRanges), mxParent->IsModifyAndBroadcast(), nTab); aName = aInsName; //! broadcast? } else { pNew = nullptr; //! uno::Exception/Error or something - delete pNewRanges; } } @@ -492,19 +491,18 @@ void SAL_CALL ScNamedRangesObj::addNewByName( const OUString& aName, ScRangeName* pNames = GetRangeName_Impl(); if (pNames && !pNames->findByUpperName(ScGlobal::pCharClass->uppercase(aName))) { - ScRangeName* pNewRanges = new ScRangeName( *pNames ); + std::unique_ptr<ScRangeName> pNewRanges(new ScRangeName( *pNames )); // GRAM_API for API compatibility. ScRangeData* pNew = new ScRangeData( &rDoc, aName, aContent, aPos, nNewType,formula::FormulaGrammar::GRAM_API ); if ( pNewRanges->insert(pNew) ) { - pDocShell->GetDocFunc().SetNewRangeNames(pNewRanges, mbModifyAndBroadcast, GetTab_Impl()); + pDocShell->GetDocFunc().SetNewRangeNames(std::move(pNewRanges), mbModifyAndBroadcast, GetTab_Impl()); bDone = true; } else { pNew = nullptr; - delete pNewRanges; } } } @@ -549,9 +547,9 @@ void SAL_CALL ScNamedRangesObj::removeByName( const OUString& aName ) const ScRangeData* pData = pNames->findByUpperName(ScGlobal::pCharClass->uppercase(aName)); if (pData && lcl_UserVisibleName(*pData)) { - ScRangeName* pNewRanges = new ScRangeName(*pNames); + std::unique_ptr<ScRangeName> pNewRanges(new ScRangeName(*pNames)); pNewRanges->erase(*pData); - pDocShell->GetDocFunc().SetNewRangeNames( pNewRanges, mbModifyAndBroadcast, GetTab_Impl()); + pDocShell->GetDocFunc().SetNewRangeNames( std::move(pNewRanges), mbModifyAndBroadcast, GetTab_Impl()); bDone = true; } } diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index e176bbffb54c..6b3d0d83df0d 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -87,6 +87,7 @@ #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <comphelper/lok.hxx> #include <mergecellsdialog.hxx> +#include <sheetevents.hxx> #include <vector> #include <memory> @@ -1009,7 +1010,7 @@ void ScViewFunc::SetPrintRanges( bool bEntireSheet, const OUString* pPrint, rDoc.SetRepeatColRange( nTab, nullptr ); else if ( aRange.ParseAny( *pRepCol, &rDoc, aDetails ) & ScRefFlags::VALID ) - rDoc.SetRepeatColRange( nTab, &aRange ); + rDoc.SetRepeatColRange( nTab, std::unique_ptr<ScRange>(new ScRange(aRange)) ); } // repeat rows @@ -1020,7 +1021,7 @@ void ScViewFunc::SetPrintRanges( bool bEntireSheet, const OUString* pPrint, rDoc.SetRepeatRowRange( nTab, nullptr ); else if ( aRange.ParseAny( *pRepRow, &rDoc, aDetails ) & ScRefFlags::VALID ) - rDoc.SetRepeatRowRange( nTab, &aRange ); + rDoc.SetRepeatRowRange( nTab, std::unique_ptr<ScRange>(new ScRange(aRange)) ); } } @@ -2369,7 +2370,8 @@ bool ScViewFunc::DeleteTables(const vector<SCTAB> &TheTabs, bool bRecord ) } pUndoDoc->SetVisible( nTab, rDoc.IsVisible( nTab ) ); pUndoDoc->SetTabBgColor( nTab, rDoc.GetTabBgColor(nTab) ); - pUndoDoc->SetSheetEvents( nTab, rDoc.GetSheetEvents( nTab ) ); + auto pSheetEvents = rDoc.GetSheetEvents( nTab ); + pUndoDoc->SetSheetEvents( nTab, std::unique_ptr<ScSheetEvents>(pSheetEvents ? new ScSheetEvents(*pSheetEvents) : nullptr) ); pUndoDoc->SetLayoutRTL( nTab, rDoc.IsLayoutRTL( nTab ) ); if ( rDoc.IsTabProtected( nTab ) ) |