tdf#130197 give paragraph and table panels column widths of 5 toolbutton widths

Change-Id: Iae4f10eef6b293731d22eec8dcbb85a07d3e6c11
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87462
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/include/svx/dlgctrl.hxx b/include/svx/dlgctrl.hxx
index eaa31a5..6625b06 100644
--- a/include/svx/dlgctrl.hxx
+++ b/include/svx/dlgctrl.hxx
@@ -417,6 +417,8 @@

SVX_DLLPUBLIC void limitWidthForSidebar(weld::SpinButton& rSpinButton);
SVX_DLLPUBLIC void limitWidthForSidebar(RelativeField& rMetricSpinButton);
//tdf#130197 Give this toolbar a width as if it had 5 standard toolbutton entries
SVX_DLLPUBLIC void padWidthForSidebar(weld::Toolbar& rToolbar, const css::uno::Reference<css::frame::XFrame>& rFrame);

#endif // INCLUDED_SVX_DLGCTRL_HXX

diff --git a/svx/UIConfig_svx.mk b/svx/UIConfig_svx.mk
index 3d52a83..56192ca 100644
--- a/svx/UIConfig_svx.mk
+++ b/svx/UIConfig_svx.mk
@@ -69,6 +69,7 @@
	svx/uiconfig/ui/interimdockparent \
	svx/uiconfig/ui/interimparent \
	svx/uiconfig/ui/linkwarndialog \
	svx/uiconfig/ui/measurewidthbar \
	svx/uiconfig/ui/mediaplayback \
	svx/uiconfig/ui/namespacedialog \
	svx/uiconfig/ui/numberingwindow \
diff --git a/svx/source/dialog/dlgctrl.cxx b/svx/source/dialog/dlgctrl.cxx
index b23970a..c9cb58c 100644
--- a/svx/source/dialog/dlgctrl.cxx
+++ b/svx/source/dialog/dlgctrl.cxx
@@ -22,6 +22,7 @@
#include <vcl/virdev.hxx>
#include <vcl/event.hxx>
#include <sfx2/dialoghelper.hxx>
#include <sfx2/weldutils.hxx>
#include <svx/relfld.hxx>
#include <svx/xlineit0.hxx>
#include <svx/xtable.hxx>
@@ -1465,4 +1466,23 @@
    limitWidthForSidebar(rSpinButton);
}

void padWidthForSidebar(weld::Toolbar& rToolbar, const css::uno::Reference<css::frame::XFrame>& rFrame)
{
    static int nColumnWidth = -1;
    static vcl::ImageType eSize;
    if (nColumnWidth != -1 && eSize != rToolbar.get_icon_size())
        nColumnWidth = -1;
    if (nColumnWidth == -1)
    {
        // use the, filled-in by dispatcher, width of measurewidth as the width
        // of a "standard" column in a two column panel
        std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(&rToolbar, "svx/ui/measurewidthbar.ui"));
        std::unique_ptr<weld::Toolbar> xToolbar(xBuilder->weld_toolbar("measurewidth"));
        std::unique_ptr<ToolbarUnoDispatcher> xDispatcher(new ToolbarUnoDispatcher(*xToolbar, rFrame));
        nColumnWidth = xToolbar->get_preferred_size().Width();
        eSize = rToolbar.get_icon_size();
    }
    rToolbar.set_size_request(nColumnWidth, -1);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/sidebar/paragraph/ParaPropertyPanel.cxx b/svx/source/sidebar/paragraph/ParaPropertyPanel.cxx
