Blame SOURCES/0164-lok-add-Document-getPartPageRectangles.patch

135360
From ed4ab7cba0e5f7eaf18b4f10b731d52ae3b8f049 Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Tue, 29 Sep 2015 10:47:31 +0200
135360
Subject: [PATCH 164/398] lok: add Document::getPartPageRectangles()
135360
135360
(cherry picked from commit d355207b45755cfe1eef0147bc25ead931741684)
135360
135360
Change-Id: I20acd44f7a81471982ba96ad3894a9124e035c5f
135360
---
135360
 desktop/qa/desktop_lib/test_desktop_lib.cxx | 25 +++++++++++++++++++++++++
135360
 desktop/source/lib/init.cxx                 | 19 +++++++++++++++++++
135360
 include/LibreOfficeKit/LibreOfficeKit.h     |  3 +++
135360
 include/LibreOfficeKit/LibreOfficeKit.hxx   | 14 ++++++++++++++
135360
 include/vcl/ITiledRenderable.hxx            |  8 ++++++++
135360
 sw/inc/crsrsh.hxx                           |  3 +++
135360
 sw/inc/unotxdoc.hxx                         |  2 ++
135360
 sw/source/core/crsr/crsrsh.cxx              | 14 ++++++++++++++
135360
 sw/source/uibase/uno/unotxdoc.cxx           | 11 +++++++++++
135360
 9 files changed, 99 insertions(+)
135360
135360
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
index d7b93472c1b5..a7696d824bee 100644
135360
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
@@ -52,12 +52,14 @@ public:
135360
     void testGetFonts();
135360
     void testCreateView();
135360
     void testGetFilterTypes();
135360
+    void testGetPartPageRectangles();
135360
 
135360
     CPPUNIT_TEST_SUITE(DesktopLOKTest);
135360
     CPPUNIT_TEST(testGetStyles);
135360
     CPPUNIT_TEST(testGetFonts);
135360
     CPPUNIT_TEST(testCreateView);
135360
     CPPUNIT_TEST(testGetFilterTypes);
135360
+    CPPUNIT_TEST(testGetPartPageRectangles);
135360
     CPPUNIT_TEST_SUITE_END();
135360
 
135360
     uno::Reference<lang::XComponent> mxComponent;
135360
@@ -152,6 +154,29 @@ void DesktopLOKTest::testCreateView()
135360
     closeDoc();
135360
 }
135360
 
135360
+void DesktopLOKTest::testGetPartPageRectangles()
135360
+{
135360
+    // Test that we get as many page rectangles as expected: blank document is
135360
+    // one page.
135360
+    LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
135360
+    char* pRectangles = pDocument->pClass->getPartPageRectangles(pDocument);
135360
+    OUString sRectangles = OUString::fromUtf8(pRectangles);
135360
+
135360
+    std::vector<OUString> aRectangles;
135360
+    sal_Int32 nIndex = 0;
135360
+    do
135360
+    {
135360
+        OUString aRectangle = sRectangles.getToken(0, ';', nIndex);
135360
+        if (!aRectangle.isEmpty())
135360
+            aRectangles.push_back(aRectangle);
135360
+    }
135360
+    while (nIndex >= 0);
135360
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aRectangles.size());
135360
+
135360
+    free(pRectangles);
135360
+    closeDoc();
135360
+}
135360
+
135360
 void DesktopLOKTest::testGetFilterTypes()
135360
 {
135360
     LibLibreOffice_Impl aOffice;
135360
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
135360
index 5d716abdf8c4..4432ec8ea889 100644
135360
--- a/desktop/source/lib/init.cxx
135360
+++ b/desktop/source/lib/init.cxx
135360
@@ -203,6 +203,7 @@ static void doc_destroy(LibreOfficeKitDocument* pThis);
135360
 static int  doc_saveAs(LibreOfficeKitDocument* pThis, const char* pUrl, const char* pFormat, const char* pFilterOptions);
135360
 static int doc_getDocumentType(LibreOfficeKitDocument* pThis);
135360
 static int doc_getParts(LibreOfficeKitDocument* pThis);
135360
+static char* doc_getPartPageRectangles(LibreOfficeKitDocument* pThis);
135360
 static int doc_getPart(LibreOfficeKitDocument* pThis);
135360
 static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart);
