summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@collabora.co.uk>2014-04-23 05:23:50 +0200
committerMarkus Mohrhard <markus.mohrhard@collabora.co.uk>2014-04-23 05:23:50 +0200
commit340b1fe5220076aee2b95e0d125a4cf7f3b8144d (patch)
tree8094b3dc47ca4139cd5cc8ede5153122fe097c9a
parent86c065a143c8c35f744fa3c1160f3550446ffcf3 (diff)
WIP: undo conditional format private/moggi/orcus-improvements
Change-Id: I11db1e5824077135c4352ae43cc0e8d139244268
-rw-r--r--sc/source/ui/docshell/docfunc.cxx39
-rw-r--r--sc/source/ui/inc/undoblk.hxx22
-rw-r--r--sc/source/ui/undo/undoblk.cxx53
3 files changed, 112 insertions, 2 deletions
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index 5950a9ddd111..d6ef07ea28ba 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -5302,6 +5302,31 @@ void ScDocFunc::ReplaceConditionalFormat( sal_uLong nOldFormat, ScConditionalFor
if(pDoc->IsTabProtected(nTab))
return;
+ bool bUndo = pDoc->IsUndoEnabled();
+ ScDocument* pUndoDoc = NULL;
+ ScRange aCombinedRange = rRanges.Combine();
+ ScRange aCompleteRange;
+ if(bUndo)
+ {
+ pUndoDoc = new ScDocument(SCDOCMODE_UNDO);
+ pUndoDoc->InitUndo( pDoc, nTab, nTab );
+
+ if(pFormat)
+ {
+ aCompleteRange = aCombinedRange;
+ }
+ if(nOldFormat)
+ {
+ ScConditionalFormat* pOldFormat = pDoc->GetCondFormList(nTab)->GetFormat(nOldFormat);
+ if(pOldFormat)
+ aCompleteRange.ExtendTo(pOldFormat->GetRange().Combine());
+ }
+
+ pDoc->CopyToDocument( aCompleteRange.aStart.Col(),aCompleteRange.aStart.Row(),nTab,
+ aCompleteRange.aEnd.Col(),aCompleteRange.aEnd.Row(),nTab,
+ IDF_ALL, false, pUndoDoc );
+ }
+
boost::scoped_ptr<ScRange> pRepaintRange;
if(nOldFormat)
{
@@ -5318,9 +5343,9 @@ void ScDocFunc::ReplaceConditionalFormat( sal_uLong nOldFormat, ScConditionalFor
if(pFormat)
{
if(pRepaintRange)
- pRepaintRange->ExtendTo(rRanges.Combine());
+ pRepaintRange->ExtendTo(aCombinedRange);
else
- pRepaintRange.reset(new ScRange(rRanges.Combine()));
+ pRepaintRange.reset(new ScRange(aCombinedRange));
sal_uLong nIndex = pDoc->AddCondFormat(pFormat, nTab);
@@ -5328,6 +5353,16 @@ void ScDocFunc::ReplaceConditionalFormat( sal_uLong nOldFormat, ScConditionalFor
pDoc->SetStreamValid(nTab, false);
}
+ if(bUndo)
+ {
+ ScDocument* pRedoDoc = new ScDocument(SCDOCMODE_UNDO);
+ pDoc->CopyToDocument( aCompleteRange.aStart.Col(),aCompleteRange.aStart.Row(),nTab,
+ aCompleteRange.aEnd.Col(),aCompleteRange.aEnd.Row(),nTab,
+ IDF_ALL, false, pRedoDoc );
+ rDocShell.GetUndoManager()->AddUndoAction(
+ new ScUndoConditionalFormat(&rDocShell, pUndoDoc, pRedoDoc, aCompleteRange));
+ }
+
if(pRepaintRange)
rDocShell.PostPaint(*pRepaintRange, PAINT_GRID);
diff --git a/sc/source/ui/inc/undoblk.hxx b/sc/source/ui/inc/undoblk.hxx
index d619e5b03c7c..40af6cc415b4 100644
--- a/sc/source/ui/inc/undoblk.hxx
+++ b/sc/source/ui/inc/undoblk.hxx
@@ -636,6 +636,28 @@ private:
void DoChange( ScDocument* pSrcDoc ) const;
};
+class ScUndoConditionalFormat : public ScSimpleUndo
+{
+public:
+ TYPEINFO_OVERRIDE();
+ ScUndoConditionalFormat( ScDocShell* pNewDocShell,
+ ScDocument* pUndoDoc, ScDocument* pRedoDoc, const ScRange& rRange);
+ virtual ~ScUndoConditionalFormat();
+
+ virtual void Undo() SAL_OVERRIDE;
+ virtual void Redo() SAL_OVERRIDE;
+ virtual void Repeat(SfxRepeatTarget& rTarget) SAL_OVERRIDE;
+ virtual bool CanRepeat(SfxRepeatTarget& rTarget) const SAL_OVERRIDE;
+
+ virtual OUString GetComment() const SAL_OVERRIDE;
+
+private:
+ void DoChange(ScDocument* pDoc);
+ boost::scoped_ptr<ScDocument> mpUndoDoc;
+ boost::scoped_ptr<ScDocument> mpRedoDoc;
+ ScRange maRange;
+};
+
class ScUndoUseScenario: public ScSimpleUndo
{
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index 8496fc236b2f..82ac93ad08a7 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -61,6 +61,7 @@ TYPEINIT1(ScUndoCut, ScBlockUndo);
TYPEINIT1(ScUndoPaste, SfxUndoAction);
TYPEINIT1(ScUndoDragDrop, SfxUndoAction);
TYPEINIT1(ScUndoListNames, SfxUndoAction);
+TYPEINIT1(ScUndoConditionalFormat, SfxUndoAction);
TYPEINIT1(ScUndoUseScenario, SfxUndoAction);
TYPEINIT1(ScUndoSelectionStyle, SfxUndoAction);
TYPEINIT1(ScUndoEnterMatrix, ScBlockUndo);
@@ -1430,6 +1431,58 @@ bool ScUndoListNames::CanRepeat(SfxRepeatTarget& rTarget) const
return rTarget.ISA(ScTabViewTarget);
}
+ScUndoConditionalFormat::ScUndoConditionalFormat(ScDocShell* pNewDocShell,
+ ScDocument* pUndoDoc, ScDocument* pRedoDoc, const ScRange& rRange):
+ ScSimpleUndo( pNewDocShell ),
+ mpUndoDoc(pUndoDoc),
+ mpRedoDoc(pRedoDoc),
+ maRange(rRange)
+{
+}
+
+ScUndoConditionalFormat::~ScUndoConditionalFormat()
+{
+}
+
+OUString ScUndoConditionalFormat::GetComment() const
+{
+ return OUString("Undo conditional format change");
+}
+
+void ScUndoConditionalFormat::Undo()
+{
+ DoChange(mpUndoDoc.get());
+}
+
+void ScUndoConditionalFormat::Redo()
+{
+ DoChange(mpRedoDoc.get());
+}
+
+void ScUndoConditionalFormat::DoChange(ScDocument* pSrcDoc)
+{
+ ScDocument* pDoc = pDocShell->GetDocument();
+
+ pDoc->DeleteAreaTab( maRange, IDF_ALL );
+ pSrcDoc->CopyToDocument( maRange, IDF_ALL, false, pDoc );
+ pDocShell->PostPaint( maRange, PAINT_GRID );
+ pDocShell->PostDataChanged();
+ ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
+ if (pViewShell)
+ pViewShell->CellContentChanged();
+
+}
+
+void ScUndoConditionalFormat::Repeat(SfxRepeatTarget& )
+{
+}
+
+bool ScUndoConditionalFormat::CanRepeat(SfxRepeatTarget& ) const
+{
+ return false;
+}
+
+
ScUndoUseScenario::ScUndoUseScenario( ScDocShell* pNewDocShell,
const ScMarkData& rMark,
/*C*/ const ScArea& rDestArea,