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 <[email protected]>
Change-Id: I639828021dcbba52f6bc21366f23faf7e38bb03e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167726
Tested-by: Jenkins CollaboraOffice <[email protected]>
Reviewed-by: Caolán McNamara <[email protected]>
(cherry picked from commit 95575b8bd026e3ae4aaddf3a023488d7a5fa0976)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167677
Tested-by: Jenkins
diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi
index 4240bb5..3591ca1 100644
--- a/sc/sdi/scalc.sdi
+++ b/sc/sdi/scalc.sdi
@@ -338,7 +338,7 @@


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 ae55a33..3c59c4d 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -876,6 +876,9 @@
                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 ) )
@@ -888,13 +891,33 @@
                            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

@@ -968,6 +991,10 @@
                        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:

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant