fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / undo / refundo.cxx
blobf782f7e7aa249589bebe76fbf8b38fa38b50f3e9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
23 #include "dbdata.hxx"
24 #include "rangenam.hxx"
25 #include "pivot.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 ) :
38 pDBCollection(NULL),
39 pRangeName(NULL),
40 pPrintRanges(pDoc->CreatePrintRangeSaver()),
41 pDPCollection(NULL),
42 pDetOpList(NULL),
43 pChartListenerCollection(NULL),
44 pAreaLinks(NULL),
45 pUnoRefs(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();
66 if (pOldChartLisColl)
67 pChartListenerCollection = new ScChartListenerCollection(*pOldChartLisColl);
69 pAreaLinks = ScAreaLinkSaveCollection::CreateFromDoc(pDoc); // returns NULL if empty
71 const_cast<ScDocument*>(pDoc)->BeginUnoRefUndo();
74 ScRefUndoData::~ScRefUndoData()
76 delete pDBCollection;
77 delete pRangeName;
78 delete pPrintRanges;
79 delete pDPCollection;
80 delete pDetOpList;
81 delete pChartListenerCollection;
82 delete pAreaLinks;
83 delete pUnoRefs;
86 void ScRefUndoData::DeleteUnchanged( const ScDocument* pDoc )
88 if (pDBCollection)
90 ScDBCollection* pNewDBColl = pDoc->GetDBCollection();
91 if ( pNewDBColl && *pDBCollection == *pNewDBColl )
92 DELETEZ(pDBCollection);
94 if (pRangeName)
96 ScRangeName* pNewRanges = pDoc->GetRangeName();
97 if ( pNewRanges && *pRangeName == *pNewRanges )
98 DELETEZ(pRangeName);
101 if (pPrintRanges)
103 ScPrintRangeSaver* pNewRanges = pDoc->CreatePrintRangeSaver();
104 if ( pNewRanges && *pPrintRanges == *pNewRanges )
105 DELETEZ(pPrintRanges);
106 delete pNewRanges;
109 if (pDPCollection)
111 ScDPCollection* pNewDP = const_cast<ScDocument*>(pDoc)->GetDPCollection(); //! const
112 if ( pNewDP && pDPCollection->RefsEqual(*pNewDP) )
113 DELETEZ(pDPCollection);
116 if (pDetOpList)
118 ScDetOpList* pNewDetOp = pDoc->GetDetOpList();
119 if ( pNewDetOp && *pDetOpList == *pNewDetOp )
120 DELETEZ(pDetOpList);
123 if ( pChartListenerCollection )
125 ScChartListenerCollection* pNewChartListenerCollection =
126 pDoc->GetChartListenerCollection();
127 if ( pNewChartListenerCollection &&
128 *pChartListenerCollection == *pNewChartListenerCollection )
129 DELETEZ( pChartListenerCollection );
132 if (pAreaLinks)
134 if ( pAreaLinks->IsEqual( pDoc ) )
135 DELETEZ(pAreaLinks);
138 if ( pDoc->HasUnoRefUndo() )
140 pUnoRefs = const_cast<ScDocument*>(pDoc)->EndUnoRefUndo();
141 if ( pUnoRefs && pUnoRefs->IsEmpty() )
143 DELETEZ( pUnoRefs );
148 void ScRefUndoData::DoUndo( ScDocument* pDoc, bool bUndoRefFirst )
150 if (pDBCollection)
151 pDoc->SetDBCollection( new ScDBCollection(*pDBCollection) );
152 if (pRangeName)
153 pDoc->SetRangeName( new ScRangeName(*pRangeName) );
155 if (pPrintRanges)
156 pDoc->RestorePrintRanges(*pPrintRanges);
158 if (pDPCollection)
160 ScDPCollection* pDocDP = pDoc->GetDPCollection();
161 if (pDocDP)
162 pDPCollection->WriteRefsTo( *pDocDP );
165 if (pDetOpList)
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);
176 pDoc->CompileAll();
178 sc::SetFormulaDirtyContext aCxt;
179 pDoc->SetAllFormulasDirty(aCxt);
182 if (pAreaLinks)
183 pAreaLinks->Restore( pDoc );
185 if ( pUnoRefs )
186 pUnoRefs->Undo( pDoc );
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */