[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - 2 commits - sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Thu Mar 21 16:37:44 PDT 2013


 sc/source/ui/docshell/docfunc.cxx |    2 
 sc/source/ui/inc/undocell.hxx     |   67 ++++++++++-------
 sc/source/ui/undo/undocell.cxx    |  148 ++++++++++++++++++++++++++------------
 3 files changed, 146 insertions(+), 71 deletions(-)

New commits:
commit 34f8a35237f15098d4e1c0d1bb0f59a1c571dfdc
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Mar 21 17:25:37 2013 -0400

    Add assign() and commit() methods to make it easier to use this class.
    
    Change-Id: Ia9c2fe3fea3dfeef0410e8c430d5953a66b0cba1

diff --git a/sc/source/ui/inc/undocell.hxx b/sc/source/ui/inc/undocell.hxx
index 2f5e370..a9ff3f1 100644
--- a/sc/source/ui/inc/undocell.hxx
+++ b/sc/source/ui/inc/undocell.hxx
@@ -34,7 +34,11 @@ class SdrUndoAction;
 class ScDetOpList;
 class ScDetOpData;
 class ScRangeName;
+class ScDocument;
 
+/**
+ * Store arbitrary cell value of any kind for undo objects.
+ */
 struct ScUndoCellValue
 {
     CellType meType;
@@ -52,6 +56,18 @@ struct ScUndoCellValue
     ScUndoCellValue( const ScFormulaCell& rFormula );
     ScUndoCellValue( const ScUndoCellValue& r );
     ~ScUndoCellValue();
+
+    void clear();
+
+    /**
+     * Take cell value from specified position in specified document.
+     */
+    void assign( const ScDocument& rDoc, const ScAddress& rPos );
+
+    /**
+     * Set cell value at specified position in specified document.
+     */
+    void commit( ScDocument& rDoc, const ScAddress& rPos );
 };
 
 class ScUndoCursorAttr: public ScSimpleUndo
@@ -94,6 +110,8 @@ private:
 class ScUndoEnterData: public ScSimpleUndo
 {
 public:
+    TYPEINFO();
+
     struct Value
     {
         SCTAB mnTab;
@@ -106,7 +124,6 @@ public:
 
     typedef std::vector<Value> ValuesType;
 
-                    TYPEINFO();
     ScUndoEnterData(
         ScDocShell* pNewDocShell, const ScAddress& rPos,
         ValuesType& rOldValues, const OUString& rNewStr, EditTextObject* pObj = NULL );
diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx
index 7715624..171a758 100644
--- a/sc/source/ui/undo/undocell.cxx
+++ b/sc/source/ui/undo/undocell.cxx
@@ -71,6 +71,11 @@ ScUndoCellValue::ScUndoCellValue( const ScUndoCellValue& r ) : meType(r.meType),
 
 ScUndoCellValue::~ScUndoCellValue()
 {
+    clear();
+}
+
+void ScUndoCellValue::clear()
+{
     switch (meType)
     {
         case CELLTYPE_STRING:
@@ -85,6 +90,59 @@ ScUndoCellValue::~ScUndoCellValue()
         default:
             ;
     }
+
+    // Reset to empty value.
+    meType = CELLTYPE_NONE;
+    mfValue = 0.0;
+}
+
+void ScUndoCellValue::assign( const ScDocument& rDoc, const ScAddress& rPos )
+{
+    clear();
+
+    meType = rDoc.GetCellType(rPos);
+    switch (meType)
+    {
+        case CELLTYPE_STRING:
+            mpString = new OUString(rDoc.GetString(rPos));
+        break;
+        case CELLTYPE_EDIT:
+            mpEditText = rDoc.GetEditText(rPos)->Clone();
+        break;
+        case CELLTYPE_VALUE:
+            mfValue = rDoc.GetValue(rPos);
+        break;
+        case CELLTYPE_FORMULA:
+            mpFormula = rDoc.GetFormulaCell(rPos)->Clone();
+        break;
+        default:
+            meType = CELLTYPE_NONE; // reset to empty.
+    }
+}
+
+void ScUndoCellValue::commit( ScDocument& rDoc, const ScAddress& rPos )
+{
+    switch (meType)
+    {
+        case CELLTYPE_STRING:
+        {
+            ScSetStringParam aParam;
+            aParam.setTextInput();
+            rDoc.SetString(rPos, *mpString, &aParam);
+        }
+        break;
+        case CELLTYPE_EDIT:
+            rDoc.SetEditText(rPos, mpEditText->Clone());
+        break;
+        case CELLTYPE_VALUE:
+            rDoc.SetValue(rPos, mfValue);
+        break;
+        case CELLTYPE_FORMULA:
+            rDoc.SetFormulaCell(rPos, mpFormula->Clone());
+        break;
+        default:
+            rDoc.SetEmptyCell(rPos);
+    }
 }
 
 TYPEINIT1(ScUndoCursorAttr, ScSimpleUndo);
commit 0cb01e5532cd824e56a1e5b3829677acd623936a
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Mar 21 17:11:39 2013 -0400

    ScUndoSetCell::Value to ScUndoCellValue in global scope.
    
    I could use this in other undo classes.
    
    Change-Id: I721ab2b67810af21ddbbb711c268783b73904e48

diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index c1caa2e..d3061e1 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -809,7 +809,7 @@ sal_Bool ScDocFunc::SetNormalString( bool& o_rbNumFmtSet, const ScAddress& rPos,
 
 namespace {
 
-void pushUndoSetCell( ScDocShell& rDocShell, ScDocument* pDoc, const ScAddress& rPos, const ScUndoSetCell::Value& rNewVal )
+void pushUndoSetCell( ScDocShell& rDocShell, ScDocument* pDoc, const ScAddress& rPos, const ScUndoCellValue& rNewVal )
 {
     svl::IUndoManager* pUndoMgr = rDocShell.GetUndoManager();
     switch (pDoc->GetCellType(rPos))
diff --git a/sc/source/ui/inc/undocell.hxx b/sc/source/ui/inc/undocell.hxx
index 76d9032..2f5e370 100644
--- a/sc/source/ui/inc/undocell.hxx
+++ b/sc/source/ui/inc/undocell.hxx
@@ -35,6 +35,25 @@ class ScDetOpList;
 class ScDetOpData;
 class ScRangeName;
 
+struct ScUndoCellValue
+{
+    CellType meType;
+    union {
+        double mfValue;
+        OUString* mpString;
+        EditTextObject* mpEditText;
+        ScFormulaCell* mpFormula;
+    };
+
+    ScUndoCellValue();
+    ScUndoCellValue( double fValue );
+    ScUndoCellValue( const OUString& rString );
+    ScUndoCellValue( const EditTextObject& rEditText );
+    ScUndoCellValue( const ScFormulaCell& rFormula );
+    ScUndoCellValue( const ScUndoCellValue& r );
+    ~ScUndoCellValue();
+};
+
 class ScUndoCursorAttr: public ScSimpleUndo
 {
 public:
@@ -142,28 +161,9 @@ private:
 class ScUndoSetCell : public ScSimpleUndo
 {
 public:
-    struct Value
-    {
-        CellType meType;
-        union {
-            double mfValue;
-            OUString* mpString;
-            EditTextObject* mpEditText;
-            ScFormulaCell* mpFormula;
-        };
-
-        Value();
-        Value( double fValue );
-        Value( const OUString& rString );
-        Value( const EditTextObject& rEditText );
-        Value( const ScFormulaCell& rFormula );
-        Value( const Value& r );
-        ~Value();
-    };
-
     TYPEINFO();
-    ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const Value& rNewVal );
-    ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const Value& rOldVal, const Value& rNewVal );
+    ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScUndoCellValue& rNewVal );
+    ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScUndoCellValue& rOldVal, const ScUndoCellValue& rNewVal );
 
     virtual ~ScUndoSetCell();
 
@@ -174,12 +174,12 @@ public:
     virtual OUString GetComment() const;
 
 private:
-    void SetValue( const Value& rVal );
+    void SetValue( const ScUndoCellValue& rVal );
 
 private:
     ScAddress maPos;
-    Value maOldValue;
-    Value maNewValue;
+    ScUndoCellValue maOldValue;
+    ScUndoCellValue maNewValue;
 };
 
 class ScUndoPageBreak: public ScSimpleUndo
diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx
index d969d14..7715624 100644
--- a/sc/source/ui/undo/undocell.cxx
+++ b/sc/source/ui/undo/undocell.cxx
@@ -45,6 +45,48 @@
 
 using ::boost::shared_ptr;
 
+ScUndoCellValue::ScUndoCellValue() : meType(CELLTYPE_NONE), mfValue(0.0) {}
+ScUndoCellValue::ScUndoCellValue( double fValue ) : meType(CELLTYPE_VALUE), mfValue(fValue) {}
+ScUndoCellValue::ScUndoCellValue( const OUString& rString ) : meType(CELLTYPE_STRING), mpString(new OUString(rString)) {}
+ScUndoCellValue::ScUndoCellValue( const EditTextObject& rEditText ) : meType(CELLTYPE_EDIT), mpEditText(rEditText.Clone()) {}
+ScUndoCellValue::ScUndoCellValue( const ScFormulaCell& rFormula ) : meType(CELLTYPE_FORMULA), mpFormula(rFormula.Clone()) {}
+
+ScUndoCellValue::ScUndoCellValue( const ScUndoCellValue& r ) : meType(r.meType), mfValue(r.mfValue)
+{
+    switch (r.meType)
+    {
+        case CELLTYPE_STRING:
+            mpString = new OUString(*r.mpString);
+        break;
+        case CELLTYPE_EDIT:
+            mpEditText = r.mpEditText->Clone();
+        break;
+        case CELLTYPE_FORMULA:
+            mpFormula = r.mpFormula->Clone();
+        break;
+        default:
+            ;
+    }
+}
+
+ScUndoCellValue::~ScUndoCellValue()
+{
+    switch (meType)
+    {
+        case CELLTYPE_STRING:
+            delete mpString;
+        break;
+        case CELLTYPE_EDIT:
+            delete mpEditText;
+        break;
+        case CELLTYPE_FORMULA:
+            mpFormula->Delete();
+        break;
+        default:
+            ;
+    }
+}
+
 TYPEINIT1(ScUndoCursorAttr, ScSimpleUndo);
 TYPEINIT1(ScUndoEnterData, ScSimpleUndo);
 TYPEINIT1(ScUndoEnterValue, ScSimpleUndo);
@@ -415,52 +457,10 @@ sal_Bool ScUndoEnterValue::CanRepeat(SfxRepeatTarget& /* rTarget */) const
     return false;
 }
 
-ScUndoSetCell::Value::Value() : meType(CELLTYPE_NONE), mfValue(0.0) {}
-ScUndoSetCell::Value::Value( double fValue ) : meType(CELLTYPE_VALUE), mfValue(fValue) {}
-ScUndoSetCell::Value::Value( const OUString& rString ) : meType(CELLTYPE_STRING), mpString(new OUString(rString)) {}
-ScUndoSetCell::Value::Value( const EditTextObject& rEditText ) : meType(CELLTYPE_EDIT), mpEditText(rEditText.Clone()) {}
-ScUndoSetCell::Value::Value( const ScFormulaCell& rFormula ) : meType(CELLTYPE_FORMULA), mpFormula(rFormula.Clone()) {}
-
-ScUndoSetCell::Value::Value( const Value& r ) : meType(r.meType), mfValue(r.mfValue)
-{
-    switch (r.meType)
-    {
-        case CELLTYPE_STRING:
-            mpString = new OUString(*r.mpString);
-        break;
-        case CELLTYPE_EDIT:
-            mpEditText = r.mpEditText->Clone();
-        break;
-        case CELLTYPE_FORMULA:
-            mpFormula = r.mpFormula->Clone();
-        break;
-        default:
-            ;
-    }
-}
-
-ScUndoSetCell::Value::~Value()
-{
-    switch (meType)
-    {
-        case CELLTYPE_STRING:
-            delete mpString;
-        break;
-        case CELLTYPE_EDIT:
-            delete mpEditText;
-        break;
-        case CELLTYPE_FORMULA:
-            mpFormula->Delete();
-        break;
-        default:
-            ;
-    }
-}
-
-ScUndoSetCell::ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const Value& rNewVal ) :
+ScUndoSetCell::ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScUndoCellValue& rNewVal ) :
     ScSimpleUndo(pDocSh), maPos(rPos), maNewValue(rNewVal) {}
 
-ScUndoSetCell::ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const Value& rOldVal, const Value& rNewVal ) :
+ScUndoSetCell::ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScUndoCellValue& rOldVal, const ScUndoCellValue& rNewVal ) :
     ScSimpleUndo(pDocSh), maPos(rPos), maOldValue(rOldVal), maNewValue(rNewVal) {}
 
 ScUndoSetCell::~ScUndoSetCell() {}
@@ -496,7 +496,7 @@ OUString ScUndoSetCell::GetComment() const
     return ScGlobal::GetRscString(STR_UNDO_ENTERDATA); // "Input"
 }
 
-void ScUndoSetCell::SetValue( const Value& rVal )
+void ScUndoSetCell::SetValue( const ScUndoCellValue& rVal )
 {
     ScDocument* pDoc = pDocShell->GetDocument();
 


More information about the Libreoffice-commits mailing list