use unique_ptr in sc
Change-Id: If64b50919002f1f7376602f6e9cfb24e2184263b Reviewed-on: https://gerrit.libreoffice.org/66417 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
@@ -125,14 +125,11 @@ bool TokenPool::GrowElement()
|
||||
if (!nElementNew)
|
||||
return false;
|
||||
|
||||
sal_uInt16* pElementNew = new (::std::nothrow) sal_uInt16[ nElementNew ];
|
||||
E_TYPE* pTypeNew = new (::std::nothrow) E_TYPE[ nElementNew ];
|
||||
sal_uInt16* pSizeNew = new (::std::nothrow) sal_uInt16[ nElementNew ];
|
||||
std::unique_ptr<sal_uInt16[]> pElementNew(new (::std::nothrow) sal_uInt16[ nElementNew ]);
|
||||
std::unique_ptr<E_TYPE[]> pTypeNew(new (::std::nothrow) E_TYPE[ nElementNew ]);
|
||||
std::unique_ptr<sal_uInt16[]> pSizeNew(new (::std::nothrow) sal_uInt16[ nElementNew ]);
|
||||
if (!pElementNew || !pTypeNew || !pSizeNew)
|
||||
{
|
||||
delete [] pElementNew;
|
||||
delete [] pTypeNew;
|
||||
delete [] pSizeNew;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -145,9 +142,9 @@ bool TokenPool::GrowElement()
|
||||
|
||||
nElement = nElementNew;
|
||||
|
||||
pElement.reset( pElementNew );
|
||||
pType.reset( pTypeNew );
|
||||
pSize.reset( pSizeNew );
|
||||
pElement = std::move( pElementNew );
|
||||
pType = std::move( pTypeNew );
|
||||
pSize = std::move( pSizeNew );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -782,7 +782,7 @@ bool ScDBDocFunc::Query( SCTAB nTab, const ScQueryParam& rQueryParam,
|
||||
rDoc.BeginDrawUndo();
|
||||
}
|
||||
|
||||
ScDocument* pAttribDoc = nullptr;
|
||||
std::unique_ptr<ScDocument> pAttribDoc;
|
||||
ScRange aAttribRange;
|
||||
if (pDestData) // delete destination range
|
||||
{
|
||||
@@ -798,7 +798,7 @@ bool ScDBDocFunc::Query( SCTAB nTab, const ScQueryParam& rQueryParam,
|
||||
// also for filled-in formulas
|
||||
aAttribRange.aEnd.SetCol( aAttribRange.aEnd.Col() + nFormulaCols );
|
||||
|
||||
pAttribDoc = new ScDocument( SCDOCMODE_UNDO );
|
||||
pAttribDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
|
||||
pAttribDoc->InitUndo( &rDoc, nDestTab, nDestTab, false, true );
|
||||
rDoc.CopyToDocument(aAttribRange, InsertDeleteFlags::ATTRIB, false, *pAttribDoc);
|
||||
}
|
||||
@@ -882,8 +882,6 @@ bool ScDBDocFunc::Query( SCTAB nTab, const ScQueryParam& rQueryParam,
|
||||
nDestTab, *pStyle );
|
||||
}
|
||||
}
|
||||
|
||||
delete pAttribDoc;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2457,7 +2457,7 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark,
|
||||
WaitObject aWait( ScDocShell::GetActiveDialogParent() ); // important because of TrackFormulas in UpdateReference
|
||||
|
||||
ScDocumentUniquePtr pUndoDoc;
|
||||
ScDocument* pRefUndoDoc = nullptr;
|
||||
std::unique_ptr<ScDocument> pRefUndoDoc;
|
||||
std::unique_ptr<ScRefUndoData> pUndoData;
|
||||
if ( bRecord )
|
||||
{
|
||||
@@ -2480,7 +2480,7 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark,
|
||||
InsertDeleteFlags::ALL | InsertDeleteFlags::NOCAPTIONS, false, *pUndoDoc );
|
||||
}
|
||||
|
||||
pRefUndoDoc = new ScDocument( SCDOCMODE_UNDO );
|
||||
pRefUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
|
||||
pRefUndoDoc->InitUndo( &rDoc, 0, nTabCount-1 );
|
||||
|
||||
pUndoData.reset(new ScRefUndoData( &rDoc ));
|
||||
@@ -2501,22 +2501,22 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark,
|
||||
switch (eCmd)
|
||||
{
|
||||
case DelCellCmd::CellsUp:
|
||||
rDoc.DeleteRow( nStartCol, 0, nEndCol, MAXTAB, nStartRow, static_cast<SCSIZE>(nEndRow-nStartRow+1), pRefUndoDoc, nullptr, &aFullMark );
|
||||
rDoc.DeleteRow( nStartCol, 0, nEndCol, MAXTAB, nStartRow, static_cast<SCSIZE>(nEndRow-nStartRow+1), pRefUndoDoc.get(), nullptr, &aFullMark );
|
||||
nPaintEndRow = MAXROW;
|
||||
break;
|
||||
case DelCellCmd::Rows:
|
||||
rDoc.DeleteRow( 0, 0, MAXCOL, MAXTAB, nStartRow, static_cast<SCSIZE>(nEndRow-nStartRow+1), pRefUndoDoc, &bUndoOutline, &aFullMark );
|
||||
rDoc.DeleteRow( 0, 0, MAXCOL, MAXTAB, nStartRow, static_cast<SCSIZE>(nEndRow-nStartRow+1), pRefUndoDoc.get(), &bUndoOutline, &aFullMark );
|
||||
nPaintStartCol = 0;
|
||||
nPaintEndCol = MAXCOL;
|
||||
nPaintEndRow = MAXROW;
|
||||
nPaintFlags |= PaintPartFlags::Left;
|
||||
break;
|
||||
case DelCellCmd::CellsLeft:
|
||||
rDoc.DeleteCol( nStartRow, 0, nEndRow, MAXTAB, nStartCol, static_cast<SCSIZE>(nEndCol-nStartCol+1), pRefUndoDoc, nullptr, &aFullMark );
|
||||
rDoc.DeleteCol( nStartRow, 0, nEndRow, MAXTAB, nStartCol, static_cast<SCSIZE>(nEndCol-nStartCol+1), pRefUndoDoc.get(), nullptr, &aFullMark );
|
||||
nPaintEndCol = MAXCOL;
|
||||
break;
|
||||
case DelCellCmd::Cols:
|
||||
rDoc.DeleteCol( 0, 0, MAXROW, MAXTAB, nStartCol, static_cast<SCSIZE>(nEndCol-nStartCol+1), pRefUndoDoc, &bUndoOutline, &aFullMark );
|
||||
rDoc.DeleteCol( 0, 0, MAXROW, MAXTAB, nStartCol, static_cast<SCSIZE>(nEndCol-nStartCol+1), pRefUndoDoc.get(), &bUndoOutline, &aFullMark );
|
||||
nPaintStartRow = 0;
|
||||
nPaintEndRow = MAXROW;
|
||||
nPaintEndCol = MAXCOL;
|
||||
@@ -2544,7 +2544,7 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark,
|
||||
|
||||
// copy with bColRowFlags=false (#54194#)
|
||||
pRefUndoDoc->CopyToDocument(0,0,0,MAXCOL,MAXROW,MAXTAB,InsertDeleteFlags::FORMULA,false,*pUndoDoc,nullptr,false);
|
||||
delete pRefUndoDoc;
|
||||
pRefUndoDoc.reset();
|
||||
|
||||
std::unique_ptr<SCTAB[]> pTabs( new SCTAB[nSelCount]);
|
||||
std::unique_ptr<SCTAB[]> pScenarios( new SCTAB[nSelCount]);
|
||||
|
@@ -1176,17 +1176,17 @@ bool ScDocShell::MergeSharedDocument( ScDocShell* pSharedDocShell )
|
||||
// merge own changes into shared document
|
||||
sal_uLong nActStartShared = pSharedAction->GetActionNumber();
|
||||
sal_uLong nActEndShared = pSharedTrack->GetActionMax();
|
||||
ScDocument* pTmpDoc = new ScDocument;
|
||||
std::unique_ptr<ScDocument> pTmpDoc(new ScDocument);
|
||||
for ( sal_Int32 nIndex = 0; nIndex < m_aDocument.GetTableCount(); ++nIndex )
|
||||
{
|
||||
OUString sTabName;
|
||||
pTmpDoc->CreateValidTabName( sTabName );
|
||||
pTmpDoc->InsertTab( SC_TAB_APPEND, sTabName );
|
||||
}
|
||||
m_aDocument.GetChangeTrack()->Clone( pTmpDoc );
|
||||
m_aDocument.GetChangeTrack()->Clone( pTmpDoc.get() );
|
||||
ScChangeActionMergeMap aOwnInverseMergeMap;
|
||||
pSharedDocShell->MergeDocument( *pTmpDoc, true, true, 0, &aOwnInverseMergeMap, true );
|
||||
delete pTmpDoc;
|
||||
pTmpDoc.reset();
|
||||
sal_uLong nActStartOwn = nActEndShared + 1;
|
||||
sal_uLong nActEndOwn = pSharedTrack->GetActionMax();
|
||||
|
||||
@@ -1224,14 +1224,14 @@ bool ScDocShell::MergeSharedDocument( ScDocShell* pSharedDocShell )
|
||||
pSharedTrack->Undo( nActStartOwn, nActEndOwn );
|
||||
|
||||
// clone change track for merging into own document
|
||||
pTmpDoc = new ScDocument;
|
||||
pTmpDoc.reset(new ScDocument);
|
||||
for ( sal_Int32 nIndex = 0; nIndex < m_aDocument.GetTableCount(); ++nIndex )
|
||||
{
|
||||
OUString sTabName;
|
||||
pTmpDoc->CreateValidTabName( sTabName );
|
||||
pTmpDoc->InsertTab( SC_TAB_APPEND, sTabName );
|
||||
}
|
||||
pThisTrack->Clone( pTmpDoc );
|
||||
pThisTrack->Clone( pTmpDoc.get() );
|
||||
|
||||
// undo own changes since last save in own document
|
||||
sal_uLong nStartShared = pThisAction->GetActionNumber();
|
||||
@@ -1276,7 +1276,7 @@ bool ScDocShell::MergeSharedDocument( ScDocShell* pSharedDocShell )
|
||||
sal_uLong nStartOwn = nEndShared + 1;
|
||||
ScChangeActionMergeMap aOwnMergeMap;
|
||||
MergeDocument( *pTmpDoc, true, true, nEndShared - nStartShared + 1, &aOwnMergeMap );
|
||||
delete pTmpDoc;
|
||||
pTmpDoc.reset();
|
||||
sal_uLong nEndOwn = pThisTrack->GetActionMax();
|
||||
|
||||
// resolve conflicts for shared content actions and own actions
|
||||
|
@@ -5599,49 +5599,44 @@ uno::Reference<sheet::XSheetFilterDescriptor> SAL_CALL ScCellRangeObj::createFil
|
||||
uno::Reference<sheet::XCellRangeAddressable> xAddr( xObject, uno::UNO_QUERY );
|
||||
|
||||
ScDocShell* pDocSh = GetDocShell();
|
||||
if ( pDocSh && xAddr.is() )
|
||||
if ( !pDocSh || !xAddr.is() )
|
||||
{
|
||||
//! check if xObject is in the same document
|
||||
|
||||
ScFilterDescriptor* pNew = new ScFilterDescriptor(pDocSh); //! instead from object?
|
||||
|
||||
ScQueryParam aParam = pNew->GetParam();
|
||||
aParam.bHasHeader = true;
|
||||
|
||||
table::CellRangeAddress aDataAddress(xAddr->getRangeAddress());
|
||||
aParam.nCol1 = static_cast<SCCOL>(aDataAddress.StartColumn);
|
||||
aParam.nRow1 = static_cast<SCROW>(aDataAddress.StartRow);
|
||||
aParam.nCol2 = static_cast<SCCOL>(aDataAddress.EndColumn);
|
||||
aParam.nRow2 = static_cast<SCROW>(aDataAddress.EndRow);
|
||||
aParam.nTab = aDataAddress.Sheet;
|
||||
|
||||
ScDocument& rDoc = pDocSh->GetDocument();
|
||||
if (rDoc.CreateQueryParam(aRange, aParam))
|
||||
{
|
||||
// FilterDescriptor contains the counted fields inside the area
|
||||
SCCOLROW nFieldStart = aParam.bByRow ?
|
||||
static_cast<SCCOLROW>(aDataAddress.StartColumn) :
|
||||
static_cast<SCCOLROW>(aDataAddress.StartRow);
|
||||
SCSIZE nCount = aParam.GetEntryCount();
|
||||
for (SCSIZE i=0; i<nCount; i++)
|
||||
{
|
||||
ScQueryEntry& rEntry = aParam.GetEntry(i);
|
||||
if (rEntry.bDoQuery && rEntry.nField >= nFieldStart)
|
||||
rEntry.nField -= nFieldStart;
|
||||
}
|
||||
|
||||
pNew->SetParam( aParam );
|
||||
return pNew;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pNew;
|
||||
return nullptr;
|
||||
}
|
||||
OSL_FAIL("no document or no area");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
OSL_FAIL("no document or no area");
|
||||
return nullptr;
|
||||
//! check if xObject is in the same document
|
||||
|
||||
std::unique_ptr<ScFilterDescriptor> pNew(new ScFilterDescriptor(pDocSh)); //! instead from object?
|
||||
|
||||
ScQueryParam aParam = pNew->GetParam();
|
||||
aParam.bHasHeader = true;
|
||||
|
||||
table::CellRangeAddress aDataAddress(xAddr->getRangeAddress());
|
||||
aParam.nCol1 = static_cast<SCCOL>(aDataAddress.StartColumn);
|
||||
aParam.nRow1 = static_cast<SCROW>(aDataAddress.StartRow);
|
||||
aParam.nCol2 = static_cast<SCCOL>(aDataAddress.EndColumn);
|
||||
aParam.nRow2 = static_cast<SCROW>(aDataAddress.EndRow);
|
||||
aParam.nTab = aDataAddress.Sheet;
|
||||
|
||||
ScDocument& rDoc = pDocSh->GetDocument();
|
||||
if (!rDoc.CreateQueryParam(aRange, aParam))
|
||||
return nullptr;
|
||||
|
||||
// FilterDescriptor contains the counted fields inside the area
|
||||
SCCOLROW nFieldStart = aParam.bByRow ?
|
||||
static_cast<SCCOLROW>(aDataAddress.StartColumn) :
|
||||
static_cast<SCCOLROW>(aDataAddress.StartRow);
|
||||
SCSIZE nCount = aParam.GetEntryCount();
|
||||
for (SCSIZE i=0; i<nCount; i++)
|
||||
{
|
||||
ScQueryEntry& rEntry = aParam.GetEntry(i);
|
||||
if (rEntry.bDoQuery && rEntry.nField >= nFieldStart)
|
||||
rEntry.nField -= nFieldStart;
|
||||
}
|
||||
|
||||
pNew->SetParam( aParam );
|
||||
return pNew.release();
|
||||
}
|
||||
|
||||
// XSubTotalSource
|
||||
|
@@ -1400,7 +1400,7 @@ void ScFormatShell::ExecuteTextAttr( SfxRequest& rReq )
|
||||
const ScPatternAttr* pAttrs = pTabViewShell->GetSelectionPattern();
|
||||
const SfxItemSet* pSet = rReq.GetArgs();
|
||||
sal_uInt16 nSlot = rReq.GetSlot();
|
||||
SfxAllItemSet* pNewSet = nullptr;
|
||||
std::unique_ptr<SfxAllItemSet> pNewSet;
|
||||
|
||||
pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
|
||||
|
||||
@@ -1412,7 +1412,7 @@ void ScFormatShell::ExecuteTextAttr( SfxRequest& rReq )
|
||||
||(nSlot == SID_ULINE_VAL_DOUBLE)
|
||||
||(nSlot == SID_ULINE_VAL_DOTTED) )
|
||||
{
|
||||
pNewSet = new SfxAllItemSet( GetPool() );
|
||||
pNewSet.reset(new SfxAllItemSet( GetPool() ));
|
||||
|
||||
switch ( nSlot )
|
||||
{
|
||||
@@ -1631,7 +1631,7 @@ void ScFormatShell::ExecuteTextAttr( SfxRequest& rReq )
|
||||
if( pNewSet )
|
||||
{
|
||||
rReq.Done( *pNewSet );
|
||||
delete pNewSet;
|
||||
pNewSet.reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -1309,12 +1309,12 @@ void ScPreview::MouseMove( const MouseEvent& rMEvt )
|
||||
{
|
||||
ScPrintOptions aOptions = SC_MOD()->GetPrintOptions();
|
||||
|
||||
ScPrintFunc* pPrintFunc;
|
||||
std::unique_ptr<ScPrintFunc> pPrintFunc;
|
||||
|
||||
if (bStateValid)
|
||||
pPrintFunc = new ScPrintFunc( this, pDocShell, aState, &aOptions );
|
||||
pPrintFunc.reset(new ScPrintFunc( this, pDocShell, aState, &aOptions ));
|
||||
else
|
||||
pPrintFunc = new ScPrintFunc( this, pDocShell, nTab, nFirstAttr[nTab], nTotalPages, nullptr, &aOptions );
|
||||
pPrintFunc.reset(new ScPrintFunc( this, pDocShell, nTab, nFirstAttr[nTab], nTotalPages, nullptr, &aOptions ));
|
||||
|
||||
nLeftMargin = static_cast<long>( pPrintFunc->GetLeftMargin() * HMM_PER_TWIPS - aOffset.X() );
|
||||
nRightMargin = static_cast<long>( pPrintFunc->GetRightMargin() * HMM_PER_TWIPS );
|
||||
@@ -1332,7 +1332,6 @@ void ScPreview::MouseMove( const MouseEvent& rMEvt )
|
||||
nHeaderHeight = static_cast<long>( nTopMargin + pPrintFunc->GetHeader().nHeight * HMM_PER_TWIPS );
|
||||
nFooterHeight = static_cast<long>( nBottomMargin - pPrintFunc->GetFooter().nHeight * HMM_PER_TWIPS );
|
||||
}
|
||||
delete pPrintFunc;
|
||||
}
|
||||
|
||||
Point aPixPt( rMEvt.GetPosPixel() );
|
||||
|
@@ -1237,7 +1237,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
|
||||
bool bRowInfo = ( nStartCol==0 && nEndCol==MAXCOL );
|
||||
|
||||
ScDocumentUniquePtr pUndoDoc;
|
||||
ScDocument* pRefUndoDoc = nullptr;
|
||||
std::unique_ptr<ScDocument> pRefUndoDoc;
|
||||
std::unique_ptr<ScRefUndoData> pUndoData;
|
||||
|
||||
if ( bRecord )
|
||||
@@ -1252,7 +1252,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
|
||||
|
||||
if ( bCutMode )
|
||||
{
|
||||
pRefUndoDoc = new ScDocument( SCDOCMODE_UNDO );
|
||||
pRefUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
|
||||
pRefUndoDoc->InitUndo( pDoc, 0, nTabCount-1 );
|
||||
|
||||
pUndoData.reset(new ScRefUndoData( pDoc ));
|
||||
@@ -1301,23 +1301,23 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
|
||||
{
|
||||
// copy normally (original range)
|
||||
pDoc->CopyFromClip( aUserRange, aFilteredMark, nNoObjFlags,
|
||||
pRefUndoDoc, pClipDoc, true, false, bIncludeFiltered,
|
||||
pRefUndoDoc.get(), pClipDoc, true, false, bIncludeFiltered,
|
||||
bSkipEmpty, (bMarkIsFiltered ? &aRangeList : nullptr) );
|
||||
|
||||
// adapt refs manually in case of transpose
|
||||
if ( bTranspose && bCutMode && (nFlags & InsertDeleteFlags::CONTENTS) )
|
||||
pDoc->UpdateTranspose( aUserRange.aStart, pOrigClipDoc, aFilteredMark, pRefUndoDoc );
|
||||
pDoc->UpdateTranspose( aUserRange.aStart, pOrigClipDoc, aFilteredMark, pRefUndoDoc.get() );
|
||||
}
|
||||
else if (!bTranspose)
|
||||
{
|
||||
// copy with bAsLink=TRUE
|
||||
pDoc->CopyFromClip( aUserRange, aFilteredMark, nNoObjFlags, pRefUndoDoc, pClipDoc,
|
||||
pDoc->CopyFromClip( aUserRange, aFilteredMark, nNoObjFlags, pRefUndoDoc.get(), pClipDoc,
|
||||
true, true, bIncludeFiltered, bSkipEmpty );
|
||||
}
|
||||
else
|
||||
{
|
||||
// copy all content (TransClipDoc contains only formula)
|
||||
pDoc->CopyFromClip( aUserRange, aFilteredMark, nContFlags, pRefUndoDoc, pClipDoc );
|
||||
pDoc->CopyFromClip( aUserRange, aFilteredMark, nContFlags, pRefUndoDoc.get(), pClipDoc );
|
||||
}
|
||||
|
||||
// skipped rows and merged cells don't mix
|
||||
@@ -1350,7 +1350,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
|
||||
|
||||
// Paste the drawing objects after the row heights have been updated.
|
||||
|
||||
pDoc->CopyFromClip( aUserRange, aFilteredMark, InsertDeleteFlags::OBJECTS, pRefUndoDoc, pClipDoc,
|
||||
pDoc->CopyFromClip( aUserRange, aFilteredMark, InsertDeleteFlags::OBJECTS, pRefUndoDoc.get(), pClipDoc,
|
||||
true, false, bIncludeFiltered );
|
||||
}
|
||||
|
||||
@@ -1384,7 +1384,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
|
||||
|
||||
SCTAB nTabCount = pDoc->GetTableCount();
|
||||
pRedoDoc->AddUndoTab( 0, nTabCount-1 );
|
||||
pDoc->CopyUpdated( pRefUndoDoc, pRedoDoc.get() );
|
||||
pDoc->CopyUpdated( pRefUndoDoc.get(), pRedoDoc.get() );
|
||||
|
||||
// move old refs to Undo-Doc
|
||||
|
||||
@@ -1393,7 +1393,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
|
||||
pRefUndoDoc->DeleteArea( nStartCol, nStartRow, nEndCol, nEndRow, aFilteredMark, InsertDeleteFlags::ALL );
|
||||
pRefUndoDoc->CopyToDocument( 0,0,0, MAXCOL,MAXROW,nTabCount-1,
|
||||
InsertDeleteFlags::FORMULA, false, *pUndoDoc );
|
||||
delete pRefUndoDoc;
|
||||
pRefUndoDoc.reset();
|
||||
}
|
||||
|
||||
// DeleteUnchanged for pUndoData is in ScUndoPaste ctor,
|
||||
|
Reference in New Issue
Block a user