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