[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - sc/inc sc/source
Dennis Francis (via logerrit)
logerrit at kemper.freedesktop.org
Wed Feb 3 12:32:39 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 bc025dac6ce3301f5798e8ada4fee07b415de76a
Author: Dennis Francis <dennis.francis at collabora.com>
AuthorDate: Tue Jan 19 14:46:48 2021 +0530
Commit: Tor Lillqvist <tml at collabora.com>
CommitDate: Wed Feb 3 13:32:01 2021 +0100
lok: Take indent and margins into account
... when painting tiles with edit-text content.
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>
diff --git a/sc/inc/editutil.hxx b/sc/inc/editutil.hxx
index 6cfb2f3cae8a..72532fae5d1a 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 );
+ long GetIndent(const ScPatternAttr* pPattern) const;
+ void GetMargins(const ScPatternAttr* pPattern, long& nLeftMargin, long& nTopMargin,
+ long& nRightMargin, long& BottomMargin) const;
+
};
class ScEditAttrTester
diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx
index 6cf6a1d4dcfa..aa642fcb56eb 100644
--- a/sc/source/core/tool/editutil.cxx
+++ b/sc/source/core/tool/editutil.cxx
@@ -282,6 +282,39 @@ OUString ScEditUtil::GetCellFieldValue(
return aRet;
}
+long ScEditUtil::GetIndent(const ScPatternAttr* pPattern) const
+{
+ if (!pPattern)
+ pPattern = pDoc->GetPattern( nCol, nRow, nTab );
+
+ if ( pPattern->GetItem(ATTR_HOR_JUSTIFY).GetValue() ==
+ SvxCellHorJustify::Left )
+ {
+ long nIndent = pPattern->GetItem(ATTR_INDENT).GetValue();
+ if (!bInPrintTwips)
+ nIndent = static_cast<long>(nIndent * nPPTX);
+ return nIndent;
+ }
+
+ return 0;
+}
+
+void ScEditUtil::GetMargins(const ScPatternAttr* pPattern, long& nLeftMargin, long& nTopMargin,
+ long& nRightMargin, 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<long>(pMargin->GetLeftMargin() * nPPTX);
+ nRightMargin = bInPrintTwips ? pMargin->GetRightMargin() : static_cast<long>(pMargin->GetRightMargin() * nPPTX);
+ nTopMargin = bInPrintTwips ? pMargin->GetTopMargin() : static_cast<long>(pMargin->GetTopMargin() * nPPTY);
+ nBottomMargin = bInPrintTwips ? pMargin->GetBottomMargin() : static_cast<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<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();
- long nDifX = pMargin->GetLeftMargin() + nIndent;
- if (!bInPrintTwips)
- nDifX = static_cast<long>( nDifX * nPPTX );
+ long nRightMargin = 0;
+ long nTopMargin = 0;
+ long nBottomMargin = 0;
+ long nDifX = 0;
+ {
+ long nLeftMargin = 0;
+ bool bInPrintTwipsOrig = bInPrintTwips;
+ bInPrintTwips = true;
+ 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<long>(nDifX * nPPTX);
+ nRightMargin = static_cast<long>(nRightMargin * nPPTX);
+ nTopMargin = static_cast<long>(nTopMargin * nPPTY);
+ nBottomMargin = static_cast<long>(nBottomMargin * nPPTY);
+ }
+ }
+
+
aStartPos.AdjustX(nDifX * nLayoutSign );
- nCellX -= nDifX + (bInPrintTwips ? pMargin->GetRightMargin() :
- static_cast<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
long nDifY;
- long nTopMargin = pMargin->GetTopMargin();
- if (!bInPrintTwips)
- nTopMargin = static_cast<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<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 1d5d0f5d9936..7fa1b6c0001c 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -276,6 +276,25 @@ static void lcl_DrawHighlight( ScOutputData& rOutputData, const ScViewData* pVie
}
}
+// Calculates top-left offset to be applied based on margins and indent.
+static void lcl_GetEditAreaTLOffset(long& nOffsetX, long& nOffsetY, const ScAddress& rAddr,
+ const ScViewData* pViewData, ScDocument& rDoc)
+{
+ long nLeftMargin = 0;
+ long nTopMargin = 0;
+ long nIndent = 0;
+ long nDummy = 0;
+ ScEditUtil aEUtil(&rDoc, rAddr.Col(), rAddr.Row(), rAddr.Tab(),
+ Point(0, 0), nullptr, pViewData->GetPPTX(),
+ pViewData->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 )
@@ -1039,8 +1058,11 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& rTableI
rDevice.DrawRect(rDevice.PixelToLogic(aBackground));
tools::Rectangle aEditRect(aBackground);
- aEditRect.AdjustLeft(1);
- aEditRect.AdjustTop(1);
+ long nOffsetX = 0, nOffsetY = 0;
+ // Get top-left offset because of margin and indent.
+ lcl_GetEditAreaTLOffset(nOffsetX, nOffsetY, ScAddress(nCol1, nRow1, pViewData->GetTabNo()), pViewData, 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
@@ -1144,8 +1166,12 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& rTableI
if (bIsTiledRendering)
{
tools::Rectangle aEditRect(aBackground);
- aEditRect.AdjustLeft(1);
- aEditRect.AdjustTop(1);
+ long nOffsetX = 0, nOffsetY = 0;
+ // Get top-left offset because of margin and indent.
+ lcl_GetEditAreaTLOffset(nOffsetX, nOffsetY, ScAddress(nCol1, nRow1, pViewData->GetTabNo()), pViewData, 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