summaryrefslogtreecommitdiff
path: root/sc/source/core/data/column4.cxx
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-02-18 16:45:02 -0500
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-02-18 16:51:18 -0500
commitcdc8ebf9646e773351c91039a62f2414c7b02105 (patch)
treeed0cedf4dc04dd347293d4e40a04bb997c218fdb /sc/source/core/data/column4.cxx
parent3c7b65c171eeade3272cc766b813b99a35a6ef7d (diff)
fdo#74573: Delete ranges that are non-empty before pasting from clipboard.
The conditional formatting part is still not working. But other bits appear to be working now. Change-Id: Ia8a2cbe57cd2fa9ca9ad46635a91a1d8b99b0e7d
Diffstat (limited to 'sc/source/core/data/column4.cxx')
-rw-r--r--sc/source/core/data/column4.cxx98
1 files changed, 98 insertions, 0 deletions
diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx
index 5848183442a7..fa188180f272 100644
--- a/sc/source/core/data/column4.cxx
+++ b/sc/source/core/data/column4.cxx
@@ -17,6 +17,11 @@
#include <columnspanset.hxx>
#include <listenercontext.hxx>
#include <mtvcellfunc.hxx>
+#include <clipcontext.hxx>
+#include <attrib.hxx>
+#include <patattr.hxx>
+#include <docpool.hxx>
+#include <conditio.hxx>
#include <svl/sharedstringpool.hxx>
@@ -28,6 +33,99 @@ bool ScColumn::IsMerged( SCROW nRow ) const
return pAttrArray->IsMerged(nRow);
}
+void ScColumn::DeleteBeforeCopyFromClip( sc::CopyFromClipContext& rCxt, const ScColumn& rClipCol )
+{
+ sc::CopyFromClipContext::Range aRange = rCxt.getDestRange();
+ if (!ValidRow(aRange.mnRow1) || !ValidRow(aRange.mnRow2))
+ return;
+
+ ScRange aClipRange = rCxt.getClipDoc()->GetClipParam().getWholeRange();
+ SCROW nClipRow1 = aClipRange.aStart.Row();
+ SCROW nClipRow2 = aClipRange.aEnd.Row();
+ SCROW nClipRowLen = nClipRow2 - nClipRow1 + 1;
+
+ // Check for non-empty cell ranges in the clip column.
+ sc::SingleColumnSpanSet aSpanSet;
+ aSpanSet.scan(rClipCol, nClipRow1, nClipRow2);
+ sc::SingleColumnSpanSet::SpansType aSpans;
+ aSpanSet.getSpans(aSpans);
+
+ // Translate the clip column spans into the destination column, and repeat as needed.
+ std::vector<sc::RowSpan> aDestSpans;
+ SCROW nDestOffset = aRange.mnRow1 - nClipRow1;
+ bool bContinue = true;
+ while (bContinue)
+ {
+ sc::SingleColumnSpanSet::SpansType::const_iterator it = aSpans.begin(), itEnd = aSpans.end();
+ for (; it != itEnd && bContinue; ++it)
+ {
+ const sc::RowSpan& r = *it;
+ SCROW nDestRow1 = r.mnRow1 + nDestOffset;
+ SCROW nDestRow2 = r.mnRow2 + nDestOffset;
+
+ if (nDestRow1 > aRange.mnRow2)
+ {
+ // We're done.
+ bContinue = false;
+ continue;
+ }
+
+ if (nDestRow2 > aRange.mnRow2)
+ {
+ // Truncate this range, and set it as the last span.
+ nDestRow2 = aRange.mnRow2;
+ bContinue = false;
+ }
+
+ aDestSpans.push_back(sc::RowSpan(nDestRow1, nDestRow2));
+ }
+
+ nDestOffset += nClipRowLen;
+ }
+
+ std::vector<SCROW> aDeletedRows;
+ sal_uInt16 nDelFlag = rCxt.getDeleteFlag();
+ sc::ColumnBlockPosition aBlockPos;
+ InitBlockPosition(aBlockPos);
+
+ std::vector<sc::RowSpan>::const_iterator it = aDestSpans.begin(), itEnd = aDestSpans.end();
+ for (; it != itEnd; ++it)
+ {
+ SCROW nRow1 = it->mnRow1;
+ SCROW nRow2 = it->mnRow2;
+
+ if (nDelFlag & IDF_CONTENTS)
+ DeleteCells(aBlockPos, nRow1, nRow2, nDelFlag, aDeletedRows);
+
+ if (nDelFlag & IDF_NOTE)
+ DeleteCellNotes(aBlockPos, nRow1, nRow2);
+
+ if (nDelFlag & IDF_EDITATTR)
+ RemoveEditAttribs(nRow1, nRow2);
+
+ // Delete attributes just now
+ if (nDelFlag & IDF_ATTRIB)
+ {
+ pAttrArray->DeleteArea(nRow1, nRow2);
+
+ if (rCxt.isTableProtected())
+ {
+ ScPatternAttr aPattern(pDocument->GetPool());
+ aPattern.GetItemSet().Put(ScProtectionAttr(false));
+ ApplyPatternArea(nRow1, nRow2, aPattern);
+ }
+
+ ScConditionalFormatList* pCondList = rCxt.getCondFormatList();
+ if (pCondList)
+ pCondList->DeleteArea(nCol, nRow1, nCol, nRow2);
+ }
+ else if ((nDelFlag & IDF_HARDATTR) == IDF_HARDATTR)
+ pAttrArray->DeleteHardAttr(nRow1, nRow2);
+ }
+
+ BroadcastCells(aDeletedRows, SC_HINT_DATACHANGED);
+}
+
void ScColumn::CopyOneCellFromClip( sc::CopyFromClipContext& rCxt, SCROW nRow1, SCROW nRow2 )
{
assert(nRow1 <= nRow2);