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 "colorscale.hxx"
14 #include "condformatbuffer.hxx"
15 #include "condformatcontext.hxx"
16 #include "document.hxx"
18 #include "rangeutl.hxx"
20 using ::oox::core::ContextHandlerRef
;
25 ExtCfRuleContext::ExtCfRuleContext( WorksheetContextBase
& rFragment
, ScDataBarFormatData
* pTarget
):
26 WorksheetContextBase( rFragment
),
32 ContextHandlerRef
ExtCfRuleContext::onCreateContext( sal_Int32
, const AttributeList
& )
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
);
47 case XLS14_TOKEN( negativeFillColor
):
49 ExtCfDataBarRuleRef xRule
= getCondFormats().createExtCfDataBarRule(mpTarget
);
50 xRule
->importNegativeFillColor( rAttribs
);
53 case XLS14_TOKEN( axisColor
):
55 ExtCfDataBarRuleRef xRule
= getCondFormats().createExtCfDataBarRule(mpTarget
);
56 xRule
->importAxisColor( rAttribs
);
59 case XLS14_TOKEN( cfvo
):
61 ExtCfDataBarRuleRef xRule
= getCondFormats().createExtCfDataBarRule(mpTarget
);
62 xRule
->importCfvo( rAttribs
);
63 xRule
->getModel().mbIsLower
= mbFirstEntry
;
72 ExtConditionalFormattingContext::ExtConditionalFormattingContext(WorksheetContextBase
& rFragment
):
73 WorksheetContextBase(rFragment
),
78 ContextHandlerRef
ExtConditionalFormattingContext::onCreateContext(sal_Int32 nElement
, const AttributeList
& rAttribs
)
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
);
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())
103 ScDataBarFormatData
* pInfo
= aExt
->second
;
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
);
120 SAL_WARN("sc", "unhandled XLS14_TOKEN(cfRule) with type: " << aType
);
123 else if (nElement
== XM_TOKEN(sqref
))
131 void ExtConditionalFormattingContext::onStartElement(const AttributeList
& /*rAttribs*/)
133 switch (getCurrentElement())
135 case XM_TOKEN(sqref
):
142 void ExtConditionalFormattingContext::onCharacters(const OUString
& rCharacters
)
144 aChars
= rCharacters
;
147 void ExtConditionalFormattingContext::onEndElement()
149 switch (getCurrentElement())
151 case XM_TOKEN(sqref
):
154 ScDocument
* pDoc
= &getScDocument();
155 bool bSuccess
= ScRangeStringConverter::GetRangeListFromString(aRange
, aChars
, pDoc
, formula::FormulaGrammar::CONV_XL_OOX
);
156 if (!bSuccess
|| aRange
.empty())
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
));
170 case XLS14_TOKEN(cfRule
):
180 ExtLstLocalContext::ExtLstLocalContext( WorksheetContextBase
& rFragment
, ScDataBarFormatData
* pTarget
):
181 WorksheetContextBase(rFragment
),
186 ContextHandlerRef
ExtLstLocalContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& )
188 switch( getCurrentElement() )
190 case XLS_TOKEN( extLst
):
191 if(nElement
== XLS_TOKEN( ext
))
196 case XLS_TOKEN( ext
):
197 if (nElement
== XLS14_TOKEN( id
))
205 void ExtLstLocalContext::onStartElement( const AttributeList
& )
207 switch( getCurrentElement() )
209 case XLS14_TOKEN( id
):
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);
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 );
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();
268 aCalcConfig
.SetStringRefSyntax( formula::FormulaGrammar::CONV_OOO
);
271 aCalcConfig
.SetStringRefSyntax( formula::FormulaGrammar::CONV_XL_A1
);
274 aCalcConfig
.SetStringRefSyntax( formula::FormulaGrammar::CONV_XL_R1C1
);
276 case XML_CalcA1ExcelA1
:
277 aCalcConfig
.SetStringRefSyntax( formula::FormulaGrammar::CONV_A1_XL_A1
);
280 aCalcConfig
.SetStringRefSyntax( formula::FormulaGrammar::CONV_UNSPECIFIED
);
283 pDoc
->SetCalcConfig(aCalcConfig
);
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 );
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */