/src/libreoffice/sc/source/ui/docshell/docfuncutil.cxx
Line | Count | Source |
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 <undobase.hxx> |
23 | | #include <global.hxx> |
24 | | #include <undoblk.hxx> |
25 | | #include <columnspanset.hxx> |
26 | | |
27 | | #include <memory> |
28 | | #include <utility> |
29 | | |
30 | | namespace sc { |
31 | | |
32 | | bool DocFuncUtil::hasProtectedTab( const ScDocument& rDoc, const ScMarkData& rMark ) |
33 | 0 | { |
34 | 0 | SCTAB nTabCount = rDoc.GetTableCount(); |
35 | 0 | for (const auto& rTab : rMark) |
36 | 0 | { |
37 | 0 | if (rTab >= nTabCount) |
38 | 0 | break; |
39 | | |
40 | 0 | if (rDoc.IsTabProtected(rTab)) |
41 | 0 | return true; |
42 | 0 | } |
43 | | |
44 | 0 | return false; |
45 | 0 | } |
46 | | |
47 | | ScDocumentUniquePtr DocFuncUtil::createDeleteContentsUndoDoc( |
48 | | ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange, |
49 | | InsertDeleteFlags nFlags, bool bOnlyMarked ) |
50 | 0 | { |
51 | 0 | ScDocumentUniquePtr pUndoDoc(new ScDocument(SCDOCMODE_UNDO)); |
52 | 0 | SCTAB nTab = rRange.aStart.Tab(); |
53 | 0 | pUndoDoc->InitUndo(rDoc, nTab, nTab); |
54 | 0 | SCTAB nTabCount = rDoc.GetTableCount(); |
55 | 0 | for (const auto& rTab : rMark) |
56 | 0 | if (rTab != nTab) |
57 | 0 | pUndoDoc->AddUndoTab( rTab, rTab ); |
58 | 0 | ScRange aCopyRange = rRange; |
59 | 0 | aCopyRange.aStart.SetTab(0); |
60 | 0 | aCopyRange.aEnd.SetTab(nTabCount-1); |
61 | | |
62 | | // in case of "Format/Standard" copy all attributes, because CopyToDocument |
63 | | // with InsertDeleteFlags::HARDATTR only is too time-consuming: |
64 | 0 | InsertDeleteFlags nUndoDocFlags = nFlags; |
65 | 0 | if (nFlags & InsertDeleteFlags::ATTRIB) |
66 | 0 | nUndoDocFlags |= InsertDeleteFlags::ATTRIB; |
67 | 0 | if (nFlags & InsertDeleteFlags::EDITATTR) // Edit-Engine-Attribute |
68 | 0 | nUndoDocFlags |= InsertDeleteFlags::STRING; // -> cells will be changed |
69 | 0 | if (nFlags & InsertDeleteFlags::NOTE) |
70 | 0 | nUndoDocFlags |= InsertDeleteFlags::CONTENTS; // copy all cells with their notes |
71 | | // do not copy note captions to undo document |
72 | 0 | nUndoDocFlags |= InsertDeleteFlags::NOCAPTIONS; |
73 | 0 | rDoc.CopyToDocument(aCopyRange, nUndoDocFlags, bOnlyMarked, *pUndoDoc, &rMark); |
74 | |
|
75 | 0 | return pUndoDoc; |
76 | 0 | } |
77 | | |
78 | | void DocFuncUtil::addDeleteContentsUndo( |
79 | | SfxUndoManager* pUndoMgr, ScDocShell& rDocSh, const ScMarkData& rMark, |
80 | | const ScRange& rRange, ScDocumentUniquePtr&& pUndoDoc, InsertDeleteFlags nFlags, |
81 | | const std::shared_ptr<ScSimpleUndo::DataSpansType>& pSpans, |
82 | | bool bMulti, bool bDrawUndo ) |
83 | 0 | { |
84 | 0 | std::unique_ptr<ScUndoDeleteContents> pUndo( |
85 | 0 | new ScUndoDeleteContents( |
86 | 0 | rDocSh, rMark, rRange, std::move(pUndoDoc), bMulti, nFlags, bDrawUndo)); |
87 | 0 | pUndo->SetDataSpans(pSpans); |
88 | |
|
89 | 0 | pUndoMgr->AddUndoAction(std::move(pUndo)); |
90 | 0 | } |
91 | | |
92 | | std::shared_ptr<ScSimpleUndo::DataSpansType> DocFuncUtil::getNonEmptyCellSpans( |
93 | | const ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange ) |
94 | 0 | { |
95 | 0 | auto pDataSpans = std::make_shared<ScSimpleUndo::DataSpansType>(); |
96 | 0 | for (const SCTAB nTab : rMark) |
97 | 0 | { |
98 | 0 | SCCOL nCol1 = rRange.aStart.Col(), nCol2 = rRange.aEnd.Col(); |
99 | 0 | SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row(); |
100 | |
|
101 | 0 | std::pair<ScSimpleUndo::DataSpansType::iterator,bool> r = |
102 | 0 | pDataSpans->insert(std::make_pair(nTab, std::make_unique<sc::ColumnSpanSet>())); |
103 | |
|
104 | 0 | if (r.second) |
105 | 0 | { |
106 | 0 | sc::ColumnSpanSet *const pSet = r.first->second.get(); |
107 | 0 | pSet->scan(rDoc, nTab, nCol1, nRow1, nCol2, nRow2, true); |
108 | 0 | } |
109 | 0 | } |
110 | |
|
111 | 0 | return pDataSpans; |
112 | 0 | } |
113 | | |
114 | | } |
115 | | |
116 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |