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 "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"
17 :
18 : using namespace ::oox;
19 :
20 : namespace {
21 :
22 0 : const char* getIconSetName( ScIconSetType eType )
23 : {
24 0 : ScIconSetMap* pMap = ScIconSetFormat::getIconSetMap();
25 0 : for(; pMap->pName; ++pMap)
26 : {
27 0 : if(pMap->eType == eType)
28 0 : return pMap->pName;
29 : }
30 :
31 0 : return "";
32 : }
33 :
34 : }
35 :
36 1 : XclExpExt::XclExpExt( const XclExpRoot& rRoot ):
37 1 : XclExpRoot(rRoot)
38 : {
39 1 : }
40 :
41 229 : XclExtLst::XclExtLst( const XclExpRoot& rRoot ):
42 229 : XclExpRoot(rRoot)
43 : {
44 229 : }
45 :
46 5 : XclExpExtNegativeColor::XclExpExtNegativeColor( const Color& rColor ):
47 5 : maColor(rColor)
48 : {
49 5 : }
50 :
51 5 : void XclExpExtNegativeColor::SaveXml( XclExpXmlStream& rStrm )
52 : {
53 5 : rStrm.GetCurrentStream()->singleElementNS( XML_x14, XML_negativeFillColor,
54 : XML_rgb, XclXmlUtils::ToOString( maColor ).getStr(),
55 10 : FSEND );
56 5 : }
57 :
58 5 : XclExpExtAxisColor::XclExpExtAxisColor( const Color& rColor ):
59 5 : maAxisColor(rColor)
60 : {
61 5 : }
62 :
63 5 : void XclExpExtAxisColor::SaveXml( XclExpXmlStream& rStrm )
64 : {
65 5 : rStrm.GetCurrentStream()->singleElementNS( XML_x14, XML_axisColor,
66 : XML_rgb, XclXmlUtils::ToOString( maAxisColor ).getStr(),
67 10 : FSEND );
68 5 : }
69 :
70 0 : XclExpExtIcon::XclExpExtIcon(const XclExpRoot& rRoot, const std::pair<ScIconSetType, sal_Int32>& rCustomEntry):
71 : XclExpRoot(rRoot),
72 0 : nIndex(rCustomEntry.second)
73 : {
74 0 : pIconSetName = getIconSetName(rCustomEntry.first);
75 0 : }
76 :
77 0 : void XclExpExtIcon::SaveXml(XclExpXmlStream& rStrm)
78 : {
79 0 : sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
80 :
81 0 : if (nIndex == -1)
82 : {
83 0 : nIndex = 0;
84 0 : pIconSetName = "NoIcons";
85 : }
86 :
87 : rWorksheet->singleElementNS(XML_x14, XML_cfIcon,
88 : XML_iconSet, pIconSetName,
89 : XML_iconId, OString::number(nIndex).getStr(),
90 0 : FSEND);
91 0 : }
92 :
93 10 : XclExpExtCfvo::XclExpExtCfvo( const XclExpRoot& rRoot, const ScColorScaleEntry& rEntry, const ScAddress& rSrcPos, bool bFirst ):
94 : XclExpRoot(rRoot),
95 10 : meType(rEntry.GetType()),
96 20 : mbFirst(bFirst)
97 : {
98 10 : if( rEntry.GetType() == COLORSCALE_FORMULA )
99 : {
100 1 : const ScTokenArray* pArr = rEntry.GetFormula();
101 1 : OUString aFormula;
102 1 : if(pArr)
103 : {
104 2 : aFormula = XclXmlUtils::ToOUString( GetCompileFormulaContext(), rSrcPos,
105 2 : pArr->Clone());
106 : }
107 1 : maValue = OUStringToOString(aFormula, RTL_TEXTENCODING_UTF8 );
108 : }
109 : else
110 9 : maValue = OString::number(rEntry.GetValue());
111 10 : }
112 :
113 : namespace {
114 :
115 10 : const char* getColorScaleType( ScColorScaleEntryType eType, bool bFirst )
116 : {
117 10 : switch(eType)
118 : {
119 : case COLORSCALE_MIN:
120 1 : return "min";
121 : case COLORSCALE_MAX:
122 1 : return "max";
123 : case COLORSCALE_PERCENT:
124 1 : return "percent";
125 : case COLORSCALE_FORMULA:
126 1 : return "formula";
127 : case COLORSCALE_AUTO:
128 4 : if(bFirst)
129 2 : return "autoMin";
130 : else
131 2 : return "autoMax";
132 : case COLORSCALE_PERCENTILE:
133 1 : return "percentile";
134 : default:
135 1 : break;
136 : }
137 1 : return "num";
138 : }
139 :
140 : }
141 :
142 10 : void XclExpExtCfvo::SaveXml( XclExpXmlStream& rStrm )
143 : {
144 10 : sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
145 : rWorksheet->startElementNS( XML_x14, XML_cfvo,
146 : XML_type, getColorScaleType(meType, mbFirst),
147 10 : FSEND );
148 :
149 19 : if (meType == COLORSCALE_FORMULA ||
150 17 : meType == COLORSCALE_PERCENT ||
151 15 : meType == COLORSCALE_PERCENTILE ||
152 7 : meType == COLORSCALE_VALUE)
153 : {
154 4 : rWorksheet->startElementNS(XML_xm, XML_f, FSEND);
155 4 : rWorksheet->writeEscaped(maValue.getStr());
156 4 : rWorksheet->endElementNS(XML_xm, XML_f);
157 : }
158 :
159 10 : rWorksheet->endElementNS(XML_x14, XML_cfvo);
160 10 : }
161 :
162 5 : XclExpExtDataBar::XclExpExtDataBar( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, const ScAddress& rPos ):
163 5 : XclExpRoot(rRoot)
164 : {
165 5 : const ScDataBarFormatData& rFormatData = *rFormat.GetDataBarData();
166 5 : mpLowerLimit.reset( new XclExpExtCfvo( *this, *rFormatData.mpLowerLimit.get(), rPos, true ) );
167 5 : mpUpperLimit.reset( new XclExpExtCfvo( *this, *rFormatData.mpUpperLimit.get(), rPos, false ) );
168 5 : if(rFormatData.mpNegativeColor.get())
169 5 : mpNegativeColor.reset( new XclExpExtNegativeColor( *rFormatData.mpNegativeColor.get() ) );
170 : else
171 0 : mpNegativeColor.reset( new XclExpExtNegativeColor( rFormatData.maPositiveColor ) );
172 5 : mpAxisColor.reset( new XclExpExtAxisColor( rFormatData.maAxisColor ) );
173 :
174 5 : meAxisPosition = rFormatData.meAxisPosition;
175 5 : mbGradient = rFormatData.mbGradient;
176 5 : mnMinLength = rFormatData.mnMinLength;
177 5 : mnMaxLength = rFormatData.mnMaxLength;
178 5 : }
179 :
180 : namespace {
181 :
182 5 : const char* getAxisPosition(databar::ScAxisPosition eAxisPosition)
183 : {
184 5 : switch(eAxisPosition)
185 : {
186 : case databar::NONE:
187 0 : return "none";
188 : case databar::AUTOMATIC:
189 4 : return "automatic";
190 : case databar::MIDDLE:
191 1 : return "middle";
192 : }
193 0 : return "";
194 : }
195 :
196 : }
197 :
198 5 : void XclExpExtDataBar::SaveXml( XclExpXmlStream& rStrm )
199 : {
200 5 : 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 5 : FSEND );
207 :
208 5 : mpLowerLimit->SaveXml( rStrm );
209 5 : mpUpperLimit->SaveXml( rStrm );
210 5 : mpNegativeColor->SaveXml( rStrm );
211 5 : mpAxisColor->SaveXml( rStrm );
212 :
213 5 : rWorksheet->endElementNS( XML_x14, XML_dataBar );
214 5 : }
215 :
216 0 : XclExpExtIconSet::XclExpExtIconSet(const XclExpRoot& rRoot, const ScIconSetFormat& rFormat, const ScAddress& rPos):
217 0 : XclExpRoot(rRoot)
218 : {
219 0 : const ScIconSetFormatData& rData = *rFormat.GetIconSetData();
220 0 : for (auto itr = rData.maEntries.begin(); itr != rData.maEntries.end(); ++itr)
221 : {
222 0 : maCfvos.AppendNewRecord(new XclExpExtCfvo(*this, *itr, rPos, false));
223 : }
224 0 : mbCustom = rData.mbCustom;
225 0 : mbReverse = rData.mbReverse;
226 0 : mbShowValue = rData.mbShowValue;
227 0 : mpIconSetName = getIconSetName(rData.eIconSetType);
228 :
229 0 : if (mbCustom)
230 : {
231 0 : for (auto itr = rData.maCustomVector.begin(); itr != rData.maCustomVector.end(); ++itr)
232 : {
233 0 : maCustom.AppendNewRecord(new XclExpExtIcon(*this, *itr));
234 : }
235 : }
236 0 : }
237 :
238 0 : void XclExpExtIconSet::SaveXml(XclExpXmlStream& rStrm)
239 : {
240 0 : sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
241 :
242 : rWorksheet->startElementNS(XML_x14, XML_iconSet,
243 : XML_iconSet, mpIconSetName,
244 0 : XML_custom, mbCustom ? XclXmlUtils::ToPsz10(mbCustom) : NULL,
245 : XML_reverse, XclXmlUtils::ToPsz10(mbReverse),
246 : XML_showValue, XclXmlUtils::ToPsz10(mbShowValue),
247 0 : FSEND);
248 :
249 0 : maCfvos.SaveXml(rStrm);
250 :
251 0 : if (mbCustom)
252 : {
253 0 : maCustom.SaveXml(rStrm);
254 : }
255 :
256 0 : rWorksheet->endElementNS(XML_x14, XML_iconSet);
257 0 : }
258 :
259 5 : 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 5 : mnPriority(nPriority)
264 : {
265 5 : switch (rFormat.GetType())
266 : {
267 : case condformat::DATABAR:
268 : {
269 5 : const ScDataBarFormat& rDataBar = static_cast<const ScDataBarFormat&>(rFormat);
270 5 : mxEntry.reset( new XclExpExtDataBar( *this, rDataBar, rPos ) );
271 5 : pType = "dataBar";
272 : }
273 5 : break;
274 : case condformat::ICONSET:
275 : {
276 0 : const ScIconSetFormat& rIconSet = static_cast<const ScIconSetFormat&>(rFormat);
277 0 : mxEntry.reset(new XclExpExtIconSet(*this, rIconSet, rPos));
278 0 : pType = "iconSet";
279 : }
280 : default:
281 0 : break;
282 : }
283 5 : }
284 :
285 5 : void XclExpExtCfRule::SaveXml( XclExpXmlStream& rStrm )
286 : {
287 5 : if (!mxEntry)
288 5 : return;
289 :
290 5 : sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
291 : rWorksheet->startElementNS( XML_x14, XML_cfRule,
292 : XML_type, pType,
293 10 : XML_priority, mnPriority == -1 ? NULL : OString::number(mnPriority).getStr(),
294 : XML_id, maId.getStr(),
295 15 : FSEND );
296 :
297 5 : mxEntry->SaveXml( rStrm );
298 :
299 5 : rWorksheet->endElementNS( XML_x14, XML_cfRule );
300 :
301 : }
302 :
303 5 : XclExpExtConditionalFormatting::XclExpExtConditionalFormatting( const XclExpRoot& rRoot,
304 : std::vector<XclExpExtCondFormatData>& rData, const ScRangeList& rRange):
305 : XclExpRoot(rRoot),
306 5 : maRange(rRange)
307 : {
308 5 : ScAddress aAddr = maRange.front()->aStart;
309 10 : for (auto itr = rData.begin(), itrEnd = rData.end(); itr != itrEnd; ++itr)
310 : {
311 5 : const ScFormatEntry* pEntry = itr->pEntry;
312 5 : switch (pEntry->GetType())
313 : {
314 : case condformat::ICONSET:
315 : {
316 0 : const ScIconSetFormat& rIconSet = static_cast<const ScIconSetFormat&>(*pEntry);
317 0 : bool bNeedsExt = false;
318 0 : switch (rIconSet.GetIconSetData()->eIconSetType)
319 : {
320 : case IconSet_3Triangles:
321 : case IconSet_3Smilies:
322 : case IconSet_3ColorSmilies:
323 : case IconSet_5Boxes:
324 0 : bNeedsExt = true;
325 0 : break;
326 : default:
327 0 : break;
328 : }
329 :
330 0 : if (rIconSet.GetIconSetData()->mbCustom)
331 0 : bNeedsExt = true;
332 :
333 0 : if (bNeedsExt)
334 : {
335 0 : maCfRules.AppendNewRecord(new XclExpExtCfRule(*this, *pEntry, aAddr, itr->aGUID, itr->nPriority));
336 : }
337 : }
338 0 : break;
339 : case condformat::DATABAR:
340 5 : maCfRules.AppendNewRecord(new XclExpExtCfRule( *this, *pEntry, aAddr, itr->aGUID, itr->nPriority));
341 5 : break;
342 : default:
343 0 : break;
344 : }
345 : }
346 5 : }
347 :
348 5 : void XclExpExtConditionalFormatting::SaveXml( XclExpXmlStream& rStrm )
349 : {
350 5 : 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 5 : FSEND );
354 :
355 5 : maCfRules.SaveXml( rStrm );
356 5 : rWorksheet->startElementNS( XML_xm, XML_sqref, FSEND );
357 5 : rWorksheet->write(XclXmlUtils::ToOString(maRange).getStr());
358 :
359 5 : rWorksheet->endElementNS( XML_xm, XML_sqref );
360 :
361 5 : rWorksheet->endElementNS( XML_x14, XML_conditionalFormatting );
362 5 : }
363 :
364 1 : XclExpExtCondFormat::XclExpExtCondFormat( const XclExpRoot& rRoot ):
365 1 : XclExpExt( rRoot )
366 : {
367 1 : maURI = OString("{78C0D931-6437-407d-A8EE-F0AAD7539E65}");
368 1 : }
369 :
370 1 : void XclExpExtCondFormat::SaveXml( XclExpXmlStream& rStrm )
371 : {
372 1 : sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
373 : rWorksheet->startElement( XML_ext,
374 : FSNS( XML_xmlns, XML_x14 ), "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",
375 : XML_uri, maURI.getStr(),
376 1 : FSEND );
377 :
378 : rWorksheet->startElementNS( XML_x14, XML_conditionalFormattings,
379 1 : FSEND );
380 :
381 1 : maCF.SaveXml( rStrm );
382 :
383 1 : rWorksheet->endElementNS( XML_x14, XML_conditionalFormattings );
384 1 : rWorksheet->endElement( XML_ext );
385 1 : }
386 :
387 5 : void XclExpExtCondFormat::AddRecord( XclExpExtConditionalFormattingRef aEntry )
388 : {
389 5 : maCF.AppendRecord( aEntry );
390 5 : }
391 :
392 200 : void XclExtLst::SaveXml( XclExpXmlStream& rStrm )
393 : {
394 200 : if(maExtEntries.IsEmpty())
395 399 : return;
396 :
397 1 : sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
398 : rWorksheet->startElement( XML_extLst,
399 1 : FSEND );
400 :
401 1 : maExtEntries.SaveXml(rStrm);
402 :
403 1 : rWorksheet->endElement( XML_extLst );
404 : }
405 :
406 1 : void XclExtLst::AddRecord( XclExpExtRef aEntry )
407 : {
408 1 : maExtEntries.AppendRecord( aEntry );
409 1 : }
410 :
411 11 : XclExpExtRef XclExtLst::GetItem( XclExpExtType eType )
412 : {
413 11 : size_t n = maExtEntries.GetSize();
414 11 : for( size_t i = 0; i < n; ++i )
415 : {
416 10 : if (maExtEntries.GetRecord( i )->GetType() == eType)
417 10 : return maExtEntries.GetRecord( i );
418 : }
419 :
420 1 : return XclExpExtRef();
421 30 : }
422 :
423 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|