tdf#138546 sw PageDialog: fix bad reset of colwidth
The presence of border padding was causing the algorithm
to reset the overall width, which in page style triggered
an even redistribution of the columns. That should only
happen when the number of columns changes, or else one of
the 5 predefined column choices is selected.
My first python unit test is included.
make UITest_writer_tests4 \
UITEST_TEST_NAME=tdf138546.tdf138546.test_tdf138546
Change-Id: I650e429568f2ab794649cc557998a809479b6e82
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108210
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
diff --git a/sw/qa/uitest/data/tdf138546.odt b/sw/qa/uitest/data/tdf138546.odt
new file mode 100644
index 0000000..8bfa9f6
--- /dev/null
+++ b/sw/qa/uitest/data/tdf138546.odt
Binary files differ
diff --git a/sw/qa/uitest/writer_tests4/tdf138546.py b/sw/qa/uitest/writer_tests4/tdf138546.py
new file mode 100644
index 0000000..c94f7ee
--- /dev/null
+++ b/sw/qa/uitest/writer_tests4/tdf138546.py
@@ -0,0 +1,46 @@
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# 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/.
#
from uitest.framework import UITestCase
from uitest.uihelper.common import change_measurement_unit
from uitest.uihelper.common import get_state_as_dict, type_text
from uitest.uihelper.common import select_pos
import org.libreoffice.unotest
import pathlib
def get_url_for_data_file(file_name):
return pathlib.Path(org.libreoffice.unotest.makeCopyFromTDOC(file_name)).as_uri()
class tdf138546(UITestCase):
def test_tdf138546(self):
self.ui_test.load_file(get_url_for_data_file("tdf138546.odt"))
xWriterDoc = self.xUITest.getTopFocusWindow()
change_measurement_unit(self, "Centimeter")
#dialog Columns
self.ui_test.execute_dialog_through_command(".uno:FormatColumns")
xDialog = self.xUITest.getTopFocusWindow()
colsnf = xDialog.getChild("colsnf")
width1mf = xDialog.getChild("width1mf")
self.assertEqual(get_state_as_dict(colsnf)["Text"], "2")
self.assertEqual((get_state_as_dict(width1mf)["Text"])[0:3], "2.0") #2.00 cm
xOKBtn = xDialog.getChild("cancel")
self.ui_test.close_dialog_through_button(xOKBtn)
self.ui_test.execute_dialog_through_command(".uno:PageDialog")
xDialog = self.xUITest.getTopFocusWindow()
tabcontrol = xDialog.getChild("tabcontrol")
select_pos(tabcontrol, "7") #Columns
colsnf = xDialog.getChild("colsnf")
width1mf = xDialog.getChild("width1mf")
self.assertEqual(get_state_as_dict(colsnf)["Text"], "2")
self.assertEqual((get_state_as_dict(width1mf)["Text"])[0:3], "2.0") #2.00 cm
xOKBtn = xDialog.getChild("cancel")
self.ui_test.close_dialog_through_button(xOKBtn)
self.ui_test.close_doc()
# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/ui/frmdlg/column.cxx b/sw/source/ui/frmdlg/column.cxx
index 4adf7cb..472ce06 100644
--- a/sw/source/ui/frmdlg/column.cxx
+++ b/sw/source/ui/frmdlg/column.cxx
@@ -903,12 +903,12 @@ void SwColumnPage::SetLabels( sal_uInt16 nVis )
* the column number overwrites potential user's width settings; all columns
* are equally wide.
*/
IMPL_LINK(SwColumnPage, ColModify, weld::SpinButton&, rEdit, void)
IMPL_LINK_NOARG(SwColumnPage, ColModify, weld::SpinButton&, void)
{
ColModify(&rEdit);
ColModify(/*bForceColReset=*/false);
}
void SwColumnPage::ColModify(const weld::SpinButton* pNF)
void SwColumnPage::ColModify(bool bForceColReset)
{
m_nCols = static_cast<sal_uInt16>(m_xCLNrEdt->get_value());
//#107890# the handler is also called from LoseFocus()
@@ -916,10 +916,10 @@ void SwColumnPage::ColModify(const weld::SpinButton* pNF)
// #i17816# changing the displayed types within the ValueSet
//from two columns to two columns with different settings doesn't invalidate the
// example windows in ::ColModify()
if (pNF && m_xColMgr->GetCount() == m_nCols)
if (!bForceColReset && m_xColMgr->GetCount() == m_nCols)
return;
if (pNF)
if (!bForceColReset)
m_aDefaultVS.SetNoSelection();
tools::Long nDist = static_cast< tools::Long >(m_xDistEd1->DenormalizePercent(m_xDistEd1->get_value(FieldUnit::TWIP)));
m_xColMgr->SetCount(m_nCols, static_cast<sal_uInt16>(nDist));
@@ -1191,7 +1191,7 @@ void SwColumnPage::ActivatePage(const SfxItemSet& rSet)
if( m_xColMgr->GetActualSize() != nActWidth)
{
m_xColMgr->SetActualWidth(nActWidth);
ColModify( nullptr );
ColModify(/*bForceColReset=*/false);
UpdateColMgr( *m_xLineWidthEdit );
}
}
@@ -1270,7 +1270,7 @@ IMPL_LINK(SwColumnPage, SetDefaultsHdl, ValueSet *, pVS, void)
m_xCLNrEdt->set_value(nItem);
m_xAutoWidthBox->set_active(true);
m_xDistEd1->set_value(50, FieldUnit::CM);
ColModify(nullptr);
ColModify(/*bForceColReset=*/true);
}
else
{
@@ -1278,7 +1278,7 @@ IMPL_LINK(SwColumnPage, SetDefaultsHdl, ValueSet *, pVS, void)
m_xCLNrEdt->set_value(2);
m_xAutoWidthBox->set_active(false);
m_xDistEd1->set_value(50, FieldUnit::CM);
ColModify(nullptr);
ColModify(/*bForceColReset=*/true);
// now set the width ratio to 2 : 1 or 1 : 2 respectively
const tools::Long nSmall = static_cast< tools::Long >(m_xColMgr->GetActualSize() / 3);
if(nItem == 4)
diff --git a/sw/source/uibase/inc/column.hxx b/sw/source/uibase/inc/column.hxx
index 006eec6..fdf8080 100644
--- a/sw/source/uibase/inc/column.hxx
+++ b/sw/source/uibase/inc/column.hxx
@@ -136,7 +136,7 @@ class SwColumnPage : public SfxTabPage
// Handler
DECL_LINK(ColModify, weld::SpinButton&, void);
void ColModify(const weld::SpinButton*);
void ColModify(bool bForceColReset);
DECL_LINK(GapModify, weld::MetricSpinButton&, void);
DECL_LINK(EdModify, weld::MetricSpinButton&, void);
DECL_LINK(AutoWidthHdl, weld::ToggleButton&, void );