tdf#83830: Use SpacingListBox in Header/Footer and Sidebar Wrap Panel

Change-Id: I80ea84b6eaabcf241b313d46695cffdd74174c08
Reviewed-on: https://gerrit.libreoffice.org/28104
Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
Tested-by: Katarina Behrens <Katarina.Behrens@cib.de>
diff --git a/include/svx/dialogs.hrc b/include/svx/dialogs.hrc
index 8e87be9..c7eb352 100644
--- a/include/svx/dialogs.hrc
+++ b/include/svx/dialogs.hrc
@@ -1084,9 +1084,10 @@
#define RID_SVXSTRARY_PAPERSIZE_STD      (RID_SVX_START + 1395)
#define RID_SVXSTRARY_PAPERSIZE_DRAW     (RID_SVX_START + 1396)
#define RID_SVXSTRARY_PAGE_NUMBERING     (RID_SVX_START + 1397)
#define RID_SVXSTRARY_SPACING            (RID_SVX_START + 1398)

// !!! IMPORTANT: consider and update RID_SVXSTR_NEXTFREE when introducing new RIDs for Strings !!!
#define RID_SVXSTR_NEXTFREE              (RID_SVX_START + 1398)
#define RID_SVXSTR_NEXTFREE              (RID_SVX_START + 1399)

// if we have _a_lot_ time, we should group the resource ids by type, instead
// of grouping them by semantics. The reason is that resource ids have to be
diff --git a/include/svx/spacinglistbox.hxx b/include/svx/spacinglistbox.hxx
new file mode 100644
index 0000000..eb8ebe4
--- /dev/null
+++ b/include/svx/spacinglistbox.hxx
@@ -0,0 +1,35 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_SVX_SPACINGLISTBOXHELPER_HXX
#define INCLUDED_SVX_SPACINGLISTBOXHELPER_HXX

#include <svx/svxdllapi.h>
#include <vcl/lstbox.hxx>

/// Custom Widget ListBox to hold entries for Spacing & Margin settings of Header/Footer
class SVX_DLLPUBLIC SpacingListBox : public ListBox
{
public:
    SpacingListBox( vcl::Window* pParent, WinBits nBits = WB_BORDER | WB_DROPDOWN );
    Size GetOptimalSize() const override;
};

