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>
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
):
54 case C_TOKEN( builtInUnit
):
55 mrModel
.mnBuiltInUnit
= rAttribs
.getString( XML_val
, "thousands" );
57 case C_TOKEN( custUnit
):
58 mrModel
.mfCustomUnit
= rAttribs
.getDouble( XML_val
, 0.0 );
60 case C_TOKEN( dispUnitsLbl
):
65 case C_TOKEN( dispUnitsLbl
):
68 case C_TOKEN( layout
):
69 return new LayoutContext( *this, mrModel
.mxLayout
.create() );
71 return new ShapePropertiesContext( *this, mrModel
.mxShapeProp
.create() );
73 return new TextContext( *this, mrModel
.mxText
.create() );
75 return new TextBodyContext( *this, mrModel
.mxTextProp
.create() );
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
):
102 case C_TOKEN( axId
):
103 mrModel
.mnAxisId
= rAttribs
.getInteger( XML_val
, -1 );
105 case C_TOKEN( crossAx
):
106 mrModel
.mnCrossAxisId
= rAttribs
.getInteger( XML_val
, -1 );
108 case C_TOKEN( crosses
):
109 mrModel
.mnCrossMode
= rAttribs
.getToken( XML_val
, XML_autoZero
);
111 case C_TOKEN( crossesAt
):
112 mrModel
.mofCrossesAt
= rAttribs
.getDouble( XML_val
, 0.0 );
114 case C_TOKEN( delete ):
115 mrModel
.mbDeleted
= rAttribs
.getBool( XML_val
, !bMSO2007Doc
);
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
);
123 mrModel
.mnAxisPos
= rAttribs
.getToken( XML_val
, XML_TOKEN_INVALID
);
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
);
130 case C_TOKEN( numFmt
):
131 mrModel
.maNumberFormat
.setAttributes( rAttribs
);
133 case C_TOKEN( scaling
):
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
);
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() );
151 case C_TOKEN( scaling
):
154 case C_TOKEN( logBase
):
155 mrModel
.mofLogBase
= rAttribs
.getDouble( XML_val
, 0.0 );
158 mrModel
.mofMax
= rAttribs
.getDouble( XML_val
, 0.0 );
161 mrModel
.mofMin
= rAttribs
.getDouble( XML_val
, 0.0 );
163 case C_TOKEN( orientation
):
164 mrModel
.mnOrientation
= rAttribs
.getToken( XML_val
, XML_minMax
);
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
);
189 case C_TOKEN( lblAlgn
):
190 mrModel
.mnLabelAlign
= rAttribs
.getToken( XML_val
, XML_ctr
);
192 case C_TOKEN( lblOffset
):
193 mrModel
.mnLabelOffset
= rAttribs
.getInteger( XML_val
, 100 );
195 case C_TOKEN( noMultiLvlLbl
):
196 mrModel
.mbNoMultiLevel
= rAttribs
.getBool( XML_val
, !bMSO2007Doc
);
198 case C_TOKEN( tickLblSkip
):
199 mrModel
.mnTickLabelSkip
= rAttribs
.getInteger( XML_val
, 0 );
201 case C_TOKEN( tickMarkSkip
):
202 mrModel
.mnTickMarkSkip
= rAttribs
.getInteger( XML_val
, 0 );
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
);
225 case C_TOKEN( baseTimeUnit
):
226 mrModel
.monBaseTimeUnit
= rAttribs
.getToken( XML_val
, XML_days
);
228 case C_TOKEN( lblOffset
):
229 mrModel
.mnLabelOffset
= rAttribs
.getInteger( XML_val
, 100 );
231 case C_TOKEN( majorTimeUnit
):
232 mrModel
.mnMajorTimeUnit
= rAttribs
.getToken( XML_val
, XML_days
);
234 case C_TOKEN( majorUnit
):
235 mrModel
.mofMajorUnit
= rAttribs
.getDouble( XML_val
, 0.0 );
237 case C_TOKEN( minorTimeUnit
):
238 mrModel
.mnMinorTimeUnit
= rAttribs
.getToken( XML_val
, XML_days
);
240 case C_TOKEN( minorUnit
):
241 mrModel
.mofMinorUnit
= rAttribs
.getDouble( XML_val
, 0.0 );
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 );
263 case C_TOKEN( tickMarkSkip
):
264 mrModel
.mnTickMarkSkip
= rAttribs
.getInteger( XML_val
, 0 );
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
, XML_between
);
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 );
291 case C_TOKEN( minorUnit
):
292 mrModel
.mofMinorUnit
= rAttribs
.getDouble( XML_val
, 0.0 );
295 return AxisContextBase::onCreateContext( nElement
, rAttribs
);
299 } // namespace drawingml
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */