sc/sdi/scalc.sdi              |    2 +-
 sc/source/ui/view/cellsh1.cxx |   35 +++++++++++++++++++++++++++++++----
 2 files changed, 32 insertions(+), 5 deletions(-)

New commits:
commit 95575b8bd026e3ae4aaddf3a023488d7a5fa0976
Author:     Bayram Çiçek <bayram.ci...@collabora.com>
AuthorDate: Thu May 16 09:58:28 2024 +0300
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Thu May 16 12:24:13 2024 +0200

    make AutoFill work for Copy cells and Fill series
    
    FID_FILL_AUTO (.uno:AutoFill):
    - added new parameter: SfxBoolItem Copy FN_PARAM_1
      - if the parameter is true, we use "Copy cells", otherwise use "Fill 
series"
    
    Signed-off-by: Bayram Çiçek <bayram.ci...@collabora.com>
    Change-Id: I639828021dcbba52f6bc21366f23faf7e38bb03e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167726
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi
index db3832133b70..f158aa4bbede 100644
--- a/sc/sdi/scalc.sdi
+++ b/sc/sdi/scalc.sdi
@@ -338,7 +338,7 @@ SfxBoolItem AutoComplete FID_AUTOCOMPLETE
 
 
 SfxVoidItem AutoFill FID_FILL_AUTO
-(SfxStringItem EndCell FID_FILL_AUTO)
+(SfxStringItem EndCell FID_FILL_AUTO,SfxBoolItem Copy FN_PARAM_1)
 [
     AutoUpdate = FALSE,
     FastCall = FALSE,
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 9a0542355497..3a44db570119 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -873,6 +873,9 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                 SCROW nFillRow = GetViewData().GetRefEndY();
                 ScDocument& rDoc = GetViewData().GetDocument();
 
+                sal_uInt16 nOrigScFillModeMouseModifier = 
nScFillModeMouseModifier;
+                bool bUseSelection = true;
+
                 if( pReqArgs != nullptr )
                 {
                     if( const SfxStringItem* pItem = pReqArgs->GetItemIfSet( 
FID_FILL_AUTO ) )
@@ -885,13 +888,33 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                             nFillRow = aScAddress.Row();
                             nFillCol = aScAddress.Col();
                         }
+
+                        SCTAB nStartTab, nEndTab;
+                        GetViewData().GetSimpleArea(nStartCol, nStartRow, 
nStartTab, nEndCol,
+                                                    nEndRow, nEndTab);
+                        bUseSelection = false;
                     }
 
-                    SCTAB nStartTab, nEndTab;
-                    GetViewData().GetSimpleArea( nStartCol,nStartRow,nStartTab,
-                                              nEndCol,nEndRow,nEndTab );
+                    const SfxPoolItem* pItem;
+                    if (pReqArgs->HasItem(FN_PARAM_1, &pItem))
+                    {
+                        /*
+                            nScFillModeMouseModifier controls if we "Copy 
cells" or "Fill series"
+                            - if nScFillModeMouseModifier is set to 
"KEY_MOD1", use "Copy cells"
+                            - otherwise use "Fill series"
+
+                            This is also the same with auto fill by dragging 
mouse
+                            - dragging with Ctrl key will set 
nScFillModeMouseModifier to KEY_MOD1, use "Copy cells"
+                            - only dragging will use "Fill series" (no Ctrl 
key)
+                        */
+                        const bool bCopyCells = static_cast<const 
SfxBoolItem*>(pItem)->GetValue();
+                        nScFillModeMouseModifier &= ~KEY_MOD1; // turn off, 
reset to 0
+
+                        if (bCopyCells)
+                            nScFillModeMouseModifier |= KEY_MOD1; // turn on
+                    }
                 }
-                else    // call via mouse
+                if (bUseSelection) // call via mouse or if FN_PARAM_1 exists
                 {
                     //  not in a merged cell
 
@@ -965,6 +988,10 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                         OSL_FAIL( "Direction not unique for autofill" );
                     }
                 }
+
+                // reset nScFillModeMouseModifier to its original state
+                // otherwise, auto fill by dragging will not work as expected
+                nScFillModeMouseModifier = nOrigScFillModeMouseModifier;
             }
             break;
         case FID_FILL_SINGLE_EDIT:

Reply via email to