desktop/source/lib/init.cxx     |  127 +++++++++++++++++++++++++++++++++++++++-
 sc/source/ui/docshell/docsh.cxx |    3 
 2 files changed, 127 insertions(+), 3 deletions(-)

New commits:
commit 452baabeb950901f293ca26542c8e6df3dbfb7c5
Author:     Henry Castro <[email protected]>
AuthorDate: Wed Jan 11 16:14:57 2023 -0400
Commit:     Andras Timar <[email protected]>
CommitDate: Sat Jan 28 09:25:50 2023 +0000

    lok: add function getDocLanguages
    
    If the spell checker is disabled to use a remote
    spelling feature, the getLanguages function is obsolete.
    
    In order to not break stable functions, introduce the
    getDocLanguages for the remote spelling feature.
    
    Signed-off-by: Henry Castro <[email protected]>
    Change-Id: Ic210f31eddd3208b29d073ff35ba4fa2d98ea772
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145363
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Andras Timar <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145614
    Tested-by: Andras Timar <[email protected]>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 1fbe2ab4162b..938fdfc404fe 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -72,6 +72,7 @@
 #include <com/sun/star/document/MacroExecMode.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/document/XDocumentLanguages.hpp>
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/frame/DispatchResultEvent.hpp>
 #include <com/sun/star/frame/DispatchResultState.hpp>
@@ -97,6 +98,7 @@
 #include <com/sun/star/xml/crypto/XCertificateCreator.hpp>
 #include <com/sun/star/security/XCertificate.hpp>
 
+#include <com/sun/star/linguistic2/LanguageGuessing.hpp>
 #include <com/sun/star/linguistic2/LinguServiceManager.hpp>
 #include <com/sun/star/linguistic2/XSpellChecker.hpp>
 #include <com/sun/star/i18n/LocaleCalendar2.hpp>
@@ -5352,6 +5354,119 @@ static void 
doc_setGraphicSelection(LibreOfficeKitDocument* pThis, int nType, in
     pDoc->setGraphicSelection(nType, nX, nY);
 }
 
+static uno::Any getDocLanguages(LibreOfficeKitDocument* pThis)
+{
+    SfxViewFrame* pViewFrame = SfxViewFrame::Current();
+    if (!pViewFrame)
+        return uno::makeAny(Sequence<lang::Locale>());
+
+    SfxDispatcher* pDispatcher = pViewFrame->GetBindings().GetDispatcher();
+    if (!pDispatcher)
+        return uno::makeAny(Sequence<lang::Locale>());
+
+    css::uno::Any aLangStatus;
+    pDispatcher->QueryState(SID_LANGUAGE_STATUS, aLangStatus);
+
+    Sequence<OUString> aSeqLang;
+    if (!(aLangStatus >>= aSeqLang))
+        return uno::makeAny(Sequence<lang::Locale>());
+
+    // (aSeqLang[0] == "Current Language",  aSeqLang[1] == "Script Type",
+    //  aSeqLang[2] == "Keyboard Language", aSeqLang[3] == "Guess Text Lang")
+    if (aSeqLang.getLength() != 4)
+        return uno::makeAny(Sequence<lang::Locale>());
+
+    LanguageType nLangType;
+    std::set<LanguageType> aLangItems;
+    SvtScriptType eScriptType = 
static_cast<SvtScriptType>(aSeqLang[1].toInt32());
+
+    if (!aSeqLang[0].isEmpty())
+    {
+        nLangType = SvtLanguageTable::GetLanguageType(aSeqLang[0]);
+        if (nLangType != LANGUAGE_DONTKNOW)
+        {
+            aLangItems.insert(nLangType);
+        }
+    }
+
+    const AllSettings& rAllSettings = Application::GetSettings();
+    nLangType = rAllSettings.GetLanguageTag().getLanguageType();
+    if (nLangType != LANGUAGE_DONTKNOW &&
+        (eScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType)))
+    {
+        aLangItems.insert(nLangType);
+    }
+
+    nLangType = rAllSettings.GetUILanguageTag().getLanguageType();
+    if (nLangType != LANGUAGE_DONTKNOW &&
+        (eScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType)))
+    {
+        aLangItems.insert(nLangType);
+    }
+
+    if (!aSeqLang[2].isEmpty())
+    {
+        nLangType = SvtLanguageTable::GetLanguageType(aSeqLang[2]);
+        if (nLangType != LANGUAGE_DONTKNOW &&
+            (eScriptType & 
SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType)))
+        {
+            aLangItems.insert(nLangType);
+        }
+    }
+
+    if (!aSeqLang[3].isEmpty())
+    {
+        Reference<linguistic2::XLanguageGuessing> xLangGuesser;
+        try
+        {
+            xLangGuesser = linguistic2::LanguageGuessing::create(xContext);
+        }
+        catch(...)
+        {
+        }
+
+        if (xLangGuesser.is())
+        {
+            lang::Locale aLocale = 
xLangGuesser->guessPrimaryLanguage(aSeqLang[3], 0,
+                                                                      
aSeqLang[3].getLength());
+            nLangType = LanguageTag(aLocale).makeFallback().getLanguageType();
+            if (nLangType != LANGUAGE_DONTKNOW &&
+                (eScriptType & 
SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType)))
+            {
+                aLangItems.insert(nLangType);
+            }
+        }
+    }
+
+    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
+    Reference<document::XDocumentLanguages> 
xDocumentLanguages(pDocument->mxComponent, UNO_QUERY);
+    if (xDocumentLanguages.is())
+    {
+        const Sequence<lang::Locale> 
aLocales(xDocumentLanguages->getDocumentLanguages(
+                                                  
static_cast<sal_Int16>(eScriptType), 64));
+
+        for (const lang::Locale& aLocale : aLocales)
+        {
+            nLangType = SvtLanguageTable::GetLanguageType(aLocale.Language);
+            if (nLangType != LANGUAGE_DONTKNOW &&
+                (eScriptType & 
SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType)))
+            {
+                aLangItems.insert(nLangType);
+            }
+        }
+    }
+
+    int nLocale = 0;
+    Sequence<lang::Locale> aLocales(aLangItems.size());
+    auto pLocales = aLocales.getArray();
+    for (const LanguageType& itLang : aLangItems)
+    {
+        pLocales[nLocale++] = LanguageTag::convertToLocale(itLang);
+    }
+
+    return uno::makeAny(aLocales);
+}
+
 static void doc_resetSelection(LibreOfficeKitDocument* pThis)
 {
     comphelper::ProfileZone aZone("doc_resetSelection");
@@ -5369,7 +5484,7 @@ static void doc_resetSelection(LibreOfficeKitDocument* 
pThis)
     pDoc->resetSelection();
 }
 
