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
;
20 XclExpExt::XclExpExt( const XclExpRoot
& rRoot
):
25 XclExtLst::XclExtLst( const XclExpRoot
& rRoot
):
30 XclExpExtNegativeColor::XclExpExtNegativeColor( const Color
& rColor
):
35 void XclExpExtNegativeColor::SaveXml( XclExpXmlStream
& rStrm
)
37 rStrm
.GetCurrentStream()->singleElementNS( XML_x14
, XML_negativeFillColor
,
38 XML_rgb
, XclXmlUtils::ToOString( maColor
).getStr(),
42 XclExpExtAxisColor::XclExpExtAxisColor( const Color
& rColor
):
47 void XclExpExtAxisColor::SaveXml( XclExpXmlStream
& rStrm
)
49 rStrm
.GetCurrentStream()->singleElementNS( XML_x14
, XML_axisColor
,
50 XML_rgb
, XclXmlUtils::ToOString( maAxisColor
).getStr(),
54 XclExpExtCfvo::XclExpExtCfvo( const XclExpRoot
& rRoot
, const ScColorScaleEntry
& rEntry
, const ScAddress
& rSrcPos
, bool bFirst
):
56 meType(rEntry
.GetType()),
59 if( rEntry
.GetType() == COLORSCALE_FORMULA
)
61 const ScTokenArray
* pArr
= rEntry
.GetFormula();
65 aFormula
= XclXmlUtils::ToOUString( GetRoot().GetDoc(), rSrcPos
,
66 pArr
->Clone(), GetRoot().GetOpCodeMap() );
68 maValue
= OUStringToOString(aFormula
, RTL_TEXTENCODING_UTF8
);
71 maValue
= OString::valueOf(rEntry
.GetValue());
76 const char* getColorScaleType( ScColorScaleEntryType eType
, bool bFirst
)
84 case COLORSCALE_PERCENT
:
86 case COLORSCALE_FORMULA
:
93 case COLORSCALE_PERCENTILE
:
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(),
112 XclExpExtDataBar::XclExpExtDataBar( const XclExpRoot
& rRoot
, const ScDataBarFormat
& rFormat
, const ScAddress
& rPos
):
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() ) );
121 mpNegativeColor
.reset( new XclExpExtNegativeColor( rFormatData
.maPositiveColor
) );
122 mpAxisColor
.reset( new XclExpExtAxisColor( rFormatData
.maAxisColor
) );
124 meAxisPosition
= rFormatData
.meAxisPosition
;
129 const char* getAxisPosition(databar::ScAxisPosition eAxisPosition
)
131 switch(eAxisPosition
)
135 case databar::AUTOMATIC
:
137 case databar::MIDDLE
:
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
),
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
):
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
,
174 XML_id
, maId
.getStr(),
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
):
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",
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
):
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(),
220 rWorksheet
->startElementNS( XML_x14
, XML_conditionalFormattings
,
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())
239 sax_fastparser::FSHelperPtr
& rWorksheet
= rStrm
.GetCurrentStream();
240 rWorksheet
->startElement( XML_extLst
,
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: */