summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--desktop/source/lib/init.cxx34
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.h3
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.hxx8
-rw-r--r--libreofficekit/qa/unit/tiledrendering.cxx35
4 files changed, 80 insertions, 0 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index abd8ca0b640b..51302d1f8466 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -35,11 +35,13 @@
#include <comphelper/processfactory.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/ucb/XContentProvider.hpp>
#include <com/sun/star/ucb/XUniversalContentBroker.hpp>
@@ -233,6 +235,7 @@ static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis,
int nX,
int nY);
static void doc_resetSelection (LibreOfficeKitDocument* pThis);
+static char* doc_getStyles(LibreOfficeKitDocument* pThis);
struct LibLODocument_Impl : public _LibreOfficeKitDocument
{
@@ -267,6 +270,7 @@ struct LibLODocument_Impl : public _LibreOfficeKitDocument
m_pDocumentClass->getTextSelection = doc_getTextSelection;
m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection;
m_pDocumentClass->resetSelection = doc_resetSelection;
+ m_pDocumentClass->getStyles = doc_getStyles;
gDocumentClass = m_pDocumentClass;
}
@@ -864,6 +868,36 @@ static void doc_resetSelection(LibreOfficeKitDocument* pThis)
pDoc->resetSelection();
}
+static char* doc_getStyles(LibreOfficeKitDocument* pThis)
+{
+ LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
+
+ boost::property_tree::ptree aTree;
+ uno::Reference<css::style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(pDocument->mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XNameAccess> xStyleFamilies(xStyleFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY);
+ uno::Sequence<OUString> aStyleFamilies = xStyleFamilies->getElementNames();
+
+ for (sal_Int32 nStyleFam = 0; nStyleFam < aStyleFamilies.getLength(); ++nStyleFam)
+ {
+ boost::property_tree::ptree aChildren;
+ OUString sStyleFam = aStyleFamilies[nStyleFam];
+ uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName(sStyleFam), uno::UNO_QUERY);
+ uno::Sequence<OUString> aStyles = xStyleFamily->getElementNames();
+ for (sal_Int32 nInd = 0; nInd < aStyles.getLength(); ++nInd)
+ {
+ boost::property_tree::ptree aChild;
+ aChild.put("", aStyles[nInd]);
+ aChildren.push_back(std::make_pair("", aChild));
+ }
+ aTree.add_child(sStyleFam.toUtf8().getStr(), aChildren);
+ }
+ std::stringstream aStream;
+ boost::property_tree::write_json(aStream, aTree);
+ char* pJson = static_cast<char*>(malloc(aStream.str().size() + 1));
+ strcpy(pJson, aStream.str().c_str());
+ pJson[aStream.str().size()] = '\0';
+ return pJson;
+}
static char* lo_getError (LibreOfficeKit *pThis)
{
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index e3b485052444..af7155c4db67 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -159,6 +159,9 @@ struct _LibreOfficeKitDocumentClass
/// @see lok::Document::resetSelection
void (*resetSelection) (LibreOfficeKitDocument* pThis);
+
+ /// @see lok::Document:getStyles
+ char* (*getStyles) (LibreOfficeKitDocument* pThis);
#endif // LOK_USE_UNSTABLE_API
};
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 816ade5649b2..c526bda95593 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -246,6 +246,14 @@ public:
{
mpDoc->pClass->resetSelection(mpDoc);
}
+
+ /**
+ * Returns a json map, {"familyName1" : ["list of style names in the family1"], etc.}
+ */
+ inline char* getStyles()
+ {
+ return mpDoc->pClass->getStyles(mpDoc);
+ }
#endif // LOK_USE_UNSTABLE_API
};
diff --git a/libreofficekit/qa/unit/tiledrendering.cxx b/libreofficekit/qa/unit/tiledrendering.cxx
index 0ebbc6a09a1e..a4e552507c39 100644
--- a/libreofficekit/qa/unit/tiledrendering.cxx
+++ b/libreofficekit/qa/unit/tiledrendering.cxx
@@ -9,6 +9,7 @@
#include <memory>
#include <boost/scoped_ptr.hpp>
+#include <boost/property_tree/json_parser.hpp>
#include <cppunit/TestFixture.h>
#include <cppunit/plugin/TestPlugIn.h>
#include <cppunit/extensions/HelperMacros.h>
@@ -67,6 +68,7 @@ public:
void testDocumentTypes( Office* pOffice );
void testImpressSlideNames( Office* pOffice );
void testCalcSheetNames( Office* pOffice );
+ void testGetStyles( Office* pOffice );
#if 0
void testOverlay( Office* pOffice );
#endif
@@ -93,6 +95,7 @@ void TiledRenderingTest::runAllTests()
testDocumentTypes( pOffice.get() );
testImpressSlideNames( pOffice.get() );
testCalcSheetNames( pOffice.get() );
+ testGetStyles( pOffice.get() );
#if 0
testOverlay( pOffice.get() );
#endif
@@ -181,6 +184,38 @@ void TiledRenderingTest::testCalcSheetNames( Office* pOffice )
CPPUNIT_ASSERT( strcmp( pDocument->getPartName( 2 ), "Sheet3" ) == 0 );
}
+void TiledRenderingTest::testGetStyles( Office* pOffice )
+{
+ const string sDocPath = m_sSrcRoot + "/libreofficekit/qa/data/blank_text.odt";
+ const string sLockFile = m_sSrcRoot +"/libreofficekit/qa/data/.~lock.blank_text.odt#";
+
+ // FIXME: LOK will fail when trying to open a locked file
+ remove( sLockFile.c_str() );
+
+ scoped_ptr< Document> pDocument( pOffice->documentLoad( sDocPath.c_str() ) );
+
+ boost::property_tree::ptree aTree;
+ char* pJSON = pDocument->getStyles();
+ std::stringstream aStream(pJSON);
+ boost::property_tree::read_json(aStream, aTree);
+ CPPUNIT_ASSERT( aTree.size() > 0 );
+
+ for (const std::pair<std::string, boost::property_tree::ptree>& rPair : aTree)
+ {
+ CPPUNIT_ASSERT( rPair.second.size() > 0);
+ if (rPair.first != "CharacterStyles" &&
+ rPair.first != "ParagraphStyles" &&
+ rPair.first != "FrameStyles" &&
+ rPair.first != "PageStyles" &&
+ rPair.first != "NumberingStyles" &&
+ rPair.first != "CellStyles" &&
+ rPair.first != "ShapeStyles")
+ {
+ CPPUNIT_FAIL("Unknown style family: " + rPair.first);
+ }
+ }
+}
+
#if 0
static void dumpRGBABitmap( const OUString& rPath, const unsigned char* pBuffer,
const int nWidth, const int nHeight )