sc/inc/cellvalue.hxx | 4 + sc/source/core/data/cellvalue.cxx | 18 +++++++ sc/source/ui/docshell/docfunc.cxx | 89 +++++++++++++++++--------------------- sc/source/ui/inc/undocell.hxx | 2 sc/source/ui/undo/undocell.cxx | 40 ++++++++++++++++- 5 files changed, 102 insertions(+), 51 deletions(-)
New commits: commit 3e885b5972999d69c14a46bf2507471376760d09 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Fri Mar 22 11:23:08 2013 -0400 Get change tracking to work again with these new ScDocFunc methods. Change-Id: Icdbf2af7bc552bc8f4914cc8bd036ed45934c461 diff --git a/sc/inc/cellvalue.hxx b/sc/inc/cellvalue.hxx index 409e178..ac96274 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 fe038ce..6a51c68 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 70ca4c3..1bc8021 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 e550cc0..24b7800 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 d78ac09..14296f1 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(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits