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/.
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
):
52 case C_TOKEN( builtInUnit
):
53 mrModel
.mnBuiltInUnit
= rAttribs
.getString( XML_val
, u
"thousands"_ustr
);
55 case C_TOKEN( custUnit
):
56 mrModel
.mfCustomUnit
= rAttribs
.getDouble( XML_val
, 0.0 );
58 case C_TOKEN( dispUnitsLbl
):
63 case C_TOKEN( dispUnitsLbl
):
66 case C_TOKEN( layout
):
67 return new LayoutContext( *this, mrModel
.mxLayout
.create() );
69 return new ShapePropertiesContext( *this, mrModel
.mxShapeProp
.create() );
71 return new TextContext( *this, mrModel
.mxText
.create() );
73 return new TextBodyContext( *this, mrModel
.mxTextProp
.create() );
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
):
100 case C_TOKEN( axId
):
101 mrModel
.mnAxisId
= rAttribs
.getInteger( XML_val
, -1 );
103 case C_TOKEN( crossAx
):
104 mrModel
.mnCrossAxisId
= rAttribs
.getInteger( XML_val
, -1 );
106 case C_TOKEN( crosses
):
107 mrModel
.mnCrossMode
= rAttribs
.getToken( XML_val
, XML_autoZero
);
109 case C_TOKEN( crossesAt
):
110 mrModel
.mofCrossesAt
= rAttribs
.getDouble( XML_val
, 0.0 );
112 case C_TOKEN( delete ):
113 mrModel
.mbDeleted
= rAttribs
.getBool( XML_val
, !bMSO2007Doc
);
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
);
121 mrModel
.mnAxisPos
= rAttribs
.getToken( XML_val
, XML_TOKEN_INVALID
);
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
);
128 case C_TOKEN( numFmt
):
129 mrModel
.maNumberFormat
.setAttributes( rAttribs
);
131 case C_TOKEN( scaling
):
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
);
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() );
149 case C_TOKEN( scaling
):
152 case C_TOKEN( logBase
):
153 mrModel
.mofLogBase
= rAttribs
.getDouble( XML_val
, 0.0 );
156 mrModel
.mofMax
= rAttribs
.getDouble( XML_val
, 0.0 );
159 mrModel
.mofMin
= rAttribs
.getDouble( XML_val
, 0.0 );
161 case C_TOKEN( orientation
):
162 mrModel
.mnOrientation
= rAttribs
.getToken( XML_val
, XML_minMax
);
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
);
187 case C_TOKEN( lblAlgn
):
188 mrModel
.mnLabelAlign
= rAttribs
.getToken( XML_val
, XML_ctr
);
190 case C_TOKEN( lblOffset
):
191 mrModel
.mnLabelOffset
= rAttribs
.getInteger( XML_val
, 100 );
193 case C_TOKEN( noMultiLvlLbl
):
194 mrModel
.mbNoMultiLevel
= rAttribs
.getBool( XML_val
, !bMSO2007Doc
);
196 case C_TOKEN( tickLblSkip
):
197 mrModel
.mnTickLabelSkip
= rAttribs
.getInteger( XML_val
, 0 );
199 case C_TOKEN( tickMarkSkip
):
200 mrModel
.mnTickMarkSkip
= rAttribs
.getInteger( XML_val
, 0 );
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
);
223 case C_TOKEN( baseTimeUnit
):
224 mrModel
.monBaseTimeUnit
= rAttribs
.getToken( XML_val
, XML_days
);
226 case C_TOKEN( lblOffset
):
227 mrModel
.mnLabelOffset
= rAttribs
.getInteger( XML_val
, 100 );
229 case C_TOKEN( majorTimeUnit
):
230 mrModel
.mnMajorTimeUnit
= rAttribs
.getToken( XML_val
, XML_days
);
232 case C_TOKEN( majorUnit
):
233 mrModel
.mofMajorUnit
= rAttribs
.getDouble( XML_val
, 0.0 );
235 case C_TOKEN( minorTimeUnit
):
236 mrModel
.mnMinorTimeUnit
= rAttribs
.getToken( XML_val
, XML_days
);
238 case C_TOKEN( minorUnit
):
239 mrModel
.mofMinorUnit
= rAttribs
.getDouble( XML_val
, 0.0 );
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 );
261 case C_TOKEN( tickMarkSkip
):
262 mrModel
.mnTickMarkSkip
= rAttribs
.getInteger( XML_val
, 0 );
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 );
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 );
289 case C_TOKEN( minorUnit
):
290 mrModel
.mofMinorUnit
= rAttribs
.getDouble( XML_val
, 0.0 );
293 return AxisContextBase::onCreateContext( nElement
, rAttribs
);
296 } // namespace oox::drawingml::chart
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */