sc/inc/sc.hrc                 |    3 +
 sc/sdi/cellsh.sdi             |    2 
 sc/sdi/scalc.sdi              |   37 +++++++++++++++++
 sc/source/ui/app/inputwin.cxx |   87 ++++++++++++++++++++++--------------------
 sc/source/ui/inc/inputwin.hxx |    1 
 sc/source/ui/view/cellsh1.cxx |   17 +++++++-
 sc/source/ui/view/cellsh3.cxx |   17 ++++++++
 7 files changed, 123 insertions(+), 41 deletions(-)

New commits:
commit b974bb3a19f2146218981e614349de3674142fa6
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Tue Apr 26 18:15:22 2022 +0200
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Thu Apr 28 08:20:16 2022 +0200

    lok: Introduce uno commands for formulabar actions
    
    thanks to that we can reach them using LOK as formulabar
    is not fully welded yet
    
    Change-Id: Icc1963ab11c1e6e3c407222d76b2a87fdaffa652
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133496
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Mert Tumer <mert.tu...@collabora.com>

diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc
index 1392cd6f20b4..24a6fefa19bf 100644
--- a/sc/inc/sc.hrc
+++ b/sc/inc/sc.hrc
@@ -506,6 +506,9 @@
 #define SID_NEXT_TABLE_SEL      (SID_KEYFUNC_START + 40)
 #define SID_PREV_TABLE_SEL      (SID_KEYFUNC_START + 41)
 
+#define SID_ACCEPT_FORMULA      (SID_KEYFUNC_START + 42)
+#define SID_START_FORMULA       (SID_KEYFUNC_START + 43)
+
 #define SID_KEYFUNC_END         (SID_KEYFUNC_START + 50)
 
 #define SID_NEW_SLOTS           (SID_KEYFUNC_END)
diff --git a/sc/sdi/cellsh.sdi b/sc/sdi/cellsh.sdi
index 38eb86cb27b9..d61f9cb863f8 100644
--- a/sc/sdi/cellsh.sdi
+++ b/sc/sdi/cellsh.sdi
@@ -209,6 +209,8 @@ interface CellSelection
     FID_INSERT_NAME                     [ ExecMethod = ExecuteEdit; 
StateMethod = GetState; ]
     FID_USE_NAME                        [ ExecMethod = ExecuteEdit; 
StateMethod = GetState; ]
     SID_CANCEL                          [ ExecMethod = Execute; ]
+    SID_ACCEPT_FORMULA                  [ ExecMethod = Execute; ]
+    SID_START_FORMULA                   [ ExecMethod = Execute; ]
     SID_TOGGLE_REL                      [ ExecMethod = ExecuteEdit; 
StateMethod = GetState; ]
     SID_POPUP_CONDFRMT                  []
     SID_COLUMN_OPERATIONS               [ ExecMethod = ExecuteEdit; 
StateMethod = GetBlockState; ]
diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi
index bb438041a892..d7087be5c056 100644
--- a/sc/sdi/scalc.sdi
+++ b/sc/sdi/scalc.sdi
@@ -483,6 +483,42 @@ SfxVoidItem Cancel SID_CANCEL
     GroupId = SfxGroupId::Edit;
 ]
 
+SfxVoidItem AcceptFormula SID_ACCEPT_FORMULA
+()
+[
+    AutoUpdate = FALSE,
+    FastCall = FALSE,
+    ReadOnlyDoc = TRUE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+    Asynchron;
+
+    AccelConfig = TRUE,
+    MenuConfig = FALSE,
+    ToolBoxConfig = TRUE,
+    GroupId = SfxGroupId::Edit;
+]
+
+SfxVoidItem StartFormula SID_START_FORMULA
+()
+[
+    AutoUpdate = FALSE,
+    FastCall = FALSE,
+    ReadOnlyDoc = TRUE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+    Asynchron;
+
+    AccelConfig = TRUE,
+    MenuConfig = FALSE,
+    ToolBoxConfig = TRUE,
+    GroupId = SfxGroupId::Edit;
+]
+
 
 SfxVoidItem ChangeChartData SID_CHART_SOURCE
 (SfxStringItem Name SID_CHART_NAME,SfxStringItem Range 
SID_CHART_SOURCE,SfxBoolItem ColHeaders FN_PARAM_1,SfxBoolItem RowHeaders 
FN_PARAM_2)
@@ -6550,6 +6586,7 @@ SfxUInt16Item NumberFormatType SID_NUMBER_TYPE_FORMAT
 
 
 SfxVoidItem AutoSum SID_AUTO_SUM
