nss: upgrade to release 3.73
[LibreOffice.git] / sc / source / filter / xml / XMLTrackedChangesContext.cxx
blob7a6f7a0a7e56d8ba1ad336af8d5d04e276225aca
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 <memory>
21 #include "XMLTrackedChangesContext.hxx"
22 #include "XMLChangeTrackingImportHelper.hxx"
23 #include "xmlimprt.hxx"
24 #include "xmlconti.hxx"
25 #include <formulacell.hxx>
26 #include <textuno.hxx>
27 #include <editutil.hxx>
28 #include <document.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/xmlnamespace.hxx>
31 #include <xmloff/namespacemap.hxx>
32 #include <xmloff/xmluconv.hxx>
33 #include <sax/tools/converter.hxx>
34 #include <svl/sharedstringpool.hxx>
35 #include <comphelper/base64.hxx>
36 #include <com/sun/star/text/XTextCursor.hpp>
37 #include <com/sun/star/text/ControlCharacter.hpp>
39 using namespace com::sun::star;
40 using namespace xmloff::token;
42 namespace {
44 class ScXMLChangeInfoContext : public ScXMLImportContext
46 ScMyActionInfo aInfo;
47 OUStringBuffer sAuthorBuffer{32};
48 OUStringBuffer sDateTimeBuffer{32};
49 OUStringBuffer sCommentBuffer{64};
50 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
51 sal_uInt32 nParagraphCount;
53 public:
54 ScXMLChangeInfoContext( ScXMLImport& rImport,
55 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
56 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
58 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
59 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
61 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
64 class ScXMLBigRangeContext : public ScXMLImportContext
66 public:
67 ScXMLBigRangeContext( ScXMLImport& rImport,
68 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
69 ScBigRange& rBigRange);
72 class ScXMLCellContentDeletionContext : public ScXMLImportContext
74 OUString sFormulaAddress;
75 OUString sFormula;
76 OUString sFormulaNmsp;
77 OUString sInputString;
78 ScBigRange aBigRange;
79 double fValue;
80 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
81 ScCellValue maCell;
82 sal_uInt32 nID;
83 sal_Int32 nMatrixCols;
84 sal_Int32 nMatrixRows;
85 formula::FormulaGrammar::Grammar eGrammar;
86 sal_uInt16 nType;
87 ScMatrixMode nMatrixFlag;
89 public:
90 ScXMLCellContentDeletionContext( ScXMLImport& rImport,
91 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
92 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
94 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
95 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
97 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
100 class ScXMLDependenceContext : public ScXMLImportContext
102 public:
103 ScXMLDependenceContext( ScXMLImport& rImport,
104 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
105 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
108 class ScXMLDependingsContext : public ScXMLImportContext
110 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
112 public:
113 ScXMLDependingsContext( ScXMLImport& rImport,
114 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
116 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
117 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
120 class ScXMLChangeDeletionContext : public ScXMLImportContext
122 public:
123 ScXMLChangeDeletionContext( ScXMLImport& rImport,
124 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
125 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
129 class ScXMLDeletionsContext : public ScXMLImportContext
131 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
133 public:
134 ScXMLDeletionsContext( ScXMLImport& rImport,
135 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
137 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
138 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
141 class ScXMLChangeCellContext;
143 class ScXMLChangeTextPContext : public ScXMLImportContext
145 css::uno::Reference< css::xml::sax::XAttributeList> xAttrList;
146 OUString sLName;
147 OUStringBuffer sText;
148 ScXMLChangeCellContext* pChangeCellContext;
149 rtl::Reference<SvXMLImportContext>
150 pTextPContext;
151 sal_uInt16 nPrefix;
153 public:
155 ScXMLChangeTextPContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
156 const OUString& rLName,
157 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList,
158 ScXMLChangeCellContext* pChangeCellContext);
160 virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
161 const OUString& rLocalName,
162 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override;
164 virtual void SAL_CALL characters( const OUString& rChars ) override;
166 virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
169 class ScXMLChangeCellContext : public ScXMLImportContext
171 ScCellValue& mrOldCell;
173 OUString sText;
174 OUString& rInputString;
175 rtl::Reference<ScEditEngineTextObj> mpEditTextObj;
176 double fValue;
177 sal_uInt16& rType;
178 bool bEmpty;
179 bool bFirstParagraph;
180 bool bString;
181 bool bFormula;
183 public:
184 ScXMLChangeCellContext( ScXMLImport& rImport,
185 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
186 ScCellValue& rOldCell, OUString& sAddress,
187 OUString& rFormula, OUString& rFormulaNmsp,
188 formula::FormulaGrammar::Grammar& rGrammar,
189 OUString& rInputString, double& fValue, sal_uInt16& nType,
190 ScMatrixMode& nMatrixFlag, sal_Int32& nMatrixCols, sal_Int32& nMatrixRows);
192 virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
193 const OUString& rLocalName,
194 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override;
195 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
196 sal_Int32 /*nElement*/, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) override
197 { return nullptr; }
199 void CreateTextPContext(bool bIsNewParagraph);
200 bool IsEditCell() const { return mpEditTextObj.is(); }
201 void SetText(const OUString& sTempText) { sText = sTempText; }
203 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
206 class ScXMLPreviousContext : public ScXMLImportContext
208 OUString sFormulaAddress;
209 OUString sFormula;
210 OUString sFormulaNmsp;
211 OUString sInputString;
212 double fValue;
213 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
214 ScCellValue maOldCell;
215 sal_uInt32 nID;
216 sal_Int32 nMatrixCols;
217 sal_Int32 nMatrixRows;
218 formula::FormulaGrammar::Grammar eGrammar;
219 sal_uInt16 nType;
220 ScMatrixMode nMatrixFlag;
222 public:
223 ScXMLPreviousContext( ScXMLImport& rImport,
224 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
225 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
227 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
228 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
230 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
233 class ScXMLContentChangeContext : public ScXMLImportContext
235 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
236 ScBigRange aBigRange;
238 public:
239 ScXMLContentChangeContext( ScXMLImport& rImport,
240 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
241 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
243 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
244 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
246 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
249 class ScXMLInsertionContext : public ScXMLImportContext
251 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
253 public:
254 ScXMLInsertionContext( ScXMLImport& rImport,
255 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
256 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
258 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
259 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
261 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
264 class ScXMLInsertionCutOffContext : public ScXMLImportContext
266 public:
267 ScXMLInsertionCutOffContext( ScXMLImport& rImport,
268 const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList,
269 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
272 class ScXMLMovementCutOffContext : public ScXMLImportContext
274 public:
275 ScXMLMovementCutOffContext( ScXMLImport& rImport,
276 const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList,
277 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
280 class ScXMLCutOffsContext : public ScXMLImportContext
282 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
284 public:
285 ScXMLCutOffsContext( ScXMLImport& rImport,
286 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
288 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
289 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
292 class ScXMLDeletionContext : public ScXMLImportContext
294 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
296 public:
297 ScXMLDeletionContext( ScXMLImport& rImport,
298 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
299 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
301 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
302 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
304 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
307 class ScXMLMovementContext : public ScXMLImportContext
309 ScBigRange aSourceRange;
310 ScBigRange aTargetRange;
311 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
313 public:
314 ScXMLMovementContext( ScXMLImport& rImport,
315 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
316 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
318 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
319 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
321 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
324 class ScXMLRejectionContext : public ScXMLImportContext
326 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
328 public:
329 ScXMLRejectionContext( ScXMLImport& rImport,
330 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
331 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
333 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
334 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
336 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
341 ScXMLTrackedChangesContext::ScXMLTrackedChangesContext( ScXMLImport& rImport,
342 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
343 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
344 ScXMLImportContext( rImport ),
345 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
347 rImport.LockSolarMutex();
349 if ( !rAttrList.is() )
350 return;
352 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_PROTECTION_KEY ) ) );
353 if (aIter != rAttrList->end())
355 if( !aIter.isEmpty() )
357 uno::Sequence<sal_Int8> aPass;
358 ::comphelper::Base64::decode( aPass, aIter.toString() );
359 pChangeTrackingImportHelper->SetProtection(aPass);
364 ScXMLTrackedChangesContext::~ScXMLTrackedChangesContext()
366 GetScImport().UnlockSolarMutex();
369 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLTrackedChangesContext::createFastChildContext(
370 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
372 SvXMLImportContext *pContext(nullptr);
373 sax_fastparser::FastAttributeList *pAttribList =
374 &sax_fastparser::castToFastAttributeList( xAttrList );
376 switch (nElement)
378 case XML_ELEMENT( TABLE, XML_CELL_CONTENT_CHANGE ):
379 pContext = new ScXMLContentChangeContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
380 break;
381 case XML_ELEMENT( TABLE, XML_INSERTION ):
382 pContext = new ScXMLInsertionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
383 break;
384 case XML_ELEMENT( TABLE, XML_DELETION ):
385 pContext = new ScXMLDeletionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
386 break;
387 case XML_ELEMENT( TABLE, XML_MOVEMENT ):
388 pContext = new ScXMLMovementContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
389 break;
390 case XML_ELEMENT( TABLE, XML_REJECTION ):
391 pContext = new ScXMLRejectionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
392 break;
395 return pContext;
398 ScXMLChangeInfoContext::ScXMLChangeInfoContext( ScXMLImport& rImport,
399 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
400 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
401 ScXMLImportContext( rImport ),
402 aInfo(),
403 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper),
404 nParagraphCount(0)
406 if ( rAttrList.is() )
408 for (auto &aIter : *rAttrList)
410 sal_Int32 nToken = aIter.getToken();
411 if ( nToken == XML_ELEMENT( OFFICE, XML_CHG_AUTHOR ) )
412 sAuthorBuffer = aIter.toString();
413 else if ( nToken == XML_ELEMENT( OFFICE, XML_CHG_DATE_TIME ) )
414 sDateTimeBuffer = aIter.toString();
419 css::uno::Reference< css::xml::sax::XFastContextHandler > ScXMLChangeInfoContext::createFastChildContext(
420 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
422 SvXMLImportContext *pContext(nullptr);
424 if( nElement == XML_ELEMENT(DC, XML_CREATOR ) )
425 pContext = new ScXMLContentContext(GetScImport(), sAuthorBuffer);
426 else if( nElement == XML_ELEMENT(DC, XML_DATE ) )
427 pContext = new ScXMLContentContext(GetScImport(), sDateTimeBuffer);
428 else if (nElement == XML_ELEMENT(TEXT, XML_P))
430 if(nParagraphCount)
431 sCommentBuffer.append('\n');
432 ++nParagraphCount;
433 pContext = new ScXMLContentContext( GetScImport(), sCommentBuffer);
436 return pContext;
439 void SAL_CALL ScXMLChangeInfoContext::endFastElement( sal_Int32 /*nElement*/ )
441 aInfo.sUser = sAuthorBuffer.makeStringAndClear();
442 ::sax::Converter::parseDateTime(aInfo.aDateTime,
443 sDateTimeBuffer.makeStringAndClear());
444 aInfo.sComment = sCommentBuffer.makeStringAndClear();
445 pChangeTrackingImportHelper->SetActionInfo(aInfo);
448 ScXMLBigRangeContext::ScXMLBigRangeContext( ScXMLImport& rImport,
449 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
450 ScBigRange& rBigRange ) :
451 ScXMLImportContext( rImport )
453 bool bColumn(false);
454 bool bRow(false);
455 bool bTable(false);
456 sal_Int32 nColumn(0);
457 sal_Int32 nRow(0);
458 sal_Int32 nTable(0);
459 sal_Int32 nStartColumn(0);
460 sal_Int32 nEndColumn(0);
461 sal_Int32 nStartRow(0);
462 sal_Int32 nEndRow(0);
463 sal_Int32 nStartTable(0);
464 sal_Int32 nEndTable(0);
465 if ( rAttrList.is() )
467 for (auto &aIter : *rAttrList)
469 switch (aIter.getToken())
471 case XML_ELEMENT( TABLE, XML_COLUMN ):
472 nColumn = aIter.toInt32();
473 bColumn = true;
474 break;
475 case XML_ELEMENT( TABLE, XML_ROW ):
476 nRow = aIter.toInt32();
477 bRow = true;
478 break;
479 case XML_ELEMENT( TABLE, XML_TABLE ):
480 nTable = aIter.toInt32();
481 bTable = true;
482 break;
483 case XML_ELEMENT( TABLE, XML_START_COLUMN ):
484 nStartColumn = aIter.toInt32();
485 break;
486 case XML_ELEMENT( TABLE, XML_END_COLUMN ):
487 nEndColumn = aIter.toInt32();
488 break;
489 case XML_ELEMENT( TABLE, XML_START_ROW ):
490 nStartRow = aIter.toInt32();
491 break;
492 case XML_ELEMENT( TABLE, XML_END_ROW ):
493 nEndRow = aIter.toInt32();
494 break;
495 case XML_ELEMENT( TABLE, XML_START_TABLE ):
496 nStartTable = aIter.toInt32();
497 break;
498 case XML_ELEMENT( TABLE, XML_END_TABLE ):
499 nEndTable = aIter.toInt32();
500 break;
505 if (bColumn)
506 nStartColumn = nEndColumn = nColumn;
507 if (bRow)
508 nStartRow = nEndRow = nRow;
509 if (bTable)
510 nStartTable = nEndTable = nTable;
511 rBigRange.Set(nStartColumn, nStartRow, nStartTable,
512 nEndColumn, nEndRow, nEndTable);
515 ScXMLCellContentDeletionContext::ScXMLCellContentDeletionContext( ScXMLImport& rImport,
516 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
517 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper) :
518 ScXMLImportContext( rImport ),
519 fValue(0.0),
520 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper),
521 nID(0),
522 nMatrixCols(0),
523 nMatrixRows(0),
524 eGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT),
525 nType(css::util::NumberFormat::ALL),
526 nMatrixFlag(ScMatrixMode::NONE)
528 if ( rAttrList.is() )
530 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_ID ) ) );
531 if (aIter != rAttrList->end())
532 nID = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
536 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellContentDeletionContext::createFastChildContext(
537 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
539 SvXMLImportContext *pContext(nullptr);
540 sax_fastparser::FastAttributeList *pAttribList =
541 &sax_fastparser::castToFastAttributeList( xAttrList );
543 switch (nElement)
545 case XML_ELEMENT( TABLE, XML_CHANGE_TRACK_TABLE_CELL ):
546 pContext = new ScXMLChangeCellContext(GetScImport(), pAttribList,
547 maCell, sFormulaAddress, sFormula, sFormulaNmsp, eGrammar, sInputString, fValue, nType, nMatrixFlag, nMatrixCols, nMatrixRows );
548 break;
549 case XML_ELEMENT( TABLE, XML_CELL_ADDRESS ):
550 OSL_ENSURE(!nID, "a action with a ID should not contain a BigRange");
551 pContext = new ScXMLBigRangeContext(GetScImport(), pAttribList, aBigRange);
552 break;
555 return pContext;
558 void SAL_CALL ScXMLCellContentDeletionContext::endFastElement( sal_Int32 /*nElement*/ )
560 std::unique_ptr<ScMyCellInfo> pCellInfo(new ScMyCellInfo(maCell, sFormulaAddress, sFormula, eGrammar, sInputString, fValue, nType,
561 nMatrixFlag, nMatrixCols, nMatrixRows));
562 if (nID)
563 pChangeTrackingImportHelper->AddDeleted(nID, std::move(pCellInfo));
564 else
565 pChangeTrackingImportHelper->AddGenerated(std::move(pCellInfo), aBigRange);
568 ScXMLDependenceContext::ScXMLDependenceContext( ScXMLImport& rImport,
569 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
570 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper ) :
571 ScXMLImportContext( rImport )
573 sal_uInt32 nID(0);
574 if ( rAttrList.is() )
576 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_ID ) ) );
577 if (aIter != rAttrList->end())
578 nID = ScXMLChangeTrackingImportHelper::GetIDFromString(aIter.toString());
580 pChangeTrackingImportHelper->AddDependence(nID);
583 ScXMLDependingsContext::ScXMLDependingsContext( ScXMLImport& rImport,
584 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
585 ScXMLImportContext( rImport ),
586 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
588 // here are no attributes
591 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDependingsContext::createFastChildContext(
592 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
594 SvXMLImportContext *pContext(nullptr);
595 sax_fastparser::FastAttributeList *pAttribList =
596 &sax_fastparser::castToFastAttributeList( xAttrList );
598 // #i80033# read both old (dependence) and new (dependency) elements
599 if (nElement == XML_ELEMENT( TABLE, XML_DEPENDENCE ) ||
600 nElement == XML_ELEMENT( TABLE, XML_DEPENDENCY ))
602 pContext = new ScXMLDependenceContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
605 return pContext;
608 ScXMLChangeDeletionContext::ScXMLChangeDeletionContext( ScXMLImport& rImport,
609 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
610 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper ) :
611 ScXMLImportContext( rImport )
613 sal_uInt32 nID(0);
614 if ( rAttrList.is() )
616 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_ID ) ) );
617 if (aIter != rAttrList->end())
618 nID = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
620 pChangeTrackingImportHelper->AddDeleted(nID);
623 ScXMLDeletionsContext::ScXMLDeletionsContext( ScXMLImport& rImport,
624 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
625 ScXMLImportContext( rImport ),
626 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
628 // here are no attributes
631 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDeletionsContext::createFastChildContext(
632 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
634 SvXMLImportContext *pContext(nullptr);
635 sax_fastparser::FastAttributeList *pAttribList =
636 &sax_fastparser::castToFastAttributeList( xAttrList );
638 switch (nElement)
640 case XML_ELEMENT( TABLE, XML_CHANGE_DELETION ):
641 pContext = new ScXMLChangeDeletionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
642 break;
643 case XML_ELEMENT( TABLE, XML_CELL_CONTENT_DELETION ):
644 pContext = new ScXMLCellContentDeletionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
645 break;
648 return pContext;
651 ScXMLChangeTextPContext::ScXMLChangeTextPContext( ScXMLImport& rImport,
652 sal_uInt16 nPrfx,
653 const OUString& rLName,
654 const css::uno::Reference<css::xml::sax::XAttributeList>& xTempAttrList,
655 ScXMLChangeCellContext* pTempChangeCellContext) :
656 ScXMLImportContext( rImport, nPrfx, rLName ),
657 xAttrList(xTempAttrList),
658 sLName(rLName),
659 sText(),
660 pChangeCellContext(pTempChangeCellContext),
661 nPrefix(nPrfx)
663 // here are no attributes
666 SvXMLImportContextRef ScXMLChangeTextPContext::CreateChildContext( sal_uInt16 nTempPrefix,
667 const OUString& rLName,
668 const css::uno::Reference<css::xml::sax::XAttributeList>& xTempAttrList )
670 SvXMLImportContextRef xContext;
672 if ((nPrefix == XML_NAMESPACE_TEXT) && (IsXMLToken(rLName, XML_S)) && !pTextPContext)
674 sal_Int32 nRepeat(0);
675 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
676 for( sal_Int16 i=0; i < nAttrCount; ++i )
678 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
679 const OUString& sValue(xAttrList->getValueByIndex( i ));
680 OUString aLocalName;
681 sal_uInt16 nPrfx(GetScImport().GetNamespaceMap().GetKeyByAttrName(
682 sAttrName, &aLocalName ));
683 if ((nPrfx == XML_NAMESPACE_TEXT) && (IsXMLToken(aLocalName, XML_C)))
684 nRepeat = sValue.toInt32();
686 if (nRepeat)
687 for (sal_Int32 j = 0; j < nRepeat; ++j)
688 sText.append(' ');
689 else
690 sText.append(' ');
692 else
694 if (!pChangeCellContext->IsEditCell())
695 pChangeCellContext->CreateTextPContext(false);
696 bool bWasContext (true);
697 if (!pTextPContext)
699 bWasContext = false;
700 pTextPContext= GetScImport().GetTextImport()->CreateTextChildContext(
701 GetScImport(), nPrefix, sLName, xAttrList);
703 if (pTextPContext)
705 if (!bWasContext)
706 pTextPContext->characters(sText.makeStringAndClear());
707 xContext = pTextPContext->CreateChildContext(nTempPrefix, rLName, xTempAttrList);
711 return xContext;
714 void ScXMLChangeTextPContext::characters( const OUString& rChars )
716 if (!pTextPContext)
717 sText.append(rChars);
718 else
719 pTextPContext->characters(rChars);
722 void ScXMLChangeTextPContext::endFastElement(sal_Int32 )
724 if (!pTextPContext)
725 pChangeCellContext->SetText(sText.makeStringAndClear());
728 ScXMLChangeCellContext::ScXMLChangeCellContext( ScXMLImport& rImport,
729 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
730 ScCellValue& rOldCell, OUString& rAddress,
731 OUString& rFormula, OUString& rFormulaNmsp,
732 formula::FormulaGrammar::Grammar& rGrammar,
733 OUString& rTempInputString, double& rDateTimeValue, sal_uInt16& nType,
734 ScMatrixMode& nMatrixFlag, sal_Int32& nMatrixCols, sal_Int32& nMatrixRows )
735 : ScXMLImportContext( rImport )
736 , mrOldCell(rOldCell)
737 , rInputString(rTempInputString)
738 , fValue(0.0)
739 , rType(nType)
740 , bEmpty(true)
741 , bFirstParagraph(true)
742 , bString(true)
743 , bFormula(false)
745 bool bIsMatrix(false);
746 bool bIsCoveredMatrix(false);
747 if ( rAttrList.is() )
749 for (auto &aIter : *rAttrList)
751 switch (aIter.getToken())
753 case XML_ELEMENT( TABLE, XML_FORMULA ):
754 bEmpty = false;
755 GetScImport().ExtractFormulaNamespaceGrammar( rFormula, rFormulaNmsp, rGrammar, aIter.toString() );
756 bFormula = true;
757 break;
758 case XML_ELEMENT( TABLE, XML_CELL_ADDRESS ):
759 rAddress = aIter.toString();
760 break;
761 case XML_ELEMENT( TABLE, XML_MATRIX_COVERED ):
762 bIsCoveredMatrix = IsXMLToken(aIter, XML_TRUE);
763 break;
764 case XML_ELEMENT( TABLE, XML_NUMBER_MATRIX_COLUMNS_SPANNED ):
765 bIsMatrix = true;
766 nMatrixCols = aIter.toInt32();
767 break;
768 case XML_ELEMENT( TABLE, XML_NUMBER_MATRIX_ROWS_SPANNED ):
769 bIsMatrix = true;
770 nMatrixRows = aIter.toInt32();
771 break;
772 case XML_ELEMENT( OFFICE, XML_VALUE_TYPE ):
773 if (IsXMLToken(aIter, XML_FLOAT))
774 bString = false;
775 else if (IsXMLToken(aIter, XML_DATE))
777 rType = css::util::NumberFormat::DATE;
778 bString = false;
780 else if (IsXMLToken(aIter, XML_TIME))
782 rType = css::util::NumberFormat::TIME;
783 bString = false;
785 break;
786 case XML_ELEMENT( OFFICE, XML_VALUE ):
787 fValue = aIter.toDouble();
788 bEmpty = false;
789 break;
790 case XML_ELEMENT( OFFICE, XML_DATE_VALUE ):
791 bEmpty = false;
792 if (GetScImport().GetMM100UnitConverter().setNullDate(GetScImport().GetModel()))
793 GetScImport().GetMM100UnitConverter().convertDateTime(rDateTimeValue, aIter.toString());
794 fValue = rDateTimeValue;
795 break;
796 case XML_ELEMENT( OFFICE, XML_TIME_VALUE ):
797 bEmpty = false;
798 ::sax::Converter::convertDuration(rDateTimeValue, aIter.toString());
799 fValue = rDateTimeValue;
804 if (bIsCoveredMatrix)
805 nMatrixFlag = ScMatrixMode::Reference;
806 else if (bIsMatrix && nMatrixRows && nMatrixCols)
807 nMatrixFlag = ScMatrixMode::Formula;
810 SvXMLImportContextRef ScXMLChangeCellContext::CreateChildContext( sal_uInt16 nPrefix,
811 const OUString& rLocalName,
812 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList )
814 SvXMLImportContext *pContext(nullptr);
816 if ((nPrefix == XML_NAMESPACE_TEXT) && (IsXMLToken(rLocalName, XML_P)))
818 bEmpty = false;
819 if (bFirstParagraph)
821 pContext = new ScXMLChangeTextPContext(GetScImport(), nPrefix, rLocalName, xAttrList, this);
822 bFirstParagraph = false;
824 else
826 if (!mpEditTextObj.is())
827 CreateTextPContext(true);
828 pContext = GetScImport().GetTextImport()->CreateTextChildContext(
829 GetScImport(), nPrefix, rLocalName, xAttrList);
833 return pContext;
836 void ScXMLChangeCellContext::CreateTextPContext(bool bIsNewParagraph)
838 if (!GetScImport().GetDocument())
839 return;
841 mpEditTextObj = new ScEditEngineTextObj();
842 mpEditTextObj->GetEditEngine()->SetEditTextObjectPool(GetScImport().GetDocument()->GetEditPool());
843 uno::Reference <text::XText> xText(mpEditTextObj.get());
844 if (xText.is())
846 uno::Reference<text::XTextCursor> xTextCursor(xText->createTextCursor());
847 if (bIsNewParagraph)
849 xText->setString(sText);
850 xTextCursor->gotoEnd(false);
851 xText->insertControlCharacter(xTextCursor, text::ControlCharacter::PARAGRAPH_BREAK, false);
853 GetScImport().GetTextImport()->SetCursor(xTextCursor);
857 void SAL_CALL ScXMLChangeCellContext::endFastElement( sal_Int32 /*nElement*/ )
859 if (!bEmpty)
861 ScDocument* pDoc = GetScImport().GetDocument();
862 if (mpEditTextObj.is())
864 if (GetImport().GetTextImport()->GetCursor().is())
866 //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
867 if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
869 GetImport().GetTextImport()->GetText()->insertString(
870 GetImport().GetTextImport()->GetCursorAsRange(), "",
871 true );
875 // The cell will own the text object instance.
876 mrOldCell.meType = CELLTYPE_EDIT;
877 mrOldCell.mpEditText = mpEditTextObj->CreateTextObject().release();
878 GetScImport().GetTextImport()->ResetCursor();
879 mpEditTextObj.clear();
881 else
883 if (!bFormula)
885 if (!sText.isEmpty() && bString)
887 mrOldCell.meType = CELLTYPE_STRING;
888 mrOldCell.mpString = new svl::SharedString(pDoc->GetSharedStringPool().intern(sText));
890 else
892 mrOldCell.meType = CELLTYPE_VALUE;
893 mrOldCell.mfValue = fValue;
895 if (rType == css::util::NumberFormat::DATE || rType == css::util::NumberFormat::TIME)
896 rInputString = sText;
900 else
901 mrOldCell.clear();
904 ScXMLPreviousContext::ScXMLPreviousContext( ScXMLImport& rImport,
905 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
906 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
907 ScXMLImportContext( rImport ),
908 fValue(0.0),
909 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper),
910 nID(0),
911 nMatrixCols(0),
912 nMatrixRows(0),
913 eGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT),
914 nType(css::util::NumberFormat::ALL),
915 nMatrixFlag(ScMatrixMode::NONE)
917 if ( rAttrList.is() )
919 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_ID ) ) );
920 if (aIter != rAttrList->end())
921 nID = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
925 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLPreviousContext::createFastChildContext(
926 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
928 SvXMLImportContext *pContext(nullptr);
929 sax_fastparser::FastAttributeList *pAttribList =
930 &sax_fastparser::castToFastAttributeList( xAttrList );
932 if ( nElement == XML_ELEMENT( TABLE, XML_CHANGE_TRACK_TABLE_CELL ) )
933 pContext = new ScXMLChangeCellContext(GetScImport(), pAttribList,
934 maOldCell, sFormulaAddress, sFormula, sFormulaNmsp, eGrammar, sInputString, fValue, nType, nMatrixFlag, nMatrixCols, nMatrixRows);
936 return pContext;
939 void SAL_CALL ScXMLPreviousContext::endFastElement( sal_Int32 /*nElement*/ )
941 pChangeTrackingImportHelper->SetPreviousChange(nID, new ScMyCellInfo(maOldCell, sFormulaAddress, sFormula, eGrammar, sInputString,
942 fValue, nType, nMatrixFlag, nMatrixCols, nMatrixRows));
945 ScXMLContentChangeContext::ScXMLContentChangeContext( ScXMLImport& rImport,
946 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
947 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
948 ScXMLImportContext( rImport ),
949 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
951 sal_uInt32 nActionNumber(0);
952 sal_uInt32 nRejectingNumber(0);
953 ScChangeActionState nActionState(SC_CAS_VIRGIN);
955 if ( rAttrList.is() )
957 for (auto &aIter : *rAttrList)
959 switch (aIter.getToken())
961 case XML_ELEMENT( TABLE, XML_ID ):
962 nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
963 break;
964 case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
965 if (IsXMLToken( aIter, XML_ACCEPTED ))
966 nActionState = SC_CAS_ACCEPTED;
967 else if (IsXMLToken( aIter, XML_REJECTED ))
968 nActionState = SC_CAS_REJECTED;
969 break;
970 case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
971 nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
976 pChangeTrackingImportHelper->StartChangeAction(SC_CAT_CONTENT);
977 pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
978 pChangeTrackingImportHelper->SetActionState(nActionState);
979 pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
982 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLContentChangeContext::createFastChildContext(
983 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
985 SvXMLImportContext *pContext(nullptr);
986 sax_fastparser::FastAttributeList *pAttribList =
987 &sax_fastparser::castToFastAttributeList( xAttrList );
989 switch (nElement)
991 case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
992 pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
993 break;
994 case XML_ELEMENT( TABLE, XML_CELL_ADDRESS ):
995 pContext = new ScXMLBigRangeContext(GetScImport(), pAttribList, aBigRange);
996 break;
997 case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
998 pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
999 break;
1000 case XML_ELEMENT( TABLE, XML_DELETIONS ):
1001 pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1002 break;
1003 case XML_ELEMENT( TABLE, XML_PREVIOUS ):
1004 pContext = new ScXMLPreviousContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1005 break;
1008 return pContext;
1011 void SAL_CALL ScXMLContentChangeContext::endFastElement( sal_Int32 /*nElement*/ )
1013 pChangeTrackingImportHelper->SetBigRange(aBigRange);
1014 pChangeTrackingImportHelper->EndChangeAction();
1017 ScXMLInsertionContext::ScXMLInsertionContext( ScXMLImport& rImport,
1018 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1019 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1020 ScXMLImportContext( rImport ),
1021 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1023 sal_uInt32 nActionNumber(0);
1024 sal_uInt32 nRejectingNumber(0);
1025 sal_Int32 nPosition(0);
1026 sal_Int32 nCount(1);
1027 sal_Int32 nTable(0);
1028 ScChangeActionState nActionState(SC_CAS_VIRGIN);
1029 ScChangeActionType nActionType(SC_CAT_INSERT_COLS);
1031 if ( rAttrList.is() )
1033 for (auto &aIter : *rAttrList)
1035 switch (aIter.getToken())
1037 case XML_ELEMENT( TABLE, XML_ID ):
1038 nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
1039 break;
1040 case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
1041 if (IsXMLToken( aIter, XML_ACCEPTED ))
1042 nActionState = SC_CAS_ACCEPTED;
1043 else if (IsXMLToken( aIter, XML_REJECTED ))
1044 nActionState = SC_CAS_REJECTED;
1045 break;
1046 case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
1047 nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
1048 break;
1049 case XML_ELEMENT( TABLE, XML_TYPE ):
1050 if (IsXMLToken( aIter, XML_ROW ))
1051 nActionType = SC_CAT_INSERT_ROWS;
1052 else if (IsXMLToken( aIter, XML_TABLE ))
1053 nActionType = SC_CAT_INSERT_TABS;
1054 break;
1055 case XML_ELEMENT( TABLE, XML_POSITION ):
1056 nPosition = aIter.toInt32();
1057 break;
1058 case XML_ELEMENT( TABLE, XML_TABLE ):
1059 nTable = aIter.toInt32();
1060 break;
1061 case XML_ELEMENT( TABLE, XML_COUNT ):
1062 nCount = aIter.toInt32();
1063 break;
1068 pChangeTrackingImportHelper->StartChangeAction(nActionType);
1069 pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1070 pChangeTrackingImportHelper->SetActionState(nActionState);
1071 pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1072 pChangeTrackingImportHelper->SetPosition(nPosition, nCount, nTable);
1075 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLInsertionContext::createFastChildContext(
1076 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1078 SvXMLImportContext *pContext(nullptr);
1079 sax_fastparser::FastAttributeList *pAttribList =
1080 &sax_fastparser::castToFastAttributeList( xAttrList );
1082 switch (nElement)
1084 case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
1085 pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1086 break;
1087 case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
1088 pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
1089 break;
1090 case XML_ELEMENT( TABLE, XML_DELETIONS ):
1091 pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1092 break;
1095 return pContext;
1098 void SAL_CALL ScXMLInsertionContext::endFastElement( sal_Int32 /*nElement*/ )
1100 pChangeTrackingImportHelper->EndChangeAction();
1103 ScXMLInsertionCutOffContext::ScXMLInsertionCutOffContext( ScXMLImport& rImport,
1104 const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
1105 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper ) :
1106 ScXMLImportContext( rImport )
1108 sal_uInt32 nID(0);
1109 sal_Int32 nPosition(0);
1110 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
1112 const OUString sValue = aIter.toString();
1114 switch (aIter.getToken())
1116 case XML_ELEMENT(TABLE, XML_ID):
1117 nID = ScXMLChangeTrackingImportHelper::GetIDFromString(sValue);
1118 break;
1119 case XML_ELEMENT(TABLE, XML_POSITION):
1120 ::sax::Converter::convertNumber(nPosition, sValue);
1121 break;
1124 pChangeTrackingImportHelper->SetInsertionCutOff(nID, nPosition);
1128 ScXMLMovementCutOffContext::ScXMLMovementCutOffContext( ScXMLImport& rImport,
1129 const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
1130 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper ) :
1131 ScXMLImportContext( rImport )
1133 sal_uInt32 nID(0);
1134 sal_Int32 nPosition(0);
1135 sal_Int32 nStartPosition(0);
1136 sal_Int32 nEndPosition(0);
1137 bool bPosition(false);
1138 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
1140 const OUString sValue = aIter.toString();
1142 switch (aIter.getToken())
1144 case XML_ELEMENT(TABLE, XML_ID):
1145 nID = ScXMLChangeTrackingImportHelper::GetIDFromString(sValue);
1146 break;
1147 case XML_ELEMENT(TABLE, XML_POSITION):
1148 bPosition = true;
1149 ::sax::Converter::convertNumber(nPosition, sValue);
1150 break;
1151 case XML_ELEMENT(TABLE, XML_START_POSITION):
1152 ::sax::Converter::convertNumber(nStartPosition, sValue);
1153 break;
1154 case XML_ELEMENT(TABLE, XML_END_POSITION):
1155 ::sax::Converter::convertNumber(nEndPosition, sValue);
1156 break;
1159 if (bPosition)
1160 nStartPosition = nEndPosition = nPosition;
1161 pChangeTrackingImportHelper->AddMoveCutOff(nID, nStartPosition, nEndPosition);
1164 ScXMLCutOffsContext::ScXMLCutOffsContext( ScXMLImport& rImport,
1165 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1166 ScXMLImportContext( rImport ),
1167 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1169 // here are no attributes
1172 css::uno::Reference< css::xml::sax::XFastContextHandler > ScXMLCutOffsContext::createFastChildContext(
1173 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
1175 SvXMLImportContext *pContext(nullptr);
1177 if (nElement == XML_ELEMENT(TABLE, XML_INSERTION_CUT_OFF))
1178 pContext = new ScXMLInsertionCutOffContext(GetScImport(), xAttrList, pChangeTrackingImportHelper);
1179 else if (nElement == XML_ELEMENT(TABLE, XML_MOVEMENT_CUT_OFF))
1180 pContext = new ScXMLMovementCutOffContext(GetScImport(), xAttrList, pChangeTrackingImportHelper);
1182 return pContext;
1185 ScXMLDeletionContext::ScXMLDeletionContext( ScXMLImport& rImport,
1186 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1187 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1188 ScXMLImportContext( rImport ),
1189 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1191 sal_uInt32 nActionNumber(0);
1192 sal_uInt32 nRejectingNumber(0);
1193 sal_Int32 nPosition(0);
1194 sal_Int32 nMultiSpanned(0);
1195 sal_Int32 nTable(0);
1196 ScChangeActionState nActionState(SC_CAS_VIRGIN);
1197 ScChangeActionType nActionType(SC_CAT_DELETE_COLS);
1199 if ( rAttrList.is() )
1201 for (auto &aIter : *rAttrList)
1203 sal_Int32 nToken = aIter.getToken();
1204 switch (nToken)
1206 case XML_ELEMENT( TABLE, XML_ID ):
1207 nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
1208 break;
1209 case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
1210 if (IsXMLToken( aIter, XML_ACCEPTED ))
1211 nActionState = SC_CAS_ACCEPTED;
1212 else if (IsXMLToken( aIter, XML_REJECTED ))
1213 nActionState = SC_CAS_REJECTED;
1214 break;
1215 case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
1216 nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
1217 break;
1218 case XML_ELEMENT( TABLE, XML_TYPE ):
1219 if (IsXMLToken( aIter, XML_ROW ))
1220 nActionType = SC_CAT_DELETE_ROWS;
1221 else if (IsXMLToken( aIter, XML_TABLE ))
1222 nActionType = SC_CAT_DELETE_TABS;
1223 break;
1224 case XML_ELEMENT( TABLE, XML_POSITION ):
1225 nPosition = aIter.toInt32();
1226 break;
1227 case XML_ELEMENT( TABLE, XML_TABLE ):
1228 nTable = aIter.toInt32();
1229 break;
1230 case XML_ELEMENT( TABLE, XML_MULTI_DELETION_SPANNED ):
1231 nMultiSpanned = aIter.toInt32();
1232 break;
1237 pChangeTrackingImportHelper->StartChangeAction(nActionType);
1238 pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1239 pChangeTrackingImportHelper->SetActionState(nActionState);
1240 pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1241 pChangeTrackingImportHelper->SetPosition(nPosition, 1, nTable);
1242 pChangeTrackingImportHelper->SetMultiSpanned(static_cast<sal_Int16>(nMultiSpanned));
1245 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDeletionContext::createFastChildContext(
1246 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1248 SvXMLImportContext *pContext(nullptr);
1249 sax_fastparser::FastAttributeList *pAttribList =
1250 &sax_fastparser::castToFastAttributeList( xAttrList );
1252 switch (nElement)
1254 case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
1255 pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1256 break;
1257 case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
1258 pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
1259 break;
1260 case XML_ELEMENT( TABLE, XML_DELETIONS ):
1261 pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1262 break;
1263 case XML_ELEMENT( TABLE, XML_CUT_OFFS ):
1264 case XML_ELEMENT( TABLE, XML_CUT_OFFS2 ): // cut_offs
1265 pContext = new ScXMLCutOffsContext(GetScImport(), pChangeTrackingImportHelper);
1268 return pContext;
1271 void SAL_CALL ScXMLDeletionContext::endFastElement( sal_Int32 /*nElement*/ )
1273 pChangeTrackingImportHelper->EndChangeAction();
1276 ScXMLMovementContext::ScXMLMovementContext( ScXMLImport& rImport,
1277 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1278 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1279 ScXMLImportContext( rImport ),
1280 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1282 sal_uInt32 nActionNumber(0);
1283 sal_uInt32 nRejectingNumber(0);
1284 ScChangeActionState nActionState(SC_CAS_VIRGIN);
1286 if ( rAttrList.is() )
1288 for (auto &aIter : *rAttrList)
1290 switch (aIter.getToken())
1292 case XML_ELEMENT( TABLE, XML_ID ):
1293 nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
1294 break;
1295 case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
1296 if (IsXMLToken( aIter, XML_ACCEPTED ))
1297 nActionState = SC_CAS_ACCEPTED;
1298 else if (IsXMLToken( aIter, XML_REJECTED ))
1299 nActionState = SC_CAS_REJECTED;
1300 break;
1301 case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
1302 nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
1303 break;
1308 pChangeTrackingImportHelper->StartChangeAction(SC_CAT_MOVE);
1309 pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1310 pChangeTrackingImportHelper->SetActionState(nActionState);
1311 pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1314 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLMovementContext::createFastChildContext(
1315 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1317 SvXMLImportContext *pContext(nullptr);
1318 sax_fastparser::FastAttributeList *pAttribList =
1319 &sax_fastparser::castToFastAttributeList( xAttrList );
1321 switch (nElement)
1323 case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
1324 pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1325 break;
1326 case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
1327 pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
1328 break;
1329 case XML_ELEMENT( TABLE, XML_DELETIONS ):
1330 pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1331 break;
1332 case XML_ELEMENT( TABLE, XML_SOURCE_RANGE_ADDRESS ):
1333 pContext = new ScXMLBigRangeContext(GetScImport(), pAttribList, aSourceRange);
1334 break;
1335 case XML_ELEMENT( TABLE, XML_TARGET_RANGE_ADDRESS ):
1336 pContext = new ScXMLBigRangeContext(GetScImport(), pAttribList, aTargetRange);
1337 break;
1340 return pContext;
1343 void SAL_CALL ScXMLMovementContext::endFastElement( sal_Int32 /*nElement*/ )
1345 pChangeTrackingImportHelper->SetMoveRanges(aSourceRange, aTargetRange);
1346 pChangeTrackingImportHelper->EndChangeAction();
1349 ScXMLRejectionContext::ScXMLRejectionContext( ScXMLImport& rImport,
1350 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1351 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1352 ScXMLImportContext( rImport ),
1353 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1355 sal_uInt32 nActionNumber(0);
1356 sal_uInt32 nRejectingNumber(0);
1357 ScChangeActionState nActionState(SC_CAS_VIRGIN);
1359 if ( rAttrList.is() )
1361 for (auto &aIter : *rAttrList)
1363 switch (aIter.getToken())
1365 case XML_ELEMENT( TABLE, XML_ID ):
1366 nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
1367 break;
1368 case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
1369 if (IsXMLToken( aIter, XML_ACCEPTED ))
1370 nActionState = SC_CAS_ACCEPTED;
1371 else if (IsXMLToken( aIter, XML_REJECTED ))
1372 nActionState = SC_CAS_REJECTED;
1373 break;
1374 case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
1375 nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
1376 break;
1381 pChangeTrackingImportHelper->StartChangeAction(SC_CAT_MOVE);
1382 pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1383 pChangeTrackingImportHelper->SetActionState(nActionState);
1384 pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1387 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLRejectionContext::createFastChildContext(
1388 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1390 SvXMLImportContext *pContext(nullptr);
1391 sax_fastparser::FastAttributeList *pAttribList =
1392 &sax_fastparser::castToFastAttributeList( xAttrList );
1394 switch (nElement)
1396 case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
1397 pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1398 break;
1399 case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
1400 pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
1401 break;
1402 case XML_ELEMENT( TABLE, XML_DELETIONS ):
1403 pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1404 break;
1407 return pContext;
1410 void SAL_CALL ScXMLRejectionContext::endFastElement( sal_Int32 /*nElement*/ )
1412 pChangeTrackingImportHelper->EndChangeAction();
1415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */