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
, pArr
);
106 maValue
= OUStringToOString(aFormula
, RTL_TEXTENCODING_UTF8
);
109 maValue
= OString::number(rEntry
.GetValue());
114 const char* getColorScaleType( ScColorScaleEntryType eType
, bool bFirst
)
122 case COLORSCALE_PERCENT
:
124 case COLORSCALE_FORMULA
:
126 case COLORSCALE_AUTO
:
131 case COLORSCALE_PERCENTILE
:
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
),
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
):
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() ) );
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
;
181 const char* getAxisPosition(databar::ScAxisPosition eAxisPosition
)
183 switch(eAxisPosition
)
187 case databar::AUTOMATIC
:
189 case databar::MIDDLE
:
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
),
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
):
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
);
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
),
248 maCfvos
.SaveXml(rStrm
);
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
):
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
) );
273 case condformat::ICONSET
:
275 const ScIconSetFormat
& rIconSet
= static_cast<const ScIconSetFormat
&>(rFormat
);
276 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 ? nullptr : 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
:
331 if (rIconSet
.GetIconSetData()->mbCustom
)
336 maCfRules
.AppendNewRecord(new XclExpExtCfRule(*this, *pEntry
, aAddr
, itr
->aGUID
, itr
->nPriority
));
340 case condformat::DATABAR
:
341 maCfRules
.AppendNewRecord(new XclExpExtCfRule( *this, *pEntry
, aAddr
, itr
->aGUID
, itr
->nPriority
));
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",
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
):
369 maURI
= OString("{7626C862-2A13-11E5-B345-FEFF819CDC9F}");
373 case formula::FormulaGrammar::CONV_OOO
:
374 maSyntax
= OString("CalcA1");
376 case formula::FormulaGrammar::CONV_XL_A1
:
377 maSyntax
= OString("ExcelA1");
379 case formula::FormulaGrammar::CONV_XL_R1C1
:
380 maSyntax
= OString("ExcelR1C1");
382 case formula::FormulaGrammar::CONV_A1_XL_A1
:
383 maSyntax
= OString("CalcA1ExcelA1");
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");
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(),
403 rWorksheet
->singleElementNS( XML_loext
, XML_extCalcPr
,
404 XML_stringRefSyntax
, maSyntax
.getStr(),
407 rWorksheet
->endElement( XML_ext
);
410 XclExpExtCondFormat::XclExpExtCondFormat( const XclExpRoot
& 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(),
424 rWorksheet
->startElementNS( XML_x14
, XML_conditionalFormattings
,
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())
443 sax_fastparser::FSHelperPtr
& rWorksheet
= rStrm
.GetCurrentStream();
444 rWorksheet
->startElement( XML_extLst
,
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: */