use insert function instead of for loop
[LibreOffice.git] / oox / source / drawingml / chart / axiscontext.cxx
blob8f1defe40bea4b465f8817bcce229cbc5d4e12e3
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::drawingml::chart {
33 using ::oox::core::ContextHandlerRef;
34 using ::oox::core::ContextHandler2Helper;
36 AxisDispUnitsContext::AxisDispUnitsContext( ContextHandler2Helper& rParent, AxisDispUnitsModel& rModel ) :
37 ContextBase< AxisDispUnitsModel >( rParent, rModel )
41 AxisDispUnitsContext::~AxisDispUnitsContext()
45 ContextHandlerRef AxisDispUnitsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
47 switch( getCurrentElement() )
49 case C_TOKEN( dispUnits ):
50 switch( nElement )
52 case C_TOKEN( builtInUnit ):
53 mrModel.mnBuiltInUnit = rAttribs.getString( XML_val, u"thousands"_ustr );
54 return nullptr;
55 case C_TOKEN( custUnit ):
56 mrModel.mfCustomUnit = rAttribs.getDouble( XML_val, 0.0 );
57 return nullptr;
58 case C_TOKEN( dispUnitsLbl ):
59 return this;
61 break;
63 case C_TOKEN( dispUnitsLbl ):
64 switch( nElement )
66 case C_TOKEN( layout ):
67 return new LayoutContext( *this, mrModel.mxLayout.create() );
68 case C_TOKEN( spPr ):
69 return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() );
70 case C_TOKEN( tx ):
71 return new TextContext( *this, mrModel.mxText.create() );
72 case C_TOKEN( txPr ):
73 return new TextBodyContext( *this, mrModel.mxTextProp.create() );
75 break;
77 return nullptr;
80 AxisContextBase::AxisContextBase( ContextHandler2Helper& rParent, AxisModel& rModel ) :
81 ContextBase< AxisModel >( rParent, rModel )
85 AxisContextBase::~AxisContextBase()
89 ContextHandlerRef AxisContextBase::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
91 bool bMSO2007Doc = getFilter().isMSO2007Document();
92 switch( getCurrentElement() )
94 case C_TOKEN( catAx ):
95 case C_TOKEN( dateAx ):
96 case C_TOKEN( serAx ):
97 case C_TOKEN( valAx ):
98 switch( nElement )
100 case C_TOKEN( axId ):
101 mrModel.mnAxisId = rAttribs.getInteger( XML_val, -1 );
102 return nullptr;
103 case C_TOKEN( crossAx ):
104 mrModel.mnCrossAxisId = rAttribs.getInteger( XML_val, -1 );
105 return nullptr;
106 case C_TOKEN( crosses ):
107 mrModel.mnCrossMode = rAttribs.getToken( XML_val, XML_autoZero );
108 return nullptr;
109 case C_TOKEN( crossesAt ):
110 mrModel.mofCrossesAt = rAttribs.getDouble( XML_val, 0.0 );
111 return nullptr;
112 case C_TOKEN( delete ):
113 mrModel.mbDeleted = rAttribs.getBool( XML_val, !bMSO2007Doc );
114 return nullptr;
115 case C_TOKEN( majorGridlines ):
116 return new ShapePrWrapperContext( *this, mrModel.mxMajorGridLines.create() );
117 case C_TOKEN( majorTickMark ):
118 mrModel.mnMajorTickMark = rAttribs.getToken( XML_val, bMSO2007Doc ? XML_out : XML_cross );
119 return nullptr;
120 case C_TOKEN(axPos):
121 mrModel.mnAxisPos = rAttribs.getToken( XML_val, XML_TOKEN_INVALID );
122 return nullptr;
123 case C_TOKEN( minorGridlines ):
124 return new ShapePrWrapperContext( *this, mrModel.mxMinorGridLines.create() );
125 case C_TOKEN( minorTickMark ):
126 mrModel.mnMinorTickMark = rAttribs.getToken( XML_val, bMSO2007Doc ? XML_none : XML_cross );
127 return nullptr;
128 case C_TOKEN( numFmt ):
129 mrModel.maNumberFormat.setAttributes( rAttribs );
130 return nullptr;
131 case C_TOKEN( scaling ):
132 return this;
133 case C_TOKEN( spPr ):
134 return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() );
135 case C_TOKEN( tickLblPos ):
136 mrModel.mnTickLabelPos = rAttribs.getToken( XML_val, XML_nextTo );
137 return nullptr;
138 case C_TOKEN( title ):
140 bool bVerticalDefault = mrModel.mnAxisPos == XML_l || mrModel.mnAxisPos == XML_r;
141 sal_Int32 nDefaultRotation = bVerticalDefault ? -5400000 : 0;
142 return new TitleContext( *this, mrModel.mxTitle.create(nDefaultRotation) );
144 case C_TOKEN( txPr ):
145 return new TextBodyContext( *this, mrModel.mxTextProp.create() );
147 break;
149 case C_TOKEN( scaling ):
150 switch( nElement )
152 case C_TOKEN( logBase ):
153 mrModel.mofLogBase = rAttribs.getDouble( XML_val, 0.0 );
154 return nullptr;
155 case C_TOKEN( max ):
156 mrModel.mofMax = rAttribs.getDouble( XML_val, 0.0 );
157 return nullptr;
158 case C_TOKEN( min ):
159 mrModel.mofMin = rAttribs.getDouble( XML_val, 0.0 );
160 return nullptr;
161 case C_TOKEN( orientation ):
162 mrModel.mnOrientation = rAttribs.getToken( XML_val, XML_minMax );
163 return nullptr;
165 break;
167 return nullptr;
170 CatAxisContext::CatAxisContext( ContextHandler2Helper& rParent, AxisModel& rModel ) :
171 AxisContextBase( rParent, rModel )
175 CatAxisContext::~CatAxisContext()
179 ContextHandlerRef CatAxisContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
181 bool bMSO2007Doc = getFilter().isMSO2007Document();
182 if( isRootElement() ) switch( nElement )
184 case C_TOKEN( auto ):
185 mrModel.mbAuto = rAttribs.getBool( XML_val, !bMSO2007Doc );
186 return nullptr;
187 case C_TOKEN( lblAlgn ):
188 mrModel.mnLabelAlign = rAttribs.getToken( XML_val, XML_ctr );
189 return nullptr;
190 case C_TOKEN( lblOffset ):
191 mrModel.mnLabelOffset = rAttribs.getInteger( XML_val, 100 );
192 return nullptr;
193 case C_TOKEN( noMultiLvlLbl ):
194 mrModel.mbNoMultiLevel = rAttribs.getBool( XML_val, !bMSO2007Doc );
195 return nullptr;
196 case C_TOKEN( tickLblSkip ):
197 mrModel.mnTickLabelSkip = rAttribs.getInteger( XML_val, 0 );
198 return nullptr;
199 case C_TOKEN( tickMarkSkip ):
200 mrModel.mnTickMarkSkip = rAttribs.getInteger( XML_val, 0 );
201 return nullptr;
203 return AxisContextBase::onCreateContext( nElement, rAttribs );
206 DateAxisContext::DateAxisContext( ContextHandler2Helper& rParent, AxisModel& rModel ) :
207 AxisContextBase( rParent, rModel )
211 DateAxisContext::~DateAxisContext()
215 ContextHandlerRef DateAxisContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
217 bool bMSO2007Doc = getFilter().isMSO2007Document();
218 if( isRootElement() ) switch( nElement )
220 case C_TOKEN( auto ):
221 mrModel.mbAuto = rAttribs.getBool( XML_val, !bMSO2007Doc );
222 return nullptr;
223 case C_TOKEN( baseTimeUnit ):
224 mrModel.monBaseTimeUnit = rAttribs.getToken( XML_val, XML_days );
225 return nullptr;
226 case C_TOKEN( lblOffset ):
227 mrModel.mnLabelOffset = rAttribs.getInteger( XML_val, 100 );
228 return nullptr;
229 case C_TOKEN( majorTimeUnit ):
230 mrModel.mnMajorTimeUnit = rAttribs.getToken( XML_val, XML_days );
231 return nullptr;
232 case C_TOKEN( majorUnit ):
233 mrModel.mofMajorUnit = rAttribs.getDouble( XML_val, 0.0 );
234 return nullptr;
235 case C_TOKEN( minorTimeUnit ):
236 mrModel.mnMinorTimeUnit = rAttribs.getToken( XML_val, XML_days );
237 return nullptr;
238 case C_TOKEN( minorUnit ):
239 mrModel.mofMinorUnit = rAttribs.getDouble( XML_val, 0.0 );
240 return nullptr;
242 return AxisContextBase::onCreateContext( nElement, rAttribs );
245 SerAxisContext::SerAxisContext( ContextHandler2Helper& rParent, AxisModel& rModel ) :
246 AxisContextBase( rParent, rModel )
250 SerAxisContext::~SerAxisContext()
254 ContextHandlerRef SerAxisContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
256 if( isRootElement() ) switch( nElement )
258 case C_TOKEN( tickLblSkip ):
259 mrModel.mnTickLabelSkip = rAttribs.getInteger( XML_val, 0 );
260 return nullptr;
261 case C_TOKEN( tickMarkSkip ):
262 mrModel.mnTickMarkSkip = rAttribs.getInteger( XML_val, 0 );
263 return nullptr;
265 return AxisContextBase::onCreateContext( nElement, rAttribs );
268 ValAxisContext::ValAxisContext( ContextHandler2Helper& rParent, AxisModel& rModel ) :
269 AxisContextBase( rParent, rModel )
273 ValAxisContext::~ValAxisContext()
277 ContextHandlerRef ValAxisContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
279 if( isRootElement() ) switch( nElement )
281 case C_TOKEN( crossBetween ):
282 mrModel.mnCrossBetween = rAttribs.getToken( XML_val, -1 );
283 return nullptr;
284 case C_TOKEN( dispUnits ):
285 return new AxisDispUnitsContext( *this, mrModel.mxDispUnits.create() );
286 case C_TOKEN( majorUnit ):
287 mrModel.mofMajorUnit = rAttribs.getDouble( XML_val, 0.0 );
288 return nullptr;
289 case C_TOKEN( minorUnit ):
290 mrModel.mofMinorUnit = rAttribs.getDouble( XML_val, 0.0 );
291 return nullptr;
293 return AxisContextBase::onCreateContext( nElement, rAttribs );
296 } // namespace oox::drawingml::chart
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */