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 | |
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')
-rw-r--r-- | sw/qa/uibase/frmdlg/frmdlg.cxx | 45 | ||||
-rw-r--r-- | sw/source/uibase/frmdlg/frmmgr.cxx | 35 | ||||
-rw-r--r-- | sw/source/uibase/inc/frmmgr.hxx | 1 |
3 files changed, 81 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: */ diff --git a/sw/source/uibase/frmdlg/frmmgr.cxx b/sw/source/uibase/frmdlg/frmmgr.cxx index 729892398997..a71b7ef3fb0a 100644 --- a/sw/source/uibase/frmdlg/frmmgr.cxx +++ b/sw/source/uibase/frmdlg/frmmgr.cxx @@ -84,6 +84,9 @@ SwFlyFrameAttrMgr::SwFlyFrameAttrMgr( bool bNew, SwWrtShell* pSh, Frmmgr_Type nT } m_aSet.SetParent( &m_pOwnSh->GetFormatFromPool( nId )->GetAttrSet()); m_aSet.Put( SwFormatFrameSize( SwFrameSize::Minimum, DFLT_WIDTH, DFLT_HEIGHT )); + + SetFrameSizeFromTable(); + if ( 0 != ::GetHtmlMode(pSh->GetView().GetDocShell()) ) m_aSet.Put( SwFormatHoriOrient( 0, text::HoriOrientation::LEFT, text::RelOrientation::PRINT_AREA ) ); @@ -622,4 +625,36 @@ void SwFlyFrameAttrMgr::SetAttrSet(const SfxItemSet& rSet) m_aSet.Put( rSet ); } +void SwFlyFrameAttrMgr::SetFrameSizeFromTable() +{ + if (!m_pOwnSh->IsTableMode()) + { + return; + } + + // We have a table selection. + SwSelBoxes aBoxes; + GetTableSel(*m_pOwnSh, aBoxes); + if (aBoxes.empty()) + { + return; + } + + auto pTableNd = const_cast<SwTableNode*>(aBoxes[0]->GetSttNd()->FindTableNode()); + if (!pTableNd) + { + return; + } + + SwTable& rTable = pTableNd->GetTable(); + if (aBoxes.size() != rTable.GetTabSortBoxes().size()) + { + return; + } + + // The whole table is selected: default fly width should be the table width + // in this case. + m_aSet.Put(rTable.GetFrameFormat()->GetFrameSize()); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/inc/frmmgr.hxx b/sw/source/uibase/inc/frmmgr.hxx index c5ac8eba3edd..f9186bd0707b 100644 --- a/sw/source/uibase/inc/frmmgr.hxx +++ b/sw/source/uibase/inc/frmmgr.hxx @@ -124,6 +124,7 @@ public: const SfxItemSet &GetAttrSet() const { return m_aSet; } SfxItemSet &GetAttrSet() { return m_aSet; } void SetAttrSet(const SfxItemSet& rSet); + void SetFrameSizeFromTable(); inline const SwFormatVertOrient &GetVertOrient() const; inline const SwFormatHoriOrient &GetHoriOrient() const; |