[Libreoffice-commits] core.git: comphelper/source desktop/source include/comphelper

Henry Castro hcastro at collabora.com
Tue Oct 3 04:00:23 UTC 2017


 comphelper/source/misc/lok.cxx |   15 ++++++++
 desktop/source/lib/init.cxx    |   70 ++++++++++++++++++-----------------------
 include/comphelper/lok.hxx     |    5 ++
 3 files changed, 51 insertions(+), 39 deletions(-)

New commits:
commit f50bf3c5225b49b3c6f77f882e35305e5dc5ccd3
Author: Henry Castro <hcastro at collabora.com>
Date:   Mon Oct 2 22:49:03 2017 -0400

    lok: use getCommandValues to obtain a list of languages
    
    Change-Id: I4a1f04b9dfe9e3ebbc174380db93c332e958ccfa
    Reviewed-on: https://gerrit.libreoffice.org/43060
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Henry Castro <hcastro at collabora.com>

diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx
index a4f60ac6c565..4e24ab9d391b 100644
--- a/comphelper/source/misc/lok.cxx
+++ b/comphelper/source/misc/lok.cxx
@@ -8,6 +8,11 @@
  */
 
 #include <comphelper/lok.hxx>
+#include <comphelper/processfactory.hxx>
+
+#include <com/sun/star/linguistic2/LinguServiceManager.hpp>
+#include <com/sun/star/linguistic2/XSpellChecker.hpp>
+
 
 namespace comphelper
 {
@@ -114,6 +119,16 @@ void statusIndicatorFinish()
         pStatusIndicatorCallback(pStatusIndicatorCallbackData, statusIndicatorCallbackType::Finish, 0);
 }
 
+css::uno::Sequence< css::lang::Locale > getSpellLanguages()
+{
+    css::uno::Reference< css::uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
+    css::uno::Reference< css::linguistic2::XLinguServiceManager2 > xLangSrv = css::linguistic2::LinguServiceManager::create(xContext);
+    css::uno::Reference< css::linguistic2::XSpellChecker > xSpell(xLangSrv.is() ? xLangSrv->getSpellChecker() : nullptr, css::uno::UNO_QUERY);
+    css::uno::Reference< css::linguistic2::XSupportedLocales > xLocales(xSpell, css::uno::UNO_QUERY);
+    css::uno::Sequence< css::lang::Locale > aLocales(xLocales.is() ? xLocales->getLocales() : css::uno::Sequence< css::lang::Locale >());
+    return aLocales;
+}
+
 } // namespace LibreOfficeKit
 
 } // namespace comphelper
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 48f08bb57ccd..ff186f69eacd 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -59,7 +59,6 @@
 
 #include <editeng/fontitem.hxx>
 #include <editeng/flstitem.hxx>
-#include <editeng/unolingu.hxx>
 #include <sfx2/objsh.hxx>
 #include <sfx2/viewsh.hxx>
 #include <sfx2/viewfrm.hxx>
@@ -75,7 +74,6 @@
 #include <vcl/svapp.hxx>
 #include <unotools/resmgr.hxx>
 #include <tools/fract.hxx>
-#include <linguistic/misc.hxx>
 #include <svtools/ctrltool.hxx>
 #include <svtools/langtab.hxx>
 #include <vcl/fontcharmap.hxx>
@@ -1534,36 +1532,7 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
     return false;
 }
 
-static void doc_iniUnoCommand(const SfxViewShell* pViewShell, const OUString& aUnoCommand)
-{
-    OUStringBuffer aBuffer;
-
-    if (aUnoCommand.endsWith("LanguageStatus"))
-    {
-        uno::Reference< css::linguistic2::XLinguServiceManager2 > xLangSrv = css::linguistic2::LinguServiceManager::create(xContext);
-        uno::Reference< css::linguistic2::XSpellChecker > xSpell(xLangSrv.is() ? xLangSrv->getSpellChecker() : nullptr, uno::UNO_QUERY);
-        uno::Reference< css::linguistic2::XSupportedLocales > xLocales(xSpell, uno::UNO_QUERY);
-        uno::Sequence< css::lang::Locale > aLocales(xLocales.is() ? xLocales->getLocales() : uno::Sequence< css::lang::Locale >());
-
-        aBuffer.append(aUnoCommand);
-        aBuffer.append("?[");
-        for ( sal_Int32 itLocale = 0; itLocale < aLocales.getLength(); itLocale++ )
-        {
-            aBuffer.append("\"" + SvtLanguageTable::GetLanguageString(LanguageTag::convertToLanguageType(aLocales[itLocale])) + "\"");
-            if (itLocale + 1 != aLocales.getLength())
-                aBuffer.append(",");
-        }
-        aBuffer.append("]");
-    }
-
-    if (pViewShell && !aBuffer.isEmpty())
-    {
-        OUString payload = aBuffer.makeStringAndClear();
-        pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, payload.toUtf8().getStr());
-    }
-}
-
-static void doc_iniUnoCommands (const SfxViewShell* pViewShell)
+static void doc_iniUnoCommands ()
 {
     SolarMutexGuard aGuard;
 
@@ -1652,6 +1621,7 @@ static void doc_iniUnoCommands (const SfxViewShell* pViewShell)
     };
 
     util::URL aCommandURL;
+    SfxViewShell* pViewShell = SfxViewShell::Current();
     SfxViewFrame* pViewFrame = pViewShell? pViewShell->GetViewFrame(): nullptr;
 
     // check if Frame-Controller were created.
@@ -1685,11 +1655,7 @@ static void doc_iniUnoCommands (const SfxViewShell* pViewShell)
         if (pSlot)
         {
             // Initialize slot to dispatch .uno: Command.
-            uno::Reference<frame::XDispatch> xDispatch(pViewFrame->GetBindings().GetDispatch(pSlot, aCommandURL, false));
-            if (xDispatch.is())
-            {
-                doc_iniUnoCommand(pViewShell, sUnoCommand);
-            }
+            pViewFrame->GetBindings().GetDispatch(pSlot, aCommandURL, false);
         }
     }
 }
@@ -2039,6 +2005,7 @@ static void doc_initializeForRendering(LibreOfficeKitDocument* pThis,
     ITiledRenderable* pDoc = getTiledRenderable(pThis);
     if (pDoc)
     {
+        doc_iniUnoCommands();
         pDoc->initializeForTiledRendering(
                 comphelper::containerToSequence(jsonToPropertyValuesVector(pArguments)));
     }
@@ -2096,7 +2063,6 @@ static void doc_registerCallback(LibreOfficeKitDocument* pThis,
     if (SfxViewShell* pViewShell = SfxViewShell::Current())
     {
         pViewShell->registerLibreOfficeKitViewCallback(CallbackFlushHandler::callback, pDocument->mpCallbackFlushHandlers[nView].get());
-        doc_iniUnoCommands(pViewShell);
     }
 }
 
@@ -2452,6 +2418,28 @@ static void doc_resetSelection(LibreOfficeKitDocument* pThis)
     pDoc->resetSelection();
 }
 
+static char* getLanguages(const char* pCommand)
+{
+    uno::Sequence< css::lang::Locale > aLocales(comphelper::LibreOfficeKit::getSpellLanguages());
+
+    boost::property_tree::ptree aTree;
+    aTree.put("commandName", pCommand);
+    boost::property_tree::ptree aValues;
+    for ( sal_Int32 itLocale = 0; itLocale < aLocales.getLength(); itLocale++ )
+    {
+        boost::property_tree::ptree aChild;
+        aChild.put("", SvtLanguageTable::GetLanguageString(LanguageTag::convertToLanguageType(aLocales[itLocale])).toUtf8());
+        aValues.push_back(std::make_pair("", aChild));
+    }
+    aTree.add_child("commandValues", aValues);
+    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* getFonts (const char* pCommand)
 {
     SfxObjectShell* pDocSh = SfxObjectShell::Current();
@@ -2757,7 +2745,11 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
     static const OString aCellCursor(".uno:CellCursor");
     static const OString aFontSubset(".uno:FontSubset&name=");
 
-    if (!strcmp(pCommand, ".uno:CharFontName"))
+    if (!strcmp(pCommand, ".uno:LanguageStatus"))
+    {
+        return getLanguages(pCommand);
+    }
+    else if (!strcmp(pCommand, ".uno:CharFontName"))
     {
         return getFonts(pCommand);
     }
diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx
index 7a293ca70352..22f0c70556c7 100644
--- a/include/comphelper/lok.hxx
+++ b/include/comphelper/lok.hxx
@@ -10,7 +10,10 @@
 #ifndef INCLUDED_COMPHELPER_LOK_HXX
 #define INCLUDED_COMPHELPER_LOK_HXX
 
+#include <com/sun/star/lang/Locale.hpp>
+
 #include <comphelper/comphelperdllapi.h>
+#include <comphelper/sequence.hxx>
 
 // Interface between the LibreOfficeKit implementation called by LibreOfficeKit clients and other
 // LibreOffice code.
@@ -68,6 +71,8 @@ COMPHELPER_DLLPUBLIC void statusIndicatorStart();
 COMPHELPER_DLLPUBLIC void statusIndicatorSetValue(int percent);
 COMPHELPER_DLLPUBLIC void statusIndicatorFinish();
 
+COMPHELPER_DLLPUBLIC css::uno::Sequence< css::lang::Locale > getSpellLanguages();
+
 }
 }
 


More information about the Libreoffice-commits mailing list