sw/qa/core/doc/doc.cxx        |   40 ++++++++++++++++++++++++++++++++++++++++
 sw/source/core/doc/docfly.cxx |   13 +++++++++++++
 2 files changed, 53 insertions(+)

New commits:
commit a13264fc7578cbd3267065f4992ded9f7558ec7a
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed May 17 08:23:43 2023 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed May 17 10:22:08 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.
    
    Change-Id: I637d594d41ba9a80d58bc0bef37627d8104293ad
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151856
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

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 )

Reply via email to