Kaydet (Commit) 9640dcea authored tarafından Mihai Varga's avatar Mihai Varga

LOK: added a general getCommandValues method

This method returns a JSON mapping of the posible values for the given
command (e.g. .uno:StyleApply, etc).

returns:
{commandName: "cmdName", commandValues: {json_of_cmd_values}}

Change-Id: Ic8f970d077af6be9bc226f72f725b6cdf2d4c160
üst 51ac2bf2
...@@ -235,7 +235,7 @@ static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis, ...@@ -235,7 +235,7 @@ static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis,
int nX, int nX,
int nY); int nY);
static void doc_resetSelection (LibreOfficeKitDocument* pThis); static void doc_resetSelection (LibreOfficeKitDocument* pThis);
static char* doc_getStyles(LibreOfficeKitDocument* pThis); static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand);
struct LibLODocument_Impl : public _LibreOfficeKitDocument struct LibLODocument_Impl : public _LibreOfficeKitDocument
{ {
...@@ -270,7 +270,7 @@ struct LibLODocument_Impl : public _LibreOfficeKitDocument ...@@ -270,7 +270,7 @@ struct LibLODocument_Impl : public _LibreOfficeKitDocument
m_pDocumentClass->getTextSelection = doc_getTextSelection; m_pDocumentClass->getTextSelection = doc_getTextSelection;
m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection; m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection;
m_pDocumentClass->resetSelection = doc_resetSelection; m_pDocumentClass->resetSelection = doc_resetSelection;
m_pDocumentClass->getStyles = doc_getStyles; m_pDocumentClass->getCommandValues = doc_getCommandValues;
gDocumentClass = m_pDocumentClass; gDocumentClass = m_pDocumentClass;
} }
...@@ -868,15 +868,17 @@ static void doc_resetSelection(LibreOfficeKitDocument* pThis) ...@@ -868,15 +868,17 @@ static void doc_resetSelection(LibreOfficeKitDocument* pThis)
pDoc->resetSelection(); pDoc->resetSelection();
} }
static char* doc_getStyles(LibreOfficeKitDocument* pThis) static char* getStyles(LibreOfficeKitDocument* pThis, const char* pCommand)
{ {
LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis); LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
boost::property_tree::ptree aTree; boost::property_tree::ptree aTree;
aTree.put("commandName", pCommand);
uno::Reference<css::style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(pDocument->mxComponent, uno::UNO_QUERY); uno::Reference<css::style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(pDocument->mxComponent, uno::UNO_QUERY);
uno::Reference<container::XNameAccess> xStyleFamilies(xStyleFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY); uno::Reference<container::XNameAccess> xStyleFamilies(xStyleFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY);
uno::Sequence<OUString> aStyleFamilies = xStyleFamilies->getElementNames(); uno::Sequence<OUString> aStyleFamilies = xStyleFamilies->getElementNames();
boost::property_tree::ptree aValues;
for (sal_Int32 nStyleFam = 0; nStyleFam < aStyleFamilies.getLength(); ++nStyleFam) for (sal_Int32 nStyleFam = 0; nStyleFam < aStyleFamilies.getLength(); ++nStyleFam)
{ {
boost::property_tree::ptree aChildren; boost::property_tree::ptree aChildren;
...@@ -889,8 +891,9 @@ static char* doc_getStyles(LibreOfficeKitDocument* pThis) ...@@ -889,8 +891,9 @@ static char* doc_getStyles(LibreOfficeKitDocument* pThis)
aChild.put("", aStyles[nInd]); aChild.put("", aStyles[nInd]);
aChildren.push_back(std::make_pair("", aChild)); aChildren.push_back(std::make_pair("", aChild));
} }
aTree.add_child(sStyleFam.toUtf8().getStr(), aChildren); aValues.add_child(sStyleFam.toUtf8().getStr(), aChildren);
} }
aTree.add_child("commandValues", aValues);
std::stringstream aStream; std::stringstream aStream;
boost::property_tree::write_json(aStream, aTree); boost::property_tree::write_json(aStream, aTree);
char* pJson = static_cast<char*>(malloc(aStream.str().size() + 1)); char* pJson = static_cast<char*>(malloc(aStream.str().size() + 1));
...@@ -898,6 +901,19 @@ static char* doc_getStyles(LibreOfficeKitDocument* pThis) ...@@ -898,6 +901,19 @@ static char* doc_getStyles(LibreOfficeKitDocument* pThis)
pJson[aStream.str().size()] = '\0'; pJson[aStream.str().size()] = '\0';
return pJson; return pJson;
} }
static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand)
{
if (!strcmp(pCommand, ".uno:StyleApply"))
{
return getStyles(pThis, pCommand);
}
else {
gImpl->maLastExceptionMsg = "Unknown command, no values returned";
return NULL;
}
}
static char* lo_getError (LibreOfficeKit *pThis) static char* lo_getError (LibreOfficeKit *pThis)
{ {
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis); LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
......
...@@ -161,7 +161,7 @@ struct _LibreOfficeKitDocumentClass ...@@ -161,7 +161,7 @@ struct _LibreOfficeKitDocumentClass
void (*resetSelection) (LibreOfficeKitDocument* pThis); void (*resetSelection) (LibreOfficeKitDocument* pThis);
/// @see lok::Document:getStyles /// @see lok::Document:getStyles
char* (*getStyles) (LibreOfficeKitDocument* pThis); char* (*getCommandValues) (LibreOfficeKitDocument* pThis, const char* pCommand);
#endif // LOK_USE_UNSTABLE_API #endif // LOK_USE_UNSTABLE_API
}; };
......
...@@ -248,11 +248,14 @@ public: ...@@ -248,11 +248,14 @@ public:
} }
/** /**
* Returns a json map, {"familyName1" : ["list of style names in the family1"], etc.} * Returns a json mapping of the possible values for the given command
* e.g. {commandName: ".uno:StyleApply", commandValues: {"familyName1" : ["list of style names in the family1"], etc.}}
* @param pCommand a uno command for which the possible values are requested
* @return {commandName: unoCmd, commandValues: {possible_values}}
*/ */
inline char* getStyles() inline char* getCommandValues(const char* pCommand)
{ {
return mpDoc->pClass->getStyles(mpDoc); return mpDoc->pClass->getCommandValues(mpDoc, pCommand);
} }
#endif // LOK_USE_UNSTABLE_API #endif // LOK_USE_UNSTABLE_API
}; };
......
...@@ -195,12 +195,16 @@ void TiledRenderingTest::testGetStyles( Office* pOffice ) ...@@ -195,12 +195,16 @@ void TiledRenderingTest::testGetStyles( Office* pOffice )
scoped_ptr< Document> pDocument( pOffice->documentLoad( sDocPath.c_str() ) ); scoped_ptr< Document> pDocument( pOffice->documentLoad( sDocPath.c_str() ) );
boost::property_tree::ptree aTree; boost::property_tree::ptree aTree;
char* pJSON = pDocument->getStyles(); char* pJSON = pDocument->getCommandValues(".uno:StyleApply");
std::stringstream aStream(pJSON); std::stringstream aStream(pJSON);
boost::property_tree::read_json(aStream, aTree); boost::property_tree::read_json(aStream, aTree);
CPPUNIT_ASSERT( aTree.size() > 0 ); CPPUNIT_ASSERT( aTree.size() > 0 );
CPPUNIT_ASSERT( aTree.get_value<std::string>("commandName") == ".uno:StyleApply" );
for (const std::pair<std::string, boost::property_tree::ptree>& rPair : aTree)
boost::property_tree::ptree aValues = aTree.get_child("commandValues");
CPPUNIT_ASSERT( aValues.size() > 0 );
for (const std::pair<std::string, boost::property_tree::ptree>& rPair : aValues)
{ {
CPPUNIT_ASSERT( rPair.second.size() > 0); CPPUNIT_ASSERT( rPair.second.size() > 0);
if (rPair.first != "CharacterStyles" && if (rPair.first != "CharacterStyles" &&
......
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