-static char* getLanguages(const char* pCommand)
+static char* getLanguages(LibreOfficeKitDocument* pThis, const char* pCommand)
 {
     css::uno::Sequence< css::lang::Locale > aLocales;
 
@@ -5382,6 +5497,14 @@ static char* getLanguages(const char* pCommand)
             if (xSpell.is())
                 aLocales = xSpell->getLocales();
         }
+
+        /* FIXME: To obtain the document languages the spell checker can be 
disabled,
+           so a future re-work of the getLanguages function is needed in favor 
to use
+           getDocLanguages */
+        if (!aLocales.hasElements())
+        {
+            getDocLanguages(pThis) >>= aLocales;
+        }
     }
 
     boost::property_tree::ptree aTree;
@@ -5737,7 +5860,7 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* 
pThis, const char* pCo
 
     if (!strcmp(pCommand, ".uno:LanguageStatus"))
     {
-        return getLanguages(pCommand);
+        return getLanguages(pThis, pCommand);
     }
     else if (!strcmp(pCommand, ".uno:CharFontName"))
     {
commit 7137fa5158530c0f6adb1f80f82203b43213187f
Author:     Henry Castro <[email protected]>
AuthorDate: Thu Jan 5 11:32:32 2023 -0400
Commit:     Andras Timar <[email protected]>
CommitDate: Sat Jan 28 09:25:38 2023 +0000

    lok: sc: avoid the shared spreadsheet dialog
    
    It is not needed the LO core shared spreadsheet
    because the online has collaborative functionality turns on
    by default.
    
    Signed-off-by: Henry Castro <[email protected]>
    Change-Id: I57ab83eae2913522d55704ae5a115e30c9d10034
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145091
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Andras Timar <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145613
    Tested-by: Andras Timar <[email protected]>

diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 458feb6dea2a..9a5b5968d9ec 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -727,7 +727,8 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& 
rHint )
 #endif
 
 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
-                    if ( IsDocShared() && !SC_MOD()->IsInSharedDocLoading() )
+                    if ( IsDocShared() && !SC_MOD()->IsInSharedDocLoading()
+                         && !comphelper::LibreOfficeKit::isActive() )
                     {
                         ScAppOptions aAppOptions = SC_MOD()->GetAppOptions();
                         if ( aAppOptions.GetShowSharedDocumentWarning() )

Reply via email to