sw/qa/uitest/data/chained-frames.odt |binary
 sw/qa/uitest/ui/frmdlg/frmdlg.py     |   17 +++++++++++++++++
 sw/source/ui/frmdlg/frmpage.cxx      |   23 ++++++++++++-----------
 3 files changed, 29 insertions(+), 11 deletions(-)

New commits:
commit d9cd177b9b08d454882dd77ffeb825a184a1b540
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue May 16 08:31:21 2023 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue May 16 09:42:18 2023 +0200

    sw floattable: disable UI if the frame is chained already
    
    TextFrames can be chained and we look at those fly frames as shapes. In
    this case, we should not offer the "split fly" functionality, which
    makes sense only when the fly frame is considered as a floating table.
    
    The combination of these two features have no use-case and it would just
    cause trouble when exporting to Word formats.
    
    Fix the problem by making SwFramePage::Reset() more strict: it already
    only allowed fly split for the case when the content was a single table,
    but now it also requires no chaining.
    
    The other way around (split fly -> no chain) still needs doing.
    
    Change-Id: I06c240209a3a26519a5df953e22c9ee1b54aed34
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151822
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/uitest/data/chained-frames.odt 
b/sw/qa/uitest/data/chained-frames.odt
new file mode 100644
index 000000000000..281e06520e27
Binary files /dev/null and b/sw/qa/uitest/data/chained-frames.odt differ
diff --git a/sw/qa/uitest/ui/frmdlg/frmdlg.py b/sw/qa/uitest/ui/frmdlg/frmdlg.py
index cfa2dd8ba954..e3aeb67c569c 100644
--- a/sw/qa/uitest/ui/frmdlg/frmdlg.py
+++ b/sw/qa/uitest/ui/frmdlg/frmdlg.py
@@ -13,6 +13,7 @@ import time
 from libreoffice.uno.propertyvalue import mkPropertyValues
 from uitest.framework import UITestCase
 from uitest.uihelper.common import get_state_as_dict
+from uitest.uihelper.common import get_url_for_data_file
 
 
 class Test(UITestCase):
@@ -44,5 +45,21 @@ class Test(UITestCase):
             # Then make sure the doc model is updated correctly:
             self.assertEqual(xComponent.TextFrames.Frame1.IsSplitAllowed, True)
 
+    def test_chained_fly_split(self):
+        # Given a document with 2 chained fly frames:
+        with 
self.ui_test.load_file(get_url_for_data_file("chained-frames.odt")):
+            # When selecting the first and opening the fly frame properties 
dialog:
+            self.xUITest.executeCommand(".uno:JumpToNextFrame")
+            # Wait until SwTextShell is replaced with SwDrawShell after 120 
ms, as set in the SwView
+            # ctor.
+            time.sleep(0.2)
+            with 
self.ui_test.execute_dialog_through_command(".uno:FrameDialog") as xDialog:
+                # Then make sure that the 'split' checkbox is hidden:
+                xFlysplit = xDialog.getChild("flysplit")
+                # Without the accompanying fix in place, this test would have 
failed with:
+                # AssertionError: 'true' != 'false'
+                # i.e. the UI didn't hide this option, leading to some weird 
mix of chained shapes
+                # and floating tables.
+                self.assertEqual(get_state_as_dict(xFlysplit)['Visible'], 
"false")
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/ui/frmdlg/frmpage.cxx b/sw/source/ui/frmdlg/frmpage.cxx
index 74ccc1a51809..82bb86e7a095 100644
--- a/sw/source/ui/frmdlg/frmpage.cxx
+++ b/sw/source/ui/frmdlg/frmpage.cxx
@@ -798,15 +798,9 @@ namespace
     };
 
 /// Checks if the current fly frame contains exactly one table.
-bool ContainsSingleTable(SwWrtShell* pWrtShell)
+bool ContainsSingleTable(const SwFrameFormat& rFlyFormat)
 {
-    const SwFrameFormat* pFlyFormat = pWrtShell->GetFlyFrameFormat();
-    if (!pFlyFormat)
-    {
-        return false;
-    }
-
-    const SwNodeIndex* pStartNode = pFlyFormat->GetContent().GetContentIdx();
+    const SwNodeIndex* pStartNode = rFlyFormat.GetContent().GetContentIdx();
     if (!pStartNode)
     {
         return false;
@@ -830,6 +824,12 @@ bool ContainsSingleTable(SwWrtShell* pWrtShell)
 
     return true;
 }
+
+bool ContainsChain(const SwFrameFormat& rFlyFormat)
+{
+    const SwFormatChain& rChain = rFlyFormat.GetChain();
+    return rChain.GetPrev() || rChain.GetNext();
+}
 }
 
 void SwFramePage::setOptimalRelWidth()
@@ -1047,10 +1047,11 @@ void SwFramePage::Reset( const SfxItemSet *rSet )
         m_xFlySplitCB->set_sensitive(m_xAnchorAtParaRB->get_active());
     }
 
-    if (!ContainsSingleTable(pSh))
+    const SwFrameFormat* pFlyFormat = pSh->GetFlyFrameFormat();
+    if (!pFlyFormat || !ContainsSingleTable(*pFlyFormat) || 
ContainsChain(*pFlyFormat))
     {
-        // Only allow fly split if the frame contains a single table, 
otherwise it would be hard the
-        // resulting model to Word formats.
+        // Only allow fly split if the frame contains a single table, 
otherwise it would be hard to
+        // save the resulting model to Word formats.
         m_xFlySplitCB->hide();
     }
 

Reply via email to