summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@collabora.co.uk>2014-04-23 05:23:50 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2014-05-01 20:36:47 +0200
commitc5c5b68fbf8165ba0614fd1f8fd7f8a642e408a8 (patch)
tree0ae883ae2cf6d7104678642eea9d6e11a5b8b2f5 /sc
parent1bad7ad98a41725907b6cb2a0a8486e0891ac306 (diff)
add undo action for conditional formatting, cp#1000050, fdo#77381
Conflicts: sc/inc/globstr.hrc sc/source/ui/src/globstr.src Change-Id: I11db1e5824077135c4352ae43cc0e8d139244268
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/globstr.hrc4
-rw-r--r--sc/source/ui/docshell/docfunc.cxx40
-rw-r--r--sc/source/ui/inc/undoblk.hxx22
-rw-r--r--sc/source/ui/src/globstr.src4
-rw-r--r--sc/source/ui/undo/undoblk.cxx52
5 files changed, 119 insertions, 3 deletions
diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc
index f02ef5122b00..4f5b351c4f69 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -694,7 +694,9 @@
#define STR_CTRLCLICKHYPERLINK 526
#define STR_CLICKHYPERLINK 527
-#define SC_GLOBSTR_STR_COUNT 528 /**< the count of permanently resident strings */
+#define STR_UNDO_CONDFORMAT 528
+
+#define SC_GLOBSTR_STR_COUNT 529 /**< the count of permanently resident strings */
#endif
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index bcb45b661637..2ce4ab864dc4 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -5329,6 +5329,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)
{
@@ -5345,9 +5370,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);
@@ -5355,6 +5380,17 @@ void ScDocFunc::ReplaceConditionalFormat( sal_uLong nOldFormat, ScConditionalFor
pDoc->SetStreamValid(nTab, false);
}
+ if(bUndo)
+ {
+ ScDocument* pRedoDoc = new ScDocument(SCDOCMODE_UNDO);
+ pRedoDoc->InitUndo( pDoc, nTab, nTab );
+ 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 758e5bb91357..36bf05813b80 100644
--- a/sc/source/ui/inc/undoblk.hxx
+++ b/sc/source/ui/inc/undoblk.hxx
@@ -637,6 +637,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/src/globstr.src b/sc/source/ui/src/globstr.src
index ee46a95bb2cb..839ecdb545ba 100644
--- a/sc/source/ui/src/globstr.src
+++ b/sc/source/ui/src/globstr.src
@@ -2081,6 +2081,10 @@ Resource RID_GLOBSTR
{
Text [ en-US ] = "click to open hyperlink:";
};
+ String STR_UNDO_CONDFORMAT
+ {
+ Text [ en-US ] = "Conditional Format";
+ };
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index cb4f25ab9fcb..e0697ba999d8 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -60,6 +60,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);
@@ -1433,6 +1434,57 @@ 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 ScGlobal::GetRscString( STR_UNDO_CONDFORMAT );
+}
+
+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,