sw/source/uibase/uiview/formatclipboard.cxx |  103 ++++++++++++++++------------
 1 file changed, 62 insertions(+), 41 deletions(-)

New commits:
commit 42b82c4411ca9f930fa3742a0a82495f49367cb2
Author:     Oliver Specht <oliver.spe...@cib.de>
AuthorDate: Wed May 29 12:19:24 2024 +0200
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Wed Jul 17 21:01:15 2024 +0200

    tdf#122756 clone formatting includes table number format
    
    In clone formatting the number format of the current cell(s)
    is copied and applied if the target is a table
    
    Change-Id: I0b7dc1d5015aeb2262c8d37f76442519c5b6d655
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168184
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>
    Tested-by: Jenkins
    (cherry picked from commit 3e4aa127416a5947882e6644409468aa1ca039ae)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170484

diff --git a/sw/source/uibase/uiview/formatclipboard.cxx 
b/sw/source/uibase/uiview/formatclipboard.cxx
index 1878b3efc209..1d5d1f80c39c 100644
--- a/sw/source/uibase/uiview/formatclipboard.cxx
+++ b/sw/source/uibase/uiview/formatclipboard.cxx
@@ -23,6 +23,7 @@
 #include <formatclipboard.hxx>
 
 #include <cmdid.h>
+#include <cellatr.hxx>
 #include <charfmt.hxx>
 #include <frmfmt.hxx>
 #include <docstyle.hxx>
@@ -91,51 +92,55 @@ std::unique_ptr<SfxItemSet> lcl_CreateEmptyItemSet( 
SelectionType nSelectionType
     return pItemSet;
 }
 
-void lcl_getTableAttributes( SfxItemSet& rSet, SwWrtShell &rSh )
+void lcl_getTableAttributes( SfxItemSet& rSet, SwWrtShell &rSh, bool 
bAllCellAttrs )
 {
-    std::unique_ptr<SvxBrushItem> 
aBrush(std::make_unique<SvxBrushItem>(RES_BACKGROUND));
-    rSh.GetBoxBackground(aBrush);
-    rSet.Put( *aBrush );
-    if(rSh.GetRowBackground(aBrush))
+    if (bAllCellAttrs)
     {
-        aBrush->SetWhich(SID_ATTR_BRUSH_ROW);
+        std::unique_ptr<SvxBrushItem> 
aBrush(std::make_unique<SvxBrushItem>(RES_BACKGROUND));
+        rSh.GetBoxBackground(aBrush);
+        rSet.Put( *aBrush );
+        if(rSh.GetRowBackground(aBrush))
+        {
+            aBrush->SetWhich(SID_ATTR_BRUSH_ROW);
+            rSet.Put( *aBrush );
+        }
+        else
+            rSet.InvalidateItem(SID_ATTR_BRUSH_ROW);
+        rSh.GetTabBackground(aBrush);
+        aBrush->SetWhich(SID_ATTR_BRUSH_TABLE);
         rSet.Put( *aBrush );
-    }
-    else
-        rSet.InvalidateItem(SID_ATTR_BRUSH_ROW);
-    rSh.GetTabBackground(aBrush);
-    aBrush->SetWhich(SID_ATTR_BRUSH_TABLE);
-    rSet.Put( *aBrush );
-
-    SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
-    rSet.Put(aBoxInfo);
-    rSh.GetTabBorders( rSet );
-
-    std::unique_ptr<SvxFrameDirectionItem> 
aBoxDirection(std::make_unique<SvxFrameDirectionItem>(SvxFrameDirection::Environment,
 RES_FRAMEDIR));
-    if(rSh.GetBoxDirection( aBoxDirection ))
-    {
-        aBoxDirection->SetWhich(FN_TABLE_BOX_TEXTORIENTATION);
-        rSet.Put(std::move(aBoxDirection));
-    }
 
-    rSet.Put(SfxUInt16Item(FN_TABLE_SET_VERT_ALIGN, rSh.GetBoxAlign()));
+        SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
+        rSet.Put(aBoxInfo);
+        rSh.GetTabBorders( rSet );
 
-    rSet.Put( SfxUInt16Item( FN_PARAM_TABLE_HEADLINE, rSh.GetRowsToRepeat() ) 
);
+        std::unique_ptr<SvxFrameDirectionItem> 
aBoxDirection(std::make_unique<SvxFrameDirectionItem>(SvxFrameDirection::Environment,
 RES_FRAMEDIR));
+        if(rSh.GetBoxDirection( aBoxDirection ))
+        {
+            aBoxDirection->SetWhich(FN_TABLE_BOX_TEXTORIENTATION);
+            rSet.Put(std::move(aBoxDirection));
+        }
 
-    SwFrameFormat *pFrameFormat = rSh.GetTableFormat();
-    if(pFrameFormat)
-    {
-        rSet.Put( pFrameFormat->GetShadow() );
-        rSet.Put( pFrameFormat->GetBreak() );
-        rSet.Put( pFrameFormat->GetPageDesc() );
-        rSet.Put( pFrameFormat->GetLayoutSplit() );
-        rSet.Put( pFrameFormat->GetKeep() );
-        rSet.Put( pFrameFormat->GetFrameDir() );
-    }
+        rSet.Put(SfxUInt16Item(FN_TABLE_SET_VERT_ALIGN, rSh.GetBoxAlign()));
+
+        rSet.Put( SfxUInt16Item( FN_PARAM_TABLE_HEADLINE, 
rSh.GetRowsToRepeat() ) );
 
-    std::unique_ptr<SwFormatRowSplit> pSplit = rSh.GetRowSplit();
-    if(pSplit)
-        rSet.Put(std::move(pSplit));
+        SwFrameFormat *pFrameFormat = rSh.GetTableFormat();
+        if(pFrameFormat)
+        {
+            rSet.Put( pFrameFormat->GetShadow() );
+            rSet.Put( pFrameFormat->GetBreak() );
+            rSet.Put( pFrameFormat->GetPageDesc() );
+            rSet.Put( pFrameFormat->GetLayoutSplit() );
+            rSet.Put( pFrameFormat->GetKeep() );
+            rSet.Put( pFrameFormat->GetFrameDir() );
+        }
+
+        std::unique_ptr<SwFormatRowSplit> pSplit = rSh.GetRowSplit();
+        if(pSplit)
+            rSet.Put(std::move(pSplit));
+    }
+    rSh.GetTableBoxFormulaAttrs(rSet);
 }
 
 void lcl_setTableAttributes( const SfxItemSet& rSet, SwWrtShell &rSh )
@@ -216,6 +221,10 @@ void lcl_setTableAttributes( const SfxItemSet& rSet, 
SwWrtShell &rSh )
 
     if( const SwFormatRowSplit* pSplitItem = rSet.GetItemIfSet( RES_ROW_SPLIT, 
false ) )
         rSh.SetRowSplit(*pSplitItem);
+
+    if (rSet.GetItemIfSet( RES_BOXATR_FORMAT, false ))
+        rSh.SetTableBoxFormulaAttrs(rSet);
+
 }
 }//end anonymous namespace
 
@@ -364,22 +373,34 @@ void SwFormatClipboard::Copy( SwWrtShell& rWrtShell, 
SfxItemPool& rPool, bool bP
         }
     }
 
-    if( nSelectionType & SelectionType::TableCell )//only copy table 
attributes if really cells are selected (not only text in tables)
+    if(nSelectionType & (SelectionType::Table | SelectionType::TableCell))
     {
-        m_pTableItemSet = std::make_unique<SfxItemSetFixed<
+        if (nSelectionType & SelectionType::TableCell)
+        {
+            //only copy all table attributes if really cells are selected (not 
only text in tables)
+            m_pTableItemSet = std::make_unique<SfxItemSetFixed<
                 RES_PAGEDESC, RES_BREAK,
                 RES_BACKGROUND, RES_SHADOW, // RES_BOX is inbetween
                 RES_KEEP, RES_KEEP,
                 RES_LAYOUT_SPLIT, RES_LAYOUT_SPLIT,
                 RES_FRAMEDIR, RES_FRAMEDIR,
                 RES_ROW_SPLIT, RES_ROW_SPLIT,
+                RES_BOXATR_FORMAT, RES_BOXATR_FORMAT,
                 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_SHADOW,
                     // SID_ATTR_BORDER_OUTER is inbetween
                 SID_ATTR_BRUSH_ROW, SID_ATTR_BRUSH_TABLE,
                 FN_TABLE_SET_VERT_ALIGN, FN_TABLE_SET_VERT_ALIGN,
                 FN_TABLE_BOX_TEXTORIENTATION, FN_TABLE_BOX_TEXTORIENTATION,
                 FN_PARAM_TABLE_HEADLINE, FN_PARAM_TABLE_HEADLINE>>(rPool);
-        lcl_getTableAttributes( *m_pTableItemSet, rWrtShell );
+        }
+        else
+        {
+            //selection in table should copy number format
+            m_pTableItemSet = std::make_unique<SfxItemSetFixed<
+                RES_BOXATR_FORMAT, RES_BOXATR_FORMAT>>(rPool);
+        }
+
+        lcl_getTableAttributes( *m_pTableItemSet, rWrtShell, nSelectionType & 
SelectionType::TableCell ? true : false);
     }
 
     m_nSelectionType = nSelectionType;

Reply via email to