Kaydet (Commit) 6bb268db authored tarafından Miklos Vajna's avatar Miklos Vajna

lok: add Document::getPartPageRectangles()

Change-Id: I20acd44f7a81471982ba96ad3894a9124e035c5f
(cherry picked from commit d355207b)
üst ecfca0c7
...@@ -52,12 +52,14 @@ public: ...@@ -52,12 +52,14 @@ public:
void testGetFonts(); void testGetFonts();
void testCreateView(); void testCreateView();
void testGetFilterTypes(); void testGetFilterTypes();
void testGetPartPageRectangles();
CPPUNIT_TEST_SUITE(DesktopLOKTest); CPPUNIT_TEST_SUITE(DesktopLOKTest);
CPPUNIT_TEST(testGetStyles); CPPUNIT_TEST(testGetStyles);
CPPUNIT_TEST(testGetFonts); CPPUNIT_TEST(testGetFonts);
CPPUNIT_TEST(testCreateView); CPPUNIT_TEST(testCreateView);
CPPUNIT_TEST(testGetFilterTypes); CPPUNIT_TEST(testGetFilterTypes);
CPPUNIT_TEST(testGetPartPageRectangles);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
uno::Reference<lang::XComponent> mxComponent; uno::Reference<lang::XComponent> mxComponent;
...@@ -152,6 +154,29 @@ void DesktopLOKTest::testCreateView() ...@@ -152,6 +154,29 @@ void DesktopLOKTest::testCreateView()
closeDoc(); 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<OUString> 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<size_t>(1), aRectangles.size());
free(pRectangles);
closeDoc();
}
void DesktopLOKTest::testGetFilterTypes() void DesktopLOKTest::testGetFilterTypes()
{ {
LibLibreOffice_Impl aOffice; LibLibreOffice_Impl aOffice;
......
...@@ -207,6 +207,7 @@ static void doc_destroy(LibreOfficeKitDocument* pThis); ...@@ -207,6 +207,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_saveAs(LibreOfficeKitDocument* pThis, const char* pUrl, const char* pFormat, const char* pFilterOptions);
static int doc_getDocumentType(LibreOfficeKitDocument* pThis); static int doc_getDocumentType(LibreOfficeKitDocument* pThis);
static int doc_getParts(LibreOfficeKitDocument* pThis); static int doc_getParts(LibreOfficeKitDocument* pThis);
static char* doc_getPartPageRectangles(LibreOfficeKitDocument* pThis);
static int doc_getPart(LibreOfficeKitDocument* pThis); static int doc_getPart(LibreOfficeKitDocument* pThis);
static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart); static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart);
static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart); static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart);
...@@ -269,6 +270,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone ...@@ -269,6 +270,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
m_pDocumentClass->saveAs = doc_saveAs; m_pDocumentClass->saveAs = doc_saveAs;
m_pDocumentClass->getDocumentType = doc_getDocumentType; m_pDocumentClass->getDocumentType = doc_getDocumentType;
m_pDocumentClass->getParts = doc_getParts; m_pDocumentClass->getParts = doc_getParts;
m_pDocumentClass->getPartPageRectangles = doc_getPartPageRectangles;
m_pDocumentClass->getPart = doc_getPart; m_pDocumentClass->getPart = doc_getPart;
m_pDocumentClass->setPart = doc_setPart; m_pDocumentClass->setPart = doc_setPart;
m_pDocumentClass->getPartName = doc_getPartName; m_pDocumentClass->getPartName = doc_getPartName;
...@@ -661,6 +663,23 @@ static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart) ...@@ -661,6 +663,23 @@ static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart)
pDoc->setPart( 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<char*>(malloc(aString.getLength() + 1));
strcpy(pMemory, aString.getStr());
return pMemory;
}
static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart) static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart)
{ {
ITiledRenderable* pDoc = getTiledRenderable(pThis); ITiledRenderable* pDoc = getTiledRenderable(pThis);
......
...@@ -85,6 +85,9 @@ struct _LibreOfficeKitDocumentClass ...@@ -85,6 +85,9 @@ struct _LibreOfficeKitDocumentClass
/// @see lok::Document::getParts(). /// @see lok::Document::getParts().
int (*getParts) (LibreOfficeKitDocument* pThis); int (*getParts) (LibreOfficeKitDocument* pThis);
/// @see lok::Document::getPartPageRectangles().
char* (*getPartPageRectangles) (LibreOfficeKitDocument* pThis);
/// @see lok::Document::getPart(). /// @see lok::Document::getPart().
int (*getPart) (LibreOfficeKitDocument* pThis); int (*getPart) (LibreOfficeKitDocument* pThis);
......
...@@ -76,6 +76,20 @@ public: ...@@ -76,6 +76,20 @@ public:
return mpDoc->pClass->getParts(mpDoc); 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. /// Get the current part of the document.
inline int getPart() inline int getPart()
{ {
......
...@@ -139,6 +139,14 @@ public: ...@@ -139,6 +139,14 @@ public:
* @see lok::Document::resetSelection(). * @see lok::Document::resetSelection().
*/ */
virtual void resetSelection() = 0; virtual void resetSelection() = 0;
/**
* @see lok::Document::getPartPageRectangles().
*/
virtual OUString getPartPageRectangles()
{
return OUString();
}
}; };
} // namespace vcl } // namespace vcl
......
...@@ -854,6 +854,8 @@ public: ...@@ -854,6 +854,8 @@ public:
OUString GetCrsrDescr() const; OUString GetCrsrDescr() const;
virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const SAL_OVERRIDE; virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const SAL_OVERRIDE;
/// Implementation of lok::Document::getPartPageRectangles() for Writer.
OUString getPageRectangles();
}; };
// Cursor Inlines: // Cursor Inlines:
......
...@@ -431,6 +431,8 @@ public: ...@@ -431,6 +431,8 @@ public:
virtual void setGraphicSelection(int nType, int nX, int nY) SAL_OVERRIDE; virtual void setGraphicSelection(int nType, int nX, int nY) SAL_OVERRIDE;
/// @see vcl::ITiledRenderable::resetSelection(). /// @see vcl::ITiledRenderable::resetSelection().
virtual void resetSelection() SAL_OVERRIDE; virtual void resetSelection() SAL_OVERRIDE;
/// @see vcl::ITiledRenderable::getPartPageRectangles().
virtual OUString getPartPageRectangles() SAL_OVERRIDE;
// ::com::sun::star::tiledrendering::XTiledRenderable // ::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; 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;
......
...@@ -1201,6 +1201,20 @@ sal_uInt16 SwCrsrShell::GetPageCnt() ...@@ -1201,6 +1201,20 @@ sal_uInt16 SwCrsrShell::GetPageCnt()
return GetLayout()->GetPageNum(); 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 /// go to the next SSelection
bool SwCrsrShell::GoNextCrsr() bool SwCrsrShell::GoNextCrsr()
{ {
......
...@@ -3177,6 +3177,17 @@ int SwXTextDocument::getParts() ...@@ -3177,6 +3177,17 @@ int SwXTextDocument::getParts()
return pWrtShell->GetPageCnt(); return pWrtShell->GetPageCnt();
} }
OUString SwXTextDocument::getPartPageRectangles()
{
SolarMutexGuard aGuard;
SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
if (!pWrtShell)
return OUString();
return pWrtShell->getPageRectangles();
}
int SwXTextDocument::getPart() int SwXTextDocument::getPart()
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment