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 2 : XclExpExt::XclExpExt( const XclExpRoot& rRoot ):
21 2 : XclExpRoot(rRoot)
22 : {
23 2 : }
24 :
25 198 : XclExtLst::XclExtLst( const XclExpRoot& rRoot ):
26 198 : XclExpRoot(rRoot)
27 : {
28 198 : }
29 :
30 10 : XclExpExtNegativeColor::XclExpExtNegativeColor( const Color& rColor ):
31 10 : maColor(rColor)
32 : {
33 10 : }
34 :
35 10 : void XclExpExtNegativeColor::SaveXml( XclExpXmlStream& rStrm )
36 : {
37 10 : rStrm.GetCurrentStream()->singleElementNS( XML_x14, XML_negativeFillColor,
38 : XML_rgb, XclXmlUtils::ToOString( maColor ).getStr(),
39 20 : FSEND );
40 10 : }
41 :
42 10 : XclExpExtAxisColor::XclExpExtAxisColor( const Color& rColor ):
43 10 : maAxisColor(rColor)
44 : {
45 10 : }
46 :
47 10 : void XclExpExtAxisColor::SaveXml( XclExpXmlStream& rStrm )
48 : {
49 10 : rStrm.GetCurrentStream()->singleElementNS( XML_x14, XML_axisColor,
50 : XML_rgb, XclXmlUtils::ToOString( maAxisColor ).getStr(),
51 20 : FSEND );
52 10 : }
53 :
54 20 : XclExpExtCfvo::XclExpExtCfvo( const XclExpRoot& rRoot, const ScColorScaleEntry& rEntry, const ScAddress& rSrcPos, bool bFirst ):
55 : XclExpRoot(rRoot),
56 20 : meType(rEntry.GetType()),
57 40 : mbFirst(bFirst)
58 : {
59 20 : if( rEntry.GetType() == COLORSCALE_FORMULA )
60 : {
61 2 : const ScTokenArray* pArr = rEntry.GetFormula();
62 2 : OUString aFormula;
63 2 : if(pArr)
64 : {
65 4 : aFormula = XclXmlUtils::ToOUString( GetCompileFormulaContext(), rSrcPos,
66 4 : pArr->Clone());
67 : }
68 2 : maValue = OUStringToOString(aFormula, RTL_TEXTENCODING_UTF8 );
69 : }
70 : else
71 18 : maValue = OString::number(rEntry.GetValue());
72 20 : }
73 :
74 : namespace {
75 :
76 20 : const char* getColorScaleType( ScColorScaleEntryType eType, bool bFirst )
77 : {
78 20 : switch(eType)
79 : {
80 : case COLORSCALE_MIN:
81 2 : return "min";
82 : case COLORSCALE_MAX:
83 2 : return "max";
84 : case COLORSCALE_PERCENT:
85 2 : return "percent";
86 : case COLORSCALE_FORMULA:
87 2 : return "formula";
88 : case COLORSCALE_AUTO:
89 8 : if(bFirst)
90 4 : return "autoMin";
91 : else
92 4 : return "autoMax";
93 : case COLORSCALE_PERCENTILE:
94 2 : return "percentile";
95 : default:
96 2 : break;
97 : }
98 2 : return "num";
99 : }
100 :
101 : }
102 :
103 20 : void XclExpExtCfvo::SaveXml( XclExpXmlStream& rStrm )
104 : {
105 20 : 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 20 : FSEND );
110 20 : }
111 :
112 10 : XclExpExtDataBar::XclExpExtDataBar( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, const ScAddress& rPos ):
113 10 : XclExpRoot(rRoot)
114 : {
115 10 : const ScDataBarFormatData& rFormatData = *rFormat.GetDataBarData();
116 10 : mpLowerLimit.reset( new XclExpExtCfvo( *this, *rFormatData.mpLowerLimit.get(), rPos, true ) );
117 10 : mpUpperLimit.reset( new XclExpExtCfvo( *this, *rFormatData.mpUpperLimit.get(), rPos, false ) );
118 10 : if(rFormatData.mpNegativeColor.get())
119 10 : mpNegativeColor.reset( new XclExpExtNegativeColor( *rFormatData.mpNegativeColor.get() ) );
120 : else
121 0 : mpNegativeColor.reset( new XclExpExtNegativeColor( rFormatData.maPositiveColor ) );
122 10 : mpAxisColor.reset( new XclExpExtAxisColor( rFormatData.maAxisColor ) );
123 :
124 10 : meAxisPosition = rFormatData.meAxisPosition;
125 10 : }
126 :
127 : namespace {
128 :
129 10 : const char* getAxisPosition(databar::ScAxisPosition eAxisPosition)
130 : {
131 10 : switch(eAxisPosition)
132 : {
133 : case databar::NONE:
134 0 : return "none";
135 : case databar::AUTOMATIC:
136 8 : return "automatic";
137 : case databar::MIDDLE:
138 2 : return "middle";
139 : }
140 0 : return "";
141 : }
142 :
143 : }
144 :
145 10 : void XclExpExtDataBar::SaveXml( XclExpXmlStream& rStrm )
146 : {
147 10 : 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 10 : FSEND );
153 :
154 10 : mpLowerLimit->SaveXml( rStrm );
155 10 : mpUpperLimit->SaveXml( rStrm );
156 10 : mpNegativeColor->SaveXml( rStrm );
157 10 : mpAxisColor->SaveXml( rStrm );
158 :
159 10 : rWorksheet->endElementNS( XML_x14, XML_dataBar );
160 10 : }
161 :
162 10 : XclExpExtCfRule::XclExpExtCfRule( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, const ScAddress& rPos, const OString& rId ):
163 : XclExpRoot(rRoot),
164 10 : maId(rId)
165 : {
166 10 : maDataBar.reset( new XclExpExtDataBar( *this, rFormat, rPos ) );
167 10 : }
168 :
169 10 : void XclExpExtCfRule::SaveXml( XclExpXmlStream& rStrm )
170 : {
171 10 : sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
172 : rWorksheet->startElementNS( XML_x14, XML_cfRule,
173 : XML_type, "dataBar",
174 : XML_id, maId.getStr(),
175 10 : FSEND );
176 :
177 10 : maDataBar->SaveXml( rStrm );
178 :
179 10 : rWorksheet->endElementNS( XML_x14, XML_cfRule );
180 :
181 10 : }
182 :
183 10 : XclExpExtConditionalFormatting::XclExpExtConditionalFormatting( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, const ScAddress& rPos, const OString& rId ):
184 10 : XclExpRoot(rRoot)
185 : {
186 10 : maCfRule.reset( new XclExpExtCfRule( *this, rFormat, rPos, rId ) );
187 10 : maRange = rFormat.GetRange();
188 10 : }
189 :
190 10 : void XclExpExtConditionalFormatting::SaveXml( XclExpXmlStream& rStrm )
191 : {
192 10 : 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 10 : FSEND );
196 :
197 10 : maCfRule->SaveXml( rStrm );
198 10 : rWorksheet->startElementNS( XML_xm, XML_sqref, FSEND );
199 10 : rWorksheet->write(XclXmlUtils::ToOString(maRange).getStr());
200 :
201 10 : rWorksheet->endElementNS( XML_xm, XML_sqref );
202 :
203 10 : rWorksheet->endElementNS( XML_x14, XML_conditionalFormatting );
204 10 : }
205 :
206 2 : XclExpExtCondFormat::XclExpExtCondFormat( const XclExpRoot& rRoot ):
207 2 : XclExpExt( rRoot )
208 : {
209 2 : maURI = OString("{78C0D931-6437-407d-A8EE-F0AAD7539E65}");
210 2 : }
211 :
212 2 : void XclExpExtCondFormat::SaveXml( XclExpXmlStream& rStrm )
213 : {
214 2 : 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 2 : FSEND );
219 :
220 : rWorksheet->startElementNS( XML_x14, XML_conditionalFormattings,
221 2 : FSEND );
222 :
223 2 : maCF.SaveXml( rStrm );
224 :
225 2 : rWorksheet->endElementNS( XML_x14, XML_conditionalFormattings );
226 2 : rWorksheet->endElement( XML_ext );
227 2 : }
228 :
229 10 : void XclExpExtCondFormat::AddRecord( XclExpExtConditionalFormattingRef aEntry )
230 : {
231 10 : maCF.AppendRecord( aEntry );
232 10 : }
233 :
234 148 : void XclExtLst::SaveXml( XclExpXmlStream& rStrm )
235 : {
236 148 : if(maExtEntries.IsEmpty())
237 294 : return;
238 :
239 2 : sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
240 : rWorksheet->startElement( XML_extLst,
241 2 : FSEND );
242 :
243 2 : maExtEntries.SaveXml(rStrm);
244 :
245 2 : rWorksheet->endElement( XML_extLst );
246 : }
247 :
248 2 : void XclExtLst::AddRecord( XclExpExtRef aEntry )
249 : {
250 2 : maExtEntries.AppendRecord( aEntry );
251 2 : }
252 :
253 22 : XclExpExtRef XclExtLst::GetItem( XclExpExtType eType )
254 : {
255 22 : size_t n = maExtEntries.GetSize();
256 22 : for( size_t i = 0; i < n; ++i )
257 : {
258 20 : if (maExtEntries.GetRecord( i )->GetType() == eType)
259 20 : return maExtEntries.GetRecord( i );
260 : }
261 :
262 2 : return XclExpExtRef();
263 48 : }
264 :
265 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|