LibreOffice Module sc (master) 1
refundo.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <refundo.hxx>
21#include <document.hxx>
22#include <dbdata.hxx>
23#include <rangenam.hxx>
24#include <detdata.hxx>
25#include <prnsave.hxx>
26#include <chartlis.hxx>
27#include <dpobject.hxx>
28#include <areasave.hxx>
29#include <unoreflist.hxx>
30#include <scopetools.hxx>
31#include <refupdatecontext.hxx>
32
34 pPrintRanges(pDoc->CreatePrintRangeSaver())
35{
36 const ScDBCollection* pOldDBColl = pDoc->GetDBCollection();
37 if (pOldDBColl && !pOldDBColl->empty())
38 pDBCollection.reset(new ScDBCollection(*pOldDBColl));
39
40 const ScRangeName* pOldRanges = pDoc->GetRangeName();
41 if (pOldRanges && !pOldRanges->empty())
42 pRangeName.reset(new ScRangeName(*pOldRanges));
43
44 // when handling Pivot solely keep the range?
45
46 const ScDPCollection* pOldDP = pDoc->GetDPCollection();
47 if (pOldDP && pOldDP->GetCount())
48 pDPCollection.reset(new ScDPCollection(*pOldDP));
49
50 const ScDetOpList* pOldDetOp = pDoc->GetDetOpList();
51 if (pOldDetOp && pOldDetOp->Count())
52 pDetOpList.reset(new ScDetOpList(*pOldDetOp));
53
54 const ScChartListenerCollection* pOldChartLisColl = pDoc->GetChartListenerCollection();
55 if (pOldChartLisColl)
56 pChartListenerCollection.reset(new ScChartListenerCollection(*pOldChartLisColl));
57
58 pAreaLinks = ScAreaLinkSaveCollection::CreateFromDoc(pDoc); // returns NULL if empty
59
60 const_cast<ScDocument*>(pDoc)->BeginUnoRefUndo();
61}
62
64{
65 pDBCollection.reset();
66 pRangeName.reset();
67 pPrintRanges.reset();
68 pDPCollection.reset();
69 pDetOpList.reset();
71 pAreaLinks.reset();
72}
73
75{
76 if (pDBCollection)
77 {
78 ScDBCollection* pNewDBColl = pDoc->GetDBCollection();
79 if ( pNewDBColl && *pDBCollection == *pNewDBColl )
80 pDBCollection.reset();
81 }
82 if (pRangeName)
83 {
84 ScRangeName* pNewRanges = pDoc->GetRangeName();
85 if ( pNewRanges && *pRangeName == *pNewRanges )
86 pRangeName.reset();
87 }
88
89 if (pPrintRanges)
90 {
91 std::unique_ptr<ScPrintRangeSaver> pNewRanges = pDoc->CreatePrintRangeSaver();
92 if ( pNewRanges && *pPrintRanges == *pNewRanges )
93 pPrintRanges.reset();
94 }
95
96 if (pDPCollection)
97 {
98 ScDPCollection* pNewDP = const_cast<ScDocument*>(pDoc)->GetDPCollection();
99 if ( pNewDP && pDPCollection->RefsEqual(*pNewDP) )
100 pDPCollection.reset();
101 }
102
103 if (pDetOpList)
104 {
105 ScDetOpList* pNewDetOp = pDoc->GetDetOpList();
106 if ( pNewDetOp && *pDetOpList == *pNewDetOp )
107 pDetOpList.reset();
108 }
109
111 {
112 ScChartListenerCollection* pNewChartListenerCollection =
114 if ( pNewChartListenerCollection &&
115 *pChartListenerCollection == *pNewChartListenerCollection )
117 }
118
119 if (pAreaLinks)
120 {
121 if ( pAreaLinks->IsEqual( pDoc ) )
122 pAreaLinks.reset();
123 }
124
125 if ( pDoc->HasUnoRefUndo() )
126 {
127 pUnoRefs = const_cast<ScDocument*>(pDoc)->EndUnoRefUndo();
128 if ( pUnoRefs && pUnoRefs->IsEmpty() )
129 {
130 pUnoRefs.reset();
131 }
132 }
133}
134
135void ScRefUndoData::DoUndo( ScDocument* pDoc, bool bUndoRefFirst )
136{
137 if (pDBCollection)
138 pDoc->SetDBCollection( std::unique_ptr<ScDBCollection>(new ScDBCollection(*pDBCollection)) );
139 if (pRangeName)
140 pDoc->SetRangeName( std::unique_ptr<ScRangeName>(new ScRangeName(*pRangeName)) );
141
142 if (pPrintRanges)
144
145 if (pDPCollection)
146 {
147 ScDPCollection* pDocDP = pDoc->GetDPCollection();
148 if (pDocDP)
149 pDPCollection->WriteRefsTo( *pDocDP );
150 }
151
152 if (pDetOpList)
153 pDoc->SetDetOpList( std::unique_ptr<ScDetOpList>(new ScDetOpList(*pDetOpList)) );
154
155 // bUndoRefFirst is bSetChartRangeLists
157 pDoc->SetChartListenerCollection( std::make_unique<ScChartListenerCollection>(
158 *pChartListenerCollection ), bUndoRefFirst );
159
161 {
162 sc::AutoCalcSwitch aACSwitch(*pDoc, false);
163 pDoc->CompileAll();
164
166 pDoc->SetAllFormulasDirty(aCxt);
167 }
168
169 if (pAreaLinks)
170 pAreaLinks->Restore( pDoc );
171
172 if ( pUnoRefs )
173 pUnoRefs->Undo( pDoc );
174}
175
176/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static std::unique_ptr< ScAreaLinkSaveCollection > CreateFromDoc(const ScDocument *pDoc)
Definition: areasave.cxx:147
bool empty() const
Definition: dbdata.cxx:1634
SC_DLLPUBLIC size_t GetCount() const
Definition: dpobject.cxx:3717
size_t Count() const
Definition: detdata.hxx:78
void CompileAll()
Definition: document.cxx:3963
void SetRangeName(SCTAB nTab, std::unique_ptr< ScRangeName > pNew)
Definition: documen3.cxx:185
ScDetOpList * GetDetOpList() const
Definition: document.hxx:1852
SC_DLLPUBLIC ScChartListenerCollection * GetChartListenerCollection() const
Definition: document.hxx:2233
void SetChartListenerCollection(std::unique_ptr< ScChartListenerCollection >, bool bSetChartRangeLists)
Definition: documen3.cxx:412
void RestorePrintRanges(const ScPrintRangeSaver &rSaver)
Definition: document.cxx:6331
void SetAllFormulasDirty(const sc::SetFormulaDirtyContext &rCxt)
Definition: document.cxx:3819
void SetDetOpList(std::unique_ptr< ScDetOpList > pNew)
Definition: documen4.cxx:905
bool HasUnoRefUndo() const
Definition: document.hxx:1090
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:827
SC_DLLPUBLIC ScRangeName * GetRangeName(SCTAB nTab) const
Definition: documen3.cxx:171
std::unique_ptr< ScPrintRangeSaver > CreatePrintRangeSaver() const
Definition: document.cxx:6321
void SetDBCollection(std::unique_ptr< ScDBCollection > pNewDBCollection, bool bRemoveAutoFilter=false)
Definition: documen3.cxx:275
SC_DLLPUBLIC ScDPCollection * GetDPCollection()
Definition: documen3.cxx:365
bool empty() const
Definition: rangenam.hxx:249
std::unique_ptr< ScRangeName > pRangeName
Definition: refundo.hxx:39
void DoUndo(ScDocument *pDoc, bool bUndoRefFirst)
Definition: refundo.cxx:135
std::unique_ptr< ScUnoRefList > pUnoRefs
Definition: refundo.hxx:45
std::unique_ptr< ScChartListenerCollection > pChartListenerCollection
Definition: refundo.hxx:43
ScRefUndoData(const ScDocument *pDoc)
Definition: refundo.cxx:33
void DeleteUnchanged(const ScDocument *pDoc)
Definition: refundo.cxx:74
std::unique_ptr< ScDPCollection > pDPCollection
Definition: refundo.hxx:41
std::unique_ptr< ScAreaLinkSaveCollection > pAreaLinks
Definition: refundo.hxx:44
std::unique_ptr< ScDetOpList > pDetOpList
Definition: refundo.hxx:42
std::unique_ptr< ScDBCollection > pDBCollection
Definition: refundo.hxx:38
std::unique_ptr< ScPrintRangeSaver > pPrintRanges
Definition: refundo.hxx:40
Temporarily switch on/off auto calculation mode.
Definition: scopetools.hxx:27