sc/inc/document.hxx               |    2 -
 sc/inc/table.hxx                  |    4 +--
 sc/source/core/data/dociter.cxx   |    4 +--
 sc/source/core/data/document.cxx  |    6 ++--
 sc/source/core/data/table1.cxx    |   23 +++++++++--------
 sc/source/core/data/table2.cxx    |   25 ++++++++++++-------
 sc/source/filter/rtf/eeimpars.cxx |    2 -
 sc/source/ui/docshell/docfunc.cxx |   50 +++++++++++++++++++-------------------
 sc/source/ui/docshell/docsh5.cxx  |    2 -
 sc/source/ui/inc/docfunc.hxx      |    2 -
 sc/source/ui/inc/viewfunc.hxx     |    2 -
 sc/source/ui/undo/undobase.cxx    |    2 -
 sc/source/ui/undo/undoblk.cxx     |    6 ++--
 sc/source/ui/undo/undoblk3.cxx    |    6 ++--
 sc/source/ui/view/viewfun2.cxx    |    6 ++--
 sc/source/ui/view/viewfun3.cxx    |    2 -
 sc/source/ui/view/viewfun4.cxx    |    2 -
 sc/source/ui/view/viewfunc.cxx    |   10 +++----
 18 files changed, 82 insertions(+), 74 deletions(-)

New commits:
commit 84f149b2bb88832b7493ec6edee1c3b9d0753dd9
Author:     Tor Lillqvist <t...@collabora.com>
AuthorDate: Fri Jan 29 16:03:29 2021 +0200
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Sun Jun 26 22:14:10 2022 +0200

    Don't bother shrinking row height when changing just one row interactively
    
    I.e. when interactively entering a new value.
    
    This used to happen at least for a sample document in .xlsx format for
    cells with automatic wrap turned on. After entering a value, the row
    height was annoyingly shrunk by a few pixels, which looked weird and
    pointless, and caused unnecessary invalidation thrash in the online
    collaborative editing context.
    
    We assume that the call to ScDocFunc::SetNormalString() in
    ScViewFunc::EnterData() is the result of interactivity.
    
    Change-Id: I3c77f7fb4e575f02e1dd7cdc18f2919f5eb3426e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110245
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136366
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>
    Tested-by: Thorsten Behrens <thorsten.behr...@allotropia.de>

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index f505f06114a9..d5aaf44d9db5 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1879,7 +1879,7 @@ public:
                                                     const ScColWidthParam* 
