editeng/inc/EditLineList.hxx        |    7 +-
 editeng/source/editeng/impedit.hxx  |    6 +-
 editeng/source/editeng/impedit3.cxx |  101 ++++++++++++++++++++----------------
 editeng/source/editeng/impedit4.cxx |    5 -
 4 files changed, 69 insertions(+), 50 deletions(-)

New commits:
commit bf82669bf76428d00cc2c6041daf2c7a4812ceae
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Fri Jan 12 12:54:15 2024 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Sun Jan 14 04:51:27 2024 +0100

    editeng: use unique_ptr for Append and Insert into a EditLineList
    
    We can better handle the lifecycle of the EditLine this way.
    
    Change-Id: I6fa3834bfdc19576158370a2c82da0771529a7f2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162010
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/editeng/inc/EditLineList.hxx b/editeng/inc/EditLineList.hxx
index a3a547d7ce24..e28ce6692764 100644
--- a/editeng/inc/EditLineList.hxx
+++ b/editeng/inc/EditLineList.hxx
@@ -64,10 +64,11 @@ public:
     const EditLine& operator[](sal_Int32 nPos) const { return *maLines[nPos]; }
     EditLine& operator[](sal_Int32 nPos) { return *maLines[nPos]; }
 
-    void Append(EditLine* p) { 
maLines.push_back(std::unique_ptr<EditLine>(p)); }
-    void Insert(sal_Int32 nPos, EditLine* p)
+    void Append(std::unique_ptr<EditLine> pEditLine) { 
maLines.push_back(std::move(pEditLine)); }
+
+    void Insert(sal_Int32 nPos, std::unique_ptr<EditLine> pEditLine)
     {
-        maLines.insert(maLines.begin() + nPos, std::unique_ptr<EditLine>(p));
+        maLines.insert(maLines.begin() + nPos, std::move(pEditLine));
     }
 };
 
diff --git a/editeng/source/editeng/impedit3.cxx 
b/editeng/source/editeng/impedit3.cxx
index 6dcf3fcdbff6..49e0015280f1 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -702,8 +702,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, 
sal_uInt32 nStartPosY )
 
     if ( pParaPortion->GetLines().Count() == 0 )
     {
-        EditLine* pLine = new EditLine;
-        pParaPortion->GetLines().Append(pLine);
+        pParaPortion->GetLines().Append(std::make_unique<EditLine>());
     }
 
     // Get Paragraph attributes...
@@ -1725,7 +1724,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, 
sal_uInt32 nStartPosY )
                 if ( nIndex < pNode->Len() )
                 {
                     pLine = new EditLine;
-                    pParaPortion->GetLines().Insert(++nLine, pLine);
+                    pParaPortion->GetLines().Insert(++nLine, 
std::unique_ptr<EditLine>(pLine));
                 }
                 else if ( nIndex && bLineBreak && GetTextRanger() )
                 {
@@ -1734,7 +1733,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, 
sal_uInt32 nStartPosY )
                     TextPortion* pDummyPortion = new TextPortion( 0 );
                     pParaPortion->GetTextPortions().Append(pDummyPortion);
                     pLine = new EditLine;
-                    pParaPortion->GetLines().Insert(++nLine, pLine);
+                    pParaPortion->GetLines().Insert(++nLine, 
std::unique_ptr<EditLine>(pLine));
                     bForceOneRun = true;
                     bProcessingEmptyLine = true;
                 }
@@ -1775,7 +1774,7 @@ void ImpEditEngine::CreateAndInsertEmptyLine( 
ParaPortion* pParaPortion )
     EditLine* pTmpLine = new EditLine;
     pTmpLine->SetStart( pParaPortion->GetNode()->Len() );
     pTmpLine->SetEnd( pParaPortion->GetNode()->Len() );
-    pParaPortion->GetLines().Append(pTmpLine);
+    pParaPortion->GetLines().Append(std::unique_ptr<EditLine>(pTmpLine));
 
     bool bLineBreak = pParaPortion->GetNode()->Len() > 0;
     sal_Int32 nSpaceBefore = 0;
diff --git a/editeng/source/editeng/impedit4.cxx 
b/editeng/source/editeng/impedit4.cxx
index 337d30b096df..6140fc9a7250 100644
--- a/editeng/source/editeng/impedit4.cxx
+++ b/editeng/source/editeng/impedit4.cxx
@@ -1148,8 +1148,7 @@ std::unique_ptr<EditTextObject> 
ImpEditEngine::CreateTextObject( EditSelection a
             for ( n = 0; n < nCount; n++ )
             {
                 const EditLine& rLine = pParaPortion->GetLines()[n];
-                EditLine* pNew = rLine.Clone();
-                pX->aLines.Append(pNew);
+                pX->aLines.Append(std::unique_ptr<EditLine>(rLine.Clone()));
             }
 #ifdef DBG_UTIL
             sal_uInt16 nTest;
@@ -1348,7 +1347,7 @@ EditSelection ImpEditEngine::InsertTextObject( const 
EditTextObject& rTextObject
                     const EditLine& rLine = rXP.aLines[m];
                     EditLine* pNew = rLine.Clone();
                     pNew->SetInvalid(); // Paint again!
-                    pParaPortion->GetLines().Append(pNew);
+                    
pParaPortion->GetLines().Append(std::unique_ptr<EditLine>(pNew));
                 }
 #ifdef DBG_UTIL
                 sal_uInt16 nTest;
commit c00f1227d3b9086c94aacea1c25496b73d32dc93
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon Jan 8 17:08:11 2024 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Sun Jan 14 04:51:18 2024 +0100

    editeng: split up some code into own methods for CreateLines
    
    Change-Id: Ic61bdb09f9c6d84ce14c1ef84dc4a959ce62595f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161821
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/editeng/source/editeng/impedit.hxx 
b/editeng/source/editeng/impedit.hxx
index abc9a96c98df..6705f4e5dc4f 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -673,7 +673,11 @@ private:
 
     void                Clear();
     EditPaM             RemoveText();
-    bool                CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY );
+
+    bool createLinesForEmptyParagraph(ParaPortion& rParaPortion);
+    tools::Long calculateMaxLineWidth(tools::Long nStartX, SvxLRSpaceItem 
const& rLRItem);
+    bool CreateLines(sal_Int32 nPara, sal_uInt32 nStartPosY);
+
     void                CreateAndInsertEmptyLine( ParaPortion* pParaPortion );
     bool                FinishCreateLines( ParaPortion* pParaPortion );
     void                CreateTextPortions( ParaPortion* pParaPortion, 
sal_Int32& rStartPos /*, sal_Bool bCreateBlockPortions */ );
diff --git a/editeng/source/editeng/impedit3.cxx 
b/editeng/source/editeng/impedit3.cxx
index bc93802694fd..6dcf3fcdbff6 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -635,6 +635,38 @@ tools::Long ImpEditEngine::GetColumnWidth(const Size& 
rPaperSize) const
     return (nWidth - mnColumnSpacing * (mnColumns - 1)) / mnColumns;
 }
 
+bool ImpEditEngine::createLinesForEmptyParagraph(ParaPortion& rParaPortion)
+{
+    // fast special treatment...
+    if (rParaPortion.GetTextPortions().Count())
+        rParaPortion.GetTextPortions().Reset();
+    if (rParaPortion.GetLines().Count())
+        rParaPortion.GetLines().Reset();
+
+    CreateAndInsertEmptyLine(&rParaPortion);
+    return FinishCreateLines(&rParaPortion);
+}
+
+tools::Long ImpEditEngine::calculateMaxLineWidth(tools::Long nStartX, 
SvxLRSpaceItem const& rLRItem)
+{
+    const bool bAutoSize = IsEffectivelyVertical() ? maStatus.AutoPageHeight() 
: maStatus.AutoPageWidth();
+    tools::Long nMaxLineWidth = GetColumnWidth(bAutoSize ? maMaxAutoPaperSize 
: maPaperSize);
+
+    nMaxLineWidth -= scaleXSpacingValue(rLRItem.GetRight());
+    nMaxLineWidth -= nStartX;
+
+    // If PaperSize == long_max, one cannot take away any negative
+    // first line indent. (Overflow)
+    if (nMaxLineWidth < 0 && nStartX < 0)
+        nMaxLineWidth = GetColumnWidth(maPaperSize) - 
scaleXSpacingValue(rLRItem.GetRight());
+
+    // If still less than 0, it may be just the right edge.
+    if (nMaxLineWidth <= 0)
+        nMaxLineWidth = 1;
+
+    return nMaxLineWidth;
+}
+
 bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
 {
     ParaPortion* pParaPortion = GetParaPortions()[nPara];
@@ -649,17 +681,9 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, 
sal_uInt32 nStartPosY )
 
 
     // Fast special treatment for empty paragraphs...
-
-    if ( ( pParaPortion->GetNode()->Len() == 0 ) && !GetTextRanger() )
-    {
-        // fast special treatment...
-        if ( pParaPortion->GetTextPortions().Count() )
-            pParaPortion->GetTextPortions().Reset();
-        if ( pParaPortion->GetLines().Count() )
-            pParaPortion->GetLines().Reset();
-        CreateAndInsertEmptyLine( pParaPortion );
-        return FinishCreateLines( pParaPortion );
-    }
+    bool bEmptyParagraph = pParaPortion->GetNode()->Len() == 0 && 
!GetTextRanger();
+    if (bEmptyParagraph)
+        return createLinesForEmptyParagraph(*pParaPortion);
 
     sal_Int64 nCurrentPosY = nStartPosY;
     // If we're allowed to skip parts outside and this cannot possibly fit in 
the given height,
@@ -678,11 +702,10 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, 
sal_uInt32 nStartPosY )
 
     if ( pParaPortion->GetLines().Count() == 0 )
     {
-        EditLine* pL = new EditLine;
-        pParaPortion->GetLines().Append(pL);
+        EditLine* pLine = new EditLine;
+        pParaPortion->GetLines().Append(pLine);
     }
 
-
     // Get Paragraph attributes...
 
     ContentNode* const pNode = pParaPortion->GetNode();
@@ -739,7 +762,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, 
sal_uInt32 nStartPosY )
 
     sal_Int32 nRealInvalidStart = nInvalidStart;
 
-    if ( bEmptyNodeWithPolygon )
+    if (bEmptyNodeWithPolygon)
     {
         TextPortion* pDummyPortion = new TextPortion( 0 );
         pParaPortion->GetTextPortions().Reset();
@@ -755,7 +778,6 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, 
sal_uInt32 nStartPosY )
         CreateTextPortions( pParaPortion, nRealInvalidStart );
     }
 
-
     // Search for line with InvalidPos, start one line before
     // Flag the line => do not remove it !
 
@@ -773,14 +795,16 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, 
sal_uInt32 nStartPosY )
     }
     // Begin one line before...
     // If it is typed at the end, the line in front cannot change.
-    if ( nLine && ( !pParaPortion->IsSimpleInvalid() || ( nInvalidEnd < 
pNode->Len() ) || ( nInvalidDiff <= 0 ) ) )
+    if (nLine && (!pParaPortion->IsSimpleInvalid() ||
+                    (nInvalidEnd < pNode->Len()) ||
+                    (nInvalidDiff <= 0)))
+    {
         nLine--;
+    }
 
-    EditLine* pLine = &pParaPortion->GetLines()[nLine];
+    tools::Rectangle aBulletArea{Point(), Point()};
 
-    static const tools::Rectangle aZeroArea { Point(), Point() };
-    tools::Rectangle aBulletArea( aZeroArea );
-    if ( !nLine )
+    if (!nLine)
     {
         aBulletArea = GetEditEnginePtr()->GetBulletArea( 
GetParaPortions().GetPos( pParaPortion ) );
         if ( !aBulletArea.IsWidthEmpty() && aBulletArea.Right() > 0 )
@@ -789,14 +813,15 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, 
sal_uInt32 nStartPosY )
             pParaPortion->SetBulletX( 0 ); // if Bullet is set incorrectly
     }
 
-
     // Reformat all lines from here...
 
     sal_Int32 nDelFromLine = -1;
     bool bLineBreak = false;
 
+    EditLine* pLine = &pParaPortion->GetLines()[nLine];
     sal_Int32 nIndex = pLine->GetStart();
     EditLine aSaveLine( *pLine );
+
     SvxFont aTmpFont( pNode->GetCharAttribs().GetDefFont() );
 
     KernArray aCharPositionArray;
@@ -830,20 +855,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, 
sal_uInt32 nStartPosY )
             }
         }
 
-        const bool bAutoSize = IsEffectivelyVertical() ? 
maStatus.AutoPageHeight() : maStatus.AutoPageWidth();
-        tools::Long nMaxLineWidth = GetColumnWidth(bAutoSize ? 
maMaxAutoPaperSize : maPaperSize);
-
-        nMaxLineWidth -= scaleXSpacingValue(rLRItem.GetRight());
-        nMaxLineWidth -= nStartX;
-
-        // If PaperSize == long_max, one cannot take away any negative
-        // first line indent. (Overflow)
-        if ( ( nMaxLineWidth < 0 ) && ( nStartX < 0 ) )
-            nMaxLineWidth = GetColumnWidth(maPaperSize) - 
scaleXSpacingValue(rLRItem.GetRight());
-
-        // If still less than 0, it may be just the right edge.
-        if ( nMaxLineWidth <= 0 )
-            nMaxLineWidth = 1;
+        tools::Long nMaxLineWidth = calculateMaxLineWidth(nStartX, rLRItem);
 
         // Problem:
         // Since formatting starts a line _before_ the invalid position,
@@ -1256,12 +1268,13 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, 
sal_uInt32 nStartPosY )
                 tools::Long nWidthAfterTab = 0;
                 for ( sal_Int32 n = aCurrentTab.nTabPortion+1; n <= 
nTmpPortion; n++  )
                 {
-                    const TextPortion& rTP = 
pParaPortion->GetTextPortions()[n];
-                    nWidthAfterTab += rTP.GetSize().Width();
+                    const TextPortion& rTextPortion = 
pParaPortion->GetTextPortions()[n];
+                    nWidthAfterTab += rTextPortion.GetSize().Width();
                 }
                 tools::Long nW = nWidthAfterTab;   // Length before tab 
position
                 if ( aCurrentTab.aTabStop.GetAdjustment() == 
SvxTabAdjust::Right )
                 {
+                    // Do nothing
                 }
                 else if ( aCurrentTab.aTabStop.GetAdjustment() == 
SvxTabAdjust::Center )
                 {
@@ -1269,8 +1282,11 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, 
sal_uInt32 nStartPosY )
                 }
                 else if ( aCurrentTab.aTabStop.GetAdjustment() == 
SvxTabAdjust::Decimal )
                 {
-                    OUString aText = GetSelected( EditSelection(  EditPaM( 
pParaPortion->GetNode(), nTmpPos ),
-                                                                EditPaM( 
pParaPortion->GetNode(), nTmpPos + nPortionLen ) ) );
+                    EditPaM aSelectionStart(pParaPortion->GetNode(), nTmpPos);
+                    EditPaM aSelectionEnd(pParaPortion->GetNode(), nTmpPos + 
nPortionLen);
+                    EditSelection aSelection(aSelectionStart, aSelectionEnd);
+                    OUString aText = GetSelected(aSelection);
+
                     sal_Int32 nDecPos = aText.indexOf( 
aCurrentTab.aTabStop.GetDecimal() );
                     if ( nDecPos != -1 )
                     {

Reply via email to