Kaydet (Commit) a7fea048 authored tarafından Noel Grandin's avatar Noel Grandin

use unique_ptr in starmath

Change-Id: Ib9c555507d5271343424686f2321ae13efcbf41a
Reviewed-on: https://gerrit.libreoffice.org/66550
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst a7ea0439
...@@ -486,12 +486,12 @@ awt::Rectangle SAL_CALL SmGraphicAccessible::getCharacterBounds( sal_Int32 nInde ...@@ -486,12 +486,12 @@ awt::Rectangle SAL_CALL SmGraphicAccessible::getCharacterBounds( sal_Int32 nInde
Point aTLPos (pWin->GetFormulaDrawPos() + aOffset); Point aTLPos (pWin->GetFormulaDrawPos() + aOffset);
Size aSize (pNode->GetSize()); Size aSize (pNode->GetSize());
long* pXAry = new long[ aNodeText.getLength() ]; std::unique_ptr<long[]> pXAry(new long[ aNodeText.getLength() ]);
pWin->SetFont( pNode->GetFont() ); pWin->SetFont( pNode->GetFont() );
pWin->GetTextArray( aNodeText, pXAry, 0, aNodeText.getLength() ); pWin->GetTextArray( aNodeText, pXAry.get(), 0, aNodeText.getLength() );
aTLPos.AdjustX(nNodeIndex > 0 ? pXAry[nNodeIndex - 1] : 0 ); aTLPos.AdjustX(nNodeIndex > 0 ? pXAry[nNodeIndex - 1] : 0 );
aSize.setWidth( nNodeIndex > 0 ? pXAry[nNodeIndex] - pXAry[nNodeIndex - 1] : pXAry[nNodeIndex] ); aSize.setWidth( nNodeIndex > 0 ? pXAry[nNodeIndex] - pXAry[nNodeIndex - 1] : pXAry[nNodeIndex] );
delete[] pXAry; pXAry.reset();
aTLPos = pWin->LogicToPixel( aTLPos ); aTLPos = pWin->LogicToPixel( aTLPos );
aSize = pWin->LogicToPixel( aSize ); aSize = pWin->LogicToPixel( aSize );
...@@ -556,15 +556,15 @@ sal_Int32 SAL_CALL SmGraphicAccessible::getIndexAtPoint( const awt::Point& aPoin ...@@ -556,15 +556,15 @@ sal_Int32 SAL_CALL SmGraphicAccessible::getIndexAtPoint( const awt::Point& aPoin
long nNodeX = pNode->GetLeft(); long nNodeX = pNode->GetLeft();
long* pXAry = new long[ aTxt.getLength() ]; std::unique_ptr<long[]> pXAry(new long[ aTxt.getLength() ]);
pWin->SetFont( pNode->GetFont() ); pWin->SetFont( pNode->GetFont() );
pWin->GetTextArray( aTxt, pXAry, 0, aTxt.getLength() ); pWin->GetTextArray( aTxt, pXAry.get(), 0, aTxt.getLength() );
for (sal_Int32 i = 0; i < aTxt.getLength() && nRes == -1; ++i) for (sal_Int32 i = 0; i < aTxt.getLength() && nRes == -1; ++i)
{ {
if (pXAry[i] + nNodeX > aPos.X()) if (pXAry[i] + nNodeX > aPos.X())
nRes = i; nRes = i;
} }
delete[] pXAry; pXAry.reset();
OSL_ENSURE( nRes >= 0 && nRes < aTxt.getLength(), "index out of range" ); OSL_ENSURE( nRes >= 0 && nRes < aTxt.getLength(), "index out of range" );
OSL_ENSURE( pNode->GetAccessibleIndex() >= 0, OSL_ENSURE( pNode->GetAccessibleIndex() >= 0,
"invalid accessible index" ); "invalid accessible index" );
......
...@@ -740,7 +740,7 @@ bool SmCursor::InsertRow() { ...@@ -740,7 +740,7 @@ bool SmCursor::InsertRow() {
//If we're in the context of a table //If we're in the context of a table
if(pTable) { if(pTable) {
SmNodeList *pNewLineList = new SmNodeList; std::unique_ptr<SmNodeList> pNewLineList(new SmNodeList);
//Move elements from pLineList to pNewLineList //Move elements from pLineList to pNewLineList
pNewLineList->splice(pNewLineList->begin(), *pLineList, it, pLineList->end()); pNewLineList->splice(pNewLineList->begin(), *pLineList, it, pLineList->end());
//Make sure it is valid again //Make sure it is valid again
...@@ -750,8 +750,8 @@ bool SmCursor::InsertRow() { ...@@ -750,8 +750,8 @@ bool SmCursor::InsertRow() {
if(pNewLineList->empty()) if(pNewLineList->empty())
pNewLineList->push_front(new SmPlaceNode()); pNewLineList->push_front(new SmPlaceNode());
//Parse new line //Parse new line
std::unique_ptr<SmNode> pNewLine(SmNodeListParser().Parse(pNewLineList)); std::unique_ptr<SmNode> pNewLine(SmNodeListParser().Parse(pNewLineList.get()));
delete pNewLineList; pNewLineList.reset();
//Wrap pNewLine in SmLineNode if needed //Wrap pNewLine in SmLineNode if needed
if(pLineParent->GetType() == SmNodeType::Line) { if(pLineParent->GetType() == SmNodeType::Line) {
std::unique_ptr<SmLineNode> pNewLineNode(new SmLineNode(SmToken(TNEWLINE, '\0', "newline"))); std::unique_ptr<SmLineNode> pNewLineNode(new SmLineNode(SmToken(TNEWLINE, '\0', "newline")));
......
...@@ -721,11 +721,11 @@ void SmXMLExport::ExportTable(const SmNode *pNode, int nLevel) ...@@ -721,11 +721,11 @@ void SmXMLExport::ExportTable(const SmNode *pNode, int nLevel)
{ {
if (const SmNode *pTemp = pNode->GetSubNode(i)) if (const SmNode *pTemp = pNode->GetSubNode(i))
{ {
SvXMLElementExport *pRow=nullptr; std::unique_ptr<SvXMLElementExport> pRow;
SvXMLElementExport *pCell=nullptr; std::unique_ptr<SvXMLElementExport> pCell;
if (pTable) if (pTable)
{ {
pRow = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MTR, true, true); pRow.reset(new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MTR, true, true));
SmTokenType eAlign = TALIGNC; SmTokenType eAlign = TALIGNC;
if (pTemp->GetType() == SmNodeType::Align) if (pTemp->GetType() == SmNodeType::Align)
{ {
...@@ -752,11 +752,9 @@ void SmXMLExport::ExportTable(const SmNode *pNode, int nLevel) ...@@ -752,11 +752,9 @@ void SmXMLExport::ExportTable(const SmNode *pNode, int nLevel)
AddAttribute(XML_NAMESPACE_MATH, XML_COLUMNALIGN, AddAttribute(XML_NAMESPACE_MATH, XML_COLUMNALIGN,
eAlign == TALIGNL ? XML_LEFT : XML_RIGHT); eAlign == TALIGNL ? XML_LEFT : XML_RIGHT);
} }
pCell = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MTD, true, true); pCell.reset(new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MTD, true, true));
} }
ExportNodes(pTemp, nLevel+1); ExportNodes(pTemp, nLevel+1);
delete pCell;
delete pRow;
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment