1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
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
) :
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()
98 delete pChartListenerCollection
;
103 void ScRefUndoData::DeleteUnchanged( const ScDocument
* pDoc
)
107 ScDBCollection
* pNewDBColl
= pDoc
->GetDBCollection();
108 if ( pNewDBColl
&& *pDBCollection
== *pNewDBColl
)
109 DELETEZ(pDBCollection
);
113 ScRangeName
* pNewRanges
= ((ScDocument
*)pDoc
)->GetRangeName(); //! const
114 if ( pNewRanges
&& *pRangeName
== *pNewRanges
)
120 ScPrintRangeSaver
* pNewRanges
= pDoc
->CreatePrintRangeSaver();
121 if ( pNewRanges
&& *pPrintRanges
== *pNewRanges
)
122 DELETEZ(pPrintRanges
);
128 ScDPCollection
* pNewDP
= ((ScDocument
*)pDoc
)->GetDPCollection(); //! const
129 if ( pNewDP
&& pDPCollection
->RefsEqual(*pNewDP
) )
130 DELETEZ(pDPCollection
);
135 ScConditionalFormatList
* pNewCond
= pDoc
->GetCondFormList();
136 if ( pNewCond
&& *pCondFormList
== *pNewCond
)
137 DELETEZ(pCondFormList
);
142 ScDetOpList
* pNewDetOp
= pDoc
->GetDetOpList();
143 if ( pNewDetOp
&& *pDetOpList
== *pNewDetOp
)
147 if ( pChartListenerCollection
)
149 ScChartListenerCollection
* pNewChartListenerCollection
=
150 pDoc
->GetChartListenerCollection();
151 if ( pNewChartListenerCollection
&&
152 *pChartListenerCollection
== *pNewChartListenerCollection
)
153 DELETEZ( pChartListenerCollection
);
158 if ( pAreaLinks
->IsEqual( pDoc
) )
162 if ( pDoc
->HasUnoRefUndo() )
164 pUnoRefs
= const_cast<ScDocument
*>(pDoc
)->EndUnoRefUndo();
165 if ( pUnoRefs
&& pUnoRefs
->IsEmpty() )
172 void ScRefUndoData::DoUndo( ScDocument
* pDoc
, BOOL bUndoRefFirst
)
175 pDoc
->SetDBCollection( new ScDBCollection(*pDBCollection
) );
177 pDoc
->SetRangeName( new ScRangeName(*pRangeName
) );
180 pDoc
->RestorePrintRanges(*pPrintRanges
);
184 ScDPCollection
* pDocDP
= pDoc
->GetDPCollection();
186 pDPCollection
->WriteRefsTo( *pDocDP
);
190 pDoc
->SetCondFormList( new ScConditionalFormatList(*pCondFormList
) );
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
205 pDoc
->SetAutoCalc( bOldAutoCalc
);
209 pAreaLinks
->Restore( pDoc
);
212 pUnoRefs
->Undo( pDoc
);