Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "XMLChangeTrackingExportHelper.hxx"
30 : : #include "xmlexprt.hxx"
31 : : #include "XMLConverter.hxx"
32 : : #include "document.hxx"
33 : : #include "chgtrack.hxx"
34 : : #include "chgviset.hxx"
35 : : #include "cell.hxx"
36 : : #include "textuno.hxx"
37 : : #include "rangeutl.hxx"
38 : : #include <xmloff/xmlnmspe.hxx>
39 : : #include <xmloff/nmspmap.hxx>
40 : : #include <xmloff/xmluconv.hxx>
41 : : #include <sax/tools/converter.hxx>
42 : : #include <com/sun/star/util/DateTime.hpp>
43 : : #include <tools/datetime.hxx>
44 : : #include <svl/zforlist.hxx>
45 : :
46 : : #define SC_CHANGE_ID_PREFIX "ct"
47 : :
48 : : using namespace ::com::sun::star;
49 : : using namespace xmloff::token;
50 : :
51 : 25 : ScChangeTrackingExportHelper::ScChangeTrackingExportHelper(ScXMLExport& rTempExport)
52 : : : rExport(rTempExport),
53 : : pChangeTrack(NULL),
54 : : pEditTextObj(NULL),
55 : : pDependings(NULL),
56 : 25 : sChangeIDPrefix(RTL_CONSTASCII_USTRINGPARAM(SC_CHANGE_ID_PREFIX))
57 : : {
58 [ + - ]: 25 : pChangeTrack = rExport.GetDocument() ? rExport.GetDocument()->GetChangeTrack() : NULL;
59 [ + - ][ + - ]: 25 : pDependings = new ScChangeActionMap();
60 : 25 : }
61 : :
62 : 22 : ScChangeTrackingExportHelper::~ScChangeTrackingExportHelper()
63 : : {
64 [ + - ]: 22 : if (pDependings)
65 [ + - ]: 22 : delete pDependings;
66 : 22 : }
67 : :
68 : 0 : rtl::OUString ScChangeTrackingExportHelper::GetChangeID(const sal_uInt32 nActionNumber)
69 : : {
70 [ # # ]: 0 : rtl::OUStringBuffer sBuffer(sChangeIDPrefix);
71 : : ::sax::Converter::convertNumber(sBuffer,
72 [ # # ]: 0 : static_cast<sal_Int32>(nActionNumber));
73 [ # # ]: 0 : return sBuffer.makeStringAndClear();
74 : : }
75 : :
76 : 0 : void ScChangeTrackingExportHelper::GetAcceptanceState(const ScChangeAction* pAction)
77 : : {
78 [ # # ]: 0 : if (pAction->IsRejected())
79 : 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_ACCEPTANCE_STATE, XML_REJECTED);
80 [ # # ]: 0 : else if (pAction->IsAccepted())
81 : 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_ACCEPTANCE_STATE, XML_ACCEPTED);
82 : 0 : }
83 : :
84 : 0 : void ScChangeTrackingExportHelper::WriteBigRange(const ScBigRange& rBigRange, XMLTokenEnum aName)
85 : : {
86 : : sal_Int32 nStartColumn;
87 : : sal_Int32 nEndColumn;
88 : : sal_Int32 nStartRow;
89 : : sal_Int32 nEndRow;
90 : : sal_Int32 nStartSheet;
91 : : sal_Int32 nEndSheet;
92 : : rBigRange.GetVars(nStartColumn, nStartRow, nStartSheet,
93 : 0 : nEndColumn, nEndRow, nEndSheet);
94 [ # # ][ # # ]: 0 : if ((nStartColumn == nEndColumn) && (nStartRow == nEndRow) && (nStartSheet == nEndSheet))
[ # # ]
95 : : {
96 : 0 : rtl::OUStringBuffer sBuffer;
97 [ # # ]: 0 : ::sax::Converter::convertNumber(sBuffer, nStartColumn);
98 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_COLUMN, sBuffer.makeStringAndClear());
99 [ # # ]: 0 : ::sax::Converter::convertNumber(sBuffer, nStartRow);
100 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_ROW, sBuffer.makeStringAndClear());
101 [ # # ]: 0 : ::sax::Converter::convertNumber(sBuffer, nStartSheet);
102 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_TABLE, sBuffer.makeStringAndClear());
103 : : }
104 : : else
105 : : {
106 : 0 : rtl::OUStringBuffer sBuffer;
107 [ # # ]: 0 : ::sax::Converter::convertNumber(sBuffer, nStartColumn);
108 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_START_COLUMN, sBuffer.makeStringAndClear());
109 [ # # ]: 0 : ::sax::Converter::convertNumber(sBuffer, nStartRow);
110 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_START_ROW, sBuffer.makeStringAndClear());
111 [ # # ]: 0 : ::sax::Converter::convertNumber(sBuffer, nStartSheet);
112 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_START_TABLE, sBuffer.makeStringAndClear());
113 [ # # ]: 0 : ::sax::Converter::convertNumber(sBuffer, nEndColumn);
114 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_END_COLUMN, sBuffer.makeStringAndClear());
115 [ # # ]: 0 : ::sax::Converter::convertNumber(sBuffer, nEndRow);
116 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_END_ROW, sBuffer.makeStringAndClear());
117 [ # # ]: 0 : ::sax::Converter::convertNumber(sBuffer, nEndSheet);
118 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_END_TABLE, sBuffer.makeStringAndClear());
119 : : }
120 [ # # ][ # # ]: 0 : SvXMLElementExport aBigRangeElem(rExport, XML_NAMESPACE_TABLE, aName, true, true);
121 : 0 : }
122 : :
123 : 0 : void ScChangeTrackingExportHelper::WriteChangeInfo(const ScChangeAction* pAction)
124 : : {
125 [ # # ]: 0 : SvXMLElementExport aElemInfo (rExport, XML_NAMESPACE_OFFICE, XML_CHANGE_INFO, true, true);
126 : :
127 : : {
128 : : SvXMLElementExport aCreatorElem( rExport, XML_NAMESPACE_DC,
129 : : XML_CREATOR, true,
130 [ # # ]: 0 : false );
131 [ # # ]: 0 : rtl::OUString sAuthor(pAction->GetUser());
132 [ # # ][ # # ]: 0 : rExport.Characters(sAuthor);
133 : : }
134 : :
135 : : {
136 : 0 : rtl::OUStringBuffer sDate;
137 [ # # ]: 0 : ScXMLConverter::ConvertDateTimeToString(pAction->GetDateTimeUTC(), sDate);
138 : : SvXMLElementExport aDateElem( rExport, XML_NAMESPACE_DC,
139 : : XML_DATE, true,
140 [ # # ]: 0 : false );
141 [ # # ][ # # ]: 0 : rExport.Characters(sDate.makeStringAndClear());
[ # # ]
142 : : }
143 : :
144 [ # # ]: 0 : rtl::OUString sComment(pAction->GetComment());
145 [ # # ]: 0 : if (!sComment.isEmpty())
146 : : {
147 [ # # ]: 0 : SvXMLElementExport aElemC(rExport, XML_NAMESPACE_TEXT, XML_P, true, false);
148 : 0 : bool bPrevCharWasSpace(true);
149 [ # # ][ # # ]: 0 : rExport.GetTextParagraphExport()->exportText(sComment, bPrevCharWasSpace);
[ # # ][ # # ]
[ # # ]
150 [ # # ]: 0 : }
151 : 0 : }
152 : :
153 : 0 : void ScChangeTrackingExportHelper::WriteGenerated(const ScChangeAction* pGeneratedAction)
154 : : {
155 : : #if OSL_DEBUG_LEVEL > 0
156 : : sal_uInt32 nActionNumber(pGeneratedAction->GetActionNumber());
157 : : OSL_ENSURE(pChangeTrack->IsGenerated(nActionNumber), "a not generated action found");
158 : : #endif
159 [ # # ]: 0 : SvXMLElementExport aElemPrev(rExport, XML_NAMESPACE_TABLE, XML_CELL_CONTENT_DELETION, true, true);
160 [ # # ]: 0 : WriteBigRange(pGeneratedAction->GetBigRange(), XML_CELL_ADDRESS);
161 : 0 : rtl::OUString sValue;
162 [ # # ]: 0 : static_cast<const ScChangeActionContent*>(pGeneratedAction)->GetNewString(sValue);
163 [ # # ][ # # ]: 0 : WriteCell(static_cast<const ScChangeActionContent*>(pGeneratedAction)->GetNewCell(), sValue);
[ # # ][ # # ]
164 : 0 : }
165 : :
166 : 0 : void ScChangeTrackingExportHelper::WriteDeleted(const ScChangeAction* pDeletedAction)
167 : : {
168 : 0 : sal_uInt32 nActionNumber(pDeletedAction->GetActionNumber());
169 [ # # ]: 0 : if (pDeletedAction->GetType() == SC_CAT_CONTENT)
170 : : {
171 : 0 : const ScChangeActionContent* pContentAction = static_cast<const ScChangeActionContent*>(pDeletedAction);
172 [ # # ]: 0 : if (pContentAction)
173 : : {
174 [ # # ]: 0 : if (!pChangeTrack->IsGenerated(nActionNumber))
175 : : {
176 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_ID, GetChangeID(nActionNumber));
177 [ # # ]: 0 : SvXMLElementExport aElemPrev(rExport, XML_NAMESPACE_TABLE, XML_CELL_CONTENT_DELETION, true, true);
178 [ # # ][ # # ]: 0 : if (static_cast<const ScChangeActionContent*>(pDeletedAction)->IsTopContent() && pDeletedAction->IsDeletedIn())
[ # # ][ # # ]
179 : : {
180 : 0 : rtl::OUString sValue;
181 [ # # ]: 0 : pContentAction->GetNewString(sValue);
182 [ # # ][ # # ]: 0 : WriteCell(pContentAction->GetNewCell(), sValue);
[ # # ]
183 [ # # ]: 0 : }
184 : : }
185 : : else
186 : 0 : WriteGenerated(pContentAction);
187 : : }
188 : : }
189 : : else
190 : : {
191 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_ID, GetChangeID(nActionNumber));
192 [ # # ][ # # ]: 0 : SvXMLElementExport aElemPrev(rExport, XML_NAMESPACE_TABLE, XML_CHANGE_DELETION, true, true);
193 : : }
194 : 0 : }
195 : :
196 : 0 : void ScChangeTrackingExportHelper::WriteDepending(const ScChangeAction* pDependAction)
197 : : {
198 : 0 : sal_uInt32 nActionNumber(pDependAction->GetActionNumber());
199 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_ID, GetChangeID(nActionNumber));
200 : :
201 : : // #i80033# save old "dependence" element if backward compatibility is requested,
202 : : // correct "dependency" element otherwise
203 : 0 : const bool bSaveBackwardsCompatible = ( rExport.getExportFlags() & EXPORT_SAVEBACKWARDCOMPATIBLE );
204 : : SvXMLElementExport aDependElem(rExport, XML_NAMESPACE_TABLE,
205 : : bSaveBackwardsCompatible ? XML_DEPENDENCE : XML_DEPENDENCY,
206 [ # # ][ # # ]: 0 : true, true);
[ # # ]
207 : 0 : }
208 : :
209 : 0 : void ScChangeTrackingExportHelper::WriteDependings(ScChangeAction* pAction)
210 : : {
211 [ # # ]: 0 : if (pAction->HasDependent())
212 : : {
213 [ # # ]: 0 : SvXMLElementExport aDependingsElem (rExport, XML_NAMESPACE_TABLE, XML_DEPENDENCIES, true, true);
214 : 0 : const ScChangeActionLinkEntry* pEntry = pAction->GetFirstDependentEntry();
215 [ # # ]: 0 : while (pEntry)
216 : : {
217 [ # # ]: 0 : WriteDepending(pEntry->GetAction());
218 : 0 : pEntry = pEntry->GetNext();
219 [ # # ]: 0 : }
220 : : }
221 [ # # ]: 0 : if (pAction->HasDeleted())
222 : : {
223 [ # # ]: 0 : SvXMLElementExport aDependingsElem (rExport, XML_NAMESPACE_TABLE, XML_DELETIONS, true, true);
224 : 0 : const ScChangeActionLinkEntry* pEntry = pAction->GetFirstDeletedEntry();
225 [ # # ]: 0 : while (pEntry)
226 : : {
227 [ # # ]: 0 : WriteDeleted(pEntry->GetAction());
228 : 0 : pEntry = pEntry->GetNext();
229 [ # # ]: 0 : }
230 : : }
231 : 0 : }
232 : :
233 : 0 : void ScChangeTrackingExportHelper::WriteEmptyCell()
234 : : {
235 [ # # ][ # # ]: 0 : SvXMLElementExport aElemEmptyCell(rExport, XML_NAMESPACE_TABLE, XML_CHANGE_TRACK_TABLE_CELL, true, true);
236 : 0 : }
237 : :
238 : 0 : void ScChangeTrackingExportHelper::SetValueAttributes(const double& fValue, const String& sValue)
239 : : {
240 : 0 : bool bSetAttributes(false);
241 [ # # ]: 0 : if (sValue.Len())
242 : : {
243 : : sal_uInt32 nIndex;
244 : : double fTempValue;
245 [ # # ][ # # ]: 0 : if (rExport.GetDocument() && rExport.GetDocument()->GetFormatTable()->IsNumberFormat(sValue, nIndex, fTempValue))
[ # # ][ # # ]
[ # # ]
246 : : {
247 [ # # ][ # # ]: 0 : sal_uInt16 nType = rExport.GetDocument()->GetFormatTable()->GetType(nIndex);
248 [ # # ]: 0 : if ((nType & NUMBERFORMAT_DEFINED) == NUMBERFORMAT_DEFINED)
249 : 0 : nType -= NUMBERFORMAT_DEFINED;
250 [ # # # ]: 0 : switch(nType)
251 : : {
252 : : case NUMBERFORMAT_DATE:
253 : : {
254 [ # # ][ # # ]: 0 : if ( rExport.GetMM100UnitConverter().setNullDate(rExport.GetModel()) )
255 : : {
256 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_DATE);
257 : 0 : rtl::OUStringBuffer sBuffer;
258 [ # # ]: 0 : rExport.GetMM100UnitConverter().convertDateTime(sBuffer, fTempValue);
259 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_DATE_VALUE, sBuffer.makeStringAndClear());
260 : 0 : bSetAttributes = true;
261 : : }
262 : : }
263 : 0 : break;
264 : : case NUMBERFORMAT_TIME:
265 : : {
266 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_TIME);
267 : 0 : rtl::OUStringBuffer sBuffer;
268 [ # # ]: 0 : ::sax::Converter::convertDuration(sBuffer, fTempValue);
269 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_TIME_VALUE, sBuffer.makeStringAndClear());
270 : 0 : bSetAttributes = true;
271 : : }
272 : 0 : break;
273 : : }
274 : : }
275 : : }
276 [ # # ]: 0 : if (!bSetAttributes)
277 : : {
278 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_FLOAT);
279 : 0 : rtl::OUStringBuffer sBuffer;
280 [ # # ]: 0 : ::sax::Converter::convertDouble(sBuffer, fValue);
281 [ # # ]: 0 : rtl::OUString sNumValue(sBuffer.makeStringAndClear());
282 [ # # ]: 0 : if (!sNumValue.isEmpty())
283 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE, sNumValue);
284 : : }
285 : 0 : }
286 : :
287 : :
288 : 0 : void ScChangeTrackingExportHelper::WriteValueCell(const ScBaseCell* pCell, const String& sValue)
289 : : {
290 : 0 : const ScValueCell* pValueCell = static_cast<const ScValueCell*>(pCell);
291 [ # # ]: 0 : if (pValueCell)
292 : : {
293 [ # # ]: 0 : SetValueAttributes(pValueCell->GetValue(), sValue);
294 [ # # ][ # # ]: 0 : SvXMLElementExport aElemC(rExport, XML_NAMESPACE_TABLE, XML_CHANGE_TRACK_TABLE_CELL, true, true);
295 : : }
296 : 0 : }
297 : :
298 : 0 : void ScChangeTrackingExportHelper::WriteStringCell(const ScBaseCell* pCell)
299 : : {
300 : 0 : const ScStringCell* pStringCell = static_cast<const ScStringCell*>(pCell);
301 [ # # ]: 0 : if (pStringCell)
302 : : {
303 : 0 : rtl::OUString sOUString = pStringCell->GetString();
304 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_STRING);
305 [ # # ]: 0 : SvXMLElementExport aElemC(rExport, XML_NAMESPACE_TABLE, XML_CHANGE_TRACK_TABLE_CELL, true, true);
306 [ # # ]: 0 : if (!sOUString.isEmpty())
307 : : {
308 [ # # ]: 0 : SvXMLElementExport aElemP(rExport, XML_NAMESPACE_TEXT, XML_P, true, false);
309 : 0 : bool bPrevCharWasSpace(true);
310 [ # # ][ # # ]: 0 : rExport.GetTextParagraphExport()->exportText(sOUString, bPrevCharWasSpace);
[ # # ][ # # ]
[ # # ]
311 [ # # ]: 0 : }
312 : : }
313 : 0 : }
314 : :
315 : 0 : void ScChangeTrackingExportHelper::WriteEditCell(const ScBaseCell* pCell)
316 : : {
317 : 0 : const ScEditCell* pEditCell = static_cast<const ScEditCell*>(pCell);
318 [ # # ]: 0 : if (pEditCell)
319 : : {
320 [ # # ][ # # ]: 0 : String sString = pEditCell->GetString();
321 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_STRING);
322 [ # # ]: 0 : SvXMLElementExport aElemC(rExport, XML_NAMESPACE_TABLE, XML_CHANGE_TRACK_TABLE_CELL, true, true);
323 [ # # ]: 0 : if (sString.Len())
324 : : {
325 [ # # ]: 0 : if (!pEditTextObj)
326 : : {
327 [ # # ]: 0 : pEditTextObj = new ScEditEngineTextObj();
328 [ # # ][ # # ]: 0 : xText.set(pEditTextObj);
329 : : }
330 [ # # ]: 0 : pEditTextObj->SetText(*(pEditCell->GetData()));
331 [ # # ]: 0 : if (xText.is())
332 [ # # ][ # # ]: 0 : rExport.GetTextParagraphExport()->exportText(xText, false, false);
[ # # ][ # # ]
333 [ # # ][ # # ]: 0 : }
334 : : }
335 : 0 : }
336 : :
337 : 0 : void ScChangeTrackingExportHelper::WriteFormulaCell(const ScBaseCell* pCell, const String& sValue)
338 : : {
339 : 0 : ScBaseCell* pBaseCell = const_cast<ScBaseCell*>(pCell);
340 [ # # ]: 0 : ScFormulaCell* pFormulaCell = static_cast<ScFormulaCell*>(pBaseCell);
341 [ # # ]: 0 : if (pFormulaCell)
342 : : {
343 : 0 : rtl::OUString sAddress;
344 : 0 : const ScDocument* pDoc = rExport.GetDocument();
345 [ # # ]: 0 : ScRangeStringConverter::GetStringFromAddress(sAddress, pFormulaCell->aPos, pDoc, ::formula::FormulaGrammar::CONV_OOO);
346 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_CELL_ADDRESS, sAddress);
347 : 0 : const formula::FormulaGrammar::Grammar eGrammar = pDoc->GetStorageGrammar();
348 [ # # ]: 0 : sal_uInt16 nNamespacePrefix = (eGrammar == formula::FormulaGrammar::GRAM_ODFF ? XML_NAMESPACE_OF : XML_NAMESPACE_OOOC);
349 : 0 : rtl::OUString sFormula;
350 [ # # ]: 0 : pFormulaCell->GetFormula(sFormula, eGrammar);
351 : 0 : rtl::OUString sOUFormula(sFormula);
352 : 0 : sal_uInt8 nMatrixFlag(pFormulaCell->GetMatrixFlag());
353 [ # # ]: 0 : if (nMatrixFlag)
354 : : {
355 [ # # ]: 0 : if (nMatrixFlag == MM_FORMULA)
356 : : {
357 : : SCCOL nColumns;
358 : : SCROW nRows;
359 [ # # ]: 0 : pFormulaCell->GetMatColsRows(nColumns, nRows);
360 : 0 : rtl::OUStringBuffer sColumns;
361 : 0 : rtl::OUStringBuffer sRows;
362 [ # # ]: 0 : ::sax::Converter::convertNumber(sColumns, static_cast<sal_Int32>(nColumns));
363 [ # # ]: 0 : ::sax::Converter::convertNumber(sRows, static_cast<sal_Int32>(nRows));
364 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_MATRIX_COLUMNS_SPANNED, sColumns.makeStringAndClear());
365 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_MATRIX_ROWS_SPANNED, sRows.makeStringAndClear());
366 : : }
367 : : else
368 : : {
369 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_MATRIX_COVERED, XML_TRUE);
370 : : }
371 : 0 : rtl::OUString sMatrixFormula = sOUFormula.copy(1, sOUFormula.getLength() - 2);
372 [ # # ]: 0 : rtl::OUString sQValue = rExport.GetNamespaceMap().GetQNameByKey( nNamespacePrefix, sMatrixFormula, false );
373 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_FORMULA, sQValue);
374 : : }
375 : : else
376 : : {
377 [ # # ]: 0 : rtl::OUString sQValue = rExport.GetNamespaceMap().GetQNameByKey( nNamespacePrefix, sFormula, false );
378 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_FORMULA, sQValue);
379 : : }
380 [ # # ][ # # ]: 0 : if (pFormulaCell->IsValue())
381 : : {
382 [ # # ][ # # ]: 0 : SetValueAttributes(pFormulaCell->GetValue(), sValue);
383 [ # # ][ # # ]: 0 : SvXMLElementExport aElemC(rExport, XML_NAMESPACE_TABLE, XML_CHANGE_TRACK_TABLE_CELL, true, true);
384 : : }
385 : : else
386 : : {
387 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_STRING);
388 [ # # ][ # # ]: 0 : String sCellValue = pFormulaCell->GetString();
389 [ # # ]: 0 : rtl::OUString sOUValue(sCellValue);
390 [ # # ]: 0 : SvXMLElementExport aElemC(rExport, XML_NAMESPACE_TABLE, XML_CHANGE_TRACK_TABLE_CELL, true, true);
391 [ # # ]: 0 : if (!sOUValue.isEmpty())
392 : : {
393 [ # # ]: 0 : SvXMLElementExport aElemP(rExport, XML_NAMESPACE_TEXT, XML_P, true, false);
394 : 0 : bool bPrevCharWasSpace(true);
395 [ # # ][ # # ]: 0 : rExport.GetTextParagraphExport()->exportText(sOUValue, bPrevCharWasSpace);
[ # # ][ # # ]
[ # # ]
396 [ # # ][ # # ]: 0 : }
397 : 0 : }
398 : : }
399 : 0 : }
400 : :
401 : 0 : void ScChangeTrackingExportHelper::WriteCell(const ScBaseCell* pCell, const String& sValue)
402 : : {
403 [ # # ]: 0 : if (pCell)
404 : : {
405 [ # # # # : 0 : switch (pCell->GetCellType())
# # ]
406 : : {
407 : : case CELLTYPE_NONE:
408 : 0 : WriteEmptyCell();
409 : 0 : break;
410 : : case CELLTYPE_VALUE:
411 : 0 : WriteValueCell(pCell, sValue);
412 : 0 : break;
413 : : case CELLTYPE_STRING:
414 : 0 : WriteStringCell(pCell);
415 : 0 : break;
416 : : case CELLTYPE_EDIT:
417 : 0 : WriteEditCell(pCell);
418 : 0 : break;
419 : : case CELLTYPE_FORMULA:
420 : 0 : WriteFormulaCell(pCell, sValue);
421 : 0 : break;
422 : : default:
423 : : {
424 : : // added to avoid warnings
425 : : }
426 : : }
427 : : }
428 : : else
429 : 0 : WriteEmptyCell();
430 : 0 : }
431 : :
432 : 0 : void ScChangeTrackingExportHelper::WriteContentChange(ScChangeAction* pAction)
433 : : {
434 [ # # ]: 0 : SvXMLElementExport aElemChange(rExport, XML_NAMESPACE_TABLE, XML_CELL_CONTENT_CHANGE, true, true);
435 : 0 : const ScChangeAction* pConstAction = pAction;
436 [ # # ]: 0 : WriteBigRange(pConstAction->GetBigRange(), XML_CELL_ADDRESS);
437 [ # # ]: 0 : WriteChangeInfo(pAction);
438 [ # # ]: 0 : WriteDependings(pAction);
439 : : {
440 : 0 : ScChangeActionContent* pPrevAction = static_cast<ScChangeActionContent*>(pAction)->GetPrevContent();
441 [ # # ]: 0 : if (pPrevAction)
442 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_ID, GetChangeID(pPrevAction->GetActionNumber()));
443 [ # # ]: 0 : SvXMLElementExport aElemPrev(rExport, XML_NAMESPACE_TABLE, XML_PREVIOUS, true, true);
444 : 0 : rtl::OUString sValue;
445 [ # # ]: 0 : static_cast<ScChangeActionContent*>(pAction)->GetOldString(sValue);
446 [ # # ][ # # ]: 0 : WriteCell(static_cast<ScChangeActionContent*>(pAction)->GetOldCell(), sValue);
[ # # ][ # # ]
447 [ # # ]: 0 : }
448 : 0 : }
449 : :
450 : 0 : void ScChangeTrackingExportHelper::AddInsertionAttributes(const ScChangeAction* pConstAction)
451 : : {
452 : 0 : sal_Int32 nPosition(0);
453 : 0 : sal_Int32 nCount(0);
454 : 0 : sal_Int32 nStartPosition(0);
455 : 0 : sal_Int32 nEndPosition(0);
456 : : sal_Int32 nStartColumn;
457 : : sal_Int32 nEndColumn;
458 : : sal_Int32 nStartRow;
459 : : sal_Int32 nEndRow;
460 : : sal_Int32 nStartSheet;
461 : : sal_Int32 nEndSheet;
462 : 0 : const ScBigRange& rBigRange = pConstAction->GetBigRange();
463 : : rBigRange.GetVars(nStartColumn, nStartRow, nStartSheet,
464 : 0 : nEndColumn, nEndRow, nEndSheet);
465 [ # # # # ]: 0 : switch (pConstAction->GetType())
466 : : {
467 : : case SC_CAT_INSERT_COLS :
468 : : {
469 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_TYPE, XML_COLUMN);
470 : 0 : nStartPosition = nStartColumn;
471 : 0 : nEndPosition = nEndColumn;
472 : : }
473 : 0 : break;
474 : : case SC_CAT_INSERT_ROWS :
475 : : {
476 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_TYPE, XML_ROW);
477 : 0 : nStartPosition = nStartRow;
478 : 0 : nEndPosition = nEndRow;
479 : : }
480 : 0 : break;
481 : : case SC_CAT_INSERT_TABS :
482 : : {
483 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_TYPE, XML_TABLE);
484 : 0 : nStartPosition = nStartSheet;
485 : 0 : nEndPosition = nEndSheet;
486 : : }
487 : 0 : break;
488 : : default :
489 : : {
490 : : OSL_FAIL("wrong insertion type");
491 : : }
492 : 0 : break;
493 : : }
494 : 0 : nPosition = nStartPosition;
495 : 0 : nCount = nEndPosition - nStartPosition + 1;
496 : 0 : rtl::OUStringBuffer sBuffer;
497 [ # # ]: 0 : ::sax::Converter::convertNumber(sBuffer, nPosition);
498 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_POSITION, sBuffer.makeStringAndClear());
499 : : OSL_ENSURE(nCount > 0, "wrong insertion count");
500 [ # # ]: 0 : if (nCount > 1)
501 : : {
502 [ # # ]: 0 : ::sax::Converter::convertNumber(sBuffer, nCount);
503 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_COUNT, sBuffer.makeStringAndClear());
504 : : }
505 [ # # ]: 0 : if (pConstAction->GetType() != SC_CAT_INSERT_TABS)
506 : : {
507 [ # # ]: 0 : ::sax::Converter::convertNumber(sBuffer, nStartSheet);
508 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_TABLE, sBuffer.makeStringAndClear());
509 : 0 : }
510 : 0 : }
511 : :
512 : 0 : void ScChangeTrackingExportHelper::WriteInsertion(ScChangeAction* pAction)
513 : : {
514 [ # # ]: 0 : AddInsertionAttributes(pAction);
515 [ # # ]: 0 : SvXMLElementExport aElemChange(rExport, XML_NAMESPACE_TABLE, XML_INSERTION, true, true);
516 [ # # ]: 0 : WriteChangeInfo(pAction);
517 [ # # ][ # # ]: 0 : WriteDependings(pAction);
518 : 0 : }
519 : :
520 : 0 : void ScChangeTrackingExportHelper::AddDeletionAttributes(const ScChangeActionDel* pDelAction, const ScChangeActionDel* /* pLastAction */)
521 : : {
522 : 0 : sal_Int32 nPosition(0);
523 : 0 : const ScBigRange& rBigRange = pDelAction->GetBigRange();
524 : 0 : sal_Int32 nStartColumn(0);
525 : 0 : sal_Int32 nEndColumn(0);
526 : 0 : sal_Int32 nStartRow(0);
527 : 0 : sal_Int32 nEndRow(0);
528 : 0 : sal_Int32 nStartSheet(0);
529 : 0 : sal_Int32 nEndSheet(0);
530 : : rBigRange.GetVars(nStartColumn, nStartRow, nStartSheet,
531 : 0 : nEndColumn, nEndRow, nEndSheet);
532 [ # # # # ]: 0 : switch (pDelAction->GetType())
533 : : {
534 : : case SC_CAT_DELETE_COLS :
535 : : {
536 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_TYPE, XML_COLUMN);
537 : 0 : nPosition = nStartColumn;
538 : : }
539 : 0 : break;
540 : : case SC_CAT_DELETE_ROWS :
541 : : {
542 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_TYPE, XML_ROW);
543 : 0 : nPosition = nStartRow;
544 : : }
545 : 0 : break;
546 : : case SC_CAT_DELETE_TABS :
547 : : {
548 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_TYPE, XML_TABLE);
549 : 0 : nPosition = nStartSheet;
550 : : }
551 : 0 : break;
552 : : default :
553 : : {
554 : : OSL_FAIL("wrong deletion type");
555 : : }
556 : 0 : break;
557 : : }
558 : 0 : rtl::OUStringBuffer sBuffer;
559 [ # # ]: 0 : ::sax::Converter::convertNumber(sBuffer, nPosition);
560 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_POSITION, sBuffer.makeStringAndClear());
561 [ # # ]: 0 : if (pDelAction->GetType() != SC_CAT_DELETE_TABS)
562 : : {
563 [ # # ]: 0 : ::sax::Converter::convertNumber(sBuffer, nStartSheet);
564 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_TABLE, sBuffer.makeStringAndClear());
565 [ # # ][ # # ]: 0 : if (pDelAction->IsMultiDelete() && !pDelAction->GetDx() && !pDelAction->GetDy())
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
566 : : {
567 : 0 : const ScChangeAction* p = pDelAction->GetNext();
568 : 0 : bool bAll(false);
569 : 0 : sal_Int32 nSlavesCount (1);
570 [ # # ][ # # ]: 0 : while (!bAll && p)
[ # # ]
571 : : {
572 [ # # ][ # # ]: 0 : if ( !p || p->GetType() != pDelAction->GetType() )
[ # # ]
573 : 0 : bAll = true;
574 : : else
575 : : {
576 : 0 : const ScChangeActionDel* pDel = (const ScChangeActionDel*) p;
577 [ # # ][ # # ]: 0 : if ( (pDel->GetDx() > pDelAction->GetDx() || pDel->GetDy() > pDelAction->GetDy()) &&
[ # # ][ # # ]
[ # # ]
[ # # # # ]
[ # # ]
578 : 0 : pDel->GetBigRange() == pDelAction->GetBigRange() )
579 : : {
580 : 0 : ++nSlavesCount;
581 : 0 : p = p->GetNext();
582 : : }
583 : : else
584 : 0 : bAll = true;
585 : : }
586 : : }
587 : :
588 [ # # ]: 0 : ::sax::Converter::convertNumber(sBuffer, nSlavesCount);
589 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_MULTI_DELETION_SPANNED, sBuffer.makeStringAndClear());
590 : : }
591 : 0 : }
592 : 0 : }
593 : :
594 : 0 : void ScChangeTrackingExportHelper::WriteCutOffs(const ScChangeActionDel* pAction)
595 : : {
596 : 0 : const ScChangeActionIns* pCutOffIns = pAction->GetCutOffInsert();
597 : 0 : const ScChangeActionDelMoveEntry* pLinkMove = pAction->GetFirstMoveEntry();
598 [ # # ][ # # ]: 0 : if (pCutOffIns || pLinkMove)
599 : : {
600 [ # # ]: 0 : SvXMLElementExport aCutOffsElem (rExport, XML_NAMESPACE_TABLE, XML_CUT_OFFS, true, true);
601 : 0 : rtl::OUStringBuffer sBuffer;
602 [ # # ]: 0 : if (pCutOffIns)
603 : : {
604 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_ID, GetChangeID(pCutOffIns->GetActionNumber()));
605 : : ::sax::Converter::convertNumber(sBuffer,
606 [ # # ]: 0 : static_cast<sal_Int32>(pAction->GetCutOffCount()));
607 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_POSITION, sBuffer.makeStringAndClear());
608 [ # # ][ # # ]: 0 : SvXMLElementExport aInsertCutOffElem (rExport, XML_NAMESPACE_TABLE, XML_INSERTION_CUT_OFF, true, true);
609 : : }
610 [ # # ]: 0 : while (pLinkMove)
611 : : {
612 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_ID, GetChangeID(pLinkMove->GetAction()->GetActionNumber()));
613 [ # # ]: 0 : if (pLinkMove->GetCutOffFrom() == pLinkMove->GetCutOffTo())
614 : : {
615 : : ::sax::Converter::convertNumber(sBuffer,
616 [ # # ]: 0 : static_cast<sal_Int32>(pLinkMove->GetCutOffFrom()));
617 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_POSITION, sBuffer.makeStringAndClear());
618 : : }
619 : : else
620 : : {
621 : : ::sax::Converter::convertNumber(sBuffer,
622 [ # # ]: 0 : static_cast<sal_Int32>(pLinkMove->GetCutOffFrom()));
623 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_START_POSITION, sBuffer.makeStringAndClear());
624 : : ::sax::Converter::convertNumber(sBuffer,
625 [ # # ]: 0 : static_cast<sal_Int32>(pLinkMove->GetCutOffTo()));
626 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_END_POSITION, sBuffer.makeStringAndClear());
627 : : }
628 [ # # ]: 0 : SvXMLElementExport aMoveCutOffElem (rExport, XML_NAMESPACE_TABLE, XML_MOVEMENT_CUT_OFF, true, true);
629 : 0 : pLinkMove = pLinkMove->GetNext();
630 [ # # ][ # # ]: 0 : }
631 : : }
632 : 0 : }
633 : :
634 : 0 : void ScChangeTrackingExportHelper::WriteDeletion(ScChangeAction* pAction)
635 : : {
636 : 0 : ScChangeActionDel* pDelAction = static_cast<ScChangeActionDel*> (pAction);
637 [ # # ]: 0 : AddDeletionAttributes(pDelAction, pDelAction);
638 [ # # ]: 0 : SvXMLElementExport aElemChange(rExport, XML_NAMESPACE_TABLE, XML_DELETION, true, true);
639 [ # # ]: 0 : WriteChangeInfo(pDelAction);
640 [ # # ]: 0 : WriteDependings(pDelAction);
641 [ # # ][ # # ]: 0 : WriteCutOffs(pDelAction);
642 : 0 : }
643 : :
644 : 0 : void ScChangeTrackingExportHelper::WriteMovement(ScChangeAction* pAction)
645 : : {
646 : 0 : const ScChangeActionMove* pMoveAction = static_cast<ScChangeActionMove*> (pAction);
647 [ # # ]: 0 : SvXMLElementExport aElemChange(rExport, XML_NAMESPACE_TABLE, XML_MOVEMENT, true, true);
648 [ # # ]: 0 : WriteBigRange(pMoveAction->GetFromRange(), XML_SOURCE_RANGE_ADDRESS);
649 [ # # ]: 0 : WriteBigRange(pMoveAction->GetBigRange(), XML_TARGET_RANGE_ADDRESS);
650 [ # # ]: 0 : WriteChangeInfo(pAction);
651 [ # # ][ # # ]: 0 : WriteDependings(pAction);
652 : 0 : }
653 : :
654 : 0 : void ScChangeTrackingExportHelper::WriteRejection(ScChangeAction* pAction)
655 : : {
656 [ # # ]: 0 : SvXMLElementExport aElemChange(rExport, XML_NAMESPACE_TABLE, XML_REJECTION, true, true);
657 [ # # ]: 0 : WriteChangeInfo(pAction);
658 [ # # ][ # # ]: 0 : WriteDependings(pAction);
659 : 0 : }
660 : :
661 : 0 : void ScChangeTrackingExportHelper::CollectCellAutoStyles(const ScBaseCell* pBaseCell)
662 : : {
663 [ # # ][ # # ]: 0 : if (pBaseCell && (pBaseCell->GetCellType() == CELLTYPE_EDIT))
[ # # ]
664 : : {
665 : 0 : const ScEditCell* pEditCell = static_cast<const ScEditCell*>(pBaseCell);
666 [ # # ]: 0 : if (pEditCell)
667 : : {
668 [ # # ]: 0 : if (!pEditTextObj)
669 : : {
670 [ # # ]: 0 : pEditTextObj = new ScEditEngineTextObj();
671 [ # # ]: 0 : xText.set(pEditTextObj);
672 : : }
673 : 0 : pEditTextObj->SetText(*(pEditCell->GetData()));
674 [ # # ]: 0 : if (xText.is())
675 [ # # ][ # # ]: 0 : rExport.GetTextParagraphExport()->collectTextAutoStyles(xText, false, false);
676 : : }
677 : : }
678 : 0 : }
679 : :
680 : 0 : void ScChangeTrackingExportHelper::CollectActionAutoStyles(ScChangeAction* pAction)
681 : : {
682 [ # # ]: 0 : if (pAction->GetType() == SC_CAT_CONTENT)
683 : : {
684 [ # # ]: 0 : if (pChangeTrack->IsGenerated(pAction->GetActionNumber()))
685 : 0 : CollectCellAutoStyles(static_cast<ScChangeActionContent*>(pAction)->GetNewCell());
686 : : else
687 : : {
688 : 0 : CollectCellAutoStyles(static_cast<ScChangeActionContent*>(pAction)->GetOldCell());
689 [ # # ][ # # ]: 0 : if (static_cast<ScChangeActionContent*>(pAction)->IsTopContent() && pAction->IsDeletedIn())
[ # # ]
690 : 0 : CollectCellAutoStyles(static_cast<ScChangeActionContent*>(pAction)->GetNewCell());
691 : : }
692 : : }
693 : 0 : }
694 : :
695 : 0 : void ScChangeTrackingExportHelper::WorkWithChangeAction(ScChangeAction* pAction)
696 : : {
697 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_ID, GetChangeID(pAction->GetActionNumber()));
698 : 0 : GetAcceptanceState(pAction);
699 [ # # ]: 0 : if (pAction->IsRejecting())
700 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_REJECTING_CHANGE_ID, GetChangeID(pAction->GetRejectAction()));
701 [ # # ]: 0 : if (pAction->GetType() == SC_CAT_CONTENT)
702 : 0 : WriteContentChange(pAction);
703 [ # # ]: 0 : else if (pAction->IsInsertType())
704 : 0 : WriteInsertion(pAction);
705 [ # # ]: 0 : else if (pAction->IsDeleteType())
706 : 0 : WriteDeletion(pAction);
707 [ # # ]: 0 : else if (pAction->GetType() == SC_CAT_MOVE)
708 : 0 : WriteMovement(pAction);
709 [ # # ]: 0 : else if (pAction->GetType() == SC_CAT_REJECT)
710 : 0 : WriteRejection(pAction);
711 : : else
712 : : {
713 : : OSL_FAIL("not a writeable type");
714 : : }
715 : 0 : rExport.CheckAttrList();
716 : 0 : }
717 : :
718 : 4 : void ScChangeTrackingExportHelper::CollectAutoStyles()
719 : : {
720 [ - + ]: 4 : if (pChangeTrack)
721 : : {
722 : 0 : sal_uInt32 nCount (pChangeTrack->GetActionMax());
723 [ # # ]: 0 : if (nCount)
724 : : {
725 : 0 : ScChangeAction* pAction = pChangeTrack->GetFirst();
726 : 0 : CollectActionAutoStyles(pAction);
727 : 0 : ScChangeAction* pLastAction = pChangeTrack->GetLast();
728 [ # # ]: 0 : while (pAction != pLastAction)
729 : : {
730 : 0 : pAction = pAction->GetNext();
731 : 0 : CollectActionAutoStyles(pAction);
732 : : }
733 : 0 : pAction = pChangeTrack->GetFirstGenerated();
734 [ # # ]: 0 : while (pAction)
735 : : {
736 : 0 : CollectActionAutoStyles(pAction);
737 : 0 : pAction = pAction->GetNext();
738 : : }
739 : : }
740 : : }
741 : 4 : }
742 : :
743 : 4 : void ScChangeTrackingExportHelper::CollectAndWriteChanges()
744 : : {
745 [ - + ]: 4 : if (pChangeTrack)
746 : : {
747 [ # # ]: 0 : SvXMLElementExport aCangeListElem(rExport, XML_NAMESPACE_TABLE, XML_TRACKED_CHANGES, true, true);
748 : : {
749 : 0 : ScChangeAction* pAction = pChangeTrack->GetFirst();
750 [ # # ]: 0 : if (pAction)
751 : : {
752 [ # # ]: 0 : WorkWithChangeAction(pAction);
753 : 0 : ScChangeAction* pLastAction = pChangeTrack->GetLast();
754 [ # # ]: 0 : while (pAction != pLastAction)
755 : : {
756 : 0 : pAction = pAction->GetNext();
757 [ # # ]: 0 : WorkWithChangeAction(pAction);
758 : : }
759 : : }
760 [ # # ]: 0 : }
761 : : }
762 : 4 : }
763 : :
764 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|