sfx2/source/appl/module.cxx                         |   14 +++++++++-----
 sfx2/source/dialog/mgetempl.cxx                     |    4 +---
 sfx2/source/sidebar/ControllerItem.cxx              |   12 ++++++++++++
 svx/source/sidebar/paragraph/ParaPropertyPanel.cxx  |    4 +---
 svx/source/sidebar/possize/PosSizePropertyPanel.cxx |    4 +---
 sw/source/uibase/sidebar/PageFormatPanel.cxx        |    4 +---
 6 files changed, 25 insertions(+), 17 deletions(-)

New commits:
commit 3ca938a25439d6f23bbd6830a96e5180ff94f757
Author:     Jaume Pujantell <jaume.pujant...@collabora.com>
AuthorDate: Fri Mar 8 16:24:11 2024 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Mar 11 09:17:21 2024 +0100

    lok: use locale units in dialogs and sidebar
    
    When oepning tha same doucment with different locales, the dailogs and
    sidebar show units (cm/inch) of the first locale (or the locale used in
    preloading, en-US) for all the views.
    
    This patch changes the units used according to the LOK locale.
    
    Change-Id: I3d515873bde661f2d9048bbc405843e83134cca7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164589
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sfx2/source/appl/module.cxx b/sfx2/source/appl/module.cxx
index 03f4fc2fa8f5..b610c2ee8e2a 100644
--- a/sfx2/source/appl/module.cxx
+++ b/sfx2/source/appl/module.cxx
@@ -32,6 +32,8 @@
 #include <comphelper/diagnose_ex.hxx>
 #include <unotools/resmgr.hxx>
 #include <sal/log.hxx>
+#include <comphelper/lok.hxx>
+#include <unotools/localedatawrapper.hxx>
 
 #define ShellClass_SfxModule
 #include <sfxslots.hxx>
@@ -245,11 +247,7 @@ FieldUnit SfxModule::GetCurrentFieldUnit()
     FieldUnit eUnit = FieldUnit::INCH;
     SfxModule* pModule = GetActiveModule();
     if ( pModule )
-    {
-        const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC );
-        if ( pItem )
-            eUnit = static_cast<FieldUnit>(static_cast<const 
SfxUInt16Item*>(pItem)->GetValue());
-    }
+        return pModule->GetFieldUnit();
     else
         SAL_WARN( "sfx.appl", "GetModuleFieldUnit(): no module found" );
     return eUnit;
