Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <docfuncutil.hxx>
21 : #include <document.hxx>
22 : #include <markdata.hxx>
23 : #include <undobase.hxx>
24 : #include <global.hxx>
25 : #include <undoblk.hxx>
26 :
27 : #include <memory>
28 :
29 : namespace sc {
30 :
31 2 : bool DocFuncUtil::hasProtectedTab( const ScDocument& rDoc, const ScMarkData& rMark )
32 : {
33 2 : SCTAB nTabCount = rDoc.GetTableCount();
34 2 : ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
35 4 : for (; itr != itrEnd && *itr < nTabCount; ++itr)
36 2 : if (rDoc.IsTabProtected(*itr))
37 0 : return true;
38 :
39 2 : return false;
40 : }
41 :
42 77 : ScDocument* DocFuncUtil::createDeleteContentsUndoDoc(
43 : ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange,
44 : InsertDeleteFlags nFlags, bool bOnlyMarked )
45 : {
46 77 : std::unique_ptr<ScDocument> pUndoDoc(new ScDocument(SCDOCMODE_UNDO));
47 77 : SCTAB nTab = rRange.aStart.Tab();
48 77 : pUndoDoc->InitUndo(&rDoc, nTab, nTab);
49 77 : SCTAB nTabCount = rDoc.GetTableCount();
50 77 : ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
51 154 : for (; itr != itrEnd; ++itr)
52 77 : if (*itr != nTab)
53 0 : pUndoDoc->AddUndoTab( *itr, *itr );
54 77 : ScRange aCopyRange = rRange;
55 77 : aCopyRange.aStart.SetTab(0);
56 77 : aCopyRange.aEnd.SetTab(nTabCount-1);
57 :
58 : // in case of "Format/Standard" copy all attributes, because CopyToDocument
59 : // with IDF_HARDATTR only is too time-consuming:
60 77 : InsertDeleteFlags nUndoDocFlags = nFlags;
61 77 : if (nFlags & IDF_ATTRIB)
62 58 : nUndoDocFlags |= IDF_ATTRIB;
63 77 : if (nFlags & IDF_EDITATTR) // Edit-Engine-Attribute
64 0 : nUndoDocFlags |= IDF_STRING; // -> cells will be changed
65 77 : if (nFlags & IDF_NOTE)
66 5 : nUndoDocFlags |= IDF_CONTENTS; // copy all cells with their notes
67 : // do not copy note captions to undo document
68 77 : nUndoDocFlags |= IDF_NOCAPTIONS;
69 77 : rDoc.CopyToDocument(aCopyRange, nUndoDocFlags, bOnlyMarked, pUndoDoc.get(), &rMark);
70 :
71 77 : return pUndoDoc.release();
72 : }
73 :
74 77 : void DocFuncUtil::addDeleteContentsUndo(
75 : svl::IUndoManager* pUndoMgr, ScDocShell* pDocSh, const ScMarkData& rMark,
76 : const ScRange& rRange, ScDocument* pUndoDoc, InsertDeleteFlags nFlags,
77 : const boost::shared_ptr<ScSimpleUndo::DataSpansType>& pSpans,
78 : bool bMulti, bool bDrawUndo )
79 : {
80 : std::unique_ptr<ScUndoDeleteContents> pUndo(
81 : new ScUndoDeleteContents(
82 77 : pDocSh, rMark, rRange, pUndoDoc, bMulti, nFlags, bDrawUndo));
83 77 : pUndo->SetDataSpans(pSpans);
84 :
85 77 : pUndoMgr->AddUndoAction(pUndo.release());
86 77 : }
87 :
88 77 : ScSimpleUndo::DataSpansType* DocFuncUtil::getNonEmptyCellSpans(
89 : const ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange )
90 : {
91 77 : std::unique_ptr<ScSimpleUndo::DataSpansType> pDataSpans(new ScSimpleUndo::DataSpansType);
92 77 : ScMarkData::const_iterator it = rMark.begin(), itEnd = rMark.end();
93 154 : for (; it != itEnd; ++it)
94 : {
95 77 : SCTAB nTab = *it;
96 :
97 77 : SCCOL nCol1 = rRange.aStart.Col(), nCol2 = rRange.aEnd.Col();
98 77 : SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row();
99 :
100 : std::pair<ScSimpleUndo::DataSpansType::iterator,bool> r =
101 77 : pDataSpans->insert(nTab, new sc::ColumnSpanSet(false));
102 :
103 77 : if (r.second)
104 : {
105 77 : sc::ColumnSpanSet* pSet = r.first->second;
106 77 : pSet->scan(rDoc, nTab, nCol1, nRow1, nCol2, nRow2, true);
107 : }
108 : }
109 :
110 77 : return pDataSpans.release();
111 : }
112 :
113 156 : }
114 :
115 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|