[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - sc/inc sc/source
Dennis Francis (via logerrit)
logerrit at kemper.freedesktop.org
Mon Apr 12 15:34:50 UTC 2021
sc/inc/editutil.hxx | 4 ++
sc/source/core/tool/editutil.cxx | 75 ++++++++++++++++++++++++++++++---------
sc/source/ui/view/gridwin4.cxx | 34 +++++++++++++++--
3 files changed, 93 insertions(+), 20 deletions(-)
New commits:
commit 8b260f6ab812ed777ee02d7e96f4bfd5a8255ed6
Author: Dennis Francis <dennis.francis at collabora.com>
AuthorDate: Tue Jan 19 14:46:48 2021 +0530
Commit: Dennis Francis <dennis.francis at collabora.com>
CommitDate: Mon Apr 12 17:34:14 2021 +0200
lok: Take indent and margins into account
... when painting tiles with edit-text content.
Conflicts:
sc/source/core/tool/editutil.cxx
Change-Id: I31199c18ed5aab005d56241046a9f7109691db99
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109755
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Tor Lillqvist <tml at collabora.com>
(cherry picked from commit bc025dac6ce3301f5798e8ada4fee07b415de76a)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110619
Tested-by: Jenkins
Reviewed-by: Dennis Francis <dennis.francis at collabora.com>
(cherry picked from commit d87fcadc242881c39d3c49c85b9d5ef83ec6dde4)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113975
Tested-by: Dennis Francis <dennis.francis at collabora.com>
diff --git a/sc/inc/editutil.hxx b/sc/inc/editutil.hxx
index d760faf5c53e..4efadface0f4 100644
--- a/sc/inc/editutil.hxx
+++ b/sc/inc/editutil.hxx
@@ -84,6 +84,10 @@ public:
const Fraction& rX, const Fraction& rY, bool bPrintTwips = false );
tools::Rectangle GetEditArea( const ScPatternAttr* pPattern, bool bForceToTop );
+ tools::Long GetIndent(const ScPatternAttr* pPattern) const;
+ void GetMargins(const ScPatternAttr* pPattern, tools::Long& nLeftMargin, tools::Long& nTopMargin,
+ tools::Long& nRightMargin, tools::Long& BottomMargin) const;
+
};
class ScEditAttrTester
diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx
index d415e0806511..be3f6a5e9d2e 100644
--- a/sc/source/core/tool/editutil.cxx
+++ b/sc/source/core/tool/editutil.cxx
@@ -282,6 +282,39 @@ OUString ScEditUtil::GetCellFieldValue(
return aRet;
}
+tools::Long ScEditUtil::GetIndent(const ScPatternAttr* pPattern) const
+{
+ if (!pPattern)
+ pPattern = pDoc->GetPattern( nCol, nRow, nTab );
+
+ if ( pPattern->GetItem(ATTR_HOR_JUSTIFY).GetValue() ==
+ SvxCellHorJustify::Left )
+ {
+ tools::Long nIndent = pPattern->GetItem(ATTR_INDENT).GetValue();
+ if (!bInPrintTwips)
+ nIndent = static_cast<tools::Long>(nIndent * nPPTX);
+ return nIndent;
+ }
+
+ return 0;
+}
+
+void ScEditUtil::GetMargins(const ScPatternAttr* pPattern, tools::Long& nLeftMargin, tools::Long& nTopMargin,
+ tools::Long& nRightMargin, tools::Long& nBottomMargin) const
+{
+ if (!pPattern)
+ pPattern = pDoc->GetPattern( nCol, nRow, nTab );
+
+ const SvxMarginItem* pMargin = &pPattern->GetItem(ATTR_MARGIN);
+ if (!pMargin)
+ return;
+
+ nLeftMargin = bInPrintTwips ? pMargin->GetLeftMargin() : static_cast<tools::Long>(pMargin->GetLeftMargin() * nPPTX);
+ nRightMargin = bInPrintTwips ? pMargin->GetRightMargin() : static_cast<tools::Long>(pMargin->GetRightMargin() * nPPTX);
+ nTopMargin = bInPrintTwips ? pMargin->GetTopMargin() : static_cast<tools::Long>(pMargin->GetTopMargin() * nPPTY);
+ nBottomMargin = bInPrintTwips ? pMargin->GetBottomMargin() : static_cast<tools::Long>(pMargin->GetBottomMargin() * nPPTY);
+}
+
tools::Rectangle ScEditUtil::GetEditArea( const ScPatternAttr* pPattern, bool bForceToTop )
{
// bForceToTop = always align to top, for editing
@@ -320,24 +353,36 @@ tools::Rectangle ScEditUtil::GetEditArea( const ScPatternAttr* pPattern, bool bF
nCellY += static_cast<tools::Long>(pDoc->GetScaledRowHeight( nRow+1, nRow+nCountY-1, nTab, nPPTY));
}
- const SvxMarginItem* pMargin = &pPattern->GetItem(ATTR_MARGIN);
- sal_uInt16 nIndent = 0;
- if ( pPattern->GetItem(ATTR_HOR_JUSTIFY).GetValue() ==
- SvxCellHorJustify::Left )
- nIndent = pPattern->GetItem(ATTR_INDENT).GetValue();
- tools::Long nDifX = pMargin->GetLeftMargin() + nIndent;
- if (!bInPrintTwips)
- nDifX = static_cast<tools::Long>( nDifX * nPPTX );
+ tools::Long nRightMargin = 0;
+ tools::Long nTopMargin = 0;
+ tools::Long nBottomMargin = 0;
+ tools::Long nDifX = 0;
+ {
+ tools::Long nLeftMargin = 0;
+ bool bInPrintTwipsOrig = bInPrintTwips;
+ bInPrintTwips = true;
+ tools::Long nIndent = GetIndent(pPattern);
+ GetMargins(pPattern, nLeftMargin, nTopMargin, nRightMargin, nBottomMargin);
+ bInPrintTwips = bInPrintTwipsOrig;
+ // Here rounding may be done only on the sum, ie nDifX,
+ // so need to get margin and indent in twips.
+ nDifX = nLeftMargin + nIndent;
+ if (!bInPrintTwips)
+ {
+ nDifX = static_cast<tools::Long>(nDifX * nPPTX);
+ nRightMargin = static_cast<tools::Long>(nRightMargin * nPPTX);
+ nTopMargin = static_cast<tools::Long>(nTopMargin * nPPTY);
+ nBottomMargin = static_cast<tools::Long>(nBottomMargin * nPPTY);
+ }
+ }
+
+
aStartPos.AdjustX(nDifX * nLayoutSign );
- nCellX -= nDifX + (bInPrintTwips ? pMargin->GetRightMargin() :
- static_cast<tools::Long>( pMargin->GetRightMargin() * nPPTX )); // due to line feed, etc.
+ nCellX -= nDifX + nRightMargin; // due to line feed, etc.
// align vertical position to the one in the table
tools::Long nDifY;
- tools::Long nTopMargin = pMargin->GetTopMargin();
- if (!bInPrintTwips)
- nTopMargin = static_cast<tools::Long>( nTopMargin * nPPTY );
SvxCellVerJustify eJust = pPattern->GetItem(ATTR_VER_JUSTIFY).GetValue();
// asian vertical is always edited top-aligned
@@ -361,9 +406,7 @@ tools::Rectangle ScEditUtil::GetEditArea( const ScPatternAttr* pPattern, bool bF
// font color doesn't matter here
pPattern->GetFont( aFont, SC_AUTOCOL_BLACK, pDev, &aZoomY );
pDev->SetFont(aFont);
- nTextHeight = pDev->GetTextHeight() + nTopMargin +
- (bInPrintTwips ? pMargin->GetBottomMargin() :
- static_cast<tools::Long>( pMargin->GetBottomMargin() * nPPTY ));
+ nTextHeight = pDev->GetTextHeight() + nTopMargin + nBottomMargin;
}
pDev->SetMapMode(aMode);
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index c5230e949fea..c95bc00f701a 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -274,6 +274,25 @@ static void lcl_DrawHighlight( ScOutputData& rOutputData, const ScViewData& rVie
}
}
+// Calculates top-left offset to be applied based on margins and indent.
+static void lcl_GetEditAreaTLOffset(tools::Long& nOffsetX, tools::Long& nOffsetY, const ScAddress& rAddr,
+ const ScViewData& rViewData, ScDocument& rDoc)
+{
+ tools::Long nLeftMargin = 0;
+ tools::Long nTopMargin = 0;
+ tools::Long nIndent = 0;
+ tools::Long nDummy = 0;
+ ScEditUtil aEUtil(&rDoc, rAddr.Col(), rAddr.Row(), rAddr.Tab(),
+ Point(0, 0), nullptr, rViewData.GetPPTX(),
+ rViewData.GetPPTY(), Fraction(1.0), Fraction(1.0),
+ false /* bPrintTwips */);
+ const ScPatternAttr* pPattern = rDoc.GetPattern(rAddr);
+ nIndent = aEUtil.GetIndent(pPattern);
+ aEUtil.GetMargins(pPattern, nLeftMargin, nTopMargin, nDummy, nDummy);
+ nOffsetX = nIndent + nLeftMargin;
+ nOffsetY = nTopMargin;
+}
+
void ScGridWindow::DoInvertRect( const tools::Rectangle& rPixel )
{
if ( rPixel == aInvertRect )
@@ -1051,8 +1070,11 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& rTableI
rDevice.DrawRect(rDevice.PixelToLogic(aBackground));
tools::Rectangle aEditRect(aBackground);
- aEditRect.AdjustLeft(1);
- aEditRect.AdjustTop(1);
+ tools::Long nOffsetX = 0, nOffsetY = 0;
+ // Get top-left offset because of margin and indent.
+ lcl_GetEditAreaTLOffset(nOffsetX, nOffsetY, ScAddress(nCol1, nRow1, nTab), mrViewData, rDoc);
+ aEditRect.AdjustLeft(nOffsetX + 1);
+ aEditRect.AdjustTop(nOffsetY + 1);
// EditView has an 'output area' which is used to clip the 'paint area' we provide below.
// So they need to be in the same coordinates/units. This is tied to the mapmode of the gridwin
@@ -1148,8 +1170,12 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& rTableI
if (bIsTiledRendering)
{
tools::Rectangle aEditRect(aBackground);
- aEditRect.AdjustLeft(1);
- aEditRect.AdjustTop(1);
+ tools::Long nOffsetX = 0, nOffsetY = 0;
+ // Get top-left offset because of margin and indent.
+ lcl_GetEditAreaTLOffset(nOffsetX, nOffsetY, ScAddress(nCol1, nRow1, mrViewData.GetTabNo()), mrViewData, rDoc);
+ aEditRect.AdjustLeft(nOffsetX + 1);
+ aEditRect.AdjustTop(nOffsetY + 1);
+
// EditView has an 'output area' which is used to clip the paint area we provide below.
// So they need to be in the same coordinates/units. This is tied to the mapmode of the gridwin
// attached to the EditView, so we have to change its mapmode too (temporarily). We save the
More information about the Libreoffice-commits
mailing list