From 0ecb69d53864b582eb59533729ada01d85d383e6 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 8 Nov 2023 08:25:23 +0100 Subject: sw floattable, insert UI: inherit fly width from selected table width Inline table width defaults to the body frame width, so a hardcoded 2cm default for the fly width is a bit poor. Leave the normal fly insert case unchanged, but if an entire table is selected, then change the default to the table width. Check for the table selection like SwFEShell::NewFlyFrame() does it, and determine if the entire table is selected like SwDoc::MakeFlyAndMove() does it. With this, a default table with a default frame keeps its width on frame insert. Change-Id: Iaf954395a4799222074acd83b5eae52ca75ae0ae Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159104 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sw/qa/uibase/frmdlg/frmdlg.cxx | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'sw/qa/uibase') diff --git a/sw/qa/uibase/frmdlg/frmdlg.cxx b/sw/qa/uibase/frmdlg/frmdlg.cxx index f6b7653de824..81a7746170c1 100644 --- a/sw/qa/uibase/frmdlg/frmdlg.cxx +++ b/sw/qa/uibase/frmdlg/frmdlg.cxx @@ -13,6 +13,11 @@ #include +#include +#include +#include +#include + /// Covers sw/source/uibase/frmdlg/ fixes. class SwUibaseFrmdlgTest : public SwModelTestBase { @@ -60,6 +65,46 @@ CPPUNIT_TEST_FIXTURE(SwUibaseFrmdlgTest, testAnchorTypeFromStyle) CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AS_CHARACTER, eActual); } +CPPUNIT_TEST_FIXTURE(SwUibaseFrmdlgTest, testInsertFrameWidth) +{ + // Given a document with an inline table, its width is set to 6000 twips: + createSwDoc(); + // Insert a table: + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 0); + pWrtShell->InsertTable(aTableOptions, /*nRows=*/1, /*nCols=*/1); + pWrtShell->MoveTable(GotoPrevTable, fnTableStart); + SwTwips nExpectedWidth = 6000; + { + SfxItemSetFixed aSet(pWrtShell->GetAttrPool()); + SwFormatFrameSize aSize(SwFrameSize::Variable, nExpectedWidth); + aSet.Put(aSize); + pWrtShell->SetTableAttr(aSet); + } + pWrtShell->GoPrevCell(); + pWrtShell->Insert("A1"); + SwFormatFrameSize aRowSize(SwFrameSize::Minimum); + pWrtShell->SetRowHeight(aRowSize); + pWrtShell->GoNextCell(); + pWrtShell->Insert("A2"); + pWrtShell->SetRowHeight(aRowSize); + // Select cell: + pWrtShell->SelAll(); + // Select table: + pWrtShell->SelAll(); + + // When converting that table to a floating table: + SwFlyFrameAttrMgr aMgr(/*bNew=*/true, pWrtShell, Frmmgr_Type::TEXT, nullptr); + + // Then make sure that the fly width will be based on the table width: + const SwFormatFrameSize* pFrameSize = aMgr.GetAttrSet().GetItem(RES_FRM_SIZE); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 6000 (nExpectedWidth) + // - Actual : 1134 (2cm) + // i.e. the fly width was the default, not inherited from the selected table. + CPPUNIT_ASSERT_EQUAL(nExpectedWidth, pFrameSize->GetWidth()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit