sw/qa/core/doc/doc.cxx | 40 ++++++++++++++++++++++++++++++++++++++++ sw/source/core/doc/docfly.cxx | 13 +++++++++++++ 2 files changed, 53 insertions(+)
New commits: commit eb34694ab0ce0b60c407f0fbe95143bc87b17638 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed May 17 08:23:43 2023 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri May 19 08:21:19 2023 +0200 sw floattable: disable chain UI if the frame is allowed to split already This is similar to d9cd177b9b08d454882dd77ffeb825a184a1b540 (sw floattable: disable UI if the frame is chained already, 2023-05-16), but here the fly is split and we disallow chaining, not the other way around. (cherry picked from commit a13264fc7578cbd3267065f4992ded9f7558ec7a) Change-Id: I637d594d41ba9a80d58bc0bef37627d8104293ad Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151937 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/core/doc/doc.cxx b/sw/qa/core/doc/doc.cxx index d827221f2717..c0c76d2c638e 100644 --- a/sw/qa/core/doc/doc.cxx +++ b/sw/qa/core/doc/doc.cxx @@ -35,6 +35,8 @@ #include <unotxdoc.hxx> #include <UndoManager.hxx> #include <IDocumentRedlineAccess.hxx> +#include <frmmgr.hxx> +#include <formatflysplit.hxx> /// Covers sw/source/core/doc/ fixes. class SwCoreDocTest : public SwModelTestBase @@ -446,6 +448,44 @@ CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testHeaderFooterDelete) createSwDoc("header-footer-delete.docx"); } +CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testSplitFlyChain) +{ + // Given a document with 2 fly frames, first is allowed to split, second is not: + createSwDoc(); + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + SwFlyFrameAttrMgr aMgr(true, pWrtShell, Frmmgr_Type::TEXT, nullptr); + RndStdIds eAnchor = RndStdIds::FLY_AT_PARA; + aMgr.InsertFlyFrame(eAnchor, aMgr.GetPos(), aMgr.GetSize()); + SwDoc* pDoc = getSwDoc(); + auto& rFlys = *pDoc->GetSpzFrameFormats(); + { + pWrtShell->StartAllAction(); + auto pFly = rFlys[0]; + SwAttrSet aSet(pFly->GetAttrSet()); + aSet.Put(SwFormatFlySplit(true)); + pDoc->SetAttr(aSet, *pFly); + pWrtShell->EndAllAction(); + } + pWrtShell->UnSelectFrame(); + pWrtShell->SttEndDoc(/*bStart=*/false); + aMgr.InsertFlyFrame(eAnchor, aMgr.GetPos(), aMgr.GetSize()); + auto pFly = rFlys[0]; + auto pFly2 = rFlys[1]; + + // When checking if chaining is allowed: + SwChainRet eActual = pDoc->Chainable(*pFly, *pFly2); + // Then make sure the source is rejected if it is a split fly: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 5 (SwChainRet::SOURCE_CHAINED) + // - Actual : 0 (SwChainRet::OK) + // i.e. the UI allowed chaining for floating tables, which doesn't make sense. + CPPUNIT_ASSERT_EQUAL(SwChainRet::SOURCE_CHAINED, eActual); + + // Also test the other way around, that should not be OK, either. + eActual = pDoc->Chainable(*pFly2, *pFly); + CPPUNIT_ASSERT_EQUAL(SwChainRet::IS_IN_CHAIN, eActual); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/doc/docfly.cxx b/sw/source/core/doc/docfly.cxx index 998f123ee6c0..f98decfa0e65 100644 --- a/sw/source/core/doc/docfly.cxx +++ b/sw/source/core/doc/docfly.cxx @@ -62,6 +62,7 @@ #include <svx/xlnstit.hxx> #include <svx/xlnedit.hxx> #include <svx/xflhtit.hxx> +#include <formatflysplit.hxx> using namespace ::com::sun::star; @@ -1008,6 +1009,18 @@ SwChainRet SwDoc::Chainable( const SwFrameFormat &rSource, const SwFrameFormat & if( rChain.GetPrev() ) return SwChainRet::IS_IN_CHAIN; + // Split flys are incompatible with chaining. + const SwFormatFlySplit& rOldSplit = rSource.GetFlySplit(); + if (rOldSplit.GetValue()) + { + return SwChainRet::SOURCE_CHAINED; + } + const SwFormatFlySplit& rNewSplit = rDest.GetFlySplit(); + if (rNewSplit.GetValue()) + { + return SwChainRet::IS_IN_CHAIN; + } + // Target must be empty. const SwNodeIndex* pCntIdx = rDest.GetContent().GetContentIdx(); if( !pCntIdx )