sw/qa/uitest/data/floattable-in-shape-text.docx |binary sw/qa/uitest/ui/frmdlg/frmdlg.py | 35 ++++++++++++++++++++++++ sw/source/ui/frmdlg/frmpage.cxx | 30 ++++++++++++++++++++ 3 files changed, 65 insertions(+)
New commits: commit b6b682d3c78ec61456572c6837ad94716a1fa0f9 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Dec 15 08:42:21 2023 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Dec 15 14:08:22 2023 +0100 sw floattable: disable UI to enable this when anchored inside TextBox Similar to headers or footers, shape text is another area where multi-page floating tables don't make sense, the Word UI to float a table in shape text is even disabled. Our UI to create a floating table is to select a table and then insert frame, and that already refused to make a new frame around a table to split. However, one could be creative and enable the split only later, and that was allowed. Fix the problem by extending SwFramePage::Reset(), so in case the currently selected frame is edited and it's anchored in a Word-style shape+text, then the checkbox to allow the split is hidden. This is meant to help users to not create document model that would be later problematic to export to Word formats. Change-Id: I63e981bd93fd16195ccdac2d5a5ec785e7c18b97 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160814 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins (cherry picked from commit 4e8895d3d86db3776c56070c395cd727fd4b9101) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160806 diff --git a/sw/qa/uitest/data/floattable-in-shape-text.docx b/sw/qa/uitest/data/floattable-in-shape-text.docx new file mode 100644 index 000000000000..357213d12912 Binary files /dev/null and b/sw/qa/uitest/data/floattable-in-shape-text.docx differ diff --git a/sw/qa/uitest/ui/frmdlg/frmdlg.py b/sw/qa/uitest/ui/frmdlg/frmdlg.py index 51b6f6e53199..36de1876bdd9 100644 --- a/sw/qa/uitest/ui/frmdlg/frmdlg.py +++ b/sw/qa/uitest/ui/frmdlg/frmdlg.py @@ -115,4 +115,39 @@ class Test(UITestCase): # inconsistent. self.assertTrue(to_char_enabled) + def test_floattable_in_shape_text(self): + with self.ui_test.load_file(get_url_for_data_file("floattable-in-shape-text.docx")) as xComponent: + # Given a table in a frame, anchored in shape text (TextBox case): + self.xUITest.executeCommand(".uno:SelectAll") + # Insert frame around the selected table: + args = { + "AnchorType": 0, + } + self.xUITest.executeCommandWithParameters(".uno:InsertFrame", mkPropertyValues(args)) + # Cut it from the body text: + self.xUITest.executeCommand(".uno:Cut") + # Select the shape: + xComponent.CurrentController.select(xComponent.DrawPage.getByIndex(0)) + xWriterDoc = self.xUITest.getTopFocusWindow() + xWriterEdit = xWriterDoc.getChild("writer_edit") + # Begin text edit on the shape: + xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"F2"})) + # Paste it into the shape text: + self.xUITest.executeCommand(".uno:Paste") + + # When editing that frame: + visible = "true" + with self.ui_test.execute_dialog_through_command(".uno:FrameDialog") as xDialog: + xFlysplit = xDialog.getChild("flysplit") + visible = get_state_as_dict(xFlysplit)['Visible'] + + # Then make sure that the option allow split is hidden: + # Without the accompanying fix in place, this test would have failed with: + # AssertionError: 'true' != 'false' + # - true + # + false + # i.e. the UI allowed creating split floating tables in shape text, which is unnecessary + # complexity. + self.assertEqual(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 bdf1c90291ff..b3e2a873ad18 100644 --- a/sw/source/ui/frmdlg/frmpage.cxx +++ b/sw/source/ui/frmdlg/frmpage.cxx @@ -829,6 +829,31 @@ bool ContainsChain(const SwFrameFormat& rFlyFormat) const SwFormatChain& rChain = rFlyFormat.GetChain(); return rChain.GetPrev() || rChain.GetNext(); } + +/// Determines if rFlyFormat is anchored in a fly frame that is part of a draw-format + fly-format +/// ("textbox") pair. +bool InTextBox(const SwFrameFormat& rFlyFormat) +{ + const SwFormatAnchor& rAnchor = rFlyFormat.GetAnchor(); + SwNode* pAnchorNode = rAnchor.GetAnchorNode(); + if (!pAnchorNode) + { + return false; + } + + const SwStartNode* pFlyNode = pAnchorNode->FindFlyStartNode(); + if (!pFlyNode) + { + return false; + } + + if (!pFlyNode->GetFlyFormat()->GetOtherTextBoxFormats()) + { + return false; + } + + return true; +} } void SwFramePage::setOptimalRelWidth() @@ -1067,6 +1092,11 @@ void SwFramePage::Reset( const SfxItemSet *rSet ) m_xFlySplitCB->hide(); } } + else if (pFlyFormat && !m_bNew && InTextBox(*pFlyFormat)) + { + // Disallow split flys in fly frames which form a textbox, i.e. non-editeng shape text. + m_xFlySplitCB->hide(); + } Init(*rSet); m_xAtVertPosED->save_value();