+(SfxStringItem Function SID_AUTO_SUM)
 [
     AutoUpdate = FALSE,
     FastCall = FALSE,
diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx
index cfad09bd4484..2874ec280f84 100644
--- a/sc/source/ui/app/inputwin.cxx
+++ b/sc/source/ui/app/inputwin.cxx
@@ -364,55 +364,61 @@ void ScInputWindow::Select()
         mxTextWindow->Invalidate(); // Or else the Selection remains
     }
     else if (curItemId == SID_INPUT_EQUAL)
+    {
+        StartFormula();
+    }
+}
+
+void ScInputWindow::StartFormula()
+{
+    ScModule* pScMod = SC_MOD();
+    mxTextWindow->StartEditEngine();
+    if ( pScMod->IsEditMode() ) // Isn't if e.g. protected
     {
         mxTextWindow->StartEditEngine();
-        if ( pScMod->IsEditMode() ) // Isn't if e.g. protected
-        {
-            mxTextWindow->StartEditEngine();
 
-            sal_Int32 nStartPos = 1;
-            sal_Int32 nEndPos = 1;
+        sal_Int32 nStartPos = 1;
+        sal_Int32 nEndPos = 1;
 
-            ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>( 
SfxViewShell::Current()  );
-            if ( pViewSh )
-            {
-                const OUString& rString = mxTextWindow->GetTextString();
-                const sal_Int32 nLen = rString.getLength();
+        ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>( 
SfxViewShell::Current()  );
+        if ( pViewSh )
+        {
+            const OUString& rString = mxTextWindow->GetTextString();
+            const sal_Int32 nLen = rString.getLength();
 
-                ScDocument& rDoc = pViewSh->GetViewData().GetDocument();
-                CellType eCellType = rDoc.GetCellType( 
pViewSh->GetViewData().GetCurPos() );
-                switch ( eCellType )
+            ScDocument& rDoc = pViewSh->GetViewData().GetDocument();
+            CellType eCellType = rDoc.GetCellType( 
pViewSh->GetViewData().GetCurPos() );
+            switch ( eCellType )
+            {
+                case CELLTYPE_VALUE:
                 {
-                    case CELLTYPE_VALUE:
-                    {
-                        nEndPos = nLen + 1;
-                        mxTextWindow->SetTextString("=" +  rString);
-                        break;
-                    }
-                    case CELLTYPE_STRING:
-                    case CELLTYPE_EDIT:
-                        nStartPos = 0;
-                        nEndPos = nLen;
-                        break;
-                    case CELLTYPE_FORMULA:
-                        nEndPos = nLen;
-                        break;
-                    default:
-                        mxTextWindow->SetTextString("=");
-                        break;
+                    nEndPos = nLen + 1;
+                    mxTextWindow->SetTextString("=" +  rString);
+                    break;
                 }
+                case CELLTYPE_STRING:
+                case CELLTYPE_EDIT:
+                    nStartPos = 0;
+                    nEndPos = nLen;
+                    break;
+                case CELLTYPE_FORMULA:
+                    nEndPos = nLen;
+                    break;
+                default:
+                    mxTextWindow->SetTextString("=");
+                    break;
             }
+        }
 
-            EditView* pView = mxTextWindow->GetEditView();
-            if (pView)
-            {
-                if (comphelper::LibreOfficeKit::isActive())
-                    TextGrabFocus();
-                pView->SetSelection( ESelection(0, nStartPos, 0, nEndPos) );
-                pScMod->InputChanged(pView);
-                SetOkCancelMode();
-                pView->SetEditEngineUpdateLayout(true);
-            }
+        EditView* pView = mxTextWindow->GetEditView();
+        if (pView)
+        {
+            if (comphelper::LibreOfficeKit::isActive())
+                TextGrabFocus();
+            pView->SetSelection( ESelection(0, nStartPos, 0, nEndPos) );
+            pScMod->InputChanged(pView);
+            SetOkCancelMode();
+            pView->SetEditEngineUpdateLayout(true);
         }
     }
 }
@@ -991,6 +997,7 @@ IMPL_LINK_NOARG(ScInputWindow, DropdownClickHdl, ToolBox *, 
void)
 {
     ToolBoxItemId nCurID = GetCurItemId();
     EndSelection();
+
     if (nCurID == SID_INPUT_SUM)
     {
         tools::Rectangle aRect(GetItemRect(SID_INPUT_SUM));
diff --git a/sc/source/ui/inc/inputwin.hxx b/sc/source/ui/inc/inputwin.hxx
index 507d91ce5c4a..6bd4c3152712 100644
--- a/sc/source/ui/inc/inputwin.hxx
+++ b/sc/source/ui/inc/inputwin.hxx
@@ -301,6 +301,7 @@ public:
     void            SetSumAssignMode();
     void            EnableButtons( bool bEnable );
 
+    void            StartFormula();
     void            SetFormulaMode( bool bSet );
 
     bool            IsInputActive();
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 31b2a6fdd3fc..edd2dac01280 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -2824,9 +2824,24 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
 
         case SID_AUTO_SUM:
             {
+                const SfxItemSet *pArgs = rReq.GetArgs();
+                const OUString sFunction = pArgs ?
+                    static_cast<const SfxStringItem&>( pArgs->Get( 
SID_AUTO_SUM ) ).GetValue()
+                    : "";
+
+                OpCode eFunction = ocSum;
+                if (sFunction == "average")
+                    eFunction = ocAverage;
+                else if (sFunction == "count")
+                    eFunction = ocCount;
+                else if (sFunction == "min")
+                    eFunction = ocMin;
+                if (sFunction == "max")
+                    eFunction = ocMax;
+
                 bool bSubTotal = false;
                 bool bRangeFinder = false;
-                const OUString aFormula = pTabViewShell->DoAutoSum( 
bRangeFinder, bSubTotal , ocSum );
+                const OUString aFormula = pTabViewShell->DoAutoSum( 
bRangeFinder, bSubTotal , eFunction );
                 if ( !aFormula.isEmpty() )
                 {
                     const sal_Int32 nPar = aFormula.indexOf( '(' );
diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx
index f5c1155ec218..dbcd309cc09c 100644
--- a/sc/source/ui/view/cellsh3.cxx
+++ b/sc/source/ui/view/cellsh3.cxx
@@ -48,6 +48,8 @@
 #include <columnspanset.hxx>
 #include <comphelper/lok.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <inputhdl.hxx>
+#include <inputwin.hxx>
 
 #include <memory>
 
@@ -1032,6 +1034,21 @@ void ScCellShell::Execute( SfxRequest& rReq )
             }
             break;
 
+        case SID_ACCEPT_FORMULA:
+            {
+                if (GetViewData().HasEditView(GetViewData().GetActivePart()))
+                    pScMod->InputEnterHandler();
+            }
+            break;
+
+        case SID_START_FORMULA:
+            {
+                ScInputHandler* pInputHandler = pScMod->GetInputHdl();
+                if (pInputHandler && pInputHandler->GetInputWindow())
+                    pInputHandler->GetInputWindow()->StartFormula();
+            }
+            break;
+
         case SID_DATA_SELECT:
             pTabViewShell->StartDataSelect();
             break;

Reply via email to