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