summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorDennis Francis <dennis.francis@collabora.com>2020-05-23 12:22:56 +0530
committerDennis Francis <dennis.francis@collabora.com>2020-05-25 00:39:59 +0530
commit314294b923d55fb6b0b6e2755cf4b13657a04ba2 (patch)
treed5a02d40179e317531b098a4025ae45bddbfca80 /sc/source
parent5ce3e57ba43a45c31b4c8c210b95894fdcdfe42f (diff)
Allow cell coordinates calculation in print twips too
Change-Id: Ie8f23bd7ba8de57d7aab104add99501a54f08819
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/ui/inc/viewdata.hxx6
-rw-r--r--sc/source/ui/view/viewdata.cxx89
2 files changed, 74 insertions, 21 deletions
diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx
index 345f9d9ae00f..b893eb63dab0 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 0fddf7862b82..4079191db11d 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 )