desktop/qa/desktop_lib/test_desktop_lib.cxx |    3 ++-
 desktop/source/lib/init.cxx                 |   28 ++++++++++++++++++++++++++++
 include/LibreOfficeKit/LibreOfficeKit.h     |    6 ++++++
 include/LibreOfficeKit/LibreOfficeKit.hxx   |    6 ++++++
 include/vcl/ITiledRenderable.hxx            |    8 ++++++++
 sc/inc/docuno.hxx                           |    3 +++
 sc/source/ui/unoobj/docuno.cxx              |   22 ++++++++++++++++++++++
 7 files changed, 75 insertions(+), 1 deletion(-)

New commits:
commit ff9b9944401a594ec4a67bca953b312f3a54e3f8
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Fri Sep 2 11:35:42 2022 +0200
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Thu Nov 10 10:16:52 2022 +0100

    lok: Introudce getDataArea for Calc
    
    It will share information about real size of a data inside
    spreadsheet so we can easily check where data ends in online
    side.
    
    Change-Id: I376187a33c5c82d409f559d5cc826a4f36d4252e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139472
    Reviewed-by: Gökay ŞATIR <gokaysa...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142503
    Tested-by: Jenkins
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx 
b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index d7089d9243f0..dd84323f6c9b 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -3623,10 +3623,11 @@ void DesktopLOKTest::testABI()
     CPPUNIT_ASSERT_EQUAL(documentClassOffset(64),
                          offsetof(struct _LibreOfficeKitDocumentClass, 
sendContentControlEvent));
     CPPUNIT_ASSERT_EQUAL(documentClassOffset(65), offsetof(struct 
_LibreOfficeKitDocumentClass, getSelectionTypeAndText));
+    CPPUNIT_ASSERT_EQUAL(documentClassOffset(66), offsetof(struct 
_LibreOfficeKitDocumentClass, getDataArea));
 
     // Extending is fine, update this, and add new assert for the offsetof the
     // new method
-    CPPUNIT_ASSERT_EQUAL(documentClassOffset(66), sizeof(struct 
_LibreOfficeKitDocumentClass));
+    CPPUNIT_ASSERT_EQUAL(documentClassOffset(67), sizeof(struct 
_LibreOfficeKitDocumentClass));
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index d4332d5c2926..f4aeaf2760cf 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1020,6 +1020,10 @@ static int doc_getTileMode(LibreOfficeKitDocument* 
pThis);
 static void doc_getDocumentSize(LibreOfficeKitDocument* pThis,
                                 long* pWidth,
                                 long* pHeight);
+static void doc_getDataArea(LibreOfficeKitDocument* pThis,
+                            long nTab,
+                            long* pCol,
+                            long* pRow);
 static void doc_initializeForRendering(LibreOfficeKitDocument* pThis,
                                        const char* pArguments);
 
@@ -1272,6 +1276,7 @@ LibLODocument_Impl::LibLODocument_Impl(uno::Reference 
<css::lang::XComponent> xC
         m_pDocumentClass->paintPartTile = doc_paintPartTile;
         m_pDocumentClass->getTileMode = doc_getTileMode;
         m_pDocumentClass->getDocumentSize = doc_getDocumentSize;
+        m_pDocumentClass->getDataArea = doc_getDataArea;
         m_pDocumentClass->initializeForRendering = doc_initializeForRendering;
         m_pDocumentClass->registerCallback = doc_registerCallback;
         m_pDocumentClass->postKeyEvent = doc_postKeyEvent;
@@ -3919,6 +3924,29 @@ static void doc_getDocumentSize(LibreOfficeKitDocument* 
pThis,
     }
 }
 
+static void doc_getDataArea(LibreOfficeKitDocument* pThis,
+                            long nTab,
+                            long* pCol,
+                            long* pRow)
+{
+    comphelper::ProfileZone aZone("doc_getDataArea");
+
+    SolarMutexGuard aGuard;
+    SetLastExceptionMsg();
+
+    ITiledRenderable* pDoc = getTiledRenderable(pThis);
+    if (pDoc)
+    {
+        Size aDocumentSize = pDoc->getDataArea(nTab);
+        *pCol = aDocumentSize.Width();
+        *pRow = aDocumentSize.Height();
+    }
+    else
+    {
+        SetLastExceptionMsg("Document doesn't support tiled rendering");
+    }
+}
+
 static void doc_initializeForRendering(LibreOfficeKitDocument* pThis,
                                        const char* pArguments)
 {
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h 
b/include/LibreOfficeKit/LibreOfficeKit.h
index 3a706ba47091..2f57f744e1d4 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -483,6 +483,12 @@ struct _LibreOfficeKitDocumentClass
                                     char** pText,
                                     char** pUsedMimeType);
 
+    /// @see lok::Document::getDataArea().
+    void (*getDataArea) (LibreOfficeKitDocument* pThis,
+                         long nPart,
+                         long* pCol,
+                         long* pRow);
+
 #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
 };
 
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx 
b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 5caa0a0503e0..1adab0d4f066 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -208,6 +208,12 @@ public:
         mpDoc->pClass->getDocumentSize(mpDoc, pWidth, pHeight);
     }
 
+    /// Get the data area (in Calc last row and column).
+    void getDataArea(long nPart, long* pCol, long* pRow)
+    {
+        mpDoc->pClass->getDataArea(mpDoc, nPart, pCol, pRow);
+    }
+
     /**
      * Initialize document for rendering.
      *
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index f06193172702..3bf7bcdddacb 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -69,6 +69,14 @@ public:
      */
     virtual Size getDocumentSize() = 0;
 
+    /**
+     * Get the data area size (in Calc last column and row).
+     */
+    virtual Size getDataArea(long /*nPart*/)
+    {
+        return Size(1, 1);
+    }
+
     /**
      * Set the document "part", i.e. slide for a slideshow, and
      * tab for a spreadsheet.
diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx
index cb1fd2049bb5..837f93ec3558 100644
--- a/sc/inc/docuno.hxx
+++ b/sc/inc/docuno.hxx
@@ -310,6 +310,9 @@ public:
     /// @see vcl::ITiledRenderable::getDocumentSize().
     virtual Size getDocumentSize() override;
 
+    /// @see vcl::ITiledRenderable::getDataArea().
+    virtual Size getDataArea(long nPart) override;
+
     /// @see vcl::ITiledRenderable::setPart().
     virtual void setPart(int nPart, bool bAllowChangeFocus = true) override;
 
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 802d8ad3cd3c..614eed94d891 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -694,6 +694,28 @@ Size ScModelObj::getDocumentSize()
     return aSize;
 }
 
+Size ScModelObj::getDataArea(long nPart)
+{
+    Size aSize(1, 1);
+
+    ScViewData* pViewData = ScDocShell::GetViewData();
+    if (!pViewData || !pDocShell)
+        return aSize;
+
+    SCTAB nTab = nPart;
+    SCCOL nEndCol = 0;
+    SCROW nEndRow = 0;
+    const ScDocument& rDoc = pDocShell->GetDocument();
+
+    const ScTable* pTab = rDoc.FetchTable(nTab);
+    if (!pTab)
+        return aSize;
+
+    pTab->GetCellArea(nEndCol, nEndRow);
+    aSize = Size(nEndCol, nEndRow);
+
+    return aSize;
+}
 
 void ScModelObj::postKeyEvent(int nType, int nCharCode, int nKeyCode)
 {

Reply via email to