diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2023-11-08 08:25:23 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-11-08 10:17:09 +0100 |
commit | 0ecb69d53864b582eb59533729ada01d85d383e6 (patch) | |
tree | 50327d15a732528af8935a286c2819d690ddf1fd /sw/qa/uibase | |
parent | 4261f337b647bd504c9500f23fbb0cdd90a2d50e (diff) |
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 <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/qa/uibase')
-rw-r--r-- | sw/qa/uibase/frmdlg/frmdlg.cxx | 45 |
1 files changed, 45 insertions, 0 deletions
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 <com/sun/star/text/TextContentAnchorType.hpp> +#include <docsh.hxx> +#include <wrtsh.hxx> +#include <frmmgr.hxx> +#include <itabenum.hxx> + /// 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<RES_FRMATR_BEGIN, RES_FRMATR_END - 1> 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: */ |