sw/qa/uitest/ui/frmdlg/frmdlg.py   |    5 +++++
 sw/source/uibase/frmdlg/frmmgr.cxx |    4 ++++
 sw/source/uibase/shells/textsh.cxx |   15 ++++++++++++---
 3 files changed, 21 insertions(+), 3 deletions(-)

New commits:
commit d16375b4dc81e964b96b82adb94cee0a2a5fd9f9
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Nov 14 08:20:47 2023 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Wed Nov 15 09:52:59 2023 +0100

    sw floattable, insert UI: fix unexpected border and spacing
    
    Select an inline table (make sure the whole table is selected), insert a
    frame, then the frame width is already calculated from the table width,
    but an unexpected second frame border / spacing is also added. Given
    that the table already has its own border, adding a second border by
    default makes no sense.
    
    It's possible to disable default borders in SetFrameSizeFromTable(), but
    in case the borders are unchanged, the dialog's output item set will
    still contain no border info, so we will still get the default borders.
    
    Fix the problem by making this explicit: if the dialog's input item set
    had border info and the output item set had none, then still copy over
    the border info from the input to the output in
    SwTextShell::ExecInsert().
    
    This automatically fixes the unwanted border spacing as well, so the
    default frame properties are on par with the ones created by Word import
    filters.
    
    (cherry picked from commit c1a535ee2db757b2e40683dc918cbad8b7429cfa)
    
    Conflicts:
            sw/source/uibase/shells/textsh.cxx
    
    Change-Id: I4c9f165dad7a8bb70cfcfadaea4466a8d174b46e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159430
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/qa/uitest/ui/frmdlg/frmdlg.py b/sw/qa/uitest/ui/frmdlg/frmdlg.py
index bbb9d9a270dd..51b6f6e53199 100644
--- a/sw/qa/uitest/ui/frmdlg/frmdlg.py
+++ b/sw/qa/uitest/ui/frmdlg/frmdlg.py
@@ -98,6 +98,11 @@ class Test(UITestCase):
             # inserted first, only then it could be marked as "split allowed".
             self.assertEqual(fly_split_visible, True)
 
+            # Without the accompanying fix in place, this test would have 
failed with:
+            # AssertionError: 2 != 0
+            # i.e. the frame had a border by default when the table already 
had its own border.
+            
self.assertEqual(xComponent.TextFrames.Frame1.LeftBorder.LineWidth, 0)
+
     def test_insert_simple_frame(self):
         # Given a Writer document:
         with self.ui_test.create_doc_in_start_center("writer") as xComponent:
diff --git a/sw/source/uibase/frmdlg/frmmgr.cxx 
b/sw/source/uibase/frmdlg/frmmgr.cxx
index c30ffcea2284..2f857a8b30e6 100644
--- a/sw/source/uibase/frmdlg/frmmgr.cxx
+++ b/sw/source/uibase/frmdlg/frmmgr.cxx
@@ -666,6 +666,10 @@ void SwFlyFrameAttrMgr::SetFrameSizeFromTable()
     // The whole table is selected: default fly width should be the table width
     // in this case.
     m_aSet.Put(pTableFormat->GetFrameSize());
+
+    // The table can have its own border already, so an additional fly border 
makes no sense.
+    SvxBoxItem aBoxItem(RES_BOX);
+    m_aSet.Put(aBoxItem);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/shells/textsh.cxx 
b/sw/source/uibase/shells/textsh.cxx
index 06e5fec50ab2..01d16ae85f99 100644
--- a/sw/source/uibase/shells/textsh.cxx
+++ b/sw/source/uibase/shells/textsh.cxx
@@ -530,7 +530,7 @@ void SwTextShell::ExecInsert(SfxRequest &rReq)
                                                   GetView().GetViewFrame(),
                                                   GetView().GetFrameWeld(),
                                                   aSet));
-            pDlg->StartExecuteAsync([pDlg, nSlot, this](sal_Int32 nResult) {
+            pDlg->StartExecuteAsync([aSet, pDlg, nSlot, this](sal_Int32 
nResult) {
                 if (nResult == RET_OK && pDlg->GetOutputItemSet())
                 {
                     SwFlyFrameAttrMgr aAttrMgr( true, GetShellPtr(), 
Frmmgr_Type::TEXT, nullptr );
@@ -540,8 +540,17 @@ void SwTextShell::ExecInsert(SfxRequest &rReq)
                     rShell.StartAllAction();
                     rShell.StartUndo(SwUndoId::INSERT);
 
-                    const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
-                        aAttrMgr.SetAttrSet(*pOutSet);
+                    SfxItemSet aOutSet(*pDlg->GetOutputItemSet());
+                    const SvxBoxItem* pBox = aSet.GetItem(RES_BOX);
+                    if (pBox && !aOutSet.HasItem(RES_BOX))
+                    {
+                        // The input set had border info but the output set 
not, then copy it over
+                        // to not lose the custom border info. This can happen 
when a whole table
+                        // is selected and that case has its own defaults, not 
matching the frame
+                        // style.
+                        aOutSet.Put(*pBox);
+                    }
+                    aAttrMgr.SetAttrSet(aOutSet);
 
                     // At first delete the selection at the ClickToEditField.
                     if( rShell.IsInClickToEdit() )

Reply via email to