diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 2867b8b6df36..37f0f2209848 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 2a87da31ee69..1b1f4164db06 100644 --- a/sc/source/ui/inc/docsh.hxx +++ b/sc/source/ui/inc/docsh.hxx @@ -314,7 +314,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 a2a6667b8f27..7a69d5d82af9 100644 --- a/sc/source/ui/view/tabview3.cxx +++ b/sc/source/ui/view/tabview3.cxx @@ -2390,7 +2390,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; @@ -2468,8 +2468,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 d551f5af7b29..21c2a9c3d44f 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 );