summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Luth <justin_luth@sil.org>2019-08-21 19:41:17 +0300
committerMiklos Vajna <vmiklos@collabora.com>2019-08-28 09:28:38 +0200
commit4a4e0cb67eab422dffda6f3339031db5b62be77a (patch)
tree0f9d6cc79b3fd8ab810f980da8664ddf6f4e15c2
parent3780d305ae1607458029af3c9452bad251490461 (diff)
tdf#126784 sw: only distribute across selected columns
partial revert of LO6.2 commit ab18c17d70e1dcf5cf9db38256d35e6af479373e because MERGED cells had a very unexpected effect on the columns that were altered. Unselected columns are INCLUDED in the calculation IF they extend over the selected columns when SwTableSearchType::Col uses the entire table column. The last table in the unit test demonstrates why the regressive behaviour was included. A user can make an ugly layout if they don't choose a good set of columns. However, the merged cell really changes the way the calculation works, and since giving power to the user is ultimately the best, just revert the portion that tries to save the user from themself. I struggled then and now to get a good enough understanding to improve the documentation - which really is needed since reading it didn't help me a lot. However, since my understanding was and is obviously flawed, I'll just revert back to the original wording. Change-Id: Icf8f01f095652e2a023e0398852f43aa6b90332f Reviewed-on: https://gerrit.libreoffice.org/77985 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--sw/inc/doc.hxx3
-rw-r--r--sw/inc/fesh.hxx2
-rw-r--r--sw/qa/extras/uiwriter/data2/tdf126784_distributeSelectedColumns.odtbin0 -> 21302 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter2.cxx31
-rw-r--r--sw/source/core/docnode/ndtbl1.cxx32
-rw-r--r--sw/source/core/frmedt/fetab.cxx4
-rw-r--r--sw/source/uibase/shells/tabsh.cxx3
7 files changed, 52 insertions, 23 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index db3220f26f18..ce2311c59c09 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1492,8 +1492,7 @@ public:
/// Adjusts selected cell widths in such a way, that their content does not need to be wrapped (if possible).
/// bBalance evenly re-distributes the available space regardless of content or wrapping.
/// bNoShrink keeps table size the same by distributing excess space proportionately.
- /// bColumnWidth tests the entire column for content width, not just selected cells.
- void AdjustCellWidth( const SwCursor& rCursor, const bool bBalance, const bool bNoShrink, const bool bColumnWidth );
+ void AdjustCellWidth( const SwCursor& rCursor, const bool bBalance, const bool bNoShrink );
SwChainRet Chainable( const SwFrameFormat &rSource, const SwFrameFormat &rDest );
SwChainRet Chain( SwFrameFormat &rSource, const SwFrameFormat &rDest );
diff --git a/sw/inc/fesh.hxx b/sw/inc/fesh.hxx
index 5d45fa3e6621..2a3c26781858 100644
--- a/sw/inc/fesh.hxx
+++ b/sw/inc/fesh.hxx
@@ -707,7 +707,7 @@ public:
bool IsInRepeatedHeadline() const { return CheckHeadline( true ); }
bool IsInHeadline() const { return CheckHeadline( false ); }
- void AdjustCellWidth( bool bBalance, const bool bNoShrink, const bool bColumnWidth );
+ void AdjustCellWidth( const bool bBalance, const bool bNoShrink );
/// Not allowed if only empty cells are selected.
bool IsAdjustCellWidthAllowed( bool bBalance = false ) const;
diff --git a/sw/qa/extras/uiwriter/data2/tdf126784_distributeSelectedColumns.odt b/sw/qa/extras/uiwriter/data2/tdf126784_distributeSelectedColumns.odt
new file mode 100644
index 000000000000..90c23c56a32d
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data2/tdf126784_distributeSelectedColumns.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 01ee96f67ee6..d8e939be005d 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -10,6 +10,7 @@
#include <swmodeltestbase.hxx>
#include <com/sun/star/awt/FontSlant.hpp>
#include <com/sun/star/frame/DispatchHelper.hpp>
+#include <com/sun/star/text/TableColumnSeparator.hpp>
#include <comphelper/propertysequence.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <svx/svdpage.hxx>
@@ -42,6 +43,7 @@ public:
void testTdf54819();
void testTdf109376_redline();
void testTdf109376();
+ void testTdf126784_distributeSelectedColumns();
void testTdf108687_tabstop();
void testTdf119571();
void testTdf119019();
@@ -60,6 +62,7 @@ public:
CPPUNIT_TEST(testTdf101534);
CPPUNIT_TEST(testTdf54819);
CPPUNIT_TEST(testTdf109376_redline);
+ CPPUNIT_TEST(testTdf126784_distributeSelectedColumns);
CPPUNIT_TEST(testTdf109376);
CPPUNIT_TEST(testTdf108687_tabstop);
CPPUNIT_TEST(testTdf119571);
@@ -360,6 +363,34 @@ void SwUiWriterTest2::testTdf109376()
CPPUNIT_ASSERT_EQUAL(size_t(1), pWrtShell->GetFlyCount(FLYCNTTYPE_FRM));
}
+void SwUiWriterTest2::testTdf126784_distributeSelectedColumns()
+{
+ SwDoc* pDoc = createDoc("tdf126784_distributeSelectedColumns.odt");
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+ uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(),
+ uno::UNO_QUERY);
+ uno::Reference<text::XTextTable> xTextTable(xTables->getByIndex(0), uno::UNO_QUERY);
+ uno::Reference<table::XTableRows> xTableRows = xTextTable->getRows();
+
+ auto aSeq = getProperty<uno::Sequence<text::TableColumnSeparator>>(xTableRows->getByIndex(0),
+ "TableColumnSeparators");
+ sal_Int16 nOrigCol2Pos = aSeq[0].Position;
+ sal_Int16 nOrigCol3Pos = aSeq[1].Position;
+
+ //Select column 1 and 2
+ pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false);
+
+ lcl_dispatchCommand(mxComponent, ".uno:DistributeColumns", {});
+
+ aSeq = getProperty<uno::Sequence<text::TableColumnSeparator>>(xTableRows->getByIndex(0),
+ "TableColumnSeparators");
+ CPPUNIT_ASSERT_MESSAGE("Second column should shrink", nOrigCol2Pos < aSeq[0].Position);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Last column shouldn't change", nOrigCol3Pos, aSeq[1].Position);
+}
+
void SwUiWriterTest2::testTdf108687_tabstop()
{
SwDoc* pDoc = createDoc("tdf108687_tabstop.odt");
diff --git a/sw/source/core/docnode/ndtbl1.cxx b/sw/source/core/docnode/ndtbl1.cxx
index 582cb226dc55..9b152b500088 100644
--- a/sw/source/core/docnode/ndtbl1.cxx
+++ b/sw/source/core/docnode/ndtbl1.cxx
@@ -1365,24 +1365,25 @@ static void lcl_CalcSubColValues( std::vector<sal_uInt16> &rToFill, const SwTabC
* We do not iterate over the TabCols' entries, but over the gaps that describe Cells.
* We set TabCol entries for which we did not calculate Cells to 0.
*
- * @param bWishValues == true: Calculate the desired width of the content
- * The highest desired value is returned.
- * @param bWishValues == false: Calculate the minimum width of the content
- * @param bColumnWidth == false: We calculate the desired value of all affected
- * Cells for the current Selection only.
- * @param bColumnWidth == true: The Selection is expanded vertically.
- * We calculate the wish/minimum value for
- * each cell in every Column that intersects
- * with the Selection.
+ * @param bWishValues == true: We calculate the desired value of all affected
+ * Cells for the current Selection/current Cell.
+ * If more Cells are within a Column, the highest
+ * desired value is returned.
+ * We set TabCol entries for which we did not calculate
+ * Cells to 0.
+ *
+ * @param bWishValues == false: The Selection is expanded vertically.
+ * We calculate the minimum value for every
+ * Column in the TabCols that intersects with the
+ * Selection.
*/
static void lcl_CalcColValues( std::vector<sal_uInt16> &rToFill, const SwTabCols &rCols,
const SwLayoutFrame *pStart, const SwLayoutFrame *pEnd,
- bool bWishValues,
- bool bColumnWidth )
+ bool bWishValues )
{
SwSelUnions aUnions;
::MakeSelUnions( aUnions, pStart, pEnd,
- bColumnWidth ? SwTableSearchType::Col : SwTableSearchType::NONE );
+ bWishValues ? SwTableSearchType::NONE : SwTableSearchType::Col );
for ( auto &rU : aUnions )
{
@@ -1463,8 +1464,7 @@ static void lcl_CalcColValues( std::vector<sal_uInt16> &rToFill, const SwTabCols
void SwDoc::AdjustCellWidth( const SwCursor& rCursor,
const bool bBalance,
- const bool bNoShrink,
- const bool bColumnWidth )
+ const bool bNoShrink )
{
// Check whether the current Cursor has it's Point/Mark in a Table
SwContentNode* pCntNd = rCursor.GetPoint()->nNode.GetNode().GetContentNode();
@@ -1492,7 +1492,7 @@ void SwDoc::AdjustCellWidth( const SwCursor& rCursor,
std::vector<sal_uInt16> aWish(aTabCols.Count() + 1);
std::vector<sal_uInt16> aMins(aTabCols.Count() + 1);
- ::lcl_CalcColValues( aWish, aTabCols, pStart, pEnd, true, bColumnWidth );
+ ::lcl_CalcColValues( aWish, aTabCols, pStart, pEnd, /*bWishValues=*/true );
// It's more robust if we calculate the minimum values for the whole Table
const SwTabFrame *pTab = pStart->ImplFindTabFrame();
@@ -1500,7 +1500,7 @@ void SwDoc::AdjustCellWidth( const SwCursor& rCursor,
pEnd = const_cast<SwLayoutFrame*>(pTab->FindLastContent()->GetUpper());
while( !pEnd->IsCellFrame() )
pEnd = pEnd->GetUpper();
- ::lcl_CalcColValues( aMins, aTabCols, pStart, pEnd, false, /*bColumnWidth=*/true );
+ ::lcl_CalcColValues( aMins, aTabCols, pStart, pEnd, /*bWishValues=*/false );
sal_uInt16 nSelectedWidth = 0, nCols = 0;
float fTotalWish = 0;
diff --git a/sw/source/core/frmedt/fetab.cxx b/sw/source/core/frmedt/fetab.cxx
index 0b50d6d938f4..aecff629e714 100644
--- a/sw/source/core/frmedt/fetab.cxx
+++ b/sw/source/core/frmedt/fetab.cxx
@@ -1107,7 +1107,7 @@ bool SwFEShell::CheckHeadline( bool bRepeat ) const
return bRet;
}
-void SwFEShell::AdjustCellWidth( bool bBalance, const bool bNoShrink, const bool bColumnWidth )
+void SwFEShell::AdjustCellWidth( const bool bBalance, const bool bNoShrink )
{
SET_CURR_SHELL( this );
StartAllAction();
@@ -1117,7 +1117,7 @@ void SwFEShell::AdjustCellWidth( bool bBalance, const bool bNoShrink, const bool
TableWait aWait(std::numeric_limits<size_t>::max(), nullptr,
*GetDoc()->GetDocShell());
- GetDoc()->AdjustCellWidth( *getShellCursor( false ), bBalance, bNoShrink, bColumnWidth );
+ GetDoc()->AdjustCellWidth( *getShellCursor( false ), bBalance, bNoShrink );
EndAllActionAndCall();
}
diff --git a/sw/source/uibase/shells/tabsh.cxx b/sw/source/uibase/shells/tabsh.cxx
index 4b3c3dc78f41..ad1aa432dfb7 100644
--- a/sw/source/uibase/shells/tabsh.cxx
+++ b/sw/source/uibase/shells/tabsh.cxx
@@ -766,14 +766,13 @@ void SwTableShell::Execute(SfxRequest &rReq)
{
bool bBalance = (FN_TABLE_BALANCE_CELLS == nSlot);
const bool bNoShrink = FN_TABLE_ADJUST_CELLS == nSlot;
- const bool bSelectedWidth = SID_TABLE_MINIMAL_COLUMN_WIDTH == nSlot;
if ( rSh.IsAdjustCellWidthAllowed(bBalance) )
{
{
// remove actions to make a valid table selection
UnoActionRemoveContext aRemoveContext(rSh.GetDoc());
}
- rSh.AdjustCellWidth(bBalance, bNoShrink, !bSelectedWidth);
+ rSh.AdjustCellWidth(bBalance, bNoShrink);
}
bCallDone = true;
break;