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 "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
;
29 ExtCfRuleContext::ExtCfRuleContext( WorksheetContextBase
& rFragment
, ScDataBarFormatData
* pTarget
):
30 WorksheetContextBase( rFragment
),
36 ContextHandlerRef
ExtCfRuleContext::onCreateContext( sal_Int32
, const AttributeList
& )
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
);
51 case XLS14_TOKEN( negativeFillColor
):
53 ExtCfDataBarRuleRef xRule
= getCondFormats().createExtCfDataBarRule(mpTarget
);
54 xRule
->importNegativeFillColor( rAttribs
);
57 case XLS14_TOKEN( axisColor
):
59 ExtCfDataBarRuleRef xRule
= getCondFormats().createExtCfDataBarRule(mpTarget
);
60 xRule
->importAxisColor( rAttribs
);
63 case XLS14_TOKEN( cfvo
):
65 ExtCfDataBarRuleRef xRule
= getCondFormats().createExtCfDataBarRule(mpTarget
);
66 xRule
->importCfvo( rAttribs
);
67 xRule
->getModel().mbIsLower
= mbFirstEntry
;
76 ExtConditionalFormattingContext::ExtConditionalFormattingContext(WorksheetContextBase
& rFragment
):
77 WorksheetContextBase(rFragment
),
78 mpCurrentRule(nullptr)
82 ContextHandlerRef
ExtConditionalFormattingContext::onCreateContext(sal_Int32 nElement
, const AttributeList
& rAttribs
)
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
);
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())
107 ScDataBarFormatData
* pInfo
= aExt
->second
;
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
);
123 SAL_WARN("sc", "unhandled XLS14_TOKEN(cfRule) with type: " << aType
);
126 else if (nElement
== XM_TOKEN(sqref
))
134 void ExtConditionalFormattingContext::onStartElement(const AttributeList
& /*rAttribs*/)
136 switch (getCurrentElement())
138 case XM_TOKEN(sqref
):
145 void ExtConditionalFormattingContext::onCharacters(const OUString
& rCharacters
)
147 aChars
= rCharacters
;
150 void ExtConditionalFormattingContext::onEndElement()
152 switch (getCurrentElement())
154 case XM_TOKEN(sqref
):
157 ScDocument
* pDoc
= &getScDocument();
158 bool bSuccess
= ScRangeStringConverter::GetRangeListFromString(aRange
, aChars
, pDoc
, formula::FormulaGrammar::CONV_XL_OOX
);
159 if (!bSuccess
|| aRange
.empty())
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
));
173 case XLS14_TOKEN(cfRule
):
183 ExtLstLocalContext::ExtLstLocalContext( WorksheetContextBase
& rFragment
, ScDataBarFormatData
* pTarget
):
184 WorksheetContextBase(rFragment
),
189 ContextHandlerRef
ExtLstLocalContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& )
191 switch( getCurrentElement() )
193 case XLS_TOKEN( extLst
):
194 if(nElement
== XLS_TOKEN( ext
))
199 case XLS_TOKEN( ext
):
200 if (nElement
== XLS14_TOKEN( id
))
208 void ExtLstLocalContext::onStartElement( const AttributeList
& )
210 switch( getCurrentElement() )
212 case XLS14_TOKEN( id
):
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);
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 );
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();
271 aCalcConfig
.SetStringRefSyntax( formula::FormulaGrammar::CONV_OOO
);
274 aCalcConfig
.SetStringRefSyntax( formula::FormulaGrammar::CONV_XL_A1
);
277 aCalcConfig
.SetStringRefSyntax( formula::FormulaGrammar::CONV_XL_R1C1
);
279 case XML_CalcA1ExcelA1
:
280 aCalcConfig
.SetStringRefSyntax( formula::FormulaGrammar::CONV_A1_XL_A1
);
283 aCalcConfig
.SetStringRefSyntax( formula::FormulaGrammar::CONV_UNSPECIFIED
);
286 pDoc
->SetCalcConfig(aCalcConfig
);
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 );
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */