Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / oox / source / drawingml / chart / axiscontext.cxx
blob45f61a9a019ccb916ecc802c97193d16f47d6515
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <drawingml/chart/axiscontext.hxx>
22 #include <drawingml/shapepropertiescontext.hxx>
23 #include <drawingml/textbodycontext.hxx>
24 #include <drawingml/chart/axismodel.hxx>
25 #include <drawingml/chart/titlecontext.hxx>
26 #include <oox/core/xmlfilterbase.hxx>
27 #include <oox/helper/attributelist.hxx>
28 #include <oox/token/namespaces.hxx>
29 #include <oox/token/tokens.hxx>
31 namespace oox {
32 namespace drawingml {
33 namespace chart {
35 using ::oox::core::ContextHandlerRef;
36 using ::oox::core::ContextHandler2Helper;
38 AxisDispUnitsContext::AxisDispUnitsContext( ContextHandler2Helper& rParent, AxisDispUnitsModel& rModel ) :
39 ContextBase< AxisDispUnitsModel >( rParent, rModel )
43 AxisDispUnitsContext::~AxisDispUnitsContext()
47 ContextHandlerRef AxisDispUnitsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
49 switch( getCurrentElement() )
51 case C_TOKEN( dispUnits ):
52 switch( nElement )
54 case C_TOKEN( builtInUnit ):
55 mrModel.mnBuiltInUnit = rAttribs.getString( XML_val, "thousands" );
56 return nullptr;
57 case C_TOKEN( custUnit ):
58 mrModel.mfCustomUnit = rAttribs.getDouble( XML_val, 0.0 );
59 return nullptr;
60 case C_TOKEN( dispUnitsLbl ):
61 return this;
63 break;
65 case C_TOKEN( dispUnitsLbl ):
66 switch( nElement )
68 case C_TOKEN( layout ):
69 return new LayoutContext( *this, mrModel.mxLayout.create() );
70 case C_TOKEN( spPr ):
71 return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() );
72 case C_TOKEN( tx ):
73 return new TextContext( *this, mrModel.mxText.create() );
74 case C_TOKEN( txPr ):
75 return new TextBodyContext( *this, mrModel.mxTextProp.create() );
77 break;
79 return nullptr;
82 AxisContextBase::AxisContextBase( ContextHandler2Helper& rParent, AxisModel& rModel ) :
83 ContextBase< AxisModel >( rParent, rModel )
87 AxisContextBase::~AxisContextBase()
91 ContextHandlerRef AxisContextBase::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
93 bool bMSO2007Doc = getFilter().isMSO2007Document();
94 switch( getCurrentElement() )
96 case C_TOKEN( catAx ):
97 case C_TOKEN( dateAx ):
98 case C_TOKEN( serAx ):
99 case C_TOKEN( valAx ):
100 switch( nElement )
102 case C_TOKEN( axId ):
103 mrModel.mnAxisId = rAttribs.getInteger( XML_val, -1 );
104 return nullptr;
105 case C_TOKEN( crossAx ):
106 mrModel.mnCrossAxisId = rAttribs.getInteger( XML_val, -1 );
107 return nullptr;
108 case C_TOKEN( crosses ):
109 mrModel.mnCrossMode = rAttribs.getToken( XML_val, XML_autoZero );
110 return nullptr;
111 case C_TOKEN( crossesAt ):
112 mrModel.mofCrossesAt = rAttribs.getDouble( XML_val, 0.0 );
113 return nullptr;
114 case C_TOKEN( delete ):
115 mrModel.mbDeleted = rAttribs.getBool( XML_val, !bMSO2007Doc );
116 return nullptr;
117 case C_TOKEN( majorGridlines ):
118 return new ShapePrWrapperContext( *this, mrModel.mxMajorGridLines.create() );
119 case C_TOKEN( majorTickMark ):
120 mrModel.mnMajorTickMark = rAttribs.getToken( XML_val, bMSO2007Doc ? XML_out : XML_cross );
121 return nullptr;
122 case C_TOKEN(axPos):
123 mrModel.mnAxisPos = rAttribs.getToken( XML_val, XML_TOKEN_INVALID );
124 return nullptr;
125 case C_TOKEN( minorGridlines ):
126 return new ShapePrWrapperContext( *this, mrModel.mxMinorGridLines.create() );
127 case C_TOKEN( minorTickMark ):
128 mrModel.mnMinorTickMark = rAttribs.getToken( XML_val, bMSO2007Doc ? XML_none : XML_cross );
129 return nullptr;
130 case C_TOKEN( numFmt ):
131 mrModel.maNumberFormat.setAttributes( rAttribs );
132 return nullptr;
133 case C_TOKEN( scaling ):
134 return this;
135 case C_TOKEN( spPr ):
136 return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() );
137 case C_TOKEN( tickLblPos ):
138 mrModel.mnTickLabelPos = rAttribs.getToken( XML_val, XML_nextTo );
139 return nullptr;
140 case C_TOKEN( title ):
142 bool bVerticalDefault = mrModel.mnAxisPos == XML_l || mrModel.mnAxisPos == XML_r;
143 sal_Int32 nDefaultRotation = bVerticalDefault ? -5400000 : 0;
144 return new TitleContext( *this, mrModel.mxTitle.create(nDefaultRotation) );
146 case C_TOKEN( txPr ):
147 return new TextBodyContext( *this, mrModel.mxTextProp.create() );
149 break;
151 case C_TOKEN( scaling ):
152 switch( nElement )
154 case C_TOKEN( logBase ):
155 mrModel.mofLogBase = rAttribs.getDouble( XML_val, 0.0 );
156 return nullptr;
157 case C_TOKEN( max ):
158 mrModel.mofMax = rAttribs.getDouble( XML_val, 0.0 );
159 return nullptr;
160 case C_TOKEN( min ):
161 mrModel.mofMin = rAttribs.getDouble( XML_val, 0.0 );
162 return nullptr;
163 case C_TOKEN( orientation ):
164 mrModel.mnOrientation = rAttribs.getToken( XML_val, XML_minMax );
165 return nullptr;
167 break;
169 return nullptr;
172 CatAxisContext::CatAxisContext( ContextHandler2Helper& rParent, AxisModel& rModel ) :
173 AxisContextBase( rParent, rModel )
177 CatAxisContext::~CatAxisContext()
181 ContextHandlerRef CatAxisContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
183 bool bMSO2007Doc = getFilter().isMSO2007Document();
184 if( isRootElement() ) switch( nElement )
186 case C_TOKEN( auto ):
187 mrModel.mbAuto = rAttribs.getBool( XML_val, !bMSO2007Doc );
188 return nullptr;
189 case C_TOKEN( lblAlgn ):
190 mrModel.mnLabelAlign = rAttribs.getToken( XML_val, XML_ctr );
191 return nullptr;
192 case C_TOKEN( lblOffset ):
193 mrModel.mnLabelOffset = rAttribs.getInteger( XML_val, 100 );
194 return nullptr;
195 case C_TOKEN( noMultiLvlLbl ):
196 mrModel.mbNoMultiLevel = rAttribs.getBool( XML_val, !bMSO2007Doc );
197 return nullptr;
198 case C_TOKEN( tickLblSkip ):
199 mrModel.mnTickLabelSkip = rAttribs.getInteger( XML_val, 0 );
200 return nullptr;
201 case C_TOKEN( tickMarkSkip ):
202 mrModel.mnTickMarkSkip = rAttribs.getInteger( XML_val, 0 );
203 return nullptr;
205 return AxisContextBase::onCreateContext( nElement, rAttribs );
208 DateAxisContext::DateAxisContext( ContextHandler2Helper& rParent, AxisModel& rModel ) :
209 AxisContextBase( rParent, rModel )
213 DateAxisContext::~DateAxisContext()
217 ContextHandlerRef DateAxisContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
219 bool bMSO2007Doc = getFilter().isMSO2007Document();
220 if( isRootElement() ) switch( nElement )
222 case C_TOKEN( auto ):
223 mrModel.mbAuto = rAttribs.getBool( XML_val, !bMSO2007Doc );
224 return nullptr;
225 case C_TOKEN( baseTimeUnit ):
226 mrModel.monBaseTimeUnit = rAttribs.getToken( XML_val, XML_days );
227 return nullptr;
228 case C_TOKEN( lblOffset ):
229 mrModel.mnLabelOffset = rAttribs.getInteger( XML_val, 100 );
230 return nullptr;
231 case C_TOKEN( majorTimeUnit ):
232 mrModel.mnMajorTimeUnit = rAttribs.getToken( XML_val, XML_days );
233 return nullptr;
234 case C_TOKEN( majorUnit ):
235 mrModel.mofMajorUnit = rAttribs.getDouble( XML_val, 0.0 );
236 return nullptr;
237 case C_TOKEN( minorTimeUnit ):
238 mrModel.mnMinorTimeUnit = rAttribs.getToken( XML_val, XML_days );
239 return nullptr;
240 case C_TOKEN( minorUnit ):
241 mrModel.mofMinorUnit = rAttribs.getDouble( XML_val, 0.0 );
242 return nullptr;
244 return AxisContextBase::onCreateContext( nElement, rAttribs );
247 SerAxisContext::SerAxisContext( ContextHandler2Helper& rParent, AxisModel& rModel ) :
248 AxisContextBase( rParent, rModel )
252 SerAxisContext::~SerAxisContext()
256 ContextHandlerRef SerAxisContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
258 if( isRootElement() ) switch( nElement )
260 case C_TOKEN( tickLblSkip ):
261 mrModel.mnTickLabelSkip = rAttribs.getInteger( XML_val, 0 );
262 return nullptr;
263 case C_TOKEN( tickMarkSkip ):
264 mrModel.mnTickMarkSkip = rAttribs.getInteger( XML_val, 0 );
265 return nullptr;
267 return AxisContextBase::onCreateContext( nElement, rAttribs );
270 ValAxisContext::ValAxisContext( ContextHandler2Helper& rParent, AxisModel& rModel ) :
271 AxisContextBase( rParent, rModel )
275 ValAxisContext::~ValAxisContext()
279 ContextHandlerRef ValAxisContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
281 if( isRootElement() ) switch( nElement )
283 case C_TOKEN( crossBetween ):
284 mrModel.mnCrossBetween = rAttribs.getToken( XML_val, -1 );
285 return nullptr;
286 case C_TOKEN( dispUnits ):
287 return new AxisDispUnitsContext( *this, mrModel.mxDispUnits.create() );
288 case C_TOKEN( majorUnit ):
289 mrModel.mofMajorUnit = rAttribs.getDouble( XML_val, 0.0 );
290 return nullptr;
291 case C_TOKEN( minorUnit ):
292 mrModel.mofMinorUnit = rAttribs.getDouble( XML_val, 0.0 );
293 return nullptr;
295 return AxisContextBase::onCreateContext( nElement, rAttribs );
298 } // namespace chart
299 } // namespace drawingml
300 } // namespace oox
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */