1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "XMLTrackedChangesContext.hxx"
22 #include "XMLChangeTrackingImportHelper.hxx"
23 #include "xmlimprt.hxx"
24 #include "xmlconti.hxx"
25 #include <formulacell.hxx>
26 #include <textuno.hxx>
27 #include <editutil.hxx>
28 #include <document.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/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>
39 using namespace com::sun::star
;
40 using namespace xmloff::token
;
42 class ScXMLChangeInfoContext
: public ScXMLImportContext
45 OUStringBuffer sAuthorBuffer
{32};
46 OUStringBuffer sDateTimeBuffer
{32};
47 OUStringBuffer sCommentBuffer
{64};
48 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
;
49 sal_uInt32 nParagraphCount
;
52 ScXMLChangeInfoContext( ScXMLImport
& rImport
,
53 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
54 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
);
56 virtual SvXMLImportContextRef
CreateChildContext( sal_uInt16 nPrefix
,
57 const OUString
& rLocalName
,
58 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttrList
) override
;
60 virtual void SAL_CALL
endFastElement( sal_Int32 nElement
) override
;
63 class ScXMLBigRangeContext
: public ScXMLImportContext
66 ScXMLBigRangeContext( ScXMLImport
& rImport
,
67 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
68 ScBigRange
& rBigRange
);
71 class ScXMLCellContentDeletionContext
: public ScXMLImportContext
73 OUString sFormulaAddress
;
75 OUString sFormulaNmsp
;
76 OUString sInputString
;
79 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
;
82 sal_Int32 nMatrixCols
;
83 sal_Int32 nMatrixRows
;
84 formula::FormulaGrammar::Grammar eGrammar
;
86 ScMatrixMode nMatrixFlag
;
89 ScXMLCellContentDeletionContext( ScXMLImport
& rImport
,
90 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
91 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
);
93 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
createFastChildContext(
94 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
96 virtual void SAL_CALL
endFastElement( sal_Int32 nElement
) override
;
99 class ScXMLDependenceContext
: public ScXMLImportContext
102 ScXMLDependenceContext( ScXMLImport
& rImport
,
103 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
104 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
);
107 class ScXMLDependingsContext
: public ScXMLImportContext
109 ScXMLChangeTrackingImportHelper
* const pChangeTrackingImportHelper
;
112 ScXMLDependingsContext( ScXMLImport
& rImport
,
113 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
);
115 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
createFastChildContext(
116 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
119 class ScXMLChangeDeletionContext
: public ScXMLImportContext
122 ScXMLChangeDeletionContext( ScXMLImport
& rImport
,
123 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
124 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
);
128 class ScXMLDeletionsContext
: public ScXMLImportContext
130 ScXMLChangeTrackingImportHelper
* const pChangeTrackingImportHelper
;
133 ScXMLDeletionsContext( ScXMLImport
& rImport
,
134 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
);
136 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
createFastChildContext(
137 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
140 class ScXMLChangeCellContext
;
142 class ScXMLChangeTextPContext
: public ScXMLImportContext
144 css::uno::Reference
< css::xml::sax::XAttributeList
> xAttrList
;
145 OUString
const sLName
;
146 OUStringBuffer sText
;
147 ScXMLChangeCellContext
* pChangeCellContext
;
148 rtl::Reference
<SvXMLImportContext
>
150 sal_uInt16
const nPrefix
;
154 ScXMLChangeTextPContext( ScXMLImport
& rImport
, sal_uInt16 nPrfx
,
155 const OUString
& rLName
,
156 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttrList
,
157 ScXMLChangeCellContext
* pChangeCellContext
);
159 virtual SvXMLImportContextRef
CreateChildContext( sal_uInt16 nPrefix
,
160 const OUString
& rLocalName
,
161 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttrList
) override
;
163 virtual void Characters( const OUString
& rChars
) override
;
165 virtual void EndElement() override
;
168 class ScXMLChangeCellContext
: public ScXMLImportContext
170 ScCellValue
& mrOldCell
;
173 OUString
& rInputString
;
174 rtl::Reference
<ScEditEngineTextObj
> mpEditTextObj
;
178 bool bFirstParagraph
;
183 ScXMLChangeCellContext( ScXMLImport
& rImport
,
184 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
185 ScCellValue
& rOldCell
, OUString
& sAddress
,
186 OUString
& rFormula
, OUString
& rFormulaNmsp
,
187 formula::FormulaGrammar::Grammar
& rGrammar
,
188 OUString
& rInputString
, double& fValue
, sal_uInt16
& nType
,
189 ScMatrixMode
& nMatrixFlag
, sal_Int32
& nMatrixCols
, sal_Int32
& nMatrixRows
);
191 virtual SvXMLImportContextRef
CreateChildContext( sal_uInt16 nPrefix
,
192 const OUString
& rLocalName
,
193 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttrList
) override
;
195 void CreateTextPContext(bool bIsNewParagraph
);
196 bool IsEditCell() const { return mpEditTextObj
.is(); }
197 void SetText(const OUString
& sTempText
) { sText
= sTempText
; }
199 virtual void SAL_CALL
endFastElement( sal_Int32 nElement
) override
;
202 class ScXMLPreviousContext
: public ScXMLImportContext
204 OUString sFormulaAddress
;
206 OUString sFormulaNmsp
;
207 OUString sInputString
;
209 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
;
210 ScCellValue maOldCell
;
212 sal_Int32 nMatrixCols
;
213 sal_Int32 nMatrixRows
;
214 formula::FormulaGrammar::Grammar eGrammar
;
216 ScMatrixMode nMatrixFlag
;
219 ScXMLPreviousContext( ScXMLImport
& rImport
,
220 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
221 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
);
223 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
createFastChildContext(
224 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
226 virtual void SAL_CALL
endFastElement( sal_Int32 nElement
) override
;
229 class ScXMLContentChangeContext
: public ScXMLImportContext
231 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
;
232 ScBigRange aBigRange
;
235 ScXMLContentChangeContext( ScXMLImport
& rImport
,
236 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
237 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
);
239 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
createFastChildContext(
240 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
242 virtual void SAL_CALL
endFastElement( sal_Int32 nElement
) override
;
245 class ScXMLInsertionContext
: public ScXMLImportContext
247 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
;
250 ScXMLInsertionContext( ScXMLImport
& rImport
,
251 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
252 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
);
254 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
createFastChildContext(
255 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
257 virtual void SAL_CALL
endFastElement( sal_Int32 nElement
) override
;
260 class ScXMLInsertionCutOffContext
: public ScXMLImportContext
263 ScXMLInsertionCutOffContext( ScXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
264 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttrList
,
265 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
);
267 virtual SvXMLImportContextRef
CreateChildContext( sal_uInt16 nPrefix
,
268 const OUString
& rLocalName
,
269 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttrList
) override
;
270 virtual void EndElement() override
;
273 class ScXMLMovementCutOffContext
: public ScXMLImportContext
276 ScXMLMovementCutOffContext( ScXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
277 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttrList
,
278 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
);
280 virtual SvXMLImportContextRef
CreateChildContext( sal_uInt16 nPrefix
,
281 const OUString
& rLocalName
,
282 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttrList
) override
;
283 virtual void EndElement() override
;
286 class ScXMLCutOffsContext
: public ScXMLImportContext
288 ScXMLChangeTrackingImportHelper
* const pChangeTrackingImportHelper
;
291 ScXMLCutOffsContext( ScXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
292 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
);
294 virtual SvXMLImportContextRef
CreateChildContext( sal_uInt16 nPrefix
,
295 const OUString
& rLocalName
,
296 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttrList
) override
;
297 virtual void EndElement() override
;
300 class ScXMLDeletionContext
: public ScXMLImportContext
302 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
;
305 ScXMLDeletionContext( ScXMLImport
& rImport
,
306 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
307 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
);
309 virtual SvXMLImportContextRef
CreateChildContext( sal_uInt16 nPrefix
,
310 const OUString
& rLocalName
,
311 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttrList
) override
;
313 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
createFastChildContext(
314 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
316 virtual void SAL_CALL
endFastElement( sal_Int32 nElement
) override
;
319 class ScXMLMovementContext
: public ScXMLImportContext
321 ScBigRange aSourceRange
;
322 ScBigRange aTargetRange
;
323 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
;
326 ScXMLMovementContext( ScXMLImport
& rImport
,
327 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
328 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
);
330 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
createFastChildContext(
331 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
333 virtual void SAL_CALL
endFastElement( sal_Int32 nElement
) override
;
336 class ScXMLRejectionContext
: public ScXMLImportContext
338 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
;
341 ScXMLRejectionContext( ScXMLImport
& rImport
,
342 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
343 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
);
345 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
createFastChildContext(
346 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
348 virtual void SAL_CALL
endFastElement( sal_Int32 nElement
) override
;
351 ScXMLTrackedChangesContext::ScXMLTrackedChangesContext( ScXMLImport
& rImport
,
352 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
353 ScXMLChangeTrackingImportHelper
* pTempChangeTrackingImportHelper
) :
354 ScXMLImportContext( rImport
),
355 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper
)
357 rImport
.LockSolarMutex();
359 if ( rAttrList
.is() )
361 auto aIter( rAttrList
->find( XML_ELEMENT( TABLE
, XML_PROTECTION_KEY
) ) );
362 if (aIter
!= rAttrList
->end())
364 if( !aIter
.isEmpty() )
366 uno::Sequence
<sal_Int8
> aPass
;
367 ::comphelper::Base64::decode( aPass
, aIter
.toString() );
368 pChangeTrackingImportHelper
->SetProtection(aPass
);
374 ScXMLTrackedChangesContext::~ScXMLTrackedChangesContext()
376 GetScImport().UnlockSolarMutex();
379 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLTrackedChangesContext::createFastChildContext(
380 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
382 SvXMLImportContext
*pContext(nullptr);
383 sax_fastparser::FastAttributeList
*pAttribList
=
384 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
388 case XML_ELEMENT( TABLE
, XML_CELL_CONTENT_CHANGE
):
389 pContext
= new ScXMLContentChangeContext(GetScImport(), pAttribList
, pChangeTrackingImportHelper
);
391 case XML_ELEMENT( TABLE
, XML_INSERTION
):
392 pContext
= new ScXMLInsertionContext(GetScImport(), pAttribList
, pChangeTrackingImportHelper
);
394 case XML_ELEMENT( TABLE
, XML_DELETION
):
395 pContext
= new ScXMLDeletionContext(GetScImport(), pAttribList
, pChangeTrackingImportHelper
);
397 case XML_ELEMENT( TABLE
, XML_MOVEMENT
):
398 pContext
= new ScXMLMovementContext(GetScImport(), pAttribList
, pChangeTrackingImportHelper
);
400 case XML_ELEMENT( TABLE
, XML_REJECTION
):
401 pContext
= new ScXMLRejectionContext(GetScImport(), pAttribList
, pChangeTrackingImportHelper
);
406 pContext
= new SvXMLImportContext( GetImport() );
411 ScXMLChangeInfoContext::ScXMLChangeInfoContext( ScXMLImport
& rImport
,
412 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
413 ScXMLChangeTrackingImportHelper
* pTempChangeTrackingImportHelper
) :
414 ScXMLImportContext( rImport
),
416 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper
),
419 if ( rAttrList
.is() )
421 for (auto &aIter
: *rAttrList
)
423 sal_Int32 nToken
= aIter
.getToken();
424 if ( nToken
== XML_ELEMENT( OFFICE
, XML_CHG_AUTHOR
) )
425 sAuthorBuffer
= aIter
.toString();
426 else if ( nToken
== XML_ELEMENT( OFFICE
, XML_CHG_DATE_TIME
) )
427 sDateTimeBuffer
= aIter
.toString();
432 SvXMLImportContextRef
ScXMLChangeInfoContext::CreateChildContext( sal_uInt16 nPrefix
,
433 const OUString
& rLocalName
,
434 const css::uno::Reference
<css::xml::sax::XAttributeList
>& /*xAttrList*/ )
436 SvXMLImportContext
*pContext(nullptr);
438 if( XML_NAMESPACE_DC
== nPrefix
)
440 if( IsXMLToken( rLocalName
, XML_CREATOR
) )
441 pContext
= new ScXMLContentContext(GetScImport(), nPrefix
,
442 rLocalName
, sAuthorBuffer
);
443 else if( IsXMLToken( rLocalName
, XML_DATE
) )
444 pContext
= new ScXMLContentContext(GetScImport(), nPrefix
,
445 rLocalName
, sDateTimeBuffer
);
447 else if ((nPrefix
== XML_NAMESPACE_TEXT
) && (IsXMLToken(rLocalName
, XML_P
)) )
450 sCommentBuffer
.append('\n');
452 pContext
= new ScXMLContentContext( GetScImport(), nPrefix
, rLocalName
, sCommentBuffer
);
456 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
461 void SAL_CALL
ScXMLChangeInfoContext::endFastElement( sal_Int32
/*nElement*/ )
463 aInfo
.sUser
= sAuthorBuffer
.makeStringAndClear();
464 ::sax::Converter::parseDateTime(aInfo
.aDateTime
,
465 sDateTimeBuffer
.makeStringAndClear());
466 aInfo
.sComment
= sCommentBuffer
.makeStringAndClear();
467 pChangeTrackingImportHelper
->SetActionInfo(aInfo
);
470 ScXMLBigRangeContext::ScXMLBigRangeContext( ScXMLImport
& rImport
,
471 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
472 ScBigRange
& rBigRange
) :
473 ScXMLImportContext( rImport
)
478 sal_Int32
nColumn(0);
481 sal_Int32
nStartColumn(0);
482 sal_Int32
nEndColumn(0);
483 sal_Int32
nStartRow(0);
484 sal_Int32
nEndRow(0);
485 sal_Int32
nStartTable(0);
486 sal_Int32
nEndTable(0);
487 if ( rAttrList
.is() )
489 for (auto &aIter
: *rAttrList
)
491 switch (aIter
.getToken())
493 case XML_ELEMENT( TABLE
, XML_COLUMN
):
494 nColumn
= aIter
.toInt32();
497 case XML_ELEMENT( TABLE
, XML_ROW
):
498 nRow
= aIter
.toInt32();
501 case XML_ELEMENT( TABLE
, XML_TABLE
):
502 nTable
= aIter
.toInt32();
505 case XML_ELEMENT( TABLE
, XML_START_COLUMN
):
506 nStartColumn
= aIter
.toInt32();
508 case XML_ELEMENT( TABLE
, XML_END_COLUMN
):
509 nEndColumn
= aIter
.toInt32();
511 case XML_ELEMENT( TABLE
, XML_START_ROW
):
512 nStartRow
= aIter
.toInt32();
514 case XML_ELEMENT( TABLE
, XML_END_ROW
):
515 nEndRow
= aIter
.toInt32();
517 case XML_ELEMENT( TABLE
, XML_START_TABLE
):
518 nStartTable
= aIter
.toInt32();
520 case XML_ELEMENT( TABLE
, XML_END_TABLE
):
521 nEndTable
= aIter
.toInt32();
528 nStartColumn
= nEndColumn
= nColumn
;
530 nStartRow
= nEndRow
= nRow
;
532 nStartTable
= nEndTable
= nTable
;
533 rBigRange
.Set(nStartColumn
, nStartRow
, nStartTable
,
534 nEndColumn
, nEndRow
, nEndTable
);
537 ScXMLCellContentDeletionContext::ScXMLCellContentDeletionContext( ScXMLImport
& rImport
,
538 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
539 ScXMLChangeTrackingImportHelper
* pTempChangeTrackingImportHelper
) :
540 ScXMLImportContext( rImport
),
542 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper
),
546 eGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT
),
547 nType(css::util::NumberFormat::ALL
),
548 nMatrixFlag(ScMatrixMode::NONE
)
550 if ( rAttrList
.is() )
552 auto aIter( rAttrList
->find( XML_ELEMENT( TABLE
, XML_ID
) ) );
553 if (aIter
!= rAttrList
->end())
554 nID
= ScXMLChangeTrackingImportHelper::GetIDFromString( aIter
.toString() );
558 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLCellContentDeletionContext::createFastChildContext(
559 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
561 SvXMLImportContext
*pContext(nullptr);
562 sax_fastparser::FastAttributeList
*pAttribList
=
563 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
567 case XML_ELEMENT( TABLE
, XML_CHANGE_TRACK_TABLE_CELL
):
568 pContext
= new ScXMLChangeCellContext(GetScImport(), pAttribList
,
569 maCell
, sFormulaAddress
, sFormula
, sFormulaNmsp
, eGrammar
, sInputString
, fValue
, nType
, nMatrixFlag
, nMatrixCols
, nMatrixRows
);
571 case XML_ELEMENT( TABLE
, XML_CELL_ADDRESS
):
572 OSL_ENSURE(!nID
, "a action with a ID should not contain a BigRange");
573 pContext
= new ScXMLBigRangeContext(GetScImport(), pAttribList
, aBigRange
);
578 pContext
= new SvXMLImportContext( GetImport() );
583 void SAL_CALL
ScXMLCellContentDeletionContext::endFastElement( sal_Int32
/*nElement*/ )
585 std::unique_ptr
<ScMyCellInfo
> pCellInfo(new ScMyCellInfo(maCell
, sFormulaAddress
, sFormula
, eGrammar
, sInputString
, fValue
, nType
,
586 nMatrixFlag
, nMatrixCols
, nMatrixRows
));
588 pChangeTrackingImportHelper
->AddDeleted(nID
, std::move(pCellInfo
));
590 pChangeTrackingImportHelper
->AddGenerated(std::move(pCellInfo
), aBigRange
);
593 ScXMLDependenceContext::ScXMLDependenceContext( ScXMLImport
& rImport
,
594 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
595 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
) :
596 ScXMLImportContext( rImport
)
599 if ( rAttrList
.is() )
601 auto aIter( rAttrList
->find( XML_ELEMENT( TABLE
, XML_ID
) ) );
602 if (aIter
!= rAttrList
->end())
603 nID
= ScXMLChangeTrackingImportHelper::GetIDFromString(aIter
.toString());
605 pChangeTrackingImportHelper
->AddDependence(nID
);
608 ScXMLDependingsContext::ScXMLDependingsContext( ScXMLImport
& rImport
,
609 ScXMLChangeTrackingImportHelper
* pTempChangeTrackingImportHelper
) :
610 ScXMLImportContext( rImport
),
611 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper
)
613 // here are no attributes
616 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLDependingsContext::createFastChildContext(
617 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
619 SvXMLImportContext
*pContext(nullptr);
620 sax_fastparser::FastAttributeList
*pAttribList
=
621 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
623 // #i80033# read both old (dependence) and new (dependency) elements
624 if (nElement
== XML_ELEMENT( TABLE
, XML_DEPENDENCE
) ||
625 nElement
== XML_ELEMENT( TABLE
, XML_DEPENDENCY
))
627 pContext
= new ScXMLDependenceContext(GetScImport(), pAttribList
, pChangeTrackingImportHelper
);
631 pContext
= new SvXMLImportContext( GetImport() );
636 ScXMLChangeDeletionContext::ScXMLChangeDeletionContext( ScXMLImport
& rImport
,
637 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
638 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
) :
639 ScXMLImportContext( rImport
)
642 if ( rAttrList
.is() )
644 auto aIter( rAttrList
->find( XML_ELEMENT( TABLE
, XML_ID
) ) );
645 if (aIter
!= rAttrList
->end())
646 nID
= ScXMLChangeTrackingImportHelper::GetIDFromString( aIter
.toString() );
648 pChangeTrackingImportHelper
->AddDeleted(nID
);
651 ScXMLDeletionsContext::ScXMLDeletionsContext( ScXMLImport
& rImport
,
652 ScXMLChangeTrackingImportHelper
* pTempChangeTrackingImportHelper
) :
653 ScXMLImportContext( rImport
),
654 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper
)
656 // here are no attributes
659 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLDeletionsContext::createFastChildContext(
660 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
662 SvXMLImportContext
*pContext(nullptr);
663 sax_fastparser::FastAttributeList
*pAttribList
=
664 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
668 case XML_ELEMENT( TABLE
, XML_CHANGE_DELETION
):
669 pContext
= new ScXMLChangeDeletionContext(GetScImport(), pAttribList
, pChangeTrackingImportHelper
);
671 case XML_ELEMENT( TABLE
, XML_CELL_CONTENT_DELETION
):
672 pContext
= new ScXMLCellContentDeletionContext(GetScImport(), pAttribList
, pChangeTrackingImportHelper
);
677 pContext
= new SvXMLImportContext( GetImport() );
682 ScXMLChangeTextPContext::ScXMLChangeTextPContext( ScXMLImport
& rImport
,
684 const OUString
& rLName
,
685 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xTempAttrList
,
686 ScXMLChangeCellContext
* pTempChangeCellContext
) :
687 ScXMLImportContext( rImport
, nPrfx
, rLName
),
688 xAttrList(xTempAttrList
),
691 pChangeCellContext(pTempChangeCellContext
),
694 // here are no attributes
697 SvXMLImportContextRef
ScXMLChangeTextPContext::CreateChildContext( sal_uInt16 nTempPrefix
,
698 const OUString
& rLName
,
699 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xTempAttrList
)
701 SvXMLImportContextRef xContext
;
703 if ((nPrefix
== XML_NAMESPACE_TEXT
) && (IsXMLToken(rLName
, XML_S
)) && !pTextPContext
)
705 sal_Int32
nRepeat(0);
706 sal_Int16
nAttrCount(xAttrList
.is() ? xAttrList
->getLength() : 0);
707 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
709 const OUString
& sAttrName(xAttrList
->getNameByIndex( i
));
710 const OUString
& sValue(xAttrList
->getValueByIndex( i
));
712 sal_uInt16
nPrfx(GetScImport().GetNamespaceMap().GetKeyByAttrName(
713 sAttrName
, &aLocalName
));
714 if ((nPrfx
== XML_NAMESPACE_TEXT
) && (IsXMLToken(aLocalName
, XML_C
)))
715 nRepeat
= sValue
.toInt32();
718 for (sal_Int32 j
= 0; j
< nRepeat
; ++j
)
725 if (!pChangeCellContext
->IsEditCell())
726 pChangeCellContext
->CreateTextPContext(false);
727 bool bWasContext (true);
731 pTextPContext
= GetScImport().GetTextImport()->CreateTextChildContext(
732 GetScImport(), nPrefix
, sLName
, xAttrList
);
737 pTextPContext
->Characters(sText
.makeStringAndClear());
738 xContext
= pTextPContext
->CreateChildContext(nTempPrefix
, rLName
, xTempAttrList
);
743 xContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
748 void ScXMLChangeTextPContext::Characters( const OUString
& rChars
)
751 sText
.append(rChars
);
753 pTextPContext
->Characters(rChars
);
756 void ScXMLChangeTextPContext::EndElement()
759 pChangeCellContext
->SetText(sText
.makeStringAndClear());
762 ScXMLChangeCellContext::ScXMLChangeCellContext( ScXMLImport
& rImport
,
763 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
764 ScCellValue
& rOldCell
, OUString
& rAddress
,
765 OUString
& rFormula
, OUString
& rFormulaNmsp
,
766 formula::FormulaGrammar::Grammar
& rGrammar
,
767 OUString
& rTempInputString
, double& rDateTimeValue
, sal_uInt16
& nType
,
768 ScMatrixMode
& nMatrixFlag
, sal_Int32
& nMatrixCols
, sal_Int32
& nMatrixRows
)
769 : ScXMLImportContext( rImport
)
770 , mrOldCell(rOldCell
)
771 , rInputString(rTempInputString
)
775 , bFirstParagraph(true)
779 bool bIsMatrix(false);
780 bool bIsCoveredMatrix(false);
781 if ( rAttrList
.is() )
783 for (auto &aIter
: *rAttrList
)
785 switch (aIter
.getToken())
787 case XML_ELEMENT( TABLE
, XML_FORMULA
):
789 GetScImport().ExtractFormulaNamespaceGrammar( rFormula
, rFormulaNmsp
, rGrammar
, aIter
.toString() );
792 case XML_ELEMENT( TABLE
, XML_CELL_ADDRESS
):
793 rAddress
= aIter
.toString();
795 case XML_ELEMENT( TABLE
, XML_MATRIX_COVERED
):
796 bIsCoveredMatrix
= IsXMLToken(aIter
, XML_TRUE
);
798 case XML_ELEMENT( TABLE
, XML_NUMBER_MATRIX_COLUMNS_SPANNED
):
800 nMatrixCols
= aIter
.toInt32();
802 case XML_ELEMENT( TABLE
, XML_NUMBER_MATRIX_ROWS_SPANNED
):
804 nMatrixRows
= aIter
.toInt32();
806 case XML_ELEMENT( OFFICE
, XML_VALUE_TYPE
):
807 if (IsXMLToken(aIter
, XML_FLOAT
))
809 else if (IsXMLToken(aIter
, XML_DATE
))
811 rType
= css::util::NumberFormat::DATE
;
814 else if (IsXMLToken(aIter
, XML_TIME
))
816 rType
= css::util::NumberFormat::TIME
;
820 case XML_ELEMENT( OFFICE
, XML_VALUE
):
821 fValue
= aIter
.toDouble();
824 case XML_ELEMENT( OFFICE
, XML_DATE_VALUE
):
826 if (GetScImport().GetMM100UnitConverter().setNullDate(GetScImport().GetModel()))
827 GetScImport().GetMM100UnitConverter().convertDateTime(rDateTimeValue
, aIter
.toString());
828 fValue
= rDateTimeValue
;
830 case XML_ELEMENT( OFFICE
, XML_TIME_VALUE
):
832 ::sax::Converter::convertDuration(rDateTimeValue
, aIter
.toString());
833 fValue
= rDateTimeValue
;
838 if (bIsCoveredMatrix
)
839 nMatrixFlag
= ScMatrixMode::Reference
;
840 else if (bIsMatrix
&& nMatrixRows
&& nMatrixCols
)
841 nMatrixFlag
= ScMatrixMode::Formula
;
844 SvXMLImportContextRef
ScXMLChangeCellContext::CreateChildContext( sal_uInt16 nPrefix
,
845 const OUString
& rLocalName
,
846 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttrList
)
848 SvXMLImportContext
*pContext(nullptr);
850 if ((nPrefix
== XML_NAMESPACE_TEXT
) && (IsXMLToken(rLocalName
, XML_P
)))
855 pContext
= new ScXMLChangeTextPContext(GetScImport(), nPrefix
, rLocalName
, xAttrList
, this);
856 bFirstParagraph
= false;
860 if (!mpEditTextObj
.is())
861 CreateTextPContext(true);
862 pContext
= GetScImport().GetTextImport()->CreateTextChildContext(
863 GetScImport(), nPrefix
, rLocalName
, xAttrList
);
868 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
873 void ScXMLChangeCellContext::CreateTextPContext(bool bIsNewParagraph
)
875 if (GetScImport().GetDocument())
877 mpEditTextObj
= new ScEditEngineTextObj();
878 mpEditTextObj
->GetEditEngine()->SetEditTextObjectPool(GetScImport().GetDocument()->GetEditPool());
879 uno::Reference
<text::XText
> xText(mpEditTextObj
.get());
882 uno::Reference
<text::XTextCursor
> xTextCursor(xText
->createTextCursor());
885 xText
->setString(sText
);
886 xTextCursor
->gotoEnd(false);
887 xText
->insertControlCharacter(xTextCursor
, text::ControlCharacter::PARAGRAPH_BREAK
, false);
889 GetScImport().GetTextImport()->SetCursor(xTextCursor
);
894 void SAL_CALL
ScXMLChangeCellContext::endFastElement( sal_Int32
/*nElement*/ )
898 ScDocument
* pDoc
= GetScImport().GetDocument();
899 if (mpEditTextObj
.is())
901 if (GetImport().GetTextImport()->GetCursor().is())
903 //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
904 if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
906 GetImport().GetTextImport()->GetText()->insertString(
907 GetImport().GetTextImport()->GetCursorAsRange(), "",
912 // The cell will own the text object instance.
913 mrOldCell
.meType
= CELLTYPE_EDIT
;
914 mrOldCell
.mpEditText
= mpEditTextObj
->CreateTextObject().release();
915 GetScImport().GetTextImport()->ResetCursor();
916 mpEditTextObj
.clear();
922 if (!sText
.isEmpty() && bString
)
924 mrOldCell
.meType
= CELLTYPE_STRING
;
925 mrOldCell
.mpString
= new svl::SharedString(pDoc
->GetSharedStringPool().intern(sText
));
929 mrOldCell
.meType
= CELLTYPE_VALUE
;
930 mrOldCell
.mfValue
= fValue
;
932 if (rType
== css::util::NumberFormat::DATE
|| rType
== css::util::NumberFormat::TIME
)
933 rInputString
= sText
;
941 ScXMLPreviousContext::ScXMLPreviousContext( ScXMLImport
& rImport
,
942 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
943 ScXMLChangeTrackingImportHelper
* pTempChangeTrackingImportHelper
) :
944 ScXMLImportContext( rImport
),
946 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper
),
950 eGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT
),
951 nType(css::util::NumberFormat::ALL
),
952 nMatrixFlag(ScMatrixMode::NONE
)
954 if ( rAttrList
.is() )
956 auto aIter( rAttrList
->find( XML_ELEMENT( TABLE
, XML_ID
) ) );
957 if (aIter
!= rAttrList
->end())
958 nID
= ScXMLChangeTrackingImportHelper::GetIDFromString( aIter
.toString() );
962 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLPreviousContext::createFastChildContext(
963 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
965 SvXMLImportContext
*pContext(nullptr);
966 sax_fastparser::FastAttributeList
*pAttribList
=
967 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
969 if ( nElement
== XML_ELEMENT( TABLE
, XML_CHANGE_TRACK_TABLE_CELL
) )
970 pContext
= new ScXMLChangeCellContext(GetScImport(), pAttribList
,
971 maOldCell
, sFormulaAddress
, sFormula
, sFormulaNmsp
, eGrammar
, sInputString
, fValue
, nType
, nMatrixFlag
, nMatrixCols
, nMatrixRows
);
974 pContext
= new SvXMLImportContext( GetImport() );
979 void SAL_CALL
ScXMLPreviousContext::endFastElement( sal_Int32
/*nElement*/ )
981 pChangeTrackingImportHelper
->SetPreviousChange(nID
, new ScMyCellInfo(maOldCell
, sFormulaAddress
, sFormula
, eGrammar
, sInputString
,
982 fValue
, nType
, nMatrixFlag
, nMatrixCols
, nMatrixRows
));
985 ScXMLContentChangeContext::ScXMLContentChangeContext( ScXMLImport
& rImport
,
986 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
987 ScXMLChangeTrackingImportHelper
* pTempChangeTrackingImportHelper
) :
988 ScXMLImportContext( rImport
),
989 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper
)
991 sal_uInt32
nActionNumber(0);
992 sal_uInt32
nRejectingNumber(0);
993 ScChangeActionState
nActionState(SC_CAS_VIRGIN
);
995 if ( rAttrList
.is() )
997 for (auto &aIter
: *rAttrList
)
999 switch (aIter
.getToken())
1001 case XML_ELEMENT( TABLE
, XML_ID
):
1002 nActionNumber
= ScXMLChangeTrackingImportHelper::GetIDFromString( aIter
.toString() );
1004 case XML_ELEMENT( TABLE
, XML_ACCEPTANCE_STATE
):
1005 if (IsXMLToken( aIter
, XML_ACCEPTED
))
1006 nActionState
= SC_CAS_ACCEPTED
;
1007 else if (IsXMLToken( aIter
, XML_REJECTED
))
1008 nActionState
= SC_CAS_REJECTED
;
1010 case XML_ELEMENT( TABLE
, XML_REJECTING_CHANGE_ID
):
1011 nRejectingNumber
= ScXMLChangeTrackingImportHelper::GetIDFromString( aIter
.toString() );
1016 pChangeTrackingImportHelper
->StartChangeAction(SC_CAT_CONTENT
);
1017 pChangeTrackingImportHelper
->SetActionNumber(nActionNumber
);
1018 pChangeTrackingImportHelper
->SetActionState(nActionState
);
1019 pChangeTrackingImportHelper
->SetRejectingNumber(nRejectingNumber
);
1022 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLContentChangeContext::createFastChildContext(
1023 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
1025 SvXMLImportContext
*pContext(nullptr);
1026 sax_fastparser::FastAttributeList
*pAttribList
=
1027 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
1031 case XML_ELEMENT( OFFICE
, XML_CHANGE_INFO
):
1032 pContext
= new ScXMLChangeInfoContext(GetScImport(), pAttribList
, pChangeTrackingImportHelper
);
1034 case XML_ELEMENT( TABLE
, XML_CELL_ADDRESS
):
1035 pContext
= new ScXMLBigRangeContext(GetScImport(), pAttribList
, aBigRange
);
1037 case XML_ELEMENT( TABLE
, XML_DEPENDENCIES
):
1038 pContext
= new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper
);
1040 case XML_ELEMENT( TABLE
, XML_DELETIONS
):
1041 pContext
= new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper
);
1043 case XML_ELEMENT( TABLE
, XML_PREVIOUS
):
1044 pContext
= new ScXMLPreviousContext(GetScImport(), pAttribList
, pChangeTrackingImportHelper
);
1049 pContext
= new SvXMLImportContext( GetImport() );
1054 void SAL_CALL
ScXMLContentChangeContext::endFastElement( sal_Int32
/*nElement*/ )
1056 pChangeTrackingImportHelper
->SetBigRange(aBigRange
);
1057 pChangeTrackingImportHelper
->EndChangeAction();
1060 ScXMLInsertionContext::ScXMLInsertionContext( ScXMLImport
& rImport
,
1061 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
1062 ScXMLChangeTrackingImportHelper
* pTempChangeTrackingImportHelper
) :
1063 ScXMLImportContext( rImport
),
1064 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper
)
1066 sal_uInt32
nActionNumber(0);
1067 sal_uInt32
nRejectingNumber(0);
1068 sal_Int32
nPosition(0);
1069 sal_Int32
nCount(1);
1070 sal_Int32
nTable(0);
1071 ScChangeActionState
nActionState(SC_CAS_VIRGIN
);
1072 ScChangeActionType
nActionType(SC_CAT_INSERT_COLS
);
1074 if ( rAttrList
.is() )
1076 for (auto &aIter
: *rAttrList
)
1078 switch (aIter
.getToken())
1080 case XML_ELEMENT( TABLE
, XML_ID
):
1081 nActionNumber
= ScXMLChangeTrackingImportHelper::GetIDFromString( aIter
.toString() );
1083 case XML_ELEMENT( TABLE
, XML_ACCEPTANCE_STATE
):
1084 if (IsXMLToken( aIter
, XML_ACCEPTED
))
1085 nActionState
= SC_CAS_ACCEPTED
;
1086 else if (IsXMLToken( aIter
, XML_REJECTED
))
1087 nActionState
= SC_CAS_REJECTED
;
1089 case XML_ELEMENT( TABLE
, XML_REJECTING_CHANGE_ID
):
1090 nRejectingNumber
= ScXMLChangeTrackingImportHelper::GetIDFromString( aIter
.toString() );
1092 case XML_ELEMENT( TABLE
, XML_TYPE
):
1093 if (IsXMLToken( aIter
, XML_ROW
))
1094 nActionType
= SC_CAT_INSERT_ROWS
;
1095 else if (IsXMLToken( aIter
, XML_TABLE
))
1096 nActionType
= SC_CAT_INSERT_TABS
;
1098 case XML_ELEMENT( TABLE
, XML_POSITION
):
1099 nPosition
= aIter
.toInt32();
1101 case XML_ELEMENT( TABLE
, XML_TABLE
):
1102 nTable
= aIter
.toInt32();
1104 case XML_ELEMENT( TABLE
, XML_COUNT
):
1105 nCount
= aIter
.toInt32();
1111 pChangeTrackingImportHelper
->StartChangeAction(nActionType
);
1112 pChangeTrackingImportHelper
->SetActionNumber(nActionNumber
);
1113 pChangeTrackingImportHelper
->SetActionState(nActionState
);
1114 pChangeTrackingImportHelper
->SetRejectingNumber(nRejectingNumber
);
1115 pChangeTrackingImportHelper
->SetPosition(nPosition
, nCount
, nTable
);
1118 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLInsertionContext::createFastChildContext(
1119 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
1121 SvXMLImportContext
*pContext(nullptr);
1122 sax_fastparser::FastAttributeList
*pAttribList
=
1123 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
1127 case XML_ELEMENT( OFFICE
, XML_CHANGE_INFO
):
1128 pContext
= new ScXMLChangeInfoContext(GetScImport(), pAttribList
, pChangeTrackingImportHelper
);
1130 case XML_ELEMENT( TABLE
, XML_DEPENDENCIES
):
1131 pContext
= new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper
);
1133 case XML_ELEMENT( TABLE
, XML_DELETIONS
):
1134 pContext
= new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper
);
1139 pContext
= new SvXMLImportContext( GetImport() );
1144 void SAL_CALL
ScXMLInsertionContext::endFastElement( sal_Int32
/*nElement*/ )
1146 pChangeTrackingImportHelper
->EndChangeAction();
1149 ScXMLInsertionCutOffContext::ScXMLInsertionCutOffContext( ScXMLImport
& rImport
,
1151 const OUString
& rLName
,
1152 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
,
1153 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
) :
1154 ScXMLImportContext( rImport
, nPrfx
, rLName
)
1157 sal_Int32
nPosition(0);
1158 sal_Int16
nAttrCount(xAttrList
.is() ? xAttrList
->getLength() : 0);
1159 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
1161 const OUString
& sAttrName(xAttrList
->getNameByIndex( i
));
1162 OUString aLocalName
;
1163 sal_uInt16
nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
1164 sAttrName
, &aLocalName
));
1165 const OUString
& sValue(xAttrList
->getValueByIndex( i
));
1167 if (nPrefix
== XML_NAMESPACE_TABLE
)
1169 if (IsXMLToken(aLocalName
, XML_ID
))
1171 nID
= ScXMLChangeTrackingImportHelper::GetIDFromString(sValue
);
1173 else if (IsXMLToken(aLocalName
, XML_POSITION
))
1175 ::sax::Converter::convertNumber(nPosition
, sValue
);
1179 pChangeTrackingImportHelper
->SetInsertionCutOff(nID
, nPosition
);
1182 SvXMLImportContextRef
ScXMLInsertionCutOffContext::CreateChildContext( sal_uInt16 nPrefix
,
1183 const OUString
& rLocalName
,
1184 const css::uno::Reference
<css::xml::sax::XAttributeList
>& /* xAttrList */ )
1186 return new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
1189 void ScXMLInsertionCutOffContext::EndElement()
1193 ScXMLMovementCutOffContext::ScXMLMovementCutOffContext( ScXMLImport
& rImport
,
1195 const OUString
& rLName
,
1196 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
,
1197 ScXMLChangeTrackingImportHelper
* pChangeTrackingImportHelper
) :
1198 ScXMLImportContext( rImport
, nPrfx
, rLName
)
1201 sal_Int32
nPosition(0);
1202 sal_Int32
nStartPosition(0);
1203 sal_Int32
nEndPosition(0);
1204 bool bPosition(false);
1205 sal_Int16
nAttrCount(xAttrList
.is() ? xAttrList
->getLength() : 0);
1206 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
1208 const OUString
& sAttrName(xAttrList
->getNameByIndex( i
));
1209 OUString aLocalName
;
1210 sal_uInt16
nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
1211 sAttrName
, &aLocalName
));
1212 const OUString
& sValue(xAttrList
->getValueByIndex( i
));
1214 if (nPrefix
== XML_NAMESPACE_TABLE
)
1216 if (IsXMLToken(aLocalName
, XML_ID
))
1218 nID
= ScXMLChangeTrackingImportHelper::GetIDFromString(sValue
);
1220 else if (IsXMLToken(aLocalName
, XML_POSITION
))
1223 ::sax::Converter::convertNumber(nPosition
, sValue
);
1225 else if (IsXMLToken(aLocalName
, XML_START_POSITION
))
1227 ::sax::Converter::convertNumber(nStartPosition
, sValue
);
1229 else if (IsXMLToken(aLocalName
, XML_END_POSITION
))
1231 ::sax::Converter::convertNumber(nEndPosition
, sValue
);
1236 nStartPosition
= nEndPosition
= nPosition
;
1237 pChangeTrackingImportHelper
->AddMoveCutOff(nID
, nStartPosition
, nEndPosition
);
1240 SvXMLImportContextRef
ScXMLMovementCutOffContext::CreateChildContext( sal_uInt16 nPrefix
,
1241 const OUString
& rLocalName
,
1242 const css::uno::Reference
<css::xml::sax::XAttributeList
>& /* xAttrList */ )
1244 return new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
1247 void ScXMLMovementCutOffContext::EndElement()
1251 ScXMLCutOffsContext::ScXMLCutOffsContext( ScXMLImport
& rImport
,
1253 const OUString
& rLName
,
1254 ScXMLChangeTrackingImportHelper
* pTempChangeTrackingImportHelper
) :
1255 ScXMLImportContext( rImport
, nPrfx
, rLName
),
1256 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper
)
1258 // here are no attributes
1261 SvXMLImportContextRef
ScXMLCutOffsContext::CreateChildContext( sal_uInt16 nPrefix
,
1262 const OUString
& rLocalName
,
1263 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttrList
)
1265 SvXMLImportContext
*pContext(nullptr);
1267 if (nPrefix
== XML_NAMESPACE_TABLE
)
1269 if (IsXMLToken(rLocalName
, XML_INSERTION_CUT_OFF
))
1270 pContext
= new ScXMLInsertionCutOffContext(GetScImport(), nPrefix
, rLocalName
, xAttrList
, pChangeTrackingImportHelper
);
1271 else if (IsXMLToken(rLocalName
, XML_MOVEMENT_CUT_OFF
))
1272 pContext
= new ScXMLMovementCutOffContext(GetScImport(), nPrefix
, rLocalName
, xAttrList
, pChangeTrackingImportHelper
);
1276 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
1281 void ScXMLCutOffsContext::EndElement()
1285 ScXMLDeletionContext::ScXMLDeletionContext( ScXMLImport
& rImport
,
1286 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
1287 ScXMLChangeTrackingImportHelper
* pTempChangeTrackingImportHelper
) :
1288 ScXMLImportContext( rImport
),
1289 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper
)
1291 sal_uInt32
nActionNumber(0);
1292 sal_uInt32
nRejectingNumber(0);
1293 sal_Int32
nPosition(0);
1294 sal_Int32
nMultiSpanned(0);
1295 sal_Int32
nTable(0);
1296 ScChangeActionState
nActionState(SC_CAS_VIRGIN
);
1297 ScChangeActionType
nActionType(SC_CAT_DELETE_COLS
);
1299 if ( rAttrList
.is() )
1301 for (auto &aIter
: *rAttrList
)
1303 sal_Int32 nToken
= aIter
.getToken();
1306 case XML_ELEMENT( TABLE
, XML_ID
):
1307 nActionNumber
= ScXMLChangeTrackingImportHelper::GetIDFromString( aIter
.toString() );
1309 case XML_ELEMENT( TABLE
, XML_ACCEPTANCE_STATE
):
1310 if (IsXMLToken( aIter
, XML_ACCEPTED
))
1311 nActionState
= SC_CAS_ACCEPTED
;
1312 else if (IsXMLToken( aIter
, XML_REJECTED
))
1313 nActionState
= SC_CAS_REJECTED
;
1315 case XML_ELEMENT( TABLE
, XML_REJECTING_CHANGE_ID
):
1316 nRejectingNumber
= ScXMLChangeTrackingImportHelper::GetIDFromString( aIter
.toString() );
1318 case XML_ELEMENT( TABLE
, XML_TYPE
):
1319 if (IsXMLToken( aIter
, XML_ROW
))
1320 nActionType
= SC_CAT_DELETE_ROWS
;
1321 else if (IsXMLToken( aIter
, XML_TABLE
))
1322 nActionType
= SC_CAT_DELETE_TABS
;
1324 case XML_ELEMENT( TABLE
, XML_POSITION
):
1325 nPosition
= aIter
.toInt32();
1327 case XML_ELEMENT( TABLE
, XML_TABLE
):
1328 nTable
= aIter
.toInt32();
1330 case XML_ELEMENT( TABLE
, XML_MULTI_DELETION_SPANNED
):
1331 nMultiSpanned
= aIter
.toInt32();
1337 pChangeTrackingImportHelper
->StartChangeAction(nActionType
);
1338 pChangeTrackingImportHelper
->SetActionNumber(nActionNumber
);
1339 pChangeTrackingImportHelper
->SetActionState(nActionState
);
1340 pChangeTrackingImportHelper
->SetRejectingNumber(nRejectingNumber
);
1341 pChangeTrackingImportHelper
->SetPosition(nPosition
, 1, nTable
);
1342 pChangeTrackingImportHelper
->SetMultiSpanned(static_cast<sal_Int16
>(nMultiSpanned
));
1345 SvXMLImportContextRef
ScXMLDeletionContext::CreateChildContext( sal_uInt16 nPrefix
,
1346 const OUString
& rLocalName
,
1347 const css::uno::Reference
<css::xml::sax::XAttributeList
>& /*xAttrList*/ )
1349 SvXMLImportContext
*pContext(nullptr);
1351 if (nPrefix
== XML_NAMESPACE_TABLE
)
1353 if (IsXMLToken(rLocalName
, XML_CUT_OFFS
) || rLocalName
== "cut_offs")
1354 pContext
= new ScXMLCutOffsContext(GetScImport(), nPrefix
, rLocalName
, pChangeTrackingImportHelper
);
1357 OSL_FAIL("don't know this");
1362 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
1367 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLDeletionContext::createFastChildContext(
1368 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
1370 SvXMLImportContext
*pContext(nullptr);
1371 sax_fastparser::FastAttributeList
*pAttribList
=
1372 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
1376 case XML_ELEMENT( OFFICE
, XML_CHANGE_INFO
):
1377 pContext
= new ScXMLChangeInfoContext(GetScImport(), pAttribList
, pChangeTrackingImportHelper
);
1379 case XML_ELEMENT( TABLE
, XML_DEPENDENCIES
):
1380 pContext
= new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper
);
1382 case XML_ELEMENT( TABLE
, XML_DELETIONS
):
1383 pContext
= new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper
);
1388 pContext
= new SvXMLImportContext( GetImport() );
1393 void SAL_CALL
ScXMLDeletionContext::endFastElement( sal_Int32
/*nElement*/ )
1395 pChangeTrackingImportHelper
->EndChangeAction();
1398 ScXMLMovementContext::ScXMLMovementContext( ScXMLImport
& rImport
,
1399 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
1400 ScXMLChangeTrackingImportHelper
* pTempChangeTrackingImportHelper
) :
1401 ScXMLImportContext( rImport
),
1402 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper
)
1404 sal_uInt32
nActionNumber(0);
1405 sal_uInt32
nRejectingNumber(0);
1406 ScChangeActionState
nActionState(SC_CAS_VIRGIN
);
1408 if ( rAttrList
.is() )
1410 for (auto &aIter
: *rAttrList
)
1412 switch (aIter
.getToken())
1414 case XML_ELEMENT( TABLE
, XML_ID
):
1415 nActionNumber
= ScXMLChangeTrackingImportHelper::GetIDFromString( aIter
.toString() );
1417 case XML_ELEMENT( TABLE
, XML_ACCEPTANCE_STATE
):
1418 if (IsXMLToken( aIter
, XML_ACCEPTED
))
1419 nActionState
= SC_CAS_ACCEPTED
;
1420 else if (IsXMLToken( aIter
, XML_REJECTED
))
1421 nActionState
= SC_CAS_REJECTED
;
1423 case XML_ELEMENT( TABLE
, XML_REJECTING_CHANGE_ID
):
1424 nRejectingNumber
= ScXMLChangeTrackingImportHelper::GetIDFromString( aIter
.toString() );
1430 pChangeTrackingImportHelper
->StartChangeAction(SC_CAT_MOVE
);
1431 pChangeTrackingImportHelper
->SetActionNumber(nActionNumber
);
1432 pChangeTrackingImportHelper
->SetActionState(nActionState
);
1433 pChangeTrackingImportHelper
->SetRejectingNumber(nRejectingNumber
);
1436 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLMovementContext::createFastChildContext(
1437 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
1439 SvXMLImportContext
*pContext(nullptr);
1440 sax_fastparser::FastAttributeList
*pAttribList
=
1441 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
1445 case XML_ELEMENT( OFFICE
, XML_CHANGE_INFO
):
1446 pContext
= new ScXMLChangeInfoContext(GetScImport(), pAttribList
, pChangeTrackingImportHelper
);
1448 case XML_ELEMENT( TABLE
, XML_DEPENDENCIES
):
1449 pContext
= new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper
);
1451 case XML_ELEMENT( TABLE
, XML_DELETIONS
):
1452 pContext
= new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper
);
1454 case XML_ELEMENT( TABLE
, XML_SOURCE_RANGE_ADDRESS
):
1455 pContext
= new ScXMLBigRangeContext(GetScImport(), pAttribList
, aSourceRange
);
1457 case XML_ELEMENT( TABLE
, XML_TARGET_RANGE_ADDRESS
):
1458 pContext
= new ScXMLBigRangeContext(GetScImport(), pAttribList
, aTargetRange
);
1463 pContext
= new SvXMLImportContext( GetImport() );
1468 void SAL_CALL
ScXMLMovementContext::endFastElement( sal_Int32
/*nElement*/ )
1470 pChangeTrackingImportHelper
->SetMoveRanges(aSourceRange
, aTargetRange
);
1471 pChangeTrackingImportHelper
->EndChangeAction();
1474 ScXMLRejectionContext::ScXMLRejectionContext( ScXMLImport
& rImport
,
1475 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
1476 ScXMLChangeTrackingImportHelper
* pTempChangeTrackingImportHelper
) :
1477 ScXMLImportContext( rImport
),
1478 pChangeTrackingImportHelper(pTempChangeTrackingImportHelper
)
1480 sal_uInt32
nActionNumber(0);
1481 sal_uInt32
nRejectingNumber(0);
1482 ScChangeActionState
nActionState(SC_CAS_VIRGIN
);
1484 if ( rAttrList
.is() )
1486 for (auto &aIter
: *rAttrList
)
1488 switch (aIter
.getToken())
1490 case XML_ELEMENT( TABLE
, XML_ID
):
1491 nActionNumber
= ScXMLChangeTrackingImportHelper::GetIDFromString( aIter
.toString() );
1493 case XML_ELEMENT( TABLE
, XML_ACCEPTANCE_STATE
):
1494 if (IsXMLToken( aIter
, XML_ACCEPTED
))
1495 nActionState
= SC_CAS_ACCEPTED
;
1496 else if (IsXMLToken( aIter
, XML_REJECTED
))
1497 nActionState
= SC_CAS_REJECTED
;
1499 case XML_ELEMENT( TABLE
, XML_REJECTING_CHANGE_ID
):
1500 nRejectingNumber
= ScXMLChangeTrackingImportHelper::GetIDFromString( aIter
.toString() );
1506 pChangeTrackingImportHelper
->StartChangeAction(SC_CAT_MOVE
);
1507 pChangeTrackingImportHelper
->SetActionNumber(nActionNumber
);
1508 pChangeTrackingImportHelper
->SetActionState(nActionState
);
1509 pChangeTrackingImportHelper
->SetRejectingNumber(nRejectingNumber
);
1512 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLRejectionContext::createFastChildContext(
1513 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
1515 SvXMLImportContext
*pContext(nullptr);
1516 sax_fastparser::FastAttributeList
*pAttribList
=
1517 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
1521 case XML_ELEMENT( OFFICE
, XML_CHANGE_INFO
):
1522 pContext
= new ScXMLChangeInfoContext(GetScImport(), pAttribList
, pChangeTrackingImportHelper
);
1524 case XML_ELEMENT( TABLE
, XML_DEPENDENCIES
):
1525 pContext
= new ScXMLDependingsContext(GetScImport(), pChangeTrackingImportHelper
);
1527 case XML_ELEMENT( TABLE
, XML_DELETIONS
):
1528 pContext
= new ScXMLDeletionsContext(GetScImport(), pChangeTrackingImportHelper
);
1533 pContext
= new SvXMLImportContext( GetImport() );
1538 void SAL_CALL
ScXMLRejectionContext::endFastElement( sal_Int32
/*nElement*/ )
1540 pChangeTrackingImportHelper
->EndChangeAction();
1543 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */