Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / filter / excel / xeextlst.cxx
blob921642aa3910c56000b7c62031d9d76014f39cf2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "xeextlst.hxx"
11 #include "xeroot.hxx"
12 #include "xehelper.hxx"
13 #include "xestyle.hxx"
14 #include "xename.hxx"
15 #include "xecontent.hxx"
16 #include "tokenarray.hxx"
18 using namespace ::oox;
20 namespace {
22 const char* getIconSetName( ScIconSetType eType )
24 ScIconSetMap* pMap = ScIconSetFormat::getIconSetMap();
25 for(; pMap->pName; ++pMap)
27 if(pMap->eType == eType)
28 return pMap->pName;
31 return "";
36 XclExpExt::XclExpExt( const XclExpRoot& rRoot ):
37 XclExpRoot(rRoot)
41 XclExtLst::XclExtLst( const XclExpRoot& rRoot ):
42 XclExpRoot(rRoot)
46 XclExpExtNegativeColor::XclExpExtNegativeColor( const Color& rColor ):
47 maColor(rColor)
51 void XclExpExtNegativeColor::SaveXml( XclExpXmlStream& rStrm )
53 rStrm.GetCurrentStream()->singleElementNS( XML_x14, XML_negativeFillColor,
54 XML_rgb, XclXmlUtils::ToOString( maColor ).getStr(),
55 FSEND );
58 XclExpExtAxisColor::XclExpExtAxisColor( const Color& rColor ):
59 maAxisColor(rColor)
63 void XclExpExtAxisColor::SaveXml( XclExpXmlStream& rStrm )
65 rStrm.GetCurrentStream()->singleElementNS( XML_x14, XML_axisColor,
66 XML_rgb, XclXmlUtils::ToOString( maAxisColor ).getStr(),
67 FSEND );
70 XclExpExtIcon::XclExpExtIcon(const XclExpRoot& rRoot, const std::pair<ScIconSetType, sal_Int32>& rCustomEntry):
71 XclExpRoot(rRoot),
72 nIndex(rCustomEntry.second)
74 pIconSetName = getIconSetName(rCustomEntry.first);
77 void XclExpExtIcon::SaveXml(XclExpXmlStream& rStrm)
79 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
81 if (nIndex == -1)
83 nIndex = 0;
84 pIconSetName = "NoIcons";
87 rWorksheet->singleElementNS(XML_x14, XML_cfIcon,
88 XML_iconSet, pIconSetName,
89 XML_iconId, OString::number(nIndex).getStr(),
90 FSEND);
93 XclExpExtCfvo::XclExpExtCfvo( const XclExpRoot& rRoot, const ScColorScaleEntry& rEntry, const ScAddress& rSrcPos, bool bFirst ):
94 XclExpRoot(rRoot),
95 meType(rEntry.GetType()),
96 mbFirst(bFirst)
98 if( rEntry.GetType() == COLORSCALE_FORMULA )
100 const ScTokenArray* pArr = rEntry.GetFormula();
101 OUString aFormula;
102 if(pArr)
104 aFormula = XclXmlUtils::ToOUString( GetCompileFormulaContext(), rSrcPos, pArr);
106 maValue = OUStringToOString(aFormula, RTL_TEXTENCODING_UTF8 );
108 else
109 maValue = OString::number(rEntry.GetValue());
112 namespace {
114 const char* getColorScaleType( ScColorScaleEntryType eType, bool bFirst )
116 switch(eType)
118 case COLORSCALE_MIN:
119 return "min";
120 case COLORSCALE_MAX:
121 return "max";
122 case COLORSCALE_PERCENT:
123 return "percent";
124 case COLORSCALE_FORMULA:
125 return "formula";
126 case COLORSCALE_AUTO:
127 if(bFirst)
128 return "autoMin";
129 else
130 return "autoMax";
131 case COLORSCALE_PERCENTILE:
132 return "percentile";
133 default:
134 break;
136 return "num";
141 void XclExpExtCfvo::SaveXml( XclExpXmlStream& rStrm )
143 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
144 rWorksheet->startElementNS( XML_x14, XML_cfvo,
145 XML_type, getColorScaleType(meType, mbFirst),
146 FSEND );
148 if (meType == COLORSCALE_FORMULA ||
149 meType == COLORSCALE_PERCENT ||
150 meType == COLORSCALE_PERCENTILE ||
151 meType == COLORSCALE_VALUE)
153 rWorksheet->startElementNS(XML_xm, XML_f, FSEND);
154 rWorksheet->writeEscaped(maValue.getStr());
155 rWorksheet->endElementNS(XML_xm, XML_f);
158 rWorksheet->endElementNS(XML_x14, XML_cfvo);
161 XclExpExtDataBar::XclExpExtDataBar( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, const ScAddress& rPos ):
162 XclExpRoot(rRoot)
164 const ScDataBarFormatData& rFormatData = *rFormat.GetDataBarData();
165 mpLowerLimit.reset( new XclExpExtCfvo( *this, *rFormatData.mpLowerLimit.get(), rPos, true ) );
166 mpUpperLimit.reset( new XclExpExtCfvo( *this, *rFormatData.mpUpperLimit.get(), rPos, false ) );
167 if(rFormatData.mpNegativeColor.get())
168 mpNegativeColor.reset( new XclExpExtNegativeColor( *rFormatData.mpNegativeColor.get() ) );
169 else
170 mpNegativeColor.reset( new XclExpExtNegativeColor( rFormatData.maPositiveColor ) );
171 mpAxisColor.reset( new XclExpExtAxisColor( rFormatData.maAxisColor ) );
173 meAxisPosition = rFormatData.meAxisPosition;
174 mbGradient = rFormatData.mbGradient;
175 mnMinLength = rFormatData.mnMinLength;
176 mnMaxLength = rFormatData.mnMaxLength;
179 namespace {
181 const char* getAxisPosition(databar::ScAxisPosition eAxisPosition)
183 switch(eAxisPosition)
185 case databar::NONE:
186 return "none";
187 case databar::AUTOMATIC:
188 return "automatic";
189 case databar::MIDDLE:
190 return "middle";
192 return "";
197 void XclExpExtDataBar::SaveXml( XclExpXmlStream& rStrm )
199 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
200 rWorksheet->startElementNS( XML_x14, XML_dataBar,
201 XML_minLength, OString::number(mnMinLength).getStr(),
202 XML_maxLength, OString::number(mnMaxLength).getStr(),
203 XML_axisPosition, getAxisPosition(meAxisPosition),
204 XML_gradient, XclXmlUtils::ToPsz(mbGradient),
205 FSEND );
207 mpLowerLimit->SaveXml( rStrm );
208 mpUpperLimit->SaveXml( rStrm );
209 mpNegativeColor->SaveXml( rStrm );
210 mpAxisColor->SaveXml( rStrm );
212 rWorksheet->endElementNS( XML_x14, XML_dataBar );
215 XclExpExtIconSet::XclExpExtIconSet(const XclExpRoot& rRoot, const ScIconSetFormat& rFormat, const ScAddress& rPos):
216 XclExpRoot(rRoot)
218 const ScIconSetFormatData& rData = *rFormat.GetIconSetData();
219 for (auto const& itr : rData.m_Entries)
221 maCfvos.AppendNewRecord(new XclExpExtCfvo(*this, *itr, rPos, false));
223 mbCustom = rData.mbCustom;
224 mbReverse = rData.mbReverse;
225 mbShowValue = rData.mbShowValue;
226 mpIconSetName = getIconSetName(rData.eIconSetType);
228 if (mbCustom)
230 for (auto itr = rData.maCustomVector.begin(); itr != rData.maCustomVector.end(); ++itr)
232 maCustom.AppendNewRecord(new XclExpExtIcon(*this, *itr));
237 void XclExpExtIconSet::SaveXml(XclExpXmlStream& rStrm)
239 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
241 rWorksheet->startElementNS(XML_x14, XML_iconSet,
242 XML_iconSet, mpIconSetName,
243 XML_custom, mbCustom ? XclXmlUtils::ToPsz10(mbCustom) : nullptr,
244 XML_reverse, XclXmlUtils::ToPsz10(mbReverse),
245 XML_showValue, XclXmlUtils::ToPsz10(mbShowValue),
246 FSEND);
248 maCfvos.SaveXml(rStrm);
250 if (mbCustom)
252 maCustom.SaveXml(rStrm);
255 rWorksheet->endElementNS(XML_x14, XML_iconSet);
258 XclExpExtCfRule::XclExpExtCfRule( const XclExpRoot& rRoot, const ScFormatEntry& rFormat, const ScAddress& rPos, const OString& rId, sal_Int32 nPriority ):
259 XclExpRoot(rRoot),
260 maId(rId),
261 pType(nullptr),
262 mnPriority(nPriority)
264 switch (rFormat.GetType())
266 case condformat::DATABAR:
268 const ScDataBarFormat& rDataBar = static_cast<const ScDataBarFormat&>(rFormat);
269 mxEntry.reset( new XclExpExtDataBar( *this, rDataBar, rPos ) );
270 pType = "dataBar";
272 break;
273 case condformat::ICONSET:
275 const ScIconSetFormat& rIconSet = static_cast<const ScIconSetFormat&>(rFormat);
276 mxEntry.reset(new XclExpExtIconSet(*this, rIconSet, rPos));
277 pType = "iconSet";
279 break;
280 default:
281 break;
285 void XclExpExtCfRule::SaveXml( XclExpXmlStream& rStrm )
287 if (!mxEntry)
288 return;
290 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
291 rWorksheet->startElementNS( XML_x14, XML_cfRule,
292 XML_type, pType,
293 XML_priority, mnPriority == -1 ? nullptr : OString::number(mnPriority).getStr(),
294 XML_id, maId.getStr(),
295 FSEND );
297 mxEntry->SaveXml( rStrm );
299 rWorksheet->endElementNS( XML_x14, XML_cfRule );
303 XclExpExtConditionalFormatting::XclExpExtConditionalFormatting( const XclExpRoot& rRoot,
304 std::vector<XclExpExtCondFormatData>& rData, const ScRangeList& rRange):
305 XclExpRoot(rRoot),
306 maRange(rRange)
308 ScAddress aAddr = maRange.front()->aStart;
309 for (auto itr = rData.begin(), itrEnd = rData.end(); itr != itrEnd; ++itr)
311 const ScFormatEntry* pEntry = itr->pEntry;
312 switch (pEntry->GetType())
314 case condformat::ICONSET:
316 const ScIconSetFormat& rIconSet = static_cast<const ScIconSetFormat&>(*pEntry);
317 bool bNeedsExt = false;
318 switch (rIconSet.GetIconSetData()->eIconSetType)
320 case IconSet_3Triangles:
321 case IconSet_3Smilies:
322 case IconSet_3ColorSmilies:
323 case IconSet_5Boxes:
324 case IconSet_3Stars:
325 bNeedsExt = true;
326 break;
327 default:
328 break;
331 if (rIconSet.GetIconSetData()->mbCustom)
332 bNeedsExt = true;
334 if (bNeedsExt)
336 maCfRules.AppendNewRecord(new XclExpExtCfRule(*this, *pEntry, aAddr, itr->aGUID, itr->nPriority));
339 break;
340 case condformat::DATABAR:
341 maCfRules.AppendNewRecord(new XclExpExtCfRule( *this, *pEntry, aAddr, itr->aGUID, itr->nPriority));
342 break;
343 default:
344 break;
349 void XclExpExtConditionalFormatting::SaveXml( XclExpXmlStream& rStrm )
351 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
352 rWorksheet->startElementNS( XML_x14, XML_conditionalFormatting,
353 FSNS( XML_xmlns, XML_xm ), "http://schemas.microsoft.com/office/excel/2006/main",
354 FSEND );
356 maCfRules.SaveXml( rStrm );
357 rWorksheet->startElementNS( XML_xm, XML_sqref, FSEND );
358 rWorksheet->write(XclXmlUtils::ToOString(maRange).getStr());
360 rWorksheet->endElementNS( XML_xm, XML_sqref );
362 rWorksheet->endElementNS( XML_x14, XML_conditionalFormatting );
365 XclExpExtCalcPr::XclExpExtCalcPr( const XclExpRoot& rRoot, formula::FormulaGrammar::AddressConvention eConv ):
366 XclExpExt( rRoot ),
367 meConv( eConv )
369 maURI = OString("{7626C862-2A13-11E5-B345-FEFF819CDC9F}");
371 switch (meConv)
373 case formula::FormulaGrammar::CONV_OOO:
374 maSyntax = OString("CalcA1");
375 break;
376 case formula::FormulaGrammar::CONV_XL_A1:
377 maSyntax = OString("ExcelA1");
378 break;
379 case formula::FormulaGrammar::CONV_XL_R1C1:
380 maSyntax = OString("ExcelR1C1");
381 break;
382 case formula::FormulaGrammar::CONV_A1_XL_A1:
383 maSyntax = OString("CalcA1ExcelA1");
384 break;
385 case formula::FormulaGrammar::CONV_UNSPECIFIED:
386 case formula::FormulaGrammar::CONV_ODF:
387 case formula::FormulaGrammar::CONV_XL_OOX:
388 case formula::FormulaGrammar::CONV_LOTUS_A1:
389 case formula::FormulaGrammar::CONV_LAST:
390 maSyntax = OString("Unspecified");
391 break;
395 void XclExpExtCalcPr::SaveXml( XclExpXmlStream& rStrm )
397 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
398 rWorksheet->startElement( XML_ext,
399 FSNS( XML_xmlns, XML_loext ), "http://schemas.libreoffice.org/",
400 XML_uri, maURI.getStr(),
401 FSEND );
403 rWorksheet->singleElementNS( XML_loext, XML_extCalcPr,
404 XML_stringRefSyntax, maSyntax.getStr(),
405 FSEND );
407 rWorksheet->endElement( XML_ext );
410 XclExpExtCondFormat::XclExpExtCondFormat( const XclExpRoot& rRoot ):
411 XclExpExt( rRoot )
413 maURI = OString("{78C0D931-6437-407d-A8EE-F0AAD7539E65}");
416 void XclExpExtCondFormat::SaveXml( XclExpXmlStream& rStrm )
418 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
419 rWorksheet->startElement( XML_ext,
420 FSNS( XML_xmlns, XML_x14 ), "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",
421 XML_uri, maURI.getStr(),
422 FSEND );
424 rWorksheet->startElementNS( XML_x14, XML_conditionalFormattings,
425 FSEND );
427 maCF.SaveXml( rStrm );
429 rWorksheet->endElementNS( XML_x14, XML_conditionalFormattings );
430 rWorksheet->endElement( XML_ext );
433 void XclExpExtCondFormat::AddRecord( const XclExpExtConditionalFormattingRef& aEntry )
435 maCF.AppendRecord( aEntry );
438 void XclExtLst::SaveXml( XclExpXmlStream& rStrm )
440 if(maExtEntries.IsEmpty())
441 return;
443 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
444 rWorksheet->startElement( XML_extLst,
445 FSEND );
447 maExtEntries.SaveXml(rStrm);
449 rWorksheet->endElement( XML_extLst );
452 void XclExtLst::AddRecord( const XclExpExtRef& aEntry )
454 maExtEntries.AppendRecord( aEntry );
457 XclExpExtRef XclExtLst::GetItem( XclExpExtType eType )
459 size_t n = maExtEntries.GetSize();
460 for( size_t i = 0; i < n; ++i )
462 if (maExtEntries.GetRecord( i )->GetType() == eType)
463 return maExtEntries.GetRecord( i );
466 return XclExpExtRef();
469 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */