[Libreoffice-commits] core.git: svx/source sw/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Mon Dec 9 21:26:57 UTC 2019


 svx/source/dialog/spacinglistbox.cxx         |    7 ++++
 sw/source/uibase/sidebar/PageFooterPanel.cxx |   39 ++++++++++++++++++++++++---
 sw/source/uibase/sidebar/PageFooterPanel.hxx |    6 ++++
 sw/source/uibase/sidebar/PageFormatPanel.cxx |   11 +++----
 sw/source/uibase/sidebar/PageFormatPanel.hxx |    2 -
 sw/source/uibase/sidebar/PageHeaderPanel.cxx |   38 ++++++++++++++++++++++++--
 sw/source/uibase/sidebar/PageHeaderPanel.hxx |    6 ++++
 7 files changed, 95 insertions(+), 14 deletions(-)

New commits:
commit fc280552a5ee0131a08aeea5ccfd8cb7b9a6225d
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Mon Dec 9 20:16:23 2019 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Mon Dec 9 22:25:34 2019 +0100

    Related: tdf#129267 change spacing unit when measurement unit changes
    
    Change-Id: I2407eb52a18dd06a51b49041df2035099c79c94a
    Reviewed-on: https://gerrit.libreoffice.org/84788
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/svx/source/dialog/spacinglistbox.cxx b/svx/source/dialog/spacinglistbox.cxx
index e0a508e9830a..85ebc624931c 100644
--- a/svx/source/dialog/spacinglistbox.cxx
+++ b/svx/source/dialog/spacinglistbox.cxx
@@ -29,6 +29,11 @@ SpacingListBox::SpacingListBox(vcl::Window* pParent)
 
 void SpacingListBox::Init(SpacingType eType)
 {
+    auto nSelected = GetSelectedEntryPos();
+    if (nSelected == LISTBOX_ENTRY_NOTFOUND)
+        nSelected = 0;
+    Clear();
+
     const std::pair<const char*, int>* pResources;
     switch (eType)
     {
@@ -57,7 +62,7 @@ void SpacingListBox::Init(SpacingType eType)
     }
 
     SetDropDownLineCount(8);
-    SelectEntryPos(0);
+    SelectEntryPos(nSelected);
 }
 
 VCL_BUILDER_FACTORY(SpacingListBox);
diff --git a/sw/source/uibase/sidebar/PageFooterPanel.cxx b/sw/source/uibase/sidebar/PageFooterPanel.cxx
index 08be58fa95c4..4cc0c62d0624 100644
--- a/sw/source/uibase/sidebar/PageFooterPanel.cxx
+++ b/sw/source/uibase/sidebar/PageFooterPanel.cxx
@@ -52,6 +52,12 @@ VclPtr<vcl::Window> PageFooterPanel::Create(
     return VclPtr<PageFooterPanel>::Create(pParent, rxFrame, pBindings);
 }
 
+void PageFooterPanel::SetMarginsAndSpacingFieldUnit()
+{
+    mpFooterSpacingLB->Init(IsInch(meFUnit) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM);
+    mpFooterMarginPresetLB->Init(IsInch(meFUnit) ? SpacingType::MARGINS_INCH : SpacingType::MARGINS_CM);
+}
+
 PageFooterPanel::PageFooterPanel(
     vcl::Window* pParent,
     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
@@ -59,9 +65,11 @@ PageFooterPanel::PageFooterPanel(
     PanelLayout(pParent, "PageFooterPanel", "modules/swriter/ui/pagefooterpanel.ui", rxFrame),
     mpBindings( pBindings ),
     maHFToggleController(SID_ATTR_PAGE_FOOTER, *pBindings, *this),
+    maMetricController(SID_ATTR_METRIC, *pBindings,*this),
     maFooterLRMarginController(SID_ATTR_PAGE_FOOTER_LRMARGIN, *pBindings, *this),
     maFooterSpacingController(SID_ATTR_PAGE_FOOTER_SPACING, *pBindings, *this),
     maFooterLayoutController(SID_ATTR_PAGE_FOOTER_LAYOUT, *pBindings, *this),
+    meFUnit(GetModuleFieldUnit()),
     aCustomEntry(),
     mpFooterItem( new SfxBoolItem(SID_ATTR_PAGE_FOOTER) ),
     mpFooterLRMarginItem( new SvxLongLRSpaceItem(0, 0, SID_ATTR_PAGE_FOOTER_LRMARGIN)),
@@ -70,11 +78,8 @@ PageFooterPanel::PageFooterPanel(
 {
     get(mpFooterToggle, "footertoggle");
     get(mpFooterSpacingLB, "spacingpreset");
-    FieldUnit eMetric = ::GetDfltMetric(false);
-    mpFooterSpacingLB->Init(IsInch(eMetric) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM);
     get(mpFooterLayoutLB, "samecontentLB");
     get(mpFooterMarginPresetLB, "footermarginpreset");
-    mpFooterMarginPresetLB->Init(IsInch(GetModuleFieldUnit()) ? SpacingType::MARGINS_INCH : SpacingType::MARGINS_CM);
     get(mpCustomEntry, "customlabel");
 
     Initialize();
@@ -88,6 +93,7 @@ PageFooterPanel::~PageFooterPanel()
 void PageFooterPanel::dispose()
 {
     mpFooterToggle.disposeAndClear();
+    maMetricController.dispose();
     mpFooterSpacingLB.disposeAndClear();
     mpFooterLayoutLB.disposeAndClear();
     mpFooterMarginPresetLB.disposeAndClear();
@@ -96,14 +102,29 @@ void PageFooterPanel::dispose()
     PanelLayout::dispose();
 }
 
+FieldUnit PageFooterPanel::GetCurrentUnit(SfxItemState eState, const SfxPoolItem* pState)
+{
+    FieldUnit eUnit;
+
+    if (pState && eState >= SfxItemState::DEFAULT)
+        eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pState)->GetValue());
+    else
+        eUnit = GetModuleFieldUnit();
+
+    return eUnit;
+}
+
 void PageFooterPanel::Initialize()
 {
+    SetMarginsAndSpacingFieldUnit();
+
     aCustomEntry = mpCustomEntry->GetText();
     mpFooterToggle->SetClickHdl( LINK(this, PageFooterPanel, FooterToggleHdl) );
     mpFooterMarginPresetLB->SetSelectHdl( LINK(this, PageFooterPanel, FooterLRMarginHdl));
     mpFooterSpacingLB->SetSelectHdl( LINK(this, PageFooterPanel, FooterSpacingHdl));
     mpFooterLayoutLB->SetSelectHdl( LINK(this, PageFooterPanel, FooterLayoutHdl));
 
+    mpBindings->Invalidate(SID_ATTR_METRIC);
     mpBindings->Invalidate(SID_ATTR_PAGE_FOOTER);
     mpBindings->Invalidate(SID_ATTR_PAGE_FOOTER_LRMARGIN);
     mpBindings->Invalidate(SID_ATTR_PAGE_FOOTER_SPACING);
@@ -221,6 +242,18 @@ void PageFooterPanel::NotifyItemUpdate(
             }
         }
         break;
+        case SID_ATTR_METRIC:
+        {
+            FieldUnit eFUnit = GetCurrentUnit(eState, pState);
+            if (meFUnit != eFUnit)
+            {
+                meFUnit = eFUnit;
+                SetMarginsAndSpacingFieldUnit();
+                UpdateSpacingControl();
+                UpdateMarginControl();
+            }
+        }
+        break;
         default:
             break;
     }
diff --git a/sw/source/uibase/sidebar/PageFooterPanel.hxx b/sw/source/uibase/sidebar/PageFooterPanel.hxx
index 3b608cbf0b5d..d41789ecad67 100644
--- a/sw/source/uibase/sidebar/PageFooterPanel.hxx
+++ b/sw/source/uibase/sidebar/PageFooterPanel.hxx
@@ -67,10 +67,13 @@ private:
     SfxBindings* mpBindings;
 
     ::sfx2::sidebar::ControllerItem maHFToggleController;
+    ::sfx2::sidebar::ControllerItem maMetricController;
     ::sfx2::sidebar::ControllerItem maFooterLRMarginController;
     ::sfx2::sidebar::ControllerItem maFooterSpacingController;
     ::sfx2::sidebar::ControllerItem maFooterLayoutController;
 
+    FieldUnit meFUnit;
+
     VclPtr<CheckBox>           mpFooterToggle;
     VclPtr<SpacingListBox>     mpFooterSpacingLB;
     VclPtr<SpacingListBox>     mpFooterMarginPresetLB;
@@ -79,6 +82,7 @@ private:
     OUString aCustomEntry;
 
     void Initialize();
+    void SetMarginsAndSpacingFieldUnit();
     void UpdateFooterCheck();
     void UpdateMarginControl();
     void UpdateSpacingControl();
@@ -89,6 +93,8 @@ private:
     ::std::unique_ptr<SvxLongULSpaceItem> mpFooterSpacingItem;
     ::std::unique_ptr<SfxInt16Item>       mpFooterLayoutItem;
 
+    static FieldUnit GetCurrentUnit(SfxItemState eState, const SfxPoolItem* pState);
+
     DECL_LINK( FooterToggleHdl, Button*, void );
     DECL_LINK( FooterLRMarginHdl, ListBox&, void);
     DECL_LINK( FooterSpacingHdl, ListBox&, void);
diff --git a/sw/source/uibase/sidebar/PageFormatPanel.cxx b/sw/source/uibase/sidebar/PageFormatPanel.cxx
index 459b7e5dd023..ecc8ff01b5c6 100644
--- a/sw/source/uibase/sidebar/PageFormatPanel.cxx
+++ b/sw/source/uibase/sidebar/PageFormatPanel.cxx
@@ -90,7 +90,6 @@ PageFormatPanel::PageFormatPanel(
     mpPageLRMarginItem( new SvxLongLRSpaceItem( 0, 0, SID_ATTR_PAGE_LRSPACE ) ),
     mpPageULMarginItem( new SvxLongULSpaceItem( 0, 0, SID_ATTR_PAGE_ULSPACE ) ),
     meFUnit(GetModuleFieldUnit()),
-    meLastFUnit(GetModuleFieldUnit()),
     meUnit(),
     aCustomEntry()
 {
@@ -154,8 +153,8 @@ void PageFormatPanel::Initialize()
     mpBindings->Update(SID_ATTR_METRIC);
     mpBindings->Update(SID_ATTR_PAGE);
     mpBindings->Update(SID_ATTR_PAGE_SIZE);
-    mpBindings->Update( SID_ATTR_PAGE_LRSPACE );
-    mpBindings->Update( SID_ATTR_PAGE_ULSPACE );
+    mpBindings->Update(SID_ATTR_PAGE_LRSPACE);
+    mpBindings->Update(SID_ATTR_PAGE_ULSPACE);
 
     UpdateMarginBox();
 }
@@ -190,15 +189,15 @@ void PageFormatPanel::NotifyItemUpdate(
         case SID_ATTR_METRIC:
         {
             meUnit = maPaperSizeController.GetCoreMetric();
-            meFUnit = GetCurrentUnit(eState, pState);
-            if(meFUnit != meLastFUnit)
+            FieldUnit eFUnit = GetCurrentUnit(eState, pState);
+            if (eFUnit != meFUnit)
             {
+                meFUnit = eFUnit;
                 SetFieldUnit( *mpPaperHeight, meFUnit );
                 SetFieldUnit( *mpPaperWidth, meFUnit );
                 SetMarginFieldUnit();
                 UpdateMarginBox();
             }
-            meLastFUnit = meFUnit;
         }
         break;
         case SID_ATTR_PAGE:
diff --git a/sw/source/uibase/sidebar/PageFormatPanel.hxx b/sw/source/uibase/sidebar/PageFormatPanel.hxx
index b6eaae68853e..1df56eccae92 100644
--- a/sw/source/uibase/sidebar/PageFormatPanel.hxx
+++ b/sw/source/uibase/sidebar/PageFormatPanel.hxx
@@ -84,7 +84,7 @@ private:
     std::unique_ptr<SvxLongLRSpaceItem> mpPageLRMarginItem;
     std::unique_ptr<SvxLongULSpaceItem> mpPageULMarginItem;
 
-    FieldUnit meFUnit, meLastFUnit;
+    FieldUnit meFUnit;
     MapUnit meUnit;
 
     long mnPageLeftMargin;
diff --git a/sw/source/uibase/sidebar/PageHeaderPanel.cxx b/sw/source/uibase/sidebar/PageHeaderPanel.cxx
index 5641eba0c3ae..557c27ff7428 100644
--- a/sw/source/uibase/sidebar/PageHeaderPanel.cxx
+++ b/sw/source/uibase/sidebar/PageHeaderPanel.cxx
@@ -54,6 +54,12 @@ VclPtr<vcl::Window> PageHeaderPanel::Create(
     return VclPtr<PageHeaderPanel>::Create(pParent, rxFrame, pBindings);
 }
 
+void PageHeaderPanel::SetMarginsAndSpacingFieldUnit()
+{
+    mpHeaderSpacingLB->Init(IsInch(meFUnit) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM);
+    mpHeaderMarginPresetLB->Init(IsInch(meFUnit) ? SpacingType::MARGINS_INCH : SpacingType::MARGINS_CM);
+}
+
 PageHeaderPanel::PageHeaderPanel(
     vcl::Window* pParent,
     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
@@ -62,9 +68,11 @@ PageHeaderPanel::PageHeaderPanel(
     PanelLayout(pParent, "PageHeaderPanel", "modules/swriter/ui/pageheaderpanel.ui", rxFrame),
     mpBindings( pBindings ),
     maHFToggleController(SID_ATTR_PAGE_HEADER, *pBindings, *this),
+    maMetricController(SID_ATTR_METRIC, *pBindings,*this),
     maHeaderLRMarginController(SID_ATTR_PAGE_HEADER_LRMARGIN, *pBindings, *this),
     maHeaderSpacingController(SID_ATTR_PAGE_HEADER_SPACING, *pBindings, *this),
     maHeaderLayoutController(SID_ATTR_PAGE_HEADER_LAYOUT, *pBindings, *this),
+    meFUnit(GetModuleFieldUnit()),
     aCustomEntry(),
     mpHeaderItem( new SfxBoolItem(SID_ATTR_PAGE_HEADER) ),
     mpHeaderLRMarginItem( new SvxLongLRSpaceItem(0, 0, SID_ATTR_PAGE_HEADER_LRMARGIN)),
@@ -73,11 +81,8 @@ PageHeaderPanel::PageHeaderPanel(
 {
     get(mpHeaderToggle, "headertoggle");
     get(mpHeaderSpacingLB, "spacingpreset");
-    FieldUnit eMetric = ::GetDfltMetric(false);
-    mpHeaderSpacingLB->Init(IsInch(eMetric) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM);
     get(mpHeaderLayoutLB, "samecontentLB");
     get(mpHeaderMarginPresetLB, "headermarginpreset");
-    mpHeaderMarginPresetLB->Init(IsInch(eMetric) ? SpacingType::MARGINS_INCH : SpacingType::MARGINS_CM);
     get(mpCustomEntry, "customlabel");
 
     Initialize();
@@ -99,14 +104,29 @@ void PageHeaderPanel::dispose()
     PanelLayout::dispose();
 }
 
+FieldUnit PageHeaderPanel::GetCurrentUnit(SfxItemState eState, const SfxPoolItem* pState)
+{
+    FieldUnit eUnit;
+
+    if (pState && eState >= SfxItemState::DEFAULT)
+        eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pState)->GetValue());
+    else
+        eUnit = GetModuleFieldUnit();
+
+    return eUnit;
+}
+
 void PageHeaderPanel::Initialize()
 {
+    SetMarginsAndSpacingFieldUnit();
+
     aCustomEntry = mpCustomEntry->GetText();
     mpHeaderToggle->SetClickHdl( LINK(this, PageHeaderPanel, HeaderToggleHdl) );
     mpHeaderMarginPresetLB->SetSelectHdl( LINK(this, PageHeaderPanel, HeaderLRMarginHdl));
     mpHeaderSpacingLB->SetSelectHdl( LINK(this, PageHeaderPanel, HeaderSpacingHdl));
     mpHeaderLayoutLB->SetSelectHdl( LINK(this, PageHeaderPanel, HeaderLayoutHdl));
 
+    mpBindings->Invalidate(SID_ATTR_METRIC);
     mpBindings->Invalidate(SID_ATTR_PAGE_HEADER);
     mpBindings->Invalidate(SID_ATTR_PAGE_HEADER_LRMARGIN);
     mpBindings->Invalidate(SID_ATTR_PAGE_HEADER_SPACING);
@@ -224,6 +244,18 @@ void PageHeaderPanel::NotifyItemUpdate(
             }
         }
         break;
+        case SID_ATTR_METRIC:
+        {
+            FieldUnit eFUnit = GetCurrentUnit(eState, pState);
+            if (meFUnit != eFUnit)
+            {
+                meFUnit = eFUnit;
+                SetMarginsAndSpacingFieldUnit();
+                UpdateSpacingControl();
+                UpdateMarginControl();
+            }
+        }
+        break;
         default:
             break;
     }
diff --git a/sw/source/uibase/sidebar/PageHeaderPanel.hxx b/sw/source/uibase/sidebar/PageHeaderPanel.hxx
index 09fa082639f2..3861b0203795 100644
--- a/sw/source/uibase/sidebar/PageHeaderPanel.hxx
+++ b/sw/source/uibase/sidebar/PageHeaderPanel.hxx
@@ -67,10 +67,13 @@ private:
     SfxBindings* mpBindings;
 
     ::sfx2::sidebar::ControllerItem maHFToggleController;
+    ::sfx2::sidebar::ControllerItem maMetricController;
     ::sfx2::sidebar::ControllerItem maHeaderLRMarginController;
     ::sfx2::sidebar::ControllerItem maHeaderSpacingController;
     ::sfx2::sidebar::ControllerItem maHeaderLayoutController;
 
+    FieldUnit meFUnit;
+
     VclPtr<CheckBox>           mpHeaderToggle;
     VclPtr<SpacingListBox>     mpHeaderSpacingLB;
     VclPtr<SpacingListBox>     mpHeaderMarginPresetLB;
@@ -79,6 +82,7 @@ private:
     OUString aCustomEntry;
 
     void Initialize();
+    void SetMarginsAndSpacingFieldUnit();
     void UpdateHeaderCheck();
     void UpdateMarginControl();
     void UpdateSpacingControl();
@@ -89,6 +93,8 @@ private:
     ::std::unique_ptr<SvxLongULSpaceItem> mpHeaderSpacingItem;
     ::std::unique_ptr<SfxInt16Item>       mpHeaderLayoutItem;
 
+    static FieldUnit GetCurrentUnit(SfxItemState eState, const SfxPoolItem* pState);
+
     DECL_LINK( HeaderToggleHdl, Button*, void );
     DECL_LINK( HeaderLRMarginHdl, ListBox&, void);
     DECL_LINK( HeaderSpacingHdl, ListBox&, void);


More information about the Libreoffice-commits mailing list