diff options
author | Justin Luth <justin.luth@collabora.com> | 2020-12-11 18:14:14 +0300 |
---|---|---|
committer | Justin Luth <justin_luth@sil.org> | 2020-12-29 10:13:56 +0100 |
commit | e4a8f55d8b44583e7aefe453e73a450fee95917a (patch) | |
tree | 74c7fc23cfda943b10deab56957bfbf9502d29ab /sw | |
parent | edd3db9ad64a4143febf0b1fc135199e0ecf53f1 (diff) |
tdf#134881 sw table dlg: make column change %-proportional
Apparently, there is a discrepancy in how the
various help manuals describe this.
What was actually happening was that the same
amount was being changed on each column
instead of the same percentage. That is really
bad if there are small columns, and a large one is reduced.
Plus it seemed like there were implementation problems anyway,
especially when growing a column too much.
This patch sets it to how the guide describes it.
"Adjust columns proportionally results in all columns changing
their widths by the same percentage when one is changed.
For example, if you reduce by half the size of a column,
the sizes of all the other columns will be halved."
(July 2018 LibreOffice Writer Guide 6.0 page 282)
Online help since 2013 simply says.
"Adjust columns proportionally:
If possible, change in column width will be equal for each column."
https://bugs.documentfoundation.org/show_bug.cgi?id=42023
One situation I noticed but don't think it needs dealing with
is if "from left" contains a value, then perhaps the table
should not be allowed to take up the full width?
It could grow to spill out past the edge of the page.
(Problem already existed with previous solution.)
Also, merged cells might cause some unexpected results,
but that becomes a user problem to fix I say.
I didn't think it would matter if I grew the table
a couple of Twips larger than full width. If it is,
then probably just reduce maxWidth by a twip for every
two columns - or truncate instead of round.
(And then I also need to account for theoretical columns
that are "increased" to MINLAY size too.)
Note that the table will NOT grow beyond
100% text width. However, if a table is already
larger than 100% (which the UI makes difficult to do)
at least an attempt to grow the columns will not cause
them to shrink. They will just stay the same sime.
make UITest_sw_table UITEST_TEST_NAME=\
tdf134881_colProportionalAdjust.tdf134881.test_tdf134881
Change-Id: Id57d80d9658b9ac1938189c75da0cbf309fc321a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107604
Tested-by: Jenkins
Reviewed-by: Justin Luth <justin_luth@sil.org>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/uitest/data/tdf134881_colProportionalAdjust.odt | bin | 0 -> 8783 bytes | |||
-rw-r--r-- | sw/qa/uitest/table/tdf134881_colProportionalAdjust.py | 55 | ||||
-rw-r--r-- | sw/source/ui/table/tabledlg.cxx | 37 |
3 files changed, 67 insertions, 25 deletions
diff --git a/sw/qa/uitest/data/tdf134881_colProportionalAdjust.odt b/sw/qa/uitest/data/tdf134881_colProportionalAdjust.odt Binary files differnew file mode 100644 index 000000000000..dd7752518487 --- /dev/null +++ b/sw/qa/uitest/data/tdf134881_colProportionalAdjust.odt diff --git a/sw/qa/uitest/table/tdf134881_colProportionalAdjust.py b/sw/qa/uitest/table/tdf134881_colProportionalAdjust.py new file mode 100644 index 000000000000..cb467c4019fb --- /dev/null +++ b/sw/qa/uitest/table/tdf134881_colProportionalAdjust.py @@ -0,0 +1,55 @@ +# -*- 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 select_pos +from uitest.uihelper.common import get_state_as_dict, type_text +from uitest.uihelper.common import change_measurement_unit +from libreoffice.uno.propertyvalue import mkPropertyValues +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() + +#Writer Table Properties + +class tdf134881(UITestCase): + def test_tdf134881(self): + writer_doc = self.ui_test.load_file(get_url_for_data_file("tdf134881_colProportionalAdjust.odt")) + document = self.ui_test.get_component() + xWriterDoc = self.xUITest.getTopFocusWindow() + + change_measurement_unit(self, "Centimeter") + + #dialog Table Properties + self.ui_test.execute_dialog_through_command(".uno:TableDialog") + xDialog = self.xUITest.getTopFocusWindow() + tabcontrol = xDialog.getChild("tabcontrol") + select_pos(tabcontrol, "2") #columns + + adaptcolumns = xDialog.getChild("adaptcolumns") + width1 = xDialog.getChild("width1") + width2 = xDialog.getChild("width2") + # Get the baseline. The first column is much shorter than the second. + self.assertEqual((get_state_as_dict(width1)["Text"])[0:3], "3.0") + self.assertEqual((get_state_as_dict(width2)["Text"])[0:4], "14.0") + # Set proportional adjust - so all columns are affected. + adaptcolumns.executeAction("CLICK", tuple()) + # Cut the second column in half. + width2.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) + width2.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) + width2.executeAction("TYPE", mkPropertyValues({"TEXT":"7"})) + width2.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"})) + + # The first column should now be half it's original value, not zero (not 3 - 7) + self.assertEqual((get_state_as_dict(width1)["Text"])[0:2], "1.") #1.5 + + xOKBtn = xDialog.getChild("ok") + 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/table/tabledlg.cxx b/sw/source/ui/table/tabledlg.cxx index 24cb02c5f67c..3a27bb61b007 100644 --- a/sw/source/ui/table/tabledlg.cxx +++ b/sw/source/ui/table/tabledlg.cxx @@ -1042,33 +1042,20 @@ void SwTableColumnPage::UpdateCols( sal_uInt16 nCurrentPos ) { //All columns will be changed proportionally with, //the table width is adjusted accordingly. - OSL_ENSURE(nDiff * m_nNoOfVisibleCols <= m_pTableData->GetSpace() - m_nTableWidth, "wrong maximum" ); - tools::Long nAdd = nDiff; - if(nDiff * m_nNoOfVisibleCols > m_pTableData->GetSpace() - m_nTableWidth) + const double fOrigColWidth = std::max(SwTwips(1), GetVisibleWidth(nCurrentPos) - nDiff); + const double fMaxWidth = std::max(m_pTableData->GetSpace(), m_nTableWidth); + const double fMaxPercent = fMaxWidth / m_nTableWidth; + const double fPercentChange = std::min(fMaxPercent, GetVisibleWidth(nCurrentPos)/fOrigColWidth); + SwTwips nNewTableSize = 0; + for( sal_uInt16 i = 0; i < m_nNoOfVisibleCols; i++ ) { - nAdd = (m_pTableData->GetSpace() - m_nTableWidth) / m_nNoOfVisibleCols; - SetVisibleWidth(nCurrentPos, GetVisibleWidth(nCurrentPos) - nDiff + nAdd ); - nDiff = nAdd; + SwTwips nNewColWidth = round( fPercentChange * (i == nCurrentPos ? fOrigColWidth : GetVisibleWidth(i)) ); + if ( nNewColWidth < MINLAY ) + nNewColWidth = MINLAY; + SetVisibleWidth(i, nNewColWidth); + nNewTableSize += nNewColWidth; } - if(nAdd) - for( sal_uInt16 i = 0; i < m_nNoOfVisibleCols; i++ ) - { - if(i == nCurrentPos) - continue; - SwTwips nVisWidth; - if((nVisWidth = GetVisibleWidth(i)) + nDiff < MINLAY) - { - nAdd += nVisWidth - MINLAY; - SetVisibleWidth(i, MINLAY); - } - else - { - SetVisibleWidth(i, nVisWidth + nDiff); - nAdd += nDiff; - } - - } - m_nTableWidth += nAdd; + m_nTableWidth = nNewTableSize; } if (!m_bPercentMode) |