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