1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sc.hxx" 26 27 // ----------------------------------------------------------------------- 28 29 30 31 // INCLUDE --------------------------------------------------------------- 32 33 #include "refundo.hxx" 34 #include "undobase.hxx" 35 #include "document.hxx" 36 #include "dbcolect.hxx" 37 #include "rangenam.hxx" 38 #include "pivot.hxx" 39 #include "chartarr.hxx" 40 #include "stlpool.hxx" 41 #include "conditio.hxx" 42 #include "detdata.hxx" 43 #include "prnsave.hxx" 44 #include "chartlis.hxx" 45 #include "dpobject.hxx" 46 #include "areasave.hxx" 47 #include "unoreflist.hxx" 48 49 // ----------------------------------------------------------------------- 50 ScRefUndoData(const ScDocument * pDoc)51ScRefUndoData::ScRefUndoData( const ScDocument* pDoc ) : 52 pUnoRefs( NULL ) 53 { 54 ScDBCollection* pOldDBColl = pDoc->GetDBCollection(); 55 pDBCollection = pOldDBColl ? new ScDBCollection(*pOldDBColl) : NULL; 56 57 ScRangeName* pOldRanges = ((ScDocument*)pDoc)->GetRangeName(); //! const 58 pRangeName = pOldRanges ? new ScRangeName(*pOldRanges) : NULL; 59 60 pPrintRanges = pDoc->CreatePrintRangeSaver(); // neu erzeugt 61 62 //! bei Pivot nur Bereiche merken ??? 63 64 ScDPCollection* pOldDP = ((ScDocument*)pDoc)->GetDPCollection(); //! const 65 pDPCollection = pOldDP ? new ScDPCollection(*pOldDP) : NULL; 66 67 ScConditionalFormatList* pOldCond = pDoc->GetCondFormList(); 68 pCondFormList = pOldCond ? new ScConditionalFormatList(*pOldCond) : NULL; 69 70 ScDetOpList* pOldDetOp = pDoc->GetDetOpList(); 71 pDetOpList = pOldDetOp ? new ScDetOpList(*pOldDetOp) : 0; 72 73 ScChartListenerCollection* pOldChartListenerCollection = 74 pDoc->GetChartListenerCollection(); 75 pChartListenerCollection = pOldChartListenerCollection ? 76 new ScChartListenerCollection( *pOldChartListenerCollection ) : NULL; 77 78 pAreaLinks = ScAreaLinkSaveCollection::CreateFromDoc(pDoc); // returns NULL if empty 79 80 const_cast<ScDocument*>(pDoc)->BeginUnoRefUndo(); 81 } 82 ~ScRefUndoData()83ScRefUndoData::~ScRefUndoData() 84 { 85 delete pDBCollection; 86 delete pRangeName; 87 delete pPrintRanges; 88 delete pDPCollection; 89 delete pCondFormList; 90 delete pDetOpList; 91 delete pChartListenerCollection; 92 delete pAreaLinks; 93 delete pUnoRefs; 94 } 95 DeleteUnchanged(const ScDocument * pDoc)96void ScRefUndoData::DeleteUnchanged( const ScDocument* pDoc ) 97 { 98 if (pDBCollection) 99 { 100 ScDBCollection* pNewDBColl = pDoc->GetDBCollection(); 101 if ( pNewDBColl && *pDBCollection == *pNewDBColl ) 102 DELETEZ(pDBCollection); 103 } 104 if (pRangeName) 105 { 106 ScRangeName* pNewRanges = ((ScDocument*)pDoc)->GetRangeName(); //! const 107 if ( pNewRanges && *pRangeName == *pNewRanges ) 108 DELETEZ(pRangeName); 109 } 110 111 if (pPrintRanges) 112 { 113 ScPrintRangeSaver* pNewRanges = pDoc->CreatePrintRangeSaver(); 114 if ( pNewRanges && *pPrintRanges == *pNewRanges ) 115 DELETEZ(pPrintRanges); 116 delete pNewRanges; 117 } 118 119 if (pDPCollection) 120 { 121 ScDPCollection* pNewDP = ((ScDocument*)pDoc)->GetDPCollection(); //! const 122 if ( pNewDP && pDPCollection->RefsEqual(*pNewDP) ) 123 DELETEZ(pDPCollection); 124 } 125 126 if (pCondFormList) 127 { 128 ScConditionalFormatList* pNewCond = pDoc->GetCondFormList(); 129 if ( pNewCond && *pCondFormList == *pNewCond ) 130 DELETEZ(pCondFormList); 131 } 132 133 if (pDetOpList) 134 { 135 ScDetOpList* pNewDetOp = pDoc->GetDetOpList(); 136 if ( pNewDetOp && *pDetOpList == *pNewDetOp ) 137 DELETEZ(pDetOpList); 138 } 139 140 if ( pChartListenerCollection ) 141 { 142 ScChartListenerCollection* pNewChartListenerCollection = 143 pDoc->GetChartListenerCollection(); 144 if ( pNewChartListenerCollection && 145 *pChartListenerCollection == *pNewChartListenerCollection ) 146 DELETEZ( pChartListenerCollection ); 147 } 148 149 if (pAreaLinks) 150 { 151 if ( pAreaLinks->IsEqual( pDoc ) ) 152 DELETEZ(pAreaLinks); 153 } 154 155 if ( pDoc->HasUnoRefUndo() ) 156 { 157 pUnoRefs = const_cast<ScDocument*>(pDoc)->EndUnoRefUndo(); 158 if ( pUnoRefs && pUnoRefs->IsEmpty() ) 159 { 160 DELETEZ( pUnoRefs ); 161 } 162 } 163 } 164 DoUndo(ScDocument * pDoc,sal_Bool bUndoRefFirst)165void ScRefUndoData::DoUndo( ScDocument* pDoc, sal_Bool bUndoRefFirst ) 166 { 167 if (pDBCollection) 168 pDoc->SetDBCollection( new ScDBCollection(*pDBCollection) ); 169 if (pRangeName) 170 pDoc->SetRangeName( new ScRangeName(*pRangeName) ); 171 172 if (pPrintRanges) 173 pDoc->RestorePrintRanges(*pPrintRanges); 174 175 if (pDPCollection) 176 { 177 ScDPCollection* pDocDP = pDoc->GetDPCollection(); 178 if (pDocDP) 179 pDPCollection->WriteRefsTo( *pDocDP ); 180 } 181 182 if (pCondFormList) 183 pDoc->SetCondFormList( new ScConditionalFormatList(*pCondFormList) ); 184 if (pDetOpList) 185 pDoc->SetDetOpList( new ScDetOpList(*pDetOpList) ); 186 187 // #65055# bUndoRefFirst ist bSetChartRangeLists 188 if ( pChartListenerCollection ) 189 pDoc->SetChartListenerCollection( new ScChartListenerCollection( 190 *pChartListenerCollection ), bUndoRefFirst ); 191 192 if (pDBCollection || pRangeName) 193 { 194 sal_Bool bOldAutoCalc = pDoc->GetAutoCalc(); 195 pDoc->SetAutoCalc( sal_False ); // Mehrfachberechnungen vermeiden 196 pDoc->CompileAll(); 197 pDoc->SetDirty(); 198 pDoc->SetAutoCalc( bOldAutoCalc ); 199 } 200 201 if (pAreaLinks) 202 pAreaLinks->Restore( pDoc ); 203 204 if ( pUnoRefs ) 205 pUnoRefs->Undo( pDoc ); 206 } 207 208 209 210 211