diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2023-08-22 12:28:59 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-08-22 15:19:34 +0200 |
commit | 56da1d30afe48cc4acd79567052a575e81f8c7a0 (patch) | |
tree | e391b39a175175d9f10ea218e415f999206dfd40 | |
parent | 8dc8413b4f8037b9c89f08a5b0b939bb61052585 (diff) |
tdf#77760 sw floattable: add support for footnotes, doc model
The bugdoc had a floating table, but we didn't convert the inline table
to floating because it had a footnote, and having footnotes in fly
frames is not supported in Writer.
One benefit of not having footnotes in fly frames is that once these are
saved to Word shapes, those can't have footnotes, either -- there is
value in limiting the UI to the constructs that can be also saved in
Word formats.
Fix the problem by allowing this for split flys, but not for
flys/headers/footers in general.
This is just the doc model, later steps (layout, etc) still need doing
in follow-up commits.
Change-Id: Ic3ba95877d7fad3f5f30743b89e2cf90e0d0af52
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155944
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | sw/inc/cshtyp.hxx | 4 | ||||
-rw-r--r-- | sw/qa/core/txtnode/txtnode.cxx | 35 | ||||
-rw-r--r-- | sw/source/core/txtnode/thints.cxx | 14 |
3 files changed, 49 insertions, 4 deletions
diff --git a/sw/inc/cshtyp.hxx b/sw/inc/cshtyp.hxx index 1ecde9f6d1d7..ec99572f6827 100644 --- a/sw/inc/cshtyp.hxx +++ b/sw/inc/cshtyp.hxx @@ -50,9 +50,9 @@ extern SW_DLLPUBLIC SwMoveFnCollection const & fnParaEnd; // Direction-parameter for MoveSection. typedef bool (*SwWhichSection)( SwPaM&, SwMoveFnCollection const & ); extern SwMoveFnCollection const & fnSectionStart; -extern SwMoveFnCollection const & fnSectionEnd; +extern SW_DLLPUBLIC SwMoveFnCollection const & fnSectionEnd; -bool GoCurrSection( SwPaM&, SwMoveFnCollection const &); +SW_DLLPUBLIC bool GoCurrSection( SwPaM&, SwMoveFnCollection const &); // Direction-parameter for MoveTable typedef bool (*SwWhichTable)( SwPaM&, SwMoveFnCollection const &, bool bInReadOnly ); diff --git a/sw/qa/core/txtnode/txtnode.cxx b/sw/qa/core/txtnode/txtnode.cxx index 4a4bf9901a2f..ad6a85aabb58 100644 --- a/sw/qa/core/txtnode/txtnode.cxx +++ b/sw/qa/core/txtnode/txtnode.cxx @@ -33,6 +33,9 @@ #include <textcontentcontrol.hxx> #include <swdtflvr.hxx> #include <txtrfmrk.hxx> +#include <frmmgr.hxx> +#include <formatflysplit.hxx> +#include <ftnidx.hxx> /// Covers sw/source/core/txtnode/ fixes. class SwCoreTxtnodeTest : public SwModelTestBase @@ -426,6 +429,38 @@ CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testContentControlCopy) CPPUNIT_ASSERT_EQUAL(SwContentControlType::CHECKBOX, rFormat2.GetContentControl()->GetType()); } +CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testFlySplitFootnote) +{ + // Given a document with a split fly (to host a table): + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + SwFlyFrameAttrMgr aMgr(true, pWrtShell, Frmmgr_Type::TEXT, nullptr); + RndStdIds eAnchor = RndStdIds::FLY_AT_PARA; + pWrtShell->StartAllAction(); + aMgr.InsertFlyFrame(eAnchor, aMgr.GetPos(), aMgr.GetSize()); + pWrtShell->EndAllAction(); + pWrtShell->StartAllAction(); + sw::FrameFormats<sw::SpzFrameFormat*>& rFlys = *pDoc->GetSpzFrameFormats(); + sw::SpzFrameFormat* pFly = rFlys[0]; + SwAttrSet aSet(pFly->GetAttrSet()); + aSet.Put(SwFormatFlySplit(true)); + pDoc->SetAttr(aSet, *pFly); + pWrtShell->EndAllAction(); + pWrtShell->UnSelectFrame(); + pWrtShell->LeaveSelFrameMode(); + pWrtShell->GetView().AttrChangedNotify(nullptr); + pWrtShell->MoveSection(GoCurrSection, fnSectionEnd); + + // When inserting a footnote: + pWrtShell->InsertFootnote(OUString()); + + // Then make sure the footnote gets inserted to the doc model. + // Without the accompanying fix in place, this test would have failed, insert code refused to + // have footnotes in all fly frames. + CPPUNIT_ASSERT(!pDoc->GetFootnoteIdxs().empty()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx index 75e80abb242a..2c0a1250f0b7 100644 --- a/sw/source/core/txtnode/thints.cxx +++ b/sw/source/core/txtnode/thints.cxx @@ -53,6 +53,7 @@ #include <fmtruby.hxx> #include <fmtmeta.hxx> #include <formatcontentcontrol.hxx> +#include <formatflysplit.hxx> #include <textcontentcontrol.hxx> #include <breakit.hxx> #include <doc.hxx> @@ -1440,7 +1441,16 @@ bool SwTextNode::InsertHint( SwTextAttr * const pAttr, const SetAttrMode nMode ) SwNodes &rNodes = rDoc.GetNodes(); // check that footnote is inserted into body or redline section - if( StartOfSectionIndex() < rNodes.GetEndOfAutotext().GetIndex() ) + bool bSplitFly = false; + if (StartOfSectionIndex() < rNodes.GetEndOfAutotext().GetIndex() + && StartOfSectionIndex() >= rNodes.GetEndOfInserts().GetIndex()) + { + // This is a frame, header or footer. Check if it's a split frame. + SwFrameFormat* pFlyFormat = StartOfSectionNode()->GetFlyFormat(); + bSplitFly = pFlyFormat && pFlyFormat->GetFlySplit().GetValue(); + } + + if (StartOfSectionIndex() < rNodes.GetEndOfAutotext().GetIndex() && !bSplitFly) { // This should not be allowed, prevent it here. // The dtor of the SwTextAttr does not delete the @@ -1527,7 +1537,7 @@ bool SwTextNode::InsertHint( SwTextAttr * const pAttr, const SetAttrMode nMode ) static_cast<SwTextFootnote*>(pAttr)->ChgTextNode( this ); // do not insert footnote in redline section into footnote array - if( StartOfSectionIndex() > rNodes.GetEndOfRedlines().GetIndex() ) + if (StartOfSectionIndex() > rNodes.GetEndOfRedlines().GetIndex() || bSplitFly) { const bool bSuccess = rDoc.GetFootnoteIdxs().insert(pTextFootnote).second; OSL_ENSURE( bSuccess, "FootnoteIdx not inserted." ); |