sw/inc/cshtyp.hxx | 4 ++-- sw/qa/core/txtnode/txtnode.cxx | 35 +++++++++++++++++++++++++++++++++++ sw/source/core/txtnode/thints.cxx | 14 ++++++++++++-- 3 files changed, 49 insertions(+), 4 deletions(-)
New commits: commit ec4f0a3a69765e17740609f4626c13d58fdcd91c Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue Aug 22 12:28:59 2023 +0200 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Wed Aug 23 11:54:43 2023 +0200 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. (cherry picked from commit 56da1d30afe48cc4acd79567052a575e81f8c7a0) Conflicts: sw/qa/core/txtnode/txtnode.cxx Change-Id: Ic3ba95877d7fad3f5f30743b89e2cf90e0d0af52 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155963 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> 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 e0526bdbb361..ed6f347d9b28 100644 --- a/sw/qa/core/txtnode/txtnode.cxx +++ b/sw/qa/core/txtnode/txtnode.cxx @@ -31,6 +31,9 @@ #include <ndtxt.hxx> #include <textcontentcontrol.hxx> #include <swdtflvr.hxx> +#include <frmmgr.hxx> +#include <formatflysplit.hxx> +#include <ftnidx.hxx> /// Covers sw/source/core/txtnode/ fixes. class SwCoreTxtnodeTest : public SwModelTestBase @@ -359,6 +362,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(); + SwFrameFormats& rFlys = *pDoc->GetSpzFrameFormats(); + SwFrameFormat* 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 59a931a406de..f267f04a8f14 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." );