1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include "xeextlst.hxx"
12 #include "xehelper.hxx"
13 #include "xestyle.hxx"
15 #include "xecontent.hxx"
16 #include "tokenarray.hxx"
18 using namespace ::oox
;
22 const char* getIconSetName( ScIconSetType eType
)
24 ScIconSetMap
* pMap
= ScIconSetFormat::getIconSetMap();
25 for(; pMap
->pName
; ++pMap
)
27 if(pMap
->eType
== eType
)
36 XclExpExt::XclExpExt( const XclExpRoot
& rRoot
):
41 XclExtLst::XclExtLst( const XclExpRoot
& rRoot
):
46 XclExpExtNegativeColor::XclExpExtNegativeColor( const Color
& rColor
):
51 void XclExpExtNegativeColor::SaveXml( XclExpXmlStream
& rStrm
)
53 rStrm
.GetCurrentStream()->singleElementNS( XML_x14
, XML_negativeFillColor
,
54 XML_rgb
, XclXmlUtils::ToOString( maColor
).getStr(),
58 XclExpExtAxisColor::XclExpExtAxisColor( const Color
& rColor
):
63 void XclExpExtAxisColor::SaveXml( XclExpXmlStream
& rStrm
)
65 rStrm
.GetCurrentStream()->singleElementNS( XML_x14
, XML_axisColor
,
66 XML_rgb
, XclXmlUtils::ToOString( maAxisColor
).getStr(),
70 XclExpExtIcon::XclExpExtIcon(const XclExpRoot
& rRoot
, const std::pair
<ScIconSetType
, sal_Int32
>& rCustomEntry
):
72 nIndex(rCustomEntry
.second
)
74 pIconSetName
= getIconSetName(rCustomEntry
.first
);
77 void XclExpExtIcon::SaveXml(XclExpXmlStream
& rStrm
)
79 sax_fastparser::FSHelperPtr
& rWorksheet
= rStrm
.GetCurrentStream();
84 pIconSetName
= "NoIcons";
87 rWorksheet
->singleElementNS(XML_x14
, XML_cfIcon
,
88 XML_iconSet
, pIconSetName
,
89 XML_iconId
, OString::number(nIndex
).getStr(),
93 XclExpExtCfvo::XclExpExtCfvo( const XclExpRoot
& rRoot
, const ScColorScaleEntry
& rEntry
, const ScAddress
& rSrcPos
, bool bFirst
):
95 meType(rEntry
.GetType()),
98 if( rEntry
.GetType() == COLORSCALE_FORMULA
)
100 const ScTokenArray
* pArr
= rEntry
.GetFormula();
104 aFormula
= XclXmlUtils::ToOUString( GetCompileFormulaContext(), rSrcPos
,
107 maValue
= OUStringToOString(aFormula
, RTL_TEXTENCODING_UTF8
);
110 maValue
= OString::number(rEntry
.GetValue());
115 const char* getColorScaleType( ScColorScaleEntryType eType
, bool bFirst
)
123 case COLORSCALE_PERCENT
:
125 case COLORSCALE_FORMULA
:
127 case COLORSCALE_AUTO
:
132 case COLORSCALE_PERCENTILE
:
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
),
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
):
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() ) );
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
;
182 const char* getAxisPosition(databar::ScAxisPosition eAxisPosition
)
184 switch(eAxisPosition
)
188 case databar::AUTOMATIC
:
190 case databar::MIDDLE
:
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
),
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
):
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
);
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
),
249 maCfvos
.SaveXml(rStrm
);
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
):
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
) );
274 case condformat::ICONSET
:
276 const ScIconSetFormat
& rIconSet
= static_cast<const ScIconSetFormat
&>(rFormat
);
277 mxEntry
.reset(new XclExpExtIconSet(*this, rIconSet
, rPos
));
285 void XclExpExtCfRule::SaveXml( XclExpXmlStream
& rStrm
)
290 sax_fastparser::FSHelperPtr
& rWorksheet
= rStrm
.GetCurrentStream();
291 rWorksheet
->startElementNS( XML_x14
, XML_cfRule
,
293 XML_priority
, mnPriority
== -1 ? NULL
: OString::number(mnPriority
).getStr(),
294 XML_id
, maId
.getStr(),
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
):
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
:
330 if (rIconSet
.GetIconSetData()->mbCustom
)
335 maCfRules
.AppendNewRecord(new XclExpExtCfRule(*this, *pEntry
, aAddr
, itr
->aGUID
, itr
->nPriority
));
339 case condformat::DATABAR
:
340 maCfRules
.AppendNewRecord(new XclExpExtCfRule( *this, *pEntry
, aAddr
, itr
->aGUID
, itr
->nPriority
));
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",
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
):
368 maURI
= OString("{7626C862-2A13-11E5-B345-FEFF819CDC9F}");
372 case formula::FormulaGrammar::CONV_OOO
:
373 maSyntax
= OString("CalcA1");
375 case formula::FormulaGrammar::CONV_XL_A1
:
376 maSyntax
= OString("ExcelA1");
378 case formula::FormulaGrammar::CONV_XL_R1C1
:
379 maSyntax
= OString("ExcelR1C1");
381 case formula::FormulaGrammar::CONV_A1_XL_A1
:
382 maSyntax
= OString("CalcA1ExcelA1");
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");
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(),
402 rWorksheet
->singleElementNS( XML_loext
, XML_extCalcPr
,
403 XML_stringRefSyntax
, maSyntax
.getStr(),
406 rWorksheet
->endElement( XML_ext
);
409 XclExpExtCondFormat::XclExpExtCondFormat( const XclExpRoot
& 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(),
423 rWorksheet
->startElementNS( XML_x14
, XML_conditionalFormattings
,
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())
442 sax_fastparser::FSHelperPtr
& rWorksheet
= rStrm
.GetCurrentStream();
443 rWorksheet
->startElement( XML_extLst
,
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: */