/src/libreoffice/sc/source/ui/undo/refundo.cxx
Line | Count | Source (jump to first uncovered line) |
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 <refundo.hxx> |
21 | | #include <document.hxx> |
22 | | #include <dbdata.hxx> |
23 | | #include <rangenam.hxx> |
24 | | #include <detdata.hxx> |
25 | | #include <prnsave.hxx> |
26 | | #include <chartlis.hxx> |
27 | | #include <dpobject.hxx> |
28 | | #include <areasave.hxx> |
29 | | #include <unoreflist.hxx> |
30 | | #include <scopetools.hxx> |
31 | | #include <refupdatecontext.hxx> |
32 | | |
33 | | ScRefUndoData::ScRefUndoData( ScDocument& rDoc ) : |
34 | 0 | pPrintRanges(rDoc.CreatePrintRangeSaver()) |
35 | 0 | { |
36 | 0 | const ScDBCollection* pOldDBColl = rDoc.GetDBCollection(); |
37 | 0 | if (pOldDBColl && !pOldDBColl->empty()) |
38 | 0 | pDBCollection.reset(new ScDBCollection(*pOldDBColl)); |
39 | |
|
40 | 0 | const ScRangeName* pOldRanges = rDoc.GetRangeName(); |
41 | 0 | if (pOldRanges && !pOldRanges->empty()) |
42 | 0 | pRangeName.reset(new ScRangeName(*pOldRanges)); |
43 | | |
44 | | // when handling Pivot solely keep the range? |
45 | |
|
46 | 0 | const ScDPCollection* pOldDP = rDoc.GetDPCollection(); |
47 | 0 | if (pOldDP && pOldDP->GetCount()) |
48 | 0 | pDPCollection.reset(new ScDPCollection(*pOldDP)); |
49 | |
|
50 | 0 | const ScDetOpList* pOldDetOp = rDoc.GetDetOpList(); |
51 | 0 | if (pOldDetOp && pOldDetOp->Count()) |
52 | 0 | pDetOpList.reset(new ScDetOpList(*pOldDetOp)); |
53 | |
|
54 | 0 | const ScChartListenerCollection* pOldChartLisColl = rDoc.GetChartListenerCollection(); |
55 | 0 | if (pOldChartLisColl) |
56 | 0 | pChartListenerCollection.reset(new ScChartListenerCollection(*pOldChartLisColl)); |
57 | |
|
58 | 0 | pAreaLinks = ScAreaLinkSaveCollection::CreateFromDoc(rDoc); // returns NULL if empty |
59 | |
|
60 | 0 | rDoc.BeginUnoRefUndo(); |
61 | 0 | } |
62 | | |
63 | | ScRefUndoData::~ScRefUndoData() |
64 | 0 | { |
65 | 0 | pDBCollection.reset(); |
66 | 0 | pRangeName.reset(); |
67 | 0 | pPrintRanges.reset(); |
68 | 0 | pDPCollection.reset(); |
69 | 0 | pDetOpList.reset(); |
70 | 0 | pChartListenerCollection.reset(); |
71 | 0 | pAreaLinks.reset(); |
72 | 0 | } |
73 | | |
74 | | void ScRefUndoData::DeleteUnchanged( ScDocument& rDoc ) |
75 | 0 | { |
76 | 0 | if (pDBCollection) |
77 | 0 | { |
78 | 0 | ScDBCollection* pNewDBColl = rDoc.GetDBCollection(); |
79 | 0 | if ( pNewDBColl && *pDBCollection == *pNewDBColl ) |
80 | 0 | pDBCollection.reset(); |
81 | 0 | } |
82 | 0 | if (pRangeName) |
83 | 0 | { |
84 | 0 | ScRangeName* pNewRanges = rDoc.GetRangeName(); |
85 | 0 | if ( pNewRanges && *pRangeName == *pNewRanges ) |
86 | 0 | pRangeName.reset(); |
87 | 0 | } |
88 | |
|
89 | 0 | if (pPrintRanges) |
90 | 0 | { |
91 | 0 | std::unique_ptr<ScPrintRangeSaver> pNewRanges = rDoc.CreatePrintRangeSaver(); |
92 | 0 | if ( pNewRanges && *pPrintRanges == *pNewRanges ) |
93 | 0 | pPrintRanges.reset(); |
94 | 0 | } |
95 | |
|
96 | 0 | if (pDPCollection) |
97 | 0 | { |
98 | 0 | ScDPCollection* pNewDP = rDoc.GetDPCollection(); //! const |
99 | 0 | if ( pNewDP && pDPCollection->RefsEqual(*pNewDP) ) |
100 | 0 | pDPCollection.reset(); |
101 | 0 | } |
102 | |
|
103 | 0 | if (pDetOpList) |
104 | 0 | { |
105 | 0 | ScDetOpList* pNewDetOp = rDoc.GetDetOpList(); |
106 | 0 | if ( pNewDetOp && *pDetOpList == *pNewDetOp ) |
107 | 0 | pDetOpList.reset(); |
108 | 0 | } |
109 | |
|
110 | 0 | if ( pChartListenerCollection ) |
111 | 0 | { |
112 | 0 | ScChartListenerCollection* pNewChartListenerCollection = |
113 | 0 | rDoc.GetChartListenerCollection(); |
114 | 0 | if ( pNewChartListenerCollection && |
115 | 0 | *pChartListenerCollection == *pNewChartListenerCollection ) |
116 | 0 | pChartListenerCollection.reset(); |
117 | 0 | } |
118 | |
|
119 | 0 | if (pAreaLinks) |
120 | 0 | { |
121 | 0 | if ( pAreaLinks->IsEqual( rDoc ) ) |
122 | 0 | pAreaLinks.reset(); |
123 | 0 | } |
124 | |
|
125 | 0 | if ( rDoc.HasUnoRefUndo() ) |
126 | 0 | { |
127 | 0 | pUnoRefs = rDoc.EndUnoRefUndo(); |
128 | 0 | if ( pUnoRefs && pUnoRefs->IsEmpty() ) |
129 | 0 | { |
130 | 0 | pUnoRefs.reset(); |
131 | 0 | } |
132 | 0 | } |
133 | 0 | } |
134 | | |
135 | | void ScRefUndoData::DoUndo( ScDocument& rDoc, bool bUndoRefFirst ) |
136 | 0 | { |
137 | 0 | if (pDBCollection) |
138 | 0 | rDoc.SetDBCollection( std::unique_ptr<ScDBCollection>(new ScDBCollection(*pDBCollection)) ); |
139 | 0 | if (pRangeName) |
140 | 0 | rDoc.SetRangeName( std::unique_ptr<ScRangeName>(new ScRangeName(*pRangeName)) ); |
141 | |
|
142 | 0 | if (pPrintRanges) |
143 | 0 | rDoc.RestorePrintRanges(*pPrintRanges); |
144 | |
|
145 | 0 | if (pDPCollection) |
146 | 0 | { |
147 | 0 | ScDPCollection* pDocDP = rDoc.GetDPCollection(); |
148 | 0 | if (pDocDP) |
149 | 0 | pDPCollection->WriteRefsTo( *pDocDP ); |
150 | 0 | } |
151 | |
|
152 | 0 | if (pDetOpList) |
153 | 0 | rDoc.SetDetOpList( std::unique_ptr<ScDetOpList>(new ScDetOpList(*pDetOpList)) ); |
154 | | |
155 | | // bUndoRefFirst is bSetChartRangeLists |
156 | 0 | if ( pChartListenerCollection ) |
157 | 0 | rDoc.SetChartListenerCollection( std::make_unique<ScChartListenerCollection>( |
158 | 0 | *pChartListenerCollection ), bUndoRefFirst ); |
159 | |
|
160 | 0 | if (pDBCollection || pRangeName) |
161 | 0 | { |
162 | 0 | sc::AutoCalcSwitch aACSwitch(rDoc, false); |
163 | 0 | rDoc.CompileAll(); |
164 | |
|
165 | 0 | sc::SetFormulaDirtyContext aCxt; |
166 | 0 | rDoc.SetAllFormulasDirty(aCxt); |
167 | 0 | } |
168 | |
|
169 | 0 | if (pAreaLinks) |
170 | 0 | pAreaLinks->Restore( rDoc ); |
171 | |
|
172 | 0 | if ( pUnoRefs ) |
173 | 0 | pUnoRefs->Undo( rDoc ); |
174 | 0 | } |
175 | | |
176 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |