Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : */
9 :
10 : #include "xmlcondformat.hxx"
11 : #include <xmloff/nmspmap.hxx>
12 :
13 : #include "colorscale.hxx"
14 : #include "conditio.hxx"
15 : #include "document.hxx"
16 : #include <sax/tools/converter.hxx>
17 : #include "rangelst.hxx"
18 : #include "rangeutl.hxx"
19 : #include "docfunc.hxx"
20 : #include "XMLConverter.hxx"
21 : #include "stylehelper.hxx"
22 :
23 30 : ScXMLConditionalFormatsContext::ScXMLConditionalFormatsContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
24 : const OUString& rLName):
25 30 : SvXMLImportContext( rImport, nPrfx, rLName )
26 : {
27 30 : GetScImport().SetNewCondFormatData();
28 30 : GetScImport().GetDocument()->SetCondFormList(new ScConditionalFormatList(), GetScImport().GetTables().GetCurrentSheet());
29 30 : }
30 :
31 132 : SvXMLImportContext* ScXMLConditionalFormatsContext::CreateChildContext( sal_uInt16 nPrefix,
32 : const OUString& rLocalName,
33 : const ::com::sun::star::uno::Reference<
34 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
35 : {
36 132 : const SvXMLTokenMap& rTokenMap = GetScImport().GetCondFormatsTokenMap();
37 132 : sal_uInt16 nToken = rTokenMap.Get(nPrefix, rLocalName);
38 132 : SvXMLImportContext* pContext = NULL;
39 132 : switch (nToken)
40 : {
41 : case XML_TOK_CONDFORMATS_CONDFORMAT:
42 132 : pContext = new ScXMLConditionalFormatContext( GetScImport(), nPrefix, rLocalName, xAttrList );
43 132 : break;
44 : }
45 :
46 132 : return pContext;
47 : }
48 :
49 30 : void ScXMLConditionalFormatsContext::EndElement()
50 : {
51 30 : ScDocument* pDoc = GetScImport().GetDocument();
52 :
53 30 : SCTAB nTab = GetScImport().GetTables().GetCurrentSheet();
54 30 : ScConditionalFormatList* pCondFormatList = pDoc->GetCondFormList(nTab);
55 30 : bool bDeleted = !pCondFormatList->CheckAllEntries();
56 :
57 : SAL_WARN_IF(bDeleted, "sc", "conditional formats have been deleted because they contained empty range info");
58 30 : }
59 :
60 132 : ScXMLConditionalFormatContext::ScXMLConditionalFormatContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
61 : const OUString& rLName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList>& xAttrList):
62 132 : SvXMLImportContext( rImport, nPrfx, rLName )
63 : {
64 132 : OUString sRange;
65 :
66 132 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
67 132 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetCondFormatAttrMap();
68 264 : for( sal_Int16 i=0; i < nAttrCount; ++i )
69 : {
70 132 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
71 264 : OUString aLocalName;
72 132 : sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
73 132 : sAttrName, &aLocalName ));
74 264 : const OUString& sValue(xAttrList->getValueByIndex( i ));
75 :
76 132 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
77 : {
78 : case XML_TOK_CONDFORMAT_TARGET_RANGE:
79 132 : sRange = sValue;
80 132 : break;
81 : default:
82 0 : break;
83 : }
84 132 : }
85 :
86 132 : ScRangeStringConverter::GetRangeListFromString(maRange, sRange, GetScImport().GetDocument(),
87 132 : formula::FormulaGrammar::CONV_ODF);
88 :
89 132 : mpFormat = new ScConditionalFormat(0, GetScImport().GetDocument());
90 132 : mpFormat->AddRange(maRange);
91 132 : }
92 :
93 180 : SvXMLImportContext* ScXMLConditionalFormatContext::CreateChildContext( sal_uInt16 nPrefix,
94 : const OUString& rLocalName,
95 : const ::com::sun::star::uno::Reference<
96 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
97 : {
98 180 : const SvXMLTokenMap& rTokenMap = GetScImport().GetCondFormatTokenMap();
99 180 : sal_uInt16 nToken = rTokenMap.Get(nPrefix, rLocalName);
100 180 : SvXMLImportContext* pContext = NULL;
101 180 : switch (nToken)
102 : {
103 : case XML_TOK_CONDFORMAT_CONDITION:
104 114 : pContext = new ScXMLCondContext( GetScImport(), nPrefix, rLocalName, xAttrList, mpFormat );
105 114 : break;
106 : case XML_TOK_CONDFORMAT_COLORSCALE:
107 36 : pContext = new ScXMLColorScaleFormatContext( GetScImport(), nPrefix, rLocalName, mpFormat );
108 36 : break;
109 : case XML_TOK_CONDFORMAT_DATABAR:
110 30 : pContext = new ScXMLDataBarFormatContext( GetScImport(), nPrefix, rLocalName, xAttrList, mpFormat );
111 30 : break;
112 : case XML_TOK_CONDFORMAT_ICONSET:
113 0 : pContext = new ScXMLIconSetFormatContext( GetScImport(), nPrefix, rLocalName, xAttrList, mpFormat );
114 0 : break;
115 : case XML_TOK_CONDFORMAT_DATE:
116 0 : pContext = new ScXMLDateContext( GetScImport(), nPrefix, rLocalName, xAttrList, mpFormat );
117 0 : break;
118 : default:
119 0 : break;
120 : }
121 :
122 180 : return pContext;
123 : }
124 :
125 132 : void ScXMLConditionalFormatContext::EndElement()
126 : {
127 132 : ScDocument* pDoc = GetScImport().GetDocument();
128 :
129 132 : SCTAB nTab = GetScImport().GetTables().GetCurrentSheet();
130 132 : sal_uLong nIndex = pDoc->AddCondFormat(mpFormat, nTab);
131 132 : mpFormat->SetKey(nIndex);
132 :
133 132 : pDoc->AddCondFormatData( mpFormat->GetRange(), nTab, nIndex);
134 132 : }
135 :
136 36 : ScXMLColorScaleFormatContext::ScXMLColorScaleFormatContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
137 : const OUString& rLName, ScConditionalFormat* pFormat):
138 : SvXMLImportContext( rImport, nPrfx, rLName ),
139 36 : pColorScaleFormat(NULL)
140 : {
141 36 : pColorScaleFormat = new ScColorScaleFormat(GetScImport().GetDocument());
142 36 : pFormat->AddEntry(pColorScaleFormat);
143 36 : }
144 :
145 90 : SvXMLImportContext* ScXMLColorScaleFormatContext::CreateChildContext( sal_uInt16 nPrefix,
146 : const OUString& rLocalName,
147 : const ::com::sun::star::uno::Reference<
148 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
149 : {
150 90 : const SvXMLTokenMap& rTokenMap = GetScImport().GetColorScaleTokenMap();
151 90 : sal_uInt16 nToken = rTokenMap.Get(nPrefix, rLocalName);
152 90 : SvXMLImportContext* pContext = NULL;
153 90 : switch (nToken)
154 : {
155 : case XML_TOK_COLORSCALE_COLORSCALEENTRY:
156 90 : pContext = new ScXMLColorScaleFormatEntryContext( GetScImport(), nPrefix, rLocalName, xAttrList, pColorScaleFormat );
157 90 : break;
158 : default:
159 0 : break;
160 : }
161 :
162 90 : return pContext;
163 : }
164 :
165 30 : ScXMLDataBarFormatContext::ScXMLDataBarFormatContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
166 : const OUString& rLName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
167 : ScConditionalFormat* pFormat):
168 : SvXMLImportContext( rImport, nPrfx, rLName ),
169 : mpDataBarFormat(NULL),
170 30 : mpFormatData(NULL)
171 : {
172 30 : OUString sPositiveColor;
173 60 : OUString sNegativeColor;
174 60 : OUString sGradient;
175 60 : OUString sAxisPosition;
176 60 : OUString sShowValue;
177 60 : OUString sAxisColor;
178 :
179 30 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
180 30 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataBarAttrMap();
181 126 : for( sal_Int16 i=0; i < nAttrCount; ++i )
182 : {
183 96 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
184 192 : OUString aLocalName;
185 96 : sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
186 96 : sAttrName, &aLocalName ));
187 192 : const OUString& sValue(xAttrList->getValueByIndex( i ));
188 :
189 96 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
190 : {
191 : case XML_TOK_DATABAR_POSITIVE_COLOR:
192 30 : sPositiveColor = sValue;
193 30 : break;
194 : case XML_TOK_DATABAR_GRADIENT:
195 0 : sGradient = sValue;
196 0 : break;
197 : case XML_TOK_DATABAR_NEGATIVE_COLOR:
198 30 : sNegativeColor = sValue;
199 30 : break;
200 : case XML_TOK_DATABAR_AXISPOSITION:
201 6 : sAxisPosition = sValue;
202 6 : break;
203 : case XML_TOK_DATABAR_SHOWVALUE:
204 0 : sShowValue = sValue;
205 0 : break;
206 : case XML_TOK_DATABAR_AXISCOLOR:
207 30 : sAxisColor = sValue;
208 30 : break;
209 : default:
210 0 : break;
211 : }
212 96 : }
213 :
214 30 : mpDataBarFormat = new ScDataBarFormat(rImport.GetDocument());
215 30 : mpFormatData = new ScDataBarFormatData();
216 30 : mpDataBarFormat->SetDataBarData(mpFormatData);
217 30 : if(!sGradient.isEmpty())
218 : {
219 0 : bool bGradient = true;
220 0 : sax::Converter::convertBool( bGradient, sGradient);
221 0 : mpFormatData->mbGradient = bGradient;
222 : }
223 :
224 30 : if(!sPositiveColor.isEmpty())
225 : {
226 30 : sal_Int32 nColor = 0;
227 30 : sax::Converter::convertColor( nColor, sPositiveColor );
228 30 : mpFormatData->maPositiveColor = Color(nColor);
229 : }
230 :
231 30 : if(!sNegativeColor.isEmpty())
232 : {
233 : // we might check here for 0xff0000 and don't write it
234 30 : sal_Int32 nColor = 0;
235 30 : sax::Converter::convertColor( nColor, sNegativeColor );
236 30 : mpFormatData->mpNegativeColor.reset(new Color(nColor));
237 : }
238 : else
239 0 : mpFormatData->mbNeg = false;
240 :
241 30 : if(!sAxisPosition.isEmpty())
242 : {
243 6 : if(sAxisPosition == "middle")
244 6 : mpFormatData->meAxisPosition = databar::MIDDLE;
245 0 : else if (sAxisPosition == "none")
246 0 : mpFormatData->meAxisPosition = databar::NONE;
247 : }
248 :
249 30 : if(!sAxisColor.isEmpty())
250 : {
251 30 : sal_Int32 nColor = 0;
252 30 : sax::Converter::convertColor( nColor, sAxisColor );
253 30 : mpFormatData->maAxisColor = Color(nColor);
254 : }
255 :
256 30 : if(!sShowValue.isEmpty())
257 : {
258 0 : bool bShowValue = true;
259 0 : sax::Converter::convertBool( bShowValue, sShowValue );
260 0 : mpFormatData->mbOnlyBar = !bShowValue;
261 : }
262 :
263 60 : pFormat->AddEntry(mpDataBarFormat);
264 30 : }
265 :
266 60 : SvXMLImportContext* ScXMLDataBarFormatContext::CreateChildContext( sal_uInt16 nPrefix,
267 : const OUString& rLocalName,
268 : const ::com::sun::star::uno::Reference<
269 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
270 : {
271 60 : const SvXMLTokenMap& rTokenMap = GetScImport().GetFormattingTokenMap();
272 60 : sal_uInt16 nToken = rTokenMap.Get(nPrefix, rLocalName);
273 60 : SvXMLImportContext* pContext = NULL;
274 60 : switch (nToken)
275 : {
276 : case XML_TOK_FORMATTING_ENTRY:
277 : case XML_TOK_DATABAR_DATABARENTRY:
278 : {
279 60 : ScColorScaleEntry* pEntry(0);
280 60 : pContext = new ScXMLFormattingEntryContext( GetScImport(), nPrefix, rLocalName, xAttrList, pEntry );
281 60 : if(mpFormatData->mpLowerLimit)
282 : {
283 30 : mpFormatData->mpUpperLimit.reset(pEntry);
284 : }
285 : else
286 : {
287 30 : mpFormatData->mpLowerLimit.reset(pEntry);
288 : }
289 : }
290 60 : break;
291 : default:
292 0 : break;
293 : }
294 :
295 60 : return pContext;
296 : }
297 :
298 0 : ScXMLIconSetFormatContext::ScXMLIconSetFormatContext(ScXMLImport& rImport, sal_uInt16 nPrfx,
299 : const OUString& rLName,
300 : const ::com::sun::star::uno::Reference<
301 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
302 : ScConditionalFormat* pFormat):
303 0 : SvXMLImportContext( rImport, nPrfx, rLName )
304 : {
305 0 : OUString aIconSetType, sShowValue;
306 0 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
307 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetIconSetAttrMap();
308 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
309 : {
310 0 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
311 0 : OUString aLocalName;
312 0 : sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
313 0 : sAttrName, &aLocalName ));
314 0 : const OUString& sValue(xAttrList->getValueByIndex( i ));
315 :
316 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
317 : {
318 : case XML_TOK_ICONSET_TYPE:
319 0 : aIconSetType = sValue;
320 0 : break;
321 : case XML_TOK_ICONSET_SHOWVALUE:
322 0 : sShowValue = sValue;
323 0 : break;
324 : default:
325 0 : break;
326 : }
327 0 : }
328 :
329 0 : ScIconSetMap* pMap = ScIconSetFormat::getIconSetMap();
330 0 : ScIconSetType eType = IconSet_3Arrows;
331 0 : for(; pMap->pName; ++pMap)
332 : {
333 0 : OUString aName = OUString::createFromAscii(pMap->pName);
334 0 : if(aName ==aIconSetType)
335 : {
336 0 : eType = pMap->eType;
337 0 : break;
338 : }
339 0 : }
340 :
341 0 : ScIconSetFormat* pIconSetFormat = new ScIconSetFormat(GetScImport().GetDocument());
342 0 : ScIconSetFormatData* pIconSetFormatData = new ScIconSetFormatData;
343 :
344 0 : if(!sShowValue.isEmpty())
345 : {
346 0 : bool bShowValue = true;
347 0 : sax::Converter::convertBool( bShowValue, sShowValue );
348 0 : pIconSetFormatData->mbShowValue = !bShowValue;
349 : }
350 :
351 0 : pIconSetFormatData->eIconSetType = eType;
352 0 : pIconSetFormat->SetIconSetData(pIconSetFormatData);
353 0 : pFormat->AddEntry(pIconSetFormat);
354 :
355 0 : mpFormatData = pIconSetFormatData;
356 0 : }
357 :
358 0 : SvXMLImportContext* ScXMLIconSetFormatContext::CreateChildContext( sal_uInt16 nPrefix,
359 : const OUString& rLocalName,
360 : const ::com::sun::star::uno::Reference<
361 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
362 : {
363 0 : const SvXMLTokenMap& rTokenMap = GetScImport().GetFormattingTokenMap();
364 0 : sal_uInt16 nToken = rTokenMap.Get(nPrefix, rLocalName);
365 0 : SvXMLImportContext* pContext = NULL;
366 0 : switch (nToken)
367 : {
368 : case XML_TOK_FORMATTING_ENTRY:
369 : {
370 0 : ScColorScaleEntry* pEntry(0);
371 0 : pContext = new ScXMLFormattingEntryContext( GetScImport(), nPrefix, rLocalName, xAttrList, pEntry );
372 0 : mpFormatData->maEntries.push_back(pEntry);
373 : }
374 0 : break;
375 : default:
376 0 : break;
377 : }
378 :
379 0 : return pContext;
380 : }
381 :
382 : namespace {
383 :
384 114 : void GetConditionData(const OUString& rValue, ScConditionMode& eMode, OUString& rExpr1, OUString& rExpr2)
385 : {
386 114 : if(rValue.startsWith("unique"))
387 : {
388 0 : eMode = SC_COND_NOTDUPLICATE;
389 : }
390 114 : else if(rValue.startsWith("duplicate"))
391 : {
392 0 : eMode = SC_COND_DUPLICATE;
393 : }
394 114 : else if(rValue.startsWith("between"))
395 : {
396 6 : const sal_Unicode* pStr = rValue.getStr();
397 6 : const sal_Unicode* pStart = pStr + 8;
398 6 : const sal_Unicode* pEnd = pStr + rValue.getLength();
399 6 : rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ',');
400 6 : rExpr2 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
401 6 : eMode = SC_COND_BETWEEN;
402 : }
403 108 : else if(rValue.startsWith("not-between"))
404 : {
405 12 : const sal_Unicode* pStr = rValue.getStr();
406 12 : const sal_Unicode* pStart = pStr + 12;
407 12 : const sal_Unicode* pEnd = pStr + rValue.getLength();
408 12 : rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ',');
409 12 : rExpr2 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
410 12 : eMode = SC_COND_NOTBETWEEN;
411 : }
412 96 : else if(rValue.startsWith("<="))
413 : {
414 0 : rExpr1 = rValue.copy(2);
415 0 : eMode = SC_COND_EQLESS;
416 : }
417 96 : else if(rValue.startsWith(">="))
418 : {
419 12 : rExpr1 = rValue.copy(2);
420 12 : eMode = SC_COND_EQGREATER;
421 : }
422 84 : else if(rValue.startsWith("!="))
423 : {
424 0 : rExpr1 = rValue.copy(2);
425 0 : eMode = SC_COND_NOTEQUAL;
426 : }
427 84 : else if(rValue.startsWith("<"))
428 : {
429 6 : rExpr1 = rValue.copy(1);
430 6 : eMode = SC_COND_LESS;
431 : }
432 78 : else if(rValue.startsWith("="))
433 : {
434 12 : rExpr1 = rValue.copy(1);
435 12 : eMode = SC_COND_EQUAL;
436 : }
437 66 : else if(rValue.startsWith(">"))
438 : {
439 6 : rExpr1 = rValue.copy(1);
440 6 : eMode = SC_COND_GREATER;
441 : }
442 60 : else if(rValue.startsWith("formula-is"))
443 : {
444 12 : const sal_Unicode* pStr = rValue.getStr();
445 12 : const sal_Unicode* pStart = pStr + 11;
446 12 : const sal_Unicode* pEnd = pStr + rValue.getLength();
447 12 : rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
448 12 : eMode = SC_COND_DIRECT;
449 : }
450 48 : else if(rValue.startsWith("top-elements"))
451 : {
452 6 : const sal_Unicode* pStr = rValue.getStr();
453 6 : const sal_Unicode* pStart = pStr + 13;
454 6 : const sal_Unicode* pEnd = pStr + rValue.getLength();
455 6 : rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
456 6 : eMode = SC_COND_TOP10;
457 : }
458 42 : else if(rValue.startsWith("bottom-elements"))
459 : {
460 6 : const sal_Unicode* pStr = rValue.getStr();
461 6 : const sal_Unicode* pStart = pStr + 16;
462 6 : const sal_Unicode* pEnd = pStr + rValue.getLength();
463 6 : rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
464 6 : eMode = SC_COND_BOTTOM10;
465 : }
466 36 : else if(rValue.startsWith("top-percent"))
467 : {
468 6 : const sal_Unicode* pStr = rValue.getStr();
469 6 : const sal_Unicode* pStart = pStr + 12;
470 6 : const sal_Unicode* pEnd = pStr + rValue.getLength();
471 6 : rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
472 6 : eMode = SC_COND_TOP_PERCENT;
473 : }
474 30 : else if(rValue.startsWith("bottom-percent"))
475 : {
476 6 : const sal_Unicode* pStr = rValue.getStr();
477 6 : const sal_Unicode* pStart = pStr + 15;
478 6 : const sal_Unicode* pEnd = pStr + rValue.getLength();
479 6 : rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
480 6 : eMode = SC_COND_BOTTOM_PERCENT;
481 : }
482 24 : else if(rValue.startsWith("above-average"))
483 : {
484 6 : eMode = SC_COND_ABOVE_AVERAGE;
485 : }
486 18 : else if(rValue.startsWith("below-average"))
487 : {
488 6 : eMode = SC_COND_BELOW_AVERAGE;
489 : }
490 12 : else if(rValue.startsWith("above-equal-average"))
491 : {
492 6 : eMode = SC_COND_ABOVE_EQUAL_AVERAGE;
493 : }
494 6 : else if(rValue.startsWith("below-equal-average"))
495 : {
496 6 : eMode = SC_COND_BELOW_EQUAL_AVERAGE;
497 : }
498 0 : else if(rValue.startsWith("is-error"))
499 : {
500 0 : eMode = SC_COND_ERROR;
501 : }
502 0 : else if(rValue.startsWith("is-no-error"))
503 : {
504 0 : eMode = SC_COND_NOERROR;
505 : }
506 0 : else if(rValue.startsWith("begins-with"))
507 : {
508 0 : eMode = SC_COND_BEGINS_WITH;
509 0 : const sal_Unicode* pStr = rValue.getStr();
510 0 : const sal_Unicode* pStart = pStr + 12;
511 0 : const sal_Unicode* pEnd = pStr + rValue.getLength();
512 0 : rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
513 : }
514 0 : else if(rValue.startsWith("ends-with"))
515 : {
516 0 : eMode = SC_COND_ENDS_WITH;
517 0 : const sal_Unicode* pStr = rValue.getStr();
518 0 : const sal_Unicode* pStart = pStr + 10;
519 0 : const sal_Unicode* pEnd = pStr + rValue.getLength();
520 0 : rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
521 : }
522 0 : else if(rValue.startsWith("contains-text"))
523 : {
524 0 : eMode = SC_COND_CONTAINS_TEXT;
525 0 : const sal_Unicode* pStr = rValue.getStr();
526 0 : const sal_Unicode* pStart = pStr + 14;
527 0 : const sal_Unicode* pEnd = pStr + rValue.getLength();
528 0 : rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
529 : }
530 0 : else if(rValue.startsWith("not-contains-text"))
531 : {
532 0 : eMode = SC_COND_NOT_CONTAINS_TEXT;
533 0 : const sal_Unicode* pStr = rValue.getStr();
534 0 : const sal_Unicode* pStart = pStr + 18;
535 0 : const sal_Unicode* pEnd = pStr + rValue.getLength();
536 0 : rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
537 : }
538 : else
539 0 : eMode = SC_COND_NONE;
540 114 : }
541 :
542 : }
543 :
544 114 : ScXMLCondContext::ScXMLCondContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
545 : const OUString& rLName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
546 : ScConditionalFormat* pFormat ):
547 114 : SvXMLImportContext( rImport, nPrfx, rLName )
548 : {
549 114 : OUString sExpression;
550 228 : OUString sStyle;
551 228 : OUString sAddress;
552 :
553 114 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
554 114 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetConditionAttrMap();
555 456 : for( sal_Int16 i=0; i < nAttrCount; ++i )
556 : {
557 342 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
558 684 : OUString aLocalName;
559 342 : sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
560 342 : sAttrName, &aLocalName ));
561 684 : const OUString& sValue(xAttrList->getValueByIndex( i ));
562 :
563 342 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
564 : {
565 : case XML_TOK_CONDITION_VALUE:
566 114 : sExpression = sValue;
567 114 : break;
568 : case XML_TOK_CONDITION_APPLY_STYLE_NAME:
569 114 : sStyle = ScStyleNameConversion::ProgrammaticToDisplayName(sValue, SFX_STYLE_FAMILY_PARA );
570 114 : break;
571 : case XML_TOK_CONDITION_BASE_CELL_ADDRESS:
572 114 : sAddress = sValue;
573 114 : break;
574 : default:
575 0 : break;
576 : }
577 342 : }
578 :
579 114 : OUString aExpr1;
580 228 : OUString aExpr2;
581 : ScConditionMode eMode;
582 114 : GetConditionData(sExpression, eMode, aExpr1, aExpr2);
583 :
584 114 : ScCondFormatEntry* pFormatEntry = new ScCondFormatEntry(eMode, aExpr1, aExpr2, GetScImport().GetDocument(), ScAddress(), sStyle,
585 114 : OUString(), OUString(), formula::FormulaGrammar::GRAM_ODFF, formula::FormulaGrammar::GRAM_ODFF);
586 114 : pFormatEntry->SetSrcString(sAddress);
587 :
588 342 : pFormat->AddEntry(pFormatEntry);
589 114 : }
590 :
591 : namespace {
592 :
593 150 : void setColorEntryType(const OUString& rType, ScColorScaleEntry* pEntry, const OUString& rFormula,
594 : ScXMLImport& rImport)
595 : {
596 150 : if(rType == "minimum")
597 18 : pEntry->SetType(COLORSCALE_MIN);
598 132 : else if(rType == "maximum")
599 18 : pEntry->SetType(COLORSCALE_MAX);
600 114 : else if(rType == "percentile")
601 24 : pEntry->SetType(COLORSCALE_PERCENTILE);
602 90 : else if(rType == "percent")
603 18 : pEntry->SetType(COLORSCALE_PERCENT);
604 72 : else if(rType == "formula")
605 : {
606 18 : pEntry->SetType(COLORSCALE_FORMULA);
607 : //position does not matter, only table is important
608 18 : pEntry->SetFormula(rFormula, rImport.GetDocument(), ScAddress(0,0,rImport.GetTables().GetCurrentSheet()), formula::FormulaGrammar::GRAM_ODFF);
609 : }
610 54 : else if(rType == "auto-minimum")
611 12 : pEntry->SetType(COLORSCALE_AUTO);
612 42 : else if(rType == "auto-maximum")
613 12 : pEntry->SetType(COLORSCALE_AUTO);
614 150 : }
615 :
616 : }
617 :
618 90 : ScXMLColorScaleFormatEntryContext::ScXMLColorScaleFormatEntryContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
619 : const OUString& rLName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
620 : ScColorScaleFormat* pFormat):
621 : SvXMLImportContext( rImport, nPrfx, rLName ),
622 90 : mpFormatEntry( NULL )
623 : {
624 90 : double nVal = 0;
625 90 : Color aColor;
626 :
627 90 : OUString sType;
628 180 : OUString sVal;
629 180 : OUString sColor;
630 :
631 90 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
632 90 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetColorScaleEntryAttrMap();
633 360 : for( sal_Int16 i=0; i < nAttrCount; ++i )
634 : {
635 270 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
636 540 : OUString aLocalName;
637 270 : sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
638 270 : sAttrName, &aLocalName ));
639 540 : const OUString& sValue(xAttrList->getValueByIndex( i ));
640 :
641 270 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
642 : {
643 : case XML_TOK_COLORSCALEENTRY_TYPE:
644 90 : sType = sValue;
645 90 : break;
646 : case XML_TOK_COLORSCALEENTRY_VALUE:
647 90 : sVal = sValue;
648 90 : break;
649 : case XML_TOK_COLORSCALEENTRY_COLOR:
650 90 : sColor = sValue;
651 90 : break;
652 : default:
653 0 : break;
654 : }
655 270 : }
656 :
657 : sal_Int32 nColor;
658 90 : sax::Converter::convertColor(nColor, sColor);
659 90 : aColor = Color(nColor);
660 :
661 90 : if(!sVal.isEmpty())
662 90 : sax::Converter::convertDouble(nVal, sVal);
663 :
664 90 : mpFormatEntry = new ScColorScaleEntry(nVal, aColor);
665 90 : setColorEntryType(sType, mpFormatEntry, sVal, GetScImport());
666 180 : pFormat->AddEntry(mpFormatEntry);
667 90 : }
668 :
669 60 : ScXMLFormattingEntryContext::ScXMLFormattingEntryContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
670 : const OUString& rLName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
671 : ScColorScaleEntry*& pColorScaleEntry):
672 60 : SvXMLImportContext( rImport, nPrfx, rLName )
673 : {
674 60 : OUString sVal;
675 120 : OUString sType;
676 :
677 60 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
678 60 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataBarEntryAttrMap();
679 180 : for( sal_Int16 i=0; i < nAttrCount; ++i )
680 : {
681 120 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
682 240 : OUString aLocalName;
683 120 : sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
684 120 : sAttrName, &aLocalName ));
685 240 : const OUString& sValue(xAttrList->getValueByIndex( i ));
686 :
687 120 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
688 : {
689 : case XML_TOK_DATABARENTRY_TYPE:
690 60 : sType = sValue;
691 60 : break;
692 : case XML_TOK_DATABARENTRY_VALUE:
693 60 : sVal = sValue;
694 60 : break;
695 : default:
696 0 : break;
697 : }
698 120 : }
699 :
700 60 : double nVal = 0;
701 60 : if(!sVal.isEmpty())
702 60 : sax::Converter::convertDouble(nVal, sVal);
703 :
704 60 : pColorScaleEntry = new ScColorScaleEntry(nVal, Color());
705 120 : setColorEntryType(sType, pColorScaleEntry, sVal, GetScImport());
706 60 : }
707 :
708 : namespace {
709 :
710 0 : condformat::ScCondFormatDateType getDateFromString(const OUString& rString)
711 : {
712 0 : if(rString == "today")
713 0 : return condformat::TODAY;
714 0 : else if(rString == "yesterday")
715 0 : return condformat::YESTERDAY;
716 0 : else if(rString == "tomorrow")
717 0 : return condformat::TOMORROW;
718 0 : else if(rString == "last-7-days")
719 0 : return condformat::LAST7DAYS;
720 0 : else if(rString == "this-week")
721 0 : return condformat::THISWEEK;
722 0 : else if(rString == "last-week")
723 0 : return condformat::LASTWEEK;
724 0 : else if(rString == "next-week")
725 0 : return condformat::NEXTWEEK;
726 0 : else if(rString == "this-month")
727 0 : return condformat::THISMONTH;
728 0 : else if(rString == "last-month")
729 0 : return condformat::LASTMONTH;
730 0 : else if(rString == "next-month")
731 0 : return condformat::NEXTMONTH;
732 0 : else if(rString == "this-year")
733 0 : return condformat::THISYEAR;
734 0 : else if(rString == "last-year")
735 0 : return condformat::LASTYEAR;
736 0 : else if(rString == "next-year")
737 0 : return condformat::NEXTYEAR;
738 :
739 : SAL_WARN("sc", "unknown date type: " << rString);
740 0 : return condformat::TODAY;
741 : }
742 :
743 : }
744 :
745 0 : ScXMLDateContext::ScXMLDateContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
746 : const OUString& rLName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
747 : ScConditionalFormat* pFormat ):
748 0 : SvXMLImportContext( rImport, nPrfx, rLName )
749 : {
750 0 : OUString sDateType, sStyle;
751 0 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
752 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetCondDateAttrMap();
753 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
754 : {
755 0 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
756 0 : OUString aLocalName;
757 0 : sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
758 0 : sAttrName, &aLocalName ));
759 0 : const OUString& sValue(xAttrList->getValueByIndex( i ));
760 :
761 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
762 : {
763 : case XML_TOK_COND_DATE_VALUE:
764 0 : sDateType = sValue;
765 0 : break;
766 : case XML_TOK_COND_DATE_STYLE:
767 0 : sStyle = ScStyleNameConversion::ProgrammaticToDisplayName(sValue, SFX_STYLE_FAMILY_PARA );
768 0 : break;
769 : default:
770 0 : break;
771 : }
772 0 : }
773 :
774 0 : ScCondDateFormatEntry* pFormatEntry = new ScCondDateFormatEntry(GetScImport().GetDocument());
775 0 : pFormatEntry->SetStyleName(sStyle);
776 0 : pFormatEntry->SetDateType(getDateFromString(sDateType));
777 0 : pFormat->AddEntry(pFormatEntry);
778 :
779 228 : }
780 :
781 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|