pParam = nullptr );
 
     SC_DLLPUBLIC bool           SetOptimalHeight( sc::RowHeightContext& rCxt, 
SCROW nStartRow,
-                                                   SCROW nEndRow, SCTAB nTab );
+                                                  SCROW nEndRow, SCTAB nTab, 
bool bApi );
 
     void                        UpdateAllRowHeights( sc::RowHeightContext& 
rCxt, const ScMarkData* pTabMark );
 
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 96702d1213e0..ab979afebc72 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -776,7 +776,7 @@ public:
                                     bool bFormula, const ScMarkData* pMarkData,
                                     const ScColWidthParam* pParam );
     bool SetOptimalHeight(
-        sc::RowHeightContext& rCxt, SCROW nStartRow, SCROW nEndRow,
+        sc::RowHeightContext& rCxt, SCROW nStartRow, SCROW nEndRow, bool bApi,
         ScProgress* pOuterProgress = nullptr, sal_uLong nProgressStart = 0 );
 
     void SetOptimalHeightOnly(
@@ -792,7 +792,7 @@ public:
     void        SetColWidthOnly( SCCOL nCol, sal_uInt16 nNewWidth );
     void        SetRowHeight( SCROW nRow, sal_uInt16 nNewHeight );
     bool        SetRowHeightRange( SCROW nStartRow, SCROW nEndRow, sal_uInt16 
nNewHeight,
-                                   double nPPTY );
+                                   double nPPTY, bool bApi );
 
     /**
      * Set specified row height to specified ranges.  Don't check for drawing
diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx
index ed55445d0558..407c5484a4c2 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -2734,7 +2734,7 @@ void ScDocRowHeightUpdater::update()
                 continue;
 
             mrDoc.maTabs[nTab]->SetOptimalHeight(
-                aCxt, aData.mnRow1, aData.mnRow2, &aProgress, nProgressStart);
+                aCxt, aData.mnRow1, aData.mnRow2, true, &aProgress, 
nProgressStart);
 
             nProgressStart += 
mrDoc.maTabs[nTab]->GetWeightedCount(aData.mnRow1, aData.mnRow2);
         }
@@ -2762,7 +2762,7 @@ void ScDocRowHeightUpdater::updateAll()
         if (!ValidTab(nTab) || !mrDoc.maTabs[nTab])
             continue;
 
-        mrDoc.maTabs[nTab]->SetOptimalHeight(aCxt, 0, mrDoc.MaxRow(), 
&aProgress, nProgressStart);
+        mrDoc.maTabs[nTab]->SetOptimalHeight(aCxt, 0, mrDoc.MaxRow(), true, 
&aProgress, nProgressStart);
         nProgressStart += mrDoc.maTabs[nTab]->GetWeightedCount();
     }
 }
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 725f6918411a..9ce58cbe64bb 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -4089,7 +4089,7 @@ void ScDocument::SetRowHeightRange( SCROW nStartRow, 
SCROW nEndRow, SCTAB nTab,
 {
     if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && 
maTabs[nTab] )
         maTabs[nTab]->SetRowHeightRange
-            ( nStartRow, nEndRow, nNewHeight, 1.0 );
+            ( nStartRow, nEndRow, nNewHeight, 1.0, true );
 }
 
 void ScDocument::SetRowHeightOnly( SCROW nStartRow, SCROW nEndRow, SCTAB nTab, 
sal_uInt16 nNewHeight )
@@ -4250,13 +4250,13 @@ long ScDocument::GetNeededSize( SCCOL nCol, SCROW nRow, 
SCTAB nTab,
     return 0;
 }
 
-bool ScDocument::SetOptimalHeight( sc::RowHeightContext& rCxt, SCROW 
nStartRow, SCROW nEndRow, SCTAB nTab )
+bool ScDocument::SetOptimalHeight( sc::RowHeightContext& rCxt, SCROW 
nStartRow, SCROW nEndRow, SCTAB nTab, bool bApi )
 {
     ScTable* pTab = FetchTable(nTab);
     if (!pTab)
         return false;
 
-    return pTab->SetOptimalHeight(rCxt, nStartRow, nEndRow);
+    return pTab->SetOptimalHeight(rCxt, nStartRow, nEndRow, bApi);
 }
 
 void ScDocument::UpdateAllRowHeights( sc::RowHeightContext& rCxt, const 
ScMarkData* pTabMark )
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index fea4dbcc66c3..71632ea1373a 100755
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -124,7 +124,7 @@ void GetOptimalHeightsInColumn(
 struct OptimalHeightsFuncObjBase
 {
     virtual ~OptimalHeightsFuncObjBase() {}
-    virtual bool operator() (SCROW nStartRow, SCROW nEndRow, sal_uInt16 
nHeight) = 0;
+    virtual bool operator() (SCROW nStartRow, SCROW nEndRow, sal_uInt16 
nHeight, bool bApi) = 0;
 };
 
 struct SetRowHeightOnlyFunc : public OptimalHeightsFuncObjBase
@@ -134,7 +134,7 @@ struct SetRowHeightOnlyFunc : public 
OptimalHeightsFuncObjBase
         mpTab(pTab)
     {}
 
-    virtual bool operator() (SCROW nStartRow, SCROW nEndRow, sal_uInt16 
nHeight) override
+    virtual bool operator() (SCROW nStartRow, SCROW nEndRow, sal_uInt16 
nHeight, bool /* bApi */) override
     {
         mpTab->SetRowHeightOnly(nStartRow, nEndRow, nHeight);
         return false;
@@ -151,16 +151,17 @@ struct SetRowHeightRangeFunc : public 
OptimalHeightsFuncObjBase
         mnPPTY(nPPTY)
     {}
 
-    virtual bool operator() (SCROW nStartRow, SCROW nEndRow, sal_uInt16 
nHeight) override
+    virtual bool operator() (SCROW nStartRow, SCROW nEndRow, sal_uInt16 
nHeight, bool bApi) override
     {
-        return mpTab->SetRowHeightRange(nStartRow, nEndRow, nHeight, mnPPTY);
+        return mpTab->SetRowHeightRange(nStartRow, nEndRow, nHeight, mnPPTY, 
bApi);
     }
 };
 
 bool SetOptimalHeightsToRows(
     sc::RowHeightContext& rCxt,
     OptimalHeightsFuncObjBase& rFuncObj,
-    ScBitMaskCompressedArray<SCROW, CRFlags>* pRowFlags, SCROW nStartRow, 
SCROW nEndRow )
+    ScBitMaskCompressedArray<SCROW, CRFlags>* pRowFlags, SCROW nStartRow, 
SCROW nEndRow,
+    bool bApi )
 {
     bool bChanged = false;
     SCROW nRngStart = 0;
@@ -200,7 +201,7 @@ bool SetOptimalHeightsToRows(
                     }
                     else
                     {
-                        bChanged |= rFuncObj(nRngStart, nRngEnd, nLast);
+                        bChanged |= rFuncObj(nRngStart, nRngEnd, nLast, bApi);
                         nLast = 0;
                     }
                 }
@@ -215,13 +216,13 @@ bool SetOptimalHeightsToRows(
         else
         {
             if (nLast)
-                bChanged |= rFuncObj(nRngStart, nRngEnd, nLast);
+                bChanged |= rFuncObj(nRngStart, nRngEnd, nLast, bApi);
             nLast = 0;
         }
         i += nMoreRows;     // already handled - skip
     }
     if (nLast)
-        bChanged |= rFuncObj(nRngStart, nRngEnd, nLast);
+        bChanged |= rFuncObj(nRngStart, nRngEnd, nLast, bApi);
 
     return bChanged;
 }
@@ -446,7 +447,7 @@ long ScTable::GetNeededSize( SCCOL nCol, SCROW nRow,
 }
 
 bool ScTable::SetOptimalHeight(
-    sc::RowHeightContext& rCxt, SCROW nStartRow, SCROW nEndRow,
+    sc::RowHeightContext& rCxt, SCROW nStartRow, SCROW nEndRow, bool bApi,
     ScProgress* pOuterProgress, sal_uLong nProgressStart )
 {
     assert(nStartRow <= nEndRow);
@@ -467,7 +468,7 @@ bool ScTable::SetOptimalHeight(
 
     rCxt.getHeightArray().enableTreeSearch(true);
     SetRowHeightRangeFunc aFunc(this, rCxt.getPPTY());
-    bool bChanged = SetOptimalHeightsToRows(rCxt, aFunc, pRowFlags.get(), 
nStartRow, nEndRow);
+    bool bChanged = SetOptimalHeightsToRows(rCxt, aFunc, pRowFlags.get(), 
nStartRow, nEndRow, bApi);
 
     if ( pProgress != pOuterProgress )
         delete pProgress;
@@ -494,7 +495,7 @@ void ScTable::SetOptimalHeightOnly(
     SetRowHeightOnlyFunc aFunc(this);
 
     rCxt.getHeightArray().enableTreeSearch(true);
-    SetOptimalHeightsToRows(rCxt, aFunc, pRowFlags.get(), nStartRow, nEndRow);
+    SetOptimalHeightsToRows(rCxt, aFunc, pRowFlags.get(), nStartRow, nEndRow, 
true);
 
     if ( pProgress != pOuterProgress )
         delete pProgress;
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 2085e623f932..cd25673b6cb7 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1,4 +1,4 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
 /*
  * This file is part of the LibreOffice project.
  *
@@ -2863,7 +2863,7 @@ void ScTable::StyleSheetChanged( const SfxStyleSheetBase* 
pStyleSheet, bool bRem
 
         SCROW nEndRow = aData.mnRow2;
         if (aData.mbValue)
-            SetOptimalHeight(aCxt, nRow, nEndRow);
+            SetOptimalHeight(aCxt, nRow, nEndRow, true);
 
         nRow = nEndRow + 1;
     }
@@ -3001,7 +3001,7 @@ namespace {
  */
 bool lcl_pixelSizeChanged(
     ScFlatUInt16RowSegments& rRowHeights, SCROW nStartRow, SCROW nEndRow,
-    sal_uInt16 nNewHeight, double nPPTY)
+    sal_uInt16 nNewHeight, double nPPTY, bool bApi)
 {
     long nNewPix = static_cast<long>(nNewHeight * nPPTY);
 
@@ -3014,7 +3014,11 @@ bool lcl_pixelSizeChanged(
 
         if (nHeight != nNewHeight)
         {
-            bool bChanged = (nNewPix != static_cast<long>(nHeight * nPPTY));
+            long nOldPix = static_cast<long>(nHeight * nPPTY);
+
+            // Heuristic: Don't bother when handling interactive input, if 
changing just one row and
+            // the height will shrink.
+            bool bChanged = (nNewPix != nOldPix) && (bApi || nEndRow - 
nStartRow > 0 || nNewPix > nOldPix);
             if (bChanged)
                 return true;
         }
@@ -3028,7 +3032,7 @@ bool lcl_pixelSizeChanged(
 }
 
 bool ScTable::SetRowHeightRange( SCROW nStartRow, SCROW nEndRow, sal_uInt16 
nNewHeight,
-                                    double nPPTY )
+                                 double nPPTY, bool bApi )
 {
     bool bChanged = false;
     if (ValidRow(nStartRow) && ValidRow(nEndRow) && mpRowHeights)
@@ -3055,17 +3059,20 @@ bool ScTable::SetRowHeightRange( SCROW nStartRow, SCROW 
nEndRow, sal_uInt16 nNew
             }
         }
 
+        // No idea why 20 is used here
         if (!bSingle || nEndRow - nStartRow < 20)
         {
-            bChanged = lcl_pixelSizeChanged(*mpRowHeights, nStartRow, nEndRow, 
nNewHeight, nPPTY);
-            mpRowHeights->setValue(nStartRow, nEndRow, nNewHeight);
+            bChanged = lcl_pixelSizeChanged(*mpRowHeights, nStartRow, nEndRow, 
nNewHeight, nPPTY, bApi);
+            if (bChanged)
+                mpRowHeights->setValue(nStartRow, nEndRow, nNewHeight);
         }
         else
         {
             SCROW nMid = (nStartRow + nEndRow) / 2;
-            if (SetRowHeightRange(nStartRow, nMid, nNewHeight, 1.0))
+            // No idea why nPPTY is ignored in these recursive calls and 
instead 1.0 is used
+            if (SetRowHeightRange(nStartRow, nMid, nNewHeight, 1.0, bApi))
                 bChanged = true;
-            if (SetRowHeightRange(nMid + 1, nEndRow, nNewHeight, 1.0))
+            if (SetRowHeightRange(nMid + 1, nEndRow, nNewHeight, 1.0, bApi))
                 bChanged = true;
         }
 
diff --git a/sc/source/filter/rtf/eeimpars.cxx 
b/sc/source/filter/rtf/eeimpars.cxx
index 368c99fa3bd6..abb920faa075 100644
--- a/sc/source/filter/rtf/eeimpars.cxx
+++ b/sc/source/filter/rtf/eeimpars.cxx
@@ -448,7 +448,7 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, 
double nOutputFactor, SvNu
         ScopedVclPtrInstance< VirtualDevice > pVirtDev;
         sc::RowHeightContext aCxt(nPPTX, nPPTY, aZoom, aZoom, pVirtDev);
         aCxt.setExtraHeight(ScGlobal::nLastRowHeightExtra);
-        mpDoc->SetOptimalHeight(aCxt, 0, nEndRow, 0);
+        mpDoc->SetOptimalHeight(aCxt, 0, nEndRow, 0, true);
 
         if ( !maRowHeights.empty() )
         {
diff --git a/sc/source/ui/docshell/docfunc.cxx 
b/sc/source/ui/docshell/docfunc.cxx
index 2922d3ccc3b4..df8419ea723a 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -133,7 +133,7 @@ static void lcl_PaintAbove( ScDocShell& rDocShell, const 
ScRange& rRange )
     }
 }
 
-bool ScDocFunc::AdjustRowHeight( const ScRange& rRange, bool bPaint )
+bool ScDocFunc::AdjustRowHeight( const ScRange& rRange, bool bPaint, bool bApi 
)
 {
     ScDocument& rDoc = rDocShell.GetDocument();
     if ( rDoc.IsImportingXML() )
@@ -154,7 +154,7 @@ bool ScDocFunc::AdjustRowHeight( const ScRange& rRange, 
bool bPaint )
     Fraction aOne(1,1);
 
     sc::RowHeightContext aCxt(aProv.GetPPTX(), aProv.GetPPTY(), aOne, aOne, 
aProv.GetDevice());
-    bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartRow, nEndRow, nTab);
+    bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartRow, nEndRow, nTab, 
bApi);
     // tdf#76183: recalculate objects' positions
     if (bChanged)
         rDoc.SetDrawPageSize(nTab);
@@ -623,7 +623,7 @@ bool ScDocFunc::DeleteContents(
             std::move(pUndoDoc), nFlags, pDataSpans, bMulti, bDrawUndo);
     }
 
-    if (!AdjustRowHeight( aExtendedRange ))
+    if (!AdjustRowHeight( aExtendedRange, true, bApi ))
         rDocShell.PostPaint( aExtendedRange, PaintPartFlags::Grid, nExtFlags );
     else if (nExtFlags & SC_PF_LINES)
         lcl_PaintAbove( rDocShell, aExtendedRange );    // for lines above the 
range
@@ -690,7 +690,7 @@ bool ScDocFunc::DeleteCell(
             nFlags, pDataSpans, false, bDrawUndo);
     }
 
-    if (!AdjustRowHeight(rPos))
+    if (!AdjustRowHeight(rPos, true, true))
         rDocShell.PostPaint(
             rPos.Col(), rPos.Row(), rPos.Tab(), rPos.Col(), rPos.Row(), 
rPos.Tab(),
             PaintPartFlags::Grid, nExtFlags);
@@ -751,7 +751,7 @@ bool ScDocFunc::TransliterateText( const ScMarkData& rMark, 
TransliterationFlags
 
     rDoc.TransliterateText( aMultiMark, nType );
 
-    if (!AdjustRowHeight( aMarkRange ))
+    if (!AdjustRowHeight( aMarkRange, true, true ))
         rDocShell.PostPaint( aMarkRange, PaintPartFlags::Grid );
 
     aModificator.SetDocumentModified();
@@ -807,7 +807,7 @@ bool ScDocFunc::SetNormalString( bool& o_rbNumFmtSet, const 
ScAddress& rPos, con
     }
 
     if ( bEditDeleted || rDoc.HasAttrib( ScRange(rPos), 
HasAttrFlags::NeedHeight ) )
-        AdjustRowHeight( ScRange(rPos) );
+        AdjustRowHeight( ScRange(rPos), true, bApi );
 
     rDocShell.PostPaintCell( rPos );
     aModificator.SetDocumentModified();
@@ -842,7 +842,7 @@ bool ScDocFunc::SetValueCell( const ScAddress& rPos, double 
fVal, bool bInteract
     }
 
     if (bHeight)
-        AdjustRowHeight(rPos);
+        AdjustRowHeight(rPos, true, !bInteraction);
 
     rDocShell.PostPaintCell( rPos );
     aModificator.SetDocumentModified();
@@ -913,7 +913,7 @@ bool ScDocFunc::SetStringCell( const ScAddress& rPos, const 
OUString& rStr, bool
     }
 
     if (bHeight)
-        AdjustRowHeight(rPos);
+        AdjustRowHeight(rPos, true, !bInteraction);
 
     rDocShell.PostPaintCell( rPos );
     aModificator.SetDocumentModified();
@@ -948,7 +948,7 @@ bool ScDocFunc::SetEditCell( const ScAddress& rPos, const 
EditTextObject& rStr,
     }
 
     if (bHeight)
-        AdjustRowHeight(rPos);
+        AdjustRowHeight(rPos, true, !bInteraction);
 
     rDocShell.PostPaintCell( rPos );
     aModificator.SetDocumentModified();
@@ -1012,7 +1012,7 @@ bool ScDocFunc::SetFormulaCell( const ScAddress& rPos, 
ScFormulaCell* pCell, boo
     }
 
     if (bHeight)
-        AdjustRowHeight(rPos);
+        AdjustRowHeight(rPos, true, !bInteraction);
 
     rDocShell.PostPaintCell( rPos );
     aModificator.SetDocumentModified();
@@ -1441,7 +1441,7 @@ bool ScDocFunc::ApplyAttributes( const ScMarkData& rMark, 
const ScPatternAttr& r
         if ( !bImportingXML )
             rDocShell.UpdatePaintExt( nExtFlags, aMultiRange );     // content 
after the change
 
-        if (!AdjustRowHeight( aMultiRange ))
+        if (!AdjustRowHeight( aMultiRange, true, bApi ))
             rDocShell.PostPaint( aMultiRange, PaintPartFlags::Grid, nExtFlags 
);
         else if (nExtFlags & SC_PF_LINES)
             lcl_PaintAbove( rDocShell, aMultiRange );   // because of lines 
above the range
@@ -1514,7 +1514,7 @@ bool ScDocFunc::ApplyStyle( const ScMarkData& rMark, 
const OUString& rStyleName,
 
     rDoc.ApplySelectionStyle( *pStyleSheet, rMark );
 
-    if (!AdjustRowHeight( aMultiRange ))
+    if (!AdjustRowHeight( aMultiRange, true, bApi ))
         rDocShell.PostPaint( aMultiRange, PaintPartFlags::Grid );
 
     aModificator.SetDocumentModified();
@@ -2163,8 +2163,8 @@ bool ScDocFunc::InsertCells( const ScRange& rRange, const 
ScMarkData* pTabMark,
                 nScenarioCount ++;
 
             bool bAdjusted = ( eCmd == INS_INSROWS_BEFORE || eCmd == 
INS_INSROWS_AFTER ) ?
-                        AdjustRowHeight(ScRange(0, nStartRow, i, 
rDoc.MaxCol(), nEndRow, i+nScenarioCount )) :
-                        AdjustRowHeight(ScRange(0, nPaintStartRow, i, 
rDoc.MaxCol(), nPaintEndRow, i+nScenarioCount ));
+                        AdjustRowHeight(ScRange(0, nStartRow, i, 
rDoc.MaxCol(), nEndRow, i+nScenarioCount ), true, bApi) :
+                        AdjustRowHeight(ScRange(0, nPaintStartRow, i, 
rDoc.MaxCol(), nPaintEndRow, i+nScenarioCount ), true, bApi);
             if (bAdjusted)
             {
                 //  paint only what is not done by AdjustRowHeight
@@ -2775,7 +2775,7 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const 
ScMarkData* pTabMark,
             nScenarioCount ++;
 
         //  delete entire rows: do not adjust
-        if ( eCmd == DelCellCmd::Rows || !AdjustRowHeight(ScRange( 0, 
nPaintStartRow, rTab, rDoc.MaxCol(), nPaintEndRow, rTab+nScenarioCount )) )
+        if ( eCmd == DelCellCmd::Rows || !AdjustRowHeight(ScRange( 0, 
nPaintStartRow, rTab, rDoc.MaxCol(), nPaintEndRow, rTab+nScenarioCount ), true, 
bApi) )
             rDocShell.PostPaint( nPaintStartCol, nPaintStartRow, rTab, 
nPaintEndCol, nPaintEndRow, rTab+nScenarioCount, nPaintFlags,  nExtFlags );
         else
         {
@@ -3001,7 +3001,7 @@ bool ScDocFunc::MoveBlock( const ScRange& rSource, const 
ScAddress& rDestPos,
                 return false;
             }
 
-        bSourceHeight = AdjustRowHeight( rSource, false );
+        bSourceHeight = AdjustRowHeight( rSource, false, bApi );
     }
 
     ScRange aPasteDest( nDestCol, nDestRow, nDestTab, nDestEndCol, 
nDestEndRow, nDestEndTab );
@@ -3026,7 +3026,7 @@ bool ScDocFunc::MoveBlock( const ScRange& rSource, const 
ScAddress& rDestPos,
 
     bool bDestHeight = AdjustRowHeight(
                             ScRange( 0,nDestRow,nDestTab, 
rDoc.MaxCol(),nDestEndRow,nDestEndTab ),
-                            false );
+                            false, bApi );
 
     /*  Paste drawing objects after adjusting formula references
         and row heights. There are no cell notes or drawing objects, if the
@@ -3692,7 +3692,7 @@ bool ScDocFunc::SetWidthOrHeight(
                 Fraction aOne(1,1);
                 sc::RowHeightContext aCxt(aProv.GetPPTX(), aProv.GetPPTY(), 
aOne, aOne, aProv.GetDevice());
                 aCxt.setForceAutoSize(bAll);
-                rDoc.SetOptimalHeight(aCxt, nStartNo, nEndNo, nTab);
+                rDoc.SetOptimalHeight(aCxt, nStartNo, nEndNo, nTab, bApi);
 
                 if (bAll)
                     rDoc.ShowRows( nStartNo, nEndNo, nTab, true );
@@ -4264,7 +4264,7 @@ bool ScDocFunc::AutoFormat( const ScRange& rRange, const 
ScMarkData* pTabMark,
                     break;
 
                 bool bAdj = AdjustRowHeight( ScRange(nStartCol, nStartRow, 
rTab,
-                                                    nEndCol, nEndRow, rTab), 
false );
+                                                     nEndCol, nEndRow, rTab), 
false, bApi );
                 if (bAdj)
                     rDocShell.PostPaint( 0,nStartRow,rTab, 
rDoc.MaxCol(),rDoc.MaxRow(),rTab,
                                         PaintPartFlags::Grid | 
PaintPartFlags::Left );
@@ -4610,7 +4610,7 @@ bool ScDocFunc::FillSimple( const ScRange& rRange, const 
ScMarkData* pTabMark,
         rDoc.Fill( aSourceArea.aStart.Col(), aSourceArea.aStart.Row(),
                 aSourceArea.aEnd.Col(), aSourceArea.aEnd.Row(), &aProgress,
                 aMark, nCount, eDir, FILL_SIMPLE );
-        AdjustRowHeight(aRange);
+        AdjustRowHeight(aRange, true, bApi);
 
         if ( bRecord )      // only now is Draw-Undo available
         {
@@ -4741,7 +4741,7 @@ bool ScDocFunc::FillSeries( const ScRange& rRange, const 
ScMarkData* pTabMark,
             rDoc.Fill( aSourceArea.aStart.Col(), aSourceArea.aStart.Row(),
                         aSourceArea.aEnd.Col(), aSourceArea.aEnd.Row(), 
&aProgress,
                         aMark, nCount, eDir, eCmd, eDateCmd, fStep, fMax );
-            AdjustRowHeight(rRange);
+            AdjustRowHeight(rRange, true, bApi);
 
             rDocShell.PostPaintGridAll();
             aModificator.SetDocumentModified();
@@ -4888,7 +4888,7 @@ bool ScDocFunc::FillAuto( ScRange& rRange, const 
ScMarkData* pTabMark, FillDir e
             aSourceArea.aEnd.Col(), aSourceArea.aEnd.Row(), &aProgress,
             aMark, nCount, eDir, eCmd, eDateCmd, fStep, fMax );
 
-    AdjustRowHeight(aDestArea);
+    AdjustRowHeight(aDestArea, true, bApi);
 
     if ( bRecord )      // only now is Draw-Undo available
     {
@@ -4989,7 +4989,7 @@ bool ScDocFunc::MergeCells( const ScCellMergeOption& 
rOption, bool bContents, bo
             rDoc.ApplyAttr( nStartCol, nStartRow, nTab, SvxVerJustifyItem( 
SvxCellVerJustify::Center, ATTR_VER_JUSTIFY ) );
         }
 
-        if ( !AdjustRowHeight( ScRange( 0,nStartRow,nTab, 
rDoc.MaxCol(),nEndRow,nTab ) ) )
+        if ( !AdjustRowHeight( ScRange( 0,nStartRow,nTab, 
rDoc.MaxCol(),nEndRow,nTab ), true, bApi ) )
             rDocShell.PostPaint( nStartCol, nStartRow, nTab,
                                  nEndCol, nEndRow, nTab, PaintPartFlags::Grid 
);
         if (bNeedContents || rOption.mbCenter)
@@ -5081,7 +5081,7 @@ bool ScDocFunc::UnmergeCells( const ScCellMergeOption& 
rOption, bool bRecord, Sc
 
         rDoc.ExtendMerge( aRefresh, true );
 
-        if ( !AdjustRowHeight( aExtended ) )
+        if ( !AdjustRowHeight( aExtended, true, true ) )
             rDocShell.PostPaint( aExtended, PaintPartFlags::Grid );
     }
 
@@ -5427,7 +5427,7 @@ bool ScDocFunc::InsertNameList( const ScAddress& 
rStartPos, bool bApi )
                                 std::move(pUndoDoc), std::move(pRedoDoc) ) );
             }
 
-            if 
(!AdjustRowHeight(ScRange(0,nStartRow,nTab,rDoc.MaxCol(),nEndRow,nTab)))
+            if 
(!AdjustRowHeight(ScRange(0,nStartRow,nTab,rDoc.MaxCol(),nEndRow,nTab), true, 
true))
                 rDocShell.PostPaint( nStartCol,nStartRow,nTab, 
nEndCol,nEndRow,nTab, PaintPartFlags::Grid );
 
             aModificator.SetDocumentModified();
diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx
index ea851d9b9d1b..374922b968f8 100644
--- a/sc/source/ui/docshell/docsh5.cxx
+++ b/sc/source/ui/docshell/docsh5.cxx
@@ -408,7 +408,7 @@ bool ScDocShell::AdjustRowHeight( SCROW nStartRow, SCROW 
nEndRow, SCTAB nTab )
     ScSizeDeviceProvider aProv(this);
     Fraction aZoom(1,1);
     sc::RowHeightContext aCxt(aProv.GetPPTX(), aProv.GetPPTY(), aZoom, aZoom, 
aProv.GetDevice());
-    bool bChange = m_aDocument.SetOptimalHeight(aCxt, nStartRow,nEndRow, nTab);
+    bool bChange = m_aDocument.SetOptimalHeight(aCxt, nStartRow,nEndRow, nTab, 
true);
 
     if (bChange)
     {
diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx
index ca0f03e0318c..af8e23fc3124 100644
--- a/sc/source/ui/inc/docfunc.hxx
+++ b/sc/source/ui/inc/docfunc.hxx
@@ -59,7 +59,7 @@ class ScDocFunc
 protected:
     ScDocShell&     rDocShell;
 
-    bool            AdjustRowHeight( const ScRange& rRange, bool bPaint = true 
);
+    bool            AdjustRowHeight( const ScRange& rRange, bool bPaint, bool 
bApi );
     void            CreateOneName( ScRangeName& rList,
                                     SCCOL nPosX, SCROW nPosY, SCTAB nTab,
                                     SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
diff --git a/sc/source/ui/inc/viewfunc.hxx b/sc/source/ui/inc/viewfunc.hxx
index fd1e05fa1a67..3c396a29b763 100644
--- a/sc/source/ui/inc/viewfunc.hxx
+++ b/sc/source/ui/inc/viewfunc.hxx
@@ -214,7 +214,7 @@ public:
     void            SetMarkedWidthOrHeight( bool bWidth, ScSizeMode eMode, 
sal_uInt16 nSizeTwips );
 
     bool            AdjustBlockHeight( bool bPaint = true, ScMarkData* 
pMarkData = nullptr );
-    bool            AdjustRowHeight( SCROW nStartRow, SCROW nEndRow );
+    bool            AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, bool bApi 
);
 
     void            ModifyCellSize( ScDirection eDir, bool bOptimal );
 
diff --git a/sc/source/ui/undo/undobase.cxx b/sc/source/ui/undo/undobase.cxx
index 7181b10d01ee..001aa69acc20 100644
--- a/sc/source/ui/undo/undobase.cxx
+++ b/sc/source/ui/undo/undobase.cxx
@@ -305,7 +305,7 @@ bool ScBlockUndo::AdjustHeight()
 
     sc::RowHeightContext aCxt(nPPTX, nPPTY, aZoomX, aZoomY, pVirtDev);
     bool bRet = rDoc.SetOptimalHeight(
-        aCxt, aBlockRange.aStart.Row(), aBlockRange.aEnd.Row(), 
aBlockRange.aStart.Tab());
+        aCxt, aBlockRange.aStart.Row(), aBlockRange.aEnd.Row(), 
aBlockRange.aStart.Tab(), true);
 
     if (bRet)
     {
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index 7c07be1f45be..3f4724147981 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -1247,7 +1247,7 @@ void ScUndoDragDrop::PaintArea( ScRange aRange, 
sal_uInt16 nExtFlags ) const
             rViewData.GetPPTX(), rViewData.GetPPTY(), rViewData.GetZoomX(), 
rViewData.GetZoomY(),
             pVirtDev);
 
-        if (rDoc.SetOptimalHeight(aCxt, aRange.aStart.Row(), 
aRange.aEnd.Row(), aRange.aStart.Tab()))
+        if (rDoc.SetOptimalHeight(aCxt, aRange.aStart.Row(), 
aRange.aEnd.Row(), aRange.aStart.Tab(), true))
         {
             // tdf#76183: recalculate objects' positions
             rDoc.SetDrawPageSize(aRange.aStart.Tab());
@@ -2249,7 +2249,7 @@ void ScUndoRemoveMerge::Undo()
             if ( pViewShell )
             {
                 pViewShell->SetTabNo(rTab);
-                bDidPaint = pViewShell->AdjustRowHeight(rOption.mnStartRow, 
rOption.mnEndRow);
+                bDidPaint = pViewShell->AdjustRowHeight(rOption.mnStartRow, 
rOption.mnEndRow, true);
             }
             if (!bDidPaint)
                 ScUndoUtil::PaintMore(pDocShell, aRange);
@@ -2295,7 +2295,7 @@ void ScUndoRemoveMerge::Redo()
             if ( pViewShell )
             {
                 pViewShell->SetTabNo(nTab);
-                bDidPaint = pViewShell->AdjustRowHeight(rOption.mnStartRow, 
rOption.mnEndRow);
+                bDidPaint = pViewShell->AdjustRowHeight(rOption.mnStartRow, 
rOption.mnEndRow, true);
             }
             if (!bDidPaint)
                 ScUndoUtil::PaintMore(pDocShell, aRange);
diff --git a/sc/source/ui/undo/undoblk3.cxx b/sc/source/ui/undo/undoblk3.cxx
index 1459e4dd482d..999a75f87841 100644
--- a/sc/source/ui/undo/undoblk3.cxx
+++ b/sc/source/ui/undo/undoblk3.cxx
@@ -161,7 +161,7 @@ void ScUndoDeleteContents::DoChange( const bool bUndo )
 
     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     if ( !( pViewShell && pViewShell->AdjustRowHeight(
-                                aRange.aStart.Row(), aRange.aEnd.Row() ) ) )
+                                aRange.aStart.Row(), aRange.aEnd.Row(), true ) 
) )
 /*A*/   pDocShell->PostPaint( aRange, PaintPartFlags::Grid | 
PaintPartFlags::Extras, nExtFlags );
 
     if (pViewShell)
@@ -720,7 +720,7 @@ void ScUndoMerge::DoChange( bool bUndo ) const
         if ( pViewShell )
         {
             pViewShell->SetTabNo(nTab);
-            bDidPaint = pViewShell->AdjustRowHeight(maOption.mnStartRow, 
maOption.mnEndRow);
+            bDidPaint = pViewShell->AdjustRowHeight(maOption.mnStartRow, 
maOption.mnEndRow, true);
         }
 
         if (!bDidPaint)
@@ -873,7 +873,7 @@ void ScUndoAutoFormat::Redo()
                     rDoc.SetRowFlags( nRow, nTab, nOld & ~CRFlags::ManualSize 
);
             }
 
-            bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartY, nEndY, nTab);
+            bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartY, nEndY, nTab, 
true);
 
             for (SCCOL nCol=nStartX; nCol<=nEndX; nCol++)
                 if (!rDoc.ColHidden(nCol, nTab))
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index 0ab2d088b0e7..02456b88d61c 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -156,7 +156,7 @@ bool ScViewFunc::AdjustBlockHeight( bool bPaint, 
ScMarkData* pMarkData )
             SCROW nEndNo = rRow.mnEnd;
             ScAddress aTopLeft(0, nStartNo, nTab);
             rDoc.UpdateScriptTypes(aTopLeft, MAXCOLCOUNT, nEndNo-nStartNo+1);
-            if (rDoc.SetOptimalHeight(aCxt, nStartNo, nEndNo, nTab))
+            if (rDoc.SetOptimalHeight(aCxt, nStartNo, nEndNo, nTab, true))
             {
                 if (!bChanged)
                     nPaintY = nStartNo;
@@ -180,7 +180,7 @@ bool ScViewFunc::AdjustBlockHeight( bool bPaint, 
ScMarkData* pMarkData )
     return bAnyChanged;
 }
 
-bool ScViewFunc::AdjustRowHeight( SCROW nStartRow, SCROW nEndRow )
+bool ScViewFunc::AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, bool bApi )
 {
     if (comphelper::LibreOfficeKit::isActive())
     {
@@ -206,7 +206,7 @@ bool ScViewFunc::AdjustRowHeight( SCROW nStartRow, SCROW 
nEndRow )
         aZoomX = aZoomY = Fraction( 1, 1 );
     }
     sc::RowHeightContext aCxt(nPPTX, nPPTY, aZoomX, aZoomY, aProv.GetDevice());
-    bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartRow, nEndRow, nTab);
+    bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartRow, nEndRow, nTab, 
bApi);
 
     // tdf#76183: recalculate objects' positions
     if (bChanged)
diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx
index 7a39f5037fa2..a801cdd738cf 100644
--- a/sc/source/ui/view/viewfun3.cxx
+++ b/sc/source/ui/view/viewfun3.cxx
@@ -139,7 +139,7 @@ void ScViewFunc::CutToClip()
         pDoc->DeleteObjectsInSelection( rMark );
         rMark.MarkToSimple();
 
-        if ( !AdjustRowHeight( aRange.aStart.Row(), aRange.aEnd.Row() ) )
+        if ( !AdjustRowHeight( aRange.aStart.Row(), aRange.aEnd.Row(), true ) )
             pDocSh->PostPaint( aRange, PaintPartFlags::Grid, nExtFlags );
 
         if ( bRecord )                          // Draw-Undo now available
diff --git a/sc/source/ui/view/viewfun4.cxx b/sc/source/ui/view/viewfun4.cxx
index 0778c2b5a710..7b1218a2f7e3 100644
--- a/sc/source/ui/view/viewfun4.cxx
+++ b/sc/source/ui/view/viewfun4.cxx
@@ -173,7 +173,7 @@ void ScViewFunc::PasteRTF( SCCOL nStartCol, SCROW nStartRow,
         else if ( aDataHelper.GetString( SotClipboardFormatId::RICHTEXT, aStr 
) )
             aImpEx.ImportString( aStr, SotClipboardFormatId::RICHTEXT );
 
-        AdjustRowHeight( nStartRow, aImpEx.GetRange().aEnd.Row() );
+        AdjustRowHeight( nStartRow, aImpEx.GetRange().aEnd.Row(), true );
         pDocSh->UpdateOle(&GetViewData());
         ShowAllCursors();
     }
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index 21d10fcd1726..abae1c2fff60 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -709,7 +709,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB 
nTab,
         if (bSimple)
         {
             if (bCommon)
-                AdjustRowHeight(nRow,nRow);
+                AdjustRowHeight(nRow,nRow,true);
 
             EnterData(nCol,nRow,nTab,aString);
         }
