fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / excel / xeextlst.cxx
blobb6c781891ddacd100d09b32e783e744bb12e83bf
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,
105 pArr->Clone());
107 maValue = OUStringToOString(aFormula, RTL_TEXTENCODING_UTF8 );
109 else
110 maValue = OString::number(rEntry.GetValue());
113 namespace {
115 const char* getColorScaleType( ScColorScaleEntryType eType, bool bFirst )
117 switch(eType)
119 case COLORSCALE_MIN:
120 return "min";
121 case COLORSCALE_MAX:
122 return "max";
123 case COLORSCALE_PERCENT:
124 return "percent";
125 case COLORSCALE_FORMULA:
126 return "formula";
127 case COLORSCALE_AUTO:
128 if(bFirst)
129 return "autoMin";
130 else
131 return "autoMax";
132 case COLORSCALE_PERCENTILE:
133 return "percentile";
134 default:
135 break;
137 return "num";
142 void XclExpExtCfvo::SaveXml( XclExpXmlStream& rStrm )
144 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
145 rWorksheet->startElementNS( XML_x14, XML_cfvo,
146 XML_type, getColorScaleType(meType, mbFirst),
147 FSEND );
149 if (meType == COLORSCALE_FORMULA ||
150 meType == COLORSCALE_PERCENT ||
151 meType == COLORSCALE_PERCENTILE ||
152 meType == COLORSCALE_VALUE)
154 rWorksheet->startElementNS(XML_xm, XML_f, FSEND);
155 rWorksheet->writeEscaped(maValue.getStr());
156 rWorksheet->endElementNS(XML_xm, XML_f);
159 rWorksheet->endElementNS(XML_x14, XML_cfvo);
162 XclExpExtDataBar::XclExpExtDataBar( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, const ScAddress& rPos ):
163 XclExpRoot(rRoot)
165 const ScDataBarFormatData& rFormatData = *rFormat.GetDataBarData();
166 mpLowerLimit.reset( new XclExpExtCfvo( *this, *rFormatData.mpLowerLimit.get(), rPos, true ) );
167 mpUpperLimit.reset( new XclExpExtCfvo( *this, *rFormatData.mpUpperLimit.get(), rPos, false ) );
168 if(rFormatData.mpNegativeColor.get())
169 mpNegativeColor.reset( new XclExpExtNegativeColor( *rFormatData.mpNegativeColor.get() ) );
170 else
171 mpNegativeColor.reset( new XclExpExtNegativeColor( rFormatData.maPositiveColor ) );
172 mpAxisColor.reset( new XclExpExtAxisColor( rFormatData.maAxisColor ) );
174 meAxisPosition = rFormatData.meAxisPosition;
175 mbGradient = rFormatData.mbGradient;
176 mnMinLength = rFormatData.mnMinLength;
177 mnMaxLength = rFormatData.mnMaxLength;
180 namespace {
182 const char* getAxisPosition(databar::ScAxisPosition eAxisPosition)
184 switch(eAxisPosition)
186 case databar::NONE:
187 return "none";
188 case databar::AUTOMATIC:
189 return "automatic";
190 case databar::MIDDLE:
191 return "middle";
193 return "";
198 void XclExpExtDataBar::SaveXml( XclExpXmlStream& rStrm )
200 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
201 rWorksheet->startElementNS( XML_x14, XML_dataBar,
202 XML_minLength, OString::number(mnMinLength).getStr(),
203 XML_maxLength, OString::number(mnMaxLength).getStr(),
204 XML_axisPosition, getAxisPosition(meAxisPosition),
205 XML_gradient, XclXmlUtils::ToPsz(mbGradient),
206 FSEND );
208 mpLowerLimit->SaveXml( rStrm );
209 mpUpperLimit->SaveXml( rStrm );
210 mpNegativeColor->SaveXml( rStrm );
211 mpAxisColor->SaveXml( rStrm );
213 rWorksheet->endElementNS( XML_x14, XML_dataBar );
216 XclExpExtIconSet::XclExpExtIconSet(const XclExpRoot& rRoot, const ScIconSetFormat& rFormat, const ScAddress& rPos):
217 XclExpRoot(rRoot)
219 const ScIconSetFormatData& rData = *rFormat.GetIconSetData();
220 for (auto itr = rData.maEntries.begin(); itr != rData.maEntries.end(); ++itr)
222 maCfvos.AppendNewRecord(new XclExpExtCfvo(*this, *itr, rPos, false));
224 mbCustom = rData.mbCustom;
225 mbReverse = rData.mbReverse;
226 mbShowValue = rData.mbShowValue;
227 mpIconSetName = getIconSetName(rData.eIconSetType);
229 if (mbCustom)
231 for (auto itr = rData.maCustomVector.begin(); itr != rData.maCustomVector.end(); ++itr)
233 maCustom.AppendNewRecord(new XclExpExtIcon(*this, *itr));
238 void XclExpExtIconSet::SaveXml(XclExpXmlStream& rStrm)
240 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
242 rWorksheet->startElementNS(XML_x14, XML_iconSet,
243 XML_iconSet, mpIconSetName,
244 XML_custom, mbCustom ? XclXmlUtils::ToPsz10(mbCustom) : NULL,
245 XML_reverse, XclXmlUtils::ToPsz10(mbReverse),
246 XML_showValue, XclXmlUtils::ToPsz10(mbShowValue),
247 FSEND);
249 maCfvos.SaveXml(rStrm);
251 if (mbCustom)
253 maCustom.SaveXml(rStrm);
256 rWorksheet->endElementNS(XML_x14, XML_iconSet);
259 XclExpExtCfRule::XclExpExtCfRule( const XclExpRoot& rRoot, const ScFormatEntry& rFormat, const ScAddress& rPos, const OString& rId, sal_Int32 nPriority ):
260 XclExpRoot(rRoot),
261 maId(rId),
262 pType(NULL),
263 mnPriority(nPriority)
265 switch (rFormat.GetType())
267 case condformat::DATABAR:
269 const ScDataBarFormat& rDataBar = static_cast<const ScDataBarFormat&>(rFormat);
270 mxEntry.reset( new XclExpExtDataBar( *this, rDataBar, rPos ) );
271 pType = "dataBar";
273 break;
274 case condformat::ICONSET:
276 const ScIconSetFormat& rIconSet = static_cast<const ScIconSetFormat&>(rFormat);
277 mxEntry.reset(new XclExpExtIconSet(*this, rIconSet, rPos));
278 pType = "iconSet";
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 ? NULL : 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 bNeedsExt = true;
325 break;
326 default:
327 break;
330 if (rIconSet.GetIconSetData()->mbCustom)
331 bNeedsExt = true;
333 if (bNeedsExt)
335 maCfRules.AppendNewRecord(new XclExpExtCfRule(*this, *pEntry, aAddr, itr->aGUID, itr->nPriority));
338 break;
339 case condformat::DATABAR:
340 maCfRules.AppendNewRecord(new XclExpExtCfRule( *this, *pEntry, aAddr, itr->aGUID, itr->nPriority));
341 break;
342 default:
343 break;
348 void XclExpExtConditionalFormatting::SaveXml( XclExpXmlStream& rStrm )
350 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
351 rWorksheet->startElementNS( XML_x14, XML_conditionalFormatting,
352 FSNS( XML_xmlns, XML_xm ), "http://schemas.microsoft.com/office/excel/2006/main",
353 FSEND );
355 maCfRules.SaveXml( rStrm );
356 rWorksheet->startElementNS( XML_xm, XML_sqref, FSEND );
357 rWorksheet->write(XclXmlUtils::ToOString(maRange).getStr());
359 rWorksheet->endElementNS( XML_xm, XML_sqref );
361 rWorksheet->endElementNS( XML_x14, XML_conditionalFormatting );
364 XclExpExtCalcPr::XclExpExtCalcPr( const XclExpRoot& rRoot, formula::FormulaGrammar::AddressConvention eConv ):
365 XclExpExt( rRoot ),
366 meConv( eConv )
368 maURI = OString("{7626C862-2A13-11E5-B345-FEFF819CDC9F}");
370 switch (meConv)
372 case formula::FormulaGrammar::CONV_OOO:
373 maSyntax = OString("CalcA1");
374 break;
375 case formula::FormulaGrammar::CONV_XL_A1:
376 maSyntax = OString("ExcelA1");
377 break;
378 case formula::FormulaGrammar::CONV_XL_R1C1:
379 maSyntax = OString("ExcelR1C1");
380 break;
381 case formula::FormulaGrammar::CONV_A1_XL_A1:
382 maSyntax = OString("CalcA1ExcelA1");
383 break;
384 case formula::FormulaGrammar::CONV_UNSPECIFIED:
385 case formula::FormulaGrammar::CONV_ODF:
386 case formula::FormulaGrammar::CONV_XL_OOX:
387 case formula::FormulaGrammar::CONV_LOTUS_A1:
388 case formula::FormulaGrammar::CONV_LAST:
389 maSyntax = OString("Unspecified");
390 break;
394 void XclExpExtCalcPr::SaveXml( XclExpXmlStream& rStrm )
396 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
397 rWorksheet->startElement( XML_ext,
398 FSNS( XML_xmlns, XML_loext ), "http://schemas.libreoffice.org/",
399 XML_uri, maURI.getStr(),
400 FSEND );
402 rWorksheet->singleElementNS( XML_loext, XML_extCalcPr,
403 XML_stringRefSyntax, maSyntax.getStr(),
404 FSEND );
406 rWorksheet->endElement( XML_ext );
409 XclExpExtCondFormat::XclExpExtCondFormat( const XclExpRoot& rRoot ):
410 XclExpExt( rRoot )
412 maURI = OString("{78C0D931-6437-407d-A8EE-F0AAD7539E65}");
415 void XclExpExtCondFormat::SaveXml( XclExpXmlStream& rStrm )
417 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
418 rWorksheet->startElement( XML_ext,
419 FSNS( XML_xmlns, XML_x14 ), "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",
420 XML_uri, maURI.getStr(),
421 FSEND );
423 rWorksheet->startElementNS( XML_x14, XML_conditionalFormattings,
424 FSEND );
426 maCF.SaveXml( rStrm );
428 rWorksheet->endElementNS( XML_x14, XML_conditionalFormattings );
429 rWorksheet->endElement( XML_ext );
432 void XclExpExtCondFormat::AddRecord( XclExpExtConditionalFormattingRef aEntry )
434 maCF.AppendRecord( aEntry );
437 void XclExtLst::SaveXml( XclExpXmlStream& rStrm )
439 if(maExtEntries.IsEmpty())
440 return;
442 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
443 rWorksheet->startElement( XML_extLst,
444 FSEND );
446 maExtEntries.SaveXml(rStrm);
448 rWorksheet->endElement( XML_extLst );
451 void XclExtLst::AddRecord( XclExpExtRef aEntry )
453 maExtEntries.AppendRecord( aEntry );
456 XclExpExtRef XclExtLst::GetItem( XclExpExtType eType )
458 size_t n = maExtEntries.GetSize();
459 for( size_t i = 0; i < n; ++i )
461 if (maExtEntries.GetRecord( i )->GetType() == eType)
462 return maExtEntries.GetRecord( i );
465 return XclExpExtRef();
468 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */