Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "refundo.hxx"
30 : : #include "undobase.hxx"
31 : : #include "document.hxx"
32 : : #include "dbdata.hxx"
33 : : #include "rangenam.hxx"
34 : : #include "pivot.hxx"
35 : : #include "chartarr.hxx"
36 : : #include "stlpool.hxx"
37 : : #include "detdata.hxx"
38 : : #include "prnsave.hxx"
39 : : #include "chartlis.hxx"
40 : : #include "dpobject.hxx"
41 : : #include "areasave.hxx"
42 : : #include "unoreflist.hxx"
43 : :
44 : : // -----------------------------------------------------------------------
45 : :
46 : 36 : ScRefUndoData::ScRefUndoData( const ScDocument* pDoc ) :
47 : 36 : pUnoRefs( NULL )
48 : : {
49 : 36 : ScDBCollection* pOldDBColl = pDoc->GetDBCollection();
50 [ + - ][ + - ]: 36 : pDBCollection = pOldDBColl ? new ScDBCollection(*pOldDBColl) : NULL;
51 : :
52 : 36 : ScRangeName* pOldRanges = ((ScDocument*)pDoc)->GetRangeName(); //! const
53 [ + - ][ + - ]: 36 : pRangeName = pOldRanges ? new ScRangeName(*pOldRanges) : NULL;
54 : :
55 : 36 : pPrintRanges = pDoc->CreatePrintRangeSaver(); // neu erzeugt
56 : :
57 : : //! bei Pivot nur Bereiche merken ???
58 : :
59 : 36 : ScDPCollection* pOldDP = ((ScDocument*)pDoc)->GetDPCollection(); //! const
60 [ + - ][ + - ]: 36 : pDPCollection = pOldDP ? new ScDPCollection(*pOldDP) : NULL;
61 : :
62 : 36 : ScDetOpList* pOldDetOp = pDoc->GetDetOpList();
63 [ # # ][ - + ]: 36 : pDetOpList = pOldDetOp ? new ScDetOpList(*pOldDetOp) : 0;
64 : :
65 : : ScChartListenerCollection* pOldChartListenerCollection =
66 : 36 : pDoc->GetChartListenerCollection();
67 : : pChartListenerCollection = pOldChartListenerCollection ?
68 [ + - ][ + - ]: 36 : new ScChartListenerCollection( *pOldChartListenerCollection ) : NULL;
69 : :
70 : 36 : pAreaLinks = ScAreaLinkSaveCollection::CreateFromDoc(pDoc); // returns NULL if empty
71 : :
72 : 36 : const_cast<ScDocument*>(pDoc)->BeginUnoRefUndo();
73 : 36 : }
74 : :
75 : 27 : ScRefUndoData::~ScRefUndoData()
76 : : {
77 [ + - ]: 27 : delete pDBCollection;
78 [ + + ]: 27 : delete pRangeName;
79 [ + + ]: 27 : delete pPrintRanges;
80 [ + + ]: 27 : delete pDPCollection;
81 [ - + ]: 27 : delete pDetOpList;
82 [ - + ]: 27 : delete pChartListenerCollection;
83 [ - + ]: 27 : delete pAreaLinks;
84 [ + + ]: 27 : delete pUnoRefs;
85 : 27 : }
86 : :
87 : 36 : void ScRefUndoData::DeleteUnchanged( const ScDocument* pDoc )
88 : : {
89 [ + - ]: 36 : if (pDBCollection)
90 : : {
91 : 36 : ScDBCollection* pNewDBColl = pDoc->GetDBCollection();
92 [ + + ][ + + ]: 36 : if ( pNewDBColl && *pDBCollection == *pNewDBColl )
[ + - ]
93 [ + - ]: 3 : DELETEZ(pDBCollection);
94 : : }
95 [ + - ]: 36 : if (pRangeName)
96 : : {
97 : 36 : ScRangeName* pNewRanges = ((ScDocument*)pDoc)->GetRangeName(); //! const
98 [ + + ][ + + ]: 36 : if ( pNewRanges && *pRangeName == *pNewRanges )
[ + - ]
99 [ + - ]: 34 : DELETEZ(pRangeName);
100 : : }
101 : :
102 [ + - ]: 36 : if (pPrintRanges)
103 : : {
104 : 36 : ScPrintRangeSaver* pNewRanges = pDoc->CreatePrintRangeSaver();
105 [ + + ][ + + ]: 36 : if ( pNewRanges && *pPrintRanges == *pNewRanges )
[ + - ]
106 [ + - ]: 17 : DELETEZ(pPrintRanges);
107 [ + - ]: 36 : delete pNewRanges;
108 : : }
109 : :
110 [ + - ]: 36 : if (pDPCollection)
111 : : {
112 : 36 : ScDPCollection* pNewDP = ((ScDocument*)pDoc)->GetDPCollection(); //! const
113 [ + + ][ + + ]: 36 : if ( pNewDP && pDPCollection->RefsEqual(*pNewDP) )
[ + - ]
114 [ + - ]: 20 : DELETEZ(pDPCollection);
115 : : }
116 : :
117 [ - + ]: 36 : if (pDetOpList)
118 : : {
119 : 0 : ScDetOpList* pNewDetOp = pDoc->GetDetOpList();
120 [ # # ][ # # ]: 0 : if ( pNewDetOp && *pDetOpList == *pNewDetOp )
[ # # ]
121 [ # # ]: 0 : DELETEZ(pDetOpList);
122 : : }
123 : :
124 [ + - ]: 36 : if ( pChartListenerCollection )
125 : : {
126 : : ScChartListenerCollection* pNewChartListenerCollection =
127 : 36 : pDoc->GetChartListenerCollection();
128 [ + - ]: 72 : if ( pNewChartListenerCollection &&
[ + - + - ]
129 : 36 : *pChartListenerCollection == *pNewChartListenerCollection )
130 [ + - ]: 36 : DELETEZ( pChartListenerCollection );
131 : : }
132 : :
133 [ - + ]: 36 : if (pAreaLinks)
134 : : {
135 [ # # ]: 0 : if ( pAreaLinks->IsEqual( pDoc ) )
136 [ # # ]: 0 : DELETEZ(pAreaLinks);
137 : : }
138 : :
139 [ + - ]: 36 : if ( pDoc->HasUnoRefUndo() )
140 : : {
141 : 36 : pUnoRefs = const_cast<ScDocument*>(pDoc)->EndUnoRefUndo();
142 [ + + ][ + + ]: 36 : if ( pUnoRefs && pUnoRefs->IsEmpty() )
[ + - ]
143 : : {
144 [ + - ]: 10 : DELETEZ( pUnoRefs );
145 : : }
146 : : }
147 : 36 : }
148 : :
149 : 6 : void ScRefUndoData::DoUndo( ScDocument* pDoc, sal_Bool bUndoRefFirst )
150 : : {
151 [ + + ]: 6 : if (pDBCollection)
152 [ + - ]: 3 : pDoc->SetDBCollection( new ScDBCollection(*pDBCollection) );
153 [ - + ]: 6 : if (pRangeName)
154 [ # # ]: 0 : pDoc->SetRangeName( new ScRangeName(*pRangeName) );
155 : :
156 [ - + ]: 6 : if (pPrintRanges)
157 : 0 : pDoc->RestorePrintRanges(*pPrintRanges);
158 : :
159 [ - + ]: 6 : if (pDPCollection)
160 : : {
161 : 0 : ScDPCollection* pDocDP = pDoc->GetDPCollection();
162 [ # # ]: 0 : if (pDocDP)
163 : 0 : pDPCollection->WriteRefsTo( *pDocDP );
164 : : }
165 : :
166 [ - + ]: 6 : if (pDetOpList)
167 [ # # ]: 0 : pDoc->SetDetOpList( new ScDetOpList(*pDetOpList) );
168 : :
169 : : // bUndoRefFirst ist bSetChartRangeLists
170 [ - + ]: 6 : if ( pChartListenerCollection )
171 : : pDoc->SetChartListenerCollection( new ScChartListenerCollection(
172 [ # # ]: 0 : *pChartListenerCollection ), bUndoRefFirst );
173 : :
174 [ + + ][ - + ]: 6 : if (pDBCollection || pRangeName)
175 : : {
176 : 3 : sal_Bool bOldAutoCalc = pDoc->GetAutoCalc();
177 : 3 : pDoc->SetAutoCalc( false ); // Mehrfachberechnungen vermeiden
178 : 3 : pDoc->CompileAll();
179 : 3 : pDoc->SetDirty();
180 : 3 : pDoc->SetAutoCalc( bOldAutoCalc );
181 : : }
182 : :
183 [ - + ]: 6 : if (pAreaLinks)
184 : 0 : pAreaLinks->Restore( pDoc );
185 : :
186 [ - + ]: 6 : if ( pUnoRefs )
187 : 0 : pUnoRefs->Undo( pDoc );
188 : 6 : }
189 : :
190 : :
191 : :
192 : :
193 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|