update dev300-m58
[ooovba.git] / sc / source / ui / undo / refundo.cxx
blob7675338f49a309987896a3983a45d769ea105d28
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: refundo.cxx,v $
10 * $Revision: 1.6.32.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // -----------------------------------------------------------------------
38 // INCLUDE ---------------------------------------------------------------
40 #include "refundo.hxx"
41 #include "undobase.hxx"
42 #include "document.hxx"
43 #include "dbcolect.hxx"
44 #include "rangenam.hxx"
45 #include "pivot.hxx"
46 #include "chartarr.hxx"
47 #include "stlpool.hxx"
48 #include "conditio.hxx"
49 #include "detdata.hxx"
50 #include "prnsave.hxx"
51 #include "chartlis.hxx"
52 #include "dpobject.hxx"
53 #include "areasave.hxx"
54 #include "unoreflist.hxx"
56 // -----------------------------------------------------------------------
58 ScRefUndoData::ScRefUndoData( const ScDocument* pDoc ) :
59 pUnoRefs( NULL )
61 ScDBCollection* pOldDBColl = pDoc->GetDBCollection();
62 pDBCollection = pOldDBColl ? new ScDBCollection(*pOldDBColl) : NULL;
64 ScRangeName* pOldRanges = ((ScDocument*)pDoc)->GetRangeName(); //! const
65 pRangeName = pOldRanges ? new ScRangeName(*pOldRanges) : NULL;
67 pPrintRanges = pDoc->CreatePrintRangeSaver(); // neu erzeugt
69 //! bei Pivot nur Bereiche merken ???
71 ScDPCollection* pOldDP = ((ScDocument*)pDoc)->GetDPCollection(); //! const
72 pDPCollection = pOldDP ? new ScDPCollection(*pOldDP) : NULL;
74 ScConditionalFormatList* pOldCond = pDoc->GetCondFormList();
75 pCondFormList = pOldCond ? new ScConditionalFormatList(*pOldCond) : NULL;
77 ScDetOpList* pOldDetOp = pDoc->GetDetOpList();
78 pDetOpList = pOldDetOp ? new ScDetOpList(*pOldDetOp) : 0;
80 ScChartListenerCollection* pOldChartListenerCollection =
81 pDoc->GetChartListenerCollection();
82 pChartListenerCollection = pOldChartListenerCollection ?
83 new ScChartListenerCollection( *pOldChartListenerCollection ) : NULL;
85 pAreaLinks = ScAreaLinkSaveCollection::CreateFromDoc(pDoc); // returns NULL if empty
87 const_cast<ScDocument*>(pDoc)->BeginUnoRefUndo();
90 ScRefUndoData::~ScRefUndoData()
92 delete pDBCollection;
93 delete pRangeName;
94 delete pPrintRanges;
95 delete pDPCollection;
96 delete pCondFormList;
97 delete pDetOpList;
98 delete pChartListenerCollection;
99 delete pAreaLinks;
100 delete pUnoRefs;
103 void ScRefUndoData::DeleteUnchanged( const ScDocument* pDoc )
105 if (pDBCollection)
107 ScDBCollection* pNewDBColl = pDoc->GetDBCollection();
108 if ( pNewDBColl && *pDBCollection == *pNewDBColl )
109 DELETEZ(pDBCollection);
111 if (pRangeName)
113 ScRangeName* pNewRanges = ((ScDocument*)pDoc)->GetRangeName(); //! const
114 if ( pNewRanges && *pRangeName == *pNewRanges )
115 DELETEZ(pRangeName);
118 if (pPrintRanges)
120 ScPrintRangeSaver* pNewRanges = pDoc->CreatePrintRangeSaver();
121 if ( pNewRanges && *pPrintRanges == *pNewRanges )
122 DELETEZ(pPrintRanges);
123 delete pNewRanges;
126 if (pDPCollection)
128 ScDPCollection* pNewDP = ((ScDocument*)pDoc)->GetDPCollection(); //! const
129 if ( pNewDP && pDPCollection->RefsEqual(*pNewDP) )
130 DELETEZ(pDPCollection);
133 if (pCondFormList)
135 ScConditionalFormatList* pNewCond = pDoc->GetCondFormList();
136 if ( pNewCond && *pCondFormList == *pNewCond )
137 DELETEZ(pCondFormList);
140 if (pDetOpList)
142 ScDetOpList* pNewDetOp = pDoc->GetDetOpList();
143 if ( pNewDetOp && *pDetOpList == *pNewDetOp )
144 DELETEZ(pDetOpList);
147 if ( pChartListenerCollection )
149 ScChartListenerCollection* pNewChartListenerCollection =
150 pDoc->GetChartListenerCollection();
151 if ( pNewChartListenerCollection &&
152 *pChartListenerCollection == *pNewChartListenerCollection )
153 DELETEZ( pChartListenerCollection );
156 if (pAreaLinks)
158 if ( pAreaLinks->IsEqual( pDoc ) )
159 DELETEZ(pAreaLinks);
162 if ( pDoc->HasUnoRefUndo() )
164 pUnoRefs = const_cast<ScDocument*>(pDoc)->EndUnoRefUndo();
165 if ( pUnoRefs && pUnoRefs->IsEmpty() )
167 DELETEZ( pUnoRefs );
172 void ScRefUndoData::DoUndo( ScDocument* pDoc, BOOL bUndoRefFirst )
174 if (pDBCollection)
175 pDoc->SetDBCollection( new ScDBCollection(*pDBCollection) );
176 if (pRangeName)
177 pDoc->SetRangeName( new ScRangeName(*pRangeName) );
179 if (pPrintRanges)
180 pDoc->RestorePrintRanges(*pPrintRanges);
182 if (pDPCollection)
184 ScDPCollection* pDocDP = pDoc->GetDPCollection();
185 if (pDocDP)
186 pDPCollection->WriteRefsTo( *pDocDP );
189 if (pCondFormList)
190 pDoc->SetCondFormList( new ScConditionalFormatList(*pCondFormList) );
191 if (pDetOpList)
192 pDoc->SetDetOpList( new ScDetOpList(*pDetOpList) );
194 // #65055# bUndoRefFirst ist bSetChartRangeLists
195 if ( pChartListenerCollection )
196 pDoc->SetChartListenerCollection( new ScChartListenerCollection(
197 *pChartListenerCollection ), bUndoRefFirst );
199 if (pDBCollection || pRangeName)
201 BOOL bOldAutoCalc = pDoc->GetAutoCalc();
202 pDoc->SetAutoCalc( FALSE ); // Mehrfachberechnungen vermeiden
203 pDoc->CompileAll();
204 pDoc->SetDirty();
205 pDoc->SetAutoCalc( bOldAutoCalc );
208 if (pAreaLinks)
209 pAreaLinks->Restore( pDoc );
211 if ( pUnoRefs )
212 pUnoRefs->Undo( pDoc );