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/xmlnmspe.hxx>
31 #include <xmloff/nmspmap.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::XAttributeList> xAttrList;
146  OUString sLName;
147  OUStringBuffer sText;
148  ScXMLChangeCellContext* pChangeCellContext;
150  pTextPContext;
151  sal_uInt16 nPrefix;
152 
153 public:
154 
155  ScXMLChangeTextPContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
156  const OUString& rLName,
157  const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList,
158  ScXMLChangeCellContext* pChangeCellContext);
159 
160  virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
161  const OUString& rLocalName,
162  const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override;
163 
164  virtual void Characters( const OUString& rChars ) override;
165 
166  virtual void EndElement() override;
167 };
168 
169 class ScXMLChangeCellContext : public ScXMLImportContext
170 {
171  ScCellValue& mrOldCell;
172 
173  OUString sText;
174  OUString& rInputString;
176  double fValue;
177  sal_uInt16& rType;
178  bool bEmpty;
179  bool bFirstParagraph;
180  bool bString;
181  bool bFormula;
182 
183 public:
184  ScXMLChangeCellContext( ScXMLImport& rImport,
186  ScCellValue& rOldCell, OUString& sAddress,
187  OUString& rFormula, OUString& rFormulaNmsp,
189  OUString& rInputString, double& fValue, sal_uInt16& nType,
190  ScMatrixMode& nMatrixFlag, sal_Int32& nMatrixCols, sal_Int32& nMatrixRows);
191 
192  virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
193  const OUString& rLocalName,
194  const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override;
195  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
196  sal_Int32 /*nElement*/, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) override
197  { return nullptr; }
198 
199  void CreateTextPContext(bool bIsNewParagraph);
200  bool IsEditCell() const { return mpEditTextObj.is(); }
201  void SetText(const OUString& sTempText) { sText = sTempText; }
202 
203  virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
204 };
205 
206 class ScXMLPreviousContext : public ScXMLImportContext
207 {
208  OUString sFormulaAddress;
209  OUString sFormula;
210  OUString sFormulaNmsp;
211  OUString sInputString;
212  double fValue;
213  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
214  ScCellValue maOldCell;
215  sal_uInt32 nID;
216  sal_Int32 nMatrixCols;
217  sal_Int32 nMatrixRows;
219  sal_uInt16 nType;
220  ScMatrixMode nMatrixFlag;
221 
222 public:
223  ScXMLPreviousContext( ScXMLImport& rImport,
225  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
226 
227  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
228  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
229 
230  virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
231 };
232 
233 class ScXMLContentChangeContext : public ScXMLImportContext
234 {
235  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
236  ScBigRange aBigRange;
237 
238 public:
239  ScXMLContentChangeContext( ScXMLImport& rImport,
241  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
242 
243  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
244  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
245 
246  virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
247 };
248 
249 class ScXMLInsertionContext : public ScXMLImportContext
250 {
251  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
252 
253 public:
254  ScXMLInsertionContext( ScXMLImport& rImport,
256  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
257 
258  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
259  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
260 
261  virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
262 };
263 
264 class ScXMLInsertionCutOffContext : public ScXMLImportContext
265 {
266 public:
267  ScXMLInsertionCutOffContext( ScXMLImport& rImport,
268  const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList,
269  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
270 };
271 
272 class ScXMLMovementCutOffContext : public ScXMLImportContext
273 {
274 public:
275  ScXMLMovementCutOffContext( ScXMLImport& rImport,
276  const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList,
277  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
278 };
279 
280 class ScXMLCutOffsContext : public ScXMLImportContext
281 {
282  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
283 
284 public:
285  ScXMLCutOffsContext( ScXMLImport& rImport,
286  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
287 
288  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
289  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
290 };
291 
292 class ScXMLDeletionContext : public ScXMLImportContext
293 {
294  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
295 
296 public:
297  ScXMLDeletionContext( ScXMLImport& rImport,
299  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
300 
301  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
302  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
303 
304  virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
305 };
306 
307 class ScXMLMovementContext : public ScXMLImportContext
308 {
309  ScBigRange aSourceRange;
310  ScBigRange aTargetRange;
311  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
312 
313 public:
314  ScXMLMovementContext( ScXMLImport& rImport,
316  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
317 
318  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
319  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
320 
321  virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
322 };
323 
324 class ScXMLRejectionContext : public ScXMLImportContext
325 {
326  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper;
327 
328 public:
329  ScXMLRejectionContext( ScXMLImport& rImport,
331  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
332 
333  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
334  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
335 
336  virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
337 };
338 
339 }
340 
343  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
344  ScXMLImportContext( rImport ),
345  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
346 {
347  rImport.LockSolarMutex();
348 
349  if ( !rAttrList.is() )
350  return;
351 
352  auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_PROTECTION_KEY ) ) );
353  if (aIter != rAttrList->end())
354  {
355  if( !aIter.isEmpty() )
356  {
357  uno::Sequence<sal_Int8> aPass;
358  ::comphelper::Base64::decode( aPass, aIter.toString() );
360  }
361  }
362 }
363 
365 {
367 }
368 
369 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLTrackedChangesContext::createFastChildContext(
370  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
371 {
372  SvXMLImportContext *pContext(nullptr);
373  sax_fastparser::FastAttributeList *pAttribList =
375 
376  switch (nElement)
377  {
379  pContext = new ScXMLContentChangeContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
380  break;
382  pContext = new ScXMLInsertionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
383  break;
384  case XML_ELEMENT( TABLE, XML_DELETION ):
385  pContext = new ScXMLDeletionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
386  break;
387  case XML_ELEMENT( TABLE, XML_MOVEMENT ):
388  pContext = new ScXMLMovementContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
389  break;
391  pContext = new ScXMLRejectionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
392  break;
393  }
394 
395  return pContext;
396 }
397 
398 ScXMLChangeInfoContext::ScXMLChangeInfoContext( ScXMLImport& rImport,
400  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
401  ScXMLImportContext( rImport ),
402  aInfo(),
403  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper),
404  nParagraphCount(0)
405 {
406  if ( rAttrList.is() )
407  {
408  for (auto &aIter : *rAttrList)
409  {
410  sal_Int32 nToken = aIter.getToken();
411  if ( nToken == XML_ELEMENT( OFFICE, XML_CHG_AUTHOR ) )
412  sAuthorBuffer = aIter.toString();
413  else if ( nToken == XML_ELEMENT( OFFICE, XML_CHG_DATE_TIME ) )
414  sDateTimeBuffer = aIter.toString();
415  }
416  }
417 }
418 
419 css::uno::Reference< css::xml::sax::XFastContextHandler > ScXMLChangeInfoContext::createFastChildContext(
420  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
421 {
422  SvXMLImportContext *pContext(nullptr);
423 
424  if( nElement == XML_ELEMENT(DC, XML_CREATOR ) )
425  pContext = new ScXMLContentContext(GetScImport(), sAuthorBuffer);
426  else if( nElement == XML_ELEMENT(DC, XML_DATE ) )
427  pContext = new ScXMLContentContext(GetScImport(), sDateTimeBuffer);
428  else if (nElement == XML_ELEMENT(TEXT, XML_P))
429  {
430  if(nParagraphCount)
431  sCommentBuffer.append('\n');
432  ++nParagraphCount;
433  pContext = new ScXMLContentContext( GetScImport(), sCommentBuffer);
434  }
435 
436  return pContext;
437 }
438 
439 void SAL_CALL ScXMLChangeInfoContext::endFastElement( sal_Int32 /*nElement*/ )
440 {
441  aInfo.sUser = sAuthorBuffer.makeStringAndClear();
442  ::sax::Converter::parseDateTime(aInfo.aDateTime,
443  sDateTimeBuffer.makeStringAndClear());
444  aInfo.sComment = sCommentBuffer.makeStringAndClear();
445  pChangeTrackingImportHelper->SetActionInfo(aInfo);
446 }
447 
448 ScXMLBigRangeContext::ScXMLBigRangeContext( ScXMLImport& rImport,
450  ScBigRange& rBigRange ) :
451  ScXMLImportContext( rImport )
452 {
453  bool bColumn(false);
454  bool bRow(false);
455  bool bTable(false);
456  sal_Int32 nColumn(0);
457  sal_Int32 nRow(0);
458  sal_Int32 nTable(0);
459  sal_Int32 nStartColumn(0);
460  sal_Int32 nEndColumn(0);
461  sal_Int32 nStartRow(0);
462  sal_Int32 nEndRow(0);
463  sal_Int32 nStartTable(0);
464  sal_Int32 nEndTable(0);
465  if ( rAttrList.is() )
466  {
467  for (auto &aIter : *rAttrList)
468  {
469  switch (aIter.getToken())
470  {
471  case XML_ELEMENT( TABLE, XML_COLUMN ):
472  nColumn = aIter.toInt32();
473  bColumn = true;
474  break;
475  case XML_ELEMENT( TABLE, XML_ROW ):
476  nRow = aIter.toInt32();
477  bRow = true;
478  break;
479  case XML_ELEMENT( TABLE, XML_TABLE ):
480  nTable = aIter.toInt32();
481  bTable = true;
482  break;
483  case XML_ELEMENT( TABLE, XML_START_COLUMN ):
484  nStartColumn = aIter.toInt32();
485  break;
486  case XML_ELEMENT( TABLE, XML_END_COLUMN ):
487  nEndColumn = aIter.toInt32();
488  break;
489  case XML_ELEMENT( TABLE, XML_START_ROW ):
490  nStartRow = aIter.toInt32();
491  break;
492  case XML_ELEMENT( TABLE, XML_END_ROW ):
493  nEndRow = aIter.toInt32();
494  break;
495  case XML_ELEMENT( TABLE, XML_START_TABLE ):
496  nStartTable = aIter.toInt32();
497  break;
498  case XML_ELEMENT( TABLE, XML_END_TABLE ):
499  nEndTable = aIter.toInt32();
500  break;
501  }
502  }
503  }
504 
505  if (bColumn)
506  nStartColumn = nEndColumn = nColumn;
507  if (bRow)
508  nStartRow = nEndRow = nRow;
509  if (bTable)
510  nStartTable = nEndTable = nTable;
511  rBigRange.Set(nStartColumn, nStartRow, nStartTable,
512  nEndColumn, nEndRow, nEndTable);
513 }
514 
515 ScXMLCellContentDeletionContext::ScXMLCellContentDeletionContext( ScXMLImport& rImport,
517  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper) :
518  ScXMLImportContext( rImport ),
519  fValue(0.0),
520  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper),
521  nID(0),
522  nMatrixCols(0),
523  nMatrixRows(0),
524  eGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT),
525  nType(css::util::NumberFormat::ALL),
526  nMatrixFlag(ScMatrixMode::NONE)
527 {
528  if ( rAttrList.is() )
529  {
530  auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_ID ) ) );
531  if (aIter != rAttrList->end())
532  nID = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
533  }
534 }
535 
536 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellContentDeletionContext::createFastChildContext(
537  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
538 {
539  SvXMLImportContext *pContext(nullptr);
540  sax_fastparser::FastAttributeList *pAttribList =
542 
543  switch (nElement)
544  {
545  case XML_ELEMENT( TABLE, XML_CHANGE_TRACK_TABLE_CELL ):
546  pContext = new ScXMLChangeCellContext(GetScImport(), pAttribList,
547  maCell, sFormulaAddress, sFormula, sFormulaNmsp, eGrammar, sInputString, fValue, nType, nMatrixFlag, nMatrixCols, nMatrixRows );
548  break;
549  case XML_ELEMENT( TABLE, XML_CELL_ADDRESS ):
550  OSL_ENSURE(!nID, "a action with a ID should not contain a BigRange");
551  pContext = new ScXMLBigRangeContext(GetScImport(), pAttribList, aBigRange);
552  break;
553  }
554 
555  return pContext;
556 }
557 
558 void SAL_CALL ScXMLCellContentDeletionContext::endFastElement( sal_Int32 /*nElement*/ )
559 {
560  std::unique_ptr<ScMyCellInfo> pCellInfo(new ScMyCellInfo(maCell, sFormulaAddress, sFormula, eGrammar, sInputString, fValue, nType,
561  nMatrixFlag, nMatrixCols, nMatrixRows));
562  if (nID)
563  pChangeTrackingImportHelper->AddDeleted(nID, std::move(pCellInfo));
564  else
565  pChangeTrackingImportHelper->AddGenerated(std::move(pCellInfo), aBigRange);
566 }
567 
568 ScXMLDependenceContext::ScXMLDependenceContext( ScXMLImport& rImport,
570  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper ) :
571  ScXMLImportContext( rImport )
572 {
573  sal_uInt32 nID(0);
574  if ( rAttrList.is() )
575  {
576  auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_ID ) ) );
577  if (aIter != rAttrList->end())
578  nID = ScXMLChangeTrackingImportHelper::GetIDFromString(aIter.toString());
579  }
580  pChangeTrackingImportHelper->AddDependence(nID);
581 }
582 
583 ScXMLDependingsContext::ScXMLDependingsContext( ScXMLImport& rImport,
584  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
585  ScXMLImportContext( rImport ),
586  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
587 {
588  // here are no attributes
589 }
590 
591 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDependingsContext::createFastChildContext(
592  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
593 {
594  SvXMLImportContext *pContext(nullptr);
595  sax_fastparser::FastAttributeList *pAttribList =
597 
598  // #i80033# read both old (dependence) and new (dependency) elements
599  if (nElement == XML_ELEMENT( TABLE, XML_DEPENDENCE ) ||
600  nElement == XML_ELEMENT( TABLE, XML_DEPENDENCY ))
601  {
602  pContext = new ScXMLDependenceContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
603  }
604 
605  return pContext;
606 }
607 
608 ScXMLChangeDeletionContext::ScXMLChangeDeletionContext( ScXMLImport& rImport,
610  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper ) :
611  ScXMLImportContext( rImport )
612 {
613  sal_uInt32 nID(0);
614  if ( rAttrList.is() )
615  {
616  auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_ID ) ) );
617  if (aIter != rAttrList->end())
618  nID = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
619  }
620  pChangeTrackingImportHelper->AddDeleted(nID);
621 }
622 
623 ScXMLDeletionsContext::ScXMLDeletionsContext( ScXMLImport& rImport,
624  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
625  ScXMLImportContext( rImport ),
626  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
627 {
628  // here are no attributes
629 }
630 
631 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDeletionsContext::createFastChildContext(
632  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
633 {
634  SvXMLImportContext *pContext(nullptr);
635  sax_fastparser::FastAttributeList *pAttribList =
637 
638  switch (nElement)
639  {
640  case XML_ELEMENT( TABLE, XML_CHANGE_DELETION ):
641  pContext = new ScXMLChangeDeletionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
642  break;
643  case XML_ELEMENT( TABLE, XML_CELL_CONTENT_DELETION ):
644  pContext = new ScXMLCellContentDeletionContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
645  break;
646  }
647 
648  return pContext;
649 }
650 
651 ScXMLChangeTextPContext::ScXMLChangeTextPContext( ScXMLImport& rImport,
652  sal_uInt16 nPrfx,
653  const OUString& rLName,
654  const css::uno::Reference<css::xml::sax::XAttributeList>& xTempAttrList,
655  ScXMLChangeCellContext* pTempChangeCellContext) :
656  ScXMLImportContext( rImport, nPrfx, rLName ),
657  xAttrList(xTempAttrList),
658  sLName(rLName),
659  sText(),
660  pChangeCellContext(pTempChangeCellContext),
661  nPrefix(nPrfx)
662 {
663  // here are no attributes
664 }
665 
666 SvXMLImportContextRef ScXMLChangeTextPContext::CreateChildContext( sal_uInt16 nTempPrefix,
667  const OUString& rLName,
668  const css::uno::Reference<css::xml::sax::XAttributeList>& xTempAttrList )
669 {
670  SvXMLImportContextRef xContext;
671 
672  if ((nPrefix == XML_NAMESPACE_TEXT) && (IsXMLToken(rLName, XML_S)) && !pTextPContext)
673  {
674  sal_Int32 nRepeat(0);
675  sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
676  for( sal_Int16 i=0; i < nAttrCount; ++i )
677  {
678  const OUString& sAttrName(xAttrList->getNameByIndex( i ));
679  const OUString& sValue(xAttrList->getValueByIndex( i ));
680  OUString aLocalName;
681  sal_uInt16 nPrfx(GetScImport().GetNamespaceMap().GetKeyByAttrName(
682  sAttrName, &aLocalName ));
683  if ((nPrfx == XML_NAMESPACE_TEXT) && (IsXMLToken(aLocalName, XML_C)))
684  nRepeat = sValue.toInt32();
685  }
686  if (nRepeat)
687  for (sal_Int32 j = 0; j < nRepeat; ++j)
688  sText.append(' ');
689  else
690  sText.append(' ');
691  }
692  else
693  {
694  if (!pChangeCellContext->IsEditCell())
695  pChangeCellContext->CreateTextPContext(false);
696  bool bWasContext (true);
697  if (!pTextPContext)
698  {
699  bWasContext = false;
700  pTextPContext= GetScImport().GetTextImport()->CreateTextChildContext(
701  GetScImport(), nPrefix, sLName, xAttrList);
702  }
703  if (pTextPContext)
704  {
705  if (!bWasContext)
706  pTextPContext->Characters(sText.makeStringAndClear());
707  xContext = pTextPContext->CreateChildContext(nTempPrefix, rLName, xTempAttrList);
708  }
709  }
710 
711  return xContext;
712 }
713 
714 void ScXMLChangeTextPContext::Characters( const OUString& rChars )
715 {
716  if (!pTextPContext)
717  sText.append(rChars);
718  else
719  pTextPContext->Characters(rChars);
720 }
721 
722 void ScXMLChangeTextPContext::EndElement()
723 {
724  if (!pTextPContext)
725  pChangeCellContext->SetText(sText.makeStringAndClear());
726 }
727 
728 ScXMLChangeCellContext::ScXMLChangeCellContext( ScXMLImport& rImport,
730  ScCellValue& rOldCell, OUString& rAddress,
731  OUString& rFormula, OUString& rFormulaNmsp,
733  OUString& rTempInputString, double& rDateTimeValue, sal_uInt16& nType,
734  ScMatrixMode& nMatrixFlag, sal_Int32& nMatrixCols, sal_Int32& nMatrixRows )
735  : ScXMLImportContext( rImport )
736  , mrOldCell(rOldCell)
737  , rInputString(rTempInputString)
738  , fValue(0.0)
739  , rType(nType)
740  , bEmpty(true)
741  , bFirstParagraph(true)
742  , bString(true)
743  , bFormula(false)
744 {
745  bool bIsMatrix(false);
746  bool bIsCoveredMatrix(false);
747  if ( rAttrList.is() )
748  {
749  for (auto &aIter : *rAttrList)
750  {
751  switch (aIter.getToken())
752  {
753  case XML_ELEMENT( TABLE, XML_FORMULA ):
754  bEmpty = false;
755  GetScImport().ExtractFormulaNamespaceGrammar( rFormula, rFormulaNmsp, rGrammar, aIter.toString() );
756  bFormula = true;
757  break;
758  case XML_ELEMENT( TABLE, XML_CELL_ADDRESS ):
759  rAddress = aIter.toString();
760  break;
761  case XML_ELEMENT( TABLE, XML_MATRIX_COVERED ):
762  bIsCoveredMatrix = IsXMLToken(aIter, XML_TRUE);
763  break;
764  case XML_ELEMENT( TABLE, XML_NUMBER_MATRIX_COLUMNS_SPANNED ):
765  bIsMatrix = true;
766  nMatrixCols = aIter.toInt32();
767  break;
768  case XML_ELEMENT( TABLE, XML_NUMBER_MATRIX_ROWS_SPANNED ):
769  bIsMatrix = true;
770  nMatrixRows = aIter.toInt32();
771  break;
772  case XML_ELEMENT( OFFICE, XML_VALUE_TYPE ):
773  if (IsXMLToken(aIter, XML_FLOAT))
774  bString = false;
775  else if (IsXMLToken(aIter, XML_DATE))
776  {
778  bString = false;
779  }
780  else if (IsXMLToken(aIter, XML_TIME))
781  {
782  rType = css::util::NumberFormat::TIME;
783  bString = false;
784  }
785  break;
786  case XML_ELEMENT( OFFICE, XML_VALUE ):
787  fValue = aIter.toDouble();
788  bEmpty = false;
789  break;
790  case XML_ELEMENT( OFFICE, XML_DATE_VALUE ):
791  bEmpty = false;
792  if (GetScImport().GetMM100UnitConverter().setNullDate(GetScImport().GetModel()))
793  GetScImport().GetMM100UnitConverter().convertDateTime(rDateTimeValue, aIter.toString());
794  fValue = rDateTimeValue;
795  break;
796  case XML_ELEMENT( OFFICE, XML_TIME_VALUE ):
797  bEmpty = false;
798  ::sax::Converter::convertDuration(rDateTimeValue, aIter.toString());
799  fValue = rDateTimeValue;
800  }
801  }
802  }
803 
804  if (bIsCoveredMatrix)
805  nMatrixFlag = ScMatrixMode::Reference;
806  else if (bIsMatrix && nMatrixRows && nMatrixCols)
807  nMatrixFlag = ScMatrixMode::Formula;
808 }
809 
810 SvXMLImportContextRef ScXMLChangeCellContext::CreateChildContext( sal_uInt16 nPrefix,
811  const OUString& rLocalName,
812  const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList )
813 {
814  SvXMLImportContext *pContext(nullptr);
815 
816  if ((nPrefix == XML_NAMESPACE_TEXT) && (IsXMLToken(rLocalName, XML_P)))
817  {
818  bEmpty = false;
819  if (bFirstParagraph)
820  {
821  pContext = new ScXMLChangeTextPContext(GetScImport(), nPrefix, rLocalName, xAttrList, this);
822  bFirstParagraph = false;
823  }
824  else
825  {
826  if (!mpEditTextObj.is())
827  CreateTextPContext(true);
828  pContext = GetScImport().GetTextImport()->CreateTextChildContext(
829  GetScImport(), nPrefix, rLocalName, xAttrList);
830  }
831  }
832 
833  return pContext;
834 }
835 
836 void ScXMLChangeCellContext::CreateTextPContext(bool bIsNewParagraph)
837 {
838  if (!GetScImport().GetDocument())
839  return;
840 
841  mpEditTextObj = new ScEditEngineTextObj();
842  mpEditTextObj->GetEditEngine()->SetEditTextObjectPool(GetScImport().GetDocument()->GetEditPool());
843  uno::Reference <text::XText> xText(mpEditTextObj.get());
844  if (xText.is())
845  {
846  uno::Reference<text::XTextCursor> xTextCursor(xText->createTextCursor());
847  if (bIsNewParagraph)
848  {
849  xText->setString(sText);
850  xTextCursor->gotoEnd(false);
851  xText->insertControlCharacter(xTextCursor, text::ControlCharacter::PARAGRAPH_BREAK, false);
852  }
853  GetScImport().GetTextImport()->SetCursor(xTextCursor);
854  }
855 }
856 
857 void SAL_CALL ScXMLChangeCellContext::endFastElement( sal_Int32 /*nElement*/ )
858 {
859  if (!bEmpty)
860  {
861  ScDocument* pDoc = GetScImport().GetDocument();
862  if (mpEditTextObj.is())
863  {
864  if (GetImport().GetTextImport()->GetCursor().is())
865  {
866  //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
867  if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
868  {
869  GetImport().GetTextImport()->GetText()->insertString(
870  GetImport().GetTextImport()->GetCursorAsRange(), "",
871  true );
872  }
873  }
874 
875  // The cell will own the text object instance.
876  mrOldCell.meType = CELLTYPE_EDIT;
877  mrOldCell.mpEditText = mpEditTextObj->CreateTextObject().release();
878  GetScImport().GetTextImport()->ResetCursor();
879  mpEditTextObj.clear();
880  }
881  else
882  {
883  if (!bFormula)
884  {
885  if (!sText.isEmpty() && bString)
886  {
887  mrOldCell.meType = CELLTYPE_STRING;
888  mrOldCell.mpString = new svl::SharedString(pDoc->GetSharedStringPool().intern(sText));
889  }
890  else
891  {
892  mrOldCell.meType = CELLTYPE_VALUE;
893  mrOldCell.mfValue = fValue;
894  }
895  if (rType == css::util::NumberFormat::DATE || rType == css::util::NumberFormat::TIME)
896  rInputString = sText;
897  }
898  }
899  }
900  else
901  mrOldCell.clear();
902 }
903 
904 ScXMLPreviousContext::ScXMLPreviousContext( ScXMLImport& rImport,
906  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
907  ScXMLImportContext( rImport ),
908  fValue(0.0),
909  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper),
910  nID(0),
911  nMatrixCols(0),
912  nMatrixRows(0),
913  eGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT),
914  nType(css::util::NumberFormat::ALL),
915  nMatrixFlag(ScMatrixMode::NONE)
916 {
917  if ( rAttrList.is() )
918  {
919  auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_ID ) ) );
920  if (aIter != rAttrList->end())
921  nID = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
922  }
923 }
924 
925 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLPreviousContext::createFastChildContext(
926  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
927 {
928  SvXMLImportContext *pContext(nullptr);
929  sax_fastparser::FastAttributeList *pAttribList =
931 
932  if ( nElement == XML_ELEMENT( TABLE, XML_CHANGE_TRACK_TABLE_CELL ) )
933  pContext = new ScXMLChangeCellContext(GetScImport(), pAttribList,
934  maOldCell, sFormulaAddress, sFormula, sFormulaNmsp, eGrammar, sInputString, fValue, nType, nMatrixFlag, nMatrixCols, nMatrixRows);
935 
936  return pContext;
937 }
938 
939 void SAL_CALL ScXMLPreviousContext::endFastElement( sal_Int32 /*nElement*/ )
940 {
941  pChangeTrackingImportHelper->SetPreviousChange(nID, new ScMyCellInfo(maOldCell, sFormulaAddress, sFormula, eGrammar, sInputString,
942  fValue, nType, nMatrixFlag, nMatrixCols, nMatrixRows));
943 }
944 
945 ScXMLContentChangeContext::ScXMLContentChangeContext( ScXMLImport& rImport,
947  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
948  ScXMLImportContext( rImport ),
949  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
950 {
951  sal_uInt32 nActionNumber(0);
952  sal_uInt32 nRejectingNumber(0);
953  ScChangeActionState nActionState(SC_CAS_VIRGIN);
954 
955  if ( rAttrList.is() )
956  {
957  for (auto &aIter : *rAttrList)
958  {
959  switch (aIter.getToken())
960  {
961  case XML_ELEMENT( TABLE, XML_ID ):
962  nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
963  break;
964  case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
965  if (IsXMLToken( aIter, XML_ACCEPTED ))
966  nActionState = SC_CAS_ACCEPTED;
967  else if (IsXMLToken( aIter, XML_REJECTED ))
968  nActionState = SC_CAS_REJECTED;
969  break;
970  case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
971  nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
972  }
973  }
974  }
975 
976  pChangeTrackingImportHelper->StartChangeAction(SC_CAT_CONTENT);
977  pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
978  pChangeTrackingImportHelper->SetActionState(nActionState);
979  pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
980 }
981 
982 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLContentChangeContext::createFastChildContext(
983  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
984 {
985  SvXMLImportContext *pContext(nullptr);
986  sax_fastparser::FastAttributeList *pAttribList =
988 
989  switch (nElement)
990  {
991  case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
992  pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
993  break;
994  case XML_ELEMENT( TABLE, XML_CELL_ADDRESS ):
995  pContext = new ScXMLBigRangeContext(GetScImport(), pAttribList, aBigRange);
996  break;
997  case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
998  pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
999  break;
1000  case XML_ELEMENT( TABLE, XML_DELETIONS ):
1001  pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1002  break;
1003  case XML_ELEMENT( TABLE, XML_PREVIOUS ):
1004  pContext = new ScXMLPreviousContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1005  break;
1006  }
1007 
1008  return pContext;
1009 }
1010 
1011 void SAL_CALL ScXMLContentChangeContext::endFastElement( sal_Int32 /*nElement*/ )
1012 {
1013  pChangeTrackingImportHelper->SetBigRange(aBigRange);
1014  pChangeTrackingImportHelper->EndChangeAction();
1015 }
1016 
1017 ScXMLInsertionContext::ScXMLInsertionContext( ScXMLImport& rImport,
1019  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1020  ScXMLImportContext( rImport ),
1021  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1022 {
1023  sal_uInt32 nActionNumber(0);
1024  sal_uInt32 nRejectingNumber(0);
1025  sal_Int32 nPosition(0);
1026  sal_Int32 nCount(1);
1027  sal_Int32 nTable(0);
1028  ScChangeActionState nActionState(SC_CAS_VIRGIN);
1030 
1031  if ( rAttrList.is() )
1032  {
1033  for (auto &aIter : *rAttrList)
1034  {
1035  switch (aIter.getToken())
1036  {
1037  case XML_ELEMENT( TABLE, XML_ID ):
1038  nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
1039  break;
1040  case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
1041  if (IsXMLToken( aIter, XML_ACCEPTED ))
1042  nActionState = SC_CAS_ACCEPTED;
1043  else if (IsXMLToken( aIter, XML_REJECTED ))
1044  nActionState = SC_CAS_REJECTED;
1045  break;
1046  case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
1047  nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
1048  break;
1049  case XML_ELEMENT( TABLE, XML_TYPE ):
1050  if (IsXMLToken( aIter, XML_ROW ))
1051  nActionType = SC_CAT_INSERT_ROWS;
1052  else if (IsXMLToken( aIter, XML_TABLE ))
1053  nActionType = SC_CAT_INSERT_TABS;
1054  break;
1055  case XML_ELEMENT( TABLE, XML_POSITION ):
1056  nPosition = aIter.toInt32();
1057  break;
1058  case XML_ELEMENT( TABLE, XML_TABLE ):
1059  nTable = aIter.toInt32();
1060  break;
1061  case XML_ELEMENT( TABLE, XML_COUNT ):
1062  nCount = aIter.toInt32();
1063  break;
1064  }
1065  }
1066  }
1067 
1068  pChangeTrackingImportHelper->StartChangeAction(nActionType);
1069  pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1070  pChangeTrackingImportHelper->SetActionState(nActionState);
1071  pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1072  pChangeTrackingImportHelper->SetPosition(nPosition, nCount, nTable);
1073 }
1074 
1075 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLInsertionContext::createFastChildContext(
1076  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1077 {
1078  SvXMLImportContext *pContext(nullptr);
1079  sax_fastparser::FastAttributeList *pAttribList =
1081 
1082  switch (nElement)
1083  {
1084  case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
1085  pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1086  break;
1087  case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
1088  pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
1089  break;
1090  case XML_ELEMENT( TABLE, XML_DELETIONS ):
1091  pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1092  break;
1093  }
1094 
1095  return pContext;
1096 }
1097 
1098 void SAL_CALL ScXMLInsertionContext::endFastElement( sal_Int32 /*nElement*/ )
1099 {
1100  pChangeTrackingImportHelper->EndChangeAction();
1101 }
1102 
1103 ScXMLInsertionCutOffContext::ScXMLInsertionCutOffContext( ScXMLImport& rImport,
1104  const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
1105  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper ) :
1106  ScXMLImportContext( rImport )
1107 {
1108  sal_uInt32 nID(0);
1109  sal_Int32 nPosition(0);
1110  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
1111  {
1112  const OUString sValue = aIter.toString();
1113 
1114  switch (aIter.getToken())
1115  {
1116  case XML_ELEMENT(TABLE, XML_ID):
1117  nID = ScXMLChangeTrackingImportHelper::GetIDFromString(sValue);
1118  break;
1119  case XML_ELEMENT(TABLE, XML_POSITION):
1120  ::sax::Converter::convertNumber(nPosition, sValue);
1121  break;
1122  }
1123  }
1124  pChangeTrackingImportHelper->SetInsertionCutOff(nID, nPosition);
1125 }
1126 
1127 
1128 ScXMLMovementCutOffContext::ScXMLMovementCutOffContext( ScXMLImport& rImport,
1129  const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
1130  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper ) :
1131  ScXMLImportContext( rImport )
1132 {
1133  sal_uInt32 nID(0);
1134  sal_Int32 nPosition(0);
1135  sal_Int32 nStartPosition(0);
1136  sal_Int32 nEndPosition(0);
1137  bool bPosition(false);
1138  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
1139  {
1140  const OUString sValue = aIter.toString();
1141 
1142  switch (aIter.getToken())
1143  {
1144  case XML_ELEMENT(TABLE, XML_ID):
1145  nID = ScXMLChangeTrackingImportHelper::GetIDFromString(sValue);
1146  break;
1147  case XML_ELEMENT(TABLE, XML_POSITION):
1148  bPosition = true;
1149  ::sax::Converter::convertNumber(nPosition, sValue);
1150  break;
1151  case XML_ELEMENT(TABLE, XML_START_POSITION):
1152  ::sax::Converter::convertNumber(nStartPosition, sValue);
1153  break;
1154  case XML_ELEMENT(TABLE, XML_END_POSITION):
1155  ::sax::Converter::convertNumber(nEndPosition, sValue);
1156  break;
1157  }
1158  }
1159  if (bPosition)
1160  nStartPosition = nEndPosition = nPosition;
1161  pChangeTrackingImportHelper->AddMoveCutOff(nID, nStartPosition, nEndPosition);
1162 }
1163 
1164 ScXMLCutOffsContext::ScXMLCutOffsContext( ScXMLImport& rImport,
1165  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1166  ScXMLImportContext( rImport ),
1167  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1168 {
1169  // here are no attributes
1170 }
1171 
1172 css::uno::Reference< css::xml::sax::XFastContextHandler > ScXMLCutOffsContext::createFastChildContext(
1173  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
1174 {
1175  SvXMLImportContext *pContext(nullptr);
1176 
1177  if (nElement == XML_ELEMENT(TABLE, XML_INSERTION_CUT_OFF))
1178  pContext = new ScXMLInsertionCutOffContext(GetScImport(), xAttrList, pChangeTrackingImportHelper);
1179  else if (nElement == XML_ELEMENT(TABLE, XML_MOVEMENT_CUT_OFF))
1180  pContext = new ScXMLMovementCutOffContext(GetScImport(), xAttrList, pChangeTrackingImportHelper);
1181 
1182  return pContext;
1183 }
1184 
1185 ScXMLDeletionContext::ScXMLDeletionContext( ScXMLImport& rImport,
1187  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1188  ScXMLImportContext( rImport ),
1189  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1190 {
1191  sal_uInt32 nActionNumber(0);
1192  sal_uInt32 nRejectingNumber(0);
1193  sal_Int32 nPosition(0);
1194  sal_Int32 nMultiSpanned(0);
1195  sal_Int32 nTable(0);
1196  ScChangeActionState nActionState(SC_CAS_VIRGIN);
1198 
1199  if ( rAttrList.is() )
1200  {
1201  for (auto &aIter : *rAttrList)
1202  {
1203  sal_Int32 nToken = aIter.getToken();
1204  switch (nToken)
1205  {
1206  case XML_ELEMENT( TABLE, XML_ID ):
1207  nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
1208  break;
1209  case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
1210  if (IsXMLToken( aIter, XML_ACCEPTED ))
1211  nActionState = SC_CAS_ACCEPTED;
1212  else if (IsXMLToken( aIter, XML_REJECTED ))
1213  nActionState = SC_CAS_REJECTED;
1214  break;
1215  case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
1216  nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
1217  break;
1218  case XML_ELEMENT( TABLE, XML_TYPE ):
1219  if (IsXMLToken( aIter, XML_ROW ))
1220  nActionType = SC_CAT_DELETE_ROWS;
1221  else if (IsXMLToken( aIter, XML_TABLE ))
1222  nActionType = SC_CAT_DELETE_TABS;
1223  break;
1224  case XML_ELEMENT( TABLE, XML_POSITION ):
1225  nPosition = aIter.toInt32();
1226  break;
1227  case XML_ELEMENT( TABLE, XML_TABLE ):
1228  nTable = aIter.toInt32();
1229  break;
1230  case XML_ELEMENT( TABLE, XML_MULTI_DELETION_SPANNED ):
1231  nMultiSpanned = aIter.toInt32();
1232  break;
1233  }
1234  }
1235  }
1236 
1237  pChangeTrackingImportHelper->StartChangeAction(nActionType);
1238  pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1239  pChangeTrackingImportHelper->SetActionState(nActionState);
1240  pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1241  pChangeTrackingImportHelper->SetPosition(nPosition, 1, nTable);
1242  pChangeTrackingImportHelper->SetMultiSpanned(static_cast<sal_Int16>(nMultiSpanned));
1243 }
1244 
1245 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDeletionContext::createFastChildContext(
1246  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1247 {
1248  SvXMLImportContext *pContext(nullptr);
1249  sax_fastparser::FastAttributeList *pAttribList =
1251 
1252  switch (nElement)
1253  {
1254  case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
1255  pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1256  break;
1257  case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
1258  pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
1259  break;
1260  case XML_ELEMENT( TABLE, XML_DELETIONS ):
1261  pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1262  break;
1263  case XML_ELEMENT( TABLE, XML_CUT_OFFS ):
1264  case XML_ELEMENT( TABLE, XML_CUT_OFFS2 ): // cut_offs
1265  pContext = new ScXMLCutOffsContext(GetScImport(), pChangeTrackingImportHelper);
1266  }
1267 
1268  return pContext;
1269 }
1270 
1271 void SAL_CALL ScXMLDeletionContext::endFastElement( sal_Int32 /*nElement*/ )
1272 {
1273  pChangeTrackingImportHelper->EndChangeAction();
1274 }
1275 
1276 ScXMLMovementContext::ScXMLMovementContext( ScXMLImport& rImport,
1278  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1279  ScXMLImportContext( rImport ),
1280  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1281 {
1282  sal_uInt32 nActionNumber(0);
1283  sal_uInt32 nRejectingNumber(0);
1284  ScChangeActionState nActionState(SC_CAS_VIRGIN);
1285 
1286  if ( rAttrList.is() )
1287  {
1288  for (auto &aIter : *rAttrList)
1289  {
1290  switch (aIter.getToken())
1291  {
1292  case XML_ELEMENT( TABLE, XML_ID ):
1293  nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
1294  break;
1295  case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
1296  if (IsXMLToken( aIter, XML_ACCEPTED ))
1297  nActionState = SC_CAS_ACCEPTED;
1298  else if (IsXMLToken( aIter, XML_REJECTED ))
1299  nActionState = SC_CAS_REJECTED;
1300  break;
1301  case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
1302  nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
1303  break;
1304  }
1305  }
1306  }
1307 
1308  pChangeTrackingImportHelper->StartChangeAction(SC_CAT_MOVE);
1309  pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1310  pChangeTrackingImportHelper->SetActionState(nActionState);
1311  pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1312 }
1313 
1314 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLMovementContext::createFastChildContext(
1315  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1316 {
1317  SvXMLImportContext *pContext(nullptr);
1318  sax_fastparser::FastAttributeList *pAttribList =
1320 
1321  switch (nElement)
1322  {
1323  case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
1324  pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1325  break;
1326  case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
1327  pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
1328  break;
1329  case XML_ELEMENT( TABLE, XML_DELETIONS ):
1330  pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1331  break;
1332  case XML_ELEMENT( TABLE, XML_SOURCE_RANGE_ADDRESS ):
1333  pContext = new ScXMLBigRangeContext(GetScImport(), pAttribList, aSourceRange);
1334  break;
1335  case XML_ELEMENT( TABLE, XML_TARGET_RANGE_ADDRESS ):
1336  pContext = new ScXMLBigRangeContext(GetScImport(), pAttribList, aTargetRange);
1337  break;
1338  }
1339 
1340  return pContext;
1341 }
1342 
1343 void SAL_CALL ScXMLMovementContext::endFastElement( sal_Int32 /*nElement*/ )
1344 {
1345  pChangeTrackingImportHelper->SetMoveRanges(aSourceRange, aTargetRange);
1346  pChangeTrackingImportHelper->EndChangeAction();
1347 }
1348 
1349 ScXMLRejectionContext::ScXMLRejectionContext( ScXMLImport& rImport,
1351  ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1352  ScXMLImportContext( rImport ),
1353  pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1354 {
1355  sal_uInt32 nActionNumber(0);
1356  sal_uInt32 nRejectingNumber(0);
1357  ScChangeActionState nActionState(SC_CAS_VIRGIN);
1358 
1359  if ( rAttrList.is() )
1360  {
1361  for (auto &aIter : *rAttrList)
1362  {
1363  switch (aIter.getToken())
1364  {
1365  case XML_ELEMENT( TABLE, XML_ID ):
1366  nActionNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
1367  break;
1368  case XML_ELEMENT( TABLE, XML_ACCEPTANCE_STATE ):
1369  if (IsXMLToken( aIter, XML_ACCEPTED ))
1370  nActionState = SC_CAS_ACCEPTED;
1371  else if (IsXMLToken( aIter, XML_REJECTED ))
1372  nActionState = SC_CAS_REJECTED;
1373  break;
1374  case XML_ELEMENT( TABLE, XML_REJECTING_CHANGE_ID ):
1375  nRejectingNumber = ScXMLChangeTrackingImportHelper::GetIDFromString( aIter.toString() );
1376  break;
1377  }
1378  }
1379  }
1380 
1381  pChangeTrackingImportHelper->StartChangeAction(SC_CAT_MOVE);
1382  pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1383  pChangeTrackingImportHelper->SetActionState(nActionState);
1384  pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1385 }
1386 
1387 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLRejectionContext::createFastChildContext(
1388  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1389 {
1390  SvXMLImportContext *pContext(nullptr);
1391  sax_fastparser::FastAttributeList *pAttribList =
1393 
1394  switch (nElement)
1395  {
1396  case XML_ELEMENT( OFFICE, XML_CHANGE_INFO ):
1397  pContext = new ScXMLChangeInfoContext(GetScImport(), pAttribList, pChangeTrackingImportHelper);
1398  break;
1399  case XML_ELEMENT( TABLE, XML_DEPENDENCIES ):
1400  pContext = new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper);
1401  break;
1402  case XML_ELEMENT( TABLE, XML_DELETIONS ):
1403  pContext = new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper);
1404  break;
1405  }
1406 
1407  return pContext;
1408 }
1409 
1410 void SAL_CALL ScXMLRejectionContext::endFastElement( sal_Int32 /*nElement*/ )
1411 {
1412  pChangeTrackingImportHelper->EndChangeAction();
1413 }
1414 
1415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
exports com.sun.star.lib. util
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
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)
static sal_uInt32 GetIDFromString(const OUString &sID)
sal_Int32 toInt32(OUString const &rStr)
XML_DELETION
ScChangeActionType
Definition: chgtrack.hxx:63
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
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:1699
int nCount
XML_ACCEPTED
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.
static bool parseDateTime(css::util::DateTime &rDateTime, const OUString &rString)
virtual ~ScXMLTrackedChangesContext() override
XML_FLOAT
int i
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:1760
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:400
ScXMLChangeTrackingImportHelper * pChangeTrackingImportHelper
void UnlockSolarMutex()
Definition: xmlimprt.cxx:1717
#define XML_ELEMENT(prefix, name)
const SvXMLUnitConverter & GetMM100UnitConverter() const
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:401
ScMatrixMode
XML_TRUE
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)