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 <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit 85db2b8338392525bb138f41a3175203c703bf73)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163284
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
This commit is contained in:
Caolán McNamara
2024-02-13 15:09:15 +01:00
parent 1f9d8733ae
commit 9bc2872d5f
6 changed files with 42 additions and 29 deletions
+11 -13
View File
@@ -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)
{
+1 -1
View File
@@ -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,
+3
View File
@@ -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 )
+4 -2
View File
@@ -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
+2 -2
View File
@@ -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);
}
+21 -11
View File
@@ -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 );