#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/AllLangResTarget_svx.mk b/svx/AllLangResTarget_svx.mk
index d33f37d..c7ee81f 100644
--- a/svx/AllLangResTarget_svx.mk
+++ b/svx/AllLangResTarget_svx.mk
@@ -49,6 +49,7 @@ $(eval $(call gb_SrsTarget_add_files,svx/res,\
    svx/source/dialog/passwd.src \
    svx/source/dialog/prtqry.src \
    svx/source/dialog/ruler.src \
    svx/source/dialog/spacing.src \
    svx/source/dialog/sdstring.src \
    svx/source/dialog/srchdlg.src \
    svx/source/dialog/svxbmpnumvalueset.src \
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index 87b44e8..228c8f3 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -120,6 +120,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
    svx/source/dialog/langbox \
    svx/source/dialog/pagenumberlistbox \
    svx/source/dialog/papersizelistbox \
    svx/source/dialog/spacinglistbox \
    svx/source/dialog/stddlg \
    svx/source/dialog/svxdlg \
    svx/source/dialog/SvxNumOptionsTabPageHelper \
diff --git a/svx/source/dialog/spacing.src b/svx/source/dialog/spacing.src
new file mode 100644
index 0000000..f7e10ee
--- /dev/null
+++ b/svx/source/dialog/spacing.src
@@ -0,0 +1,16 @@
#include <svx/dialogs.hrc>

StringArray RID_SVXSTRARY_SPACING
{
    ItemList [ en-US ] =
    {
        < "None" ;                  0; > ;
        < "Extra Small (1/16\")";   91; > ;
        < "Small (1/8\")";         181; > ;
        < "Small Medium (1/4\")";  363; > ;
        < "Medium (3/8\")";        539; > ;
        < "Medium Large (1/2\")";  720; > ;
        < "Large (3/4\")";          1077; > ;
        < "Extra Large (1\")";   1440; > ;
    };
};
\ No newline at end of file
diff --git a/svx/source/dialog/spacinglistbox.cxx b/svx/source/dialog/spacinglistbox.cxx
new file mode 100644
index 0000000..363385f
--- /dev/null
+++ b/svx/source/dialog/spacinglistbox.cxx
@@ -0,0 +1,48 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#include <svx/dialogs.hrc>
#include <svx/dialmgr.hxx>
#include <svx/spacinglistbox.hxx>
#include <tools/resary.hxx>
#include <vcl/builderfactory.hxx>

SpacingListBox::SpacingListBox(vcl::Window* pParent, WinBits nStyle)
    : ListBox( pParent, nStyle)
{
    ResStringArray aSpacingAry( SVX_RES( RID_SVXSTRARY_SPACING ) );
    sal_uInt32 nCnt = aSpacingAry.Count();

    for ( sal_uInt32 i = 0; i < nCnt; ++i )
    {
        OUString aStr = aSpacingAry.GetString(i);
        sal_uInt16 nData = aSpacingAry.GetValue(i);
        sal_Int32 nPos = InsertEntry( aStr );
        SetEntryData( nPos, reinterpret_cast<void*>((sal_uLong)nData) );
    }
    SetDropDownLineCount(8);
    SelectEntryPos(0);
}

VCL_BUILDER_FACTORY(SpacingListBox);

Size SpacingListBox::GetOptimalSize() const
{
    return Size(150, ListBox::GetOptimalSize().Height());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/sidebar/PageFooterPanel.hxx b/sw/source/uibase/sidebar/PageFooterPanel.hxx
index 6738525..10d6459 100644
--- a/sw/source/uibase/sidebar/PageFooterPanel.hxx
+++ b/sw/source/uibase/sidebar/PageFooterPanel.hxx
@@ -43,6 +43,7 @@
#include <tools/fldunit.hxx>
#include <svl/poolitem.hxx>
#include <svl/eitem.hxx>
#include <svx/spacinglistbox.hxx>

namespace sw { namespace sidebar {

@@ -79,11 +80,11 @@ private:
    ::sfx2::sidebar::ControllerItem maFooterSpacingController;
    ::sfx2::sidebar::ControllerItem maFooterLayoutController;

    VclPtr<CheckBox>    mpFooterToggle;
    VclPtr<ListBox>     mpFooterSpacingLB;
    VclPtr<ListBox>     mpFooterLayoutLB;
    VclPtr<ListBox>     mpFooterMarginPresetLB;
    VclPtr<FixedText>   mpCustomEntry;
    VclPtr<CheckBox>           mpFooterToggle;
    VclPtr<SpacingListBox>     mpFooterSpacingLB;
    VclPtr<SpacingListBox>     mpFooterMarginPresetLB;
    VclPtr<ListBox>            mpFooterLayoutLB;
    VclPtr<FixedText>          mpCustomEntry;
    OUString aCustomEntry;

    void Initialize();
diff --git a/sw/source/uibase/sidebar/PageHeaderPanel.cxx b/sw/source/uibase/sidebar/PageHeaderPanel.cxx
index ae84c2e..c88960b 100644
--- a/sw/source/uibase/sidebar/PageHeaderPanel.cxx
+++ b/sw/source/uibase/sidebar/PageHeaderPanel.cxx
@@ -251,7 +251,6 @@ IMPL_LINK_NOARG_TYPED( PageHeaderPanel, HeaderSpacingHdl, ListBox&, void )
    mpHeaderSpacingItem->SetLower(nVal);
    GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER_SPACING,
                                                 SfxCallMode::RECORD, { mpHeaderSpacingItem.get() } );

}
IMPL_LINK_NOARG_TYPED( PageHeaderPanel, HeaderLayoutHdl, ListBox&, void )
{
diff --git a/sw/source/uibase/sidebar/PageHeaderPanel.hxx b/sw/source/uibase/sidebar/PageHeaderPanel.hxx
index 54b94e2..2cfde07 100644
--- a/sw/source/uibase/sidebar/PageHeaderPanel.hxx
+++ b/sw/source/uibase/sidebar/PageHeaderPanel.hxx
@@ -43,6 +43,7 @@
#include <tools/fldunit.hxx>
#include <svl/poolitem.hxx>
#include <svl/eitem.hxx>
#include <svx/spacinglistbox.hxx>

namespace sw { namespace sidebar {

@@ -79,11 +80,11 @@ private:
    ::sfx2::sidebar::ControllerItem maHeaderSpacingController;
    ::sfx2::sidebar::ControllerItem maHeaderLayoutController;

    VclPtr<CheckBox>    mpHeaderToggle;
    VclPtr<ListBox>     mpHeaderSpacingLB;
    VclPtr<ListBox>     mpHeaderLayoutLB;
    VclPtr<ListBox>     mpHeaderMarginPresetLB;
    VclPtr<FixedText>   mpCustomEntry;
    VclPtr<CheckBox>           mpHeaderToggle;
    VclPtr<SpacingListBox>     mpHeaderSpacingLB;
    VclPtr<SpacingListBox>     mpHeaderMarginPresetLB;
    VclPtr<ListBox>            mpHeaderLayoutLB;
    VclPtr<FixedText>          mpCustomEntry;
    OUString aCustomEntry;

    void Initialize();
diff --git a/sw/source/uibase/sidebar/WrapPropertyPanel.hxx b/sw/source/uibase/sidebar/WrapPropertyPanel.hxx
index 5dd4caa..a0a62a8 100644
--- a/sw/source/uibase/sidebar/WrapPropertyPanel.hxx
+++ b/sw/source/uibase/sidebar/WrapPropertyPanel.hxx
@@ -26,6 +26,7 @@
#include <sfx2/sidebar/ControllerItem.hxx>
#include <com/sun/star/frame/XFrame.hpp>
#include <vcl/lstbox.hxx>
#include <svx/spacinglistbox.hxx>

namespace sw { namespace sidebar {

@@ -65,7 +66,7 @@ namespace sw { namespace sidebar {
        VclPtr<RadioButton> mpRBIdealWrap;
        VclPtr<Button>      mpEditContour;
        VclPtr<CheckBox> mpEnableContour;
        VclPtr<ListBox>  mpSpacingLB;
        VclPtr<SpacingListBox>  mpSpacingLB;
        VclPtr<FixedText> mpCustomEntry;

        //Spacing
diff --git a/sw/uiconfig/swriter/ui/pagefooterpanel.ui b/sw/uiconfig/swriter/ui/pagefooterpanel.ui
index a709475..0297daf 100644
--- a/sw/uiconfig/swriter/ui/pagefooterpanel.ui
+++ b/sw/uiconfig/swriter/ui/pagefooterpanel.ui
@@ -2,48 +2,6 @@
<!-- Generated with glade 3.18.3 -->
<interface>
  <requires lib="gtk+" version="3.12"/>
  <object class="GtkListStore" id="spacinglist">
    <columns>
      <!-- column-name gchararray1 -->
      <column type="gchararray"/>
      <!-- column-name gint1 -->
      <column type="gint"/>
    </columns>
    <data>
      <row>
        <col id="0" translatable="yes">None</col>
        <col id="1">0</col>
      </row>
      <row>
        <col id="0" translatable="yes">Extra Small (0.16cm)</col>
        <col id="1">91</col>
      </row>
      <row>
        <col id="0" translatable="yes">Small (0.32cm)</col>
        <col id="1">181</col>
      </row>
      <row>
        <col id="0" translatable="yes">Small Medium (0.64cm)</col>
        <col id="1">363</col>
      </row>
      <row>
        <col id="0" translatable="yes">Medium (0.95cm)</col>
        <col id="1">539</col>
      </row>
      <row>
        <col id="0" translatable="yes">Medium Large (1.27cm)</col>
        <col id="1">720</col>
      </row>
      <row>
        <col id="0" translatable="yes">Large (1.9cm)</col>
        <col id="1">1077</col>
      </row>
      <row>
        <col id="0" translatable="yes">Extra Large (2.54cm)</col>
        <col id="1">1440</col>
      </row>
    </data>
  </object>
  <object class="GtkGrid" id="PageFooterPanel">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
@@ -131,8 +89,7 @@
          </packing>
        </child>
        <child>
          <object class="GtkComboBox" id="footermarginpreset">
            <property name="width_request">150</property>
          <object class="svxcorelo-SpacingListBox" id="footermarginpreset">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="halign">end</property>
@@ -144,8 +101,7 @@
          </packing>
        </child>
        <child>
          <object class="GtkComboBox" id="spacingpreset">
            <property name="width_request">150</property>
          <object class="svxcorelo-SpacingListBox" id="spacingpreset">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="halign">end</property>
diff --git a/sw/uiconfig/swriter/ui/pageheaderpanel.ui b/sw/uiconfig/swriter/ui/pageheaderpanel.ui
index 90bfb4f..ae0de28 100644
--- a/sw/uiconfig/swriter/ui/pageheaderpanel.ui
+++ b/sw/uiconfig/swriter/ui/pageheaderpanel.ui
@@ -2,48 +2,6 @@
<!-- Generated with glade 3.16.1 -->
<interface>
  <requires lib="gtk+" version="3.12"/>
  <object class="GtkListStore" id="spacinglist">
    <columns>
      <!-- column-name gchararray1 -->
      <column type="gchararray"/>
      <!-- column-name gint1 -->
      <column type="gint"/>
    </columns>
    <data>
      <row>
        <col id="0" translatable="yes">None</col>
        <col id="1">0</col>
      </row>
      <row>
        <col id="0" translatable="yes">Extra Small (0.16cm)</col>
        <col id="1">91</col>
      </row>
      <row>
        <col id="0" translatable="yes">Small (0.32cm)</col>
        <col id="1">181</col>
      </row>
      <row>
        <col id="0" translatable="yes">Small Medium (0.64cm)</col>
        <col id="1">363</col>
      </row>
      <row>
        <col id="0" translatable="yes">Medium (0.95cm)</col>
        <col id="1">539</col>
      </row>
      <row>
        <col id="0" translatable="yes">Medium Large (1.27cm)</col>
        <col id="1">720</col>
      </row>
      <row>
        <col id="0" translatable="yes">Large (1.9cm)</col>
        <col id="1">1077</col>
      </row>
      <row>
        <col id="0" translatable="yes">Extra Large (2.54cm)</col>
        <col id="1">1440</col>
      </row>
    </data>
  </object>
  <object class="GtkGrid" id="PageHeaderPanel">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
@@ -131,8 +89,7 @@
          </packing>
        </child>
        <child>
          <object class="GtkComboBox" id="headermarginpreset">
            <property name="width_request">150</property>
          <object class="svxcorelo-SpacingListBox" id="headermarginpreset">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="halign">end</property>
@@ -144,8 +101,7 @@
          </packing>
        </child>
        <child>
          <object class="GtkComboBox" id="spacingpreset">
            <property name="width_request">150</property>
          <object class="svxcorelo-SpacingListBox" id="spacingpreset">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="halign">end</property>
diff --git a/sw/uiconfig/swriter/ui/sidebarwrap.ui b/sw/uiconfig/swriter/ui/sidebarwrap.ui
index 0b9b2df..c846adf 100644
--- a/sw/uiconfig/swriter/ui/sidebarwrap.ui
+++ b/sw/uiconfig/swriter/ui/sidebarwrap.ui
@@ -2,48 +2,6 @@
<!-- Generated with glade 3.20.0 -->
<interface>
  <requires lib="gtk+" version="3.0"/>
  <object class="GtkListStore" id="spacinglist">
    <columns>
      <!-- column-name gchararray1 -->
      <column type="gchararray"/>
      <!-- column-name gint1 -->
      <column type="gint"/>
    </columns>
    <data>
      <row>
        <col id="0" translatable="yes">None</col>
        <col id="1">0</col>
      </row>
      <row>
        <col id="0" translatable="yes">Extra Small (0.16cm)</col>
        <col id="1">91</col>
      </row>
      <row>
        <col id="0" translatable="yes">Small (0.32cm)</col>
        <col id="1">181</col>
      </row>
      <row>
        <col id="0" translatable="yes">Small Medium (0.64cm)</col>
        <col id="1">363</col>
      </row>
      <row>
        <col id="0" translatable="yes">Medium (0.95cm)</col>
        <col id="1">539</col>
      </row>
      <row>
        <col id="0" translatable="yes">Medium Large (1.27cm)</col>
        <col id="1">720</col>
      </row>
      <row>
        <col id="0" translatable="yes">Large (1.9cm)</col>
        <col id="1">1077</col>
      </row>
      <row>
        <col id="0" translatable="yes">Extra Large (2.54cm)</col>
        <col id="1">1440</col>
      </row>
    </data>
  </object>
  <object class="GtkGrid" id="WrapPropertyPanel">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
@@ -68,7 +26,6 @@
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">False</property>
                <property name="tooltip_markup" translatable="yes">None</property>
                <property name="tooltip_text" translatable="yes">None</property>
                <property name="action_name">.uno:WrapOff</property>
                <property name="xalign">0</property>
@@ -92,7 +49,6 @@
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">False</property>
                <property name="tooltip_markup" translatable="yes">Parallel</property>
                <property name="tooltip_text" translatable="yes">Parallel</property>
                <property name="action_name">.uno:WrapOn</property>
                <property name="xalign">0</property>
@@ -116,7 +72,6 @@
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">False</property>
                <property name="tooltip_markup" translatable="yes">Optimal</property>
                <property name="tooltip_text" translatable="yes">Optimal</property>
                <property name="action_name">.uno:WrapIdeal</property>
                <property name="xalign">0</property>
@@ -140,7 +95,6 @@
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">False</property>
                <property name="tooltip_markup" translatable="yes">Before</property>
                <property name="tooltip_text" translatable="yes">Before</property>
                <property name="action_name">.uno:WrapLeft</property>
                <property name="xalign">0</property>
@@ -164,7 +118,6 @@
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">False</property>
                <property name="tooltip_markup" translatable="yes">After</property>
                <property name="tooltip_text" translatable="yes">After</property>
                <property name="action_name">.uno:WrapRight</property>
                <property name="xalign">0</property>
@@ -188,7 +141,6 @@
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">False</property>
                <property name="tooltip_markup" translatable="yes">Through</property>
                <property name="tooltip_text" translatable="yes">Through</property>
                <property name="action_name">.uno:WrapThrough</property>
                <property name="xalign">0</property>
@@ -224,7 +176,6 @@
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">False</property>
                <property name="tooltip_markup" translatable="yes">Click to automatically trim unnecessary parts of the image</property>
                <property name="tooltip_text" translatable="yes">Click to automatically trim unnecessary parts of the image</property>
                <property name="xalign">0</property>
                <property name="draw_indicator">True</property>
@@ -241,7 +192,6 @@
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="tooltip_markup" translatable="yes">Edit the trimmed area of the image</property>
                <property name="tooltip_text" translatable="yes">Edit the trimmed area of the image</property>
              </object>
              <packing>
@@ -275,12 +225,10 @@
              </packing>
            </child>
            <child>
              <object class="GtkComboBox" id="spacingLB">
              <object class="svxcorelo-SpacingListBox" id="spacingLB">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="tooltip_markup" translatable="yes">Set the amount of space between the image and surrounding text</property>
                <property name="tooltip_text" translatable="yes">Set the amount of space between the image and surrounding text</property>
                <property name="model">spacinglist</property>
              </object>
              <packing>
                <property name="expand">False</property>