@@ -729,7 +729,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB 
nTab,
 
             HideAllCursors();
 
-            AdjustRowHeight(nRow,nRow);
+            AdjustRowHeight(nRow,nRow,true);
 
             for (const auto& rTab : rMark)
                 pDocSh->PostPaintCell( nCol, nRow, rTab );
@@ -1888,7 +1888,7 @@ void ScViewFunc::DeleteMulti( bool bRows )
                 pDocSh, bRows, bNeedRefresh, nTab, aSpans, 
std::move(pUndoDoc), std::move(pUndoData)));
     }
 
-    if (!AdjustRowHeight(0, rDoc.MaxRow()))
+    if (!AdjustRowHeight(0, rDoc.MaxRow(), true))
     {
         if (bRows)
         {
@@ -2160,7 +2160,7 @@ void ScViewFunc::SetWidthOrHeight(
                     sc::RowHeightContext aCxt(nPPTX, nPPTY, aZoomX, aZoomY, 
aProv.GetDevice());
                     aCxt.setForceAutoSize(bAll);
                     aCxt.setExtraHeight(nSizeTwips);
-                    rDoc.SetOptimalHeight(aCxt, nStartNo, nEndNo, nTab);
+                    rDoc.SetOptimalHeight(aCxt, nStartNo, nEndNo, nTab, true);
                     if (bAll)
                         rDoc.ShowRows( nStartNo, nEndNo, nTab, true );
 
@@ -2433,7 +2433,7 @@ void ScViewFunc::ModifyCellSize( ScDirection eDir, bool 
bOptimal )
                     pPattern->GetItem( ATTR_LINEBREAK ).GetValue() ||
                     pPattern->GetItem( ATTR_HOR_JUSTIFY ).GetValue() == 
SvxCellHorJustify::Block;
             if (bNeedHeight)
-                AdjustRowHeight( nRow, nRow );
+                AdjustRowHeight( nRow, nRow, true );
         }
     }
     else

Reply via email to