135360
 static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart);
135360
@@ -265,6 +266,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference 
135360
         m_pDocumentClass->saveAs = doc_saveAs;
135360
         m_pDocumentClass->getDocumentType = doc_getDocumentType;
135360
         m_pDocumentClass->getParts = doc_getParts;
135360
+        m_pDocumentClass->getPartPageRectangles = doc_getPartPageRectangles;
135360
         m_pDocumentClass->getPart = doc_getPart;
135360
         m_pDocumentClass->setPart = doc_setPart;
135360
         m_pDocumentClass->getPartName = doc_getPartName;
135360
@@ -658,6 +660,23 @@ static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart)
135360
     pDoc->setPart( nPart );
135360
 }
135360
 
135360
+static char* doc_getPartPageRectangles(LibreOfficeKitDocument* pThis)
135360
+{
135360
+    ITiledRenderable* pDoc = getTiledRenderable(pThis);
135360
+    if (!pDoc)
135360
+    {
135360
+        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
135360
+        return 0;
135360
+    }
135360
+
135360
+    OUString sRectangles = pDoc->getPartPageRectangles();
135360
+    OString aString = OUStringToOString(sRectangles, RTL_TEXTENCODING_UTF8);
135360
+    char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
135360
+    strcpy(pMemory, aString.getStr());
135360
+    return pMemory;
135360
+
135360
+}
135360
+
135360
 static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart)
135360
 {
135360
     ITiledRenderable* pDoc = getTiledRenderable(pThis);
135360
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
135360
index d5094bdb1b76..d83dd49f32b5 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKit.h
135360
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
135360
@@ -85,6 +85,9 @@ struct _LibreOfficeKitDocumentClass
135360
     /// @see lok::Document::getParts().
135360
     int (*getParts) (LibreOfficeKitDocument* pThis);
135360
 
135360
+    /// @see lok::Document::getPartPageRectangles().
135360
+    char* (*getPartPageRectangles) (LibreOfficeKitDocument* pThis);
135360
+
135360
     /// @see lok::Document::getPart().
135360
     int (*getPart) (LibreOfficeKitDocument* pThis);
135360
 
135360
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
135360
index 207a9ce6e883..cd12ad64f245 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
135360
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
135360
@@ -76,6 +76,20 @@ public:
135360
         return mpDoc->pClass->getParts(mpDoc);
135360
     }
135360
 
135360
+    /**
135360
+     * Get the logical rectangle of each part in the document.
135360
+     *
135360
+     * A part refers to an individual page in Writer and has no relevant for
135360
+     * Calc or Impress.
135360
+     *
135360
+     * @return a rectangle list, using the same format as
135360
+     * LOK_CALLBACK_TEXT_SELECTION.
135360
+     */
135360
+    inline char* getPartPageRectangles()
135360
+    {
135360
+        return mpDoc->pClass->getPartPageRectangles(mpDoc);
135360
+    }
135360
+
135360
     /// Get the current part of the document.
135360
     inline int getPart()
135360
     {
135360
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
135360
index 6639745e4a2f..fd336f603296 100644
135360
--- a/include/vcl/ITiledRenderable.hxx
135360
+++ b/include/vcl/ITiledRenderable.hxx
135360
@@ -139,6 +139,14 @@ public:
135360
      * @see lok::Document::resetSelection().
135360
      */
135360
     virtual void resetSelection() = 0;
135360
+
135360
+    /**
135360
+     * @see lok::Document::getPartPageRectangles().
135360
+     */
135360
+    virtual OUString getPartPageRectangles()
135360
+    {
135360
+        return OUString();
135360
+    }
135360
 };
135360
 
135360
 } // namespace vcl
135360
diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx
135360
index 073a8dfb1d8d..ee849074cd7d 100644
135360
--- a/sw/inc/crsrsh.hxx
135360
+++ b/sw/inc/crsrsh.hxx
135360
@@ -852,6 +852,9 @@ public:
135360
        @return the textual description of the current selection
135360
      */
135360
     OUString GetCrsrDescr() const;
135360
+
135360
+    /// Implementation of lok::Document::getPartPageRectangles() for Writer.
135360
+    OUString getPageRectangles();
135360
 };
135360
 
135360
 // Cursor Inlines:
135360
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
135360
index 9f0b03b3af38..311147eeaaea 100644
135360
--- a/sw/inc/unotxdoc.hxx
135360
+++ b/sw/inc/unotxdoc.hxx
135360
@@ -431,6 +431,8 @@ public:
135360
     virtual void setGraphicSelection(int nType, int nX, int nY) SAL_OVERRIDE;
135360
     /// @see vcl::ITiledRenderable::resetSelection().
135360
     virtual void resetSelection() SAL_OVERRIDE;
135360
+    /// @see vcl::ITiledRenderable::getPartPageRectangles().
135360
+    virtual OUString getPartPageRectangles() SAL_OVERRIDE;
135360
 
135360
     // ::com::sun::star::tiledrendering::XTiledRenderable
135360
     virtual void SAL_CALL paintTile( const ::css::uno::Any& Parent, ::sal_Int32 nOutputWidth, ::sal_Int32 nOutputHeight, ::sal_Int32 nTilePosX, ::sal_Int32 nTilePosY, ::sal_Int32 nTileWidth, ::sal_Int32 nTileHeight ) throw (::css::uno::RuntimeException, ::std::exception) SAL_OVERRIDE;
135360
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
135360
index cbb89aca8868..ffff6a6b2a93 100644
135360
--- a/sw/source/core/crsr/crsrsh.cxx
135360
+++ b/sw/source/core/crsr/crsrsh.cxx
135360
@@ -1201,6 +1201,20 @@ sal_uInt16 SwCrsrShell::GetPageCnt()
135360
     return GetLayout()->GetPageNum();
135360
 }
135360
 
135360
+OUString SwCrsrShell::getPageRectangles()
135360
+{
135360
+    CurrShell aCurr(this);
135360
+    SwRootFrm* pLayout = GetLayout();
135360
+    std::stringstream ss;
135360
+    for (const SwFrm* pFrm = pLayout->GetLower(); pFrm; pFrm = pFrm->GetNext())
135360
+    {
135360
+        if (pFrm != pLayout->GetLower())
135360
+            ss << "; ";
135360
+        ss << pFrm->Frm().Left() << ", " << pFrm->Frm().Top() << ", " << pFrm->Frm().Width() << ", " << pFrm->Frm().Height();
135360
+    }
135360
+    return OUString::fromUtf8(ss.str().c_str());
135360
+}
135360
+
135360
 /// go to the next SSelection
135360
 bool SwCrsrShell::GoNextCrsr()
135360
 {
135360
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
135360
index d6315d2964ae..26ab19f170b9 100644
135360
--- a/sw/source/uibase/uno/unotxdoc.cxx
135360
+++ b/sw/source/uibase/uno/unotxdoc.cxx
135360
@@ -3177,6 +3177,17 @@ int SwXTextDocument::getParts()
135360
     return pWrtShell->GetPageCnt();
135360
 }
135360
 
135360
+OUString SwXTextDocument::getPartPageRectangles()
135360
+{
135360
+    SolarMutexGuard aGuard;
135360
+
135360
+    SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
135360
+    if (!pWrtShell)
135360
+        return OUString();
135360
+
135360
+    return pWrtShell->getPageRectangles();
135360
+}
135360
+
135360
 int SwXTextDocument::getPart()
135360
 {
135360
     SolarMutexGuard aGuard;
135360
-- 
135360
2.12.0
135360