sc/source/ui/docshell/docfunc.cxx |   24 +++++++++++-------------
 sc/source/ui/inc/docsh.hxx        |    2 +-
 sc/source/ui/inc/viewdata.hxx     |    3 +++
 sc/source/ui/view/tabview3.cxx    |    6 ++++--
 sc/source/ui/view/viewfun3.cxx    |    4 ++--
 sc/source/ui/view/viewfunc.cxx    |   32 +++++++++++++++++++++-----------
 6 files changed, 42 insertions(+), 29 deletions(-)

New commits:
commit 635cb75d0ef00784a1877b6b5e2f7f92ec0469be
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Mon Feb 12 15:55:22 2024 +0000
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Feb 13 15:23:12 2024 +0100

    pass width hint around as twips and convert to pixel at the end
    
    reuse the device setup and twip calculation that GetOptimalColWidth uses
    and convert to pixel at the end with ViewData::toPixel
    
    Change-Id: Ie24a66dda2e642c23ae63ff915829dd910ee44dd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163259
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    (cherry picked from commit 85db2b8338392525bb138f41a3175203c703bf73)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163285
    Tested-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sc/source/ui/docshell/docfunc.cxx 
b/sc/source/ui/docshell/docfunc.cxx
index 21aee819174b..565fa3c41dac 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -671,24 +671,22 @@ bool ScDocFunc::DeleteContents(
     return true;
 }
 
-tools::Long ScDocShell::GetPixelWidthHint(const ScAddress& rPos)
+tools::Long ScDocShell::GetTwipWidthHint(const ScAddress& rPos)
 {
     ScViewData* pViewData = GetViewData();
     if (!pViewData)
         return -1;
 
     ScSizeDeviceProvider aProv(this);
-    OutputDevice* pDev = aProv.GetDevice();         // has pixel MapMode
-    double nPPTX = aProv.GetPPTX();
-    double nPPTY = aProv.GetPPTY();
+    Fraction aZoomX, aZoomY;
+    double nPPTX, nPPTY;
+    pViewData->setupSizeDeviceProviderForColWidth(aProv, aZoomX, aZoomY, 
nPPTX, nPPTY);
 
     ScDocument& rDoc = GetDocument();
-    Fraction aInvX(pViewData->GetZoomX().GetDenominator(),
-                   pViewData->GetZoomX().GetNumerator());
-    Fraction aInvY(pViewData->GetZoomY().GetDenominator(),
-                   pViewData->GetZoomY().GetNumerator());
-    return rDoc.GetNeededSize(rPos.Col(), rPos.Row(), rPos.Tab(), pDev,
-                              nPPTX, nPPTY, aInvX, aInvY, true /*bWidth*/);
+    tools::Long nWidth = rDoc.GetNeededSize(rPos.Col(), rPos.Row(), 
rPos.Tab(), aProv.GetDevice(),
+                                            nPPTX, nPPTY, aZoomX, aZoomY, true 
/*bWidth*/);
+
+    return (nWidth + 2) / nPPTX; // same as ScColumn::GetOptimalColWidth
 }
 
 bool ScDocFunc::DeleteCell(
@@ -739,7 +737,7 @@ bool ScDocFunc::DeleteCell(
         pDataSpans = sc::DocFuncUtil::getNonEmptyCellSpans(rDoc, rMark, rPos);
     }
 
-    tools::Long nBefore(rDocShell.GetPixelWidthHint(rPos));
+    tools::Long nBefore(rDocShell.GetTwipWidthHint(rPos));
     rDoc.DeleteArea(rPos.Col(), rPos.Row(), rPos.Col(), rPos.Row(), rMark, 
nFlags);
 
     if (bRecord)
@@ -854,9 +852,9 @@ bool ScDocFunc::SetNormalString( bool& o_rbNumFmtSet, const 
ScAddress& rPos, con
         aOldValues.push_back(aOldValue);
     }
 
-    tools::Long nBefore(rDocShell.GetPixelWidthHint(rPos));
+    tools::Long nBefore(rDocShell.GetTwipWidthHint(rPos));
     o_rbNumFmtSet = rDoc.SetString( rPos.Col(), rPos.Row(), rPos.Tab(), rText 
);
-    tools::Long nAfter(rDocShell.GetPixelWidthHint(rPos));
+    tools::Long nAfter(rDocShell.GetTwipWidthHint(rPos));
 
     if (bUndo)
     {
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index d476ce15222e..f35d8a1c9798 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -313,7 +313,7 @@ public:
 
     void            PostEditView( ScEditEngineDefaulter* pEditEngine, const 
ScAddress& rCursorPos );
 
-    tools::Long     GetPixelWidthHint(const ScAddress& rPos);
+    tools::Long     GetTwipWidthHint(const ScAddress& rPos);
 
     void            PostPaint( SCCOL nStartCol, SCROW nStartRow, SCTAB 
nStartTab,
                             SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, 
PaintPartFlags nPart,
diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx
index 72386b2efa17..62231b116813 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -115,6 +115,7 @@ class ScExtDocOptions;
 class ScViewData;
 class ScMarkData;
 class ScGridWindow;
+class ScSizeDeviceProvider;
 
 class ScPositionHelper
 {
@@ -698,6 +699,8 @@ public:
     static void     AddPixelsWhileBackward( tools::Long & rScrY, tools::Long 
nEndPixels,
                                     SCROW & rPosY, SCROW nStartRow, double 
nPPTY,
                                     const ScDocument * pDoc, SCTAB nTabNo );
+
+    void setupSizeDeviceProviderForColWidth(ScSizeDeviceProvider& rProv, 
Fraction& rZoomX, Fraction& rZoomY, double& rPPTX, double &rPPTY);
 };
 
 inline tools::Long ScViewData::ToPixel( sal_uInt16 nTwips, double nFactor )
diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx
index debf84687e3d..9e36ec386eb0 100644
--- a/sc/source/ui/view/tabview3.cxx
+++ b/sc/source/ui/view/tabview3.cxx
@@ -2389,7 +2389,7 @@ void ScTabView::UpdateFormulas(SCCOL nStartCol, SCROW 
nStartRow, SCCOL nEndCol,
 //  PaintArea - repaint block
 
 void ScTabView::PaintArea( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, 
SCROW nEndRow,
-                            ScUpdateMode eMode, tools::Long 
nMaxWidthAffectedHint )
+                            ScUpdateMode eMode, tools::Long 
nMaxWidthAffectedHintTwip )
 {
     SCCOL nCol1;
     SCROW nRow1;
@@ -2467,8 +2467,10 @@ void ScTabView::PaintArea( SCCOL nStartCol, SCROW 
nStartRow, SCCOL nEndCol, SCRO
 
         if ( eMode == ScUpdateMode::All )
         {
-            if (nMaxWidthAffectedHint != -1)
+            if (nMaxWidthAffectedHintTwip != -1)
             {
+                tools::Long nMaxWidthAffectedHint = 
ScViewData::ToPixel(nMaxWidthAffectedHintTwip, aViewData.GetPPTX());
+
                 // If we know the max text width affected then just invalidate
                 // the max of the cell width and hint of affected cell width
                 // (where affected with is in terms of max width of optimal 
cell
diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx
index 289776006284..30c5e0079ea5 100644
--- a/sc/source/ui/view/viewfun3.cxx
+++ b/sc/source/ui/view/viewfun3.cxx
@@ -1268,7 +1268,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, 
ScDocument* pClipDoc,
     const bool bSingleCellBefore = nStartCol == nEndCol &&
                                    nStartRow == nEndRow &&
                                    nStartTab == nEndTab;
-    tools::Long nBeforeHint(bSingleCellBefore ? 
pDocSh->GetPixelWidthHint(ScAddress(nStartCol, nStartRow, nStartTab)) : -1);
+    tools::Long nBeforeHint(bSingleCellBefore ? 
pDocSh->GetTwipWidthHint(ScAddress(nStartCol, nStartRow, nStartTab)) : -1);
 
     sal_uInt16 nExtFlags = 0;
     pDocSh->UpdatePaintExt( nExtFlags, nStartCol, nStartRow, nStartTab,
@@ -1452,7 +1452,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, 
ScDocument* pClipDoc,
                                   nStartTab == nEndTab;
     if (bSingleCellBefore && bSingleCellAfter)
     {
-        tools::Long nAfterHint(pDocSh->GetPixelWidthHint(ScAddress(nStartCol, 
nStartRow, nStartTab)));
+        tools::Long nAfterHint(pDocSh->GetTwipWidthHint(ScAddress(nStartCol, 
nStartRow, nStartTab)));
         nMaxWidthAffectedHint = std::max(nBeforeHint, nAfterHint);
     }
 
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index 94cbb305c64e..88261c5e561a 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -308,24 +308,34 @@ void ScViewFunc::DoAutoAttributes( SCCOL nCol, SCROW 
nRow, SCTAB nTab,
 
 //      additional routines
 
+void ScViewData::setupSizeDeviceProviderForColWidth(ScSizeDeviceProvider& 
rProv, Fraction& rZoomX, Fraction& rZoomY, double& rPPTX, double &rPPTY)
+{
+    if (rProv.IsPrinter())
+    {
+        rPPTX = rProv.GetPPTX();
+        rPPTY = rProv.GetPPTY();
+        rZoomX = rZoomY = Fraction(1, 1);
+    }
+    else
+    {
+        rPPTX = GetPPTX();
+        rPPTY = GetPPTY();
+        rZoomX = GetZoomX();
+        rZoomY = GetZoomY();
+    }
+}
+
 sal_uInt16 ScViewFunc::GetOptimalColWidth( SCCOL nCol, SCTAB nTab, bool 
bFormula )
 {
     ScDocShell* pDocSh = GetViewData().GetDocShell();
     ScDocument& rDoc = pDocSh->GetDocument();
     ScMarkData& rMark = GetViewData().GetMarkData();
 
-    double nPPTX = GetViewData().GetPPTX();
-    double nPPTY = GetViewData().GetPPTY();
-    Fraction aZoomX = GetViewData().GetZoomX();
-    Fraction aZoomY = GetViewData().GetZoomY();
-
     ScSizeDeviceProvider aProv(pDocSh);
-    if (aProv.IsPrinter())
-    {
-        nPPTX = aProv.GetPPTX();
-        nPPTY = aProv.GetPPTY();
-        aZoomX = aZoomY = Fraction( 1, 1 );
-    }
+
+    Fraction aZoomX, aZoomY;
+    double nPPTX, nPPTY;
+    GetViewData().setupSizeDeviceProviderForColWidth(aProv, aZoomX, aZoomY, 
nPPTX, nPPTY);
 
     sal_uInt16 nTwips = rDoc.GetOptimalColWidth( nCol, nTab, aProv.GetDevice(),
                                 nPPTX, nPPTY, aZoomX, aZoomY, bFormula, &rMark 
);

Reply via email to