@@ -257,6 +255,12 @@ FieldUnit SfxModule::GetCurrentFieldUnit()
 
 FieldUnit SfxModule::GetFieldUnit() const
 {
+    if (comphelper::LibreOfficeKit::isActive())
+    {
+        MeasurementSystem eSystem
+            = 
LocaleDataWrapper(comphelper::LibreOfficeKit::getLocale()).getMeasurementSystemEnum();
+        return MeasurementSystem::Metric == eSystem ? FieldUnit::CM : 
FieldUnit::INCH;
+    }
     FieldUnit eUnit = FieldUnit::INCH;
     const SfxPoolItem* pItem = GetItem( SID_ATTR_METRIC );
     if ( pItem )
diff --git a/sfx2/source/dialog/mgetempl.cxx b/sfx2/source/dialog/mgetempl.cxx
index a9b62452591e..7e9faad8dcd3 100644
--- a/sfx2/source/dialog/mgetempl.cxx
+++ b/sfx2/source/dialog/mgetempl.cxx
@@ -301,9 +301,7 @@ void SfxManageStyleSheetPage::SetDescriptionText_Impl()
     SfxModule* pModule = SfxModule::GetActiveModule();
     if ( pModule )
     {
-        const SfxPoolItem* pPoolItem = pModule->GetItem( SID_ATTR_METRIC );
-        if ( pPoolItem )
-            eFieldUnit = static_cast<FieldUnit>(static_cast<const 
SfxUInt16Item*>( pPoolItem )->GetValue());
+        eFieldUnit = pModule->GetFieldUnit();
     }
 
     switch ( eFieldUnit )
diff --git a/sfx2/source/sidebar/ControllerItem.cxx 
b/sfx2/source/sidebar/ControllerItem.cxx
index e02276ec0cdd..28248710f1a6 100644
--- a/sfx2/source/sidebar/ControllerItem.cxx
+++ b/sfx2/source/sidebar/ControllerItem.cxx
@@ -20,6 +20,11 @@
 #include <sfx2/sidebar/ControllerItem.hxx>
 
 #include <sfx2/bindings.hxx>
+#include <sfx2/sfxsids.hrc>
+#include <comphelper/lok.hxx>
+#include <unotools/localedatawrapper.hxx>
+#include <tools/fldunit.hxx>
+#include <svl/intitem.hxx>
 
 using namespace css;
 using namespace css::uno;
@@ -59,6 +64,13 @@ void ControllerItem::RequestUpdate()
 {
     std::unique_ptr<SfxPoolItem> pState;
     const SfxItemState eState (GetBindings().QueryState(GetId(), pState));
+    if (GetId() == SID_ATTR_METRIC && comphelper::LibreOfficeKit::isActive())
+    {
+        MeasurementSystem eSystem
+            = 
LocaleDataWrapper(comphelper::LibreOfficeKit::getLocale()).getMeasurementSystemEnum();
+        FieldUnit eUnit = MeasurementSystem::Metric == eSystem ? FieldUnit::CM 
: FieldUnit::INCH;
+        
static_cast<SfxUInt16Item*>(pState.get())->SetValue(static_cast<sal_uInt16>(eUnit));
+    }
     mrItemUpdateReceiver.NotifyItemUpdate(GetId(), eState, pState.get());
 }
 
diff --git a/svx/source/sidebar/paragraph/ParaPropertyPanel.cxx 
b/svx/source/sidebar/paragraph/ParaPropertyPanel.cxx
index 20e05096d6c4..8e88bdc2c656 100644
--- a/svx/source/sidebar/paragraph/ParaPropertyPanel.cxx
+++ b/svx/source/sidebar/paragraph/ParaPropertyPanel.cxx
@@ -374,9 +374,7 @@ FieldUnit ParaPropertyPanel::GetCurrentUnit( SfxItemState 
eState, const SfxPoolI
             SfxModule* pModule = pSh->GetModule();
             if ( pModule )
             {
-                const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC );
-                if ( pItem )
-                    eUnit = static_cast<FieldUnit>(static_cast<const 
SfxUInt16Item*>(pItem)->GetValue());
+                eUnit = pModule->GetFieldUnit();
             }
             else
             {
diff --git a/svx/source/sidebar/possize/PosSizePropertyPanel.cxx 
b/svx/source/sidebar/possize/PosSizePropertyPanel.cxx
index 18abfa1160e3..4b786a421ad3 100644
--- a/svx/source/sidebar/possize/PosSizePropertyPanel.cxx
+++ b/svx/source/sidebar/possize/PosSizePropertyPanel.cxx
@@ -921,9 +921,7 @@ FieldUnit PosSizePropertyPanel::GetCurrentUnit( 
SfxItemState eState, const SfxPo
             SfxModule* pModule = pSh->GetModule();
             if ( pModule )
             {
-                const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC );
-                if ( pItem )
-                    eUnit = static_cast<FieldUnit>(static_cast<const 
SfxUInt16Item*>(pItem)->GetValue());
+                eUnit = pModule->GetFieldUnit();
             }
             else
             {
diff --git a/sw/source/uibase/sidebar/PageFormatPanel.cxx 
b/sw/source/uibase/sidebar/PageFormatPanel.cxx
index fdfa9ce6616d..91a8a206e802 100644
--- a/sw/source/uibase/sidebar/PageFormatPanel.cxx
+++ b/sw/source/uibase/sidebar/PageFormatPanel.cxx
@@ -319,9 +319,7 @@ FieldUnit PageFormatPanel::GetCurrentUnit( SfxItemState 
eState, const SfxPoolIte
             SfxModule* pModule = pSh->GetModule();
             if ( pModule )
             {
-                const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC );
-                if ( pItem )
-                    eUnit = static_cast<FieldUnit>(static_cast<const 
SfxUInt16Item*>(pItem)->GetValue());
+                eUnit = pModule->GetFieldUnit();
             }
             else
             {

Reply via email to