1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 #include "XMLTrackedChangesContext.hxx"
28 #include "xmlimprt.hxx"
29 #include "xmlconti.hxx"
30 #include "XMLConverter.hxx"
31 #include "cell.hxx"
32 #include "textuno.hxx"
33 #include "editutil.hxx"
34 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/xmlnmspe.hxx>
36 #include <xmloff/nmspmap.hxx>
37 #include <xmloff/xmluconv.hxx>
38 #include <svl/zforlist.hxx>
39 #include <com/sun/star/text/XTextCursor.hpp>
40 #include <com/sun/star/text/ControlCharacter.hpp>
41 
42 using rtl::OUString;
43 using namespace com::sun::star;
44 using namespace xmloff::token;
45 
46 //-----------------------------------------------------------------------------
47 
48 class ScXMLChangeInfoContext : public SvXMLImportContext
49 {
50 	ScMyActionInfo						aInfo;
51 	::rtl::OUStringBuffer               sAuthorBuffer;
52 	::rtl::OUStringBuffer               sDateTimeBuffer;
53 	::rtl::OUStringBuffer               sCommentBuffer;
54 	ScXMLChangeTrackingImportHelper*	pChangeTrackingImportHelper;
55 	sal_uInt32							nParagraphCount;
56 
GetScImport() const57 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()58 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
59 
60 public:
61 	ScXMLChangeInfoContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
62 									  const ::com::sun::star::uno::Reference<
63 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
64 									  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
65 	virtual ~ScXMLChangeInfoContext();
66 
67 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
68 													const ::rtl::OUString& rLocalName,
69 													const ::com::sun::star::uno::Reference<
70 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
71 
72 	virtual void EndElement();
73 };
74 
75 //-----------------------------------------------------------------------------
76 
77 class ScXMLBigRangeContext : public SvXMLImportContext
78 {
79 	ScBigRange&			rBigRange;
80 
GetScImport() const81 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()82 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
83 
84 public:
85 	ScXMLBigRangeContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
86 									  const ::com::sun::star::uno::Reference<
87 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
88 									  ScBigRange& rBigRange);
89 	virtual ~ScXMLBigRangeContext();
90 
91 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
92 													const ::rtl::OUString& rLocalName,
93 													const ::com::sun::star::uno::Reference<
94 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
95 
96 	virtual void EndElement();
97 };
98 
99 //-----------------------------------------------------------------------------
100 
101 class ScXMLCellContentDeletionContext : public SvXMLImportContext
102 {
103 	rtl::OUString						sFormulaAddress;
104 	rtl::OUString						sFormula;
105     rtl::OUString                       sFormulaNmsp;
106     rtl::OUString                       sInputString;
107 	ScBigRange							aBigRange;
108 	double								fValue;
109 	ScXMLChangeTrackingImportHelper*	pChangeTrackingImportHelper;
110 	ScBaseCell*							pCell;
111 	sal_uInt32							nID;
112 	sal_Int32							nMatrixCols;
113 	sal_Int32							nMatrixRows;
114     formula::FormulaGrammar::Grammar                  eGrammar;
115 	sal_uInt16							nType;
116 	sal_uInt8							nMatrixFlag;
117 	sal_Bool							bBigRange;
118 	sal_Bool							bContainsCell;
119 
GetScImport() const120 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()121 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
122 
123 public:
124 	ScXMLCellContentDeletionContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
125 									  const ::com::sun::star::uno::Reference<
126 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
127 									  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
128 	virtual ~ScXMLCellContentDeletionContext();
129 
130 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
131 													const ::rtl::OUString& rLocalName,
132 													const ::com::sun::star::uno::Reference<
133 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
134 
135 	virtual void EndElement();
136 };
137 
138 //-----------------------------------------------------------------------------
139 
140 class ScXMLDependenceContext : public SvXMLImportContext
141 {
142 	ScXMLChangeTrackingImportHelper*	pChangeTrackingImportHelper;
143 
GetScImport() const144 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()145 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
146 
147 public:
148 	ScXMLDependenceContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
149 									  const ::com::sun::star::uno::Reference<
150 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
151 									  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
152 	virtual ~ScXMLDependenceContext();
153 
154 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
155 													const ::rtl::OUString& rLocalName,
156 													const ::com::sun::star::uno::Reference<
157 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
158 
159 	virtual void EndElement();
160 };
161 
162 //-----------------------------------------------------------------------------
163 
164 class ScXMLDependingsContext : public SvXMLImportContext
165 {
166 	ScXMLChangeTrackingImportHelper*	pChangeTrackingImportHelper;
167 
GetScImport() const168 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()169 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
170 
171 public:
172 	ScXMLDependingsContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
173 									  const ::com::sun::star::uno::Reference<
174 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
175 									  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
176 	virtual ~ScXMLDependingsContext();
177 
178 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
179 													const ::rtl::OUString& rLocalName,
180 													const ::com::sun::star::uno::Reference<
181 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
182 
183 	virtual void EndElement();
184 };
185 
186 //-----------------------------------------------------------------------------
187 
188 class ScXMLChangeDeletionContext : public SvXMLImportContext
189 {
190 	ScXMLChangeTrackingImportHelper*	pChangeTrackingImportHelper;
191 
GetScImport() const192 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()193 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
194 
195 public:
196 	ScXMLChangeDeletionContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
197 									  const ::com::sun::star::uno::Reference<
198 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
199 									  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
200 	virtual ~ScXMLChangeDeletionContext();
201 
202 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
203 													const ::rtl::OUString& rLocalName,
204 													const ::com::sun::star::uno::Reference<
205 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
206 
207 	virtual void EndElement();
208 };
209 
210 //-----------------------------------------------------------------------------
211 
212 class ScXMLDeletionsContext : public SvXMLImportContext
213 {
214 	ScXMLChangeTrackingImportHelper*	pChangeTrackingImportHelper;
215 
GetScImport() const216 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()217 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
218 
219 public:
220 	ScXMLDeletionsContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
221 									  const ::com::sun::star::uno::Reference<
222 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
223 									  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
224 	virtual ~ScXMLDeletionsContext();
225 
226 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
227 													const ::rtl::OUString& rLocalName,
228 													const ::com::sun::star::uno::Reference<
229 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
230 
231 	virtual void EndElement();
232 };
233 
234 //-----------------------------------------------------------------------------
235 
236 class ScXMLChangeCellContext;
237 
238 class ScXMLChangeTextPContext : public SvXMLImportContext
239 {
240 	::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList> xAttrList;
241 	rtl::OUString				sLName;
242 	rtl::OUStringBuffer			sText;
243 	ScXMLChangeCellContext*		pChangeCellContext;
244 	SvXMLImportContext*			pTextPContext;
245 	sal_uInt16						nPrefix;
246 
GetScImport() const247 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()248 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
249 
250 public:
251 
252 	ScXMLChangeTextPContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
253 					   const ::rtl::OUString& rLName,
254 					   const ::com::sun::star::uno::Reference<
255 										::com::sun::star::xml::sax::XAttributeList>& xAttrList,
256 						ScXMLChangeCellContext* pChangeCellContext);
257 
258 	virtual ~ScXMLChangeTextPContext();
259 
260 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
261 									 const ::rtl::OUString& rLocalName,
262 									 const ::com::sun::star::uno::Reference<
263 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
264 
265 	virtual void Characters( const ::rtl::OUString& rChars );
266 
267 	virtual void EndElement();
268 };
269 
270 //-----------------------------------------------------------------------------
271 
272 class ScXMLChangeCellContext : public SvXMLImportContext
273 {
274 	rtl::OUString			sText;
275     rtl::OUString&          rInputString;
276 	ScBaseCell*&			rOldCell;
277 	ScEditEngineTextObj*	pEditTextObj;
278 	double&					rDateTimeValue;
279 	double					fValue;
280 	sal_uInt16&				rType;
281 //    sal_Bool                bIsMatrix;
282 //    sal_Bool                bIsCoveredMatrix;
283 	sal_Bool				bEmpty;
284 	sal_Bool				bFirstParagraph;
285 	sal_Bool				bString;
286 	sal_Bool				bFormula;
287 
GetScImport() const288 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()289 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
290 
291 public:
292 	ScXMLChangeCellContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
293 									  const ::com::sun::star::uno::Reference<
294 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
295                                       ScBaseCell*& rOldCell, rtl::OUString& sAddress,
296                                       rtl::OUString& rFormula, rtl::OUString& rFormulaNmsp,
297                                       formula::FormulaGrammar::Grammar& rGrammar,
298                                       rtl::OUString& rInputString, double& fValue, sal_uInt16& nType,
299 									  sal_uInt8& nMatrixFlag, sal_Int32& nMatrixCols, sal_Int32& nMatrixRows);
300 	virtual ~ScXMLChangeCellContext();
301 
302 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
303 													const ::rtl::OUString& rLocalName,
304 													const ::com::sun::star::uno::Reference<
305 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
306 
307 	void CreateTextPContext(sal_Bool bIsNewParagraph);
IsEditCell()308 	sal_Bool IsEditCell() { return pEditTextObj != 0; }
SetText(const rtl::OUString & sTempText)309 	void SetText(const rtl::OUString& sTempText) { sText = sTempText; }
310 
311 	virtual void EndElement();
312 };
313 
314 //-----------------------------------------------------------------------------
315 
316 class ScXMLPreviousContext : public SvXMLImportContext
317 {
318 	rtl::OUString						sFormulaAddress;
319 	rtl::OUString						sFormula;
320     rtl::OUString                       sFormulaNmsp;
321     rtl::OUString                       sInputString;
322 	double								fValue;
323 	ScXMLChangeTrackingImportHelper*	pChangeTrackingImportHelper;
324 	ScBaseCell*							pOldCell;
325 	sal_uInt32							nID;
326 	sal_Int32							nMatrixCols;
327 	sal_Int32							nMatrixRows;
328     formula::FormulaGrammar::Grammar    eGrammar;
329 	sal_uInt16							nType;
330 	sal_uInt8							nMatrixFlag;
331 
GetScImport() const332 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()333 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
334 
335 public:
336 	ScXMLPreviousContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
337 									  const ::com::sun::star::uno::Reference<
338 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
339 									  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
340 	virtual ~ScXMLPreviousContext();
341 
342 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
343 													const ::rtl::OUString& rLocalName,
344 													const ::com::sun::star::uno::Reference<
345 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
346 
347 	virtual void EndElement();
348 };
349 
350 //-----------------------------------------------------------------------------
351 
352 class ScXMLContentChangeContext : public SvXMLImportContext
353 {
354 	ScXMLChangeTrackingImportHelper*	pChangeTrackingImportHelper;
355 	ScBigRange							aBigRange;
356 
GetScImport() const357 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()358 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
359 
360 public:
361 	ScXMLContentChangeContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
362 									  const ::com::sun::star::uno::Reference<
363 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
364 									  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
365 	virtual ~ScXMLContentChangeContext();
366 
367 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
368 													const ::rtl::OUString& rLocalName,
369 													const ::com::sun::star::uno::Reference<
370 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
371 	virtual void EndElement();
372 };
373 
374 //-----------------------------------------------------------------------------
375 
376 class ScXMLInsertionContext : public SvXMLImportContext
377 {
378 	ScXMLChangeTrackingImportHelper*	pChangeTrackingImportHelper;
379 
GetScImport() const380 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()381 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
382 
383 public:
384 	ScXMLInsertionContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
385 									  const ::com::sun::star::uno::Reference<
386 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
387 									  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
388 	virtual ~ScXMLInsertionContext();
389 
390 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
391 													const ::rtl::OUString& rLocalName,
392 													const ::com::sun::star::uno::Reference<
393 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
394 	virtual void EndElement();
395 };
396 
397 //-----------------------------------------------------------------------------
398 
399 class ScXMLInsertionCutOffContext : public SvXMLImportContext
400 {
401 	ScXMLChangeTrackingImportHelper*	pChangeTrackingImportHelper;
402 
GetScImport() const403 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()404 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
405 
406 public:
407 	ScXMLInsertionCutOffContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
408 									  const ::com::sun::star::uno::Reference<
409 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
410 									  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
411 	virtual ~ScXMLInsertionCutOffContext();
412 
413 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
414 													const ::rtl::OUString& rLocalName,
415 													const ::com::sun::star::uno::Reference<
416 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
417 	virtual void EndElement();
418 };
419 
420 //-----------------------------------------------------------------------------
421 
422 class ScXMLMovementCutOffContext : public SvXMLImportContext
423 {
424 	ScXMLChangeTrackingImportHelper*	pChangeTrackingImportHelper;
425 
GetScImport() const426 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()427 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
428 
429 public:
430 	ScXMLMovementCutOffContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
431 									  const ::com::sun::star::uno::Reference<
432 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
433 									  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
434 	virtual ~ScXMLMovementCutOffContext();
435 
436 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
437 													const ::rtl::OUString& rLocalName,
438 													const ::com::sun::star::uno::Reference<
439 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
440 	virtual void EndElement();
441 };
442 
443 //-----------------------------------------------------------------------------
444 
445 class ScXMLCutOffsContext : public SvXMLImportContext
446 {
447 	ScXMLChangeTrackingImportHelper*	pChangeTrackingImportHelper;
448 
GetScImport() const449 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()450 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
451 
452 public:
453 	ScXMLCutOffsContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
454 									  const ::com::sun::star::uno::Reference<
455 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
456 									  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
457 	virtual ~ScXMLCutOffsContext();
458 
459 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
460 													const ::rtl::OUString& rLocalName,
461 													const ::com::sun::star::uno::Reference<
462 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
463 	virtual void EndElement();
464 };
465 
466 //-----------------------------------------------------------------------------
467 
468 class ScXMLDeletionContext : public SvXMLImportContext
469 {
470 	ScXMLChangeTrackingImportHelper*	pChangeTrackingImportHelper;
471 
GetScImport() const472 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()473 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
474 
475 public:
476 	ScXMLDeletionContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
477 									  const ::com::sun::star::uno::Reference<
478 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
479 									  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
480 	virtual ~ScXMLDeletionContext();
481 
482 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
483 													const ::rtl::OUString& rLocalName,
484 													const ::com::sun::star::uno::Reference<
485 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
486 	virtual void EndElement();
487 };
488 
489 //-----------------------------------------------------------------------------
490 
491 class ScXMLMovementContext : public SvXMLImportContext
492 {
493 	ScBigRange							aSourceRange;
494 	ScBigRange							aTargetRange;
495 	ScXMLChangeTrackingImportHelper*	pChangeTrackingImportHelper;
496 
GetScImport() const497 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()498 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
499 
500 public:
501 	ScXMLMovementContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
502 									  const ::com::sun::star::uno::Reference<
503 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
504 									  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
505 	virtual ~ScXMLMovementContext();
506 
507 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
508 													const ::rtl::OUString& rLocalName,
509 													const ::com::sun::star::uno::Reference<
510 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
511 	virtual void EndElement();
512 };
513 
514 //-----------------------------------------------------------------------------
515 
516 class ScXMLRejectionContext : public SvXMLImportContext
517 {
518 	ScXMLChangeTrackingImportHelper*	pChangeTrackingImportHelper;
519 
GetScImport() const520 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()521 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
522 
523 public:
524 	ScXMLRejectionContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
525 									  const ::com::sun::star::uno::Reference<
526 									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
527 									  ScXMLChangeTrackingImportHelper* pChangeTrackingImportHelper);
528 	virtual ~ScXMLRejectionContext();
529 
530 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
531 													const ::rtl::OUString& rLocalName,
532 													const ::com::sun::star::uno::Reference<
533 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
534 	virtual void EndElement();
535 };
536 
537 //------------------------------------------------------------------
538 
ScXMLTrackedChangesContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScXMLChangeTrackingImportHelper * pTempChangeTrackingImportHelper)539 ScXMLTrackedChangesContext::ScXMLTrackedChangesContext( ScXMLImport& rImport,
540 											  sal_uInt16 nPrfx,
541 				   	  						  const ::rtl::OUString& rLName,
542 									  		const uno::Reference<xml::sax::XAttributeList>& xAttrList,
543 									  		ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
544 	SvXMLImportContext( rImport, nPrfx, rLName ),
545 	pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
546 {
547 	rImport.LockSolarMutex();
548 	pChangeTrackingImportHelper->SetChangeTrack(sal_True);
549 
550 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
551 	for( sal_Int16 i=0; i < nAttrCount; ++i )
552 	{
553 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
554 		rtl::OUString aLocalName;
555 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
556 											sAttrName, &aLocalName ));
557 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
558 		if (nPrefix == XML_NAMESPACE_TABLE)
559 		{
560 			if (IsXMLToken(aLocalName, XML_PROTECTION_KEY))
561 			{
562 				if (sValue.getLength())
563 				{
564 					uno::Sequence<sal_Int8> aPass;
565 					SvXMLUnitConverter::decodeBase64(aPass, sValue);
566 					pChangeTrackingImportHelper->SetProtection(aPass);
567 				}
568 			}
569 		}
570 	}
571 }
572 
~ScXMLTrackedChangesContext()573 ScXMLTrackedChangesContext::~ScXMLTrackedChangesContext()
574 {
575 	GetScImport().UnlockSolarMutex();
576 }
577 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)578 SvXMLImportContext *ScXMLTrackedChangesContext::CreateChildContext( sal_uInt16 nPrefix,
579 									 const ::rtl::OUString& rLocalName,
580 									 const ::com::sun::star::uno::Reference<
581 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList )
582 {
583 	SvXMLImportContext *pContext(0);
584 
585 	if (nPrefix == XML_NAMESPACE_TABLE)
586 	{
587 		if (IsXMLToken(rLocalName, XML_CELL_CONTENT_CHANGE))
588 		{
589 			pContext = new ScXMLContentChangeContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
590 		}
591 		else if (IsXMLToken(rLocalName, XML_INSERTION))
592 		{
593 			pContext = new ScXMLInsertionContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
594 		}
595 		else if (IsXMLToken(rLocalName, XML_DELETION))
596 		{
597 			pContext = new ScXMLDeletionContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
598 		}
599 		else if (IsXMLToken(rLocalName, XML_MOVEMENT))
600 		{
601 			pContext = new ScXMLMovementContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
602 		}
603 		else if (IsXMLToken(rLocalName, XML_REJECTION))
604 		{
605 			pContext = new ScXMLRejectionContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
606 		}
607 	}
608 
609 	if( !pContext )
610 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
611 
612 	return pContext;
613 }
614 
EndElement()615 void ScXMLTrackedChangesContext::EndElement()
616 {
617 }
618 
ScXMLChangeInfoContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScXMLChangeTrackingImportHelper * pTempChangeTrackingImportHelper)619 ScXMLChangeInfoContext::ScXMLChangeInfoContext(  ScXMLImport& rImport,
620 											  sal_uInt16 nPrfx,
621 				   	  						  const ::rtl::OUString& rLName,
622 									  		const uno::Reference<xml::sax::XAttributeList>& xAttrList,
623 											ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
624 	SvXMLImportContext( rImport, nPrfx, rLName ),
625 	aInfo(),
626 	pChangeTrackingImportHelper(pTempChangeTrackingImportHelper),
627 	nParagraphCount(0)
628 {
629 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
630 	for( sal_Int16 i=0; i < nAttrCount; ++i )
631 	{
632 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
633 		rtl::OUString aLocalName;
634 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
635 											sAttrName, &aLocalName ));
636 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
637 
638 		if (nPrefix == XML_NAMESPACE_OFFICE)
639 		{
640 			if (IsXMLToken(aLocalName, XML_CHG_AUTHOR))
641 			{
642 				sAuthorBuffer = sValue;
643 			}
644 			else if (IsXMLToken(aLocalName, XML_CHG_DATE_TIME))
645 			{
646 				sDateTimeBuffer = sValue;
647 			}
648 		}
649 	}
650 }
651 
~ScXMLChangeInfoContext()652 ScXMLChangeInfoContext::~ScXMLChangeInfoContext()
653 {
654 }
655 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)656 SvXMLImportContext *ScXMLChangeInfoContext::CreateChildContext( sal_uInt16 nPrefix,
657 									 const ::rtl::OUString& rLocalName,
658 									 const ::com::sun::star::uno::Reference<
659 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList )
660 {
661 	SvXMLImportContext *pContext(0);
662 
663 	if( XML_NAMESPACE_DC == nPrefix )
664 	{
665 		if( IsXMLToken( rLocalName, XML_CREATOR ) )
666 			pContext = new ScXMLContentContext(GetScImport(), nPrefix,
667 											rLocalName, xAttrList, sAuthorBuffer);
668 		else if( IsXMLToken( rLocalName, XML_DATE ) )
669 			pContext = new ScXMLContentContext(GetScImport(), nPrefix,
670 											rLocalName, xAttrList, sDateTimeBuffer);
671 	}
672 	else if ((nPrefix == XML_NAMESPACE_TEXT) && (IsXMLToken(rLocalName, XML_P)) )
673 	{
674 		if(nParagraphCount)
675 			sCommentBuffer.append(static_cast<sal_Unicode>('\n'));
676 		++nParagraphCount;
677 		pContext = new ScXMLContentContext( GetScImport(), nPrefix, rLocalName, xAttrList, sCommentBuffer);
678 	}
679 
680 	if( !pContext )
681 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
682 
683 	return pContext;
684 }
685 
EndElement()686 void ScXMLChangeInfoContext::EndElement()
687 {
688 	aInfo.sUser = sAuthorBuffer.makeStringAndClear();
689 	GetScImport().GetMM100UnitConverter().convertDateTime(aInfo.aDateTime, sDateTimeBuffer.makeStringAndClear());
690 	aInfo.sComment = sCommentBuffer.makeStringAndClear();
691 	pChangeTrackingImportHelper->SetActionInfo(aInfo);
692 }
693 
ScXMLBigRangeContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScBigRange & rTempBigRange)694 ScXMLBigRangeContext::ScXMLBigRangeContext(  ScXMLImport& rImport,
695 											  sal_uInt16 nPrfx,
696 				   	  						  const ::rtl::OUString& rLName,
697 									  		const uno::Reference<xml::sax::XAttributeList>& xAttrList,
698 											ScBigRange& rTempBigRange ) :
699 	SvXMLImportContext( rImport, nPrfx, rLName ),
700 	rBigRange(rTempBigRange)
701 {
702 	sal_Bool bColumn(sal_False);
703 	sal_Bool bRow(sal_False);
704 	sal_Bool bTable(sal_False);
705     sal_Int32 nColumn(0);
706     sal_Int32 nRow(0);
707     sal_Int32 nTable(0);
708     sal_Int32 nStartColumn(0);
709     sal_Int32 nEndColumn(0);
710     sal_Int32 nStartRow(0);
711     sal_Int32 nEndRow(0);
712     sal_Int32 nStartTable(0);
713     sal_Int32 nEndTable(0);
714 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
715 	for( sal_Int16 i=0; i < nAttrCount; ++i )
716 	{
717 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
718 		rtl::OUString aLocalName;
719 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
720 											sAttrName, &aLocalName ));
721 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
722 
723 		if (nPrefix == XML_NAMESPACE_TABLE)
724 		{
725 			if (IsXMLToken(aLocalName, XML_COLUMN))
726 			{
727 				SvXMLUnitConverter::convertNumber(nColumn, sValue);
728 				bColumn = sal_True;
729 			}
730 			else if (IsXMLToken(aLocalName, XML_ROW))
731 			{
732 				SvXMLUnitConverter::convertNumber(nRow, sValue);
733 				bRow = sal_True;
734 			}
735 			else if (IsXMLToken(aLocalName, XML_TABLE))
736 			{
737 				SvXMLUnitConverter::convertNumber(nTable, sValue);
738 				bTable = sal_True;
739 			}
740 			else if (IsXMLToken(aLocalName, XML_START_COLUMN))
741 				SvXMLUnitConverter::convertNumber(nStartColumn, sValue);
742 			else if (IsXMLToken(aLocalName, XML_END_COLUMN))
743 				SvXMLUnitConverter::convertNumber(nEndColumn, sValue);
744 			else if (IsXMLToken(aLocalName, XML_START_ROW))
745 				SvXMLUnitConverter::convertNumber(nStartRow, sValue);
746 			else if (IsXMLToken(aLocalName, XML_END_ROW))
747 				SvXMLUnitConverter::convertNumber(nEndRow, sValue);
748 			else if (IsXMLToken(aLocalName, XML_START_TABLE))
749 				SvXMLUnitConverter::convertNumber(nStartTable, sValue);
750 			else if (IsXMLToken(aLocalName, XML_END_TABLE))
751 				SvXMLUnitConverter::convertNumber(nEndTable, sValue);
752 		}
753 	}
754 	if (bColumn)
755 		nStartColumn = nEndColumn = nColumn;
756 	if (bRow)
757 		nStartRow = nEndRow = nRow;
758 	if (bTable)
759 		nStartTable = nEndTable = nTable;
760 	rBigRange.Set(nStartColumn, nStartRow, nStartTable,
761 		nEndColumn, nEndRow, nEndTable);
762 }
763 
~ScXMLBigRangeContext()764 ScXMLBigRangeContext::~ScXMLBigRangeContext()
765 {
766 }
767 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &)768 SvXMLImportContext *ScXMLBigRangeContext::CreateChildContext( sal_uInt16 nPrefix,
769 									 const ::rtl::OUString& rLocalName,
770 									 const ::com::sun::star::uno::Reference<
771                                         ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
772 {
773 	return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
774 }
775 
EndElement()776 void ScXMLBigRangeContext::EndElement()
777 {
778 }
779 
ScXMLCellContentDeletionContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScXMLChangeTrackingImportHelper * pTempChangeTrackingImportHelper)780 ScXMLCellContentDeletionContext::ScXMLCellContentDeletionContext(  ScXMLImport& rImport,
781 											  sal_uInt16 nPrfx,
782 				   	  						  const ::rtl::OUString& rLName,
783 									  		const uno::Reference<xml::sax::XAttributeList>& xAttrList,
784 											ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper) :
785 	SvXMLImportContext( rImport, nPrfx, rLName ),
786 	pChangeTrackingImportHelper(pTempChangeTrackingImportHelper),
787 	pCell(NULL),
788 	nID(0),
789 	nMatrixCols(0),
790 	nMatrixRows(0),
791 	nType(NUMBERFORMAT_ALL),
792 	nMatrixFlag(MM_NONE),
793 	bBigRange(sal_False),
794 	bContainsCell(sal_False)
795 {
796 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
797 	for( sal_Int16 i=0; i < nAttrCount; ++i )
798 	{
799 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
800 		rtl::OUString aLocalName;
801 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
802 											sAttrName, &aLocalName ));
803 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
804 
805 		if (nPrefix == XML_NAMESPACE_TABLE)
806 		{
807 			if (IsXMLToken(aLocalName, XML_ID))
808 				nID = pChangeTrackingImportHelper->GetIDFromString(sValue);
809 		}
810 	}
811 }
812 
~ScXMLCellContentDeletionContext()813 ScXMLCellContentDeletionContext::~ScXMLCellContentDeletionContext()
814 {
815 }
816 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)817 SvXMLImportContext *ScXMLCellContentDeletionContext::CreateChildContext( sal_uInt16 nPrefix,
818 									 const ::rtl::OUString& rLocalName,
819 									 const ::com::sun::star::uno::Reference<
820 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList )
821 {
822 	SvXMLImportContext *pContext(0);
823 
824 	if (nPrefix == XML_NAMESPACE_TABLE)
825 	{
826 		if (IsXMLToken(rLocalName, XML_CHANGE_TRACK_TABLE_CELL))
827 		{
828 			bContainsCell = sal_True;
829 			pContext = new ScXMLChangeCellContext(GetScImport(), nPrefix, rLocalName, xAttrList,
830                 pCell, sFormulaAddress, sFormula, sFormulaNmsp, eGrammar, sInputString, fValue, nType, nMatrixFlag, nMatrixCols, nMatrixRows );
831 		}
832 		else if (IsXMLToken(rLocalName, XML_CELL_ADDRESS))
833 		{
834 			DBG_ASSERT(!nID, "a action with a ID should not contain a BigRange");
835 			bBigRange = sal_True;
836 			pContext = new ScXMLBigRangeContext(GetScImport(), nPrefix, rLocalName, xAttrList, aBigRange);
837 		}
838 	}
839 
840 	if( !pContext )
841 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
842 
843 	return pContext;
844 }
845 
EndElement()846 void ScXMLCellContentDeletionContext::EndElement()
847 {
848     ScMyCellInfo* pCellInfo(new ScMyCellInfo(pCell, sFormulaAddress, sFormula, eGrammar, sInputString, fValue, nType,
849             nMatrixFlag, nMatrixCols, nMatrixRows));
850 	if (nID)
851 		pChangeTrackingImportHelper->AddDeleted(nID, pCellInfo);
852 	else
853 		pChangeTrackingImportHelper->AddGenerated(pCellInfo, aBigRange);
854 }
855 
ScXMLDependenceContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScXMLChangeTrackingImportHelper * pTempChangeTrackingImportHelper)856 ScXMLDependenceContext::ScXMLDependenceContext(  ScXMLImport& rImport,
857 											  sal_uInt16 nPrfx,
858 				   	  						  const ::rtl::OUString& rLName,
859 									  		const uno::Reference<xml::sax::XAttributeList>& xAttrList,
860 											ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
861 	SvXMLImportContext( rImport, nPrfx, rLName ),
862 	pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
863 {
864     sal_uInt32 nID(0);
865 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
866 	for( sal_Int16 i=0; i < nAttrCount; ++i )
867 	{
868 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
869 		rtl::OUString aLocalName;
870 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
871 											sAttrName, &aLocalName ));
872 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
873 
874 		if (nPrefix == XML_NAMESPACE_TABLE)
875 		{
876 			if (IsXMLToken(aLocalName, XML_ID))
877 				nID = pChangeTrackingImportHelper->GetIDFromString(sValue);
878 		}
879 	}
880 	pChangeTrackingImportHelper->AddDependence(nID);
881 }
882 
~ScXMLDependenceContext()883 ScXMLDependenceContext::~ScXMLDependenceContext()
884 {
885 }
886 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &)887 SvXMLImportContext *ScXMLDependenceContext::CreateChildContext( sal_uInt16 nPrefix,
888 									 const ::rtl::OUString& rLocalName,
889 									 const ::com::sun::star::uno::Reference<
890                                         ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
891 {
892 	return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
893 }
894 
EndElement()895 void ScXMLDependenceContext::EndElement()
896 {
897 }
898 
ScXMLDependingsContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &,ScXMLChangeTrackingImportHelper * pTempChangeTrackingImportHelper)899 ScXMLDependingsContext::ScXMLDependingsContext(  ScXMLImport& rImport,
900 											  sal_uInt16 nPrfx,
901 				   	  						  const ::rtl::OUString& rLName,
902                                             const uno::Reference<xml::sax::XAttributeList>& /* xAttrList */,
903 											ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
904 	SvXMLImportContext( rImport, nPrfx, rLName ),
905 	pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
906 {
907 	// here are no attributes
908 }
909 
~ScXMLDependingsContext()910 ScXMLDependingsContext::~ScXMLDependingsContext()
911 {
912 }
913 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)914 SvXMLImportContext *ScXMLDependingsContext::CreateChildContext( sal_uInt16 nPrefix,
915 									 const ::rtl::OUString& rLocalName,
916 									 const ::com::sun::star::uno::Reference<
917 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList )
918 {
919 	SvXMLImportContext *pContext(0);
920 
921 	if (nPrefix == XML_NAMESPACE_TABLE)
922 	{
923         // #i80033# read both old (dependence) and new (dependency) elements
924         if (IsXMLToken(rLocalName, XML_DEPENDENCE) || IsXMLToken(rLocalName, XML_DEPENDENCY))
925 			pContext = new ScXMLDependenceContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
926 	}
927 
928 	if( !pContext )
929 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
930 
931 	return pContext;
932 }
933 
EndElement()934 void ScXMLDependingsContext::EndElement()
935 {
936 }
937 
ScXMLChangeDeletionContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScXMLChangeTrackingImportHelper * pTempChangeTrackingImportHelper)938 ScXMLChangeDeletionContext::ScXMLChangeDeletionContext(  ScXMLImport& rImport,
939 											  sal_uInt16 nPrfx,
940 				   	  						  const ::rtl::OUString& rLName,
941 									  		const uno::Reference<xml::sax::XAttributeList>& xAttrList,
942 											ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
943 	SvXMLImportContext( rImport, nPrfx, rLName ),
944 	pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
945 {
946     sal_uInt32 nID(0);
947 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
948 	for( sal_Int16 i=0; i < nAttrCount; ++i )
949 	{
950 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
951 		rtl::OUString aLocalName;
952 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
953 											sAttrName, &aLocalName ));
954 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
955 
956 		if (nPrefix == XML_NAMESPACE_TABLE)
957 		{
958 			if (IsXMLToken(aLocalName, XML_ID))
959 				nID = pChangeTrackingImportHelper->GetIDFromString(sValue);
960 		}
961 	}
962 	pChangeTrackingImportHelper->AddDeleted(nID);
963 }
964 
~ScXMLChangeDeletionContext()965 ScXMLChangeDeletionContext::~ScXMLChangeDeletionContext()
966 {
967 }
968 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &)969 SvXMLImportContext *ScXMLChangeDeletionContext::CreateChildContext( sal_uInt16 nPrefix,
970 									 const ::rtl::OUString& rLocalName,
971 									 const ::com::sun::star::uno::Reference<
972                                         ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
973 {
974 	return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
975 }
976 
EndElement()977 void ScXMLChangeDeletionContext::EndElement()
978 {
979 }
980 
ScXMLDeletionsContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &,ScXMLChangeTrackingImportHelper * pTempChangeTrackingImportHelper)981 ScXMLDeletionsContext::ScXMLDeletionsContext(  ScXMLImport& rImport,
982 											  sal_uInt16 nPrfx,
983 				   	  						  const ::rtl::OUString& rLName,
984                                             const uno::Reference<xml::sax::XAttributeList>& /* xAttrList */,
985 											ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
986 	SvXMLImportContext( rImport, nPrfx, rLName ),
987 	pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
988 {
989 	// here are no attributes
990 }
991 
~ScXMLDeletionsContext()992 ScXMLDeletionsContext::~ScXMLDeletionsContext()
993 {
994 }
995 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)996 SvXMLImportContext *ScXMLDeletionsContext::CreateChildContext( sal_uInt16 nPrefix,
997 									 const ::rtl::OUString& rLocalName,
998 									 const ::com::sun::star::uno::Reference<
999 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1000 {
1001 	SvXMLImportContext *pContext(0);
1002 
1003 	if (nPrefix == XML_NAMESPACE_TABLE)
1004 	{
1005 		if (IsXMLToken(rLocalName, XML_CHANGE_DELETION))
1006 			pContext = new ScXMLChangeDeletionContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1007 		else if (IsXMLToken(rLocalName, XML_CELL_CONTENT_DELETION))
1008 			pContext = new ScXMLCellContentDeletionContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1009 	}
1010 
1011 	if( !pContext )
1012 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1013 
1014 	return pContext;
1015 }
1016 
EndElement()1017 void ScXMLDeletionsContext::EndElement()
1018 {
1019 }
1020 
ScXMLChangeTextPContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xTempAttrList,ScXMLChangeCellContext * pTempChangeCellContext)1021 ScXMLChangeTextPContext::ScXMLChangeTextPContext( ScXMLImport& rImport,
1022 									  sal_uInt16 nPrfx,
1023 									  const ::rtl::OUString& rLName,
1024 									  const ::com::sun::star::uno::Reference<
1025 									  ::com::sun::star::xml::sax::XAttributeList>& xTempAttrList,
1026 									  ScXMLChangeCellContext* pTempChangeCellContext) :
1027 	SvXMLImportContext( rImport, nPrfx, rLName ),
1028 	xAttrList(xTempAttrList),
1029 	sLName(rLName),
1030 	sText(),
1031 	pChangeCellContext(pTempChangeCellContext),
1032 	pTextPContext(NULL),
1033 	nPrefix(nPrfx)
1034 {
1035 	// here are no attributes
1036 }
1037 
~ScXMLChangeTextPContext()1038 ScXMLChangeTextPContext::~ScXMLChangeTextPContext()
1039 {
1040 	if (pTextPContext)
1041 		delete pTextPContext;
1042 }
1043 
CreateChildContext(sal_uInt16 nTempPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xTempAttrList)1044 SvXMLImportContext *ScXMLChangeTextPContext::CreateChildContext( sal_uInt16 nTempPrefix,
1045 											const ::rtl::OUString& rLName,
1046 											const ::com::sun::star::uno::Reference<
1047 									  	::com::sun::star::xml::sax::XAttributeList>& xTempAttrList )
1048 {
1049 	SvXMLImportContext *pContext(0);
1050 
1051 	if ((nPrefix == XML_NAMESPACE_TEXT) && (IsXMLToken(rLName, XML_S)) && !pTextPContext)
1052 	{
1053 		sal_Int32 nRepeat(0);
1054 		sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
1055 		for( sal_Int16 i=0; i < nAttrCount; ++i )
1056 		{
1057 			const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
1058 			const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
1059 			rtl::OUString aLocalName;
1060 			sal_uInt16 nPrfx(GetScImport().GetNamespaceMap().GetKeyByAttrName(
1061 												sAttrName, &aLocalName ));
1062 			if ((nPrfx == XML_NAMESPACE_TEXT) && (IsXMLToken(aLocalName, XML_C)))
1063 				nRepeat = sValue.toInt32();
1064 		}
1065 		if (nRepeat)
1066 			for (sal_Int32 j = 0; j < nRepeat; ++j)
1067 				sText.append(static_cast<sal_Unicode>(' '));
1068 		else
1069 			sText.append(static_cast<sal_Unicode>(' '));
1070 	}
1071 	else
1072 	{
1073 		if (!pChangeCellContext->IsEditCell())
1074 			pChangeCellContext->CreateTextPContext(sal_False);
1075 		sal_Bool bWasContext (sal_True);
1076 		if (!pTextPContext)
1077 		{
1078 			bWasContext = sal_False;
1079 			pTextPContext = GetScImport().GetTextImport()->CreateTextChildContext(
1080 									GetScImport(), nPrefix, sLName, xAttrList);
1081 		}
1082 		if (pTextPContext)
1083 		{
1084 			if (!bWasContext)
1085 				pTextPContext->Characters(sText.makeStringAndClear());
1086 			pContext = pTextPContext->CreateChildContext(nTempPrefix, rLName, xTempAttrList);
1087 		}
1088 	}
1089 
1090 	if( !pContext )
1091 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1092 
1093 	return pContext;
1094 }
1095 
Characters(const::rtl::OUString & rChars)1096 void ScXMLChangeTextPContext::Characters( const ::rtl::OUString& rChars )
1097 {
1098 	if (!pTextPContext)
1099 		sText.append(rChars);
1100 	else
1101 		pTextPContext->Characters(rChars);
1102 }
1103 
EndElement()1104 void ScXMLChangeTextPContext::EndElement()
1105 {
1106 	if (!pTextPContext)
1107 		pChangeCellContext->SetText(sText.makeStringAndClear());
1108 }
1109 
ScXMLChangeCellContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScBaseCell * & rTempOldCell,rtl::OUString & rAddress,rtl::OUString & rFormula,rtl::OUString & rFormulaNmsp,formula::FormulaGrammar::Grammar & rGrammar,rtl::OUString & rTempInputString,double & fDateTimeValue,sal_uInt16 & nType,sal_uInt8 & nMatrixFlag,sal_Int32 & nMatrixCols,sal_Int32 & nMatrixRows)1110 ScXMLChangeCellContext::ScXMLChangeCellContext(  ScXMLImport& rImport,
1111 											  sal_uInt16 nPrfx,
1112 				   	  						  const ::rtl::OUString& rLName,
1113 									  		const uno::Reference<xml::sax::XAttributeList>& xAttrList,
1114                                             ScBaseCell*& rTempOldCell, rtl::OUString& rAddress,
1115                                             rtl::OUString& rFormula, rtl::OUString& rFormulaNmsp,
1116                                             formula::FormulaGrammar::Grammar& rGrammar,
1117                                             rtl::OUString& rTempInputString, double& fDateTimeValue, sal_uInt16& nType,
1118 											sal_uInt8& nMatrixFlag, sal_Int32& nMatrixCols, sal_Int32& nMatrixRows ) :
1119 	SvXMLImportContext( rImport, nPrfx, rLName ),
1120     rInputString(rTempInputString),
1121 	rOldCell(rTempOldCell),
1122 	pEditTextObj(NULL),
1123 	rDateTimeValue(fDateTimeValue),
1124 	rType(nType),
1125 	bEmpty(sal_True),
1126 	bFirstParagraph(sal_True),
1127 	bString(sal_True),
1128 	bFormula(sal_False)
1129 {
1130 	sal_Bool bIsMatrix(sal_False);
1131 	sal_Bool bIsCoveredMatrix(sal_False);
1132 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
1133 	for( sal_Int16 i=0; i < nAttrCount; ++i )
1134 	{
1135 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
1136 		rtl::OUString aLocalName;
1137 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
1138 											sAttrName, &aLocalName ));
1139 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
1140 
1141 		if (nPrefix == XML_NAMESPACE_TABLE)
1142 		{
1143 			if (IsXMLToken(aLocalName, XML_FORMULA))
1144 			{
1145 				bEmpty = sal_False;
1146                 GetScImport().ExtractFormulaNamespaceGrammar( rFormula, rFormulaNmsp, rGrammar, sValue );
1147 				bFormula = sal_True;
1148 			}
1149 			else if (IsXMLToken(aLocalName, XML_CELL_ADDRESS))
1150 			{
1151 				rAddress = sValue;
1152 			}
1153 			else if (IsXMLToken(aLocalName, XML_MATRIX_COVERED))
1154 			{
1155 				bIsCoveredMatrix = IsXMLToken(sValue, XML_TRUE);
1156 			}
1157 			else if (IsXMLToken(aLocalName, XML_NUMBER_MATRIX_COLUMNS_SPANNED))
1158 			{
1159 				bIsMatrix = sal_True;
1160 				SvXMLUnitConverter::convertNumber(nMatrixCols, sValue);
1161 			}
1162 			else if (IsXMLToken(aLocalName, XML_NUMBER_MATRIX_ROWS_SPANNED))
1163 			{
1164 				bIsMatrix = sal_True;
1165 				SvXMLUnitConverter::convertNumber(nMatrixRows, sValue);
1166 			}
1167 		}
1168 		else if (nPrefix == XML_NAMESPACE_OFFICE)
1169 		{
1170 			if (IsXMLToken(aLocalName, XML_VALUE_TYPE))
1171 			{
1172 				if (IsXMLToken(sValue, XML_FLOAT))
1173 					bString = sal_False;
1174 				else if (IsXMLToken(sValue, XML_DATE))
1175                 {
1176 					rType = NUMBERFORMAT_DATE;
1177 					bString = sal_False;
1178                 }
1179 				else if (IsXMLToken(sValue, XML_TIME))
1180                 {
1181 					rType = NUMBERFORMAT_TIME;
1182 					bString = sal_False;
1183                 }
1184 			}
1185 			else if (IsXMLToken(aLocalName, XML_VALUE))
1186 			{
1187 				SvXMLUnitConverter::convertDouble(fValue, sValue);
1188 				bEmpty = sal_False;
1189 			}
1190 			else if (IsXMLToken(aLocalName, XML_DATE_VALUE))
1191 			{
1192 				bEmpty = sal_False;
1193 				if (GetScImport().GetMM100UnitConverter().setNullDate(GetScImport().GetModel()))
1194 					GetScImport().GetMM100UnitConverter().convertDateTime(rDateTimeValue, sValue);
1195                 fValue = rDateTimeValue;
1196 			}
1197 			else if (IsXMLToken(aLocalName, XML_TIME_VALUE))
1198 			{
1199 				bEmpty = sal_False;
1200 				GetScImport().GetMM100UnitConverter().convertTime(rDateTimeValue, sValue);
1201                 fValue = rDateTimeValue;
1202 			}
1203         }
1204 	}
1205 	if (bIsCoveredMatrix)
1206 		nMatrixFlag = MM_REFERENCE;
1207 	else if (bIsMatrix && nMatrixRows && nMatrixCols)
1208 		nMatrixFlag = MM_FORMULA;
1209 }
1210 
~ScXMLChangeCellContext()1211 ScXMLChangeCellContext::~ScXMLChangeCellContext()
1212 {
1213 }
1214 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)1215 SvXMLImportContext *ScXMLChangeCellContext::CreateChildContext( sal_uInt16 nPrefix,
1216 									 const ::rtl::OUString& rLocalName,
1217 									 const ::com::sun::star::uno::Reference<
1218 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1219 {
1220 	SvXMLImportContext *pContext(0);
1221 
1222 	if ((nPrefix == XML_NAMESPACE_TEXT) && (IsXMLToken(rLocalName, XML_P)))
1223 	{
1224 		bEmpty = sal_False;
1225 		if (bFirstParagraph)
1226 		{
1227 			pContext = new ScXMLChangeTextPContext(GetScImport(), nPrefix, rLocalName, xAttrList, this);
1228 			bFirstParagraph = sal_False;
1229 		}
1230 		else
1231 		{
1232 			if (!pEditTextObj)
1233 				CreateTextPContext(sal_True);
1234 			pContext = GetScImport().GetTextImport()->CreateTextChildContext(
1235 				GetScImport(), nPrefix, rLocalName, xAttrList);
1236 		}
1237 	}
1238 
1239 	if( !pContext )
1240 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1241 
1242 	return pContext;
1243 }
1244 
CreateTextPContext(sal_Bool bIsNewParagraph)1245 void ScXMLChangeCellContext::CreateTextPContext(sal_Bool bIsNewParagraph)
1246 {
1247 	if (GetScImport().GetDocument())
1248 	{
1249 		pEditTextObj = new ScEditEngineTextObj();
1250 		pEditTextObj->acquire();
1251 		pEditTextObj->GetEditEngine()->SetEditTextObjectPool(GetScImport().GetDocument()->GetEditPool());
1252 		uno::Reference <text::XText> xText(pEditTextObj);
1253 		if (xText.is())
1254 		{
1255 			uno::Reference<text::XTextCursor> xTextCursor(xText->createTextCursor());
1256 			if (bIsNewParagraph)
1257 			{
1258 				xText->setString(sText);
1259 				xTextCursor->gotoEnd(sal_False);
1260 				uno::Reference < text::XTextRange > xTextRange (xTextCursor, uno::UNO_QUERY);
1261 				if (xTextRange.is())
1262 					xText->insertControlCharacter(xTextRange, text::ControlCharacter::PARAGRAPH_BREAK, sal_False);
1263 			}
1264 			GetScImport().GetTextImport()->SetCursor(xTextCursor);
1265 		}
1266 	}
1267 }
1268 
EndElement()1269 void ScXMLChangeCellContext::EndElement()
1270 {
1271 	if (!bEmpty)
1272 	{
1273 		if (pEditTextObj)
1274 		{
1275 			if (GetImport().GetTextImport()->GetCursor().is())
1276 			{
1277 				//GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
1278 				if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, sal_True ) )
1279 				{
1280 					OUString sEmpty;
1281 					GetImport().GetTextImport()->GetText()->insertString(
1282 						GetImport().GetTextImport()->GetCursorAsRange(), sEmpty,
1283 						sal_True );
1284 				}
1285 			}
1286 			if (GetScImport().GetDocument())
1287 				rOldCell = new ScEditCell(pEditTextObj->CreateTextObject(), GetScImport().GetDocument(), GetScImport().GetDocument()->GetEditPool());
1288 			GetScImport().GetTextImport()->ResetCursor();
1289 			// delete pEditTextObj;
1290 			pEditTextObj->release();
1291 		}
1292 		else
1293 		{
1294 			if (!bFormula)
1295 			{
1296 				if (sText.getLength() && bString)
1297 					rOldCell = new ScStringCell(sText);
1298 				else
1299 					rOldCell = new ScValueCell(fValue);
1300 			    if (rType == NUMBERFORMAT_DATE || rType == NUMBERFORMAT_TIME)
1301                     rInputString = sText;
1302 			}
1303 			else
1304 			{
1305 				// do nothing, this has to do later (on another place)
1306 				/*ScAddress aCellPos;
1307 				rOldCell = new ScFormulaCell(GetScImport().GetDocument(), aCellPos, sFormula);
1308 				if (bString)
1309 					static_cast<ScFormulaCell*>(rOldCell)->SetString(sValue);
1310 				else
1311 					static_cast<ScFormulaCell*>(rOldCell)->SetDouble(fValue);
1312 				static_cast<ScFormulaCell*>(rOldCell)->SetInChangeTrack(sal_True);
1313 				if (bIsCoveredMatrix)
1314 					static_cast<ScFormulaCell*>(rOldCell)->SetMatrixFlag(MM_REFERENCE);
1315 				else if (bIsMatrix && nMatrixRows && nMatrixCols)
1316 				{
1317 					static_cast<ScFormulaCell*>(rOldCell)->SetMatrixFlag(MM_FORMULA);
1318 					static_cast<ScFormulaCell*>(rOldCell)->SetMatColsRows(static_cast<SCCOL>(nMatrixCols), static_cast<SCROW>(nMatrixRows));
1319 				}*/
1320 			}
1321 		}
1322 	}
1323 	else
1324 		rOldCell = NULL;
1325 }
1326 
ScXMLPreviousContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScXMLChangeTrackingImportHelper * pTempChangeTrackingImportHelper)1327 ScXMLPreviousContext::ScXMLPreviousContext(  ScXMLImport& rImport,
1328 											  sal_uInt16 nPrfx,
1329 				   	  						  const ::rtl::OUString& rLName,
1330 									  		const uno::Reference<xml::sax::XAttributeList>& xAttrList,
1331 											ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1332 	SvXMLImportContext( rImport, nPrfx, rLName ),
1333 	pChangeTrackingImportHelper(pTempChangeTrackingImportHelper),
1334 	pOldCell(NULL),
1335 	nID(0),
1336 	nMatrixCols(0),
1337 	nMatrixRows(0),
1338     eGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT),
1339 	nType(NUMBERFORMAT_ALL),
1340 	nMatrixFlag(MM_NONE)
1341 {
1342 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
1343 	for( sal_Int16 i=0; i < nAttrCount; ++i )
1344 	{
1345 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
1346 		rtl::OUString aLocalName;
1347 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
1348 											sAttrName, &aLocalName ));
1349 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
1350 
1351 		if (nPrefix == XML_NAMESPACE_TABLE)
1352 		{
1353 			if (IsXMLToken(aLocalName, XML_ID))
1354 				nID = pChangeTrackingImportHelper->GetIDFromString(sValue);
1355 		}
1356 	}
1357 }
1358 
~ScXMLPreviousContext()1359 ScXMLPreviousContext::~ScXMLPreviousContext()
1360 {
1361 }
1362 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)1363 SvXMLImportContext *ScXMLPreviousContext::CreateChildContext( sal_uInt16 nPrefix,
1364 									 const ::rtl::OUString& rLocalName,
1365 									 const ::com::sun::star::uno::Reference<
1366 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1367 {
1368 	SvXMLImportContext *pContext(0);
1369 
1370 	if ((nPrefix == XML_NAMESPACE_TABLE) && (IsXMLToken(rLocalName, XML_CHANGE_TRACK_TABLE_CELL)))
1371 		pContext = new ScXMLChangeCellContext(GetScImport(), nPrefix, rLocalName, xAttrList,
1372             pOldCell, sFormulaAddress, sFormula, sFormulaNmsp, eGrammar, sInputString, fValue, nType, nMatrixFlag, nMatrixCols, nMatrixRows);
1373 
1374 	if( !pContext )
1375 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1376 
1377 	return pContext;
1378 }
1379 
EndElement()1380 void ScXMLPreviousContext::EndElement()
1381 {
1382     pChangeTrackingImportHelper->SetPreviousChange(nID, new ScMyCellInfo(pOldCell, sFormulaAddress, sFormula, eGrammar, sInputString,
1383         fValue, nType, nMatrixFlag, nMatrixCols, nMatrixRows));
1384 }
1385 
ScXMLContentChangeContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScXMLChangeTrackingImportHelper * pTempChangeTrackingImportHelper)1386 ScXMLContentChangeContext::ScXMLContentChangeContext(  ScXMLImport& rImport,
1387 											  sal_uInt16 nPrfx,
1388 				   	  						  const ::rtl::OUString& rLName,
1389 									  		const uno::Reference<xml::sax::XAttributeList>& xAttrList,
1390 											ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1391 	SvXMLImportContext( rImport, nPrfx, rLName ),
1392 	pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1393 {
1394 	sal_uInt32 nActionNumber(0);
1395 	sal_uInt32 nRejectingNumber(0);
1396 	ScChangeActionState nActionState(SC_CAS_VIRGIN);
1397 
1398 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
1399 	for( sal_Int16 i=0; i < nAttrCount; ++i )
1400 	{
1401 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
1402 		rtl::OUString aLocalName;
1403 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
1404 											sAttrName, &aLocalName ));
1405 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
1406 
1407 		if (nPrefix == XML_NAMESPACE_TABLE)
1408 		{
1409 			if (IsXMLToken(aLocalName, XML_ID))
1410 			{
1411 				nActionNumber = pChangeTrackingImportHelper->GetIDFromString(sValue);
1412 			}
1413 			else if (IsXMLToken(aLocalName, XML_ACCEPTANCE_STATE))
1414 			{
1415 				if (IsXMLToken(sValue, XML_ACCEPTED))
1416 					nActionState = SC_CAS_ACCEPTED;
1417 				else if (IsXMLToken(sValue, XML_REJECTED))
1418 					nActionState = SC_CAS_REJECTED;
1419 			}
1420 			else if (IsXMLToken(aLocalName, XML_REJECTING_CHANGE_ID))
1421 			{
1422 				nRejectingNumber = pChangeTrackingImportHelper->GetIDFromString(sValue);
1423 			}
1424 		}
1425 	}
1426 
1427 	pChangeTrackingImportHelper->StartChangeAction(SC_CAT_CONTENT);
1428 	pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1429 	pChangeTrackingImportHelper->SetActionState(nActionState);
1430 	pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1431 }
1432 
~ScXMLContentChangeContext()1433 ScXMLContentChangeContext::~ScXMLContentChangeContext()
1434 {
1435 }
1436 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)1437 SvXMLImportContext *ScXMLContentChangeContext::CreateChildContext( sal_uInt16 nPrefix,
1438 									 const ::rtl::OUString& rLocalName,
1439 									 const ::com::sun::star::uno::Reference<
1440 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1441 {
1442 	SvXMLImportContext *pContext(0);
1443 
1444 	if ((nPrefix == XML_NAMESPACE_OFFICE) && (IsXMLToken(rLocalName, XML_CHANGE_INFO)))
1445 	{
1446 		pContext = new ScXMLChangeInfoContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1447 	}
1448 	else if (nPrefix == XML_NAMESPACE_TABLE)
1449 	{
1450 		if (IsXMLToken(rLocalName, XML_CELL_ADDRESS))
1451 		{
1452 			pContext = new ScXMLBigRangeContext(GetScImport(), nPrefix, rLocalName, xAttrList, aBigRange);
1453 		}
1454 		else if (IsXMLToken(rLocalName, XML_DEPENDENCIES))
1455 		{
1456 			pContext = new ScXMLDependingsContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1457 		}
1458 		else if (IsXMLToken(rLocalName, XML_DELETIONS))
1459 			pContext = new ScXMLDeletionsContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1460 		else if (IsXMLToken(rLocalName, XML_PREVIOUS))
1461 		{
1462 			pContext = new ScXMLPreviousContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1463 		}
1464 	}
1465 
1466 	if( !pContext )
1467 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1468 
1469 	return pContext;
1470 }
1471 
EndElement()1472 void ScXMLContentChangeContext::EndElement()
1473 {
1474 	pChangeTrackingImportHelper->SetBigRange(aBigRange);
1475 	pChangeTrackingImportHelper->EndChangeAction();
1476 }
1477 
ScXMLInsertionContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScXMLChangeTrackingImportHelper * pTempChangeTrackingImportHelper)1478 ScXMLInsertionContext::ScXMLInsertionContext( ScXMLImport& rImport,
1479 											  sal_uInt16 nPrfx,
1480 				   	  						  const ::rtl::OUString& rLName,
1481 									  		const uno::Reference<xml::sax::XAttributeList>& xAttrList,
1482 											ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1483 	SvXMLImportContext( rImport, nPrfx, rLName ),
1484 	pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1485 {
1486 	sal_uInt32 nActionNumber(0);
1487 	sal_uInt32 nRejectingNumber(0);
1488 	sal_Int32 nPosition(0);
1489 	sal_Int32 nCount(1);
1490 	sal_Int32 nTable(0);
1491 	ScChangeActionState nActionState(SC_CAS_VIRGIN);
1492 	ScChangeActionType nActionType(SC_CAT_INSERT_COLS);
1493 
1494 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
1495 	for( sal_Int16 i=0; i < nAttrCount; ++i )
1496 	{
1497 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
1498 		rtl::OUString aLocalName;
1499 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
1500 											sAttrName, &aLocalName ));
1501 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
1502 
1503 		if (nPrefix == XML_NAMESPACE_TABLE)
1504 		{
1505 			if (IsXMLToken(aLocalName, XML_ID))
1506 			{
1507 				nActionNumber = pChangeTrackingImportHelper->GetIDFromString(sValue);
1508 			}
1509 			else if (IsXMLToken(aLocalName, XML_ACCEPTANCE_STATE))
1510 			{
1511 				if (IsXMLToken(sValue, XML_ACCEPTED))
1512 					nActionState = SC_CAS_ACCEPTED;
1513 				else if (IsXMLToken(sValue, XML_REJECTED))
1514 					nActionState = SC_CAS_REJECTED;
1515 			}
1516 			else if (IsXMLToken(aLocalName, XML_REJECTING_CHANGE_ID))
1517 			{
1518 				nRejectingNumber = pChangeTrackingImportHelper->GetIDFromString(sValue);
1519 			}
1520 			else if (IsXMLToken(aLocalName, XML_TYPE))
1521 			{
1522 				if (IsXMLToken(sValue, XML_ROW))
1523 					nActionType = SC_CAT_INSERT_ROWS;
1524 				else if (IsXMLToken(sValue, XML_TABLE))
1525 					nActionType = SC_CAT_INSERT_TABS;
1526 			}
1527 			else if (IsXMLToken(aLocalName, XML_POSITION))
1528 			{
1529 				SvXMLUnitConverter::convertNumber(nPosition, sValue);
1530 			}
1531 			else if (IsXMLToken(aLocalName, XML_TABLE))
1532 			{
1533 				SvXMLUnitConverter::convertNumber(nTable, sValue);
1534 			}
1535 			else if (IsXMLToken(aLocalName, XML_COUNT))
1536 			{
1537 				SvXMLUnitConverter::convertNumber(nCount, sValue);
1538 			}
1539 		}
1540 	}
1541 
1542 	pChangeTrackingImportHelper->StartChangeAction(nActionType);
1543 	pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1544 	pChangeTrackingImportHelper->SetActionState(nActionState);
1545 	pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1546 	pChangeTrackingImportHelper->SetPosition(nPosition, nCount, nTable);
1547 }
1548 
~ScXMLInsertionContext()1549 ScXMLInsertionContext::~ScXMLInsertionContext()
1550 {
1551 }
1552 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)1553 SvXMLImportContext *ScXMLInsertionContext::CreateChildContext( sal_uInt16 nPrefix,
1554 									 const ::rtl::OUString& rLocalName,
1555 									 const ::com::sun::star::uno::Reference<
1556 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1557 {
1558 	SvXMLImportContext *pContext(0);
1559 
1560 	if ((nPrefix == XML_NAMESPACE_OFFICE) && (IsXMLToken(rLocalName, XML_CHANGE_INFO)))
1561 	{
1562 		pContext = new ScXMLChangeInfoContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1563 	}
1564 	else if (nPrefix == XML_NAMESPACE_TABLE)
1565 	{
1566 		if (IsXMLToken(rLocalName, XML_DEPENDENCIES))
1567 			pContext = new ScXMLDependingsContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1568 		else if (IsXMLToken(rLocalName, XML_DELETIONS))
1569 			pContext = new ScXMLDeletionsContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1570 	}
1571 
1572 	if( !pContext )
1573 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1574 
1575 	return pContext;
1576 }
1577 
EndElement()1578 void ScXMLInsertionContext::EndElement()
1579 {
1580 	pChangeTrackingImportHelper->EndChangeAction();
1581 }
1582 
ScXMLInsertionCutOffContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScXMLChangeTrackingImportHelper * pTempChangeTrackingImportHelper)1583 ScXMLInsertionCutOffContext::ScXMLInsertionCutOffContext( ScXMLImport& rImport,
1584 											  sal_uInt16 nPrfx,
1585 				   	  						  const ::rtl::OUString& rLName,
1586 									  		const uno::Reference<xml::sax::XAttributeList>& xAttrList,
1587 											ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1588 	SvXMLImportContext( rImport, nPrfx, rLName ),
1589 	pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1590 {
1591 	sal_uInt32 nID(0);
1592 	sal_Int32 nPosition(0);
1593 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
1594 	for( sal_Int16 i=0; i < nAttrCount; ++i )
1595 	{
1596 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
1597 		rtl::OUString aLocalName;
1598 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
1599 											sAttrName, &aLocalName ));
1600 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
1601 
1602 		if (nPrefix == XML_NAMESPACE_TABLE)
1603 		{
1604 			if (IsXMLToken(aLocalName, XML_ID))
1605 			{
1606 				nID = pChangeTrackingImportHelper->GetIDFromString(sValue);
1607 			}
1608 			else if (IsXMLToken(aLocalName, XML_POSITION))
1609 			{
1610 				SvXMLUnitConverter::convertNumber(nPosition, sValue);
1611 			}
1612 		}
1613 	}
1614 	pChangeTrackingImportHelper->SetInsertionCutOff(nID, nPosition);
1615 }
1616 
~ScXMLInsertionCutOffContext()1617 ScXMLInsertionCutOffContext::~ScXMLInsertionCutOffContext()
1618 {
1619 }
1620 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &)1621 SvXMLImportContext *ScXMLInsertionCutOffContext::CreateChildContext( sal_uInt16 nPrefix,
1622 									 const ::rtl::OUString& rLocalName,
1623 									 const ::com::sun::star::uno::Reference<
1624                                         ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
1625 {
1626 	return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1627 }
1628 
EndElement()1629 void ScXMLInsertionCutOffContext::EndElement()
1630 {
1631 }
1632 
ScXMLMovementCutOffContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScXMLChangeTrackingImportHelper * pTempChangeTrackingImportHelper)1633 ScXMLMovementCutOffContext::ScXMLMovementCutOffContext( ScXMLImport& rImport,
1634 											  sal_uInt16 nPrfx,
1635 				   	  						  const ::rtl::OUString& rLName,
1636 									  		const uno::Reference<xml::sax::XAttributeList>& xAttrList,
1637 											ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1638 	SvXMLImportContext( rImport, nPrfx, rLName ),
1639 	pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1640 {
1641 	sal_uInt32 nID(0);
1642 	sal_Int32 nPosition(0);
1643 	sal_Int32 nStartPosition(0);
1644 	sal_Int32 nEndPosition(0);
1645 	sal_Bool bPosition(sal_False);
1646 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
1647 	for( sal_Int16 i=0; i < nAttrCount; ++i )
1648 	{
1649 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
1650 		rtl::OUString aLocalName;
1651 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
1652 											sAttrName, &aLocalName ));
1653 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
1654 
1655 		if (nPrefix == XML_NAMESPACE_TABLE)
1656 		{
1657 			if (IsXMLToken(aLocalName, XML_ID))
1658 			{
1659 				nID = pChangeTrackingImportHelper->GetIDFromString(sValue);
1660 			}
1661 			else if (IsXMLToken(aLocalName, XML_POSITION))
1662 			{
1663 				bPosition = sal_True;
1664 				SvXMLUnitConverter::convertNumber(nPosition, sValue);
1665 			}
1666 			else if (IsXMLToken(aLocalName, XML_START_POSITION))
1667 			{
1668 				SvXMLUnitConverter::convertNumber(nStartPosition, sValue);
1669 			}
1670 			else if (IsXMLToken(aLocalName, XML_END_POSITION))
1671 			{
1672 				SvXMLUnitConverter::convertNumber(nEndPosition, sValue);
1673 			}
1674 		}
1675 	}
1676 	if (bPosition)
1677 		nStartPosition = nEndPosition = nPosition;
1678 	pChangeTrackingImportHelper->AddMoveCutOff(nID, nStartPosition, nEndPosition);
1679 }
1680 
~ScXMLMovementCutOffContext()1681 ScXMLMovementCutOffContext::~ScXMLMovementCutOffContext()
1682 {
1683 }
1684 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &)1685 SvXMLImportContext *ScXMLMovementCutOffContext::CreateChildContext( sal_uInt16 nPrefix,
1686 									 const ::rtl::OUString& rLocalName,
1687 									 const ::com::sun::star::uno::Reference<
1688                                         ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
1689 {
1690 	return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1691 }
1692 
EndElement()1693 void ScXMLMovementCutOffContext::EndElement()
1694 {
1695 }
1696 
ScXMLCutOffsContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &,ScXMLChangeTrackingImportHelper * pTempChangeTrackingImportHelper)1697 ScXMLCutOffsContext::ScXMLCutOffsContext( ScXMLImport& rImport,
1698 											  sal_uInt16 nPrfx,
1699 				   	  						  const ::rtl::OUString& rLName,
1700                                             const uno::Reference<xml::sax::XAttributeList>& /* xAttrList */,
1701 											ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1702 	SvXMLImportContext( rImport, nPrfx, rLName ),
1703 	pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1704 {
1705 	// here are no attributes
1706 }
1707 
~ScXMLCutOffsContext()1708 ScXMLCutOffsContext::~ScXMLCutOffsContext()
1709 {
1710 }
1711 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)1712 SvXMLImportContext *ScXMLCutOffsContext::CreateChildContext( sal_uInt16 nPrefix,
1713 									 const ::rtl::OUString& rLocalName,
1714 									 const ::com::sun::star::uno::Reference<
1715 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1716 {
1717 	SvXMLImportContext *pContext(0);
1718 
1719 	if (nPrefix == XML_NAMESPACE_TABLE)
1720 	{
1721 		if (IsXMLToken(rLocalName, XML_INSERTION_CUT_OFF))
1722 			pContext = new ScXMLInsertionCutOffContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1723 		else if (IsXMLToken(rLocalName, XML_MOVEMENT_CUT_OFF))
1724 			pContext = new ScXMLMovementCutOffContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1725 	}
1726 
1727 	if( !pContext )
1728 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1729 
1730 	return pContext;
1731 }
1732 
EndElement()1733 void ScXMLCutOffsContext::EndElement()
1734 {
1735 }
1736 
ScXMLDeletionContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScXMLChangeTrackingImportHelper * pTempChangeTrackingImportHelper)1737 ScXMLDeletionContext::ScXMLDeletionContext( ScXMLImport& rImport,
1738 											  sal_uInt16 nPrfx,
1739 				   	  						  const ::rtl::OUString& rLName,
1740 									  		const uno::Reference<xml::sax::XAttributeList>& xAttrList,
1741 											ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1742 	SvXMLImportContext( rImport, nPrfx, rLName ),
1743 	pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1744 {
1745 	sal_uInt32 nActionNumber(0);
1746 	sal_uInt32 nRejectingNumber(0);
1747 	sal_Int32 nPosition(0);
1748 	sal_Int32 nMultiSpanned(0);
1749 	sal_Int32 nTable(0);
1750 	ScChangeActionState nActionState(SC_CAS_VIRGIN);
1751 	ScChangeActionType nActionType(SC_CAT_DELETE_COLS);
1752 
1753 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
1754 	for( sal_Int16 i=0; i < nAttrCount; i++ )
1755 	{
1756 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
1757 		rtl::OUString aLocalName;
1758 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
1759 											sAttrName, &aLocalName ));
1760 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
1761 
1762 		if (nPrefix == XML_NAMESPACE_TABLE)
1763 		{
1764 			if (IsXMLToken(aLocalName, XML_ID))
1765 			{
1766 				nActionNumber = pChangeTrackingImportHelper->GetIDFromString(sValue);
1767 			}
1768 			else if (IsXMLToken(aLocalName, XML_ACCEPTANCE_STATE))
1769 			{
1770 				if (IsXMLToken(sValue, XML_ACCEPTED))
1771 					nActionState = SC_CAS_ACCEPTED;
1772 				else if (IsXMLToken(sValue, XML_REJECTED))
1773 					nActionState = SC_CAS_REJECTED;
1774 			}
1775 			else if (IsXMLToken(aLocalName, XML_REJECTING_CHANGE_ID))
1776 			{
1777 				nRejectingNumber = pChangeTrackingImportHelper->GetIDFromString(sValue);
1778 			}
1779 			else if (IsXMLToken(aLocalName, XML_TYPE))
1780 			{
1781 				if (IsXMLToken(sValue, XML_ROW))
1782 				{
1783 					nActionType = SC_CAT_DELETE_ROWS;
1784 				}
1785 				else if (IsXMLToken(aLocalName, XML_TABLE))
1786 				{
1787 					nActionType = SC_CAT_DELETE_TABS;
1788 				}
1789 			}
1790 			else if (IsXMLToken(aLocalName, XML_POSITION))
1791 			{
1792 				SvXMLUnitConverter::convertNumber(nPosition, sValue);
1793 			}
1794 			else if (IsXMLToken(aLocalName, XML_TABLE))
1795 			{
1796 				SvXMLUnitConverter::convertNumber(nTable, sValue);
1797 			}
1798 			else if (IsXMLToken(aLocalName, XML_MULTI_DELETION_SPANNED))
1799 			{
1800 				SvXMLUnitConverter::convertNumber(nMultiSpanned, sValue);
1801 			}
1802 		}
1803 	}
1804 
1805 	pChangeTrackingImportHelper->StartChangeAction(nActionType);
1806 	pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1807 	pChangeTrackingImportHelper->SetActionState(nActionState);
1808 	pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1809 	pChangeTrackingImportHelper->SetPosition(nPosition, 1, nTable);
1810 	pChangeTrackingImportHelper->SetMultiSpanned(static_cast<sal_Int16>(nMultiSpanned));
1811 }
1812 
~ScXMLDeletionContext()1813 ScXMLDeletionContext::~ScXMLDeletionContext()
1814 {
1815 }
1816 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)1817 SvXMLImportContext *ScXMLDeletionContext::CreateChildContext( sal_uInt16 nPrefix,
1818 									 const ::rtl::OUString& rLocalName,
1819 									 const ::com::sun::star::uno::Reference<
1820 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1821 {
1822 	SvXMLImportContext *pContext(0);
1823 
1824 	if ((nPrefix == XML_NAMESPACE_OFFICE) && (IsXMLToken(rLocalName, XML_CHANGE_INFO)))
1825 	{
1826 		pContext = new ScXMLChangeInfoContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1827 	}
1828 	else if (nPrefix == XML_NAMESPACE_TABLE)
1829 	{
1830 		if (IsXMLToken(rLocalName, XML_DEPENDENCIES))
1831 			pContext = new ScXMLDependingsContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1832 		else if (IsXMLToken(rLocalName, XML_DELETIONS))
1833 			pContext = new ScXMLDeletionsContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1834 		else if (IsXMLToken(rLocalName, XML_CUT_OFFS) || rLocalName.equalsAsciiL("cut_offs", 8))
1835 			pContext = new ScXMLCutOffsContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1836 		else
1837 		{
1838 			DBG_ERROR("don't know this");
1839 		}
1840 	}
1841 
1842 	if( !pContext )
1843 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1844 
1845 	return pContext;
1846 }
1847 
EndElement()1848 void ScXMLDeletionContext::EndElement()
1849 {
1850 	pChangeTrackingImportHelper->EndChangeAction();
1851 }
1852 
ScXMLMovementContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScXMLChangeTrackingImportHelper * pTempChangeTrackingImportHelper)1853 ScXMLMovementContext::ScXMLMovementContext( ScXMLImport& rImport,
1854 											  sal_uInt16 nPrfx,
1855 				   	  						  const ::rtl::OUString& rLName,
1856 									  		const uno::Reference<xml::sax::XAttributeList>& xAttrList,
1857 											ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1858 	SvXMLImportContext( rImport, nPrfx, rLName ),
1859 	pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1860 {
1861 	sal_uInt32 nActionNumber(0);
1862 	sal_uInt32 nRejectingNumber(0);
1863 	ScChangeActionState nActionState(SC_CAS_VIRGIN);
1864 
1865 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
1866 	for( sal_Int16 i=0; i < nAttrCount; ++i )
1867 	{
1868 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
1869 		rtl::OUString aLocalName;
1870 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
1871 											sAttrName, &aLocalName ));
1872 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
1873 
1874 		if (nPrefix == XML_NAMESPACE_TABLE)
1875 		{
1876 			if (IsXMLToken(aLocalName, XML_ID))
1877 			{
1878 				nActionNumber = pChangeTrackingImportHelper->GetIDFromString(sValue);
1879 			}
1880 			else if (IsXMLToken(aLocalName, XML_ACCEPTANCE_STATE))
1881 			{
1882 				if (IsXMLToken(sValue, XML_ACCEPTED))
1883 					nActionState = SC_CAS_ACCEPTED;
1884 				else if (IsXMLToken(sValue, XML_REJECTED))
1885 					nActionState = SC_CAS_REJECTED;
1886 			}
1887 			else if (IsXMLToken(aLocalName, XML_REJECTING_CHANGE_ID))
1888 			{
1889 				nRejectingNumber = pChangeTrackingImportHelper->GetIDFromString(sValue);
1890 			}
1891 		}
1892 	}
1893 
1894 	pChangeTrackingImportHelper->StartChangeAction(SC_CAT_MOVE);
1895 	pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1896 	pChangeTrackingImportHelper->SetActionState(nActionState);
1897 	pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1898 }
1899 
~ScXMLMovementContext()1900 ScXMLMovementContext::~ScXMLMovementContext()
1901 {
1902 }
1903 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)1904 SvXMLImportContext *ScXMLMovementContext::CreateChildContext( sal_uInt16 nPrefix,
1905 									 const ::rtl::OUString& rLocalName,
1906 									 const ::com::sun::star::uno::Reference<
1907 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1908 {
1909 	SvXMLImportContext *pContext(0);
1910 
1911 	if ((nPrefix == XML_NAMESPACE_OFFICE) && (IsXMLToken(rLocalName, XML_CHANGE_INFO)))
1912 	{
1913 		pContext = new ScXMLChangeInfoContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1914 	}
1915 	else if (nPrefix == XML_NAMESPACE_TABLE)
1916 	{
1917 		if (IsXMLToken(rLocalName, XML_DEPENDENCIES))
1918 			pContext = new ScXMLDependingsContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1919 		else if (IsXMLToken(rLocalName, XML_DELETIONS))
1920 			pContext = new ScXMLDeletionsContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
1921 		else if (IsXMLToken(rLocalName, XML_SOURCE_RANGE_ADDRESS))
1922 			pContext = new ScXMLBigRangeContext(GetScImport(), nPrefix, rLocalName, xAttrList, aSourceRange);
1923 		else if (IsXMLToken(rLocalName, XML_TARGET_RANGE_ADDRESS))
1924 			pContext = new ScXMLBigRangeContext(GetScImport(), nPrefix, rLocalName, xAttrList, aTargetRange);
1925 	}
1926 
1927 	if( !pContext )
1928 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1929 
1930 	return pContext;
1931 }
1932 
EndElement()1933 void ScXMLMovementContext::EndElement()
1934 {
1935 	pChangeTrackingImportHelper->SetMoveRanges(aSourceRange, aTargetRange);
1936 	pChangeTrackingImportHelper->EndChangeAction();
1937 }
1938 
ScXMLRejectionContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScXMLChangeTrackingImportHelper * pTempChangeTrackingImportHelper)1939 ScXMLRejectionContext::ScXMLRejectionContext( ScXMLImport& rImport,
1940 											  sal_uInt16 nPrfx,
1941 				   	  						  const ::rtl::OUString& rLName,
1942 									  		const uno::Reference<xml::sax::XAttributeList>& xAttrList,
1943 											ScXMLChangeTrackingImportHelper* pTempChangeTrackingImportHelper ) :
1944 	SvXMLImportContext( rImport, nPrfx, rLName ),
1945 	pChangeTrackingImportHelper(pTempChangeTrackingImportHelper)
1946 {
1947 	sal_uInt32 nActionNumber(0);
1948 	sal_uInt32 nRejectingNumber(0);
1949 	ScChangeActionState nActionState(SC_CAS_VIRGIN);
1950 
1951 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
1952 	for( sal_Int16 i=0; i < nAttrCount; ++i )
1953 	{
1954 		const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
1955 		rtl::OUString aLocalName;
1956 		sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
1957 											sAttrName, &aLocalName ));
1958 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
1959 
1960 		if (nPrefix == XML_NAMESPACE_TABLE)
1961 		{
1962 			if (IsXMLToken(aLocalName, XML_ID))
1963 			{
1964 				nActionNumber = pChangeTrackingImportHelper->GetIDFromString(sValue);
1965 			}
1966 			else if (IsXMLToken(aLocalName, XML_ACCEPTANCE_STATE))
1967 			{
1968 				if (IsXMLToken(sValue, XML_ACCEPTED))
1969 					nActionState = SC_CAS_ACCEPTED;
1970 				else if (IsXMLToken(sValue, XML_REJECTED))
1971 					nActionState = SC_CAS_REJECTED;
1972 			}
1973 			else if (IsXMLToken(aLocalName, XML_REJECTING_CHANGE_ID))
1974 			{
1975 				nRejectingNumber = pChangeTrackingImportHelper->GetIDFromString(sValue);
1976 			}
1977 		}
1978 	}
1979 
1980 	pChangeTrackingImportHelper->StartChangeAction(SC_CAT_MOVE);
1981 	pChangeTrackingImportHelper->SetActionNumber(nActionNumber);
1982 	pChangeTrackingImportHelper->SetActionState(nActionState);
1983 	pChangeTrackingImportHelper->SetRejectingNumber(nRejectingNumber);
1984 }
1985 
~ScXMLRejectionContext()1986 ScXMLRejectionContext::~ScXMLRejectionContext()
1987 {
1988 }
1989 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)1990 SvXMLImportContext *ScXMLRejectionContext::CreateChildContext( sal_uInt16 nPrefix,
1991 									 const ::rtl::OUString& rLocalName,
1992 									 const ::com::sun::star::uno::Reference<
1993 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1994 {
1995 	SvXMLImportContext *pContext(0);
1996 
1997 	if ((nPrefix == XML_NAMESPACE_OFFICE) && (IsXMLToken(rLocalName, XML_CHANGE_INFO)))
1998 	{
1999 		pContext = new ScXMLChangeInfoContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
2000 	}
2001 	else if (nPrefix == XML_NAMESPACE_TABLE)
2002 	{
2003 		if (IsXMLToken(rLocalName, XML_DEPENDENCIES))
2004 			pContext = new ScXMLDependingsContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
2005 		else if (IsXMLToken(rLocalName, XML_DELETIONS))
2006 			pContext = new ScXMLDeletionsContext(GetScImport(), nPrefix, rLocalName, xAttrList, pChangeTrackingImportHelper);
2007 	}
2008 
2009 	if( !pContext )
2010 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
2011 
2012 	return pContext;
2013 }
2014 
EndElement()2015 void ScXMLRejectionContext::EndElement()
2016 {
2017 	pChangeTrackingImportHelper->EndChangeAction();
2018 }
2019 
2020 
2021 
2022