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 85db2b8338392525bb138f41a3175203c703bf73 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 08:16:08 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> diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 750fa3e01b18..71bb31545df4 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 b4a016d8fd68..be8f551fcab0 100644 --- a/sc/source/ui/inc/docsh.hxx +++ b/sc/source/ui/inc/docsh.hxx @@ -315,7 +315,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 abe93954f774..b5265299462a 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 { @@ -696,6 +697,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 7ffa5c0d0138..15e71a1ba751 100644 --- a/sc/source/ui/view/tabview3.cxx +++ b/sc/source/ui/view/tabview3.cxx @@ -2351,7 +2351,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; @@ -2429,8 +2429,10 @@ void ScTabView::PaintArea( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCRO if ( eMode == ScUpdateMode::All ) { - if (nMaxWidthAffectedHint != -1) + if (nMaxWidthAffectedHintTwip != -1) { + tools::Long nMaxWidthAffectedHint = aViewData.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 6c78018a64d5..502340a5bbf0 100644 --- a/sc/source/ui/view/viewfun3.cxx +++ b/sc/source/ui/view/viewfun3.cxx @@ -1272,7 +1272,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, @@ -1456,7 +1456,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 503c96d29db1..299efb92e3f4 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -287,24 +287,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 );