[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.3' - cui/source include/tools sfx2/source svtools/source tools/source vcl/inc vcl/source

Jan Holesovsky kendy at collabora.com
Thu Dec 14 10:33:33 UTC 2017


 cui/source/factory/cuiresmgr.cxx |   10 ++++++----
 include/tools/resmgr.hxx         |    3 +++
 sfx2/source/bastyp/sfxresid.cxx  |   21 ++++++++++-----------
 svtools/source/misc/svtresid.cxx |   11 ++++++-----
 tools/source/rc/resmgr.cxx       |    5 +++++
 vcl/inc/svdata.hxx               |    2 +-
 vcl/source/app/settings.cxx      |    6 ++++++
 vcl/source/app/svapp.cxx         |    3 +--
 vcl/source/app/svdata.cxx        |    8 ++++----
 vcl/source/app/svmain.cxx        |    6 +-----
 vcl/source/window/builder.cxx    |    9 +++------
 11 files changed, 46 insertions(+), 38 deletions(-)

New commits:
commit eaccbef4f4f9509152efb7613f2ff48a2d6e7a5e
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Dec 13 19:17:48 2017 +0100

    lokdialog: Allow switching language of some of the ResMgr's.
    
    This way, it is possible to have all the strings translated in dialogs even
    when different users use different languages.  [It was already possible
    to have different languages previously, but not everything in the dialog has
    switched - like the buttons at the bottom of the dialogs etc.]
    
    Change-Id: I29a5ae6d31a370eec60397884200b684ec1bf5b9
    Reviewed-on: https://gerrit.libreoffice.org/46417
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/cui/source/factory/cuiresmgr.cxx b/cui/source/factory/cuiresmgr.cxx
index e872f9dd9836..e61da43b6710 100644
--- a/cui/source/factory/cuiresmgr.cxx
+++ b/cui/source/factory/cuiresmgr.cxx
@@ -25,14 +25,16 @@
 // struct DialogsResMgr --------------------------------------------------
 ResMgr* CuiResMgr::GetResMgr()
 {
-    static ResMgr* pResMgr=nullptr;
+    static std::unique_ptr<ResMgr> pResMgr;
 
-    if ( !pResMgr )
+    const LanguageTag& rLocale = Application::GetSettings().GetUILanguageTag();
+
+    if (!pResMgr || pResMgr->GetLocale() != rLocale)
     {
-        pResMgr = ResMgr::CreateResMgr("cui", Application::GetSettings().GetUILanguageTag());
+        pResMgr.reset(ResMgr::CreateResMgr("cui", rLocale));
     }
 
-    return pResMgr;
+    return pResMgr.get();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/tools/resmgr.hxx b/include/tools/resmgr.hxx
index 024c745dbd23..0679818a0b8a 100644
--- a/include/tools/resmgr.hxx
+++ b/include/tools/resmgr.hxx
@@ -190,6 +190,9 @@ public:
     OUString            ReadString();
     OString             ReadByteString();
 
+    /// The locale of this ResMgr.
+    const LanguageTag&  GetLocale() const;
+
     static void         SetReadStringHook( ResHookProc pProc );
     static ResHookProc  GetReadStringHook();
     static void         SetDefaultLocale( const LanguageTag& rLocale );
diff --git a/sfx2/source/bastyp/sfxresid.cxx b/sfx2/source/bastyp/sfxresid.cxx
index fd3774f00767..40f02c4c3caa 100644
--- a/sfx2/source/bastyp/sfxresid.cxx
+++ b/sfx2/source/bastyp/sfxresid.cxx
@@ -17,32 +17,31 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-
 #include <sfx2/sfxresid.hxx>
-#include "tools/resmgr.hxx"
-
+#include <vcl/svapp.hxx>
+#include <vcl/settings.hxx>
+#include <tools/resmgr.hxx>
 
-static ResMgr* pMgr=nullptr;
+static std::unique_ptr<ResMgr> pMgr;
 
 SfxResId::SfxResId( sal_uInt16 nId ) :
-
     ResId( nId, *GetResMgr() )
 {
 }
 
 ResMgr* SfxResId::GetResMgr()
 {
-    if ( !pMgr )
-    {
-        pMgr = ResMgr::CreateResMgr("sfx");
-    }
+    const LanguageTag& rLocale = Application::GetSettings().GetUILanguageTag();
+
+    if (!pMgr || pMgr->GetLocale() != rLocale)
+        pMgr.reset(ResMgr::CreateResMgr("sfx", rLocale));
 
-    return pMgr;
+    return pMgr.get();
 }
 
 void SfxResId::DeleteResMgr()
 {
-    DELETEZ( pMgr );
+    pMgr.reset();
 }
 
 
diff --git a/svtools/source/misc/svtresid.cxx b/svtools/source/misc/svtresid.cxx
index 24906fd8eef5..e727d95ce461 100644
--- a/svtools/source/misc/svtresid.cxx
+++ b/svtools/source/misc/svtresid.cxx
@@ -22,15 +22,16 @@
 #include <vcl/svapp.hxx>
 #include <vcl/settings.hxx>
 
-static ResMgr* pMgr=nullptr;
+static std::unique_ptr<ResMgr> pMgr;
 
 namespace
 {
     ResMgr* getResMgr(const LanguageTag& aLocale)
     {
-        if (!pMgr)
-            pMgr = ResMgr::CreateResMgr("svt", aLocale );
-        return pMgr;
+        if (!pMgr || pMgr->GetLocale() != aLocale)
+            pMgr.reset(ResMgr::CreateResMgr("svt", aLocale));
+
+        return pMgr.get();
     }
 
     ResMgr* getResMgr()
@@ -46,7 +47,7 @@ SvtResId::SvtResId(sal_uInt16 nId) :
 
 void SvtResId::DeleteResMgr()
 {
-    DELETEZ( pMgr );
+    pMgr.reset();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/tools/source/rc/resmgr.cxx b/tools/source/rc/resmgr.cxx
index c97f3ab28fed..31c4765f0304 100644
--- a/tools/source/rc/resmgr.cxx
+++ b/tools/source/rc/resmgr.cxx
@@ -1386,6 +1386,11 @@ OString ResMgr::ReadByteString()
     return aRet;
 }
 
+const LanguageTag& ResMgr::GetLocale() const
+{
+    return pImpRes->aLocale;
+}
+
 void ResMgr::SetReadStringHook( ResHookProc pProc )
 {
     osl::Guard<osl::Mutex> aGuard( getResMgrMutex() );
diff --git a/vcl/inc/svdata.hxx b/vcl/inc/svdata.hxx
index 5ed1464787ac..0f44a3937f52 100644
--- a/vcl/inc/svdata.hxx
+++ b/vcl/inc/svdata.hxx
@@ -321,7 +321,7 @@ struct ImplSVData
     SalTimer*               mpSalTimer = nullptr;           // interface to sal event loop/timers
     SalI18NImeStatus*       mpImeStatus = nullptr;          // interface to ime status window
     SalSystem*              mpSalSystem = nullptr;          // SalSystem interface
-    ResMgr*                 mpResMgr = nullptr;             // SV-Resource-Manager
+    std::unique_ptr<ResMgr> mpResMgr;                       // SV-Resource-Manager
     sal_uInt64              mnTimerPeriod = 0;              // current timer period
     ImplSVAppData           maAppData;                      // indepen data for class Application
     ImplSVGDIData           maGDIData;                      // indepen data for Output classes
diff --git a/vcl/source/app/settings.cxx b/vcl/source/app/settings.cxx
index 94cc2a351493..dedc6bb84179 100644
--- a/vcl/source/app/settings.cxx
+++ b/vcl/source/app/settings.cxx
@@ -2889,6 +2889,9 @@ const LanguageTag& AllSettings::GetLanguageTag() const
         return aRet;
     }
 
+    if (comphelper::LibreOfficeKit::isActive())
+        return comphelper::LibreOfficeKit::getLanguageTag();
+
     // SYSTEM locale means: use settings from SvtSysLocale that is resolved
     if ( mxData->maLocale.isSystemLocale() )
         mxData->maLocale = mxData->maSysLocale.GetLanguageTag();
@@ -2904,6 +2907,9 @@ const LanguageTag& AllSettings::GetUILanguageTag() const
         return aRet;
     }
 
+    if (comphelper::LibreOfficeKit::isActive())
+        return comphelper::LibreOfficeKit::getLanguageTag();
+
     // the UILocale is never changed
     if ( mxData->maUILocale.isSystemLocale() )
         mxData->maUILocale = mxData->maSysLocale.GetUILanguageTag();
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index b30f765a17af..e08adff710e3 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -699,8 +699,7 @@ void Application::SetSettings( const AllSettings& rSettings )
         if( aOldSettings.GetUILanguageTag().getLanguageType() != rSettings.GetUILanguageTag().getLanguageType() &&
                 pSVData->mpResMgr )
         {
-            delete pSVData->mpResMgr;
-            pSVData->mpResMgr = nullptr;
+            pSVData->mpResMgr.reset();
         }
         ResMgr::SetDefaultLocale( rSettings.GetUILanguageTag() );
         *pSVData->maAppData.mpSettings = rSettings;
diff --git a/vcl/source/app/svdata.cxx b/vcl/source/app/svdata.cxx
index 81b70aada41a..5f38644c8a1d 100644
--- a/vcl/source/app/svdata.cxx
+++ b/vcl/source/app/svdata.cxx
@@ -162,10 +162,10 @@ vcl::Window *ImplGetDefaultContextWindow()
 ResMgr* ImplGetResMgr()
 {
     ImplSVData* pSVData = ImplGetSVData();
-    if ( !pSVData->mpResMgr )
+    LanguageTag aLocale(Application::GetSettings().GetUILanguageTag());
+    if (!pSVData->mpResMgr || pSVData->mpResMgr->GetLocale() != aLocale)
     {
-        LanguageTag aLocale( Application::GetSettings().GetUILanguageTag());
-        pSVData->mpResMgr = ResMgr::SearchCreateResMgr( "vcl", aLocale );
+        pSVData->mpResMgr.reset(ResMgr::SearchCreateResMgr("vcl", aLocale));
 
         static bool bMessageOnce = false;
         if( !pSVData->mpResMgr && ! bMessageOnce )
@@ -179,7 +179,7 @@ ResMgr* ImplGetResMgr()
             aBox->Execute();
         }
     }
-    return pSVData->mpResMgr;
+    return pSVData->mpResMgr.get();
 }
 
 ResId VclResId( sal_Int32 nId )
diff --git a/vcl/source/app/svmain.cxx b/vcl/source/app/svmain.cxx
index 2cd613727ab4..a74279686a43 100644
--- a/vcl/source/app/svmain.cxx
+++ b/vcl/source/app/svmain.cxx
@@ -565,11 +565,7 @@ void DeInitVCL()
     delete pSVData->maGDIData.mpScreenFontCache;
     pSVData->maGDIData.mpScreenFontCache = nullptr;
 
-    if ( pSVData->mpResMgr )
-    {
-        delete pSVData->mpResMgr;
-        pSVData->mpResMgr = nullptr;
-    }
+    pSVData->mpResMgr.reset();
 
     ResMgr::DestroyAllResMgr();
 
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 1809b7a8d711..5202bbfd0b29 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -195,13 +195,10 @@ VclBuilder::VclBuilder(vcl::Window *pParent, const OUString& sUIDir, const OUStr
 
     OUString sUri = sUIDir + sUIFile;
 
-    LanguageTag aLanguageTag = Application::GetSettings().GetUILanguageTag();
-    if (comphelper::LibreOfficeKit::isActive())
-        aLanguageTag = comphelper::LibreOfficeKit::getLanguageTag();
-
-    bool bEN_US = (aLanguageTag.getBcp47() == "en-US");
+    const LanguageTag& rLanguageTag = Application::GetSettings().GetUILanguageTag();
+    bool bEN_US = (rLanguageTag.getBcp47() == "en-US");
     if (!bEN_US)
-        loadTranslations(aLanguageTag, sUri);
+        loadTranslations(rLanguageTag, sUri);
 
     try
     {


More information about the Libreoffice-commits mailing list