fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / oox / extlstcontext.cxx
blobf0980d54ffb5b59fdfeb0acd1b36633e6e77cd3c
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 "extlstcontext.hxx"
11 #include "worksheethelper.hxx"
12 #include <oox/core/contexthandler.hxx>
13 #include "colorscale.hxx"
14 #include "condformatbuffer.hxx"
15 #include "condformatcontext.hxx"
16 #include "document.hxx"
18 #include "rangeutl.hxx"
20 using ::oox::core::ContextHandlerRef;
22 namespace oox {
23 namespace xls {
25 ExtCfRuleContext::ExtCfRuleContext( WorksheetContextBase& rFragment, ScDataBarFormatData* pTarget ):
26 WorksheetContextBase( rFragment ),
27 mpTarget( pTarget ),
28 mbFirstEntry(true)
32 ContextHandlerRef ExtCfRuleContext::onCreateContext( sal_Int32 , const AttributeList& )
34 return this;
37 void ExtCfRuleContext::onStartElement( const AttributeList& rAttribs )
39 switch( getCurrentElement() )
41 case XLS14_TOKEN( dataBar ):
43 ExtCfDataBarRuleRef xRule = getCondFormats().createExtCfDataBarRule(mpTarget);
44 xRule->importDataBar( rAttribs );
45 break;
47 case XLS14_TOKEN( negativeFillColor ):
49 ExtCfDataBarRuleRef xRule = getCondFormats().createExtCfDataBarRule(mpTarget);
50 xRule->importNegativeFillColor( rAttribs );
51 break;
53 case XLS14_TOKEN( axisColor ):
55 ExtCfDataBarRuleRef xRule = getCondFormats().createExtCfDataBarRule(mpTarget);
56 xRule->importAxisColor( rAttribs );
57 break;
59 case XLS14_TOKEN( cfvo ):
61 ExtCfDataBarRuleRef xRule = getCondFormats().createExtCfDataBarRule(mpTarget);
62 xRule->importCfvo( rAttribs );
63 xRule->getModel().mbIsLower = mbFirstEntry;
64 mbFirstEntry = false;
65 break;
67 default:
68 break;
72 ExtConditionalFormattingContext::ExtConditionalFormattingContext(WorksheetContextBase& rFragment):
73 WorksheetContextBase(rFragment),
74 mpCurrentRule(NULL)
78 ContextHandlerRef ExtConditionalFormattingContext::onCreateContext(sal_Int32 nElement, const AttributeList& rAttribs)
80 if (mpCurrentRule)
82 ScFormatEntry& rFormat = *maEntries.rbegin();
83 assert(rFormat.GetType() == condformat::ICONSET);
84 ScIconSetFormat& rIconSet = static_cast<ScIconSetFormat&>(rFormat);
85 ScDocument* pDoc = &getScDocument();
86 SCTAB nTab = getSheetIndex();
87 ScAddress aPos(0, 0, nTab);
88 mpCurrentRule->SetData(&rIconSet, pDoc, aPos);
89 delete mpCurrentRule;
90 mpCurrentRule = NULL;
92 if (nElement == XLS14_TOKEN(cfRule))
94 OUString aType = rAttribs.getString(XML_type, OUString());
95 OUString aId = rAttribs.getString(XML_id, OUString());
96 if (aType == "dataBar")
98 // an ext entry does not need to have an existing corresponding entry
99 ExtLst::const_iterator aExt = getExtLst().find( aId );
100 if(aExt == getExtLst().end())
101 return NULL;
103 ScDataBarFormatData* pInfo = aExt->second;
104 if (!pInfo)
106 return NULL;
108 return new ExtCfRuleContext( *this, pInfo );
110 else if (aType == "iconSet")
112 ScDocument* pDoc = &getScDocument();
113 mpCurrentRule = new IconSetRule(*this);
114 ScIconSetFormat* pIconSet = new ScIconSetFormat(pDoc);
115 maEntries.push_back(pIconSet);
116 return new IconSetContext(*this, mpCurrentRule);
118 else
120 SAL_WARN("sc", "unhandled XLS14_TOKEN(cfRule) with type: " << aType);
123 else if (nElement == XM_TOKEN(sqref))
125 return this;
128 return NULL;
131 void ExtConditionalFormattingContext::onStartElement(const AttributeList& /*rAttribs*/)
133 switch (getCurrentElement())
135 case XM_TOKEN(sqref):
138 break;
142 void ExtConditionalFormattingContext::onCharacters(const OUString& rCharacters)
144 aChars = rCharacters;
147 void ExtConditionalFormattingContext::onEndElement()
149 switch (getCurrentElement())
151 case XM_TOKEN(sqref):
153 ScRangeList aRange;
154 ScDocument* pDoc = &getScDocument();
155 bool bSuccess = ScRangeStringConverter::GetRangeListFromString(aRange, aChars, pDoc, formula::FormulaGrammar::CONV_XL_OOX);
156 if (!bSuccess || aRange.empty())
157 break;
159 SCTAB nTab = getSheetIndex();
160 for (size_t i = 0; i < aRange.size(); ++i)
162 aRange[i]->aStart.SetTab(nTab);
163 aRange[i]->aEnd.SetTab(nTab);
166 boost::ptr_vector<ExtCfCondFormat>& rExtFormats = getCondFormats().importExtCondFormat();
167 rExtFormats.push_back(new ExtCfCondFormat(aRange, maEntries));
169 break;
170 case XLS14_TOKEN(cfRule):
171 if (mpCurrentRule)
174 break;
175 default:
176 break;
180 ExtLstLocalContext::ExtLstLocalContext( WorksheetContextBase& rFragment, ScDataBarFormatData* pTarget ):
181 WorksheetContextBase(rFragment),
182 mpTarget(pTarget)
186 ContextHandlerRef ExtLstLocalContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
188 switch( getCurrentElement() )
190 case XLS_TOKEN( extLst ):
191 if(nElement == XLS_TOKEN( ext ))
192 return this;
193 else
194 return 0;
195 break;
196 case XLS_TOKEN( ext ):
197 if (nElement == XLS14_TOKEN( id ))
198 return this;
199 else
200 return 0;
202 return 0;
205 void ExtLstLocalContext::onStartElement( const AttributeList& )
207 switch( getCurrentElement() )
209 case XLS14_TOKEN( id ):
210 break;
214 void ExtLstLocalContext::onCharacters( const OUString& rChars )
216 if (getCurrentElement() == XLS14_TOKEN( id ))
218 getExtLst().insert( std::pair< OUString, ScDataBarFormatData*>(rChars, mpTarget) );
222 ExtGlobalContext::ExtGlobalContext( WorksheetContextBase& rFragment ):
223 WorksheetContextBase(rFragment)
227 ContextHandlerRef ExtGlobalContext::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ )
229 if (nElement == XLS14_TOKEN(conditionalFormatting))
230 return new ExtConditionalFormattingContext(*this);
232 return this;
235 void ExtGlobalContext::onStartElement( const AttributeList& /*rAttribs*/ )
239 ExtLstGlobalContext::ExtLstGlobalContext( WorksheetFragment& rFragment ):
240 WorksheetContextBase(rFragment)
244 ContextHandlerRef ExtLstGlobalContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
246 if (nElement == XLS_TOKEN( ext ))
247 return new ExtGlobalContext( *this );
249 return this;
252 ExtGlobalWorkbookContext::ExtGlobalWorkbookContext( WorkbookContextBase& rFragment ):
253 WorkbookContextBase(rFragment)
257 ContextHandlerRef ExtGlobalWorkbookContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
259 if (nElement == LOEXT_TOKEN(extCalcPr))
261 ScDocument* pDoc = &getScDocument();
262 sal_Int32 nToken = rAttribs.getToken( XML_stringRefSyntax, XML_CalcA1 );
263 ScCalcConfig aCalcConfig = pDoc->GetCalcConfig();
265 switch( nToken )
267 case XML_CalcA1:
268 aCalcConfig.SetStringRefSyntax( formula::FormulaGrammar::CONV_OOO );
269 break;
270 case XML_ExcelA1:
271 aCalcConfig.SetStringRefSyntax( formula::FormulaGrammar::CONV_XL_A1 );
272 break;
273 case XML_ExcelR1C1:
274 aCalcConfig.SetStringRefSyntax( formula::FormulaGrammar::CONV_XL_R1C1 );
275 break;
276 case XML_CalcA1ExcelA1:
277 aCalcConfig.SetStringRefSyntax( formula::FormulaGrammar::CONV_A1_XL_A1 );
278 break;
279 default:
280 aCalcConfig.SetStringRefSyntax( formula::FormulaGrammar::CONV_UNSPECIFIED );
281 break;
283 pDoc->SetCalcConfig(aCalcConfig);
286 return this;
289 void ExtGlobalWorkbookContext::onStartElement( const AttributeList& /*rAttribs*/ )
293 ExtLstGlobalWorkbookContext::ExtLstGlobalWorkbookContext( WorkbookFragment& rFragment ):
294 WorkbookContextBase(rFragment)
298 ContextHandlerRef ExtLstGlobalWorkbookContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
300 if (nElement == XLS_TOKEN( ext ))
301 return new ExtGlobalWorkbookContext( *this );
303 return this;
306 } //namespace oox
307 } //namespace xls
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */