summaryrefslogtreecommitdiff
path: root/sc/source/ui/docshell
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-10-08 22:33:47 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-10-08 23:24:58 -0400
commit7adef94b82f5c71da483f238d05df7800b8da38b (patch)
tree193c4a6aadf8b1d8e021bfd5580789ae0e9bd3ec /sc/source/ui/docshell
parented0e3fdcc13e0925c16aa81f6aa461892f15d81a (diff)
Share undo doc creation code.
Change-Id: I55f27b61637ba0284479c63c2fa48b0bd8938c0f
Diffstat (limited to 'sc/source/ui/docshell')
-rw-r--r--sc/source/ui/docshell/docfunc.cxx38
-rw-r--r--sc/source/ui/docshell/docfuncutil.cxx61
2 files changed, 63 insertions, 36 deletions
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index fedbd20fbc85..6de4d7a86e2d 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -628,42 +628,8 @@ bool ScDocFunc::DeleteContents( const ScMarkData& rMark, InsertDeleteFlags nFlag
if ( bRecord )
{
- pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
- pUndoDoc->InitUndo( &rDoc, aMarkRange.aStart.Tab(), aMarkRange.aEnd.Tab() );
-
- // bei "Format/Standard" alle Attribute kopieren, weil CopyToDocument
- // nur mit IDF_HARDATTR zu langsam ist:
- InsertDeleteFlags nUndoDocFlags = nFlags;
- if (nFlags & IDF_ATTRIB)
- nUndoDocFlags |= IDF_ATTRIB;
- if (nFlags & IDF_EDITATTR) // Edit-Engine-Attribute
- nUndoDocFlags |= IDF_STRING; // -> Zellen werden geaendert
- if (nFlags & IDF_NOTE)
- nUndoDocFlags |= IDF_CONTENTS; // copy all cells with their notes
- // note captions are handled in drawing undo
- nUndoDocFlags |= IDF_NOCAPTIONS;
- rDoc.CopyToDocument( aExtendedRange, nUndoDocFlags, bMulti, pUndoDoc, &aMultiMark );
-
- pDataSpans.reset(new ScSimpleUndo::DataSpansType);
-
- ScMarkData::iterator it = aMultiMark.begin(), itEnd = aMultiMark.end();
- for (; it != itEnd; ++it)
- {
- SCTAB nTab = *it;
-
- SCCOL nCol1 = aMarkRange.aStart.Col(), nCol2 = aMarkRange.aEnd.Col();
- SCROW nRow1 = aMarkRange.aStart.Row(), nRow2 = aMarkRange.aEnd.Row();
-
- std::pair<ScSimpleUndo::DataSpansType::iterator,bool> r =
- pDataSpans->insert(nTab, new sc::ColumnSpanSet(false));
-
- if (r.second)
- {
- ScSimpleUndo::DataSpansType::iterator it2 = r.first;
- sc::ColumnSpanSet* pSet = it2->second;
- pSet->scan(rDoc, nTab, nCol1, nRow1, nCol2, nRow2, true);
- }
- }
+ pUndoDoc = sc::DocFuncUtil::createDeleteContentsUndoDoc(rDoc, aMultiMark, aMarkRange, nFlags, bMulti);
+ pDataSpans.reset(sc::DocFuncUtil::getNonEmptyCellSpans(rDoc, aMultiMark, aMarkRange));
}
rDoc.DeleteSelection( nFlags, aMultiMark );
diff --git a/sc/source/ui/docshell/docfuncutil.cxx b/sc/source/ui/docshell/docfuncutil.cxx
index 570ed521f8c5..35f3fb2b35af 100644
--- a/sc/source/ui/docshell/docfuncutil.cxx
+++ b/sc/source/ui/docshell/docfuncutil.cxx
@@ -20,6 +20,10 @@
#include <docfuncutil.hxx>
#include <document.hxx>
#include <markdata.hxx>
+#include <undobase.hxx>
+#include <global.hxx>
+
+#include <memory>
namespace sc {
@@ -34,6 +38,63 @@ bool DocFuncUtil::hasProtectedTab( const ScDocument& rDoc, const ScMarkData& rMa
return false;
}
+ScDocument* DocFuncUtil::createDeleteContentsUndoDoc(
+ ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange,
+ InsertDeleteFlags nFlags, bool bOnlyMarked )
+{
+ std::unique_ptr<ScDocument> pUndoDoc(new ScDocument(SCDOCMODE_UNDO));
+ SCTAB nTab = rRange.aStart.Tab();
+ pUndoDoc->InitUndo(&rDoc, nTab, nTab);
+ SCTAB nTabCount = rDoc.GetTableCount();
+ ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
+ for (; itr != itrEnd; ++itr)
+ if (*itr != nTab)
+ pUndoDoc->AddUndoTab( *itr, *itr );
+ ScRange aCopyRange = rRange;
+ aCopyRange.aStart.SetTab(0);
+ aCopyRange.aEnd.SetTab(nTabCount-1);
+
+ // in case of "Format/Standard" copy all attributes, because CopyToDocument
+ // with IDF_HARDATTR only is too time-consuming:
+ InsertDeleteFlags nUndoDocFlags = nFlags;
+ if (nFlags & IDF_ATTRIB)
+ nUndoDocFlags |= IDF_ATTRIB;
+ if (nFlags & IDF_EDITATTR) // Edit-Engine-Attribute
+ nUndoDocFlags |= IDF_STRING; // -> cells will be changed
+ if (nFlags & IDF_NOTE)
+ nUndoDocFlags |= IDF_CONTENTS; // copy all cells with their notes
+ // do not copy note captions to undo document
+ nUndoDocFlags |= IDF_NOCAPTIONS;
+ rDoc.CopyToDocument(aCopyRange, nUndoDocFlags, bOnlyMarked, pUndoDoc.get(), &rMark);
+
+ return pUndoDoc.release();
+}
+
+ScSimpleUndo::DataSpansType* DocFuncUtil::getNonEmptyCellSpans(
+ const ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange )
+{
+ std::unique_ptr<ScSimpleUndo::DataSpansType> pDataSpans(new ScSimpleUndo::DataSpansType);
+ ScMarkData::const_iterator it = rMark.begin(), itEnd = rMark.end();
+ for (; it != itEnd; ++it)
+ {
+ SCTAB nTab = *it;
+
+ SCCOL nCol1 = rRange.aStart.Col(), nCol2 = rRange.aEnd.Col();
+ SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row();
+
+ std::pair<ScSimpleUndo::DataSpansType::iterator,bool> r =
+ pDataSpans->insert(nTab, new sc::ColumnSpanSet(false));
+
+ if (r.second)
+ {
+ sc::ColumnSpanSet* pSet = r.first->second;
+ pSet->scan(rDoc, nTab, nCol1, nRow1, nCol2, nRow2, true);
+ }
+ }
+
+ return pDataSpans.release();
+}
+
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */