diff options
-rw-r--r-- | sw/qa/core/doc/doc.cxx | 40 | ||||
-rw-r--r-- | sw/source/core/doc/docfly.cxx | 13 |
2 files changed, 53 insertions, 0 deletions
diff --git a/sw/qa/core/doc/doc.cxx b/sw/qa/core/doc/doc.cxx index fc1ffc69e8d9..5b523067523a 100644 --- a/sw/qa/core/doc/doc.cxx +++ b/sw/qa/core/doc/doc.cxx @@ -32,6 +32,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 @@ -442,6 +444,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 1d425e62f73d..3d94cffef514 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; @@ -995,6 +996,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 ) |