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