summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-03-22 11:23:08 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-03-22 21:49:24 -0400
commitbffe8b807ec2ac9e4749360151682591895778fd (patch)
treec3c161448d19f9ff94d921d941ed8fe30abd6a60 /sc
parent6dfdce83578ce44720e4cf1d84c6e4ef50686983 (diff)
Get change tracking to work again with these new ScDocFunc methods.
Change-Id: Icdbf2af7bc552bc8f4914cc8bd036ed45934c461
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/cellvalue.hxx4
-rw-r--r--sc/source/core/data/cellvalue.cxx18
-rw-r--r--sc/source/ui/docshell/docfunc.cxx89
-rw-r--r--sc/source/ui/inc/undocell.hxx2
-rw-r--r--sc/source/ui/undo/undocell.cxx40
5 files changed, 102 insertions, 51 deletions
diff --git a/sc/inc/cellvalue.hxx b/sc/inc/cellvalue.hxx
index 409e17853c3d..ac9627460890 100644
--- a/sc/inc/cellvalue.hxx
+++ b/sc/inc/cellvalue.hxx
@@ -51,6 +51,10 @@ struct ScCellValue
void commit( ScDocument& rDoc, const ScAddress& rPos );
};
+// TODO: temporary workaround. To be removed later.
+class ScBaseCell;
+ScBaseCell* getHackedBaseCell( ScDocument* pDoc, const ScCellValue& rVal );
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/cellvalue.cxx b/sc/source/core/data/cellvalue.cxx
index fe038ced4393..6a51c68a2734 100644
--- a/sc/source/core/data/cellvalue.cxx
+++ b/sc/source/core/data/cellvalue.cxx
@@ -113,4 +113,22 @@ void ScCellValue::commit( ScDocument& rDoc, const ScAddress& rPos )
}
}
+ScBaseCell* getHackedBaseCell( ScDocument* pDoc, const ScCellValue& rVal )
+{
+ switch (rVal.meType)
+ {
+ case CELLTYPE_STRING:
+ return new ScStringCell(*rVal.mpString);
+ case CELLTYPE_EDIT:
+ return new ScEditCell(rVal.mpEditText->Clone(), pDoc);
+ case CELLTYPE_VALUE:
+ return new ScValueCell(rVal.mfValue);
+ case CELLTYPE_FORMULA:
+ return rVal.mpFormula->Clone();
+ default:
+ ;
+ }
+ return NULL;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index 70ca4c353db8..1bc80217f533 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -808,51 +808,6 @@ sal_Bool ScDocFunc::SetNormalString( bool& o_rbNumFmtSet, const ScAddress& rPos,
return sal_True;
}
-namespace {
-
-void pushUndoSetCell( ScDocShell& rDocShell, ScDocument* pDoc, const ScAddress& rPos, const ScCellValue& rNewVal )
-{
- svl::IUndoManager* pUndoMgr = rDocShell.GetUndoManager();
- switch (pDoc->GetCellType(rPos))
- {
- case CELLTYPE_NONE:
- case CELLTYPE_NOTE:
- // Empty cell.
- pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, rNewVal));
- break;
- case CELLTYPE_VALUE:
- {
- double fOldVal = pDoc->GetValue(rPos);
- pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, fOldVal, rNewVal));
- }
- break;
- case CELLTYPE_STRING:
- {
- OUString aOldStr = pDoc->GetString(rPos);
- pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, aOldStr, rNewVal));
- }
- break;
- case CELLTYPE_EDIT:
- {
- const EditTextObject* pOldText = pDoc->GetEditText(rPos);
- if (pOldText)
- pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, *pOldText, rNewVal));
- }
- break;
- case CELLTYPE_FORMULA:
- {
- const ScFormulaCell* pCell = pDoc->GetFormulaCell(rPos);
- if (pCell)
- pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, *pCell, rNewVal));
- }
- break;
- default:
- ;
- }
-}
-
-}
-
bool ScDocFunc::SetValueCell( const ScAddress& rPos, double fVal, bool bInteraction )
{
ScDocShellModificator aModificator( rDocShell );
@@ -861,11 +816,20 @@ bool ScDocFunc::SetValueCell( const ScAddress& rPos, double fVal, bool bInteract
bool bHeight = pDoc->HasAttrib(rPos, HASATTR_NEEDHEIGHT);
+ ScCellValue aOldVal;
if (bUndo)
- pushUndoSetCell(rDocShell, pDoc, rPos, fVal);
+ aOldVal.assign(*pDoc, rPos);
pDoc->SetValue(rPos, fVal);
+ if (bUndo)
+ {
+ svl::IUndoManager* pUndoMgr = rDocShell.GetUndoManager();
+ ScCellValue aNewVal;
+ aNewVal.assign(*pDoc, rPos);
+ pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, aOldVal, aNewVal));
+ }
+
if (bHeight)
AdjustRowHeight(rPos);
@@ -886,13 +850,22 @@ bool ScDocFunc::SetStringCell( const ScAddress& rPos, const OUString& rStr, bool
bool bHeight = pDoc->HasAttrib(rPos, HASATTR_NEEDHEIGHT);
+ ScCellValue aOldVal;
if (bUndo)
- pushUndoSetCell(rDocShell, pDoc, rPos, rStr);
+ aOldVal.assign(*pDoc, rPos);
ScSetStringParam aParam;
aParam.setTextInput();
pDoc->SetString(rPos, rStr, &aParam);
+ if (bUndo)
+ {
+ svl::IUndoManager* pUndoMgr = rDocShell.GetUndoManager();
+ ScCellValue aNewVal;
+ aNewVal.assign(*pDoc, rPos);
+ pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, aOldVal, aNewVal));
+ }
+
if (bHeight)
AdjustRowHeight(rPos);
@@ -913,11 +886,20 @@ bool ScDocFunc::SetEditCell( const ScAddress& rPos, const EditTextObject& rStr,
bool bHeight = pDoc->HasAttrib(rPos, HASATTR_NEEDHEIGHT);
+ ScCellValue aOldVal;
if (bUndo)
- pushUndoSetCell(rDocShell, pDoc, rPos, rStr);
+ aOldVal.assign(*pDoc, rPos);
pDoc->SetEditText(rPos, rStr.Clone());
+ if (bUndo)
+ {
+ svl::IUndoManager* pUndoMgr = rDocShell.GetUndoManager();
+ ScCellValue aNewVal;
+ aNewVal.assign(*pDoc, rPos);
+ pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, aOldVal, aNewVal));
+ }
+
if (bHeight)
AdjustRowHeight(rPos);
@@ -957,11 +939,20 @@ bool ScDocFunc::SetFormulaCell( const ScAddress& rPos, ScFormulaCell* pCell, boo
bool bHeight = pDoc->HasAttrib(rPos, HASATTR_NEEDHEIGHT);
+ ScCellValue aOldVal;
if (bUndo)
- pushUndoSetCell(rDocShell, pDoc, rPos, *xCell);
+ aOldVal.assign(*pDoc, rPos);
pDoc->SetFormulaCell(rPos, xCell.release());
+ if (bUndo)
+ {
+ svl::IUndoManager* pUndoMgr = rDocShell.GetUndoManager();
+ ScCellValue aNewVal;
+ aNewVal.assign(*pDoc, rPos);
+ pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, aOldVal, aNewVal));
+ }
+
if (bHeight)
AdjustRowHeight(rPos);
diff --git a/sc/source/ui/inc/undocell.hxx b/sc/source/ui/inc/undocell.hxx
index e550cc07cc21..24b7800aec14 100644
--- a/sc/source/ui/inc/undocell.hxx
+++ b/sc/source/ui/inc/undocell.hxx
@@ -158,12 +158,14 @@ public:
virtual OUString GetComment() const;
private:
+ void SetChangeTrack();
void SetValue( const ScCellValue& rVal );
private:
ScAddress maPos;
ScCellValue maOldValue;
ScCellValue maNewValue;
+ sal_uLong mnEndChangeAction;
};
class ScUndoPageBreak: public ScSimpleUndo
diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx
index d78ac09eaff1..14296f16053d 100644
--- a/sc/source/ui/undo/undocell.cxx
+++ b/sc/source/ui/undo/undocell.cxx
@@ -419,10 +419,16 @@ sal_Bool ScUndoEnterValue::CanRepeat(SfxRepeatTarget& /* rTarget */) const
}
ScUndoSetCell::ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScCellValue& rNewVal ) :
- ScSimpleUndo(pDocSh), maPos(rPos), maNewValue(rNewVal) {}
+ ScSimpleUndo(pDocSh), maPos(rPos), maNewValue(rNewVal), mnEndChangeAction(0)
+{
+ SetChangeTrack();
+}
ScUndoSetCell::ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScCellValue& rOldVal, const ScCellValue& rNewVal ) :
- ScSimpleUndo(pDocSh), maPos(rPos), maOldValue(rOldVal), maNewValue(rNewVal) {}
+ ScSimpleUndo(pDocSh), maPos(rPos), maOldValue(rOldVal), maNewValue(rNewVal), mnEndChangeAction(0)
+{
+ SetChangeTrack();
+}
ScUndoSetCell::~ScUndoSetCell() {}
@@ -431,6 +437,12 @@ void ScUndoSetCell::Undo()
BeginUndo();
SetValue(maOldValue);
pDocShell->PostPaintCell(maPos);
+
+ ScDocument* pDoc = pDocShell->GetDocument();
+ ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
+ if (pChangeTrack)
+ pChangeTrack->Undo(mnEndChangeAction, mnEndChangeAction);
+
EndUndo();
}
@@ -439,6 +451,7 @@ void ScUndoSetCell::Redo()
BeginRedo();
SetValue(maNewValue);
pDocShell->PostPaintCell(maPos);
+ SetChangeTrack();
EndRedo();
}
@@ -457,6 +470,29 @@ OUString ScUndoSetCell::GetComment() const
return ScGlobal::GetRscString(STR_UNDO_ENTERDATA); // "Input"
}
+void ScUndoSetCell::SetChangeTrack()
+{
+ ScDocument* pDoc = pDocShell->GetDocument();
+ ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
+ if (pChangeTrack)
+ {
+ mnEndChangeAction = pChangeTrack->GetActionMax() + 1;
+
+ {
+ // TODO: Come back to this later.
+ ScBaseCell* pOldCell = getHackedBaseCell(pDoc, maOldValue);
+ pChangeTrack->AppendContent(maPos, pOldCell);
+ if (pOldCell)
+ pOldCell->Delete();
+ }
+
+ if (mnEndChangeAction > pChangeTrack->GetActionMax())
+ mnEndChangeAction = 0; // Nothing is appended
+ }
+ else
+ mnEndChangeAction = 0;
+}
+
void ScUndoSetCell::SetValue( const ScCellValue& rVal )
{
ScDocument* pDoc = pDocShell->GetDocument();