index 0a01b42..01dd638 100644
--- a/svx/source/sidebar/paragraph/ParaPropertyPanel.cxx
+++ b/svx/source/sidebar/paragraph/ParaPropertyPanel.cxx
@@ -445,6 +445,13 @@
      mpBindings(pBindings),
      mxSidebar(rxSidebar)
{
    // tdf#130197 We want to give this toolbar a width as if it had 5 entries
    // (the parent grid has homogeneous width set so both columns will have the
    // same width).  This ParaPropertyPanel is a default panel in writer, so
    // subsequent panels, e.g. the TableEditPanel panel can have up to 5
    // entries in each of its column and remain in alignment with this panel
    padWidthForSidebar(*mxTBxIndent, rxFrame);

    initial();
    m_aMetricCtl.RequestUpdate();
}
diff --git a/svx/uiconfig/ui/measurewidthbar.ui b/svx/uiconfig/ui/measurewidthbar.ui
new file mode 100644
index 0000000..ad96cc7
--- /dev/null
+++ b/svx/uiconfig/ui/measurewidthbar.ui
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface domain="svx">
  <requires lib="gtk+" version="3.18"/>
  <object class="GtkBox">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="orientation">vertical</property>
    <child>
      <object class="GtkToolbar" id="measurewidth">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="toolbar_style">icons</property>
        <property name="show_arrow">False</property>
        <property name="icon_size">2</property>
        <child>
          <object class="GtkToolButton" id=".uno:MergeCells">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="use_underline">True</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="homogeneous">True</property>
          </packing>
        </child>
        <child>
          <object class="GtkToolButton" id=".uno:SplitCell">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="use_underline">True</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="homogeneous">True</property>
          </packing>
        </child>
        <child>
          <object class="GtkToolButton" id=".uno:SplitTable">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="use_underline">True</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="homogeneous">True</property>
          </packing>
        </child>
        <child>
          <object class="GtkToolButton" id=".uno:DeleteColumns">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="use_underline">True</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="homogeneous">True</property>
          </packing>
        </child>
        <child>
          <object class="GtkToolButton" id=".uno:DeleteTable">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="use_underline">True</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="homogeneous">True</property>
          </packing>
        </child>
      </object>
      <packing>
        <property name="expand">False</property>
        <property name="fill">True</property>
        <property name="position">0</property>
      </packing>
    </child>
  </object>
</interface>
diff --git a/svx/uiconfig/ui/sidebarparagraph.ui b/svx/uiconfig/ui/sidebarparagraph.ui
index 2d3fb09..4e0a7df6 100644
--- a/svx/uiconfig/ui/sidebarparagraph.ui
+++ b/svx/uiconfig/ui/sidebarparagraph.ui
@@ -260,8 +260,6 @@
              <object class="GtkBox" id="box11">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="margin_left">4</property>
                <property name="margin_right">6</property>
                <property name="spacing">6</property>
                <child>
                  <object class="GtkImage" id="image6">
@@ -308,8 +306,6 @@
              <object class="GtkBox" id="box12">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="margin_left">4</property>
                <property name="margin_right">6</property>
                <property name="spacing">6</property>
                <child>
                  <object class="GtkImage" id="image7">
@@ -356,7 +352,6 @@
              <object class="GtkToolbar" id="linespacing">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="margin_left">1</property>
                <property name="toolbar_style">icons</property>
                <property name="show_arrow">False</property>
                <property name="icon_size">2</property>
@@ -462,8 +457,6 @@
              <object class="GtkBox" id="box14">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="margin_left">4</property>
                <property name="margin_right">6</property>
                <property name="spacing">6</property>
                <child>
                  <object class="GtkImage" id="image8">
@@ -510,8 +503,6 @@
              <object class="GtkBox" id="box15">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="margin_left">4</property>
                <property name="margin_right">6</property>
                <property name="spacing">6</property>
                <child>
                  <object class="GtkImage" id="image9">
@@ -558,8 +549,6 @@
              <object class="GtkBox" id="box16">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="margin_left">4</property>
                <property name="margin_right">6</property>
                <property name="spacing">6</property>
                <child>
                  <object class="GtkImage" id="image10">
diff --git a/sw/source/uibase/sidebar/TableEditPanel.cxx b/sw/source/uibase/sidebar/TableEditPanel.cxx
index dcca792..8f64722 100644
--- a/sw/source/uibase/sidebar/TableEditPanel.cxx
+++ b/sw/source/uibase/sidebar/TableEditPanel.cxx
@@ -131,6 +131,12 @@
    , m_aDistributeColumnsController(FN_TABLE_BALANCE_CELLS, *pBindings, *this)
    , m_aMergeCellsController(FN_TABLE_MERGE_CELLS, *pBindings, *this)
{
    // tdf#130197 Give this toolbar a width as if it had 5 entries (the parent
    // grid has homogeneous width set so both columns will have the same
    // width). This will align this TableEditPanel's columns with
    // ParaPropertyPanel's columns
    padWidthForSidebar(*m_xSplitMerge, rxFrame);

    InitRowHeightToolitem();
    InitColumnWidthToolitem();
}