[Libreoffice-commits] core.git: sc/source

Dennis Francis (via logerrit) logerrit at kemper.freedesktop.org
Sun Jul 5 07:38:14 UTC 2020


 sc/source/ui/inc/viewdata.hxx  |    6 ++
 sc/source/ui/view/viewdata.cxx |   89 +++++++++++++++++++++++++++++++----------
 2 files changed, 74 insertions(+), 21 deletions(-)

New commits:
commit a94216649b629dc466a2fb0aafc37bd612cf975d
Author:     Dennis Francis <dennis.francis at collabora.com>
AuthorDate: Sat May 23 12:22:56 2020 +0530
Commit:     Dennis Francis <dennis.francis at collabora.com>
CommitDate: Sun Jul 5 09:37:33 2020 +0200

    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 at gmail.com>
    Reviewed-by: Dennis Francis <dennis.francis at collabora.com>
    (cherry picked from commit 0722934920d7b743d82e55c793d4abbf6c9bc11d)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97990
    Tested-by: Jenkins

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 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 )


More information about the Libreoffice-commits mailing list