diff options
author | Dennis Francis <dennis.francis@collabora.com> | 2020-05-23 12:22:56 +0530 |
---|---|---|
committer | Dennis Francis <dennis.francis@collabora.com> | 2020-07-05 09:37:33 +0200 |
commit | a94216649b629dc466a2fb0aafc37bd612cf975d (patch) | |
tree | a6afb5a20c770b5006ca5b78109abded99bdcc8b /sc/source/ui/view/viewdata.cxx | |
parent | 6420c1edbf5b41c4ad0063e98e2040f2d74cf034 (diff) |
Allow cell coordinates calculation in print twips too
Change-Id: Ie8f23bd7ba8de57d7aab104add99501a54f08819
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97961
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Dennis Francis <dennis.francis@collabora.com>
(cherry picked from commit 0722934920d7b743d82e55c793d4abbf6c9bc11d)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97990
Tested-by: Jenkins
Diffstat (limited to 'sc/source/ui/view/viewdata.cxx')
-rw-r--r-- | sc/source/ui/view/viewdata.cxx | 89 |
1 files changed, 69 insertions, 20 deletions
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx index 51339744bc98..16cf6aa21357 100644 --- a/sc/source/ui/view/viewdata.cxx +++ b/sc/source/ui/view/viewdata.cxx @@ -2210,33 +2210,66 @@ Point ScViewData::GetScrPos( SCCOL nWhereX, SCROW nWhereY, ScSplitPos eWhich, return Point( nScrPosX, nScrPosY ); } -OString ScViewData::describeCellCursorAt(SCCOL nX, SCROW nY) const +Point ScViewData::GetPrintTwipsPos(SCCOL nCol, SCROW nRow) const { - Point aScrPos = GetScrPos( nX, nY, SC_SPLIT_BOTTOMRIGHT, true ); + // hidden ones are given 0 sizes by these by default. + // TODO: rewrite this to loop over spans (matters for jumbosheets). + long nPosX = nCol ? pDoc->GetColWidth(0, nCol - 1, nTabNo) : 0; + // This is now fast as it loops over spans. + long nPosY = nRow ? pDoc->GetRowHeight(0, nRow - 1, nTabNo) : 0; + // TODO: adjust for RTL layout case. - long nSizeXPix; - long nSizeYPix; - GetMergeSizePixel( nX, nY, nSizeXPix, nSizeYPix ); + return Point(nPosX, nPosY); +} + +OString ScViewData::describeCellCursorAt(SCCOL nX, SCROW nY, bool bPixelAligned) const +{ + const bool bPosSizeInPixels = bPixelAligned; + Point aCellPos = bPosSizeInPixels ? GetScrPos( nX, nY, SC_SPLIT_BOTTOMRIGHT, true ) : + GetPrintTwipsPos(nX, nY); + + long nSizeX; + long nSizeY; + if (bPosSizeInPixels) + GetMergeSizePixel( nX, nY, nSizeX, nSizeY ); + else + GetMergeSizePrintTwips(nX, nY, nSizeX, nSizeY); - double fPPTX = GetPPTX(); - double fPPTY = GetPPTY(); + std::stringstream ss; + if (bPosSizeInPixels) + { + double fPPTX = GetPPTX(); + double fPPTY = GetPPTY(); - // make it a slim cell cursor, but not empty - if (nSizeXPix == 0) - nSizeXPix = 1; + // make it a slim cell cursor, but not empty + if (nSizeX == 0) + nSizeX = 1; - if (nSizeYPix == 0) - nSizeYPix = 1; + if (nSizeY == 0) + nSizeY = 1; - long nPosXTw = rtl::math::round(aScrPos.getX() / fPPTX); - long nPosYTw = rtl::math::round(aScrPos.getY() / fPPTY); - // look at Rectangle( const Point& rLT, const Size& rSize ) for the '- 1' - long nSizeXTw = rtl::math::round(nSizeXPix / fPPTX) - 1; - long nSizeYTw = rtl::math::round(nSizeYPix / fPPTY) - 1; + long nPosXTw = rtl::math::round(aCellPos.getX() / fPPTX); + long nPosYTw = rtl::math::round(aCellPos.getY() / fPPTY); + // look at Rectangle( const Point& rLT, const Size& rSize ) for the '- 1' + long nSizeXTw = rtl::math::round(nSizeX / fPPTX) - 1; + long nSizeYTw = rtl::math::round(nSizeY / fPPTY) - 1; - std::stringstream ss; - ss << nPosXTw << ", " << nPosYTw << ", " << nSizeXTw << ", " << nSizeYTw << ", " - << nX << ", " << nY; + ss << nPosXTw << ", " << nPosYTw << ", " << nSizeXTw << ", " << nSizeYTw << ", " + << nX << ", " << nY; + } + else + { + // make it a slim cell cursor, but not empty + if (nSizeX == 0) + nSizeX = TWIPS_PER_PIXEL; + if (nSizeY == 0) + nSizeY = TWIPS_PER_PIXEL; + + ss << aCellPos.getX() << ", " << aCellPos.getY() + // look at Rectangle( const Point& rLT, const Size& rSize ) for the '- 1' + << ", " << nSizeX - 1 << ", " << nSizeY - 1 << ", " + << nX << ", " << nY; + } return ss.str().c_str(); } @@ -2377,6 +2410,22 @@ bool ScViewData::GetMergeSizePixel( SCCOL nX, SCROW nY, long& rSizeXPix, long& r } } +bool ScViewData::GetMergeSizePrintTwips(SCCOL nX, SCROW nY, long& rSizeXTwips, long& rSizeYTwips) const +{ + const ScMergeAttr* pMerge = pDoc->GetAttr(nX, nY, nTabNo, ATTR_MERGE); + SCCOL nCountX = pMerge->GetColMerge(); + if (!nCountX) + nCountX = 1; + rSizeXTwips = pDoc->GetColWidth(nX, nX + nCountX - 1, nTabNo); + + SCROW nCountY = pMerge->GetRowMerge(); + if (!nCountY) + nCountY = 1; + rSizeYTwips = pDoc->GetRowHeight(nY, nY + nCountY - 1, nTabNo); + + return (nCountX > 1 || nCountY > 1); +} + void ScViewData::GetPosFromPixel( long nClickX, long nClickY, ScSplitPos eWhich, SCCOL& rPosX, SCROW& rPosY, bool bTestMerge, bool bRepair ) |