sd/source/core/drawdoc.cxx | 14 +++++++++++- sd/source/ui/app/sdmod.cxx | 12 ----------- sd/source/ui/app/sdmod1.cxx | 36 ++++++++++++++++++++++++++++----- sd/source/ui/app/sdmod2.cxx | 48 +++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 88 insertions(+), 22 deletions(-)
New commits: commit 055e7d866680390dca6e18864ca4297cc0ebda84 Author: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de> AuthorDate: Tue Apr 23 20:04:43 2024 +0200 Commit: Thorsten Behrens <thorsten.behr...@allotropia.de> CommitDate: Thu May 9 00:30:52 2024 +0200 Use less SdOptionsLayout->GetMetric/SetMetric in favor of officecfg Change-Id: I12c9f69e0db1bf3e726b7d642e9a6855b031d3b9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166597 Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de> Tested-by: Jenkins diff --git a/sd/source/core/drawdoc.cxx b/sd/source/core/drawdoc.cxx index 5def1937684d..b759f9b4e883 100644 --- a/sd/source/core/drawdoc.cxx +++ b/sd/source/core/drawdoc.cxx @@ -36,6 +36,7 @@ #include <unotools/configmgr.hxx> #include <unotools/useroptions.hxx> #include <officecfg/Office/Impress.hxx> +#include <officecfg/Office/Draw.hxx> #include <sfx2/linkmgr.hxx> #include <Outliner.hxx> @@ -53,6 +54,8 @@ #include <unotools/charclass.hxx> #include <comphelper/processfactory.hxx> #include <unotools/lingucfg.hxx> +#include <unotools/localedatawrapper.hxx> +#include <unotools/syslocale.hxx> #include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/xml/dom/XDocumentBuilder.hpp> #include <com/sun/star/xml/dom/XDocument.hpp> @@ -156,12 +159,19 @@ SdDrawDocument::SdDrawDocument(DocumentType eType, SfxObjectShell* pDrDocSh) sal_Int32 nX, nY; SdOptions* pOptions = SD_MOD()->GetSdOptions(meDocType); pOptions->GetScale( nX, nY ); + SvtSysLocale aSysLocale; // Allow UI scale only for draw documents. if( eType == DocumentType::Draw ) - SetUIUnit( static_cast<FieldUnit>(pOptions->GetMetric()), Fraction( nX, nY ) ); // user-defined + if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric) + SetUIUnit( static_cast<FieldUnit>(officecfg::Office::Draw::Layout::Other::MeasureUnit::Metric::get()), Fraction( nX, nY ) ); // user-defined + else + SetUIUnit( static_cast<FieldUnit>(officecfg::Office::Draw::Layout::Other::MeasureUnit::NonMetric::get()), Fraction( nX, nY ) ); // user-defined else - SetUIUnit( static_cast<FieldUnit>(pOptions->GetMetric()), Fraction( 1, 1 ) ); // default + if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric) + SetUIUnit( static_cast<FieldUnit>(officecfg::Office::Impress::Layout::Other::MeasureUnit::Metric::get()), Fraction( 1, 1 ) ); // default + else + SetUIUnit( static_cast<FieldUnit>(officecfg::Office::Impress::Layout::Other::MeasureUnit::NonMetric::get()), Fraction( 1, 1 ) ); // default SetScaleUnit(MapUnit::Map100thMM); SetDefaultFontHeight(o3tl::convert(24, o3tl::Length::pt, o3tl::Length::mm100)); diff --git a/sd/source/ui/app/sdmod.cxx b/sd/source/ui/app/sdmod.cxx index f18dd647a209..d534fe51aa23 100644 --- a/sd/source/ui/app/sdmod.cxx +++ b/sd/source/ui/app/sdmod.cxx @@ -141,18 +141,6 @@ SdOptions* SdModule::GetSdOptions(DocumentType eDocType) pOptions = pImpressOptions; } - if( pOptions ) - { - sal_uInt16 nMetric = pOptions->GetMetric(); - - ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); - SdDrawDocument* pDoc = nullptr; - if (pDocSh) - pDoc = pDocSh->GetDoc(); - - if( nMetric != 0xffff && pDoc && eDocType == pDoc->GetDocumentType() ) - PutItem( SfxUInt16Item( SID_ATTR_METRIC, nMetric ) ); - } return pOptions; } diff --git a/sd/source/ui/app/sdmod1.cxx b/sd/source/ui/app/sdmod1.cxx index 14f507fb1a1d..023e44a7c1e6 100644 --- a/sd/source/ui/app/sdmod1.cxx +++ b/sd/source/ui/app/sdmod1.cxx @@ -21,7 +21,9 @@ #include <svl/intitem.hxx> #include <sfx2/frame.hxx> #include <sfx2/viewfrm.hxx> +#include <unotools/localedatawrapper.hxx> #include <unotools/moduleoptions.hxx> +#include <unotools/syslocale.hxx> #include <framework/FrameworkHelper.hxx> #include <osl/diagnose.h> #include <vcl/commandevent.hxx> @@ -53,6 +55,9 @@ #include <memory> #include <slideshow.hxx> +#include <officecfg/Office/Draw.hxx> +#include <officecfg/Office/Impress.hxx> + using ::sd::framework::FrameworkHelper; using ::com::sun::star::uno::Reference; using ::com::sun::star::frame::XFrame; @@ -126,9 +131,21 @@ void SdModule::Execute(SfxRequest& rReq) DocumentType eDocType = pDocSh->GetDoc()->GetDocumentType(); PutItem( *pItem ); - SdOptions* pOptions = GetSdOptions( eDocType ); - if(pOptions) - pOptions->SetMetric( static_cast<sal_uInt16>(eUnit) ); + SvtSysLocale aSysLocale; + std::shared_ptr<comphelper::ConfigurationChanges> batch( + comphelper::ConfigurationChanges::create()); + + if (eDocType == DocumentType::Impress) + if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric) + officecfg::Office::Impress::Layout::Other::MeasureUnit::Metric::set(static_cast<sal_uInt16>(eUnit), batch); + else + officecfg::Office::Impress::Layout::Other::MeasureUnit::NonMetric::set(static_cast<sal_uInt16>(eUnit), batch); + else + if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric) + officecfg::Office::Draw::Layout::Other::MeasureUnit::Metric::set(static_cast<sal_uInt16>(eUnit), batch); + else + officecfg::Office::Draw::Layout::Other::MeasureUnit::NonMetric::set(static_cast<sal_uInt16>(eUnit), batch); + batch->commit(); rReq.Done(); } } @@ -313,9 +330,18 @@ void SdModule::GetState(SfxItemSet& rItemSet) if(pDocSh) { DocumentType eDocType = pDocSh->GetDoc()->GetDocumentType(); + SvtSysLocale aSysLocale; - SdOptions* pOptions = GetSdOptions(eDocType); - rItemSet.Put( SfxUInt16Item( SID_ATTR_METRIC, pOptions->GetMetric() ) ); + if (eDocType == DocumentType::Impress) + if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric) + rItemSet.Put( SfxUInt16Item( SID_ATTR_METRIC, officecfg::Office::Impress::Layout::Other::MeasureUnit::Metric::get() ) ); + else + rItemSet.Put( SfxUInt16Item( SID_ATTR_METRIC, officecfg::Office::Impress::Layout::Other::MeasureUnit::NonMetric::get() ) ); + else + if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric) + rItemSet.Put( SfxUInt16Item( SID_ATTR_METRIC, officecfg::Office::Draw::Layout::Other::MeasureUnit::Metric::get() ) ); + else + rItemSet.Put( SfxUInt16Item( SID_ATTR_METRIC, officecfg::Office::Draw::Layout::Other::MeasureUnit::NonMetric::get() ) ); } } diff --git a/sd/source/ui/app/sdmod2.cxx b/sd/source/ui/app/sdmod2.cxx index 55b7d43ba3dc..9cec489e0338 100644 --- a/sd/source/ui/app/sdmod2.cxx +++ b/sd/source/ui/app/sdmod2.cxx @@ -24,6 +24,8 @@ #include <svl/inethist.hxx> #include <svl/poolitem.hxx> #include <svl/flagitem.hxx> +#include <unotools/localedatawrapper.hxx> +#include <unotools/syslocale.hxx> #include <unotools/useroptions.hxx> #include <sfx2/bindings.hxx> #include <sfx2/viewfrm.hxx> @@ -61,6 +63,9 @@ #include <sdabstdlg.hxx> #include <svl/intitem.hxx> +#include <officecfg/Office/Draw.hxx> +#include <officecfg/Office/Impress.hxx> + /** retrieves the page that is currently painted. This will only be the master page if the current drawn view only shows the master page*/ static SdPage* GetCurrentPage( sd::ViewShell const * pViewSh, EditFieldInfo const * pInfo, bool& bMasterView ) @@ -468,10 +473,20 @@ std::optional<SfxItemSet> SdModule::CreateItemSet( sal_uInt16 nSlot ) aRet.Put( SfxUInt16Item( SID_ATTR_DEFTABSTOP, nDefTab ) ); FieldUnit nMetric = FieldUnit(0xffff); + SvtSysLocale aSysLocale; if( pFrameView) nMetric = pDoc->GetUIUnit(); else - nMetric = static_cast<FieldUnit>(pOptions->GetMetric()); + if (eDocType == DocumentType::Impress) + if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric) + nMetric = static_cast<FieldUnit>(officecfg::Office::Impress::Layout::Other::MeasureUnit::Metric::get()); + else + nMetric = static_cast<FieldUnit>(officecfg::Office::Impress::Layout::Other::MeasureUnit::NonMetric::get()); + else + if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric) + nMetric = static_cast<FieldUnit>(officecfg::Office::Impress::Layout::Other::MeasureUnit::Metric::get()); + else + nMetric = static_cast<FieldUnit>(officecfg::Office::Impress::Layout::Other::MeasureUnit::NonMetric::get()); if( nMetric == FieldUnit(0xffff) ) nMetric = GetFieldUnit(); @@ -572,7 +587,22 @@ void SdModule::ApplyItemSet( sal_uInt16 nSlot, const SfxItemSet& rSet ) { if( pDoc && eDocType == pDoc->GetDocumentType() ) PutItem( *pItem ); - pOptions->SetMetric( pItem->GetValue() ); + + SvtSysLocale aSysLocale; + std::shared_ptr<comphelper::ConfigurationChanges> batch( + comphelper::ConfigurationChanges::create()); + if (eDocType == DocumentType::Impress) + if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric) + officecfg::Office::Impress::Layout::Other::MeasureUnit::Metric::set(pItem->GetValue(), batch); + else + officecfg::Office::Impress::Layout::Other::MeasureUnit::NonMetric::set(pItem->GetValue(), batch); + else + if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric) + officecfg::Office::Draw::Layout::Other::MeasureUnit::Metric::set(pItem->GetValue(), batch); + else + officecfg::Office::Draw::Layout::Other::MeasureUnit::NonMetric::set(pItem->GetValue(), batch); + batch->commit(); + } sal_uInt16 nDefTab = pOptions->GetDefTab(); // Default-Tabulator @@ -700,7 +730,19 @@ void SdModule::ApplyItemSet( sal_uInt16 nSlot, const SfxItemSet& rSet ) // Only if also the document type matches... if( pDocSh && pDoc && eDocType == pDoc->GetDocumentType() ) { - FieldUnit eUIUnit = static_cast<FieldUnit>(pOptions->GetMetric()); + FieldUnit eUIUnit; + SvtSysLocale aSysLocale; + if (eDocType == DocumentType::Impress) + if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric) + eUIUnit = static_cast<FieldUnit>(officecfg::Office::Impress::Layout::Other::MeasureUnit::Metric::get()); + else + eUIUnit = static_cast<FieldUnit>(officecfg::Office::Impress::Layout::Other::MeasureUnit::NonMetric::get()); + else + if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric) + eUIUnit = static_cast<FieldUnit>(officecfg::Office::Impress::Layout::Other::MeasureUnit::Metric::get()); + else + eUIUnit = static_cast<FieldUnit>(officecfg::Office::Impress::Layout::Other::MeasureUnit::NonMetric::get()); + pDoc->SetUIUnit(eUIUnit); if (pViewShell)