[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - comphelper/source desktop/CppunitTest_desktop_lib.mk desktop/qa desktop/source include/comphelper include/sfx2 include/svl sfx2/source svl/source unotools/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Mon Feb 24 12:33:19 UTC 2020


 comphelper/source/misc/lok.cxx              |   68 +++++++++++++++++++++++-----
 desktop/CppunitTest_desktop_lib.mk          |    1 
 desktop/qa/desktop_lib/test_desktop_lib.cxx |    2 
 desktop/source/lib/init.cxx                 |   39 +++++++++-------
 include/comphelper/lok.hxx                  |    7 ++
 include/sfx2/lokhelper.hxx                  |    6 ++
 include/sfx2/viewsh.hxx                     |    6 ++
 include/svl/zforlist.hxx                    |    2 
 sfx2/source/view/lokhelper.cxx              |   32 ++++++++++++-
 sfx2/source/view/viewsh.cxx                 |   11 ++++
 svl/source/numbers/zforlist.cxx             |   10 ++++
 unotools/source/misc/syslocale.cxx          |    2 
 12 files changed, 154 insertions(+), 32 deletions(-)

New commits:
commit f07e77b93ddfbac967dbc526dc01ec39b5a046c7
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon Feb 24 08:07:12 2020 +0100
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Mon Feb 24 13:32:45 2020 +0100

    Fix currency symbol selection in Calc on mobile
    
    In LOK we use one language identifier for both - UI language and
    the locale used. This is a problem when we determine that we a
    language for UI is not available and fall-back to the default
    "en-US" langauge, which also changes the locale. This introduces
    a separate variable that stores the language tag for the locale
    independently to the language.
    
    Another problem is that in some cases we don't reset the staticly
    initialized data, when the new document is loaded, which is on
    the other hand used to define which currency symbol is used as
    SYSTEM locale. That can in some cases select the wrong currency
    symbol even when we changed the locale to something else. This fix
    introduces a reset function, which is triggered on every document
    load.
    
    Change-Id: I55c7f467600a832895f94346f8bf11a6ef6a1e49
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89320
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Andras Timar <andras.timar at collabora.com>

diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx
index 1834665e91a4..48b61dea8fa1 100644
--- a/comphelper/source/misc/lok.cxx
+++ b/comphelper/source/misc/lok.cxx
@@ -39,7 +39,50 @@ static bool g_bLocalRendering(false);
 
 static Compat g_eCompatFlags(Compat::none);
 
-static LanguageTag g_aLanguageTag("en-US", true);
+class LanguageAndLocale
+{
+private:
+    LanguageTag maLanguageTag;
+    LanguageTag maLocaleLanguageTag;
+
+public:
+
+    LanguageAndLocale()
+        : maLanguageTag(LANGUAGE_NONE)
+        , maLocaleLanguageTag(LANGUAGE_NONE)
+    {}
+
+    const LanguageTag& getLanguage()
+    {
+        return maLanguageTag;
+    }
+
+    void setLanguage(const LanguageTag& rLanguageTag)
+    {
+        if (maLanguageTag != rLanguageTag)
+        {
+            SAL_INFO("comphelper.lok", "Setting language from " << maLanguageTag.getBcp47() << " to " << rLanguageTag.getBcp47());
+            maLanguageTag = rLanguageTag;
+        }
+    }
+
+    const LanguageTag& getLocale()
+    {
+        return maLocaleLanguageTag;
+    }
+
+    void setLocale(const LanguageTag& rLocaleLanguageTag)
+    {
+        if (maLocaleLanguageTag != rLocaleLanguageTag)
+        {
+            SAL_INFO("comphelper.lok", "Setting locale from " << maLanguageTag.getBcp47() << " to " << rLocaleLanguageTag.getBcp47());
+            maLocaleLanguageTag = rLocaleLanguageTag;
+        }
+    }
+
+};
+
+static LanguageAndLocale g_aLanguageAndLocale;
 
 /// Scaling of the cairo or CoreGraphics canvas painting for hi-dpi
 static double g_fDPIScale(1.0);
@@ -157,23 +200,28 @@ void setCompatFlag(Compat flag) { g_eCompatFlags = static_cast<Compat>(g_eCompat
 
 bool isCompatFlagSet(Compat flag) { return (g_eCompatFlags & flag) == flag; }
 
-void setLanguageTag(const OUString& lang, bool bCanonicalize)
+void setLocale(const LanguageTag& rLanguageTag)
 {
-    g_aLanguageTag = LanguageTag(lang, bCanonicalize);
+    g_aLanguageAndLocale.setLocale(rLanguageTag);
 }
 
-void setLanguageTag(const LanguageTag& languageTag)
+const LanguageTag& getLocale()
 {
-    if (g_aLanguageTag != languageTag)
-    {
-        SAL_INFO("comphelper.lok", "setLanguageTag: from " << g_aLanguageTag.getBcp47() << " to " << languageTag.getBcp47());
-        g_aLanguageTag = languageTag;
-    }
+    const LanguageTag& rLocale = g_aLanguageAndLocale.getLocale();
+    SAL_WARN_IF(rLocale.getLanguageType() == LANGUAGE_NONE, "comphelper.lok", "Locale not set");
+    return rLocale;
+}
+
+void setLanguageTag(const LanguageTag& rLanguageTag)
+{
+    g_aLanguageAndLocale.setLanguage(rLanguageTag);
 }
 
 const LanguageTag& getLanguageTag()
 {
-    return g_aLanguageTag;
+    const LanguageTag& rLanguage = g_aLanguageAndLocale.getLanguage();
+    SAL_WARN_IF(rLanguage.getLanguageType() == LANGUAGE_NONE, "comphelper.lok", "Language not set");
+    return rLanguage;
 }
 
 bool isWhitelistedLanguage(const OUString& lang)
diff --git a/desktop/CppunitTest_desktop_lib.mk b/desktop/CppunitTest_desktop_lib.mk
index b25ab04bda8d..19c00b5d5e66 100644
--- a/desktop/CppunitTest_desktop_lib.mk
+++ b/desktop/CppunitTest_desktop_lib.mk
@@ -19,6 +19,7 @@ $(eval $(call gb_CppunitTest_use_libraries,desktop_lib, \
 	comphelper \
 	cppu \
 	cppuhelper \
+	i18nlangtag \
 	sal \
 	sc \
 	scfilt \
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 1f3365faf2f9..101fdda65742 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -2729,7 +2729,7 @@ void DesktopLOKTest::testSpellcheckerMultiView()
     SvtSysLocaleOptions aSysLocaleOptions;
     aSysLocaleOptions.SetLocaleConfigString(aLangISO);
     aSysLocaleOptions.SetUILocaleConfigString(aLangISO);
-    comphelper::LibreOfficeKit::setLanguageTag(aLangISO, true);
+    comphelper::LibreOfficeKit::setLanguageTag(LanguageTag(aLangISO, true));
 
     auto aSavedSettings = Application::GetSettings();
     std::unique_ptr<Resetter> pResetter(
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index aa6452e3d2cd..40abb74cd060 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -47,6 +47,7 @@
 #include <rtl/bootstrap.hxx>
 #include <rtl/strbuf.hxx>
 #include <rtl/uri.hxx>
+#include <svl/zforlist.hxx>
 #include <cppuhelper/bootstrap.hxx>
 #include <comphelper/base64.hxx>
 #include <comphelper/dispatchcommand.hxx>
@@ -2085,6 +2086,14 @@ void paintTileIOS(LibreOfficeKitDocument* pThis,
 }
 #endif
 
+void setLanguageAndLocale(OUString const & aLangISO)
+{
+    SvtSysLocaleOptions aLocalOptions;
+    aLocalOptions.SetLocaleConfigString(aLangISO);
+    aLocalOptions.SetUILocaleConfigString(aLangISO);
+    aLocalOptions.Commit();
+}
+
 } // anonymous namespace
 
 // Wonder global state ...
@@ -2141,13 +2150,17 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
 
         if (!aLanguage.isEmpty())
         {
+            SfxLokHelper::setDefaultLanguage(aLanguage);
+            // Set the LOK language tag, used for dialog tunneling.
+            comphelper::LibreOfficeKit::setLanguageTag(LanguageTag(aLanguage));
+            comphelper::LibreOfficeKit::setLocale(LanguageTag(aLanguage));
+
+            SAL_INFO("lok", "Set document language to " << aLanguage);
             // use with care - it sets it for the entire core, not just the
             // document
-            SvtSysLocaleOptions aSysLocaleOptions;
-            aSysLocaleOptions.SetLocaleConfigString(aLanguage);
-            aSysLocaleOptions.SetUILocaleConfigString(aLanguage);
-            // Set the LOK language tag, used for dialog tunneling.
-            comphelper::LibreOfficeKit::setLanguageTag(aSysLocaleOptions.GetLanguageTag());
+            setLanguageAndLocale(aLanguage);
+            // Need to reset the static initialized values
+            SvNumberFormatter::resetTheCurrencyTable();
         }
 
         uno::Sequence<css::beans::PropertyValue> aFilterOptions(2);
@@ -4865,6 +4878,7 @@ static int doc_createViewWithOptions(LibreOfficeKitDocument* pThis,
     {
         // Set the LOK language tag, used for dialog tunneling.
         comphelper::LibreOfficeKit::setLanguageTag(LanguageTag(aLanguage));
+        comphelper::LibreOfficeKit::setLocale(LanguageTag(aLanguage));
     }
 
     int nId = SfxLokHelper::createView();
@@ -4942,7 +4956,9 @@ static void doc_setViewLanguage(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*p
     SolarMutexGuard aGuard;
     SetLastExceptionMsg();
 
-    SfxLokHelper::setViewLanguage(nId, OStringToOUString(language, RTL_TEXTENCODING_UTF8));
+    OUString sLanguage = OStringToOUString(language, RTL_TEXTENCODING_UTF8);
+    SfxLokHelper::setViewLanguage(nId, sLanguage);
+    SfxLokHelper::setViewLocale(nId, sLanguage);
 }
 
 
@@ -5491,15 +5507,6 @@ static char* lo_getVersionInfo(SAL_UNUSED_PARAMETER LibreOfficeKit* /*pThis*/)
     return convertOUString(ReplaceStringHookProc(sVersionStrTemplate));
 }
 
-static void force_c_locale()
-{
-    // force locale (and resource files loaded) to en-US
-    OUString aLangISO("en-US");
-    SvtSysLocaleOptions aLocalOptions;
-    aLocalOptions.SetLocaleConfigString(aLangISO);
-    aLocalOptions.SetUILocaleConfigString(aLangISO);
-}
-
 static void aBasicErrorFunc(const OUString& rError, const OUString& rAction)
 {
     OStringBuffer aBuffer("Unexpected dialog: ");
@@ -5966,7 +5973,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
                 Application::ReleaseSolarMutex();
             }
 
-            force_c_locale();
+            setLanguageAndLocale("en-US");
         }
 
         if (eStage != PRE_INIT)
diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx
index 53ee43f498db..ca875b8df4a2 100644
--- a/include/comphelper/lok.hxx
+++ b/include/comphelper/lok.hxx
@@ -94,8 +94,11 @@ COMPHELPER_DLLPUBLIC bool isViewIdForVisCursorInvalidation();
 /// Set whether clients want viewId in visible cursor invalidation payload.
 COMPHELPER_DLLPUBLIC void setViewIdForVisCursorInvalidation(bool bViewIdForVisCursorInvalidation);
 
-/// Update the current LOK's language.
-COMPHELPER_DLLPUBLIC void setLanguageTag(const OUString& lang, bool bCanonicalize = false);
+/// Update the current LOK's locale.
+COMPHELPER_DLLPUBLIC void setLocale(const LanguageTag& languageTag);
+/// Get the current LOK's locale.
+COMPHELPER_DLLPUBLIC const LanguageTag& getLocale();
+
 /// Update the current LOK's language.
 COMPHELPER_DLLPUBLIC void setLanguageTag(const LanguageTag& languageTag);
 /// Get the current LOK's language.
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index aa2ceee950ba..8f2fa97a38f7 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -55,8 +55,14 @@ public:
     static std::size_t getViewsCount();
     /// Get viewIds of all existing views.
     static bool getViewIds(int* pArray, size_t nSize);
+    /// Get the default language that should be used for views
+    static LanguageTag getDefaultLanguage();
     /// Set language of the given view.
     static void setViewLanguage(int nId, const OUString& rBcp47LanguageTag);
+    /// Set the default language for views.
+    static void setDefaultLanguage(const OUString& rBcp47LanguageTag);
+    /// Set the locale for the given view.
+    static void setViewLocale(int nId, const OUString& rBcp47LanguageTag);
     /// Iterate over any view shell, except pThisViewShell, passing it to the f function.
     template<typename ViewShellType, typename FunctionType>
     static void forEachOtherView(ViewShellType* pThisViewShell, FunctionType f);
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index 0f6915d8a9c0..376b55911be8 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -155,6 +155,7 @@ friend class SfxPrinterController;
     bool                        bNoNewWindow;
     bool                        mbPrinterSettingsModified;
     LanguageTag                 maLOKLanguageTag;
+    LanguageTag                 maLOKLocale;
 
 protected:
     virtual void                Activate(bool IsMDIActivate) override;
@@ -347,6 +348,11 @@ public:
     void SetLOKLanguageTag(const OUString& rBcp47LanguageTag);
     /// Get the LibreOfficeKit language of this view.
     const LanguageTag& GetLOKLanguageTag() const { return maLOKLanguageTag; }
+
+    /// Set the LibreOfficeKit locale of this view.
+    void SetLOKLocale(const OUString& rBcp47LanguageTag);
+    /// Get the LibreOfficeKit locale of this view.
+    const LanguageTag& GetLOKLocale() const { return maLOKLocale; }
 };
 
 
diff --git a/include/svl/zforlist.hxx b/include/svl/zforlist.hxx
index 0a12e88ae3ac..0eebf6930b8a 100644
--- a/include/svl/zforlist.hxx
+++ b/include/svl/zforlist.hxx
@@ -721,6 +721,8 @@ public:
     /// Return the decimal separator matching the given locale / LanguageType.
     OUString GetLangDecimalSep( LanguageType nLang ) const;
 
+    static void resetTheCurrencyTable();
+
     /// Return a NfCurrencyTable with pointers to <type>NfCurrencyEntry</type> entries
     static const NfCurrencyTable& GetTheCurrencyTable();
 
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 1ba7d96268d9..012ee8cf633d 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -58,6 +58,11 @@ private:
 
 int DisableCallbacks::m_nDisabled = 0;
 
+namespace
+{
+static LanguageTag g_defaultLanguageTag("en-US", true);
+}
+
 int SfxLokHelper::createView()
 {
     SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst();
@@ -107,8 +112,9 @@ void SfxLokHelper::setView(int nId)
         {
             DisableCallbacks dc;
 
-            // update the current LOK language for the dialog tunneling
+            // update the current LOK language and locale for the dialog tunneling
             comphelper::LibreOfficeKit::setLanguageTag(pViewShell->GetLOKLanguageTag());
+            comphelper::LibreOfficeKit::setLocale(pViewShell->GetLOKLocale());
 
             if (pViewShell == SfxViewShell::Current())
                 return;
@@ -161,6 +167,16 @@ bool SfxLokHelper::getViewIds(int* pArray, size_t nSize)
     return true;
 }
 
+LanguageTag SfxLokHelper::getDefaultLanguage()
+{
+    return g_defaultLanguageTag;
+}
+
+void SfxLokHelper::setDefaultLanguage(const OUString& rBcp47LanguageTag)
+{
+    g_defaultLanguageTag = LanguageTag(rBcp47LanguageTag, true);
+}
+
 void SfxLokHelper::setViewLanguage(int nId, const OUString& rBcp47LanguageTag)
 {
     SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
@@ -175,6 +191,20 @@ void SfxLokHelper::setViewLanguage(int nId, const OUString& rBcp47LanguageTag)
     }
 }
 
+void SfxLokHelper::setViewLocale(int nId, const OUString& rBcp47LanguageTag)
+{
+    SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
+
+    for (SfxViewShell* pViewShell : rViewArr)
+    {
+        if (pViewShell->GetViewShellId() == ViewShellId(nId))
+        {
+            pViewShell->SetLOKLocale(rBcp47LanguageTag);
+            return;
+        }
+    }
+}
+
 static OString lcl_escapeQuotes(const OString &rStr)
 {
     if (rStr.getLength() < 1)
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 1a022e49f7b2..5ac368075d15 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -1067,7 +1067,8 @@ SfxViewShell::SfxViewShell
 ,   pWindow(nullptr)
 ,   bNoNewWindow( nFlags & SfxViewShellFlags::NO_NEWWINDOW )
 ,   mbPrinterSettingsModified(false)
-,   maLOKLanguageTag("en-US", true)
+,   maLOKLanguageTag(LANGUAGE_NONE)
+,   maLOKLocale(LANGUAGE_NONE)
 {
 
     SetMargin( pViewFrame->GetMargin_Impl() );
@@ -1081,6 +1082,9 @@ SfxViewShell::SfxViewShell
 
     if (comphelper::LibreOfficeKit::isActive())
     {
+        maLOKLanguageTag = SfxLokHelper::getDefaultLanguage();
+        maLOKLocale = SfxLokHelper::getDefaultLanguage();
+
         vcl::Window* pFrameWin = pViewFrame->GetWindow().GetFrameWindow();
         if (pFrameWin && !pFrameWin->GetLOKNotifier())
             pFrameWin->SetLOKNotifier(this, true);
@@ -1540,6 +1544,11 @@ void SfxViewShell::SetLOKLanguageTag(const OUString& rBcp47LanguageTag)
 #endif
 }
 
+void SfxViewShell::SetLOKLocale(const OUString& rBcp47LanguageTag)
+{
+    maLOKLocale = LanguageTag(rBcp47LanguageTag, true).makeFallback();
+}
+
 void SfxViewShell::NotifyCursor(SfxViewShell* /*pViewShell*/) const
 {
 }
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index 68e9ef12e1ba..15a24f0d3b13 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -3334,6 +3334,16 @@ sal_uInt16 SvNumberFormatter::GetYear2000Default()
     return 1930;
 }
 
+// static
+void SvNumberFormatter::resetTheCurrencyTable()
+{
+    SAL_INFO("svl", "Resetting the currency table.");
+
+    nSystemCurrencyPosition = 0;
+    bCurrencyTableInitialized = false;
+
+    GetFormatterRegistry().ConfigurationChanged(nullptr, ConfigurationHints::Locale | ConfigurationHints::Currency | ConfigurationHints::DatePatterns);
+}
 
 // static
 const NfCurrencyTable& SvNumberFormatter::GetTheCurrencyTable()
diff --git a/unotools/source/misc/syslocale.cxx b/unotools/source/misc/syslocale.cxx
index c9a11e7d817d..4b0040fa85cc 100644
--- a/unotools/source/misc/syslocale.cxx
+++ b/unotools/source/misc/syslocale.cxx
@@ -172,7 +172,7 @@ SvtSysLocaleOptions& SvtSysLocale::GetOptions() const
 const LanguageTag& SvtSysLocale::GetLanguageTag() const
 {
     if (comphelper::LibreOfficeKit::isActive())
-        return comphelper::LibreOfficeKit::getLanguageTag();
+        return comphelper::LibreOfficeKit::getLocale();
 
     return pImpl->aSysLocaleOptions.GetRealLanguageTag();
 }


More information about the Libreoffice-commits mailing list