1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "refundo.hxx"
21 #include "undobase.hxx"
22 #include "document.hxx"
24 #include "rangenam.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"
35 ScRefUndoData::ScRefUndoData( const ScDocument
* pDoc
) :
38 ScDBCollection
* pOldDBColl
= pDoc
->GetDBCollection();
39 pDBCollection
= pOldDBColl
? new ScDBCollection(*pOldDBColl
) : NULL
;
41 ScRangeName
* pOldRanges
= ((ScDocument
*)pDoc
)->GetRangeName(); //! const
42 pRangeName
= pOldRanges
? new ScRangeName(*pOldRanges
) : NULL
;
44 pPrintRanges
= pDoc
->CreatePrintRangeSaver(); // recreated
46 // when handling Pivot solely keep the range?
48 ScDPCollection
* pOldDP
= ((ScDocument
*)pDoc
)->GetDPCollection(); //! const
49 pDPCollection
= pOldDP
? new ScDPCollection(*pOldDP
) : NULL
;
51 ScDetOpList
* pOldDetOp
= pDoc
->GetDetOpList();
52 pDetOpList
= pOldDetOp
? new ScDetOpList(*pOldDetOp
) : 0;
54 ScChartListenerCollection
* pOldChartListenerCollection
=
55 pDoc
->GetChartListenerCollection();
56 pChartListenerCollection
= pOldChartListenerCollection
?
57 new ScChartListenerCollection( *pOldChartListenerCollection
) : NULL
;
59 pAreaLinks
= ScAreaLinkSaveCollection::CreateFromDoc(pDoc
); // returns NULL if empty
61 const_cast<ScDocument
*>(pDoc
)->BeginUnoRefUndo();
64 ScRefUndoData::~ScRefUndoData()
71 delete pChartListenerCollection
;
76 void ScRefUndoData::DeleteUnchanged( const ScDocument
* pDoc
)
80 ScDBCollection
* pNewDBColl
= pDoc
->GetDBCollection();
81 if ( pNewDBColl
&& *pDBCollection
== *pNewDBColl
)
82 DELETEZ(pDBCollection
);
86 ScRangeName
* pNewRanges
= ((ScDocument
*)pDoc
)->GetRangeName(); //! const
87 if ( pNewRanges
&& *pRangeName
== *pNewRanges
)
93 ScPrintRangeSaver
* pNewRanges
= pDoc
->CreatePrintRangeSaver();
94 if ( pNewRanges
&& *pPrintRanges
== *pNewRanges
)
95 DELETEZ(pPrintRanges
);
101 ScDPCollection
* pNewDP
= ((ScDocument
*)pDoc
)->GetDPCollection(); //! const
102 if ( pNewDP
&& pDPCollection
->RefsEqual(*pNewDP
) )
103 DELETEZ(pDPCollection
);
108 ScDetOpList
* pNewDetOp
= pDoc
->GetDetOpList();
109 if ( pNewDetOp
&& *pDetOpList
== *pNewDetOp
)
113 if ( pChartListenerCollection
)
115 ScChartListenerCollection
* pNewChartListenerCollection
=
116 pDoc
->GetChartListenerCollection();
117 if ( pNewChartListenerCollection
&&
118 *pChartListenerCollection
== *pNewChartListenerCollection
)
119 DELETEZ( pChartListenerCollection
);
124 if ( pAreaLinks
->IsEqual( pDoc
) )
128 if ( pDoc
->HasUnoRefUndo() )
130 pUnoRefs
= const_cast<ScDocument
*>(pDoc
)->EndUnoRefUndo();
131 if ( pUnoRefs
&& pUnoRefs
->IsEmpty() )
138 void ScRefUndoData::DoUndo( ScDocument
* pDoc
, sal_Bool bUndoRefFirst
)
141 pDoc
->SetDBCollection( new ScDBCollection(*pDBCollection
) );
143 pDoc
->SetRangeName( new ScRangeName(*pRangeName
) );
146 pDoc
->RestorePrintRanges(*pPrintRanges
);
150 ScDPCollection
* pDocDP
= pDoc
->GetDPCollection();
152 pDPCollection
->WriteRefsTo( *pDocDP
);
156 pDoc
->SetDetOpList( new ScDetOpList(*pDetOpList
) );
158 // bUndoRefFirst is bSetChartRangeLists
159 if ( pChartListenerCollection
)
160 pDoc
->SetChartListenerCollection( new ScChartListenerCollection(
161 *pChartListenerCollection
), bUndoRefFirst
);
163 if (pDBCollection
|| pRangeName
)
165 sal_Bool bOldAutoCalc
= pDoc
->GetAutoCalc();
166 pDoc
->SetAutoCalc( false ); // Avoid multiple calculations
169 pDoc
->SetAutoCalc( bOldAutoCalc
);
173 pAreaLinks
->Restore( pDoc
);
176 pUnoRefs
->Undo( pDoc
);
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */