sc/inc/scmod.hxx                              |    1 +
 sc/qa/unit/tiledrendering/tiledrendering2.cxx |   17 +++++++++++++++++
 sc/source/ui/app/scmod.cxx                    |    9 ++++++++-
 sc/source/ui/view/cellsh3.cxx                 |    8 ++++----
 sfx2/source/view/viewsh.cxx                   |    6 ++++++
 5 files changed, 36 insertions(+), 5 deletions(-)

New commits:
commit 7881f4c18305a3e3b67a5f9f000a7999fe7647df
Author:     Jaume Pujantell <jaume.pujant...@collabora.com>
AuthorDate: Thu Apr 24 16:36:21 2025 +0200
Commit:     Jaume Pujantell <jaume.pujant...@collabora.com>
CommitDate: Tue Apr 29 11:22:08 2025 +0200

    cool#11739 lok: sc: change dialog units per user
    
    On lok different users might have different locales so they need
    different field units in their dialogues. Right now the metric used is
    always the one stored in the ScModule's AppOptions for all users.
    With this change, for lok SfxModule::GetFieldUnit is used because it
    already has the correct metric per lok user.
    
    Change-Id: If2b047874a26deecc7c43936ab267b75eae101e3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184567
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    (cherry picked from commit d01737cb12654f488bb88235cdc562d3cf68d7db)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184741
    Reviewed-by: Jaume Pujantell <jaume.pujant...@collabora.com>
    Tested-by: Jenkins

diff --git a/sc/inc/scmod.hxx b/sc/inc/scmod.hxx
index 087942e53aa9..d51e742003c4 100644
--- a/sc/inc/scmod.hxx
+++ b/sc/inc/scmod.hxx
@@ -186,6 +186,7 @@ public:
     svtools::ColorConfig&   GetColorConfig();
     static bool         IsLOKViewInDarkMode();
     SC_DLLPUBLIC SvtUserOptions& GetUserOptions();
+    SC_DLLPUBLIC FieldUnit GetMetric();
 
     void                ModifyOptions( const SfxItemSet& rOptSet );
 
diff --git a/sc/qa/unit/tiledrendering/tiledrendering2.cxx 
b/sc/qa/unit/tiledrendering/tiledrendering2.cxx
index b3625d3128e6..41fdcb17b936 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering2.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering2.cxx
@@ -19,6 +19,7 @@
 
 #include <sctestviewcallback.hxx>
 #include <docuno.hxx>
+#include <scmod.hxx>
 #include <tabvwsh.hxx>
 
 using namespace com::sun::star;
@@ -148,6 +149,22 @@ CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, 
testDecimalSeparatorInfo)
     CPPUNIT_ASSERT_EQUAL(std::string(","), aView1.decimalSeparator);
 }
 
+CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, testCool11739LocaleDialogFieldUnit)
+{
+    createDoc("empty.ods");
+    SfxViewShell* pView1 = SfxViewShell::Current();
+    pView1->SetLOKLocale(u"fr-FR"_ustr);
+
+    ScModule* pMod = ScModule::get();
+    FieldUnit eMetric = pMod->GetMetric();
+
+    // Without the fix, it fails with
+    // - Expected: 2
+    // - Actual  : 8
+    // where 2 is FieldUnit::CM and 8 is FieldUnit::INCH
+    CPPUNIT_ASSERT_EQUAL(FieldUnit::CM, eMetric);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/app/scmod.cxx b/sc/source/ui/app/scmod.cxx
index 84dfe7e4393c..e27ba3cd98f9 100644
--- a/sc/source/ui/app/scmod.cxx
+++ b/sc/source/ui/app/scmod.cxx
@@ -567,7 +567,7 @@ void ScModule::GetState( SfxItemSet& rSet )
                 rSet.Put( SfxUInt32Item( nWhich, 
GetAppOptions().GetStatusFunc() ) );
                 break;
             case SID_ATTR_METRIC:
-                rSet.Put( SfxUInt16Item( nWhich, 
sal::static_int_cast<sal_uInt16>(GetAppOptions().GetAppMetric()) ) );
+                rSet.Put(SfxUInt16Item(nWhich, 
sal::static_int_cast<sal_uInt16>(GetMetric())));
                 break;
             case SID_AUTOSPELL_CHECK:
                 rSet.Put( SfxBoolItem( nWhich, pTabViewShell->IsAutoSpell()) );
@@ -934,6 +934,13 @@ SvtUserOptions&  ScModule::GetUserOptions()
     return *m_pUserOptions;
 }
 
