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