diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-10-10 19:59:57 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-10-10 20:36:29 -0400 |
commit | 7168096fdf35ee8b2afd330e3d9b3aab09772807 (patch) | |
tree | 8c23a0e089fea7b138a86201fa4f9f9fd6abe4d2 /sc | |
parent | 06c1844485f1d9fc4f3eb156ec7b871eebea8402 (diff) |
Add DeleteCell to ScDocFunc, which is a variant of DeleteContents ...
for a single cell case. This is equivalent of ScViewFunc::DeleteConents
with bSimple = true.
Change-Id: I5eccce21843f4cb21b29f96b0360617a180aebee
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/docshell/docfunc.cxx | 72 | ||||
-rw-r--r-- | sc/source/ui/inc/docfunc.hxx | 8 |
2 files changed, 75 insertions, 5 deletions
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 03a3a9dabd21..b3085442ce17 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -559,8 +559,8 @@ void ScDocFunc::DetectiveCollectAllSuccs(const ScRangeList& rSrcRanges, vector<S lcl_collectAllPredOrSuccRanges(rSrcRanges, rRefTokens, rDocShell, false); } -bool ScDocFunc::DeleteContents( const ScMarkData& rMark, InsertDeleteFlags nFlags, - bool bRecord, bool bApi ) +bool ScDocFunc::DeleteContents( + const ScMarkData& rMark, InsertDeleteFlags nFlags, bool bRecord, bool bApi ) { ScDocShellModificator aModificator( rDocShell ); @@ -652,6 +652,74 @@ bool ScDocFunc::DeleteContents( const ScMarkData& rMark, InsertDeleteFlags nFlag return true; } +bool ScDocFunc::DeleteCell( + const ScAddress& rPos, const ScMarkData& rMark, InsertDeleteFlags nFlags, bool bRecord, bool bApi ) +{ + ScDocShellModificator aModificator(rDocShell); + + ScDocument& rDoc = rDocShell.GetDocument(); + + if (bRecord && !rDoc.IsUndoEnabled()) + bRecord = false; + + ScEditableTester aTester(&rDoc, rPos.Col(), rPos.Row(), rPos.Col(), rPos.Row(), rMark); + if (!aTester.IsEditable()) + { + if (!bApi) + rDocShell.ErrorMessage(aTester.GetMessageId()); + return false; + } + + // no objects on protected tabs + bool bObjects = (nFlags & IDF_OBJECTS) && !sc::DocFuncUtil::hasProtectedTab(rDoc, rMark); + + sal_uInt16 nExtFlags = 0; // extra flags are needed only if attributes are deleted + if (nFlags & IDF_ATTRIB) + rDocShell.UpdatePaintExt(nExtFlags, rPos); + + // order op opeeration: + // 1) BeginDrawUndo + // 2) delete objects (DrawUndo is filled) + // 3) copy contents for undo + // 4) delete contents + // 5) add undo-action + + bool bDrawUndo = bObjects || (nFlags & IDF_NOTE); // needed for shown notes + if (bDrawUndo && bRecord) + rDoc.BeginDrawUndo(); + + if (bObjects) + rDoc.DeleteObjectsInArea(rPos.Col(), rPos.Row(), rPos.Col(), rPos.Row(), rMark); + + // To keep track of all non-empty cells within the deleted area. + boost::shared_ptr<ScSimpleUndo::DataSpansType> pDataSpans; + + ScDocument* pUndoDoc = NULL; + if (bRecord) + { + pUndoDoc = sc::DocFuncUtil::createDeleteContentsUndoDoc(rDoc, rMark, rPos, nFlags, false); + pDataSpans.reset(sc::DocFuncUtil::getNonEmptyCellSpans(rDoc, rMark, rPos)); + } + + rDoc.DeleteArea(rPos.Col(), rPos.Row(), rPos.Col(), rPos.Row(), rMark, nFlags); + + if (bRecord) + { + sc::DocFuncUtil::addDeleteContentsUndo( + rDocShell.GetUndoManager(), &rDocShell, rMark, rPos, pUndoDoc, + nFlags, pDataSpans, false, bDrawUndo); + } + + if (!AdjustRowHeight(rPos)) + rDocShell.PostPaint( + rPos.Col(), rPos.Row(), rPos.Tab(), rPos.Col(), rPos.Row(), rPos.Tab(), + PAINT_GRID, nExtFlags); + + aModificator.SetDocumentModified(); + + return true; +} + bool ScDocFunc::TransliterateText( const ScMarkData& rMark, sal_Int32 nType, bool bRecord, bool bApi ) { diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx index ebd7ac371aeb..5cd2513a347b 100644 --- a/sc/source/ui/inc/docfunc.hxx +++ b/sc/source/ui/inc/docfunc.hxx @@ -85,9 +85,11 @@ public: void DetectiveCollectAllPreds(const ScRangeList& rSrcRanges, ::std::vector<ScTokenRef>& rRefTokens); void DetectiveCollectAllSuccs(const ScRangeList& rSrcRanges, ::std::vector<ScTokenRef>& rRefTokens); - SC_DLLPUBLIC bool - DeleteContents( const ScMarkData& rMark, InsertDeleteFlags nFlags, - bool bRecord, bool bApi ); + SC_DLLPUBLIC bool DeleteContents( + const ScMarkData& rMark, InsertDeleteFlags nFlags, bool bRecord, bool bApi ); + + bool DeleteCell( + const ScAddress& rPos, const ScMarkData& rMark, InsertDeleteFlags nFlags, bool bRecord, bool bApi ); bool TransliterateText( const ScMarkData& rMark, sal_Int32 nType, bool bRecord, bool bApi ); |