+FieldUnit ScModule::GetMetric()
+{
+    if (comphelper::LibreOfficeKit::isActive())
+        return SfxModule::GetFieldUnit();
+    return GetAppOptions().GetAppMetric();
+}
+
 LanguageType ScModule::GetOptDigitLanguage()
 {
     SvtCTLOptions::TextNumerals eNumerals = 
SvtCTLOptions::GetCTLTextNumerals();
diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx
index e70e73fd8255..97f1a1208c10 100644
--- a/sc/source/ui/view/cellsh3.cxx
+++ b/sc/source/ui/view/cellsh3.cxx
@@ -726,7 +726,7 @@ void ScCellShell::Execute( SfxRequest& rReq )
                 else
                 {
                     ScViewData& rData      = GetViewData();
-                    FieldUnit eMetric = pScMod->GetAppOptions().GetAppMetric();
+                    FieldUnit eMetric = pScMod->GetMetric();
                     sal_uInt16      nCurHeight = rData.GetDocument().
                                                 GetRowHeight( rData.GetCurY(),
                                                               rData.GetTabNo() 
);
@@ -769,7 +769,7 @@ void ScCellShell::Execute( SfxRequest& rReq )
                 }
                 else
                 {
-                    FieldUnit eMetric = pScMod->GetAppOptions().GetAppMetric();
+                    FieldUnit eMetric = pScMod->GetMetric();
 
                     ScAbstractDialogFactory* pFact = 
ScAbstractDialogFactory::Create();
                     VclPtr<AbstractScMetricInputDlg> 
pDlg(pFact->CreateScMetricInputDlg(
@@ -831,7 +831,7 @@ void ScCellShell::Execute( SfxRequest& rReq )
                 }
                 else
                 {
-                    FieldUnit eMetric = pScMod->GetAppOptions().GetAppMetric();
+                    FieldUnit eMetric = pScMod->GetMetric();
                     ScViewData& rData      = GetViewData();
                     sal_uInt16      nCurHeight = rData.GetDocument().
                                                 GetColWidth( rData.GetCurX(),
@@ -874,7 +874,7 @@ void ScCellShell::Execute( SfxRequest& rReq )
                 }
                 else
                 {
-                    FieldUnit eMetric = pScMod->GetAppOptions().GetAppMetric();
+                    FieldUnit eMetric = pScMod->GetMetric();
 
                     ScAbstractDialogFactory* pFact = 
ScAbstractDialogFactory::Create();
                     VclPtr<AbstractScMetricInputDlg> 
pDlg(pFact->CreateScMetricInputDlg(
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 49568571ac62..04a363fa0a10 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -3506,6 +3506,12 @@ void SfxViewShell::SetLOKAccessibilityState(bool 
bEnabled)
 void SfxViewShell::SetLOKLocale(const OUString& rBcp47LanguageTag)
 {
     maLOKLocale = LanguageTag(rBcp47LanguageTag, true).makeFallback();
+    if (this == Current())
+    {
+        // update the current LOK language and locale for the dialog tunneling
+        comphelper::LibreOfficeKit::setLanguageTag(GetLOKLanguageTag());
+        comphelper::LibreOfficeKit::setLocale(GetLOKLocale());
+    }
 }
 
 void SfxViewShell::NotifyCursor(SfxViewShell* /*pViewShell*/) const

Reply via email to