Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / filter / oox / extlstcontext.cxx
blob023c27df29a9995ad617a3ea0f1827d374e0d7dc
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 <oox/helper/attributelist.hxx>
14 #include <oox/token/namespaces.hxx>
15 #include <oox/token/tokens.hxx>
16 #include "colorscale.hxx"
17 #include "condformatbuffer.hxx"
18 #include "condformatcontext.hxx"
19 #include "document.hxx"
21 #include "rangeutl.hxx"
22 #include <o3tl/make_unique.hxx>
24 using ::oox::core::ContextHandlerRef;
26 namespace oox {
27 namespace xls {
29 ExtCfRuleContext::ExtCfRuleContext( WorksheetContextBase& rFragment, ScDataBarFormatData* pTarget ):
30 WorksheetContextBase( rFragment ),
31 mpTarget( pTarget ),
32 mbFirstEntry(true)
36 ContextHandlerRef ExtCfRuleContext::onCreateContext( sal_Int32 , const AttributeList& )
38 return this;
41 void ExtCfRuleContext::onStartElement( const AttributeList& rAttribs )
43 switch( getCurrentElement() )
45 case XLS14_TOKEN( dataBar ):
47 ExtCfDataBarRuleRef xRule = getCondFormats().createExtCfDataBarRule(mpTarget);
48 xRule->importDataBar( rAttribs );
49 break;
51 case XLS14_TOKEN( negativeFillColor ):
53 ExtCfDataBarRuleRef xRule = getCondFormats().createExtCfDataBarRule(mpTarget);
54 xRule->importNegativeFillColor( rAttribs );
55 break;
57 case XLS14_TOKEN( axisColor ):
59 ExtCfDataBarRuleRef xRule = getCondFormats().createExtCfDataBarRule(mpTarget);
60 xRule->importAxisColor( rAttribs );
61 break;
63 case XLS14_TOKEN( cfvo ):
65 ExtCfDataBarRuleRef xRule = getCondFormats().createExtCfDataBarRule(mpTarget);
66 xRule->importCfvo( rAttribs );
67 xRule->getModel().mbIsLower = mbFirstEntry;
68 mbFirstEntry = false;
69 break;
71 default:
72 break;
76 ExtConditionalFormattingContext::ExtConditionalFormattingContext(WorksheetContextBase& rFragment):
77 WorksheetContextBase(rFragment),
78 mpCurrentRule(nullptr)
82 ContextHandlerRef ExtConditionalFormattingContext::onCreateContext(sal_Int32 nElement, const AttributeList& rAttribs)
84 if (mpCurrentRule)
86 ScFormatEntry& rFormat = *maEntries.rbegin()->get();
87 assert(rFormat.GetType() == condformat::ICONSET);
88 ScIconSetFormat& rIconSet = static_cast<ScIconSetFormat&>(rFormat);
89 ScDocument* pDoc = &getScDocument();
90 SCTAB nTab = getSheetIndex();
91 ScAddress aPos(0, 0, nTab);
92 mpCurrentRule->SetData(&rIconSet, pDoc, aPos);
93 delete mpCurrentRule;
94 mpCurrentRule = nullptr;
96 if (nElement == XLS14_TOKEN(cfRule))
98 OUString aType = rAttribs.getString(XML_type, OUString());
99 OUString aId = rAttribs.getString(XML_id, OUString());
100 if (aType == "dataBar")
102 // an ext entry does not need to have an existing corresponding entry
103 ExtLst::const_iterator aExt = getExtLst().find( aId );
104 if(aExt == getExtLst().end())
105 return nullptr;
107 ScDataBarFormatData* pInfo = aExt->second;
108 if (!pInfo)
110 return nullptr;
112 return new ExtCfRuleContext( *this, pInfo );
114 else if (aType == "iconSet")
116 ScDocument* pDoc = &getScDocument();
117 mpCurrentRule = new IconSetRule(*this);
118 maEntries.push_back(o3tl::make_unique<ScIconSetFormat>(pDoc));
119 return new IconSetContext(*this, mpCurrentRule);
121 else
123 SAL_WARN("sc", "unhandled XLS14_TOKEN(cfRule) with type: " << aType);
126 else if (nElement == XM_TOKEN(sqref))
128 return this;
131 return nullptr;
134 void ExtConditionalFormattingContext::onStartElement(const AttributeList& /*rAttribs*/)
136 switch (getCurrentElement())
138 case XM_TOKEN(sqref):
141 break;
145 void ExtConditionalFormattingContext::onCharacters(const OUString& rCharacters)
147 aChars = rCharacters;
150 void ExtConditionalFormattingContext::onEndElement()
152 switch (getCurrentElement())
154 case XM_TOKEN(sqref):
156 ScRangeList aRange;
157 ScDocument* pDoc = &getScDocument();
158 bool bSuccess = ScRangeStringConverter::GetRangeListFromString(aRange, aChars, pDoc, formula::FormulaGrammar::CONV_XL_OOX);
159 if (!bSuccess || aRange.empty())
160 break;
162 SCTAB nTab = getSheetIndex();
163 for (size_t i = 0; i < aRange.size(); ++i)
165 aRange[i]->aStart.SetTab(nTab);
166 aRange[i]->aEnd.SetTab(nTab);
169 std::vector< std::unique_ptr<ExtCfCondFormat> >& rExtFormats = getCondFormats().importExtCondFormat();
170 rExtFormats.push_back(o3tl::make_unique<ExtCfCondFormat>(aRange, maEntries));
172 break;
173 case XLS14_TOKEN(cfRule):
174 if (mpCurrentRule)
177 break;
178 default:
179 break;
183 ExtLstLocalContext::ExtLstLocalContext( WorksheetContextBase& rFragment, ScDataBarFormatData* pTarget ):
184 WorksheetContextBase(rFragment),
185 mpTarget(pTarget)
189 ContextHandlerRef ExtLstLocalContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
191 switch( getCurrentElement() )
193 case XLS_TOKEN( extLst ):
194 if(nElement == XLS_TOKEN( ext ))
195 return this;
196 else
197 return nullptr;
198 break;
199 case XLS_TOKEN( ext ):
200 if (nElement == XLS14_TOKEN( id ))
201 return this;
202 else
203 return nullptr;
205 return nullptr;
208 void ExtLstLocalContext::onStartElement( const AttributeList& )
210 switch( getCurrentElement() )
212 case XLS14_TOKEN( id ):
213 break;
217 void ExtLstLocalContext::onCharacters( const OUString& rChars )
219 if (getCurrentElement() == XLS14_TOKEN( id ))
221 getExtLst().insert( std::pair< OUString, ScDataBarFormatData*>(rChars, mpTarget) );
225 ExtGlobalContext::ExtGlobalContext( WorksheetContextBase& rFragment ):
226 WorksheetContextBase(rFragment)
230 ContextHandlerRef ExtGlobalContext::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ )
232 if (nElement == XLS14_TOKEN(conditionalFormatting))
233 return new ExtConditionalFormattingContext(*this);
235 return this;
238 void ExtGlobalContext::onStartElement( const AttributeList& /*rAttribs*/ )
242 ExtLstGlobalContext::ExtLstGlobalContext( WorksheetFragment& rFragment ):
243 WorksheetContextBase(rFragment)
247 ContextHandlerRef ExtLstGlobalContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
249 if (nElement == XLS_TOKEN( ext ))
250 return new ExtGlobalContext( *this );
252 return this;
255 ExtGlobalWorkbookContext::ExtGlobalWorkbookContext( WorkbookContextBase& rFragment ):
256 WorkbookContextBase(rFragment)
260 ContextHandlerRef ExtGlobalWorkbookContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
262 if (nElement == LOEXT_TOKEN(extCalcPr))
264 ScDocument* pDoc = &getScDocument();
265 sal_Int32 nToken = rAttribs.getToken( XML_stringRefSyntax, XML_CalcA1 );
266 ScCalcConfig aCalcConfig = pDoc->GetCalcConfig();
268 switch( nToken )
270 case XML_CalcA1:
271 aCalcConfig.SetStringRefSyntax( formula::FormulaGrammar::CONV_OOO );
272 break;
273 case XML_ExcelA1:
274 aCalcConfig.SetStringRefSyntax( formula::FormulaGrammar::CONV_XL_A1 );
275 break;
276 case XML_ExcelR1C1:
277 aCalcConfig.SetStringRefSyntax( formula::FormulaGrammar::CONV_XL_R1C1 );
278 break;
279 case XML_CalcA1ExcelA1:
280 aCalcConfig.SetStringRefSyntax( formula::FormulaGrammar::CONV_A1_XL_A1 );
281 break;
282 default:
283 aCalcConfig.SetStringRefSyntax( formula::FormulaGrammar::CONV_UNSPECIFIED );
284 break;
286 pDoc->SetCalcConfig(aCalcConfig);
289 return this;
292 void ExtGlobalWorkbookContext::onStartElement( const AttributeList& /*rAttribs*/ )
296 ExtLstGlobalWorkbookContext::ExtLstGlobalWorkbookContext( WorkbookFragment& rFragment ):
297 WorkbookContextBase(rFragment)
301 ContextHandlerRef ExtLstGlobalWorkbookContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
303 if (nElement == XLS_TOKEN( ext ))
304 return new ExtGlobalWorkbookContext( *this );
306 return this;
309 } //namespace oox
310 } //namespace xls
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */