[Libreoffice-commits] core.git: include/vcl vcl/source
Noel Grandin
noel.grandin at collabora.co.uk
Thu Apr 26 09:15:02 UTC 2018
include/vcl/texteng.hxx | 2 -
vcl/source/edit/textdoc.cxx | 34 ++++++++++----------
vcl/source/edit/textdoc.hxx | 8 ++--
vcl/source/edit/texteng.cxx | 70 ++++++++++++++++++++-----------------------
vcl/source/edit/textundo.cxx | 9 +++--
vcl/source/edit/textview.cxx | 32 +++++++++----------
6 files changed, 77 insertions(+), 78 deletions(-)
New commits:
commit 3a9d3f271c445641bebd057c4c91279f9b3cd7d5
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Mon Apr 23 09:38:41 2018 +0200
loplugin:useuniqueptr in TextDoc
Change-Id: I14b90100f0a7d2a97a1648ffc02da51658ffca63
Reviewed-on: https://gerrit.libreoffice.org/53344
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/include/vcl/texteng.hxx b/include/vcl/texteng.hxx
index 671054b8401f..82a60c7af122 100644
--- a/include/vcl/texteng.hxx
+++ b/include/vcl/texteng.hxx
@@ -205,7 +205,7 @@ class VCL_DLLPUBLIC TextEngine : public SfxBroadcaster
Range GetInvalidYOffsets( sal_uInt32 nPortion );
// for Undo/Redo
- void InsertContent( TextNode* pNode, sal_uInt32 nPara );
+ void InsertContent( std::unique_ptr<TextNode> pNode, sal_uInt32 nPara );
TextPaM SplitContent( sal_uInt32 nNode, sal_Int32 nSepPos );
TextPaM ConnectContents( sal_uInt32 nLeftNode );
diff --git a/vcl/source/edit/textdoc.cxx b/vcl/source/edit/textdoc.cxx
index 82fa75e2aab3..52cb9562cdb8 100644
--- a/vcl/source/edit/textdoc.cxx
+++ b/vcl/source/edit/textdoc.cxx
@@ -282,7 +282,7 @@ void TextNode::RemoveText( sal_Int32 nPos, sal_Int32 nChars )
CollapseAttribs( nPos, nChars );
}
-TextNode* TextNode::Split( sal_Int32 nPos )
+std::unique_ptr<TextNode> TextNode::Split( sal_Int32 nPos )
{
OUString aNewText;
if ( nPos < maText.getLength() )
@@ -290,7 +290,7 @@ TextNode* TextNode::Split( sal_Int32 nPos )
aNewText = maText.copy( nPos );
maText = maText.copy(0, nPos);
}
- TextNode* pNew = new TextNode( aNewText );
+ std::unique_ptr<TextNode> pNew(new TextNode( aNewText ));
for ( sal_uInt16 nAttr = 0; nAttr < maCharAttribs.Count(); nAttr++ )
{
@@ -396,8 +396,6 @@ void TextDoc::Clear()
void TextDoc::DestroyTextNodes()
{
- for ( auto pNode : maTextNodes )
- delete pNode;
maTextNodes.clear();
}
@@ -409,7 +407,7 @@ OUString TextDoc::GetText( const sal_Unicode* pSep ) const
const sal_uInt32 nLastNode = nNodes-1;
for ( sal_uInt32 nNode = 0; nNode < nNodes; ++nNode )
{
- TextNode* pNode = maTextNodes[ nNode ];
+ TextNode* pNode = maTextNodes[ nNode ].get();
aASCIIText += pNode->GetText();
if ( pSep && ( nNode != nLastNode ) )
aASCIIText += pSep;
@@ -420,7 +418,7 @@ OUString TextDoc::GetText( const sal_Unicode* pSep ) const
OUString TextDoc::GetText( sal_uInt32 nPara ) const
{
- TextNode* pNode = ( nPara < maTextNodes.size() ) ? maTextNodes[ nPara ] : nullptr;
+ TextNode* pNode = ( nPara < maTextNodes.size() ) ? maTextNodes[ nPara ].get() : nullptr;
if ( pNode )
return pNode->GetText();
@@ -443,7 +441,7 @@ sal_Int32 TextDoc::GetTextLen( const sal_Unicode* pSep, const TextSelection* pSe
for ( sal_uInt32 nNode = nStartNode; nNode <= nEndNode; ++nNode )
{
- TextNode* pNode = maTextNodes[ nNode ];
+ TextNode* pNode = maTextNodes[ nNode ].get();
sal_Int32 nS = 0;
sal_Int32 nE = pNode->GetText().getLength();
@@ -467,7 +465,7 @@ TextPaM TextDoc::InsertText( const TextPaM& rPaM, sal_Unicode c )
SAL_WARN_IF( c == 0x0A, "vcl", "TextDoc::InsertText: Line separator in paragraph not allowed!" );
SAL_WARN_IF( c == 0x0D, "vcl", "TextDoc::InsertText: Line separator in paragraph not allowed!" );
- TextNode* pNode = maTextNodes[ rPaM.GetPara() ];
+ TextNode* pNode = maTextNodes[ rPaM.GetPara() ].get();
pNode->InsertText( rPaM.GetIndex(), c );
TextPaM aPaM( rPaM.GetPara(), rPaM.GetIndex()+1 );
@@ -479,7 +477,7 @@ TextPaM TextDoc::InsertText( const TextPaM& rPaM, const OUString& rStr )
SAL_WARN_IF( rStr.indexOf( 0x0A ) != -1, "vcl", "TextDoc::InsertText: Line separator in paragraph not allowed!" );
SAL_WARN_IF( rStr.indexOf( 0x0D ) != -1, "vcl", "TextDoc::InsertText: Line separator in paragraph not allowed!" );
- TextNode* pNode = maTextNodes[ rPaM.GetPara() ];
+ TextNode* pNode = maTextNodes[ rPaM.GetPara() ].get();
pNode->InsertText( rPaM.GetIndex(), rStr );
TextPaM aPaM( rPaM.GetPara(), rPaM.GetIndex()+rStr.getLength() );
@@ -488,11 +486,11 @@ TextPaM TextDoc::InsertText( const TextPaM& rPaM, const OUString& rStr )
TextPaM TextDoc::InsertParaBreak( const TextPaM& rPaM )
{
- TextNode* pNode = maTextNodes[ rPaM.GetPara() ];
- TextNode* pNew = pNode->Split( rPaM.GetIndex() );
+ TextNode* pNode = maTextNodes[ rPaM.GetPara() ].get();
+ std::unique_ptr<TextNode> pNew = pNode->Split( rPaM.GetIndex() );
SAL_WARN_IF( maTextNodes.size()>=SAL_MAX_UINT32, "vcl", "InsertParaBreak: more than 4Gi paragraphs!" );
- maTextNodes.insert( maTextNodes.begin() + rPaM.GetPara() + 1, pNew );
+ maTextNodes.insert( maTextNodes.begin() + rPaM.GetPara() + 1, std::move(pNew) );
TextPaM aPaM( rPaM.GetPara()+1, 0 );
return aPaM;
@@ -504,17 +502,19 @@ TextPaM TextDoc::ConnectParagraphs( TextNode* pLeft, TextNode* pRight )
pLeft->Append( *pRight );
// the paragraph on the right vanishes
- maTextNodes.erase( std::find( maTextNodes.begin(), maTextNodes.end(), pRight ) );
- delete pRight;
+ maTextNodes.erase( std::find_if( maTextNodes.begin(), maTextNodes.end(),
+ [&] (std::unique_ptr<TextNode> const & p) { return p.get() == pRight; } ) );
- sal_uLong nLeft = ::std::find( maTextNodes.begin(), maTextNodes.end(), pLeft ) - maTextNodes.begin();
+ sal_uLong nLeft = ::std::find_if( maTextNodes.begin(), maTextNodes.end(),
+ [&] (std::unique_ptr<TextNode> const & p) { return p.get() == pLeft; } )
+ - maTextNodes.begin();
TextPaM aPaM( nLeft, nPrevLen );
return aPaM;
}
void TextDoc::RemoveChars( const TextPaM& rPaM, sal_Int32 nChars )
{
- TextNode* pNode = maTextNodes[ rPaM.GetPara() ];
+ TextNode* pNode = maTextNodes[ rPaM.GetPara() ].get();
pNode->RemoveText( rPaM.GetIndex(), nChars );
}
@@ -525,7 +525,7 @@ bool TextDoc::IsValidPaM( const TextPaM& rPaM )
OSL_FAIL( "PaM: Para out of range" );
return false;
}
- TextNode * pNode = maTextNodes[ rPaM.GetPara() ];
+ TextNode * pNode = maTextNodes[ rPaM.GetPara() ].get();
if ( rPaM.GetIndex() > pNode->GetText().getLength() )
{
OSL_FAIL( "PaM: Index out of range" );
diff --git a/vcl/source/edit/textdoc.hxx b/vcl/source/edit/textdoc.hxx
index 61839aae9936..24478e0a4d2e 100644
--- a/vcl/source/edit/textdoc.hxx
+++ b/vcl/source/edit/textdoc.hxx
@@ -87,13 +87,13 @@ public:
void InsertText( sal_Int32 nPos, sal_Unicode c );
void RemoveText( sal_Int32 nPos, sal_Int32 nChars );
- TextNode* Split( sal_Int32 nPos );
+ std::unique_ptr<TextNode> Split( sal_Int32 nPos );
void Append( const TextNode& rNode );
};
class TextDoc
{
- std::vector<TextNode*> maTextNodes;
+ std::vector<std::unique_ptr<TextNode>> maTextNodes;
sal_uInt16 mnLeftMargin;
void DestroyTextNodes();
@@ -104,8 +104,8 @@ public:
void Clear();
- std::vector<TextNode*>& GetNodes() { return maTextNodes; }
- const std::vector<TextNode*>& GetNodes() const { return maTextNodes; }
+ std::vector<std::unique_ptr<TextNode>>& GetNodes() { return maTextNodes; }
+ const std::vector<std::unique_ptr<TextNode>>& GetNodes() const { return maTextNodes; }
void RemoveChars( const TextPaM& rPaM, sal_Int32 nChars );
TextPaM InsertText( const TextPaM& rPaM, sal_Unicode c );
diff --git a/vcl/source/edit/texteng.cxx b/vcl/source/edit/texteng.cxx
index 0884040c94b1..f0a895ae77c7 100644
--- a/vcl/source/edit/texteng.cxx
+++ b/vcl/source/edit/texteng.cxx
@@ -379,10 +379,10 @@ void TextEngine::ImpInitDoc()
mpTEParaPortions.reset(new TEParaPortions);
- TextNode* pNode = new TextNode( OUString() );
- mpDoc->GetNodes().insert( mpDoc->GetNodes().begin(), pNode );
+ std::unique_ptr<TextNode> pNode(new TextNode( OUString() ));
+ mpDoc->GetNodes().insert( mpDoc->GetNodes().begin(), std::move(pNode) );
- TEParaPortion* pIniPortion = new TEParaPortion( pNode );
+ TEParaPortion* pIniPortion = new TEParaPortion( mpDoc->GetNodes().begin()->get() );
mpTEParaPortions->Insert( pIniPortion, 0 );
mbFormatted = false;
@@ -406,7 +406,7 @@ OUString TextEngine::GetText( const TextSelection& rSel, LineEnd aSeparator ) co
const sal_Unicode* pSep = static_getLineEndText( aSeparator );
for ( sal_uInt32 nNode = aSel.GetStart().GetPara(); nNode <= nEndPara; ++nNode )
{
- TextNode* pNode = mpDoc->GetNodes()[ nNode ];
+ TextNode* pNode = mpDoc->GetNodes()[ nNode ].get();
sal_Int32 nStartPos = 0;
sal_Int32 nEndPos = pNode->GetText().getLength();
@@ -469,7 +469,7 @@ void TextEngine::SetText( const OUString& rText )
void TextEngine::CursorMoved( sal_uInt32 nNode )
{
// delete empty attribute; but only if paragraph is not empty!
- TextNode* pNode = mpDoc->GetNodes()[ nNode ];
+ TextNode* pNode = mpDoc->GetNodes()[ nNode ].get();
if ( pNode && pNode->GetCharAttribs().HasEmptyAttribs() && !pNode->GetText().isEmpty() )
pNode->GetCharAttribs().DeleteEmptyAttribs();
}
@@ -480,7 +480,7 @@ void TextEngine::ImpRemoveChars( const TextPaM& rPaM, sal_Int32 nChars )
if ( IsUndoEnabled() && !IsInUndo() )
{
// attributes have to be saved for UNDO before RemoveChars!
- TextNode* pNode = mpDoc->GetNodes()[ rPaM.GetPara() ];
+ TextNode* pNode = mpDoc->GetNodes()[ rPaM.GetPara() ].get();
OUString aStr( pNode->GetText().copy( rPaM.GetIndex(), nChars ) );
// check if attributes are being deleted or changed
@@ -505,8 +505,8 @@ TextPaM TextEngine::ImpConnectParagraphs( sal_uInt32 nLeft, sal_uInt32 nRight )
{
SAL_WARN_IF( nLeft == nRight, "vcl", "ImpConnectParagraphs: connect the very same paragraph ?" );
- TextNode* pLeft = mpDoc->GetNodes()[ nLeft ];
- TextNode* pRight = mpDoc->GetNodes()[ nRight ];
+ TextNode* pLeft = mpDoc->GetNodes()[ nLeft ].get();
+ TextNode* pRight = mpDoc->GetNodes()[ nRight ].get();
if ( IsUndoEnabled() && !IsInUndo() )
InsertUndo( new TextUndoConnectParas( this, nLeft, pLeft->GetText().getLength() ) );
@@ -557,7 +557,7 @@ TextPaM TextEngine::ImpDeleteText( const TextSelection& rSel )
if ( nStartNode != nEndNode )
{
// the remainder of StartNodes...
- TextNode* pLeft = mpDoc->GetNodes()[ nStartNode ];
+ TextNode* pLeft = mpDoc->GetNodes()[ nStartNode ].get();
sal_Int32 nChars = pLeft->GetText().getLength() - aStartPaM.GetIndex();
if ( nChars )
{
@@ -599,14 +599,12 @@ TextPaM TextEngine::ImpDeleteText( const TextSelection& rSel )
void TextEngine::ImpRemoveParagraph( sal_uInt32 nPara )
{
- TextNode* pNode = mpDoc->GetNodes()[ nPara ];
+ std::unique_ptr<TextNode> pNode = std::move(mpDoc->GetNodes()[ nPara ]);
// the Node is handled by Undo and is deleted if appropriate
mpDoc->GetNodes().erase( mpDoc->GetNodes().begin() + nPara );
if ( IsUndoEnabled() && !IsInUndo() )
- InsertUndo( new TextUndoDelPara( this, pNode, nPara ) );
- else
- delete pNode;
+ InsertUndo( new TextUndoDelPara( this, pNode.release(), nPara ) );
mpTEParaPortions->Remove( nPara );
@@ -654,7 +652,7 @@ TextPaM TextEngine::ImpInsertText( sal_Unicode c, const TextSelection& rCurSel,
SAL_WARN_IF( c == '\r', "vcl", "InsertText: NewLine!" );
TextPaM aPaM( rCurSel.GetStart() );
- TextNode* pNode = mpDoc->GetNodes()[ aPaM.GetPara() ];
+ TextNode* pNode = mpDoc->GetNodes()[ aPaM.GetPara() ].get();
bool bDoOverwrite = bOverwrite && ( aPaM.GetIndex() < pNode->GetText().getLength() );
@@ -815,7 +813,7 @@ TextPaM TextEngine::ImpInsertParaBreak( const TextPaM& rPaM )
if ( IsUndoEnabled() && !IsInUndo() )
InsertUndo( new TextUndoSplitPara( this, rPaM.GetPara(), rPaM.GetIndex() ) );
- TextNode* pNode = mpDoc->GetNodes()[ rPaM.GetPara() ];
+ TextNode* pNode = mpDoc->GetNodes()[ rPaM.GetPara() ].get();
bool bFirstParaContentChanged = rPaM.GetIndex() < pNode->GetText().getLength();
TextPaM aPaM( mpDoc->InsertParaBreak( rPaM ) );
@@ -824,7 +822,7 @@ TextPaM TextEngine::ImpInsertParaBreak( const TextPaM& rPaM )
SAL_WARN_IF( !pPortion, "vcl", "ImpInsertParaBreak: Hidden Portion" );
pPortion->MarkInvalid( rPaM.GetIndex(), 0 );
- TextNode* pNewNode = mpDoc->GetNodes()[ aPaM.GetPara() ];
+ TextNode* pNewNode = mpDoc->GetNodes()[ aPaM.GetPara() ].get();
TEParaPortion* pNewPortion = new TEParaPortion( pNewNode );
mpTEParaPortions->Insert( pNewPortion, aPaM.GetPara() );
ImpParagraphInserted( aPaM.GetPara() );
@@ -1009,7 +1007,7 @@ const TextAttrib* TextEngine::FindAttrib( const TextPaM& rPaM, sal_uInt16 nWhich
const TextCharAttrib* TextEngine::FindCharAttrib( const TextPaM& rPaM, sal_uInt16 nWhich ) const
{
const TextCharAttrib* pAttr = nullptr;
- TextNode* pNode = mpDoc->GetNodes()[ rPaM.GetPara() ];
+ TextNode* pNode = mpDoc->GetNodes()[ rPaM.GetPara() ].get();
if (pNode && (rPaM.GetIndex() <= pNode->GetText().getLength()))
pAttr = pNode->GetCharAttribs().FindAttrib( nWhich, rPaM.GetIndex() );
return pAttr;
@@ -1039,7 +1037,7 @@ TextPaM TextEngine::GetPaM( const Point& rDocPos )
// not found - go to last visible
const sal_uInt32 nLastNode = static_cast<sal_uInt32>(mpDoc->GetNodes().size() - 1);
- TextNode* pLast = mpDoc->GetNodes()[ nLastNode ];
+ TextNode* pLast = mpDoc->GetNodes()[ nLastNode ].get();
return TextPaM( nLastNode, pLast->GetText().getLength() );
}
@@ -1195,7 +1193,7 @@ long TextEngine::CalcTextWidth( sal_uInt32 nPara, sal_Int32 nPortionStart, sal_I
vcl::Font aFont;
SeekCursor( nPara, nPortionStart+1, aFont, nullptr );
mpRefDev->SetFont( aFont );
- TextNode* pNode = mpDoc->GetNodes()[ nPara ];
+ TextNode* pNode = mpDoc->GetNodes()[ nPara ].get();
long nWidth = mpRefDev->GetTextWidth( pNode->GetText(), nPortionStart, nLen );
return nWidth;
}
@@ -1332,20 +1330,20 @@ void TextEngine::ResetUndo()
mpUndoManager->Clear();
}
-void TextEngine::InsertContent( TextNode* pNode, sal_uInt32 nPara )
+void TextEngine::InsertContent( std::unique_ptr<TextNode> pNode, sal_uInt32 nPara )
{
SAL_WARN_IF( !pNode, "vcl", "InsertContent: NULL-Pointer!" );
SAL_WARN_IF( !IsInUndo(), "vcl", "InsertContent: only in Undo()!" );
- TEParaPortion* pNew = new TEParaPortion( pNode );
+ TEParaPortion* pNew = new TEParaPortion( pNode.get() );
mpTEParaPortions->Insert( pNew, nPara );
- mpDoc->GetNodes().insert( mpDoc->GetNodes().begin() + nPara, pNode );
+ mpDoc->GetNodes().insert( mpDoc->GetNodes().begin() + nPara, std::move(pNode) );
ImpParagraphInserted( nPara );
}
TextPaM TextEngine::SplitContent( sal_uInt32 nNode, sal_Int32 nSepPos )
{
#ifdef DBG_UTIL
- TextNode* pNode = mpDoc->GetNodes()[ nNode ];
+ TextNode* pNode = mpDoc->GetNodes()[ nNode ].get();
SAL_WARN_IF( !pNode, "vcl", "SplitContent: Invalid Node!" );
SAL_WARN_IF( !IsInUndo(), "vcl", "SplitContent: only in Undo()!" );
SAL_WARN_IF( nSepPos > pNode->GetText().getLength(), "vcl", "SplitContent: Bad index" );
@@ -1366,7 +1364,7 @@ void TextEngine::SeekCursor( sal_uInt32 nPara, sal_Int32 nPos, vcl::Font& rFont,
if ( pOutDev )
pOutDev->SetTextColor( maTextColor );
- TextNode* pNode = mpDoc->GetNodes()[ nPara ];
+ TextNode* pNode = mpDoc->GetNodes()[ nPara ].get();
sal_uInt16 nAttribs = pNode->GetCharAttribs().Count();
for ( sal_uInt16 nAttr = 0; nAttr < nAttribs; nAttr++ )
{
@@ -1596,7 +1594,7 @@ void TextEngine::FormatDoc()
void TextEngine::CreateAndInsertEmptyLine( sal_uInt32 nPara )
{
- TextNode* pNode = mpDoc->GetNodes()[ nPara ];
+ TextNode* pNode = mpDoc->GetNodes()[ nPara ].get();
TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPara );
TextLine aTmpLine;
@@ -1628,7 +1626,7 @@ void TextEngine::CreateAndInsertEmptyLine( sal_uInt32 nPara )
void TextEngine::ImpBreakLine( sal_uInt32 nPara, TextLine* pLine, sal_Int32 nPortionStart, long nRemainingWidth )
{
- TextNode* pNode = mpDoc->GetNodes()[ nPara ];
+ TextNode* pNode = mpDoc->GetNodes()[ nPara ].get();
// Font still should be adjusted
sal_Int32 nMaxBreakPos = mpRefDev->GetTextBreak( pNode->GetText(), nRemainingWidth, nPortionStart );
@@ -2071,7 +2069,7 @@ bool TextEngine::CreateLines( sal_uInt32 nPara )
{
// bool: changing Height of Paragraph Yes/No - true/false
- TextNode* pNode = mpDoc->GetNodes()[ nPara ];
+ TextNode* pNode = mpDoc->GetNodes()[ nPara ].get();
TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPara );
SAL_WARN_IF( !pTEParaPortion->IsInvalid(), "vcl", "CreateLines: Portion not invalid!" );
@@ -2381,7 +2379,7 @@ OUString TextEngine::GetWord( const TextPaM& rCursorPos, TextPaM* pStartOfWord )
if ( rCursorPos.GetPara() < mpDoc->GetNodes().size() )
{
TextSelection aSel( rCursorPos );
- TextNode* pNode = mpDoc->GetNodes()[ rCursorPos.GetPara() ];
+ TextNode* pNode = mpDoc->GetNodes()[ rCursorPos.GetPara() ].get();
uno::Reference < i18n::XBreakIterator > xBI = GetBreakIterator();
i18n::Boundary aBoundary = xBI->getWordBoundary( pNode->GetText(), rCursorPos.GetIndex(), GetLocale(), i18n::WordType::ANYWORD_IGNOREWHITESPACES, true );
aSel.GetStart().GetIndex() = aBoundary.startPos;
@@ -2405,7 +2403,7 @@ bool TextEngine::Read( SvStream& rInput, const TextSelection* pSel )
else
{
const sal_uInt32 nParas = static_cast<sal_uInt32>(mpDoc->GetNodes().size());
- TextNode* pNode = mpDoc->GetNodes()[ nParas - 1 ];
+ TextNode* pNode = mpDoc->GetNodes()[ nParas - 1 ].get();
aSel = TextPaM( nParas-1 , pNode->GetText().getLength() );
}
@@ -2442,13 +2440,13 @@ void TextEngine::Write( SvStream& rOutput )
{
TextSelection aSel;
const sal_uInt32 nParas = static_cast<sal_uInt32>(mpDoc->GetNodes().size());
- TextNode* pSelNode = mpDoc->GetNodes()[ nParas - 1 ];
+ TextNode* pSelNode = mpDoc->GetNodes()[ nParas - 1 ].get();
aSel.GetStart() = TextPaM( 0, 0 );
aSel.GetEnd() = TextPaM( nParas-1, pSelNode->GetText().getLength() );
for ( sal_uInt32 nPara = aSel.GetStart().GetPara(); nPara <= aSel.GetEnd().GetPara(); ++nPara )
{
- TextNode* pNode = mpDoc->GetNodes()[ nPara ];
+ TextNode* pNode = mpDoc->GetNodes()[ nPara ].get();
const sal_Int32 nStartPos = nPara == aSel.GetStart().GetPara()
? aSel.GetStart().GetIndex() : 0;
@@ -2464,7 +2462,7 @@ void TextEngine::RemoveAttribs( sal_uInt32 nPara )
{
if ( nPara < mpDoc->GetNodes().size() )
{
- TextNode* pNode = mpDoc->GetNodes()[ nPara ];
+ TextNode* pNode = mpDoc->GetNodes()[ nPara ].get();
if ( pNode->GetCharAttribs().Count() )
{
pNode->GetCharAttribs().Clear();
@@ -2483,7 +2481,7 @@ void TextEngine::RemoveAttribs( sal_uInt32 nPara, sal_uInt16 nWhich )
{
if ( nPara < mpDoc->GetNodes().size() )
{
- TextNode* pNode = mpDoc->GetNodes()[ nPara ];
+ TextNode* pNode = mpDoc->GetNodes()[ nPara ].get();
if ( pNode->GetCharAttribs().Count() )
{
TextCharAttribList& rAttribs = pNode->GetCharAttribs();
@@ -2508,7 +2506,7 @@ std::unique_ptr<TextCharAttrib> TextEngine::RemoveAttrib( sal_uInt32 nPara, cons
std::unique_ptr<TextCharAttrib> pRet;
if ( nPara < mpDoc->GetNodes().size() )
{
- TextNode* pNode = mpDoc->GetNodes()[ nPara ];
+ TextNode* pNode = mpDoc->GetNodes()[ nPara ].get();
if ( pNode->GetCharAttribs().Count() )
{
TextCharAttribList& rAttribs = pNode->GetCharAttribs();
@@ -2539,7 +2537,7 @@ void TextEngine::SetAttrib( const TextAttrib& rAttr, sal_uInt32 nPara, sal_Int32
if ( nPara < mpDoc->GetNodes().size() )
{
- TextNode* pNode = mpDoc->GetNodes()[ nPara ];
+ TextNode* pNode = mpDoc->GetNodes()[ nPara ].get();
TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPara );
const sal_Int32 nMax = pNode->GetText().getLength();
@@ -2792,7 +2790,7 @@ bool TextEngine::ImpGetRightToLeft( sal_uInt32 nPara, sal_Int32 nPos )
{
bool bRightToLeft = false;
- TextNode* pNode = mpDoc->GetNodes()[ nPara ];
+ TextNode* pNode = mpDoc->GetNodes()[ nPara ].get();
if ( pNode && !pNode->GetText().isEmpty() )
{
TEParaPortion* pParaPortion = mpTEParaPortions->GetObject( nPara );
diff --git a/vcl/source/edit/textundo.cxx b/vcl/source/edit/textundo.cxx
index 15cea12cba2e..e5b3d0165517 100644
--- a/vcl/source/edit/textundo.cxx
+++ b/vcl/source/edit/textundo.cxx
@@ -150,7 +150,7 @@ TextUndoDelPara::~TextUndoDelPara()
void TextUndoDelPara::Undo()
{
- GetTextEngine()->InsertContent( mpNode, mnPara );
+ GetTextEngine()->InsertContent( std::unique_ptr<TextNode>(mpNode), mnPara );
mbDelObject = false; // belongs again to the engine
if ( GetView() )
@@ -163,19 +163,20 @@ void TextUndoDelPara::Undo()
void TextUndoDelPara::Redo()
{
// pNode is not valid anymore in case an Undo joined paragraphs
- mpNode = GetDoc()->GetNodes()[ mnPara ];
+ mpNode = GetDoc()->GetNodes()[ mnPara ].get();
GetTEParaPortions()->Remove( mnPara );
// do not delete Node because of Undo!
- GetDoc()->GetNodes().erase( ::std::find( GetDoc()->GetNodes().begin(), GetDoc()->GetNodes().end(), mpNode ) );
+ GetDoc()->GetNodes().erase( ::std::find_if( GetDoc()->GetNodes().begin(), GetDoc()->GetNodes().end(),
+ [&] (std::unique_ptr<TextNode> const & p) { return p.get() == mpNode; } ) );
GetTextEngine()->ImpParagraphRemoved( mnPara );
mbDelObject = true; // belongs again to the Undo
const sal_uInt32 nParas = static_cast<sal_uInt32>(GetDoc()->GetNodes().size());
const sal_uInt32 n = mnPara < nParas ? mnPara : nParas-1;
- TextNode* pN = GetDoc()->GetNodes()[ n ];
+ TextNode* pN = GetDoc()->GetNodes()[ n ].get();
TextPaM aPaM( n, pN->GetText().getLength() );
SetSelection( aPaM );
}
diff --git a/vcl/source/edit/textview.cxx b/vcl/source/edit/textview.cxx
index 64ba0d31a8ce..8865b7ec3769 100644
--- a/vcl/source/edit/textview.cxx
+++ b/vcl/source/edit/textview.cxx
@@ -638,7 +638,7 @@ bool TextView::KeyInput( const KeyEvent& rKeyEvent )
aCurSel = mpImpl->mpTextEngine->ImpInsertParaBreak( aCurSel );
if ( mpImpl->mbAutoIndent )
{
- TextNode* pPrev = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aCurSel.GetEnd().GetPara() - 1 ];
+ TextNode* pPrev = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aCurSel.GetEnd().GetPara() - 1 ].get();
sal_Int32 n = 0;
while ( ( n < pPrev->GetText().getLength() ) && (
( pPrev->GetText()[ n ] == ' ' ) ||
@@ -759,7 +759,7 @@ void TextView::MouseButtonDown( const MouseEvent& rMouseEvent )
if ( mpImpl->maSelection.GetEnd().GetIndex() < mpImpl->mpTextEngine->GetTextLen( mpImpl->maSelection.GetEnd().GetPara() ) )
{
HideSelection();
- TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ mpImpl->maSelection.GetEnd().GetPara() ];
+ TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ mpImpl->maSelection.GetEnd().GetPara() ].get();
css::uno::Reference < css::i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
css::i18n::Boundary aBoundary = xBI->getWordBoundary( pNode->GetText(), mpImpl->maSelection.GetEnd().GetIndex(), mpImpl->mpTextEngine->GetLocale(), css::i18n::WordType::ANYWORD_IGNOREWHITESPACES, true );
TextSelection aNewSel( mpImpl->maSelection );
@@ -819,7 +819,7 @@ void TextView::Command( const CommandEvent& rCEvt )
if ( rCEvt.GetCommand() == CommandEventId::StartExtTextInput )
{
DeleteSelected();
- TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ GetSelection().GetEnd().GetPara() ];
+ TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ GetSelection().GetEnd().GetPara() ].get();
mpImpl->mpTextEngine->mpIMEInfos = o3tl::make_unique<TEIMEInfos>( GetSelection().GetEnd(), pNode->GetText().copy( GetSelection().GetEnd().GetIndex() ) );
mpImpl->mpTextEngine->mpIMEInfos->bWasCursorOverwrite = !IsInsertMode();
}
@@ -1258,7 +1258,7 @@ TextPaM TextView::CursorLeft( const TextPaM& rPaM, sal_uInt16 nCharacterIterator
if ( aPaM.GetIndex() )
{
- TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ];
+ TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ].get();
css::uno::Reference < css::i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
sal_Int32 nCount = 1;
aPaM.GetIndex() = xBI->previousCharacters( pNode->GetText(), aPaM.GetIndex(), mpImpl->mpTextEngine->GetLocale(), nCharacterIteratorMode, nCount, nCount );
@@ -1266,7 +1266,7 @@ TextPaM TextView::CursorLeft( const TextPaM& rPaM, sal_uInt16 nCharacterIterator
else if ( aPaM.GetPara() )
{
aPaM.GetPara()--;
- TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ];
+ TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ].get();
aPaM.GetIndex() = pNode->GetText().getLength();
}
return aPaM;
@@ -1276,7 +1276,7 @@ TextPaM TextView::CursorRight( const TextPaM& rPaM, sal_uInt16 nCharacterIterato
{
TextPaM aPaM( rPaM );
- TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ];
+ TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ].get();
if ( aPaM.GetIndex() < pNode->GetText().getLength() )
{
css::uno::Reference < css::i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
@@ -1298,7 +1298,7 @@ TextPaM TextView::CursorWordLeft( const TextPaM& rPaM )
if ( aPaM.GetIndex() )
{
- TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ];
+ TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ].get();
css::uno::Reference < css::i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
css::i18n::Boundary aBoundary = xBI->getWordBoundary( pNode->GetText(), rPaM.GetIndex(), mpImpl->mpTextEngine->GetLocale(), css::i18n::WordType::ANYWORD_IGNOREWHITESPACES, true );
if ( aBoundary.startPos >= rPaM.GetIndex() )
@@ -1308,7 +1308,7 @@ TextPaM TextView::CursorWordLeft( const TextPaM& rPaM )
else if ( aPaM.GetPara() )
{
aPaM.GetPara()--;
- TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ];
+ TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ].get();
aPaM.GetIndex() = pNode->GetText().getLength();
}
return aPaM;
@@ -1318,7 +1318,7 @@ TextPaM TextView::CursorWordRight( const TextPaM& rPaM )
{
TextPaM aPaM( rPaM );
- TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ];
+ TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ].get();
if ( aPaM.GetIndex() < pNode->GetText().getLength() )
{
css::uno::Reference < css::i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
@@ -1349,7 +1349,7 @@ TextPaM TextView::ImpDelete( sal_uInt8 nMode, sal_uInt8 nDelMode )
}
else if ( nDelMode == DELMODE_RESTOFWORD )
{
- TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aEndPaM.GetPara() ];
+ TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aEndPaM.GetPara() ].get();
css::uno::Reference < css::i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
css::i18n::Boundary aBoundary = xBI->getWordBoundary( pNode->GetText(), mpImpl->maSelection.GetEnd().GetIndex(), mpImpl->mpTextEngine->GetLocale(), css::i18n::WordType::ANYWORD_IGNOREWHITESPACES, true );
if ( aBoundary.startPos == mpImpl->maSelection.GetEnd().GetIndex() )
@@ -1377,21 +1377,21 @@ TextPaM TextView::ImpDelete( sal_uInt8 nMode, sal_uInt8 nDelMode )
}
else if ( nDelMode == DELMODE_RESTOFWORD )
{
- TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aEndPaM.GetPara() ];
+ TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aEndPaM.GetPara() ].get();
css::uno::Reference < css::i18n::XBreakIterator > xBI = mpImpl->mpTextEngine->GetBreakIterator();
css::i18n::Boundary aBoundary = xBI->nextWord( pNode->GetText(), mpImpl->maSelection.GetEnd().GetIndex(), mpImpl->mpTextEngine->GetLocale(), css::i18n::WordType::ANYWORD_IGNOREWHITESPACES );
aEndPaM.GetIndex() = aBoundary.startPos;
}
else // DELMODE_RESTOFCONTENT
{
- TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aEndPaM.GetPara() ];
+ TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aEndPaM.GetPara() ].get();
if ( aEndPaM.GetIndex() < pNode->GetText().getLength() )
aEndPaM.GetIndex() = pNode->GetText().getLength();
else if ( aEndPaM.GetPara() < ( mpImpl->mpTextEngine->mpDoc->GetNodes().size() - 1 ) )
{
// next paragraph
aEndPaM.GetPara()++;
- TextNode* pNextNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aEndPaM.GetPara() ];
+ TextNode* pNextNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aEndPaM.GetPara() ].get();
aEndPaM.GetIndex() = pNextNode->GetText().getLength();
}
}
@@ -1517,7 +1517,7 @@ TextPaM TextView::CursorStartOfParagraph( const TextPaM& rPaM )
TextPaM TextView::CursorEndOfParagraph( const TextPaM& rPaM )
{
- TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ rPaM.GetPara() ];
+ TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ rPaM.GetPara() ].get();
TextPaM aPaM( rPaM );
aPaM.GetIndex() = pNode->GetText().getLength();
return aPaM;
@@ -1532,7 +1532,7 @@ TextPaM TextView::CursorStartOfDoc()
TextPaM TextView::CursorEndOfDoc()
{
const sal_uInt32 nNode = static_cast<sal_uInt32>(mpImpl->mpTextEngine->mpDoc->GetNodes().size() - 1);
- TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ nNode ];
+ TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ nNode ].get();
TextPaM aPaM( nNode, pNode->GetText().getLength() );
return aPaM;
}
@@ -1591,7 +1591,7 @@ void TextView::ImpShowCursor( bool bGotoCursor, bool bForceVisCursor, bool bSpec
if ( !IsInsertMode() && !mpImpl->maSelection.HasRange() )
{
- TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ];
+ TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ aPaM.GetPara() ].get();
if ( !pNode->GetText().isEmpty() && ( aPaM.GetIndex() < pNode->GetText().getLength() ) )
{
// If we are behind a portion, and the next portion has other direction, we must change position...
More information about the Libreoffice-commits
mailing list