desktop/source/lib/init.cxx | 36 ++++++++++++++++++-- include/LibreOfficeKit/LibreOfficeKit.h | 3 + include/LibreOfficeKit/LibreOfficeKit.hxx | 20 ++++++++++- include/LibreOfficeKit/LibreOfficeKitGtk.h | 2 - libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx | 2 - libreofficekit/source/gtk/lokdocview.cxx | 4 +- 6 files changed, 57 insertions(+), 10 deletions(-)
New commits: commit 6a8719b12e2f24e926fccdfabc60b95c089320fc Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Wed Apr 22 14:28:36 2015 +0200 lok::Document::postUnoCommand: allow passing arguments Change-Id: I6c24a8e392473f3985d3bde9b76a3148fd03bc9a diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index c1237ac..b783612 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -15,6 +15,7 @@ #include <boost/shared_ptr.hpp> #include <boost/weak_ptr.hpp> +#include <boost/property_tree/json_parser.hpp> #define LOK_USE_UNSTABLE_API #include <LibreOfficeKit/LibreOfficeKit.h> @@ -52,6 +53,7 @@ #include <unotools/syslocaleoptions.hxx> #include <unotools/mediadescriptor.hxx> #include <osl/module.hxx> +#include <comphelper/sequence.hxx> #include <app.hxx> @@ -207,7 +209,8 @@ static void doc_postMouseEvent (LibreOfficeKitDocument* pThis, int nY, int nCount); static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, - const char* pCommand); + const char* pCommand, + const char* pArguments); static void doc_setTextSelection (LibreOfficeKitDocument* pThis, int nType, int nX, @@ -701,11 +704,38 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nChar pDoc->postKeyEvent(nType, nCharCode, nKeyCode); } -static void doc_postUnoCommand(LibreOfficeKitDocument* /*pThis*/, const char* pCommand) +static void jsonToPropertyValues(const char* pJSON, uno::Sequence<beans::PropertyValue>& rPropertyValues) +{ + boost::property_tree::ptree aTree; + std::stringstream aStream(pJSON); + boost::property_tree::read_json(aStream, aTree); + + std::vector<beans::PropertyValue> aArguments; + for (const std::pair<std::string, boost::property_tree::ptree>& rPair : aTree) + { + const std::string& rType = rPair.second.get<std::string>("type"); + const std::string& rValue = rPair.second.get<std::string>("value"); + + beans::PropertyValue aValue; + aValue.Name = OUString::fromUtf8(rPair.first.c_str()); + if (rType == "string") + aValue.Value <<= OUString::fromUtf8(rValue.c_str()); + else if (rType == "boolean") + aValue.Value <<= OString(rValue.c_str()).toBoolean(); + else + SAL_WARN("desktop.lib", "jsonToPropertyValues: unhandled type '"<<rType<<"'"); + aArguments.push_back(aValue); + } + rPropertyValues = comphelper::containerToSequence(aArguments); +} + +static void doc_postUnoCommand(LibreOfficeKitDocument* /*pThis*/, const char* pCommand, const char* pArguments) { OUString aCommand(pCommand, strlen(pCommand), RTL_TEXTENCODING_UTF8); - if (!comphelper::dispatchCommand(aCommand, uno::Sequence<beans::PropertyValue>())) + uno::Sequence<beans::PropertyValue> aPropertyValues; + jsonToPropertyValues(pArguments, aPropertyValues); + if (!comphelper::dispatchCommand(aCommand, aPropertyValues)) { gImpl->maLastExceptionMsg = "Failed to dispatch the .uno: command"; } diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index c078318..e576e0a 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -132,7 +132,8 @@ struct _LibreOfficeKitDocumentClass /// @see lok::Document::postUnoCommand void (*postUnoCommand) (LibreOfficeKitDocument* pThis, - const char* pCommand); + const char* pCommand, + const char* pArguments); /// @see lok::Document::setTextSelection void (*setTextSelection) (LibreOfficeKitDocument* pThis, diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index 4f0a77a..0140348 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -181,11 +181,27 @@ public: /** * Posts an UNO command to the document. * + * Example argument string: + * + * { + * "SearchItem.SearchString": + * { + * "type": "string", + * "value": "foobar" + * }, + * "SearchItem.Backward": + * { + * "type": "boolean", + * "value": "false" + * } + * } + * * @param pCommand uno command to be posted to the document, like ".uno:Bold" + * @param pArguments arguments of the uno command. */ - inline void postUnoCommand(const char* pCommand) + inline void postUnoCommand(const char* pCommand, const char* pArguments = 0) { - mpDoc->pClass->postUnoCommand(mpDoc, pCommand); + mpDoc->pClass->postUnoCommand(mpDoc, pCommand, pArguments); } /** diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h index f76c1fb..a517fca 100644 --- a/include/LibreOfficeKit/LibreOfficeKitGtk.h +++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h @@ -68,7 +68,7 @@ void lok_docview_set_edit (LOKDocView* pDocView, gboolean lok_docview_get_edit (LOKDocView* pDocView); /// Posts the .uno: command to the LibreOfficeKit. -void lok_docview_post_command (LOKDocView* pDocView, const char* pCommand); +void lok_docview_post_command (LOKDocView* pDocView, const char* pCommand, const char* pArguments); /// Posts a keyboard event to LibreOfficeKit. void lok_docview_post_key (GtkWidget* pWidget, GdkEventKey* pEvent, gpointer pData); diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx index 7715875..2502f40 100644 --- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx @@ -156,7 +156,7 @@ void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/) GtkToolItem* pItem = GTK_TOOL_ITEM(pWidget); const std::string& rString = g_aToolItemCommandNames[pItem]; g_info("toggleToolItem: lok_docview_post_command('%s')", rString.c_str()); - lok_docview_post_command(pLOKDocView, rString.c_str()); + lok_docview_post_command(pLOKDocView, rString.c_str(), 0); } } diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index c3b75a8..00f4f4b 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -1162,9 +1162,9 @@ SAL_DLLPUBLIC_EXPORT gboolean lok_docview_get_edit(LOKDocView* pDocView) return pDocView->m_pImpl->m_bEdit; } -SAL_DLLPUBLIC_EXPORT void lok_docview_post_command(LOKDocView* pDocView, const char* pCommand) +SAL_DLLPUBLIC_EXPORT void lok_docview_post_command(LOKDocView* pDocView, const char* pCommand, const char* pArguments) { - pDocView->m_pImpl->m_pDocument->pClass->postUnoCommand(pDocView->m_pImpl->m_pDocument, pCommand); + pDocView->m_pImpl->m_pDocument->pClass->postUnoCommand(pDocView->m_pImpl->m_pDocument, pCommand, pArguments); } SAL_DLLPUBLIC_EXPORT void lok_docview_post_key(GtkWidget* /*pWidget*/, GdkEventKey* pEvent, gpointer pData) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits