1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "oox/drawingml/chart/axiscontext.hxx"
25 
26 #include "oox/drawingml/shapepropertiescontext.hxx"
27 #include "oox/drawingml/textbodycontext.hxx"
28 #include "oox/drawingml/chart/axismodel.hxx"
29 #include "oox/drawingml/chart/titlecontext.hxx"
30 
31 namespace oox {
32 namespace drawingml {
33 namespace chart {
34 
35 // ============================================================================
36 
37 using ::oox::core::ContextHandlerRef;
38 using ::oox::core::ContextHandler2Helper;
39 using ::rtl::OUString;
40 
41 // ============================================================================
42 
AxisDispUnitsContext(ContextHandler2Helper & rParent,AxisDispUnitsModel & rModel)43 AxisDispUnitsContext::AxisDispUnitsContext( ContextHandler2Helper& rParent, AxisDispUnitsModel& rModel ) :
44     ContextBase< AxisDispUnitsModel >( rParent, rModel )
45 {
46 }
47 
~AxisDispUnitsContext()48 AxisDispUnitsContext::~AxisDispUnitsContext()
49 {
50 }
51 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)52 ContextHandlerRef AxisDispUnitsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
53 {
54     switch( getCurrentElement() )
55     {
56         case C_TOKEN( dispUnits ):
57             switch( nElement )
58             {
59                 case C_TOKEN( builtInUnit ):
60                     mrModel.mnBuiltInUnit = rAttribs.getToken( XML_val, XML_thousands );
61                     return 0;
62                 case C_TOKEN( custUnit ):
63                     mrModel.mfCustomUnit = rAttribs.getDouble( XML_val, 0.0 );
64                     return 0;
65                 case C_TOKEN( dispUnitsLbl ):
66                     return this;
67             }
68         break;
69 
70         case C_TOKEN( dispUnitsLbl ):
71             switch( nElement )
72             {
73                 case C_TOKEN( layout ):
74                     return new LayoutContext( *this, mrModel.mxLayout.create() );
75                 case C_TOKEN( spPr ):
76                     return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() );
77                 case C_TOKEN( tx ):
78                     return new TextContext( *this, mrModel.mxText.create() );
79                 case C_TOKEN( txPr ):
80                     return new TextBodyContext( *this, mrModel.mxTextProp.create() );
81             }
82         break;
83     }
84     return 0;
85 }
86 
87 // ============================================================================
88 
AxisContextBase(ContextHandler2Helper & rParent,AxisModel & rModel)89 AxisContextBase::AxisContextBase( ContextHandler2Helper& rParent, AxisModel& rModel ) :
90     ContextBase< AxisModel >( rParent, rModel )
91 {
92 }
93 
~AxisContextBase()94 AxisContextBase::~AxisContextBase()
95 {
96 }
97 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)98 ContextHandlerRef AxisContextBase::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
99 {
100     switch( getCurrentElement() )
101     {
102         case C_TOKEN( catAx ):
103         case C_TOKEN( dateAx ):
104         case C_TOKEN( serAx ):
105         case C_TOKEN( valAx ):
106             switch( nElement )
107             {
108                 case C_TOKEN( axId ):
109                     mrModel.mnAxisId = rAttribs.getInteger( XML_val, -1 );
110                     return 0;
111                 case C_TOKEN( crossAx ):
112                     mrModel.mnCrossAxisId = rAttribs.getInteger( XML_val, -1 );
113                     return 0;
114                 case C_TOKEN( crosses ):
115                     mrModel.mnCrossMode = rAttribs.getToken( XML_val, XML_autoZero );
116                     return 0;
117                 case C_TOKEN( crossesAt ):
118                     mrModel.mofCrossesAt = rAttribs.getDouble( XML_val, 0.0 );
119                     return 0;
120                 case C_TOKEN( delete ):
121                     // default is 'false', not 'true' as specified
122                     mrModel.mbDeleted = rAttribs.getBool( XML_val, false );
123                     return 0;
124                 case C_TOKEN( majorGridlines ):
125                     return new ShapePrWrapperContext( *this, mrModel.mxMajorGridLines.create() );
126                 case C_TOKEN( majorTickMark ):
127                     // default is 'out', not 'cross' as specified
128                     mrModel.mnMajorTickMark = rAttribs.getToken( XML_val, XML_out );
129                     return 0;
130                 case C_TOKEN( minorGridlines ):
131                     return new ShapePrWrapperContext( *this, mrModel.mxMinorGridLines.create() );
132                 case C_TOKEN( minorTickMark ):
133                     // default is 'none', not 'cross' as specified
134                     mrModel.mnMinorTickMark = rAttribs.getToken( XML_val, XML_none );
135                     return 0;
136                 case C_TOKEN( numFmt ):
137                     mrModel.maNumberFormat.setAttributes( rAttribs );
138                     return 0;
139                 case C_TOKEN( scaling ):
140                     return this;
141                 case C_TOKEN( spPr ):
142                     return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() );
143                 case C_TOKEN( tickLblPos ):
144                     mrModel.mnTickLabelPos = rAttribs.getToken( XML_val, XML_nextTo );
145                     return 0;
146                 case C_TOKEN( title ):
147                     return new TitleContext( *this, mrModel.mxTitle.create() );
148                 case C_TOKEN( txPr ):
149                     return new TextBodyContext( *this, mrModel.mxTextProp.create() );
150             }
151         break;
152 
153         case C_TOKEN( scaling ):
154             switch( nElement )
155             {
156                 case C_TOKEN( logBase ):
157                     mrModel.mofLogBase = rAttribs.getDouble( XML_val, 0.0 );
158                     return 0;
159                 case C_TOKEN( max ):
160                     mrModel.mofMax = rAttribs.getDouble( XML_val, 0.0 );
161                     return 0;
162                 case C_TOKEN( min ):
163                     mrModel.mofMin = rAttribs.getDouble( XML_val, 0.0 );
164                     return 0;
165                 case C_TOKEN( orientation ):
166                     mrModel.mnOrientation = rAttribs.getToken( XML_val, XML_minMax );
167                     return 0;
168             }
169         break;
170     }
171     return 0;
172 }
173 
174 // ============================================================================
175 
CatAxisContext(ContextHandler2Helper & rParent,AxisModel & rModel)176 CatAxisContext::CatAxisContext( ContextHandler2Helper& rParent, AxisModel& rModel ) :
177     AxisContextBase( rParent, rModel )
178 {
179 }
180 
~CatAxisContext()181 CatAxisContext::~CatAxisContext()
182 {
183 }
184 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)185 ContextHandlerRef CatAxisContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
186 {
187     if( isRootElement() ) switch( nElement )
188     {
189         case C_TOKEN( auto ):
190             // default is 'false', not 'true' as specified
191             mrModel.mbAuto = rAttribs.getBool( XML_val, false );
192             return 0;
193         case C_TOKEN( axPos ):
194             mrModel.mnAxisPos = rAttribs.getToken( XML_val, XML_TOKEN_INVALID );
195             return 0;
196         case C_TOKEN( lblAlgn ):
197             mrModel.mnLabelAlign = rAttribs.getToken( XML_val, XML_ctr );
198             return 0;
199         case C_TOKEN( lblOffset ):
200             mrModel.mnLabelOffset = rAttribs.getInteger( XML_val, 100 );
201             return 0;
202         case C_TOKEN( noMultiLvlLbl ):
203             // default is 'false', not 'true' as specified
204             mrModel.mbNoMultiLevel = rAttribs.getBool( XML_val, false );
205             return 0;
206         case C_TOKEN( tickLblSkip ):
207             mrModel.mnTickLabelSkip = rAttribs.getInteger( XML_val, 0 );
208             return 0;
209         case C_TOKEN( tickMarkSkip ):
210             mrModel.mnTickMarkSkip = rAttribs.getInteger( XML_val, 0 );
211             return 0;
212     }
213     return AxisContextBase::onCreateContext( nElement, rAttribs );
214 }
215 
216 // ============================================================================
217 
DateAxisContext(ContextHandler2Helper & rParent,AxisModel & rModel)218 DateAxisContext::DateAxisContext( ContextHandler2Helper& rParent, AxisModel& rModel ) :
219     AxisContextBase( rParent, rModel )
220 {
221 }
222 
~DateAxisContext()223 DateAxisContext::~DateAxisContext()
224 {
225 }
226 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)227 ContextHandlerRef DateAxisContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
228 {
229     if( isRootElement() ) switch( nElement )
230     {
231         case C_TOKEN( auto ):
232             // default is 'false', not 'true' as specified
233             mrModel.mbAuto = rAttribs.getBool( XML_val, false );
234             return 0;
235         case C_TOKEN( baseTimeUnit ):
236             mrModel.monBaseTimeUnit = rAttribs.getToken( XML_val, XML_days );
237             return 0;
238         case C_TOKEN( lblOffset ):
239             mrModel.mnLabelOffset = rAttribs.getInteger( XML_val, 100 );
240             return 0;
241         case C_TOKEN( majorTimeUnit ):
242             mrModel.mnMajorTimeUnit = rAttribs.getToken( XML_val, XML_days );
243             return 0;
244         case C_TOKEN( majorUnit ):
245             mrModel.mofMajorUnit = rAttribs.getDouble( XML_val, 0.0 );
246             return 0;
247         case C_TOKEN( minorTimeUnit ):
248             mrModel.mnMinorTimeUnit = rAttribs.getToken( XML_val, XML_days );
249             return 0;
250         case C_TOKEN( minorUnit ):
251             mrModel.mofMinorUnit = rAttribs.getDouble( XML_val, 0.0 );
252             return 0;
253     }
254     return AxisContextBase::onCreateContext( nElement, rAttribs );
255 }
256 
257 // ============================================================================
258 
SerAxisContext(ContextHandler2Helper & rParent,AxisModel & rModel)259 SerAxisContext::SerAxisContext( ContextHandler2Helper& rParent, AxisModel& rModel ) :
260     AxisContextBase( rParent, rModel )
261 {
262 }
263 
~SerAxisContext()264 SerAxisContext::~SerAxisContext()
265 {
266 }
267 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)268 ContextHandlerRef SerAxisContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
269 {
270     if( isRootElement() ) switch( nElement )
271     {
272         case C_TOKEN( tickLblSkip ):
273             mrModel.mnTickLabelSkip = rAttribs.getInteger( XML_val, 0 );
274             return 0;
275         case C_TOKEN( tickMarkSkip ):
276             mrModel.mnTickMarkSkip = rAttribs.getInteger( XML_val, 0 );
277             return 0;
278     }
279     return AxisContextBase::onCreateContext( nElement, rAttribs );
280 }
281 
282 // ============================================================================
283 
ValAxisContext(ContextHandler2Helper & rParent,AxisModel & rModel)284 ValAxisContext::ValAxisContext( ContextHandler2Helper& rParent, AxisModel& rModel ) :
285     AxisContextBase( rParent, rModel )
286 {
287 }
288 
~ValAxisContext()289 ValAxisContext::~ValAxisContext()
290 {
291 }
292 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)293 ContextHandlerRef ValAxisContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
294 {
295     if( isRootElement() ) switch( nElement )
296     {
297         case C_TOKEN( crossBetween ):
298             mrModel.mnCrossBetween = rAttribs.getToken( XML_val, XML_between );
299             return 0;
300         case C_TOKEN( dispUnits ):
301             return new AxisDispUnitsContext( *this, mrModel.mxDispUnits.create() );
302         case C_TOKEN( majorUnit ):
303             mrModel.mofMajorUnit = rAttribs.getDouble( XML_val, 0.0 );
304             return 0;
305         case C_TOKEN( minorUnit ):
306             mrModel.mofMinorUnit = rAttribs.getDouble( XML_val, 0.0 );
307             return 0;
308     }
309     return AxisContextBase::onCreateContext( nElement, rAttribs );
310 }
311 
312 // ============================================================================
313 
314 } // namespace chart
315 } // namespace drawingml
316 } // namespace oox
317