LibreOffice Module sc (master)  1
XMLTrackedChangesContext.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <memory>
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>
38 
39 using namespace com::sun::star;
40 using namespace xmloff::token;
41 
42 namespace {
43 
44 class ScXMLChangeInfoContext : public ScXMLImportContext
45 {
46  ScMyActionInfo aInfo;
47  OUStringBuffer sAuthorBuffer{32};
48  OUStringBuffer sDateTimeBuffer{32};
49  OUStringBuffer sCommentBuffer{64};
50  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
51  sal_uInt32 nParagraphCount;
52 
53 public:
54  ScXMLChangeInfoContext( ScXMLImport& rImport,
56  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
57 
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;
60 
61  virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
62 };
63 
64 class ScXMLBigRangeContext : public ScXMLImportContext
65 {
66 public:
67  ScXMLBigRangeContext( ScXMLImport& rImport,
69  ScBigRange& rBigRange);
70 };
71 
72 class ScXMLCellContentDeletionContext : public ScXMLImportContext
73 {
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;
86  sal_uInt16 nType;
87  ScMatrixMode nMatrixFlag;
88 
89 public:
90  ScXMLCellContentDeletionContext( ScXMLImport& rImport,
92  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
93 
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;
96 
97  virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
98 };
99 
100 class ScXMLDependenceContext : public ScXMLImportContext
101 {
102 public:
103  ScXMLDependenceContext( ScXMLImport& rImport,
105  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
106 };
107 
108 class ScXMLDependingsContext : public ScXMLImportContext
109 {
110  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
111 
112 public:
113  ScXMLDependingsContext( ScXMLImport& rImport,
114  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
115 
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;
118 };
119 
120 class ScXMLChangeDeletionContext : public ScXMLImportContext
121 {
122 public:
123  ScXMLChangeDeletionContext( ScXMLImport& rImport,
125  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
126 
127 };
128 
129 class ScXMLDeletionsContext : public ScXMLImportContext
130 {
131  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
132 
133 public:
134  ScXMLDeletionsContext( ScXMLImport& rImport,
135  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
136 
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;
139 };
140 
141 class ScXMLChangeCellContext;
142 
143 class ScXMLChangeTextPContext : public ScXMLImportContext
144 {
145  css::uno::Reference< css::xml::sax::XFastAttributeList> mxAttrList;
146  sal_Int32 mnElement;
147  OUStringBuffer sText;
148  ScXMLChangeCellContext* pChangeCellContext;
150  pTextPContext;
151 
152 public:
153 
154  ScXMLChangeTextPContext( ScXMLImport& rImport, sal_Int32 nElement,
155  const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList,
156  ScXMLChangeCellContext* pChangeCellContext);
157 
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;
160 
161  virtual void SAL_CALL characters( const OUString& rChars ) override;
162 
163  virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
164 };
165 
166 class ScXMLChangeCellContext : public ScXMLImportContext
167 {
168  ScCellValue& mrOldCell;
169 
170  OUString sText;
171  OUString& rInputString;
173  double fValue;
174  sal_uInt16& rType;
175  bool bEmpty;
176  bool bFirstParagraph;
177  bool bString;
178  bool bFormula;
179 
180 public:
181  ScXMLChangeCellContext( ScXMLImport& rImport,
183  ScCellValue& rOldCell, OUString& sAddress,
184  OUString& rFormula, OUString& rFormulaNmsp,
186  OUString& rInputString, double& fValue, sal_uInt16& nType,
187  ScMatrixMode& nMatrixFlag, sal_Int32& nMatrixCols, sal_Int32& nMatrixRows);
188 
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;
191 
192  void CreateTextPContext(bool bIsNewParagraph);
193  bool IsEditCell() const { return mpEditTextObj.is(); }
194  void SetText(const OUString& sTempText) { sText = sTempText; }
195 
196  virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
197 };
198 
199 class ScXMLPreviousContext : public ScXMLImportContext
200 {
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;
212  sal_uInt16 nType;
213  ScMatrixMode nMatrixFlag;
214 
215 public:
216  ScXMLPreviousContext( ScXMLImport& rImport,
218  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
219 
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;
222 
223  virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
224 };
225 
226 class ScXMLContentChangeContext : public ScXMLImportContext
227 {
228  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
229  ScBigRange aBigRange;
230 
231 public:
232  ScXMLContentChangeContext( ScXMLImport& rImport,
234  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
235 
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;
238 
239  virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
240 };
241 
242 class ScXMLInsertionContext : public ScXMLImportContext
243 {
244  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
245 
246 public:
247  ScXMLInsertionContext( ScXMLImport& rImport,
249  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
250 
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;
253 
254  virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
255 };
256 
257 class ScXMLInsertionCutOffContext : public ScXMLImportContext
258 {
259 public:
260  ScXMLInsertionCutOffContext( ScXMLImport& rImport,
261  const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList,
262  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
263 };
264 
265 class ScXMLMovementCutOffContext : public ScXMLImportContext
266 {
267 public:
268  ScXMLMovementCutOffContext( ScXMLImport& rImport,
269  const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList,
270  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
271 };
272 
273 class ScXMLCutOffsContext : public ScXMLImportContext
274 {
275  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
276 
277 public:
278  ScXMLCutOffsContext( ScXMLImport& rImport,
279  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
280 
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;
283 };
284 
285 class ScXMLDeletionContext : public ScXMLImportContext
286 {
287  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
288 
289 public:
290  ScXMLDeletionContext( ScXMLImport& rImport,
292  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
293 
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;
296 
297  virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
298 };
299 
300 class ScXMLMovementContext : public ScXMLImportContext
301 {
302  ScBigRange aSourceRange;
303  ScBigRange aTargetRange;
304  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
305 
306 public:
307  ScXMLMovementContext( ScXMLImport& rImport,
309  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
310 
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;
313 
314  virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
315 };
316 
317 class ScXMLRejectionContext : public ScXMLImportContext
318 {
319  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
320 
321 public:
322  ScXMLRejectionContext( ScXMLImport& rImport,
324  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
325 
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;
328 
329  virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
330 };
331 
332 }
333 
336  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
337  ScXMLImportContext( rImport ),
338  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
339 {
340  rImport.LockSolarMutex();
341 
342  if ( !rAttrList.is() )
343  return;
344 
345  auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_PROTECTION_KEY ) ) );
346  if (aIter != rAttrList->end())
347  {
348  if( !aIter.isEmpty() )
349  {
350  uno::Sequence<sal_Int8> aPass;
351  ::comphelper::Base64::decode( aPass, aIter.toString() );
353  }
354  }
355 }
356 
358 {
360 }
361 
362 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLTrackedChangesContext::createFastChildContext(
363  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
364 {
365  SvXMLImportContext *pContext(nullptr);
366  sax_fastparser::FastAttributeList *pAttribList =
368 
369  switch (nElement)
370  {
372  pContext = new ScXMLContentChangeContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
373  break;
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;
384  pContext = new ScXMLRejectionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
385  break;
386  }
387 
388  return pContext;
389 }
390 
391 ScXMLChangeInfoContext::ScXMLChangeInfoContext( ScXMLImport& rImport,
393  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
394  ScXMLImportContext( rImport ),
395  aInfo(),
396  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper),
397  nParagraphCount(0)
398 {
399  if ( rAttrList.is() )
400  {
401  for (auto &aIter : *rAttrList)
402  {
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();
408  }
409  }
410 }
411 
412 css::uno::Reference< css::xml::sax::XFastContextHandler > ScXMLChangeInfoContext::createFastChildContext(
413  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
414 {
415  SvXMLImportContext *pContext(nullptr);
416 
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))
422  {
423  if(nParagraphCount)
424  sCommentBuffer.append('\n');
425  ++nParagraphCount;
426  pContext = new ScXMLContentContext( GetScImport(), sCommentBuffer);
427  }
428 
429  return pContext;
430 }
431 
432 void SAL_CALL ScXMLChangeInfoContext::endFastElement( sal_Int32 /*nElement*/ )
433 {
434  aInfo.sUser = sAuthorBuffer.makeStringAndClear();
435  ::sax::Converter::parseDateTime(aInfo.aDateTime,
436  sDateTimeBuffer.makeStringAndClear());
437  aInfo.sComment = sCommentBuffer.makeStringAndClear();
438  pChangeTrackingImportHelper->SetActionInfo(aInfo);
439 }
440 
441 ScXMLBigRangeContext::ScXMLBigRangeContext( ScXMLImport& rImport,
443  ScBigRange& rBigRange ) :
444  ScXMLImportContext( rImport )
445 {
446  bool bColumn(false);
447  bool bRow(false);
448  bool bTable(false);
449  sal_Int32 nColumn(0);
450  sal_Int32 nRow(0);
451  sal_Int32 nTable(0);
452  sal_Int32 nStartColumn(0);
453  sal_Int32 nEndColumn(0);
454  sal_Int32 nStartRow(0);
455  sal_Int32 nEndRow(0);
456  sal_Int32 nStartTable(0);
457  sal_Int32 nEndTable(0);
458  if ( rAttrList.is() )
459  {
460  for (auto &aIter : *rAttrList)
461  {
462  switch (aIter.getToken())
463  {
464  case XML_ELEMENT( TABLE, XML_COLUMN ):
465  nColumn = aIter.toInt32();
466  bColumn = true;
467  break;
468  case XML_ELEMENT( TABLE, XML_ROW ):
469  nRow = aIter.toInt32();
470  bRow = true;
471  break;
472  case XML_ELEMENT( TABLE, XML_TABLE ):
473  nTable = aIter.toInt32();
474  bTable = true;
475  break;
476  case XML_ELEMENT( TABLE, XML_START_COLUMN ):
477  nStartColumn = aIter.toInt32();
478  break;
479  case XML_ELEMENT( TABLE, XML_END_COLUMN ):
480  nEndColumn = aIter.toInt32();
481  break;
482  case XML_ELEMENT( TABLE, XML_START_ROW ):
483  nStartRow = aIter.toInt32();
484  break;
485  case XML_ELEMENT( TABLE, XML_END_ROW ):
486  nEndRow = aIter.toInt32();
487  break;
488  case XML_ELEMENT( TABLE, XML_START_TABLE ):
489  nStartTable = aIter.toInt32();
490  break;
491  case XML_ELEMENT( TABLE, XML_END_TABLE ):
492  nEndTable = aIter.toInt32();
493  break;
494  }
495  }
496  }
497 
498  if (bColumn)
499  nStartColumn = nEndColumn = nColumn;
500  if (bRow)
501  nStartRow = nEndRow = nRow;
502  if (bTable)
503  nStartTable = nEndTable = nTable;
504  rBigRange.Set(nStartColumn, nStartRow, nStartTable,
505  nEndColumn, nEndRow, nEndTable);
506 }
507 
508 ScXMLCellContentDeletionContext::ScXMLCellContentDeletionContext( ScXMLImport& rImport,
510  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper) :
511  ScXMLImportContext( rImport ),
512  fValue(0.0),
513  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper),
514  nID(0),
515  nMatrixCols(0),
516  nMatrixRows(0),
517  eGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT),
518  nType(css::util::NumberFormat::ALL),
519  nMatrixFlag(ScMatrixMode::NONE)
520 {
521  if ( rAttrList.is() )
522  {
523  auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_ID ) ) );
524  if (aIter != rAttrList->end())
525  nID = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
526  }
527 }
528 
529 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellContentDeletionContext::createFastChildContext(
530  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
531 {
532  SvXMLImportContext *pContext(nullptr);
533  sax_fastparser::FastAttributeList *pAttribList =
535 
536  switch (nElement)
537  {
538  case XML_ELEMENT( TABLE, XML_CHANGE_TRACK_TABLE_CELL ):
539  pContext = new ScXMLChangeCellContext(GetScImport(), pAttribList,
540  maCell, sFormulaAddress, sFormula, sFormulaNmsp, eGrammar, sInputString, fValue, nType, nMatrixFlag, nMatrixCols, nMatrixRows );
541  break;
542  case XML_ELEMENT( TABLE, XML_CELL_ADDRESS ):
543  OSL_ENSURE(!nID, "a action with a ID should not contain a BigRange");
544  pContext = new ScXMLBigRangeContext(GetScImport(), pAttribList, aBigRange);
545  break;
546  }
547 
548  return pContext;
549 }
550 
551 void SAL_CALL ScXMLCellContentDeletionContext::endFastElement( sal_Int32 /*nElement*/ )
552 {
553  std::unique_ptr<ScMyCellInfo> pCellInfo(new ScMyCellInfo(maCell, sFormulaAddress, sFormula, eGrammar, sInputString, fValue, nType,
554  nMatrixFlag, nMatrixCols, nMatrixRows));
555  if (nID)
556  pChangeTrackingImportHelper->AddDeleted(nID, std::move(pCellInfo));
557  else
558  pChangeTrackingImportHelper->AddGenerated(std::move(pCellInfo), aBigRange);
559 }
560 
561 ScXMLDependenceContext::ScXMLDependenceContext( ScXMLImport& rImport,
563  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper ) :
564  ScXMLImportContext( rImport )
565 {
566  sal_uInt32 nID(0);
567  if ( rAttrList.is() )
568  {
569  auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_ID ) ) );
570  if (aIter != rAttrList->end())
572  }
573  pChangeTrackingImportHelper->AddDependence(nID);
574 }
575 
576 ScXMLDependingsContext::ScXMLDependingsContext( ScXMLImport& rImport,
577  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
578  ScXMLImportContext( rImport ),
579  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
580 {
581  // here are no attributes
582 }
583 
584 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDependingsContext::createFastChildContext(
585  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
586 {
587  SvXMLImportContext *pContext(nullptr);
588  sax_fastparser::FastAttributeList *pAttribList =
590 
591  // #i80033# read both old (dependence) and new (dependency) elements
592  if (nElement == XML_ELEMENT( TABLE, XML_DEPENDENCE ) ||
593  nElement == XML_ELEMENT( TABLE, XML_DEPENDENCY ))
594  {
595  pContext = new ScXMLDependenceContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
596  }
597 
598  return pContext;
599 }
600 
601 ScXMLChangeDeletionContext::ScXMLChangeDeletionContext( ScXMLImport& rImport,
603  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper ) :
604  ScXMLImportContext( rImport )
605 {
606  sal_uInt32 nID(0);
607  if ( rAttrList.is() )
608  {
609  auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_ID ) ) );
610  if (aIter != rAttrList->end())
611  nID = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
612  }
613  pChangeTrackingImportHelper->AddDeleted(nID);
614 }
615 
616 ScXMLDeletionsContext::ScXMLDeletionsContext( ScXMLImport& rImport,
617  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
618  ScXMLImportContext( rImport ),
619  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
620 {
621  // here are no attributes
622 }
623 
624 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDeletionsContext::createFastChildContext(
625  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
626 {
627  SvXMLImportContext *pContext(nullptr);
628  sax_fastparser::FastAttributeList *pAttribList =
630 
631  switch (nElement)
632  {
633  case XML_ELEMENT( TABLE, XML_CHANGE_DELETION ):
634  pContext = new ScXMLChangeDeletionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
635  break;
636  case XML_ELEMENT( TABLE, XML_CELL_CONTENT_DELETION ):
637  pContext = new ScXMLCellContentDeletionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
638  break;
639  }
640 
641  return pContext;
642 }
643 
644 ScXMLChangeTextPContext::ScXMLChangeTextPContext( ScXMLImport& rImport,
645  sal_Int32 nElement,
646  const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList,
647  ScXMLChangeCellContext* pTempChangeCellContext) :
648  ScXMLImportContext( rImport ),
649  mxAttrList(xAttrList),
650  mnElement(nElement),
651  sText(),
652  pChangeCellContext(pTempChangeCellContext)
653 {
654  // here are no attributes
655 }
656 
657 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLChangeTextPContext::createFastChildContext(
658  sal_Int32 nElement,
659  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
660 {
661  uno::Reference< xml::sax::XFastContextHandler > xContext;
662  if (IsTokenInNamespace(mnElement, XML_NAMESPACE_TEXT)
663  && (nElement & TOKEN_MASK) == XML_S
664  && !pTextPContext)
665  {
666  sal_Int32 nRepeat(0);
667  for( auto& aIter : sax_fastparser::castToFastAttributeList(mxAttrList) )
668  {
669  if (aIter.getToken() == XML_ELEMENT(TEXT, XML_C))
670  nRepeat = aIter.toInt32();
671  else
672  XMLOFF_WARN_UNKNOWN("sc", aIter);
673  }
674  if (nRepeat)
675  for (sal_Int32 j = 0; j < nRepeat; ++j)
676  sText.append(' ');
677  else
678  sText.append(' ');
679  }
680  else
681  {
682  if (!pChangeCellContext->IsEditCell())
683  pChangeCellContext->CreateTextPContext(false);
684  bool bWasContext (true);
685  if (!pTextPContext)
686  {
687  bWasContext = false;
688  pTextPContext = GetScImport().GetTextImport()->CreateTextChildContext(
689  GetScImport(), mnElement, mxAttrList);
690  }
691  if (pTextPContext)
692  {
693  if (!bWasContext)
694  pTextPContext->characters(sText.makeStringAndClear());
695  xContext = pTextPContext->createFastChildContext(nElement, xAttrList);
696  }
697  }
698 
699  return xContext;
700 }
701 
702 void ScXMLChangeTextPContext::characters( const OUString& rChars )
703 {
704  if (!pTextPContext)
705  sText.append(rChars);
706  else
707  pTextPContext->characters(rChars);
708 }
709 
710 void ScXMLChangeTextPContext::endFastElement(sal_Int32 /*nElement*/)
711 {
712  if (!pTextPContext)
713  pChangeCellContext->SetText(sText.makeStringAndClear());
714 }
715 
716 ScXMLChangeCellContext::ScXMLChangeCellContext( ScXMLImport& rImport,
718  ScCellValue& rOldCell, OUString& rAddress,
719  OUString& rFormula, OUString& rFormulaNmsp,
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)
732 {
733  bool bIsMatrix(false);
734  bool bIsCoveredMatrix(false);
735  if ( rAttrList.is() )
736  {
737  for (auto &aIter : *rAttrList)
738  {
739  switch (aIter.getToken())
740  {
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))
764  {
766  bString = false;
767  }
768  else if (IsXMLToken(aIter, XML_TIME))
769  {
770  rType = css::util::NumberFormat::TIME;
771  bString = false;
772  }
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.toString());
782  fValue = rDateTimeValue;
783  break;
784  case XML_ELEMENT( OFFICE, XML_TIME_VALUE ):
785  bEmpty = false;
786  ::sax::Converter::convertDuration(rDateTimeValue, aIter.toString());
787  fValue = rDateTimeValue;
788  }
789  }
790  }
791 
792  if (bIsCoveredMatrix)
793  nMatrixFlag = ScMatrixMode::Reference;
794  else if (bIsMatrix && nMatrixRows && nMatrixCols)
795  nMatrixFlag = ScMatrixMode::Formula;
796 }
797 
798 uno::Reference< xml::sax::XFastContextHandler > ScXMLChangeCellContext::createFastChildContext(
799  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
800 {
801  SvXMLImportContext *pContext(nullptr);
802 
803  if (nElement == XML_ELEMENT(TEXT, XML_P))
804  {
805  bEmpty = false;
806  if (bFirstParagraph)
807  {
808  pContext = new ScXMLChangeTextPContext(GetScImport(), nElement, xAttrList, this);
809  bFirstParagraph = false;
810  }
811  else
812  {
813  if (!mpEditTextObj.is())
814  CreateTextPContext(true);
815  pContext = GetScImport().GetTextImport()->CreateTextChildContext(
816  GetScImport(), nElement, xAttrList);
817  }
818  }
819  else
820  XMLOFF_WARN_UNKNOWN_ELEMENT("sc", nElement);
821 
822  return pContext;
823 }
824 
825 void ScXMLChangeCellContext::CreateTextPContext(bool bIsNewParagraph)
826 {
827  if (!GetScImport().GetDocument())
828  return;
829 
830  mpEditTextObj = new ScEditEngineTextObj();
831  mpEditTextObj->GetEditEngine()->SetEditTextObjectPool(GetScImport().GetDocument()->GetEditPool());
832  uno::Reference <text::XText> xText(mpEditTextObj.get());
833  if (xText.is())
834  {
835  uno::Reference<text::XTextCursor> xTextCursor(xText->createTextCursor());
836  if (bIsNewParagraph)
837  {
838  xText->setString(sText);
839  xTextCursor->gotoEnd(false);
840  xText->insertControlCharacter(xTextCursor, text::ControlCharacter::PARAGRAPH_BREAK, false);
841  }
842  GetScImport().GetTextImport()->SetCursor(xTextCursor);
843  }
844 }
845 
846 void SAL_CALL ScXMLChangeCellContext::endFastElement( sal_Int32 /*nElement*/ )
847 {
848  if (!bEmpty)
849  {
850  ScDocument* pDoc = GetScImport().GetDocument();
851  if (mpEditTextObj.is())
852  {
853  if (GetImport().GetTextImport()->GetCursor().is())
854  {
855  //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
856  if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
857  {
858  GetImport().GetTextImport()->GetText()->insertString(
859  GetImport().GetTextImport()->GetCursorAsRange(), "",
860  true );
861  }
862  }
863 
864  // The cell will own the text object instance.
865  mrOldCell.meType = CELLTYPE_EDIT;
866  mrOldCell.mpEditText = mpEditTextObj->CreateTextObject().release();
867  GetScImport().GetTextImport()->ResetCursor();
868  mpEditTextObj.clear();
869  }
870  else
871  {
872  if (!bFormula)
873  {
874  if (!sText.isEmpty() && bString)
875  {
876  mrOldCell.meType = CELLTYPE_STRING;
877  mrOldCell.mpString = new svl::SharedString(pDoc->GetSharedStringPool().intern(sText));
878  }
879  else
880  {
881  mrOldCell.meType = CELLTYPE_VALUE;
882  mrOldCell.mfValue = fValue;
883  }
884  if (rType == css::util::NumberFormat::DATE || rType == css::util::NumberFormat::TIME)
885  rInputString = sText;
886  }
887  }
888  }
889  else
890  mrOldCell.clear();
891 }
892 
893 ScXMLPreviousContext::ScXMLPreviousContext( ScXMLImport& rImport,
895  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
896  ScXMLImportContext( rImport ),
897  fValue(0.0),
898  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper),
899  nID(0),
900  nMatrixCols(0),
901  nMatrixRows(0),
902  eGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT),
903  nType(css::util::NumberFormat::ALL),
904  nMatrixFlag(ScMatrixMode::NONE)
905 {
906  if ( rAttrList.is() )
907  {
908  auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_ID ) ) );
909  if (aIter != rAttrList->end())
910  nID = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
911  }
912 }
913 
914 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLPreviousContext::createFastChildContext(
915  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
916 {
917  SvXMLImportContext *pContext(nullptr);
918  sax_fastparser::FastAttributeList *pAttribList =
920 
921  if ( nElement == XML_ELEMENT( TABLE, XML_CHANGE_TRACK_TABLE_CELL ) )
922  pContext = new ScXMLChangeCellContext(GetScImport(), pAttribList,
923  maOldCell, sFormulaAddress, sFormula, sFormulaNmsp, eGrammar, sInputString, fValue, nType, nMatrixFlag, nMatrixCols, nMatrixRows);
924 
925  return pContext;
926 }
927 
928 void SAL_CALL ScXMLPreviousContext::endFastElement( sal_Int32 /*nElement*/ )
929 {
930  pChangeTrackingImportHelper->SetPreviousChange(nID, new ScMyCellInfo(maOldCell, sFormulaAddress, sFormula, eGrammar, sInputString,
931  fValue, nType, nMatrixFlag, nMatrixCols, nMatrixRows));
932 }
933 
934 ScXMLContentChangeContext::ScXMLContentChangeContext( ScXMLImport& rImport,
936  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
937  ScXMLImportContext( rImport ),
938  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
939 {
940  sal_uInt32 nActionNumber(0);
941  sal_uInt32 nRejectingNumber(0);
942  ScChangeActionState nActionState(SC_CAS_VIRGIN);
943 
944  if ( rAttrList.is() )
945  {
946  for (auto &aIter : *rAttrList)
947  {
948  switch (aIter.getToken())
949  {
950  case XML_ELEMENT( TABLE, XML_ID ):
951  nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
952  break;
953  case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
954  if (IsXMLToken( aIter, XML_ACCEPTED ))
955  nActionState = SC_CAS_ACCEPTED;
956  else if (IsXMLToken( aIter, XML_REJECTED ))
957  nActionState = SC_CAS_REJECTED;
958  break;
959  case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
960  nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
961  }
962  }
963  }
964 
965  pChangeTrackingImportHelper->StartChangeAction(SC_CAT_CONTENT);
966  pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
967  pChangeTrackingImportHelper->SetActionState(nActionState);
968  pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
969 }
970 
971 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLContentChangeContext::createFastChildContext(
972  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
973 {
974  SvXMLImportContext *pContext(nullptr);
975  sax_fastparser::FastAttributeList *pAttribList =
977 
978  switch (nElement)
979  {
980  case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
981  pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
982  break;
983  case XML_ELEMENT( TABLE, XML_CELL_ADDRESS ):
984  pContext = new ScXMLBigRangeContext(GetScImport(), pAttribList, aBigRange);
985  break;
986  case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
987  pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
988  break;
989  case XML_ELEMENT( TABLE, XML_DELETIONS ):
990  pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
991  break;
992  case XML_ELEMENT( TABLE, XML_PREVIOUS ):
993  pContext = new ScXMLPreviousContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
994  break;
995  }
996 
997  return pContext;
998 }
999 
1000 void SAL_CALL ScXMLContentChangeContext::endFastElement( sal_Int32 /*nElement*/ )
1001 {
1002  pChangeTrackingImportHelper->SetBigRange(aBigRange);
1003  pChangeTrackingImportHelper->EndChangeAction();
1004 }
1005 
1006 ScXMLInsertionContext::ScXMLInsertionContext( ScXMLImport& rImport,
1008  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1009  ScXMLImportContext( rImport ),
1010  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1011 {
1012  sal_uInt32 nActionNumber(0);
1013  sal_uInt32 nRejectingNumber(0);
1014  sal_Int32 nPosition(0);
1015  sal_Int32 nCount(1);
1016  sal_Int32 nTable(0);
1017  ScChangeActionState nActionState(SC_CAS_VIRGIN);
1019 
1020  if ( rAttrList.is() )
1021  {
1022  for (auto &aIter : *rAttrList)
1023  {
1024  switch (aIter.getToken())
1025  {
1026  case XML_ELEMENT( TABLE, XML_ID ):
1027  nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
1028  break;
1029  case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
1030  if (IsXMLToken( aIter, XML_ACCEPTED ))
1031  nActionState = SC_CAS_ACCEPTED;
1032  else if (IsXMLToken( aIter, XML_REJECTED ))
1033  nActionState = SC_CAS_REJECTED;
1034  break;
1035  case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
1036  nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
1037  break;
1038  case XML_ELEMENT( TABLE, XML_TYPE ):
1039  if (IsXMLToken( aIter, XML_ROW ))
1040  nActionType = SC_CAT_INSERT_ROWS;
1041  else if (IsXMLToken( aIter, XML_TABLE ))
1042  nActionType = SC_CAT_INSERT_TABS;
1043  break;
1044  case XML_ELEMENT( TABLE, XML_POSITION ):
1045  nPosition = aIter.toInt32();
1046  break;
1047  case XML_ELEMENT( TABLE, XML_TABLE ):
1048  nTable = aIter.toInt32();
1049  break;
1050  case XML_ELEMENT( TABLE, XML_COUNT ):
1051  nCount = aIter.toInt32();
1052  break;
1053  }
1054  }
1055  }
1056 
1057  pChangeTrackingImportHelper->StartChangeAction(nActionType);
1058  pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1059  pChangeTrackingImportHelper->SetActionState(nActionState);
1060  pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1061  pChangeTrackingImportHelper->SetPosition(nPosition, nCount, nTable);
1062 }
1063 
1064 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLInsertionContext::createFastChildContext(
1065  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1066 {
1067  SvXMLImportContext *pContext(nullptr);
1068  sax_fastparser::FastAttributeList *pAttribList =
1070 
1071  switch (nElement)
1072  {
1073  case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
1074  pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1075  break;
1076  case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
1077  pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
1078  break;
1079  case XML_ELEMENT( TABLE, XML_DELETIONS ):
1080  pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1081  break;
1082  }
1083 
1084  return pContext;
1085 }
1086 
1087 void SAL_CALL ScXMLInsertionContext::endFastElement( sal_Int32 /*nElement*/ )
1088 {
1089  pChangeTrackingImportHelper->EndChangeAction();
1090 }
1091 
1092 ScXMLInsertionCutOffContext::ScXMLInsertionCutOffContext( ScXMLImport& rImport,
1093  const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
1094  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper ) :
1095  ScXMLImportContext( rImport )
1096 {
1097  sal_uInt32 nID(0);
1098  sal_Int32 nPosition(0);
1099  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
1100  {
1101  switch (aIter.getToken())
1102  {
1103  case XML_ELEMENT(TABLE, XML_ID):
1104  nID = ScXMLChangeTrackingImportHelper::GetIDFromString(aIter.toView());
1105  break;
1106  case XML_ELEMENT(TABLE, XML_POSITION):
1107  ::sax::Converter::convertNumber(nPosition, aIter.toView());
1108  break;
1109  }
1110  }
1111  pChangeTrackingImportHelper->SetInsertionCutOff(nID, nPosition);
1112 }
1113 
1114 
1115 ScXMLMovementCutOffContext::ScXMLMovementCutOffContext( ScXMLImport& rImport,
1116  const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
1117  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper ) :
1118  ScXMLImportContext( rImport )
1119 {
1120  sal_uInt32 nID(0);
1121  sal_Int32 nPosition(0);
1122  sal_Int32 nStartPosition(0);
1123  sal_Int32 nEndPosition(0);
1124  bool bPosition(false);
1125  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
1126  {
1127  switch (aIter.getToken())
1128  {
1129  case XML_ELEMENT(TABLE, XML_ID):
1130  nID = ScXMLChangeTrackingImportHelper::GetIDFromString(aIter.toView());
1131  break;
1132  case XML_ELEMENT(TABLE, XML_POSITION):
1133  bPosition = true;
1134  ::sax::Converter::convertNumber(nPosition, aIter.toView());
1135  break;
1136  case XML_ELEMENT(TABLE, XML_START_POSITION):
1137  ::sax::Converter::convertNumber(nStartPosition, aIter.toView());
1138  break;
1139  case XML_ELEMENT(TABLE, XML_END_POSITION):
1140  ::sax::Converter::convertNumber(nEndPosition, aIter.toView());
1141  break;
1142  }
1143  }
1144  if (bPosition)
1145  nStartPosition = nEndPosition = nPosition;
1146  pChangeTrackingImportHelper->AddMoveCutOff(nID, nStartPosition, nEndPosition);
1147 }
1148 
1149 ScXMLCutOffsContext::ScXMLCutOffsContext( ScXMLImport& rImport,
1150  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1151  ScXMLImportContext( rImport ),
1152  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1153 {
1154  // here are no attributes
1155 }
1156 
1157 css::uno::Reference< css::xml::sax::XFastContextHandler > ScXMLCutOffsContext::createFastChildContext(
1158  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
1159 {
1160  SvXMLImportContext *pContext(nullptr);
1161 
1162  if (nElement == XML_ELEMENT(TABLE, XML_INSERTION_CUT_OFF))
1163  pContext = new ScXMLInsertionCutOffContext(GetScImport(), xAttrList, pChangeTrackingImportHelper);
1164  else if (nElement == XML_ELEMENT(TABLE, XML_MOVEMENT_CUT_OFF))
1165  pContext = new ScXMLMovementCutOffContext(GetScImport(), xAttrList, pChangeTrackingImportHelper);
1166 
1167  return pContext;
1168 }
1169 
1170 ScXMLDeletionContext::ScXMLDeletionContext( ScXMLImport& rImport,
1172  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1173  ScXMLImportContext( rImport ),
1174  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1175 {
1176  sal_uInt32 nActionNumber(0);
1177  sal_uInt32 nRejectingNumber(0);
1178  sal_Int32 nPosition(0);
1179  sal_Int32 nMultiSpanned(0);
1180  sal_Int32 nTable(0);
1181  ScChangeActionState nActionState(SC_CAS_VIRGIN);
1183 
1184  if ( rAttrList.is() )
1185  {
1186  for (auto &aIter : *rAttrList)
1187  {
1188  sal_Int32 nToken = aIter.getToken();
1189  switch (nToken)
1190  {
1191  case XML_ELEMENT( TABLE, XML_ID ):
1192  nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
1193  break;
1194  case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
1195  if (IsXMLToken( aIter, XML_ACCEPTED ))
1196  nActionState = SC_CAS_ACCEPTED;
1197  else if (IsXMLToken( aIter, XML_REJECTED ))
1198  nActionState = SC_CAS_REJECTED;
1199  break;
1200  case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
1201  nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
1202  break;
1203  case XML_ELEMENT( TABLE, XML_TYPE ):
1204  if (IsXMLToken( aIter, XML_ROW ))
1205  nActionType = SC_CAT_DELETE_ROWS;
1206  else if (IsXMLToken( aIter, XML_TABLE ))
1207  nActionType = SC_CAT_DELETE_TABS;
1208  break;
1209  case XML_ELEMENT( TABLE, XML_POSITION ):
1210  nPosition = aIter.toInt32();
1211  break;
1212  case XML_ELEMENT( TABLE, XML_TABLE ):
1213  nTable = aIter.toInt32();
1214  break;
1215  case XML_ELEMENT( TABLE, XML_MULTI_DELETION_SPANNED ):
1216  nMultiSpanned = aIter.toInt32();
1217  break;
1218  }
1219  }
1220  }
1221 
1222  pChangeTrackingImportHelper->StartChangeAction(nActionType);
1223  pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1224  pChangeTrackingImportHelper->SetActionState(nActionState);
1225  pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1226  pChangeTrackingImportHelper->SetPosition(nPosition, 1, nTable);
1227  pChangeTrackingImportHelper->SetMultiSpanned(static_cast<sal_Int16>(nMultiSpanned));
1228 }
1229 
1230 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDeletionContext::createFastChildContext(
1231  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1232 {
1233  SvXMLImportContext *pContext(nullptr);
1234  sax_fastparser::FastAttributeList *pAttribList =
1236 
1237  switch (nElement)
1238  {
1239  case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
1240  pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1241  break;
1242  case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
1243  pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
1244  break;
1245  case XML_ELEMENT( TABLE, XML_DELETIONS ):
1246  pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1247  break;
1248  case XML_ELEMENT( TABLE, XML_CUT_OFFS ):
1249  case XML_ELEMENT( TABLE, XML_CUT_OFFS2 ): // cut_offs
1250  pContext = new ScXMLCutOffsContext(GetScImport(), pChangeTrackingImportHelper);
1251  }
1252 
1253  return pContext;
1254 }
1255 
1256 void SAL_CALL ScXMLDeletionContext::endFastElement( sal_Int32 /*nElement*/ )
1257 {
1258  pChangeTrackingImportHelper->EndChangeAction();
1259 }
1260 
1261 ScXMLMovementContext::ScXMLMovementContext( ScXMLImport& rImport,
1263  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1264  ScXMLImportContext( rImport ),
1265  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1266 {
1267  sal_uInt32 nActionNumber(0);
1268  sal_uInt32 nRejectingNumber(0);
1269  ScChangeActionState nActionState(SC_CAS_VIRGIN);
1270 
1271  if ( rAttrList.is() )
1272  {
1273  for (auto &aIter : *rAttrList)
1274  {
1275  switch (aIter.getToken())
1276  {
1277  case XML_ELEMENT( TABLE, XML_ID ):
1278  nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
1279  break;
1280  case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
1281  if (IsXMLToken( aIter, XML_ACCEPTED ))
1282  nActionState = SC_CAS_ACCEPTED;
1283  else if (IsXMLToken( aIter, XML_REJECTED ))
1284  nActionState = SC_CAS_REJECTED;
1285  break;
1286  case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
1287  nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
1288  break;
1289  }
1290  }
1291  }
1292 
1293  pChangeTrackingImportHelper->StartChangeAction(SC_CAT_MOVE);
1294  pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1295  pChangeTrackingImportHelper->SetActionState(nActionState);
1296  pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1297 }
1298 
1299 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLMovementContext::createFastChildContext(
1300  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1301 {
1302  SvXMLImportContext *pContext(nullptr);
1303  sax_fastparser::FastAttributeList *pAttribList =
1305 
1306  switch (nElement)
1307  {
1308  case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
1309  pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1310  break;
1311  case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
1312  pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
1313  break;
1314  case XML_ELEMENT( TABLE, XML_DELETIONS ):
1315  pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1316  break;
1317  case XML_ELEMENT( TABLE, XML_SOURCE_RANGE_ADDRESS ):
1318  pContext = new ScXMLBigRangeContext(GetScImport(), pAttribList, aSourceRange);
1319  break;
1320  case XML_ELEMENT( TABLE, XML_TARGET_RANGE_ADDRESS ):
1321  pContext = new ScXMLBigRangeContext(GetScImport(), pAttribList, aTargetRange);
1322  break;
1323  }
1324 
1325  return pContext;
1326 }
1327 
1328 void SAL_CALL ScXMLMovementContext::endFastElement( sal_Int32 /*nElement*/ )
1329 {
1330  pChangeTrackingImportHelper->SetMoveRanges(aSourceRange, aTargetRange);
1331  pChangeTrackingImportHelper->EndChangeAction();
1332 }
1333 
1334 ScXMLRejectionContext::ScXMLRejectionContext( ScXMLImport& rImport,
1336  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1337  ScXMLImportContext( rImport ),
1338  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1339 {
1340  sal_uInt32 nActionNumber(0);
1341  sal_uInt32 nRejectingNumber(0);
1342  ScChangeActionState nActionState(SC_CAS_VIRGIN);
1343 
1344  if ( rAttrList.is() )
1345  {
1346  for (auto &aIter : *rAttrList)
1347  {
1348  switch (aIter.getToken())
1349  {
1350  case XML_ELEMENT( TABLE, XML_ID ):
1351  nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
1352  break;
1353  case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
1354  if (IsXMLToken( aIter, XML_ACCEPTED ))
1355  nActionState = SC_CAS_ACCEPTED;
1356  else if (IsXMLToken( aIter, XML_REJECTED ))
1357  nActionState = SC_CAS_REJECTED;
1358  break;
1359  case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
1360  nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toView() );
1361  break;
1362  }
1363  }
1364  }
1365 
1366  pChangeTrackingImportHelper->StartChangeAction(SC_CAT_MOVE);
1367  pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1368  pChangeTrackingImportHelper->SetActionState(nActionState);
1369  pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1370 }
1371 
1372 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLRejectionContext::createFastChildContext(
1373  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1374 {
1375  SvXMLImportContext *pContext(nullptr);
1376  sax_fastparser::FastAttributeList *pAttribList =
1378 
1379  switch (nElement)
1380  {
1381  case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
1382  pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1383  break;
1384  case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
1385  pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
1386  break;
1387  case XML_ELEMENT( TABLE, XML_DELETIONS ):
1388  pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1389  break;
1390  }
1391 
1392  return pContext;
1393 }
1394 
1395 void SAL_CALL ScXMLRejectionContext::endFastElement( sal_Int32 /*nElement*/ )
1396 {
1397  pChangeTrackingImportHelper->EndChangeAction();
1398 }
1399 
1400 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
exports com.sun.star.lib. util
ScChangeActionState
Definition: chgtrack.hxx:77
void Set(sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1, sal_Int32 nCol2, sal_Int32 nRow2, sal_Int32 nTab2)
Definition: bigrange.hxx:125
OOO_DLLPUBLIC_DBTOOLS double toDouble(const css::util::Date &rVal, const css::util::Date &_rNullDate=getStandardDate())
SharedString intern(const OUString &rStr)
SC_DLLPUBLIC svl::SharedStringPool & GetSharedStringPool()
Definition: documen2.cxx:563
void StartChangeAction(const ScChangeActionType nActionType)
void SetRejectingNumber(const sal_uInt32 nRejectingNumber)
sal_Int32 toInt32(OUString const &rStr)
XML_DELETION
ScChangeActionType
Definition: chgtrack.hxx:63
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
static bool parseDateTime(css::util::DateTime &rDateTime, std::u16string_view rString)
XML_CUT_OFFS2
void SetProtection(const css::uno::Sequence< sal_Int8 > &rProtect)
void SetPreviousChange(const sal_uInt32 nPreviousAction, ScMyCellInfo *pCellInfo)
XML_REJECTION
Store arbitrary cell value of any kind.
Definition: cellvalue.hxx:36
XML_PROTECTION_KEY
XML_CELL_CONTENT_CHANGE
XML_ROW
void LockSolarMutex()
Definition: xmlimprt.cxx:1518
int nCount
#define XMLOFF_WARN_UNKNOWN(area, rIter)
XML_ACCEPTED
static sal_uInt32 GetIDFromString(std::string_view sID)
void SetBigRange(const ScBigRange &aBigRange)
void AddMoveCutOff(const sal_uInt32 nID, const sal_Int32 nStartPosition, const sal_Int32 nEndPosition)
void SetActionState(const ScChangeActionState nActionState)
void SetPosition(const sal_Int32 nPosition, const sal_Int32 nCount, const sal_Int32 nTable)
XML_MOVEMENT
This class exists only to provide GetScImport() to its derived classes.
virtual ~ScXMLTrackedChangesContext() override
XML_FLOAT
static void decode(css::uno::Sequence< sal_Int8 > &aPass, const OUString &sBuffer)
void convertDateTime(OUStringBuffer &rBuffer, const double &fDateTime, bool const bAddTimeIf0AM=false)
static void convertDuration(OUStringBuffer &rBuffer, const double fTime)
ScXMLImport & GetScImport()
void SetMultiSpanned(const sal_Int16 nMultiSpanned)
void ExtractFormulaNamespaceGrammar(OUString &rFormula, OUString &rFormulaNmsp,::formula::FormulaGrammar::Grammar &reGrammar, const OUString &rAttrValue, bool bRestrictToExternalNmsp=false) const
Extracts the formula string, the formula grammar namespace URL, and a grammar enum value from the pas...
Definition: xmlimprt.cxx:1579
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
ScXMLTrackedChangesContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScXMLChangeTrackingImportHelper *pChangeTrackingImportHelper)
TABLE
DefTokenId nToken
Definition: qproform.cxx:399
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
ScXMLChangeTrackingImportHelper * pChangeTrackingImportHelper
void UnlockSolarMutex()
Definition: xmlimprt.cxx:1536
#define XML_ELEMENT(prefix, name)
const SvXMLUnitConverter & GetMM100UnitConverter() const
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:400
ScMatrixMode
XML_TRUE
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
void SetActionNumber(const sal_uInt32 nActionNumber)
if(!pCandidateA->getEnd().equal(pCandidateB->getStart()))
void SetInsertionCutOff(const sal_uInt32 nID, const sal_Int32 nPosition)
void SetMoveRanges(const ScBigRange &aSourceRange, const ScBigRange &aTargetRange)
XML_INSERTION
OUString toString(OptionInfo const *info)
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)