tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / filter / xml / XMLTrackedChangesContext.cxx
blob29d0ab99740d951d7aef28eb0964746e5f1131f0
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 <utility>
30 #include <xmloff/xmltoken.hxx>
31 #include <xmloff/xmlnamespace.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::XFastAttributeList> mxAttrList;
146 sal_Int32 mnElement;
147 OUStringBuffer sText;
148 ScXMLChangeCellContext* pChangeCellContext;
149 rtl::Reference<SvXMLImportContext>
150 pTextPContext;
152 public:
154 ScXMLChangeTextPContext( ScXMLImport& rImport, sal_Int32 nElement,
155 css::uno::Reference<css::xml::sax::XFastAttributeList> xAttrList,
156 ScXMLChangeCellContext* pChangeCellContext);
158 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
159 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
161 virtual void SAL_CALL characters( const OUString& rChars ) override;
163 virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
166 class ScXMLChangeCellContext : public ScXMLImportContext
168 ScCellValue& mrOldCell;
170 OUString sText;
171 OUString& rInputString;
172 rtl::Reference<ScEditEngineTextObj> mpEditTextObj;
173 double fValue;
174 sal_uInt16& rType;
175 bool bEmpty;
176 bool bFirstParagraph;
177 bool bString;
178 bool bFormula;
180 public:
181 ScXMLChangeCellContext( ScXMLImport& rImport,
182 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
183 ScCellValue& rOldCell, OUString& sAddress,
184 OUString& rFormula, OUString& rFormulaNmsp,
185 formula::FormulaGrammar::Grammar& rGrammar,
186 OUString& rInputString, double& fValue, sal_uInt16& nType,
187 ScMatrixMode& nMatrixFlag, sal_Int32& nMatrixCols, sal_Int32& nMatrixRows);
189 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
190 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
192 void CreateTextPContext(bool bIsNewParagraph);
193 bool IsEditCell() const { return mpEditTextObj.is(); }
194 void SetText(const OUString& sTempText) { sText = sTempText; }
196 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
199 class ScXMLPreviousContext : public ScXMLImportContext
201 OUString sFormulaAddress;
202 OUString sFormula;
203 OUString sFormulaNmsp;
204 OUString sInputString;
205 double fValue;
206 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
207 ScCellValue maOldCell;
208 sal_uInt32 nID;
209 sal_Int32 nMatrixCols;
210 sal_Int32 nMatrixRows;
211 formula::FormulaGrammar::Grammar eGrammar;
212 sal_uInt16 nType;
213 ScMatrixMode nMatrixFlag;
215 public:
216 ScXMLPreviousContext( ScXMLImport& rImport,
217 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
218 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
220 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
221 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
223 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
226 class ScXMLContentChangeContext : public ScXMLImportContext
228 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
229 ScBigRange aBigRange;
231 public:
232 ScXMLContentChangeContext( ScXMLImport& rImport,
233 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
234 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
236 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
237 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
239 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
242 class ScXMLInsertionContext : public ScXMLImportContext
244 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
246 public:
247 ScXMLInsertionContext( ScXMLImport& rImport,
248 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
249 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
251 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
252 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
254 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
257 class ScXMLInsertionCutOffContext : public ScXMLImportContext
259 public:
260 ScXMLInsertionCutOffContext( ScXMLImport& rImport,
261 const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList,
262 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
265 class ScXMLMovementCutOffContext : public ScXMLImportContext
267 public:
268 ScXMLMovementCutOffContext( ScXMLImport& rImport,
269 const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList,
270 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
273 class ScXMLCutOffsContext : public ScXMLImportContext
275 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
277 public:
278 ScXMLCutOffsContext( ScXMLImport& rImport,
279 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
281 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
282 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
285 class ScXMLDeletionContext : public ScXMLImportContext
287 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
289 public:
290 ScXMLDeletionContext( ScXMLImport& rImport,
291 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
292 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
294 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
295 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
297 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
300 class ScXMLMovementContext : public ScXMLImportContext
302 ScBigRange aSourceRange;
303 ScBigRange aTargetRange;
304 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
306 public:
307 ScXMLMovementContext( ScXMLImport& rImport,
308 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
309 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
311 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
312 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
314 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
317 class ScXMLRejectionContext : public ScXMLImportContext
319 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
321 public:
322 ScXMLRejectionContext( ScXMLImport& rImport,
323 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
324 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
326 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
327 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
329 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
334 ScXMLTrackedChangesContext::ScXMLTrackedChangesContext( ScXMLImport& rImport,
335 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
336 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
337 ScXMLImportContext( rImport ),
338 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
340 rImport.LockSolarMutex();
342 if ( !rAttrList.is() )
343 return;
345 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_PROTECTION_KEY ) ) );
346 if (aIter != rAttrList->end())
348 if( !aIter.isEmpty() )
350 uno::Sequence<sal_Int8> aPass;
351 ::comphelper::Base64::decode( aPass, aIter.toString() );
352 pChangeTrackingImportHelper->SetProtection(aPass);
357 ScXMLTrackedChangesContext::~ScXMLTrackedChangesContext()
359 GetScImport().UnlockSolarMutex();
362 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLTrackedChangesContext::createFastChildContext(
363 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
365 SvXMLImportContext *pContext(nullptr);
366 sax_fastparser::FastAttributeList *pAttribList =
367 &sax_fastparser::castToFastAttributeList( xAttrList );
369 switch (nElement)
371 case XML_ELEMENT( TABLE, XML_CELL_CONTENT_CHANGE ):
372 pContext = new ScXMLContentChangeContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
373 break;
374 case XML_ELEMENT( TABLE, XML_INSERTION ):
375 pContext = new ScXMLInsertionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
376 break;
377 case XML_ELEMENT( TABLE, XML_DELETION ):
378 pContext = new ScXMLDeletionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
379 break;
380 case XML_ELEMENT( TABLE, XML_MOVEMENT ):
381 pContext = new ScXMLMovementContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
382 break;
383 case XML_ELEMENT( TABLE, XML_REJECTION ):
384 pContext = new ScXMLRejectionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
385 break;
388 return pContext;
391 ScXMLChangeInfoContext::ScXMLChangeInfoContext( ScXMLImport& rImport,
392 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
393 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
394 ScXMLImportContext( rImport ),
395 aInfo(),
396 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper),
397 nParagraphCount(0)
399 if ( rAttrList.is() )
401 for (auto &aIter : *rAttrList)
403 sal_Int32 nToken = aIter.getToken();
404 if ( nToken == XML_ELEMENT( OFFICE, XML_CHG_AUTHOR ) )
405 sAuthorBuffer = aIter.toString();
406 else if ( nToken == XML_ELEMENT( OFFICE, XML_CHG_DATE_TIME ) )
407 sDateTimeBuffer = aIter.toString();
412 css::uno::Reference< css::xml::sax::XFastContextHandler > ScXMLChangeInfoContext::createFastChildContext(
413 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
415 SvXMLImportContext *pContext(nullptr);
417 if( nElement == XML_ELEMENT(DC, XML_CREATOR ) )
418 pContext = new ScXMLContentContext(GetScImport(), sAuthorBuffer);
419 else if( nElement == XML_ELEMENT(DC, XML_DATE ) )
420 pContext = new ScXMLContentContext(GetScImport(), sDateTimeBuffer);
421 else if (nElement == XML_ELEMENT(TEXT, XML_P))
423 if(nParagraphCount)
424 sCommentBuffer.append('\n');
425 ++nParagraphCount;
426 pContext = new ScXMLContentContext( GetScImport(), sCommentBuffer);
429 return pContext;
432 void SAL_CALL ScXMLChangeInfoContext::endFastElement( sal_Int32 /*nElement*/ )
434 aInfo.sUser = sAuthorBuffer.makeStringAndClear();
435 if (!::sax::Converter::parseDateTime(aInfo.aDateTime, sDateTimeBuffer))
436 SAL_WARN("sc.filter", "ScXMLChangeInfoContext: broken DateTime '" << sDateTimeBuffer.toString() << "'");
437 sDateTimeBuffer.setLength(0);
438 aInfo.sComment = sCommentBuffer.makeStringAndClear();
439 pChangeTrackingImportHelper->SetActionInfo(aInfo);
442 ScXMLBigRangeContext::ScXMLBigRangeContext( ScXMLImport& rImport,
443 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
444 ScBigRange& rBigRange ) :
445 ScXMLImportContext( rImport )
447 bool bColumn(false);
448 bool bRow(false);
449 bool bTable(false);
450 sal_Int32 nColumn(0);
451 sal_Int32 nRow(0);
452 sal_Int32 nTable(0);
453 sal_Int32 nStartColumn(0);
454 sal_Int32 nEndColumn(0);
455 sal_Int32 nStartRow(0);
456 sal_Int32 nEndRow(0);
457 sal_Int32 nStartTable(0);
458 sal_Int32 nEndTable(0);
459 if ( rAttrList.is() )
461 for (auto &aIter : *rAttrList)
463 switch (aIter.getToken())
465 case XML_ELEMENT( TABLE, XML_COLUMN ):
466 nColumn = aIter.toInt32();
467 bColumn = true;
468 break;
469 case XML_ELEMENT( TABLE, XML_ROW ):
470 nRow = aIter.toInt32();
471 bRow = true;
472 break;
473 case XML_ELEMENT( TABLE, XML_TABLE ):
474 nTable = aIter.toInt32();
475 bTable = true;
476 break;
477 case XML_ELEMENT( TABLE, XML_START_COLUMN ):
478 nStartColumn = aIter.toInt32();
479 break;
480 case XML_ELEMENT( TABLE, XML_END_COLUMN ):
481 nEndColumn = aIter.toInt32();
482 break;
483 case XML_ELEMENT( TABLE, XML_START_ROW ):
484 nStartRow = aIter.toInt32();
485 break;
486 case XML_ELEMENT( TABLE, XML_END_ROW ):
487 nEndRow = aIter.toInt32();
488 break;
489 case XML_ELEMENT( TABLE, XML_START_TABLE ):
490 nStartTable = aIter.toInt32();
491 break;
492 case XML_ELEMENT( TABLE, XML_END_TABLE ):
493 nEndTable = aIter.toInt32();
494 break;
499 if (bColumn)
500 nStartColumn = nEndColumn = nColumn;
501 if (bRow)
502 nStartRow = nEndRow = nRow;
503 if (bTable)
504 nStartTable = nEndTable = nTable;
505 rBigRange.Set(nStartColumn, nStartRow, nStartTable,
506 nEndColumn, nEndRow, nEndTable);
509 ScXMLCellContentDeletionContext::ScXMLCellContentDeletionContext( ScXMLImport& rImport,
510 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
511 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper) :
512 ScXMLImportContext( rImport ),
513 fValue(0.0),
514 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper),
515 nID(0),
516 nMatrixCols(0),
517 nMatrixRows(0),
518 eGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT),
519 nType(css::util::NumberFormat::ALL),
520 nMatrixFlag(ScMatrixMode::NONE)
522 if ( rAttrList.is() )
524 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_ID ) ) );
525 if (aIter != rAttrList->end())
526 nID = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
530 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellContentDeletionContext::createFastChildContext(
531 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
533 SvXMLImportContext *pContext(nullptr);
534 sax_fastparser::FastAttributeList *pAttribList =
535 &sax_fastparser::castToFastAttributeList( xAttrList );
537 switch (nElement)
539 case XML_ELEMENT( TABLE, XML_CHANGE_TRACK_TABLE_CELL ):
540 pContext = new ScXMLChangeCellContext(GetScImport(), pAttribList,
541 maCell, sFormulaAddress, sFormula, sFormulaNmsp, eGrammar, sInputString, fValue, nType, nMatrixFlag, nMatrixCols, nMatrixRows );
542 break;
543 case XML_ELEMENT( TABLE, XML_CELL_ADDRESS ):
544 OSL_ENSURE(!nID, "a action with a ID should not contain a BigRange");
545 pContext = new ScXMLBigRangeContext(GetScImport(), pAttribList, aBigRange);
546 break;
549 return pContext;
552 void SAL_CALL ScXMLCellContentDeletionContext::endFastElement( sal_Int32 /*nElement*/ )
554 std::unique_ptr<ScMyCellInfo> pCellInfo(new ScMyCellInfo(maCell, sFormulaAddress, sFormula, eGrammar, sInputString, fValue, nType,
555 nMatrixFlag, nMatrixCols, nMatrixRows));
556 if (nID)
557 pChangeTrackingImportHelper->AddDeleted(nID, std::move(pCellInfo));
558 else
559 pChangeTrackingImportHelper->AddGenerated(std::move(pCellInfo), aBigRange);
562 ScXMLDependenceContext::ScXMLDependenceContext( ScXMLImport& rImport,
563 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
564 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper ) :
565 ScXMLImportContext( rImport )
567 sal_uInt32 nID(0);
568 if ( rAttrList.is() )
570 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_ID ) ) );
571 if (aIter != rAttrList->end())
572 nID = ScXMLChangeTrackingImportHelper::GetIDFromString(aIter.toView());
574 pChangeTrackingImportHelper->AddDependence(nID);
577 ScXMLDependingsContext::ScXMLDependingsContext( ScXMLImport& rImport,
578 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
579 ScXMLImportContext( rImport ),
580 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
582 // here are no attributes
585 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDependingsContext::createFastChildContext(
586 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
588 SvXMLImportContext *pContext(nullptr);
589 sax_fastparser::FastAttributeList *pAttribList =
590 &sax_fastparser::castToFastAttributeList( xAttrList );
592 // #i80033# read both old (dependence) and new (dependency) elements
593 if (nElement == XML_ELEMENT( TABLE, XML_DEPENDENCE ) ||
594 nElement == XML_ELEMENT( TABLE, XML_DEPENDENCY ))
596 pContext = new ScXMLDependenceContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
599 return pContext;
602 ScXMLChangeDeletionContext::ScXMLChangeDeletionContext( ScXMLImport& rImport,
603 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
604 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper ) :
605 ScXMLImportContext( rImport )
607 sal_uInt32 nID(0);
608 if ( rAttrList.is() )
610 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_ID ) ) );
611 if (aIter != rAttrList->end())
612 nID = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
614 pChangeTrackingImportHelper->AddDeleted(nID);
617 ScXMLDeletionsContext::ScXMLDeletionsContext( ScXMLImport& rImport,
618 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
619 ScXMLImportContext( rImport ),
620 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
622 // here are no attributes
625 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDeletionsContext::createFastChildContext(
626 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
628 SvXMLImportContext *pContext(nullptr);
629 sax_fastparser::FastAttributeList *pAttribList =
630 &sax_fastparser::castToFastAttributeList( xAttrList );
632 switch (nElement)
634 case XML_ELEMENT( TABLE, XML_CHANGE_DELETION ):
635 pContext = new ScXMLChangeDeletionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
636 break;
637 case XML_ELEMENT( TABLE, XML_CELL_CONTENT_DELETION ):
638 pContext = new ScXMLCellContentDeletionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
639 break;
642 return pContext;
645 ScXMLChangeTextPContext::ScXMLChangeTextPContext( ScXMLImport& rImport,
646 sal_Int32 nElement,
647 css::uno::Reference<css::xml::sax::XFastAttributeList> xAttrList,
648 ScXMLChangeCellContext* pTempChangeCellContext) :
649 ScXMLImportContext( rImport ),
650 mxAttrList(std::move(xAttrList)),
651 mnElement(nElement),
652 pChangeCellContext(pTempChangeCellContext)
654 // here are no attributes
657 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLChangeTextPContext::createFastChildContext(
658 sal_Int32 nElement,
659 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
661 uno::Reference< xml::sax::XFastContextHandler > xContext;
662 if (IsTokenInNamespace(mnElement, XML_NAMESPACE_TEXT)
663 && (nElement & TOKEN_MASK) == XML_S
664 && !pTextPContext)
666 sal_Int32 nRepeat(0);
667 for( auto& aIter : sax_fastparser::castToFastAttributeList(mxAttrList) )
669 if (aIter.getToken() == XML_ELEMENT(TEXT, XML_C))
670 nRepeat = aIter.toInt32();
671 else
672 XMLOFF_WARN_UNKNOWN("sc", aIter);
674 if (nRepeat)
675 for (sal_Int32 j = 0; j < nRepeat; ++j)
676 sText.append(' ');
677 else
678 sText.append(' ');
680 else
682 if (!pChangeCellContext->IsEditCell())
683 pChangeCellContext->CreateTextPContext(false);
684 bool bWasContext (true);
685 if (!pTextPContext)
687 bWasContext = false;
688 pTextPContext = GetScImport().GetTextImport()->CreateTextChildContext(
689 GetScImport(), mnElement, mxAttrList);
691 if (pTextPContext)
693 if (!bWasContext)
694 pTextPContext->characters(sText.makeStringAndClear());
695 xContext = pTextPContext->createFastChildContext(nElement, xAttrList);
699 return xContext;
702 void ScXMLChangeTextPContext::characters( const OUString& rChars )
704 if (!pTextPContext)
705 sText.append(rChars);
706 else
707 pTextPContext->characters(rChars);
710 void ScXMLChangeTextPContext::endFastElement(sal_Int32 /*nElement*/)
712 if (!pTextPContext)
713 pChangeCellContext->SetText(sText.makeStringAndClear());
716 ScXMLChangeCellContext::ScXMLChangeCellContext( ScXMLImport& rImport,
717 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
718 ScCellValue& rOldCell, OUString& rAddress,
719 OUString& rFormula, OUString& rFormulaNmsp,
720 formula::FormulaGrammar::Grammar& rGrammar,
721 OUString& rTempInputString, double& rDateTimeValue, sal_uInt16& nType,
722 ScMatrixMode& nMatrixFlag, sal_Int32& nMatrixCols, sal_Int32& nMatrixRows )
723 : ScXMLImportContext( rImport )
724 , mrOldCell(rOldCell)
725 , rInputString(rTempInputString)
726 , fValue(0.0)
727 , rType(nType)
728 , bEmpty(true)
729 , bFirstParagraph(true)
730 , bString(true)
731 , bFormula(false)
733 bool bIsMatrix(false);
734 bool bIsCoveredMatrix(false);
735 if ( rAttrList.is() )
737 for (auto &aIter : *rAttrList)
739 switch (aIter.getToken())
741 case XML_ELEMENT( TABLE, XML_FORMULA ):
742 bEmpty = false;
743 GetScImport().ExtractFormulaNamespaceGrammar( rFormula, rFormulaNmsp, rGrammar, aIter.toString() );
744 bFormula = true;
745 break;
746 case XML_ELEMENT( TABLE, XML_CELL_ADDRESS ):
747 rAddress = aIter.toString();
748 break;
749 case XML_ELEMENT( TABLE, XML_MATRIX_COVERED ):
750 bIsCoveredMatrix = IsXMLToken(aIter, XML_TRUE);
751 break;
752 case XML_ELEMENT( TABLE, XML_NUMBER_MATRIX_COLUMNS_SPANNED ):
753 bIsMatrix = true;
754 nMatrixCols = aIter.toInt32();
755 break;
756 case XML_ELEMENT( TABLE, XML_NUMBER_MATRIX_ROWS_SPANNED ):
757 bIsMatrix = true;
758 nMatrixRows = aIter.toInt32();
759 break;
760 case XML_ELEMENT( OFFICE, XML_VALUE_TYPE ):
761 if (IsXMLToken(aIter, XML_FLOAT))
762 bString = false;
763 else if (IsXMLToken(aIter, XML_DATE))
765 rType = css::util::NumberFormat::DATE;
766 bString = false;
768 else if (IsXMLToken(aIter, XML_TIME))
770 rType = css::util::NumberFormat::TIME;
771 bString = false;
773 break;
774 case XML_ELEMENT( OFFICE, XML_VALUE ):
775 fValue = aIter.toDouble();
776 bEmpty = false;
777 break;
778 case XML_ELEMENT( OFFICE, XML_DATE_VALUE ):
779 bEmpty = false;
780 if (GetScImport().GetMM100UnitConverter().setNullDate(GetScImport().GetModel()))
781 GetScImport().GetMM100UnitConverter().convertDateTime(rDateTimeValue, aIter.toView());
782 fValue = rDateTimeValue;
783 break;
784 case XML_ELEMENT( OFFICE, XML_TIME_VALUE ):
785 bEmpty = false;
786 ::sax::Converter::convertDuration(rDateTimeValue, aIter.toView());
787 fValue = rDateTimeValue;
792 if (bIsCoveredMatrix)
793 nMatrixFlag = ScMatrixMode::Reference;
794 else if (bIsMatrix && nMatrixRows && nMatrixCols)
795 nMatrixFlag = ScMatrixMode::Formula;
798 uno::Reference< xml::sax::XFastContextHandler > ScXMLChangeCellContext::createFastChildContext(
799 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
801 SvXMLImportContext *pContext(nullptr);
803 if (nElement == XML_ELEMENT(TEXT, XML_P))
805 bEmpty = false;
806 if (bFirstParagraph)
808 pContext = new ScXMLChangeTextPContext(GetScImport(), nElement, xAttrList, this);
809 bFirstParagraph = false;
811 else
813 if (!mpEditTextObj.is())
814 CreateTextPContext(true);
815 pContext = GetScImport().GetTextImport()->CreateTextChildContext(
816 GetScImport(), nElement, xAttrList);
819 else
820 XMLOFF_WARN_UNKNOWN_ELEMENT("sc", nElement);
822 return pContext;
825 void ScXMLChangeCellContext::CreateTextPContext(bool bIsNewParagraph)
827 ScDocument* pDoc = GetScImport().GetDocument();
828 if (!pDoc)
829 return;
831 mpEditTextObj = new ScEditEngineTextObj();
832 mpEditTextObj->GetEditEngine()->SetEditTextObjectPool(pDoc->GetEditPool());
833 uno::Reference <text::XText> xText(mpEditTextObj);
834 if (xText.is())
836 uno::Reference<text::XTextCursor> xTextCursor(xText->createTextCursor());
837 if (bIsNewParagraph)
839 xText->setString(sText);
840 xTextCursor->gotoEnd(false);
841 xText->insertControlCharacter(xTextCursor, text::ControlCharacter::PARAGRAPH_BREAK, false);
843 GetScImport().GetTextImport()->SetCursor(xTextCursor);
847 void SAL_CALL ScXMLChangeCellContext::endFastElement( sal_Int32 /*nElement*/ )
849 if (!bEmpty)
851 if (mpEditTextObj.is())
853 if (GetImport().GetTextImport()->GetCursor().is())
855 //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
856 if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
858 GetImport().GetTextImport()->GetText()->insertString(
859 GetImport().GetTextImport()->GetCursorAsRange(), u""_ustr,
860 true );
864 // The cell will own the text object instance.
865 mrOldCell.set(mpEditTextObj->CreateTextObject());
866 GetScImport().GetTextImport()->ResetCursor();
867 mpEditTextObj.clear();
869 else
871 if (!bFormula)
873 if (!sText.isEmpty() && bString)
875 if (ScDocument* pDoc = GetScImport().GetDocument())
876 mrOldCell.set(pDoc->GetSharedStringPool().intern(sText));
878 else
880 mrOldCell.set(fValue);
882 if (rType == css::util::NumberFormat::DATE || rType == css::util::NumberFormat::TIME)
883 rInputString = sText;
887 else
888 mrOldCell.clear();
891 ScXMLPreviousContext::ScXMLPreviousContext( ScXMLImport& rImport,
892 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
893 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
894 ScXMLImportContext( rImport ),
895 fValue(0.0),
896 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper),
897 nID(0),
898 nMatrixCols(0),
899 nMatrixRows(0),
900 eGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT),
901 nType(css::util::NumberFormat::ALL),
902 nMatrixFlag(ScMatrixMode::NONE)
904 if ( rAttrList.is() )
906 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_ID ) ) );
907 if (aIter != rAttrList->end())
908 nID = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
912 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLPreviousContext::createFastChildContext(
913 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
915 SvXMLImportContext *pContext(nullptr);
916 sax_fastparser::FastAttributeList *pAttribList =
917 &sax_fastparser::castToFastAttributeList( xAttrList );
919 if ( nElement == XML_ELEMENT( TABLE, XML_CHANGE_TRACK_TABLE_CELL ) )
920 pContext = new ScXMLChangeCellContext(GetScImport(), pAttribList,
921 maOldCell, sFormulaAddress, sFormula, sFormulaNmsp, eGrammar, sInputString, fValue, nType, nMatrixFlag, nMatrixCols, nMatrixRows);
923 return pContext;
926 void SAL_CALL ScXMLPreviousContext::endFastElement( sal_Int32 /*nElement*/ )
928 pChangeTrackingImportHelper->SetPreviousChange(nID, new ScMyCellInfo(maOldCell, sFormulaAddress, sFormula, eGrammar, sInputString,
929 fValue, nType, nMatrixFlag, nMatrixCols, nMatrixRows));
932 ScXMLContentChangeContext::ScXMLContentChangeContext( ScXMLImport& rImport,
933 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
934 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
935 ScXMLImportContext( rImport ),
936 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
938 sal_uInt32 nActionNumber(0);
939 sal_uInt32 nRejectingNumber(0);
940 ScChangeActionState nActionState(SC_CAS_VIRGIN);
942 if ( rAttrList.is() )
944 for (auto &aIter : *rAttrList)
946 switch (aIter.getToken())
948 case XML_ELEMENT( TABLE, XML_ID ):
949 nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
950 break;
951 case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
952 if (IsXMLToken( aIter, XML_ACCEPTED ))
953 nActionState = SC_CAS_ACCEPTED;
954 else if (IsXMLToken( aIter, XML_REJECTED ))
955 nActionState = SC_CAS_REJECTED;
956 break;
957 case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
958 nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
963 pChangeTrackingImportHelper->StartChangeAction(SC_CAT_CONTENT);
964 pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
965 pChangeTrackingImportHelper->SetActionState(nActionState);
966 pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
969 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLContentChangeContext::createFastChildContext(
970 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
972 SvXMLImportContext *pContext(nullptr);
973 sax_fastparser::FastAttributeList *pAttribList =
974 &sax_fastparser::castToFastAttributeList( xAttrList );
976 switch (nElement)
978 case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
979 pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
980 break;
981 case XML_ELEMENT( TABLE, XML_CELL_ADDRESS ):
982 pContext = new ScXMLBigRangeContext(GetScImport(), pAttribList, aBigRange);
983 break;
984 case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
985 pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
986 break;
987 case XML_ELEMENT( TABLE, XML_DELETIONS ):
988 pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
989 break;
990 case XML_ELEMENT( TABLE, XML_PREVIOUS ):
991 pContext = new ScXMLPreviousContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
992 break;
995 return pContext;
998 void SAL_CALL ScXMLContentChangeContext::endFastElement( sal_Int32 /*nElement*/ )
1000 pChangeTrackingImportHelper->SetBigRange(aBigRange);
1001 pChangeTrackingImportHelper->EndChangeAction();
1004 ScXMLInsertionContext::ScXMLInsertionContext( ScXMLImport& rImport,
1005 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1006 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1007 ScXMLImportContext( rImport ),
1008 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1010 sal_uInt32 nActionNumber(0);
1011 sal_uInt32 nRejectingNumber(0);
1012 sal_Int32 nPosition(0);
1013 sal_Int32 nCount(1);
1014 sal_Int32 nTable(0);
1015 ScChangeActionState nActionState(SC_CAS_VIRGIN);
1016 ScChangeActionType nActionType(SC_CAT_INSERT_COLS);
1018 if ( rAttrList.is() )
1020 for (auto &aIter : *rAttrList)
1022 switch (aIter.getToken())
1024 case XML_ELEMENT( TABLE, XML_ID ):
1025 nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
1026 break;
1027 case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
1028 if (IsXMLToken( aIter, XML_ACCEPTED ))
1029 nActionState = SC_CAS_ACCEPTED;
1030 else if (IsXMLToken( aIter, XML_REJECTED ))
1031 nActionState = SC_CAS_REJECTED;
1032 break;
1033 case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
1034 nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
1035 break;
1036 case XML_ELEMENT( TABLE, XML_TYPE ):
1037 if (IsXMLToken( aIter, XML_ROW ))
1038 nActionType = SC_CAT_INSERT_ROWS;
1039 else if (IsXMLToken( aIter, XML_TABLE ))
1040 nActionType = SC_CAT_INSERT_TABS;
1041 break;
1042 case XML_ELEMENT( TABLE, XML_POSITION ):
1043 nPosition = aIter.toInt32();
1044 break;
1045 case XML_ELEMENT( TABLE, XML_TABLE ):
1046 nTable = aIter.toInt32();
1047 break;
1048 case XML_ELEMENT( TABLE, XML_COUNT ):
1049 nCount = aIter.toInt32();
1050 break;
1055 pChangeTrackingImportHelper->StartChangeAction(nActionType);
1056 pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1057 pChangeTrackingImportHelper->SetActionState(nActionState);
1058 pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1059 pChangeTrackingImportHelper->SetPosition(nPosition, nCount, nTable);
1062 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLInsertionContext::createFastChildContext(
1063 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1065 SvXMLImportContext *pContext(nullptr);
1066 sax_fastparser::FastAttributeList *pAttribList =
1067 &sax_fastparser::castToFastAttributeList( xAttrList );
1069 switch (nElement)
1071 case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
1072 pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1073 break;
1074 case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
1075 pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
1076 break;
1077 case XML_ELEMENT( TABLE, XML_DELETIONS ):
1078 pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1079 break;
1082 return pContext;
1085 void SAL_CALL ScXMLInsertionContext::endFastElement( sal_Int32 /*nElement*/ )
1087 pChangeTrackingImportHelper->EndChangeAction();
1090 ScXMLInsertionCutOffContext::ScXMLInsertionCutOffContext( ScXMLImport& rImport,
1091 const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
1092 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper ) :
1093 ScXMLImportContext( rImport )
1095 sal_uInt32 nID(0);
1096 sal_Int32 nPosition(0);
1097 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
1099 switch (aIter.getToken())
1101 case XML_ELEMENT(TABLE, XML_ID):
1102 nID = ScXMLChangeTrackingImportHelper::GetIDFromString(aIter.toView());
1103 break;
1104 case XML_ELEMENT(TABLE, XML_POSITION):
1105 ::sax::Converter::convertNumber(nPosition, aIter.toView());
1106 break;
1109 pChangeTrackingImportHelper->SetInsertionCutOff(nID, nPosition);
1113 ScXMLMovementCutOffContext::ScXMLMovementCutOffContext( ScXMLImport& rImport,
1114 const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
1115 ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper ) :
1116 ScXMLImportContext( rImport )
1118 sal_uInt32 nID(0);
1119 sal_Int32 nPosition(0);
1120 sal_Int32 nStartPosition(0);
1121 sal_Int32 nEndPosition(0);
1122 bool bPosition(false);
1123 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
1125 switch (aIter.getToken())
1127 case XML_ELEMENT(TABLE, XML_ID):
1128 nID = ScXMLChangeTrackingImportHelper::GetIDFromString(aIter.toView());
1129 break;
1130 case XML_ELEMENT(TABLE, XML_POSITION):
1131 bPosition = true;
1132 ::sax::Converter::convertNumber(nPosition, aIter.toView());
1133 break;
1134 case XML_ELEMENT(TABLE, XML_START_POSITION):
1135 ::sax::Converter::convertNumber(nStartPosition, aIter.toView());
1136 break;
1137 case XML_ELEMENT(TABLE, XML_END_POSITION):
1138 ::sax::Converter::convertNumber(nEndPosition, aIter.toView());
1139 break;
1142 if (bPosition)
1143 nStartPosition = nEndPosition = nPosition;
1144 pChangeTrackingImportHelper->AddMoveCutOff(nID, nStartPosition, nEndPosition);
1147 ScXMLCutOffsContext::ScXMLCutOffsContext( ScXMLImport& rImport,
1148 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1149 ScXMLImportContext( rImport ),
1150 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1152 // here are no attributes
1155 css::uno::Reference< css::xml::sax::XFastContextHandler > ScXMLCutOffsContext::createFastChildContext(
1156 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
1158 SvXMLImportContext *pContext(nullptr);
1160 if (nElement == XML_ELEMENT(TABLE, XML_INSERTION_CUT_OFF))
1161 pContext = new ScXMLInsertionCutOffContext(GetScImport(), xAttrList, pChangeTrackingImportHelper);
1162 else if (nElement == XML_ELEMENT(TABLE, XML_MOVEMENT_CUT_OFF))
1163 pContext = new ScXMLMovementCutOffContext(GetScImport(), xAttrList, pChangeTrackingImportHelper);
1165 return pContext;
1168 ScXMLDeletionContext::ScXMLDeletionContext( ScXMLImport& rImport,
1169 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1170 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1171 ScXMLImportContext( rImport ),
1172 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1174 sal_uInt32 nActionNumber(0);
1175 sal_uInt32 nRejectingNumber(0);
1176 sal_Int32 nPosition(0);
1177 sal_Int32 nMultiSpanned(0);
1178 sal_Int32 nTable(0);
1179 ScChangeActionState nActionState(SC_CAS_VIRGIN);
1180 ScChangeActionType nActionType(SC_CAT_DELETE_COLS);
1182 if ( rAttrList.is() )
1184 for (auto &aIter : *rAttrList)
1186 sal_Int32 nToken = aIter.getToken();
1187 switch (nToken)
1189 case XML_ELEMENT( TABLE, XML_ID ):
1190 nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
1191 break;
1192 case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
1193 if (IsXMLToken( aIter, XML_ACCEPTED ))
1194 nActionState = SC_CAS_ACCEPTED;
1195 else if (IsXMLToken( aIter, XML_REJECTED ))
1196 nActionState = SC_CAS_REJECTED;
1197 break;
1198 case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
1199 nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
1200 break;
1201 case XML_ELEMENT( TABLE, XML_TYPE ):
1202 if (IsXMLToken( aIter, XML_ROW ))
1203 nActionType = SC_CAT_DELETE_ROWS;
1204 else if (IsXMLToken( aIter, XML_TABLE ))
1205 nActionType = SC_CAT_DELETE_TABS;
1206 break;
1207 case XML_ELEMENT( TABLE, XML_POSITION ):
1208 nPosition = aIter.toInt32();
1209 break;
1210 case XML_ELEMENT( TABLE, XML_TABLE ):
1211 nTable = aIter.toInt32();
1212 break;
1213 case XML_ELEMENT( TABLE, XML_MULTI_DELETION_SPANNED ):
1214 nMultiSpanned = aIter.toInt32();
1215 break;
1220 pChangeTrackingImportHelper->StartChangeAction(nActionType);
1221 pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1222 pChangeTrackingImportHelper->SetActionState(nActionState);
1223 pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1224 pChangeTrackingImportHelper->SetPosition(nPosition, 1, nTable);
1225 pChangeTrackingImportHelper->SetMultiSpanned(static_cast<sal_Int16>(nMultiSpanned));
1228 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDeletionContext::createFastChildContext(
1229 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1231 SvXMLImportContext *pContext(nullptr);
1232 sax_fastparser::FastAttributeList *pAttribList =
1233 &sax_fastparser::castToFastAttributeList( xAttrList );
1235 switch (nElement)
1237 case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
1238 pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1239 break;
1240 case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
1241 pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
1242 break;
1243 case XML_ELEMENT( TABLE, XML_DELETIONS ):
1244 pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1245 break;
1246 case XML_ELEMENT( TABLE, XML_CUT_OFFS ):
1247 case XML_ELEMENT( TABLE, XML_CUT_OFFS2 ): // cut_offs
1248 pContext = new ScXMLCutOffsContext(GetScImport(), pChangeTrackingImportHelper);
1251 return pContext;
1254 void SAL_CALL ScXMLDeletionContext::endFastElement( sal_Int32 /*nElement*/ )
1256 pChangeTrackingImportHelper->EndChangeAction();
1259 ScXMLMovementContext::ScXMLMovementContext( ScXMLImport& rImport,
1260 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1261 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1262 ScXMLImportContext( rImport ),
1263 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1265 sal_uInt32 nActionNumber(0);
1266 sal_uInt32 nRejectingNumber(0);
1267 ScChangeActionState nActionState(SC_CAS_VIRGIN);
1269 if ( rAttrList.is() )
1271 for (auto &aIter : *rAttrList)
1273 switch (aIter.getToken())
1275 case XML_ELEMENT( TABLE, XML_ID ):
1276 nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
1277 break;
1278 case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
1279 if (IsXMLToken( aIter, XML_ACCEPTED ))
1280 nActionState = SC_CAS_ACCEPTED;
1281 else if (IsXMLToken( aIter, XML_REJECTED ))
1282 nActionState = SC_CAS_REJECTED;
1283 break;
1284 case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
1285 nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
1286 break;
1291 pChangeTrackingImportHelper->StartChangeAction(SC_CAT_MOVE);
1292 pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1293 pChangeTrackingImportHelper->SetActionState(nActionState);
1294 pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1297 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLMovementContext::createFastChildContext(
1298 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1300 SvXMLImportContext *pContext(nullptr);
1301 sax_fastparser::FastAttributeList *pAttribList =
1302 &sax_fastparser::castToFastAttributeList( xAttrList );
1304 switch (nElement)
1306 case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
1307 pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1308 break;
1309 case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
1310 pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
1311 break;
1312 case XML_ELEMENT( TABLE, XML_DELETIONS ):
1313 pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1314 break;
1315 case XML_ELEMENT( TABLE, XML_SOURCE_RANGE_ADDRESS ):
1316 pContext = new ScXMLBigRangeContext(GetScImport(), pAttribList, aSourceRange);
1317 break;
1318 case XML_ELEMENT( TABLE, XML_TARGET_RANGE_ADDRESS ):
1319 pContext = new ScXMLBigRangeContext(GetScImport(), pAttribList, aTargetRange);
1320 break;
1323 return pContext;
1326 void SAL_CALL ScXMLMovementContext::endFastElement( sal_Int32 /*nElement*/ )
1328 pChangeTrackingImportHelper->SetMoveRanges(aSourceRange, aTargetRange);
1329 pChangeTrackingImportHelper->EndChangeAction();
1332 ScXMLRejectionContext::ScXMLRejectionContext( ScXMLImport& rImport,
1333 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1334 ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1335 ScXMLImportContext( rImport ),
1336 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1338 sal_uInt32 nActionNumber(0);
1339 sal_uInt32 nRejectingNumber(0);
1340 ScChangeActionState nActionState(SC_CAS_VIRGIN);
1342 if ( rAttrList.is() )
1344 for (auto &aIter : *rAttrList)
1346 switch (aIter.getToken())
1348 case XML_ELEMENT( TABLE, XML_ID ):
1349 nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
1350 break;
1351 case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
1352 if (IsXMLToken( aIter, XML_ACCEPTED ))
1353 nActionState = SC_CAS_ACCEPTED;
1354 else if (IsXMLToken( aIter, XML_REJECTED ))
1355 nActionState = SC_CAS_REJECTED;
1356 break;
1357 case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
1358 nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
1359 break;
1364 pChangeTrackingImportHelper->StartChangeAction(SC_CAT_MOVE);
1365 pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1366 pChangeTrackingImportHelper->SetActionState(nActionState);
1367 pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1370 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLRejectionContext::createFastChildContext(
1371 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1373 SvXMLImportContext *pContext(nullptr);
1374 sax_fastparser::FastAttributeList *pAttribList =
1375 &sax_fastparser::castToFastAttributeList( xAttrList );
1377 switch (nElement)
1379 case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
1380 pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1381 break;
1382 case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
1383 pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
1384 break;
1385 case XML_ELEMENT( TABLE, XML_DELETIONS ):
1386 pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1387 break;
1390 return pContext;
1393 void SAL_CALL ScXMLRejectionContext::endFastElement( sal_Int32 /*nElement*/ )
1395 pChangeTrackingImportHelper->EndChangeAction();
1398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */