sc/Library_sc.mk                                    |    4 
 sc/source/ui/docshell/SheetViewOperationsTester.cxx |    8 +
 sc/source/ui/docshell/docfunc.cxx                   |  152 +-------------------
 sc/source/ui/inc/SheetViewOperationsTester.hxx      |    4 
 sc/source/ui/inc/docfunc.hxx                        |    8 +
 sc/source/ui/inc/operation/SetEditTextOperation.hxx |   41 +++++
 sc/source/ui/inc/operation/SetFormulaOperation.hxx  |   41 +++++
 sc/source/ui/inc/operation/SetStringOperation.hxx   |   40 +++++
 sc/source/ui/inc/operation/SetValueOperation.hxx    |   39 +++++
 sc/source/ui/operation/SetEditTextOperation.cxx     |   76 ++++++++++
 sc/source/ui/operation/SetFormulaOperation.cxx      |   92 ++++++++++++
 sc/source/ui/operation/SetStringOperation.cxx       |   76 ++++++++++
 sc/source/ui/operation/SetValueOperation.cxx        |   72 +++++++++
 13 files changed, 513 insertions(+), 140 deletions(-)

New commits:
commit b126aba564494fc7353e6f8a944cf71a6aaeffee
Author:     Tomaž Vajngerl <[email protected]>
AuthorDate: Tue Feb 10 16:51:17 2026 +0900
Commit:     Miklos Vajna <[email protected]>
CommitDate: Mon Feb 16 13:49:33 2026 +0100

    sc: Introduce various set operations and move code from ScDocFunc
    
    Add SetValueOperation, SetStringOperation, SetFormulaOperation and
    SetEditTextOperation. Move the code from ScDocFunc.
    
    Makes no other functional change.
    
    Change-Id: I0ba470bd2bc0e5882201011db9b69e8df9108175
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199181
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index eb7c339d7c42..137c72f06ed8 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -532,7 +532,11 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
     sc/source/ui/operation/DeleteCellOperation \
     sc/source/ui/operation/DeleteContentOperation \
     sc/source/ui/operation/Operation \
+    sc/source/ui/operation/SetEditTextOperation \
+    sc/source/ui/operation/SetFormulaOperation \
     sc/source/ui/operation/SetNormalStringOperation \
+    sc/source/ui/operation/SetStringOperation \
+    sc/source/ui/operation/SetValueOperation \
     sc/source/ui/operation/SortOperation \
     sc/source/ui/pagedlg/areasdlg \
     sc/source/ui/pagedlg/tphfedit \
diff --git a/sc/source/ui/docshell/SheetViewOperationsTester.cxx 
b/sc/source/ui/docshell/SheetViewOperationsTester.cxx
index 6ca6f9a62e1c..dc7c39ce58d9 100644
--- a/sc/source/ui/docshell/SheetViewOperationsTester.cxx
+++ b/sc/source/ui/docshell/SheetViewOperationsTester.cxx
@@ -35,6 +35,14 @@ constexpr std::string_view getOperationName(OperationType 
eOperation)
             return "TransliterateText";
         case OperationType::SetNormalString:
             return "SetNormalString";
+        case OperationType::SetValue:
+            return "SetValue";
+        case OperationType::SetString:
+            return "SetString";
+        case OperationType::SetTextEdit:
+            return "SetTextEdit";
+        case OperationType::SetFormula:
+            return "SetFormula";
         case OperationType::SetNoteText:
             return "SetNoteText";
         case OperationType::ReplaceNoteText:
diff --git a/sc/source/ui/docshell/docfunc.cxx 
b/sc/source/ui/docshell/docfunc.cxx
index 0eb84decbca6..f9211d3f75ff 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -113,6 +113,10 @@
 #include <operation/DeleteContentOperation.hxx>
 #include <operation/DeleteCellOperation.hxx>
 #include <operation/SetNormalStringOperation.hxx>
+#include <operation/SetValueOperation.hxx>
+#include <operation/SetStringOperation.hxx>
+#include <operation/SetFormulaOperation.hxx>
+#include <operation/SetEditTextOperation.hxx>
 #include <basic/basmgr.hxx>
 #include <set>
 #include <vector>
@@ -695,37 +699,8 @@ bool ScDocFunc::SetNormalString(bool& o_rbNumFmtSet, const 
ScAddress& rPos, cons
 
 bool ScDocFunc::SetValueCell( const ScAddress& rPos, double fVal, bool 
bInteraction )
 {
-    ScDocShellModificator aModificator( rDocShell );
-    ScDocument& rDoc = rDocShell.GetDocument();
-    bool bUndo = rDoc.IsUndoEnabled();
-
-    bool bHeight = rDoc.HasAttrib(ScRange(rPos), HasAttrFlags::NeedHeight);
-
-    ScCellValue aOldVal;
-    if (bUndo)
-        aOldVal.assign(rDoc, rPos);
-
-    rDoc.SetValue(rPos, fVal);
-
-    if (bUndo)
-    {
-        SfxUndoManager* pUndoMgr = rDocShell.GetUndoManager();
-        ScCellValue aNewVal;
-        aNewVal.assign(rDoc, rPos);
-        pUndoMgr->AddUndoAction(std::make_unique<ScUndoSetCell>(&rDocShell, 
rPos, aOldVal, aNewVal));
-    }
-
-    if (bHeight)
-        AdjustRowHeight(ScRange(rPos), true, !bInteraction);
-
-    rDocShell.PostPaintCell( rPos );
-    aModificator.SetDocumentModified();
-
-    // #103934#; notify editline and cell in edit mode
-    if (!bInteraction)
-        NotifyInputHandler( rPos );
-
-    return true;
+    sc::SetValueOperation aOperation(*this, rDocShell, rPos, fVal, 
!bInteraction);
+    return aOperation.run();
 }
 
 void ScDocFunc::SetValueCells( const ScAddress& rPos, const 
std::vector<double>& aVals, bool bInteraction )
@@ -764,74 +739,14 @@ void ScDocFunc::SetValueCells( const ScAddress& rPos, 
const std::vector<double>&
 
 bool ScDocFunc::SetStringCell( const ScAddress& rPos, const OUString& rStr, 
bool bInteraction )
 {
-    ScDocShellModificator aModificator( rDocShell );
-    ScDocument& rDoc = rDocShell.GetDocument();
-    bool bUndo = rDoc.IsUndoEnabled();
-
-    bool bHeight = rDoc.HasAttrib(ScRange(rPos), HasAttrFlags::NeedHeight);
-
-    ScCellValue aOldVal;
-    if (bUndo)
-        aOldVal.assign(rDoc, rPos);
-
-    ScSetStringParam aParam;
-    aParam.setTextInput();
-    rDoc.SetString(rPos, rStr, &aParam);
-
-    if (bUndo)
-    {
-        SfxUndoManager* pUndoMgr = rDocShell.GetUndoManager();
-        ScCellValue aNewVal;
-        aNewVal.assign(rDoc, rPos);
-        pUndoMgr->AddUndoAction(std::make_unique<ScUndoSetCell>(&rDocShell, 
rPos, aOldVal, aNewVal));
-    }
-
-    if (bHeight)
-        AdjustRowHeight(ScRange(rPos), true, !bInteraction);
-
-    rDocShell.PostPaintCell( rPos );
-    aModificator.SetDocumentModified();
-
-    // #103934#; notify editline and cell in edit mode
-    if (!bInteraction)
-        NotifyInputHandler( rPos );
-
-    return true;
+    sc::SetStringOperation aOperation(*this, rDocShell, rPos, rStr, 
!bInteraction);
+    return aOperation.run();
 }
 
 bool ScDocFunc::SetEditCell( const ScAddress& rPos, const EditTextObject& 
rStr, bool bInteraction )
 {
-    ScDocShellModificator aModificator( rDocShell );
-    ScDocument& rDoc = rDocShell.GetDocument();
-    bool bUndo = rDoc.IsUndoEnabled();
-
-    bool bHeight = rDoc.HasAttrib(ScRange(rPos), HasAttrFlags::NeedHeight);
-
-    ScCellValue aOldVal;
-    if (bUndo)
-        aOldVal.assign(rDoc, rPos);
-
-    rDoc.SetEditText(rPos, rStr.Clone());
-
-    if (bUndo)
-    {
-        SfxUndoManager* pUndoMgr = rDocShell.GetUndoManager();
-        ScCellValue aNewVal;
-        aNewVal.assign(rDoc, rPos);
-        pUndoMgr->AddUndoAction(std::make_unique<ScUndoSetCell>(&rDocShell, 
rPos, aOldVal, aNewVal));
-    }
-
-    if (bHeight)
-        AdjustRowHeight(ScRange(rPos), true, !bInteraction);
-
-    rDocShell.PostPaintCell( rPos );
-    aModificator.SetDocumentModified();
-
-    // #103934#; notify editline and cell in edit mode
-    if (!bInteraction)
-        NotifyInputHandler( rPos );
-
-    return true;
+    sc::SetEditTextOperation aOperation(*this, rDocShell, rPos, rStr, 
!bInteraction);
+    return aOperation.run();
 }
 
 bool ScDocFunc::SetStringOrEditCell( const ScAddress& rPos, const OUString& 
rStr, bool bInteraction )
@@ -851,51 +766,8 @@ bool ScDocFunc::SetStringOrEditCell( const ScAddress& 
rPos, const OUString& rStr
 
 bool ScDocFunc::SetFormulaCell( const ScAddress& rPos, ScFormulaCell* pCell, 
bool bInteraction )
 {
-    std::unique_ptr<ScFormulaCell> xCell(pCell);
-
-    ScDocShellModificator aModificator( rDocShell );
-    ScDocument& rDoc = rDocShell.GetDocument();
-    bool bUndo = rDoc.IsUndoEnabled();
-
-    bool bHeight = rDoc.HasAttrib(ScRange(rPos), HasAttrFlags::NeedHeight);
-
-    ScCellValue aOldVal;
-    if (bUndo)
-        aOldVal.assign(rDoc, rPos);
-
-    pCell = rDoc.SetFormulaCell(rPos, xCell.release());
-
-    // For performance reasons API calls may disable calculation while
-    // operating and recalculate once when done. If through user interaction
-    // and AutoCalc is disabled, calculate the formula (without its
-    // dependencies) once so the result matches the current document's content.
-    if (bInteraction && !rDoc.GetAutoCalc() && pCell)
-    {
-        // calculate just the cell once and set Dirty again
-        pCell->Interpret();
-        pCell->SetDirtyVar();
-        rDoc.PutInFormulaTree( pCell);
-    }
-
-    if (bUndo)
-    {
-        SfxUndoManager* pUndoMgr = rDocShell.GetUndoManager();
-        ScCellValue aNewVal;
-        aNewVal.assign(rDoc, rPos);
-        pUndoMgr->AddUndoAction(std::make_unique<ScUndoSetCell>(&rDocShell, 
rPos, aOldVal, aNewVal));
-    }
-
-    if (bHeight)
-        AdjustRowHeight(ScRange(rPos), true, !bInteraction);
-
-    rDocShell.PostPaintCell( rPos );
-    aModificator.SetDocumentModified();
-
-    // #103934#; notify editline and cell in edit mode
-    if (!bInteraction)
-        NotifyInputHandler( rPos );
-
-    return true;
+    sc::SetFormulaOperation aOperation(*this, rDocShell, rPos, pCell, 
!bInteraction);
+    return aOperation.run();
 }
 
 bool ScDocFunc::SetFormulaCells( const ScAddress& rPos, 
std::vector<ScFormulaCell*>& rCells, bool bInteraction )
diff --git a/sc/source/ui/inc/SheetViewOperationsTester.hxx 
b/sc/source/ui/inc/SheetViewOperationsTester.hxx
index b0e3281b308b..898d7d735299 100644
--- a/sc/source/ui/inc/SheetViewOperationsTester.hxx
+++ b/sc/source/ui/inc/SheetViewOperationsTester.hxx
@@ -23,6 +23,10 @@ enum class OperationType
     DeleteCell,
     TransliterateText,
     SetNormalString,
+    SetValue,
+    SetString,
+    SetTextEdit,
+    SetFormula,
     SetNoteText,
     ReplaceNoteText,
     InsertColumnsBefore,
diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx
index e8a3ef5fb514..25f53bf6e029 100644
--- a/sc/source/ui/inc/docfunc.hxx
+++ b/sc/source/ui/inc/docfunc.hxx
@@ -62,6 +62,10 @@ namespace sc
     class DeleteContentOperation;
     class DeleteCellOperation;
     class SetNormalStringOperation;
+    class SetValueOperation;
+    class SetStringOperation;
+    class SetEditTextOperation;
+    class SetFormulaOperation;
 }
 namespace tools
 {
@@ -73,6 +77,10 @@ class ScDocFunc
     friend class sc::DeleteContentOperation;
     friend class sc::DeleteCellOperation;
     friend class sc::SetNormalStringOperation;
+    friend class sc::SetValueOperation;
+    friend class sc::SetStringOperation;
+    friend class sc::SetEditTextOperation;
+    friend class sc::SetFormulaOperation;
 
     ScDocShell&     rDocShell;
     static bool CheckSheetViewProtection(sc::OperationType eOperation);
diff --git a/sc/source/ui/inc/operation/SetEditTextOperation.hxx 
b/sc/source/ui/inc/operation/SetEditTextOperation.hxx
new file mode 100644
index 000000000000..558771184af5
--- /dev/null
+++ b/sc/source/ui/inc/operation/SetEditTextOperation.hxx
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include "Operation.hxx"
+#include <sal/types.h>
+#include <rtl/ustring.hxx>
+
+class ScDocShell;
+class ScAddress;
+class ScDocFunc;
+class EditTextObject;
+
+namespace sc
+{
+/** Operation which sets a text object to a cell. */
+class SetEditTextOperation : public Operation
+{
+private:
+    ScDocFunc& mrDocFunc;
+    ScDocShell& mrDocShell;
+    ScAddress const& mrPosition;
+    EditTextObject const& mrEditObject;
+
+    bool runImplementation() override;
+
+public:
+    SetEditTextOperation(ScDocFunc& rDocFunc, ScDocShell& rDocShell, const 
ScAddress& rPosition,
+                         const EditTextObject& rEditObject, bool bApi);
+};
+
+} // end sc namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/operation/SetFormulaOperation.hxx 
b/sc/source/ui/inc/operation/SetFormulaOperation.hxx
new file mode 100644
index 000000000000..06921b7bea63
--- /dev/null
+++ b/sc/source/ui/inc/operation/SetFormulaOperation.hxx
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include "Operation.hxx"
+#include <sal/types.h>
+#include <rtl/ustring.hxx>
+
+class ScDocShell;
+class ScAddress;
+class ScDocFunc;
+class ScFormulaCell;
+
+namespace sc
+{
+/** Operation which sets a formula to a cell. */
+class SetFormulaOperation : public Operation
+{
+private:
+    ScDocFunc& mrDocFunc;
+    ScDocShell& mrDocShell;
+    ScAddress const& mrPosition;
+    ScFormulaCell* mpFormulaCell;
+
+    bool runImplementation() override;
+
+public:
+    SetFormulaOperation(ScDocFunc& rDocFunc, ScDocShell& rDocShell, const 
ScAddress& rPosition,
+                        ScFormulaCell* pFormulaCell, bool bApi);
+};
+
+} // end sc namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/operation/SetStringOperation.hxx 
b/sc/source/ui/inc/operation/SetStringOperation.hxx
new file mode 100644
index 000000000000..651d60140cff
--- /dev/null
+++ b/sc/source/ui/inc/operation/SetStringOperation.hxx
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include "Operation.hxx"
+#include <sal/types.h>
+#include <rtl/ustring.hxx>
+
+class ScDocShell;
+class ScAddress;
+class ScDocFunc;
+
+namespace sc
+{
+/** Operation which sets a string to a cell. */
+class SetStringOperation : public Operation
+{
+private:
+    ScDocFunc& mrDocFunc;
+    ScDocShell& mrDocShell;
+    ScAddress const& mrPosition;
+    OUString const& mrString;
+
+    bool runImplementation() override;
+
+public:
+    SetStringOperation(ScDocFunc& rDocFunc, ScDocShell& rDocShell, const 
ScAddress& rPosition,
+                       OUString const& rString, bool bApi);
+};
+
+} // end sc namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/operation/SetValueOperation.hxx 
b/sc/source/ui/inc/operation/SetValueOperation.hxx
new file mode 100644
index 000000000000..319cf2f4850f
--- /dev/null
+++ b/sc/source/ui/inc/operation/SetValueOperation.hxx
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include "Operation.hxx"
+#include <sal/types.h>
+#include <rtl/ustring.hxx>
+
+class ScDocShell;
+class ScAddress;
+class ScDocFunc;
+
+namespace sc
+{
+/** Operation which sets a floating point value to a cell. */
+class SetValueOperation : public Operation
+{
+private:
+    ScDocFunc& mrDocFunc;
+    ScDocShell& mrDocShell;
+    ScAddress const& mrPosition;
+    double mfValue;
+
+    bool runImplementation() override;
+
+public:
+    SetValueOperation(ScDocFunc& rDocFunc, ScDocShell& rDocShell, const 
ScAddress& rPosition,
+                      double fValue, bool bApi);
+};
+} // end sc namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/operation/SetEditTextOperation.cxx 
b/sc/source/ui/operation/SetEditTextOperation.cxx
new file mode 100644
index 000000000000..5f97070192cd
--- /dev/null
+++ b/sc/source/ui/operation/SetEditTextOperation.cxx
@@ -0,0 +1,76 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <operation/SetEditTextOperation.hxx>
+
+#include <docfuncutil.hxx>
+#include <docfunc.hxx>
+#include <address.hxx>
+#include <editable.hxx>
+#include <undocell.hxx>
+#include <validat.hxx>
+#include <detfunc.hxx>
+#include <stringutil.hxx>
+
+#include <memory>
+
+namespace sc
+{
+SetEditTextOperation::SetEditTextOperation(ScDocFunc& rDocFunc, ScDocShell& 
rDocShell,
+                                           const ScAddress& rPosition,
+                                           const EditTextObject& rEditObject, 
bool bApi)
+    : Operation(OperationType::SetTextEdit, true, bApi)
+    , mrDocFunc(rDocFunc)
+    , mrDocShell(rDocShell)
+    , mrPosition(rPosition)
+    , mrEditObject(rEditObject)
+{
+}
+
+bool SetEditTextOperation::runImplementation()
+{
+    ScAddress const& rPos = mrPosition;
+
+    ScDocShellModificator aModificator(mrDocShell);
+    ScDocument& rDoc = mrDocShell.GetDocument();
+    bool bUndo = rDoc.IsUndoEnabled();
+
+    bool bHeight = rDoc.HasAttrib(ScRange(rPos), HasAttrFlags::NeedHeight);
+
+    ScCellValue aOldVal;
+    if (bUndo)
+        aOldVal.assign(rDoc, rPos);
+
+    rDoc.SetEditText(rPos, mrEditObject.Clone());
+
+    if (bUndo)
+    {
+        SfxUndoManager* pUndoMgr = mrDocShell.GetUndoManager();
+        ScCellValue aNewVal;
+        aNewVal.assign(rDoc, rPos);
+        pUndoMgr->AddUndoAction(
+            std::make_unique<ScUndoSetCell>(&mrDocShell, rPos, aOldVal, 
aNewVal));
+    }
+
+    if (bHeight)
+        mrDocFunc.AdjustRowHeight(ScRange(rPos), true, mbApi);
+
+    mrDocShell.PostPaintCell(rPos);
+    aModificator.SetDocumentModified();
+
+    // #103934#; notify editline and cell in edit mode
+    if (mbApi)
+        mrDocFunc.NotifyInputHandler(rPos);
+
+    return true;
+}
+
+} // end sc namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/operation/SetFormulaOperation.cxx 
b/sc/source/ui/operation/SetFormulaOperation.cxx
new file mode 100644
index 000000000000..01b6f4d2440c
--- /dev/null
+++ b/sc/source/ui/operation/SetFormulaOperation.cxx
@@ -0,0 +1,92 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <operation/SetFormulaOperation.hxx>
+
+#include <docfuncutil.hxx>
+#include <docfunc.hxx>
+#include <address.hxx>
+#include <editable.hxx>
+#include <undocell.hxx>
+#include <validat.hxx>
+#include <detfunc.hxx>
+#include <stringutil.hxx>
+#include <formulacell.hxx>
+
+#include <memory>
+
+namespace sc
+{
+SetFormulaOperation::SetFormulaOperation(ScDocFunc& rDocFunc, ScDocShell& 
rDocShell,
+                                         const ScAddress& rPosition, 
ScFormulaCell* pFormulaCell,
+                                         bool bApi)
+    : Operation(OperationType::SetFormula, true, bApi)
+    , mrDocFunc(rDocFunc)
+    , mrDocShell(rDocShell)
+    , mrPosition(rPosition)
+    , mpFormulaCell(pFormulaCell)
+{
+}
+
+bool SetFormulaOperation::runImplementation()
+{
+    ScAddress const& rPos = mrPosition;
+
+    ScFormulaCell* pCell(mpFormulaCell);
+    std::unique_ptr<ScFormulaCell> xCell(mpFormulaCell);
+
+    ScDocShellModificator aModificator(mrDocShell);
+    ScDocument& rDoc = mrDocShell.GetDocument();
+    bool bUndo = rDoc.IsUndoEnabled();
+
+    bool bHeight = rDoc.HasAttrib(ScRange(rPos), HasAttrFlags::NeedHeight);
+
+    ScCellValue aOldVal;
+    if (bUndo)
+        aOldVal.assign(rDoc, rPos);
+
+    pCell = rDoc.SetFormulaCell(rPos, xCell.release());
+
+    // For performance reasons API calls may disable calculation while
+    // operating and recalculate once when done. If through user interaction
+    // and AutoCalc is disabled, calculate the formula (without its
+    // dependencies) once so the result matches the current document's content.
+    if (!mbApi && !rDoc.GetAutoCalc() && pCell)
+    {
+        // calculate just the cell once and set Dirty again
+        pCell->Interpret();
+        pCell->SetDirtyVar();
+        rDoc.PutInFormulaTree(pCell);
+    }
+
+    if (bUndo)
+    {
+        SfxUndoManager* pUndoMgr = mrDocShell.GetUndoManager();
+        ScCellValue aNewVal;
+        aNewVal.assign(rDoc, rPos);
+        pUndoMgr->AddUndoAction(
+            std::make_unique<ScUndoSetCell>(&mrDocShell, rPos, aOldVal, 
aNewVal));
+    }
+
+    if (bHeight)
+        mrDocFunc.AdjustRowHeight(ScRange(rPos), true, mbApi);
+
+    mrDocShell.PostPaintCell(rPos);
+    aModificator.SetDocumentModified();
+
+    // #103934#; notify editline and cell in edit mode
+    if (mbApi)
+        mrDocFunc.NotifyInputHandler(rPos);
+
+    return true;
+}
+
+} // end sc namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/operation/SetStringOperation.cxx 
b/sc/source/ui/operation/SetStringOperation.cxx
new file mode 100644
index 000000000000..ec74cbd7750d
--- /dev/null
+++ b/sc/source/ui/operation/SetStringOperation.cxx
@@ -0,0 +1,76 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <operation/SetStringOperation.hxx>
+
+#include <docfuncutil.hxx>
+#include <docfunc.hxx>
+#include <address.hxx>
+#include <editable.hxx>
+#include <undocell.hxx>
+#include <validat.hxx>
+#include <stringutil.hxx>
+
+#include <memory>
+
+namespace sc
+{
+SetStringOperation::SetStringOperation(ScDocFunc& rDocFunc, ScDocShell& 
rDocShell,
+                                       const ScAddress& rPosition, OUString 
const& rString,
+                                       bool bApi)
+    : Operation(OperationType::SetString, true, bApi)
+    , mrDocFunc(rDocFunc)
+    , mrDocShell(rDocShell)
+    , mrPosition(rPosition)
+    , mrString(rString)
+{
+}
+
+bool SetStringOperation::runImplementation()
+{
+    ScAddress const& rPos = mrPosition;
+
+    ScDocShellModificator aModificator(mrDocShell);
+    ScDocument& rDoc = mrDocShell.GetDocument();
+    bool bUndo = rDoc.IsUndoEnabled();
+
+    bool bHeight = rDoc.HasAttrib(ScRange(rPos), HasAttrFlags::NeedHeight);
+
+    ScCellValue aOldVal;
+    if (bUndo)
+        aOldVal.assign(rDoc, rPos);
+
+    ScSetStringParam aParam;
+    aParam.setTextInput();
+    rDoc.SetString(rPos, mrString, &aParam);
+
+    if (bUndo)
+    {
+        SfxUndoManager* pUndoMgr = mrDocShell.GetUndoManager();
+        ScCellValue aNewVal;
+        aNewVal.assign(rDoc, rPos);
+        pUndoMgr->AddUndoAction(
+            std::make_unique<ScUndoSetCell>(&mrDocShell, rPos, aOldVal, 
aNewVal));
+    }
+
+    if (bHeight)
+        mrDocFunc.AdjustRowHeight(ScRange(rPos), true, mbApi);
+
+    mrDocShell.PostPaintCell(rPos);
+    aModificator.SetDocumentModified();
+
+    // #103934#; notify editline and cell in edit mode
+    if (mbApi)
+        mrDocFunc.NotifyInputHandler(rPos);
+
+    return true;
+}
+} // end sc namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/operation/SetValueOperation.cxx 
b/sc/source/ui/operation/SetValueOperation.cxx
new file mode 100644
index 000000000000..a0250cc6ea92
--- /dev/null
+++ b/sc/source/ui/operation/SetValueOperation.cxx
@@ -0,0 +1,72 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <operation/SetValueOperation.hxx>
+
+#include <docfuncutil.hxx>
+#include <docfunc.hxx>
+#include <address.hxx>
+#include <editable.hxx>
+#include <undocell.hxx>
+#include <validat.hxx>
+#include <stringutil.hxx>
+
+#include <memory>
+
+namespace sc
+{
+SetValueOperation::SetValueOperation(ScDocFunc& rDocFunc, ScDocShell& 
rDocShell,
+                                     const ScAddress& rPosition, double 
fValue, bool bApi)
+    : Operation(OperationType::SetValue, true, bApi)
+    , mrDocFunc(rDocFunc)
+    , mrDocShell(rDocShell)
+    , mrPosition(rPosition)
+    , mfValue(fValue)
+{
+}
+
+bool SetValueOperation::runImplementation()
+{
+    ScAddress const& rPos = mrPosition;
+
+    ScDocShellModificator aModificator(mrDocShell);
+    ScDocument& rDoc = mrDocShell.GetDocument();
+    bool bUndo = rDoc.IsUndoEnabled();
+    bool bHeight = rDoc.HasAttrib(ScRange(rPos), HasAttrFlags::NeedHeight);
+
+    ScCellValue aOldVal;
+    if (bUndo)
+        aOldVal.assign(rDoc, rPos);
+
+    rDoc.SetValue(rPos, mfValue);
+
+    if (bUndo)
+    {
+        SfxUndoManager* pUndoMgr = mrDocShell.GetUndoManager();
+        ScCellValue aNewVal;
+        aNewVal.assign(rDoc, rPos);
+        pUndoMgr->AddUndoAction(
+            std::make_unique<ScUndoSetCell>(&mrDocShell, rPos, aOldVal, 
aNewVal));
+    }
+
+    if (bHeight)
+        mrDocFunc.AdjustRowHeight(ScRange(rPos), true, mbApi);
+
+    mrDocShell.PostPaintCell(rPos);
+    aModificator.SetDocumentModified();
+
+    // #103934#; notify editline and cell in edit mode
+    if (mbApi)
+        mrDocFunc.NotifyInputHandler(rPos);
+
+    return true;
+}
+} // end sc namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to