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"
34 #include <scopetools.hxx>
35 #include <refupdatecontext.hxx>
37 ScRefUndoData::ScRefUndoData( const ScDocument
* pDoc
) :
40 pPrintRanges(pDoc
->CreatePrintRangeSaver()),
43 pChartListenerCollection(NULL
),
47 const ScDBCollection
* pOldDBColl
= pDoc
->GetDBCollection();
48 if (pOldDBColl
&& !pOldDBColl
->empty())
49 pDBCollection
= new ScDBCollection(*pOldDBColl
);
51 const ScRangeName
* pOldRanges
= pDoc
->GetRangeName();
52 if (pOldRanges
&& !pOldRanges
->empty())
53 pRangeName
= new ScRangeName(*pOldRanges
);
55 // when handling Pivot solely keep the range?
57 const ScDPCollection
* pOldDP
= pDoc
->GetDPCollection();
58 if (pOldDP
&& pOldDP
->GetCount())
59 pDPCollection
= new ScDPCollection(*pOldDP
);
61 const ScDetOpList
* pOldDetOp
= pDoc
->GetDetOpList();
62 if (pOldDetOp
&& pOldDetOp
->Count())
63 pDetOpList
= new ScDetOpList(*pOldDetOp
);
65 const ScChartListenerCollection
* pOldChartLisColl
= pDoc
->GetChartListenerCollection();
67 pChartListenerCollection
= new ScChartListenerCollection(*pOldChartLisColl
);
69 pAreaLinks
= ScAreaLinkSaveCollection::CreateFromDoc(pDoc
); // returns NULL if empty
71 const_cast<ScDocument
*>(pDoc
)->BeginUnoRefUndo();
74 ScRefUndoData::~ScRefUndoData()
81 delete pChartListenerCollection
;
86 void ScRefUndoData::DeleteUnchanged( const ScDocument
* pDoc
)
90 ScDBCollection
* pNewDBColl
= pDoc
->GetDBCollection();
91 if ( pNewDBColl
&& *pDBCollection
== *pNewDBColl
)
92 DELETEZ(pDBCollection
);
96 ScRangeName
* pNewRanges
= pDoc
->GetRangeName();
97 if ( pNewRanges
&& *pRangeName
== *pNewRanges
)
103 ScPrintRangeSaver
* pNewRanges
= pDoc
->CreatePrintRangeSaver();
104 if ( pNewRanges
&& *pPrintRanges
== *pNewRanges
)
105 DELETEZ(pPrintRanges
);
111 ScDPCollection
* pNewDP
= const_cast<ScDocument
*>(pDoc
)->GetDPCollection(); //! const
112 if ( pNewDP
&& pDPCollection
->RefsEqual(*pNewDP
) )
113 DELETEZ(pDPCollection
);
118 ScDetOpList
* pNewDetOp
= pDoc
->GetDetOpList();
119 if ( pNewDetOp
&& *pDetOpList
== *pNewDetOp
)
123 if ( pChartListenerCollection
)
125 ScChartListenerCollection
* pNewChartListenerCollection
=
126 pDoc
->GetChartListenerCollection();
127 if ( pNewChartListenerCollection
&&
128 *pChartListenerCollection
== *pNewChartListenerCollection
)
129 DELETEZ( pChartListenerCollection
);
134 if ( pAreaLinks
->IsEqual( pDoc
) )
138 if ( pDoc
->HasUnoRefUndo() )
140 pUnoRefs
= const_cast<ScDocument
*>(pDoc
)->EndUnoRefUndo();
141 if ( pUnoRefs
&& pUnoRefs
->IsEmpty() )
148 void ScRefUndoData::DoUndo( ScDocument
* pDoc
, bool bUndoRefFirst
)
151 pDoc
->SetDBCollection( new ScDBCollection(*pDBCollection
) );
153 pDoc
->SetRangeName( new ScRangeName(*pRangeName
) );
156 pDoc
->RestorePrintRanges(*pPrintRanges
);
160 ScDPCollection
* pDocDP
= pDoc
->GetDPCollection();
162 pDPCollection
->WriteRefsTo( *pDocDP
);
166 pDoc
->SetDetOpList( new ScDetOpList(*pDetOpList
) );
168 // bUndoRefFirst is bSetChartRangeLists
169 if ( pChartListenerCollection
)
170 pDoc
->SetChartListenerCollection( new ScChartListenerCollection(
171 *pChartListenerCollection
), bUndoRefFirst
);
173 if (pDBCollection
|| pRangeName
)
175 sc::AutoCalcSwitch
aACSwitch(*pDoc
, false);
178 sc::SetFormulaDirtyContext aCxt
;
179 pDoc
->SetAllFormulasDirty(aCxt
);
183 pAreaLinks
->Restore( pDoc
);
186 pUnoRefs
->Undo( pDoc
);
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */