bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / filter / excel / xeextlst.cxx
blob58594fe01a1345e1ad777c6f2ae0f1919d12bfc5
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 XclExpExt::XclExpExt( const XclExpRoot& rRoot ):
21 XclExpRoot(rRoot)
25 XclExtLst::XclExtLst( const XclExpRoot& rRoot ):
26 XclExpRoot(rRoot)
30 XclExpExtNegativeColor::XclExpExtNegativeColor( const Color& rColor ):
31 maColor(rColor)
35 void XclExpExtNegativeColor::SaveXml( XclExpXmlStream& rStrm )
37 rStrm.GetCurrentStream()->singleElementNS( XML_x14, XML_negativeFillColor,
38 XML_rgb, XclXmlUtils::ToOString( maColor ).getStr(),
39 FSEND );
42 XclExpExtAxisColor::XclExpExtAxisColor( const Color& rColor ):
43 maAxisColor(rColor)
47 void XclExpExtAxisColor::SaveXml( XclExpXmlStream& rStrm )
49 rStrm.GetCurrentStream()->singleElementNS( XML_x14, XML_axisColor,
50 XML_rgb, XclXmlUtils::ToOString( maAxisColor ).getStr(),
51 FSEND );
54 XclExpExtCfvo::XclExpExtCfvo( const XclExpRoot& rRoot, const ScColorScaleEntry& rEntry, const ScAddress& rSrcPos, bool bFirst ):
55 XclExpRoot(rRoot),
56 meType(rEntry.GetType()),
57 mbFirst(bFirst)
59 if( rEntry.GetType() == COLORSCALE_FORMULA )
61 const ScTokenArray* pArr = rEntry.GetFormula();
62 OUString aFormula;
63 if(pArr)
65 aFormula = XclXmlUtils::ToOUString( GetRoot().GetDoc(), rSrcPos,
66 pArr->Clone(), GetRoot().GetOpCodeMap() );
68 maValue = OUStringToOString(aFormula, RTL_TEXTENCODING_UTF8 );
70 else
71 maValue = OString::valueOf(rEntry.GetValue());
74 namespace {
76 const char* getColorScaleType( ScColorScaleEntryType eType, bool bFirst )
78 switch(eType)
80 case COLORSCALE_MIN:
81 return "min";
82 case COLORSCALE_MAX:
83 return "max";
84 case COLORSCALE_PERCENT:
85 return "percent";
86 case COLORSCALE_FORMULA:
87 return "formula";
88 case COLORSCALE_AUTO:
89 if(bFirst)
90 return "autoMin";
91 else
92 return "autoMax";
93 case COLORSCALE_PERCENTILE:
94 return "percentile";
95 default:
96 break;
98 return "num";
103 void XclExpExtCfvo::SaveXml( XclExpXmlStream& rStrm )
105 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
106 rWorksheet->singleElementNS( XML_x14, XML_cfvo,
107 XML_type, getColorScaleType(meType, mbFirst),
108 XML_value, maValue.getStr(),
109 FSEND );
112 XclExpExtDataBar::XclExpExtDataBar( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, const ScAddress& rPos ):
113 XclExpRoot(rRoot)
115 const ScDataBarFormatData& rFormatData = *rFormat.GetDataBarData();
116 mpLowerLimit.reset( new XclExpExtCfvo( *this, *rFormatData.mpLowerLimit.get(), rPos, true ) );
117 mpUpperLimit.reset( new XclExpExtCfvo( *this, *rFormatData.mpUpperLimit.get(), rPos, false ) );
118 if(rFormatData.mpNegativeColor.get())
119 mpNegativeColor.reset( new XclExpExtNegativeColor( *rFormatData.mpNegativeColor.get() ) );
120 else
121 mpNegativeColor.reset( new XclExpExtNegativeColor( rFormatData.maPositiveColor ) );
122 mpAxisColor.reset( new XclExpExtAxisColor( rFormatData.maAxisColor ) );
124 meAxisPosition = rFormatData.meAxisPosition;
127 namespace {
129 const char* getAxisPosition(databar::ScAxisPosition eAxisPosition)
131 switch(eAxisPosition)
133 case databar::NONE:
134 return "none";
135 case databar::AUTOMATIC:
136 return "automatic";
137 case databar::MIDDLE:
138 return "middle";
140 return "";
145 void XclExpExtDataBar::SaveXml( XclExpXmlStream& rStrm )
147 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
148 rWorksheet->startElementNS( XML_x14, XML_dataBar,
149 XML_minLength, OString::number(0).getStr(),
150 XML_maxLength, OString::number(100).getStr(),
151 XML_axisPosition, getAxisPosition(meAxisPosition),
152 FSEND );
154 mpLowerLimit->SaveXml( rStrm );
155 mpUpperLimit->SaveXml( rStrm );
156 mpNegativeColor->SaveXml( rStrm );
157 mpAxisColor->SaveXml( rStrm );
159 rWorksheet->endElementNS( XML_x14, XML_dataBar );
162 XclExpExtCfRule::XclExpExtCfRule( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, const ScAddress& rPos, const OString& rId ):
163 XclExpRoot(rRoot),
164 maId(rId)
166 maDataBar.reset( new XclExpExtDataBar( *this, rFormat, rPos ) );
169 void XclExpExtCfRule::SaveXml( XclExpXmlStream& rStrm )
171 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
172 rWorksheet->startElementNS( XML_x14, XML_cfRule,
173 XML_type, "dataBar",
174 XML_id, maId.getStr(),
175 FSEND );
177 maDataBar->SaveXml( rStrm );
179 rWorksheet->endElementNS( XML_x14, XML_cfRule );
183 XclExpExtConditionalFormatting::XclExpExtConditionalFormatting( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, const ScAddress& rPos, const OString& rId ):
184 XclExpRoot(rRoot)
186 maCfRule.reset( new XclExpExtCfRule( *this, rFormat, rPos, rId ) );
187 maRange = rFormat.GetRange();
190 void XclExpExtConditionalFormatting::SaveXml( XclExpXmlStream& rStrm )
192 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
193 rWorksheet->startElementNS( XML_x14, XML_conditionalFormatting,
194 FSNS( XML_xmlns, XML_xm ), "http://schemas.microsoft.com/office/excel/2006/main",
195 FSEND );
197 maCfRule->SaveXml( rStrm );
198 rWorksheet->startElementNS( XML_xm, XML_sqref, FSEND );
199 rWorksheet->write(XclXmlUtils::ToOString(maRange).getStr());
201 rWorksheet->endElementNS( XML_xm, XML_sqref );
203 rWorksheet->endElementNS( XML_x14, XML_conditionalFormatting );
206 XclExpExtCondFormat::XclExpExtCondFormat( const XclExpRoot& rRoot ):
207 XclExpExt( rRoot )
209 maURI = OString("{78C0D931-6437-407d-A8EE-F0AAD7539E65}");
212 void XclExpExtCondFormat::SaveXml( XclExpXmlStream& rStrm )
214 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
215 rWorksheet->startElement( XML_ext,
216 FSNS( XML_xmlns, XML_x14 ), "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",
217 XML_uri, maURI.getStr(),
218 FSEND );
220 rWorksheet->startElementNS( XML_x14, XML_conditionalFormattings,
221 FSEND );
223 maCF.SaveXml( rStrm );
225 rWorksheet->endElementNS( XML_x14, XML_conditionalFormattings );
226 rWorksheet->endElement( XML_ext );
229 void XclExpExtCondFormat::AddRecord( XclExpExtConditionalFormattingRef aEntry )
231 maCF.AppendRecord( aEntry );
234 void XclExtLst::SaveXml( XclExpXmlStream& rStrm )
236 if(maExtEntries.IsEmpty())
237 return;
239 sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
240 rWorksheet->startElement( XML_extLst,
241 FSEND );
243 maExtEntries.SaveXml(rStrm);
245 rWorksheet->endElement( XML_extLst );
248 void XclExtLst::AddRecord( XclExpExtRef aEntry )
250 maExtEntries.AppendRecord( aEntry );
253 XclExpExtRef XclExtLst::GetItem( XclExpExtType eType )
255 size_t n = maExtEntries.GetSize();
256 for( size_t i = 0; i < n; ++i )
258 if (maExtEntries.GetRecord( i )->GetType() == eType)
259 return maExtEntries.GetRecord( i );
262 return XclExpExtRef();
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */