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-04 19:19:52 +0200 |
commit | 0722934920d7b743d82e55c793d4abbf6c9bc11d (patch) | |
tree | 680785f16fb35f051e0bdc9501a0c26e555c058a /sc/source/ui | |
parent | 3c6c039685870ed23d2f25cbfd984d3b54c4b60d (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>
Diffstat (limited to 'sc/source/ui')
-rw-r--r-- | sc/source/ui/inc/viewdata.hxx | 6 | ||||
-rw-r--r-- | sc/source/ui/view/viewdata.cxx | 89 |
2 files changed, 74 insertions, 21 deletions
diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx index e5833dec5d32..45aacdee6bd1 100644 --- a/sc/source/ui/inc/viewdata.hxx +++ b/sc/source/ui/inc/viewdata.hxx @@ -503,6 +503,7 @@ public: // TRUE: Cell is merged bool GetMergeSizePixel( SCCOL nX, SCROW nY, long& rSizeXPix, long& rSizeYPix ) const; + bool GetMergeSizePrintTwips( SCCOL nX, SCROW nY, long& rSizeXTwips, long& rSizeYTwips ) const; void GetPosFromPixel( long nClickX, long nClickY, ScSplitPos eWhich, SCCOL& rPosX, SCROW& rPosY, bool bTestMerge = true, bool bRepair = false ); @@ -603,10 +604,13 @@ public: bool bAllowNeg = false ) const; Point GetScrPos( SCCOL nWhereX, SCROW nWhereY, ScHSplitPos eWhich ) const; Point GetScrPos( SCCOL nWhereX, SCROW nWhereY, ScVSplitPos eWhich ) const; + /// returns the position (top-left corner) of the requested cell in print twips coordinates. + Point GetPrintTwipsPos( SCCOL nCol, SCROW nRow ) const; /// return json for our cursor position. OString describeCellCursor() const { return describeCellCursorAt(GetCurX(), GetCurY()); } - OString describeCellCursorAt( SCCOL nCol, SCROW nRow ) const; + OString describeCellCursorInPrintTwips() const { return describeCellCursorAt(GetCurX(), GetCurY(), false); } + OString describeCellCursorAt( SCCOL nCol, SCROW nRow, bool bPixelAligned = true ) const; SCCOL CellsAtX( SCCOL nPosX, SCCOL nDir, ScHSplitPos eWhichX, sal_uInt16 nScrSizeY = SC_SIZE_NONE ) const; SCROW CellsAtY( SCROW nPosY, SCROW nDir, ScVSplitPos eWhichY, sal_uInt16 nScrSizeX = SC_SIZE_NONE ) const; diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx index 6849c11e314a..5b5b4baf3b83 100644 --- a/sc/source/ui/view/viewdata.cxx +++ b/sc/source/ui/view/viewdata.cxx @@ -2208,33 +2208,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(); } @@ -2375,6 +2408,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 ) |