Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "XMLChangeTrackingImportHelper.hxx"
30 : : #include "XMLConverter.hxx"
31 : : #include "cell.hxx"
32 : : #include "document.hxx"
33 : : #include "chgviset.hxx"
34 : : #include "rangeutl.hxx"
35 : : #include <tools/datetime.hxx>
36 : : #include <svl/zforlist.hxx>
37 : : #include <sax/tools/converter.hxx>
38 : :
39 : : #define SC_CHANGE_ID_PREFIX "ct"
40 : :
41 : 0 : ScMyCellInfo::ScMyCellInfo(ScBaseCell* pTempCell, const rtl::OUString& rFormulaAddress, const rtl::OUString& rFormula,
42 : : const formula::FormulaGrammar::Grammar eTempGrammar, const rtl::OUString& rInputString,
43 : : const double& rValue, const sal_uInt16 nTempType, const sal_uInt8 nTempMatrixFlag, const sal_Int32 nTempMatrixCols,
44 : : const sal_Int32 nTempMatrixRows)
45 : : : pCell(pTempCell),
46 : : sFormulaAddress(rFormulaAddress),
47 : : sFormula(rFormula),
48 : : sInputString(rInputString),
49 : : fValue(rValue),
50 : : nMatrixCols(nTempMatrixCols),
51 : : nMatrixRows(nTempMatrixRows),
52 : : eGrammar( eTempGrammar),
53 : : nType(nTempType),
54 [ # # ]: 0 : nMatrixFlag(nTempMatrixFlag)
55 : : {
56 : 0 : }
57 : :
58 [ # # ]: 0 : ScMyCellInfo::~ScMyCellInfo()
59 : : {
60 [ # # ]: 0 : if (pCell)
61 [ # # ]: 0 : pCell->Delete();
62 : 0 : }
63 : :
64 : 0 : ScBaseCell* ScMyCellInfo::CreateCell(ScDocument* pDoc)
65 : : {
66 [ # # ][ # # ]: 0 : if (!pCell && !sFormula.isEmpty() && !sFormulaAddress.isEmpty())
[ # # ][ # # ]
67 : : {
68 : 0 : ScAddress aPos;
69 : 0 : sal_Int32 nOffset(0);
70 [ # # ]: 0 : ScRangeStringConverter::GetAddressFromString(aPos, sFormulaAddress, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset);
71 [ # # ][ # # ]: 0 : pCell = new ScFormulaCell(pDoc, aPos, sFormula, eGrammar, nMatrixFlag);
[ # # ]
72 [ # # ][ # # ]: 0 : static_cast<ScFormulaCell*>(pCell)->SetMatColsRows(static_cast<SCCOL>(nMatrixCols), static_cast<SCROW>(nMatrixRows));
73 : : }
74 : :
75 [ # # ][ # # ]: 0 : if ((nType == NUMBERFORMAT_DATE || nType == NUMBERFORMAT_TIME) && sInputString.Len() == 0)
[ # # ][ # # ]
76 : : {
77 : 0 : sal_uInt32 nFormat(0);
78 [ # # ]: 0 : if (nType == NUMBERFORMAT_DATE)
79 : 0 : nFormat = pDoc->GetFormatTable()->GetStandardFormat( NUMBERFORMAT_DATE, ScGlobal::eLnge );
80 [ # # ]: 0 : else if (nType == NUMBERFORMAT_TIME)
81 : 0 : nFormat = pDoc->GetFormatTable()->GetStandardFormat( NUMBERFORMAT_TIME, ScGlobal::eLnge );
82 : 0 : pDoc->GetFormatTable()->GetInputLineString(fValue, nFormat, sInputString);
83 : : }
84 : :
85 [ # # ]: 0 : return pCell ? pCell->Clone( *pDoc ) : 0;
86 : : }
87 : :
88 : 0 : ScMyDeleted::ScMyDeleted()
89 : 0 : : pCellInfo(NULL)
90 : : {
91 : 0 : }
92 : :
93 : 0 : ScMyDeleted::~ScMyDeleted()
94 : : {
95 [ # # ]: 0 : if (pCellInfo)
96 [ # # ]: 0 : delete pCellInfo;
97 : 0 : }
98 : :
99 : 0 : ScMyGenerated::ScMyGenerated(ScMyCellInfo* pTempCellInfo, const ScBigRange& aTempBigRange)
100 : : : aBigRange(aTempBigRange),
101 : : nID(0),
102 : 0 : pCellInfo(pTempCellInfo)
103 : : {
104 : 0 : }
105 : :
106 : 0 : ScMyGenerated::~ScMyGenerated()
107 : : {
108 [ # # ]: 0 : if (pCellInfo)
109 [ # # ]: 0 : delete pCellInfo;
110 : 0 : }
111 : :
112 : 0 : ScMyBaseAction::ScMyBaseAction(const ScChangeActionType nTempActionType)
113 : : : aDependencies(),
114 : : aDeletedList(),
115 : : nActionNumber(0),
116 : : nRejectingNumber(0),
117 : : nPreviousAction(0),
118 : : nActionType(nTempActionType),
119 [ # # ][ # # ]: 0 : nActionState(SC_CAS_VIRGIN)
120 : : {
121 : 0 : }
122 : :
123 : 0 : ScMyBaseAction::~ScMyBaseAction()
124 : : {
125 [ # # ]: 0 : }
126 : :
127 : 0 : ScMyInsAction::ScMyInsAction(const ScChangeActionType nActionTypeP)
128 : 0 : : ScMyBaseAction(nActionTypeP)
129 : : {
130 : 0 : }
131 : :
132 : 0 : ScMyInsAction::~ScMyInsAction()
133 : : {
134 [ # # ]: 0 : }
135 : :
136 : 0 : ScMyDelAction::ScMyDelAction(const ScChangeActionType nActionTypeP)
137 : : : ScMyBaseAction(nActionTypeP),
138 : : aGeneratedList(),
139 : : pInsCutOff(NULL),
140 : : aMoveCutOffs(),
141 [ # # ][ # # ]: 0 : nD(0)
142 : : {
143 : 0 : }
144 : :
145 : 0 : ScMyDelAction::~ScMyDelAction()
146 : : {
147 [ # # ]: 0 : if (pInsCutOff)
148 : 0 : delete pInsCutOff;
149 [ # # ]: 0 : }
150 : :
151 : 0 : ScMyMoveAction::ScMyMoveAction()
152 : : : ScMyBaseAction(SC_CAT_MOVE),
153 : : aGeneratedList(),
154 [ # # ]: 0 : pMoveRanges(NULL)
155 : : {
156 : 0 : }
157 : :
158 : 0 : ScMyMoveAction::~ScMyMoveAction()
159 : : {
160 [ # # ]: 0 : if (pMoveRanges)
161 : 0 : delete pMoveRanges;
162 [ # # ]: 0 : }
163 : :
164 : :
165 : 0 : ScMyContentAction::ScMyContentAction()
166 : : : ScMyBaseAction(SC_CAT_CONTENT),
167 : 0 : pCellInfo(NULL)
168 : : {
169 : 0 : }
170 : :
171 : 0 : ScMyContentAction::~ScMyContentAction()
172 : : {
173 [ # # ]: 0 : if (pCellInfo)
174 [ # # ][ # # ]: 0 : delete pCellInfo;
175 [ # # ]: 0 : }
176 : :
177 : 0 : ScMyRejAction::ScMyRejAction()
178 : 0 : : ScMyBaseAction(SC_CAT_REJECT)
179 : : {
180 : 0 : }
181 : :
182 : 0 : ScMyRejAction::~ScMyRejAction()
183 : : {
184 [ # # ]: 0 : }
185 : :
186 : 0 : ScXMLChangeTrackingImportHelper::ScXMLChangeTrackingImportHelper() :
187 : : aActions(),
188 : : pDoc(NULL),
189 : : pTrack(NULL),
190 : : pCurrentAction(NULL),
191 : : sIDPrefix(RTL_CONSTASCII_USTRINGPARAM(SC_CHANGE_ID_PREFIX)),
192 : : nMultiSpanned(0),
193 : : nMultiSpannedSlaveCount(0),
194 [ # # ][ # # ]: 0 : bChangeTrack(false)
[ # # ]
195 : : {
196 : 0 : nPrefixLength = sIDPrefix.getLength();
197 : 0 : }
198 : :
199 [ # # ]: 0 : ScXMLChangeTrackingImportHelper::~ScXMLChangeTrackingImportHelper()
200 : : {
201 : 0 : }
202 : :
203 : 0 : void ScXMLChangeTrackingImportHelper::StartChangeAction(const ScChangeActionType nActionType)
204 : : {
205 : : OSL_ENSURE(!pCurrentAction, "a not inserted action");
206 [ # # # # : 0 : switch (nActionType)
# # ]
207 : : {
208 : : case SC_CAT_INSERT_COLS:
209 : : case SC_CAT_INSERT_ROWS:
210 : : case SC_CAT_INSERT_TABS:
211 : : {
212 [ # # ]: 0 : pCurrentAction = new ScMyInsAction(nActionType);
213 : : }
214 : 0 : break;
215 : : case SC_CAT_DELETE_COLS:
216 : : case SC_CAT_DELETE_ROWS:
217 : : case SC_CAT_DELETE_TABS:
218 : : {
219 [ # # ]: 0 : pCurrentAction = new ScMyDelAction(nActionType);
220 : : }
221 : 0 : break;
222 : : case SC_CAT_MOVE:
223 : : {
224 [ # # ]: 0 : pCurrentAction = new ScMyMoveAction();
225 : : }
226 : 0 : break;
227 : : case SC_CAT_CONTENT:
228 : : {
229 [ # # ]: 0 : pCurrentAction = new ScMyContentAction();
230 : : }
231 : 0 : break;
232 : : case SC_CAT_REJECT:
233 : : {
234 [ # # ]: 0 : pCurrentAction = new ScMyRejAction();
235 : : }
236 : 0 : break;
237 : : default:
238 : : {
239 : : // added to avoid warnings
240 : : }
241 : : }
242 : 0 : }
243 : :
244 : 0 : sal_uInt32 ScXMLChangeTrackingImportHelper::GetIDFromString(const rtl::OUString& sID)
245 : : {
246 : 0 : sal_uInt32 nResult(0);
247 : 0 : sal_uInt32 nLength(sID.getLength());
248 [ # # ]: 0 : if (nLength)
249 : : {
250 [ # # ]: 0 : if (sID.compareTo(sIDPrefix, nPrefixLength) == 0)
251 : : {
252 : 0 : rtl::OUString sValue(sID.copy(nPrefixLength, nLength - nPrefixLength));
253 : : sal_Int32 nValue;
254 [ # # ]: 0 : ::sax::Converter::convertNumber(nValue, sValue);
255 : : OSL_ENSURE(nValue > 0, "wrong change action ID");
256 : 0 : nResult = nValue;
257 : : }
258 : : else
259 : : {
260 : : OSL_FAIL("wrong change action ID");
261 : : }
262 : : }
263 : 0 : return nResult;
264 : : }
265 : :
266 : 0 : void ScXMLChangeTrackingImportHelper::SetActionInfo(const ScMyActionInfo& aInfo)
267 : : {
268 : 0 : pCurrentAction->aInfo = aInfo;
269 : 0 : aUsers.insert(aInfo.sUser);
270 : 0 : }
271 : :
272 : 0 : void ScXMLChangeTrackingImportHelper::SetPreviousChange(const sal_uInt32 nPreviousAction,
273 : : ScMyCellInfo* pCellInfo)
274 : : {
275 : : OSL_ENSURE(pCurrentAction->nActionType == SC_CAT_CONTENT, "wrong action type");
276 : 0 : ScMyContentAction* pAction = static_cast<ScMyContentAction*>(pCurrentAction);
277 : 0 : pAction->nPreviousAction = nPreviousAction;
278 : 0 : pAction->pCellInfo = pCellInfo;
279 : 0 : }
280 : :
281 : 0 : void ScXMLChangeTrackingImportHelper::SetPosition(const sal_Int32 nPosition, const sal_Int32 nCount, const sal_Int32 nTable)
282 : : {
283 : : OSL_ENSURE(((pCurrentAction->nActionType != SC_CAT_MOVE) &&
284 : : (pCurrentAction->nActionType != SC_CAT_CONTENT) &&
285 : : (pCurrentAction->nActionType != SC_CAT_REJECT)), "wrong action type");
286 : : OSL_ENSURE(nCount > 0, "wrong count");
287 [ # # # # ]: 0 : switch(pCurrentAction->nActionType)
288 : : {
289 : : case SC_CAT_INSERT_COLS:
290 : : case SC_CAT_DELETE_COLS:
291 : : {
292 : : pCurrentAction->aBigRange.Set(nPosition, nInt32Min, nTable,
293 : 0 : nPosition + nCount - 1, nInt32Max, nTable);
294 : : }
295 : 0 : break;
296 : : case SC_CAT_INSERT_ROWS:
297 : : case SC_CAT_DELETE_ROWS:
298 : : {
299 : : pCurrentAction->aBigRange.Set(nInt32Min, nPosition, nTable,
300 : 0 : nInt32Max, nPosition + nCount - 1, nTable);
301 : : }
302 : 0 : break;
303 : : case SC_CAT_INSERT_TABS:
304 : : case SC_CAT_DELETE_TABS:
305 : : {
306 : : pCurrentAction->aBigRange.Set(nInt32Min, nInt32Min, nPosition,
307 : 0 : nInt32Max, nInt32Max, nPosition + nCount - 1);
308 : : }
309 : 0 : break;
310 : : default:
311 : : {
312 : : // added to avoid warnings
313 : : }
314 : : }
315 : 0 : }
316 : :
317 : 0 : void ScXMLChangeTrackingImportHelper::AddDeleted(const sal_uInt32 nID)
318 : : {
319 [ # # ]: 0 : ScMyDeleted* pDeleted = new ScMyDeleted();
320 : 0 : pDeleted->nID = nID;
321 [ # # ]: 0 : pCurrentAction->aDeletedList.push_front(pDeleted);
322 : 0 : }
323 : :
324 : 0 : void ScXMLChangeTrackingImportHelper::AddDeleted(const sal_uInt32 nID, ScMyCellInfo* pCellInfo)
325 : : {
326 [ # # ]: 0 : ScMyDeleted* pDeleted = new ScMyDeleted();
327 : 0 : pDeleted->nID = nID;
328 : 0 : pDeleted->pCellInfo = pCellInfo;
329 [ # # ]: 0 : pCurrentAction->aDeletedList.push_front(pDeleted);
330 : 0 : }
331 : :
332 : 0 : void ScXMLChangeTrackingImportHelper::SetMultiSpanned(const sal_Int16 nTempMultiSpanned)
333 : : {
334 [ # # ]: 0 : if (nTempMultiSpanned)
335 : : {
336 : : OSL_ENSURE(((pCurrentAction->nActionType == SC_CAT_DELETE_COLS) ||
337 : : (pCurrentAction->nActionType == SC_CAT_DELETE_ROWS)), "wrong action type");
338 : 0 : nMultiSpanned = nTempMultiSpanned;
339 : 0 : nMultiSpannedSlaveCount = 0;
340 : : }
341 : 0 : }
342 : :
343 : 0 : void ScXMLChangeTrackingImportHelper::SetInsertionCutOff(const sal_uInt32 nID, const sal_Int32 nPosition)
344 : : {
345 [ # # ][ # # ]: 0 : if ((pCurrentAction->nActionType == SC_CAT_DELETE_COLS) ||
346 : : (pCurrentAction->nActionType == SC_CAT_DELETE_ROWS))
347 : : {
348 : 0 : static_cast<ScMyDelAction*>(pCurrentAction)->pInsCutOff = new ScMyInsertionCutOff(nID, nPosition);
349 : : }
350 : : else
351 : : {
352 : : OSL_FAIL("wrong action type");
353 : : }
354 : 0 : }
355 : :
356 : 0 : void ScXMLChangeTrackingImportHelper::AddMoveCutOff(const sal_uInt32 nID, const sal_Int32 nStartPosition, const sal_Int32 nEndPosition)
357 : : {
358 [ # # ][ # # ]: 0 : if ((pCurrentAction->nActionType == SC_CAT_DELETE_COLS) ||
359 : : (pCurrentAction->nActionType == SC_CAT_DELETE_ROWS))
360 : : {
361 [ # # ]: 0 : static_cast<ScMyDelAction*>(pCurrentAction)->aMoveCutOffs.push_front(ScMyMoveCutOff(nID, nStartPosition, nEndPosition));
362 : : }
363 : : else
364 : : {
365 : : OSL_FAIL("wrong action type");
366 : : }
367 : 0 : }
368 : :
369 : 0 : void ScXMLChangeTrackingImportHelper::SetMoveRanges(const ScBigRange& aSourceRange, const ScBigRange& aTargetRange)
370 : : {
371 [ # # ]: 0 : if (pCurrentAction->nActionType == SC_CAT_MOVE)
372 : : {
373 [ # # ]: 0 : static_cast<ScMyMoveAction*>(pCurrentAction)->pMoveRanges = new ScMyMoveRanges(aSourceRange, aTargetRange);
374 : : }
375 : : else
376 : : {
377 : : OSL_FAIL("wrong action type");
378 : : }
379 : 0 : }
380 : :
381 : 0 : void ScXMLChangeTrackingImportHelper::GetMultiSpannedRange()
382 : : {
383 [ # # ][ # # ]: 0 : if ((pCurrentAction->nActionType == SC_CAT_DELETE_COLS) ||
384 : : (pCurrentAction->nActionType == SC_CAT_DELETE_ROWS))
385 : : {
386 [ # # ]: 0 : if (nMultiSpannedSlaveCount)
387 : : {
388 : 0 : static_cast<ScMyDelAction*>(pCurrentAction)->nD = nMultiSpannedSlaveCount;
389 : : }
390 : 0 : ++nMultiSpannedSlaveCount;
391 [ # # ]: 0 : if (nMultiSpannedSlaveCount >= nMultiSpanned)
392 : : {
393 : 0 : nMultiSpanned = 0;
394 : 0 : nMultiSpannedSlaveCount = 0;
395 : : }
396 : : }
397 : : else
398 : : {
399 : : OSL_FAIL("wrong action type");
400 : : }
401 : 0 : }
402 : :
403 : 0 : void ScXMLChangeTrackingImportHelper::AddGenerated(ScMyCellInfo* pCellInfo, const ScBigRange& aBigRange)
404 : : {
405 [ # # ]: 0 : ScMyGenerated* pGenerated = new ScMyGenerated(pCellInfo, aBigRange);
406 [ # # ]: 0 : if (pCurrentAction->nActionType == SC_CAT_MOVE)
407 : : {
408 [ # # ]: 0 : static_cast<ScMyMoveAction*>(pCurrentAction)->aGeneratedList.push_back(pGenerated);
409 : : }
410 [ # # ][ # # ]: 0 : else if ((pCurrentAction->nActionType == SC_CAT_DELETE_COLS) ||
411 : : (pCurrentAction->nActionType == SC_CAT_DELETE_ROWS))
412 : : {
413 [ # # ]: 0 : static_cast<ScMyDelAction*>(pCurrentAction)->aGeneratedList.push_back(pGenerated);
414 : : }
415 : : else
416 : : {
417 : : OSL_FAIL("try to insert a generated action to a wrong action");
418 : : }
419 : 0 : }
420 : :
421 : 0 : void ScXMLChangeTrackingImportHelper::EndChangeAction()
422 : : {
423 [ # # ][ # # ]: 0 : if ((pCurrentAction->nActionType == SC_CAT_DELETE_COLS) ||
424 : : (pCurrentAction->nActionType == SC_CAT_DELETE_ROWS))
425 : 0 : GetMultiSpannedRange();
426 [ # # ][ # # ]: 0 : if (pCurrentAction && pCurrentAction->nActionNumber > 0)
427 : 0 : aActions.push_back(pCurrentAction);
428 : : else
429 : : {
430 : : OSL_FAIL("no current action");
431 : : }
432 : 0 : pCurrentAction = NULL;
433 : 0 : }
434 : :
435 : 0 : void ScXMLChangeTrackingImportHelper::ConvertInfo(const ScMyActionInfo& aInfo, String& rUser, DateTime& aDateTime)
436 : : {
437 : 0 : Date aDate(aInfo.aDateTime.Day, aInfo.aDateTime.Month, aInfo.aDateTime.Year);
438 [ # # ]: 0 : Time aTime(aInfo.aDateTime.Hours, aInfo.aDateTime.Minutes, aInfo.aDateTime.Seconds, aInfo.aDateTime.HundredthSeconds);
439 : 0 : aDateTime.SetDate( aDate.GetDate() );
440 : 0 : aDateTime.SetTime( aTime.GetTime() );
441 : :
442 : : // old files didn't store 100th seconds, enable again
443 [ # # ]: 0 : if ( aInfo.aDateTime.HundredthSeconds )
444 : 0 : pTrack->SetTime100thSeconds( true );
445 : :
446 [ # # ]: 0 : const std::set<rtl::OUString>& rUsers = pTrack->GetUserCollection();
447 [ # # ]: 0 : std::set<rtl::OUString>::const_iterator it = rUsers.find(aInfo.sUser);
448 [ # # ]: 0 : if (it != rUsers.end())
449 : : {
450 : : // It's probably pointless to do this.
451 [ # # ]: 0 : rUser = *it;
452 : : }
453 : : else
454 [ # # ]: 0 : rUser = aInfo.sUser; // shouldn't happen
455 : 0 : }
456 : :
457 : 0 : ScChangeAction* ScXMLChangeTrackingImportHelper::CreateInsertAction(ScMyInsAction* pAction)
458 : : {
459 [ # # ]: 0 : DateTime aDateTime( Date(0), Time(0) );
460 [ # # ]: 0 : String aUser;
461 [ # # ]: 0 : ConvertInfo(pAction->aInfo, aUser, aDateTime);
462 : :
463 [ # # ]: 0 : String sComment (pAction->aInfo.sComment);
464 : :
465 : : ScChangeAction* pNewAction = new ScChangeActionIns(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
466 [ # # ][ # # ]: 0 : pAction->aBigRange, aUser, aDateTime, sComment, pAction->nActionType);
[ # # ][ # # ]
467 [ # # ][ # # ]: 0 : return pNewAction;
468 : : }
469 : :
470 : 0 : ScChangeAction* ScXMLChangeTrackingImportHelper::CreateDeleteAction(ScMyDelAction* pAction)
471 : : {
472 [ # # ]: 0 : DateTime aDateTime( Date(0), Time(0) );
473 [ # # ]: 0 : String aUser;
474 [ # # ]: 0 : ConvertInfo(pAction->aInfo, aUser, aDateTime);
475 : :
476 [ # # ]: 0 : String sComment (pAction->aInfo.sComment);
477 : :
478 : : ScChangeAction* pNewAction = new ScChangeActionDel(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
479 [ # # ][ # # ]: 0 : pAction->aBigRange, aUser, aDateTime, sComment, pAction->nActionType, pAction->nD, pTrack);
[ # # ][ # # ]
480 [ # # ][ # # ]: 0 : return pNewAction;
481 : : }
482 : :
483 : 0 : ScChangeAction* ScXMLChangeTrackingImportHelper::CreateMoveAction(ScMyMoveAction* pAction)
484 : : {
485 : : OSL_ENSURE(pAction->pMoveRanges, "no move ranges");
486 [ # # ]: 0 : if (pAction->pMoveRanges)
487 : : {
488 [ # # ]: 0 : DateTime aDateTime( Date(0), Time(0) );
489 [ # # ]: 0 : String aUser;
490 [ # # ]: 0 : ConvertInfo(pAction->aInfo, aUser, aDateTime);
491 : :
492 [ # # ]: 0 : String sComment (pAction->aInfo.sComment);
493 : :
494 : : ScChangeAction* pNewAction = new ScChangeActionMove(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
495 [ # # ][ # # ]: 0 : pAction->pMoveRanges->aTargetRange, aUser, aDateTime, sComment, pAction->pMoveRanges->aSourceRange , pTrack);
[ # # ][ # # ]
496 [ # # ][ # # ]: 0 : return pNewAction;
497 : : }
498 : 0 : return NULL;
499 : : }
500 : :
501 : 0 : ScChangeAction* ScXMLChangeTrackingImportHelper::CreateRejectionAction(ScMyRejAction* pAction)
502 : : {
503 [ # # ]: 0 : DateTime aDateTime( Date(0), Time(0) );
504 [ # # ]: 0 : String aUser;
505 [ # # ]: 0 : ConvertInfo(pAction->aInfo, aUser, aDateTime);
506 : :
507 [ # # ]: 0 : String sComment (pAction->aInfo.sComment);
508 : :
509 : : ScChangeAction* pNewAction = new ScChangeActionReject(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
510 [ # # ][ # # ]: 0 : pAction->aBigRange, aUser, aDateTime, sComment);
[ # # ][ # # ]
511 [ # # ][ # # ]: 0 : return pNewAction;
512 : : }
513 : :
514 : 0 : ScChangeAction* ScXMLChangeTrackingImportHelper::CreateContentAction(ScMyContentAction* pAction)
515 : : {
516 : 0 : ScBaseCell* pCell = NULL;
517 [ # # ]: 0 : if (pAction->pCellInfo)
518 [ # # ]: 0 : pCell = pAction->pCellInfo->CreateCell(pDoc);
519 : :
520 [ # # ]: 0 : DateTime aDateTime( Date(0), Time(0) );
521 [ # # ]: 0 : String aUser;
522 [ # # ]: 0 : ConvertInfo(pAction->aInfo, aUser, aDateTime);
523 : :
524 [ # # ]: 0 : String sComment (pAction->aInfo.sComment);
525 : :
526 : : ScChangeAction* pNewAction = new ScChangeActionContent(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
527 [ # # ][ # # ]: 0 : pAction->aBigRange, aUser, aDateTime, sComment, pCell, pDoc, pAction->pCellInfo->sInputString);
[ # # ][ # # ]
[ # # ]
528 [ # # ][ # # ]: 0 : return pNewAction;
529 : : }
530 : :
531 : 0 : void ScXMLChangeTrackingImportHelper::CreateGeneratedActions(ScMyGeneratedList& rList)
532 : : {
533 [ # # ]: 0 : if (!rList.empty())
534 : : {
535 : 0 : ScMyGeneratedList::iterator aItr(rList.begin());
536 : 0 : ScMyGeneratedList::iterator aEndItr(rList.end());
537 [ # # ]: 0 : while (aItr != aEndItr)
538 : : {
539 [ # # ]: 0 : if ((*aItr)->nID == 0)
540 : : {
541 : 0 : ScBaseCell* pCell = NULL;
542 [ # # ]: 0 : if ((*aItr)->pCellInfo)
543 [ # # ]: 0 : pCell = (*aItr)->pCellInfo->CreateCell(pDoc);
544 : :
545 [ # # ]: 0 : if (pCell)
546 : : {
547 [ # # ][ # # ]: 0 : (*aItr)->nID = pTrack->AddLoadedGenerated(pCell, (*aItr)->aBigRange, (*aItr)->pCellInfo->sInputString );
548 : : OSL_ENSURE((*aItr)->nID, "could not insert generated action");
549 : : }
550 : : }
551 : 0 : ++aItr;
552 : : }
553 : : }
554 : 0 : }
555 : :
556 : 0 : void ScXMLChangeTrackingImportHelper::SetDeletionDependencies(ScMyDelAction* pAction, ScChangeActionDel* pDelAct)
557 : : {
558 [ # # ]: 0 : if (!pAction->aGeneratedList.empty())
559 : : {
560 : : OSL_ENSURE(((pAction->nActionType == SC_CAT_DELETE_COLS) ||
561 : : (pAction->nActionType == SC_CAT_DELETE_ROWS) ||
562 : : (pAction->nActionType == SC_CAT_DELETE_TABS)), "wrong action type");
563 [ # # ]: 0 : if (pDelAct)
564 : : {
565 : 0 : ScMyGeneratedList::iterator aItr(pAction->aGeneratedList.begin());
566 : 0 : ScMyGeneratedList::iterator aEndItr(pAction->aGeneratedList.end());
567 [ # # ]: 0 : while (aItr != aEndItr)
568 : : {
569 : : OSL_ENSURE((*aItr)->nID, "a not inserted generated action");
570 [ # # ]: 0 : pDelAct->SetDeletedInThis((*aItr)->nID, pTrack);
571 [ # # ]: 0 : if (*aItr)
572 [ # # ][ # # ]: 0 : delete *aItr;
573 [ # # ]: 0 : aItr = pAction->aGeneratedList.erase(aItr);
574 : : }
575 : : }
576 : : }
577 [ # # ]: 0 : if (pAction->pInsCutOff)
578 : : {
579 : : OSL_ENSURE(((pAction->nActionType == SC_CAT_DELETE_COLS) ||
580 : : (pAction->nActionType == SC_CAT_DELETE_ROWS) ||
581 : : (pAction->nActionType == SC_CAT_DELETE_TABS)), "wrong action type");
582 : 0 : ScChangeAction* pChangeAction = pTrack->GetAction(pAction->pInsCutOff->nID);
583 [ # # ][ # # ]: 0 : if (pChangeAction && pChangeAction->IsInsertType())
[ # # ]
584 : : {
585 : 0 : ScChangeActionIns* pInsAction = static_cast<ScChangeActionIns*>(pChangeAction);
586 [ # # ][ # # ]: 0 : if (pInsAction && pDelAct)
587 : 0 : pDelAct->SetCutOffInsert(pInsAction, static_cast<sal_Int16>(pAction->pInsCutOff->nPosition));
588 : : }
589 : : else
590 : : {
591 : : OSL_FAIL("no cut off insert action");
592 : : }
593 : : }
594 [ # # ]: 0 : if (!pAction->aMoveCutOffs.empty())
595 : : {
596 : : OSL_ENSURE(((pAction->nActionType == SC_CAT_DELETE_COLS) ||
597 : : (pAction->nActionType == SC_CAT_DELETE_ROWS) ||
598 : : (pAction->nActionType == SC_CAT_DELETE_TABS)), "wrong action type");
599 : 0 : ScMyMoveCutOffs::iterator aItr(pAction->aMoveCutOffs.begin());
600 : 0 : ScMyMoveCutOffs::iterator aEndItr(pAction->aMoveCutOffs.end());
601 [ # # ]: 0 : while(aItr != aEndItr)
602 : : {
603 [ # # ]: 0 : ScChangeAction* pChangeAction = pTrack->GetAction(aItr->nID);
604 [ # # ][ # # ]: 0 : if (pChangeAction && (pChangeAction->GetType() == SC_CAT_MOVE))
[ # # ]
605 : : {
606 : 0 : ScChangeActionMove* pMoveAction = static_cast<ScChangeActionMove*>(pChangeAction);
607 [ # # ][ # # ]: 0 : if (pMoveAction && pDelAct)
608 : 0 : pDelAct->AddCutOffMove(pMoveAction, static_cast<sal_Int16>(aItr->nStartPosition),
609 [ # # ]: 0 : static_cast<sal_Int16>(aItr->nEndPosition));
610 : : }
611 : : else
612 : : {
613 : : OSL_FAIL("no cut off move action");
614 : : }
615 [ # # ]: 0 : aItr = pAction->aMoveCutOffs.erase(aItr);
616 : : }
617 : : }
618 : 0 : }
619 : :
620 : 0 : void ScXMLChangeTrackingImportHelper::SetMovementDependencies(ScMyMoveAction* pAction, ScChangeActionMove* pMoveAct)
621 : : {
622 [ # # ]: 0 : if (!pAction->aGeneratedList.empty())
623 : : {
624 [ # # ]: 0 : if (pAction->nActionType == SC_CAT_MOVE)
625 : : {
626 [ # # ]: 0 : if (pMoveAct)
627 : : {
628 : 0 : ScMyGeneratedList::iterator aItr(pAction->aGeneratedList.begin());
629 : 0 : ScMyGeneratedList::iterator aEndItr(pAction->aGeneratedList.end());
630 [ # # ]: 0 : while (aItr != aEndItr)
631 : : {
632 : : OSL_ENSURE((*aItr)->nID, "a not inserted generated action");
633 [ # # ]: 0 : pMoveAct->SetDeletedInThis((*aItr)->nID, pTrack);
634 [ # # ]: 0 : if (*aItr)
635 [ # # ][ # # ]: 0 : delete *aItr;
636 [ # # ]: 0 : aItr = pAction->aGeneratedList.erase(aItr);
637 : : }
638 : : }
639 : : }
640 : : }
641 : 0 : }
642 : :
643 : 0 : void ScXMLChangeTrackingImportHelper::SetContentDependencies(ScMyContentAction* pAction, ScChangeActionContent* pActContent)
644 : : {
645 [ # # ]: 0 : if (pAction->nPreviousAction)
646 : : {
647 : : OSL_ENSURE(pAction->nActionType == SC_CAT_CONTENT, "wrong action type");
648 : 0 : ScChangeAction* pPrevAct = pTrack->GetAction(pAction->nPreviousAction);
649 [ # # ]: 0 : if (pPrevAct)
650 : : {
651 : 0 : ScChangeActionContent* pPrevActContent = static_cast<ScChangeActionContent*>(pPrevAct);
652 [ # # ][ # # ]: 0 : if (pPrevActContent && pActContent)
653 : : {
654 : 0 : pActContent->SetPrevContent(pPrevActContent);
655 : 0 : pPrevActContent->SetNextContent(pActContent);
656 : 0 : const ScBaseCell* pOldCell = pActContent->GetOldCell();
657 [ # # ]: 0 : if (pOldCell)
658 : : {
659 : 0 : ScBaseCell* pNewCell = pOldCell->Clone( *pDoc );
660 [ # # ]: 0 : if (pNewCell)
661 : : {
662 [ # # ]: 0 : pPrevActContent->SetNewCell(pNewCell, pDoc, EMPTY_STRING);
663 : 0 : pPrevActContent->SetNewValue(pActContent->GetOldCell(), pDoc);
664 : : }
665 : : }
666 : : }
667 : : }
668 : : }
669 : 0 : }
670 : :
671 : 0 : void ScXMLChangeTrackingImportHelper::SetDependencies(ScMyBaseAction* pAction)
672 : : {
673 : 0 : ScChangeAction* pAct = pTrack->GetAction(pAction->nActionNumber);
674 [ # # ]: 0 : if (pAct)
675 : : {
676 [ # # ]: 0 : if (!pAction->aDependencies.empty())
677 : : {
678 : 0 : ScMyDependencies::iterator aItr(pAction->aDependencies.begin());
679 : 0 : ScMyDependencies::iterator aEndItr(pAction->aDependencies.end());
680 [ # # ][ # # ]: 0 : while(aItr != aEndItr)
681 : : {
682 [ # # ][ # # ]: 0 : pAct->AddDependent(*aItr, pTrack);
683 [ # # ]: 0 : aItr = pAction->aDependencies.erase(aItr);
684 : : }
685 : : }
686 [ # # ]: 0 : if (!pAction->aDeletedList.empty())
687 : : {
688 : 0 : ScMyDeletedList::iterator aItr(pAction->aDeletedList.begin());
689 : 0 : ScMyDeletedList::iterator aEndItr(pAction->aDeletedList.end());
690 [ # # ]: 0 : while(aItr != aEndItr)
691 : : {
692 [ # # ]: 0 : pAct->SetDeletedInThis((*aItr)->nID, pTrack);
693 [ # # ]: 0 : ScChangeAction* pDeletedAct = pTrack->GetAction((*aItr)->nID);
694 [ # # ][ # # ]: 0 : if ((pDeletedAct->GetType() == SC_CAT_CONTENT) && (*aItr)->pCellInfo)
[ # # ]
695 : : {
696 : 0 : ScChangeActionContent* pContentAct = static_cast<ScChangeActionContent*>(pDeletedAct);
697 [ # # ][ # # ]: 0 : if (pContentAct && (*aItr)->pCellInfo)
[ # # ]
698 : : {
699 [ # # ]: 0 : ScBaseCell* pCell = (*aItr)->pCellInfo->CreateCell(pDoc);
700 [ # # ][ # # ]: 0 : if (!ScBaseCell::CellEqual(pCell, pContentAct->GetNewCell()))
701 : : {
702 : : // #i40704# Don't overwrite SetNewCell result by calling SetNewValue,
703 : : // instead pass the input string to SetNewCell.
704 [ # # ][ # # ]: 0 : pContentAct->SetNewCell(pCell, pDoc, (*aItr)->pCellInfo->sInputString);
705 : : }
706 : : }
707 : : }
708 [ # # ]: 0 : if (*aItr)
709 [ # # ][ # # ]: 0 : delete *aItr;
710 [ # # ]: 0 : aItr = pAction->aDeletedList.erase(aItr);
711 : : }
712 : : }
713 [ # # ][ # # ]: 0 : if ((pAction->nActionType == SC_CAT_DELETE_COLS) ||
714 : : (pAction->nActionType == SC_CAT_DELETE_ROWS))
715 : 0 : SetDeletionDependencies(static_cast<ScMyDelAction*>(pAction), static_cast<ScChangeActionDel*>(pAct));
716 [ # # ]: 0 : else if (pAction->nActionType == SC_CAT_MOVE)
717 : 0 : SetMovementDependencies(static_cast<ScMyMoveAction*>(pAction), static_cast<ScChangeActionMove*>(pAct));
718 [ # # ]: 0 : else if (pAction->nActionType == SC_CAT_CONTENT)
719 : 0 : SetContentDependencies(static_cast<ScMyContentAction*>(pAction), static_cast<ScChangeActionContent*>(pAct));
720 : : }
721 : : else
722 : : {
723 : : OSL_FAIL("could not find the action");
724 : : }
725 : 0 : }
726 : :
727 : 0 : void ScXMLChangeTrackingImportHelper::SetNewCell(ScMyContentAction* pAction)
728 : : {
729 : 0 : ScChangeAction* pChangeAction = pTrack->GetAction(pAction->nActionNumber);
730 [ # # ]: 0 : if (pChangeAction)
731 : : {
732 : 0 : ScChangeActionContent* pChangeActionContent = static_cast<ScChangeActionContent*>(pChangeAction);
733 [ # # ]: 0 : if (pChangeActionContent)
734 : : {
735 [ # # ][ # # ]: 0 : if (pChangeActionContent->IsTopContent() && !pChangeActionContent->IsDeletedIn())
[ # # ]
736 : : {
737 : : sal_Int32 nCol, nRow, nTab, nCol2, nRow2, nTab2;
738 : 0 : pAction->aBigRange.GetVars(nCol, nRow, nTab, nCol2, nRow2, nTab2);
739 [ # # ][ # # ]: 0 : if ((nCol >= 0) && (nCol <= MAXCOL) &&
[ # # ][ # # ]
[ # # ][ # # ]
740 : : (nRow >= 0) && (nRow <= MAXROW) &&
741 : : (nTab >= 0) && (nTab <= MAXTAB))
742 : : {
743 : : ScAddress aAddress (static_cast<SCCOL>(nCol),
744 : : static_cast<SCROW>(nRow),
745 : 0 : static_cast<SCTAB>(nTab));
746 [ # # ]: 0 : ScBaseCell* pCell = pDoc->GetCell(aAddress);
747 [ # # ]: 0 : if (pCell)
748 : : {
749 : 0 : ScBaseCell* pNewCell = NULL;
750 [ # # ]: 0 : if (pCell->GetCellType() != CELLTYPE_FORMULA)
751 [ # # ]: 0 : pNewCell = pCell->Clone( *pDoc );
752 : : else
753 : : {
754 [ # # ]: 0 : sal_uInt8 nMatrixFlag = static_cast<ScFormulaCell*>(pCell)->GetMatrixFlag();
755 : 0 : rtl::OUString sFormula;
756 : : // With GRAM_ODFF reference detection is faster on compilation.
757 : : /* FIXME: new cell should be created with a clone
758 : : * of the token array instead. Any reason why this
759 : : * wasn't done? */
760 [ # # ][ # # ]: 0 : static_cast<ScFormulaCell*>(pCell)->GetFormula(sFormula,formula::FormulaGrammar::GRAM_ODFF);
761 : :
762 : : // #i87826# [Collaboration] Rejected move destroys formulas
763 : : // FIXME: adjust ScFormulaCell::GetFormula(), so that the right formula string
764 : : // is returned and no further string handling is necessary
765 : 0 : rtl::OUString sFormula2;
766 [ # # ]: 0 : if ( nMatrixFlag != MM_NONE )
767 : : {
768 : 0 : sFormula2 = sFormula.copy( 2, sFormula.getLength() - 3 );
769 : : }
770 : : else
771 : : {
772 : 0 : sFormula2 = sFormula.copy( 1, sFormula.getLength() - 1 );
773 : : }
774 : :
775 [ # # ][ # # ]: 0 : pNewCell = new ScFormulaCell(pDoc, aAddress, sFormula2,formula::FormulaGrammar::GRAM_ODFF, nMatrixFlag);
[ # # ]
776 [ # # ]: 0 : if (pNewCell)
777 : : {
778 [ # # ]: 0 : if (nMatrixFlag == MM_FORMULA)
779 : : {
780 : : SCCOL nCols;
781 : : SCROW nRows;
782 [ # # ][ # # ]: 0 : static_cast<ScFormulaCell*>(pCell)->GetMatColsRows(nCols, nRows);
783 [ # # ][ # # ]: 0 : static_cast<ScFormulaCell*>(pNewCell)->SetMatColsRows(nCols, nRows);
784 : : }
785 [ # # ]: 0 : static_cast<ScFormulaCell*>(pNewCell)->SetInChangeTrack(true);
786 : 0 : }
787 : : }
788 [ # # ][ # # ]: 0 : pChangeActionContent->SetNewCell(pNewCell, pDoc, EMPTY_STRING);
[ # # ]
789 : : // #i40704# don't overwrite the formula string from above with pCell's content
790 [ # # ]: 0 : if (pCell->GetCellType() != CELLTYPE_FORMULA)
791 [ # # ]: 0 : pChangeActionContent->SetNewValue(pCell, pDoc);
792 : : }
793 : : }
794 : : else
795 : : {
796 : : OSL_FAIL("wrong cell position");
797 : : }
798 : : }
799 : : }
800 : : }
801 : 0 : }
802 : :
803 : 0 : void ScXMLChangeTrackingImportHelper::CreateChangeTrack(ScDocument* pTempDoc)
804 : : {
805 : 0 : pDoc = pTempDoc;
806 [ # # ]: 0 : if (pDoc)
807 : : {
808 [ # # ][ # # ]: 0 : pTrack = new ScChangeTrack(pDoc, aUsers);
809 : : // old files didn't store 100th seconds, disable until encountered
810 : 0 : pTrack->SetTime100thSeconds( false );
811 : :
812 : 0 : ScMyActions::iterator aItr(aActions.begin());
813 : 0 : ScMyActions::iterator aEndItr(aActions.end());
814 [ # # ]: 0 : while (aItr != aEndItr)
815 : : {
816 : 0 : ScChangeAction* pAction = NULL;
817 : :
818 [ # # # # : 0 : switch ((*aItr)->nActionType)
# # ]
819 : : {
820 : : case SC_CAT_INSERT_COLS:
821 : : case SC_CAT_INSERT_ROWS:
822 : : case SC_CAT_INSERT_TABS:
823 : : {
824 [ # # ]: 0 : pAction = CreateInsertAction(static_cast<ScMyInsAction*>(*aItr));
825 : : }
826 : 0 : break;
827 : : case SC_CAT_DELETE_COLS:
828 : : case SC_CAT_DELETE_ROWS:
829 : : case SC_CAT_DELETE_TABS:
830 : : {
831 : 0 : ScMyDelAction* pDelAct = static_cast<ScMyDelAction*>(*aItr);
832 [ # # ]: 0 : pAction = CreateDeleteAction(pDelAct);
833 [ # # ]: 0 : CreateGeneratedActions(pDelAct->aGeneratedList);
834 : : }
835 : 0 : break;
836 : : case SC_CAT_MOVE:
837 : : {
838 : 0 : ScMyMoveAction* pMovAct = static_cast<ScMyMoveAction*>(*aItr);
839 [ # # ]: 0 : pAction = CreateMoveAction(pMovAct);
840 [ # # ]: 0 : CreateGeneratedActions(pMovAct->aGeneratedList);
841 : : }
842 : 0 : break;
843 : : case SC_CAT_CONTENT:
844 : : {
845 [ # # ]: 0 : pAction = CreateContentAction(static_cast<ScMyContentAction*>(*aItr));
846 : : }
847 : 0 : break;
848 : : case SC_CAT_REJECT:
849 : : {
850 [ # # ]: 0 : pAction = CreateRejectionAction(static_cast<ScMyRejAction*>(*aItr));
851 : : }
852 : 0 : break;
853 : : default:
854 : : {
855 : : // added to avoid warnings
856 : : }
857 : : }
858 : :
859 [ # # ]: 0 : if (pAction)
860 [ # # ]: 0 : pTrack->AppendLoaded(pAction);
861 : : else
862 : : {
863 : : OSL_FAIL("no action");
864 : : }
865 : :
866 : 0 : ++aItr;
867 : : }
868 [ # # ]: 0 : if (pTrack->GetLast())
869 : 0 : pTrack->SetActionMax(pTrack->GetLast()->GetActionNumber());
870 : :
871 : 0 : aItr = aActions.begin();
872 : 0 : aEndItr = aActions.end();
873 [ # # ]: 0 : while (aItr != aEndItr)
874 : : {
875 [ # # ]: 0 : SetDependencies(*aItr);
876 : :
877 [ # # ]: 0 : if ((*aItr)->nActionType == SC_CAT_CONTENT)
878 : 0 : ++aItr;
879 : : else
880 : : {
881 [ # # ]: 0 : if (*aItr)
882 [ # # ][ # # ]: 0 : delete (*aItr);
883 [ # # ]: 0 : aItr = aActions.erase(aItr);
884 : : }
885 : : }
886 : :
887 : 0 : aItr = aActions.begin();
888 : 0 : aEndItr = aActions.end();
889 [ # # ]: 0 : while (aItr != aEndItr)
890 : : {
891 : : OSL_ENSURE((*aItr)->nActionType == SC_CAT_CONTENT, "wrong action type");
892 [ # # ]: 0 : SetNewCell(static_cast<ScMyContentAction*>(*aItr));
893 [ # # ]: 0 : if (*aItr)
894 [ # # ][ # # ]: 0 : delete (*aItr);
895 [ # # ]: 0 : aItr = aActions.erase(aItr);
896 : : }
897 [ # # ]: 0 : if (aProtect.getLength())
898 [ # # ]: 0 : pTrack->SetProtection(aProtect);
899 [ # # ][ # # ]: 0 : else if (pDoc->GetChangeTrack() && pDoc->GetChangeTrack()->IsProtected())
[ # # ][ # # ]
900 [ # # ][ # # ]: 0 : pTrack->SetProtection(pDoc->GetChangeTrack()->GetProtection());
[ # # ]
901 : :
902 [ # # ]: 0 : if ( pTrack->GetLast() )
903 : 0 : pTrack->SetLastSavedActionNumber(pTrack->GetLast()->GetActionNumber());
904 : :
905 [ # # ]: 0 : pDoc->SetChangeTrack(pTrack);
906 : : }
907 : 0 : }
908 : :
909 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|