summaryrefslogtreecommitdiff
path: root/desktop/source
diff options
context:
space:
mode:
authorHenry Castro <hcastro@collabora.com>2017-10-02 22:49:03 -0400
committerHenry Castro <hcastro@collabora.com>2017-10-03 05:59:54 +0200
commitf50bf3c5225b49b3c6f77f882e35305e5dc5ccd3 (patch)
tree36c443acfdeeb3aae2bebebd6f366577059cfe12 /desktop/source
parent34e8fd7e99489e9f50a512b07c6f3923b358b4d3 (diff)
lok: use getCommandValues to obtain a list of languages
Change-Id: I4a1f04b9dfe9e3ebbc174380db93c332e958ccfa Reviewed-on: https://gerrit.libreoffice.org/43060 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Henry Castro <hcastro@collabora.com>
Diffstat (limited to 'desktop/source')
-rw-r--r--desktop/source/lib/init.cxx70
1 files changed, 31 insertions, 39 deletions
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);
}