Update ooo320-m1
[ooovba.git] / oox / source / drawingml / chart / datasourcecontext.cxx
blob56d35992892cb683c5a9264daea1c12937988d72
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: datasourcecontext.cxx,v $
11 * $Revision: 1.2 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "oox/drawingml/chart/datasourcecontext.hxx"
33 #include "oox/drawingml/chart/datasourcemodel.hxx"
35 using ::rtl::OUString;
36 using ::oox::core::ContextHandler2Helper;
37 using ::oox::core::ContextHandlerRef;
39 namespace oox {
40 namespace drawingml {
41 namespace chart {
43 // ============================================================================
45 DoubleSequenceContext::DoubleSequenceContext( ContextHandler2Helper& rParent, DataSequenceModel& rModel ) :
46 DataSequenceContextBase( rParent, rModel ),
47 mnPtIndex( -1 )
51 DoubleSequenceContext::~DoubleSequenceContext()
55 ContextHandlerRef DoubleSequenceContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
57 switch( getCurrentElement() )
59 case C_TOKEN( numRef ):
60 switch( nElement )
62 case C_TOKEN( f ):
63 case C_TOKEN( numCache ):
64 return this;
66 break;
68 case C_TOKEN( numCache ):
69 case C_TOKEN( numLit ):
70 switch( nElement )
72 case C_TOKEN( formatCode ):
73 return this;
74 case C_TOKEN( ptCount ):
75 mrModel.mnPointCount = rAttribs.getInteger( XML_val, -1 );
76 return 0;
77 case C_TOKEN( pt ):
78 mnPtIndex = rAttribs.getInteger( XML_idx, -1 );
79 return this;
81 break;
83 case C_TOKEN( pt ):
84 switch( nElement )
86 case C_TOKEN( v ):
87 return this;
89 break;
91 return 0;
94 void DoubleSequenceContext::onEndElement( const OUString& rChars )
96 switch( getCurrentElement() )
98 case C_TOKEN( f ):
99 mrModel.maFormula = rChars;
100 break;
101 case C_TOKEN( formatCode ):
102 mrModel.maFormatCode = rChars;
103 break;
104 case C_TOKEN( v ):
105 if( mnPtIndex >= 0 )
106 mrModel.maData[ mnPtIndex ] <<= rChars.toDouble();
107 break;
111 // ============================================================================
113 StringSequenceContext::StringSequenceContext( ContextHandler2Helper& rParent, DataSequenceModel& rModel ) :
114 DataSequenceContextBase( rParent, rModel )
118 StringSequenceContext::~StringSequenceContext()
122 ContextHandlerRef StringSequenceContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
124 switch( getCurrentElement() )
126 case C_TOKEN( multiLvlStrRef ):
127 switch( nElement )
129 case C_TOKEN( f ):
130 return this;
132 break;
134 case C_TOKEN( strRef ):
135 switch( nElement )
137 case C_TOKEN( f ):
138 case C_TOKEN( strCache ):
139 return this;
141 break;
143 case C_TOKEN( strCache ):
144 case C_TOKEN( strLit ):
145 switch( nElement )
147 case C_TOKEN( ptCount ):
148 mrModel.mnPointCount = rAttribs.getInteger( XML_val, -1 );
149 return 0;
150 case C_TOKEN( pt ):
151 mnPtIndex = rAttribs.getInteger( XML_idx, -1 );
152 return this;
154 break;
156 case C_TOKEN( pt ):
157 switch( nElement )
159 case C_TOKEN( v ):
160 return this;
162 break;
164 return 0;
167 void StringSequenceContext::onEndElement( const OUString& rChars )
169 switch( getCurrentElement() )
171 case C_TOKEN( f ):
172 mrModel.maFormula = rChars;
173 break;
174 case C_TOKEN( v ):
175 if( mnPtIndex >= 0 )
176 mrModel.maData[ mnPtIndex ] <<= rChars;
177 break;
181 // ============================================================================
183 DataSourceContext::DataSourceContext( ContextHandler2Helper& rParent, DataSourceModel& rModel ) :
184 ContextBase< DataSourceModel >( rParent, rModel )
188 DataSourceContext::~DataSourceContext()
192 ContextHandlerRef DataSourceContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
194 switch( getCurrentElement() )
196 case C_TOKEN( cat ):
197 case C_TOKEN( xVal ):
198 switch( nElement )
200 case C_TOKEN( multiLvlStrRef ):
201 case C_TOKEN( strLit ):
202 case C_TOKEN( strRef ):
203 OSL_ENSURE( !mrModel.mxDataSeq, "DataSourceContext::onCreateContext - multiple data sequences" );
204 return new StringSequenceContext( *this, mrModel.mxDataSeq.create() );
206 case C_TOKEN( numLit ):
207 case C_TOKEN( numRef ):
208 OSL_ENSURE( !mrModel.mxDataSeq, "DataSourceContext::onCreateContext - multiple data sequences" );
209 return new DoubleSequenceContext( *this, mrModel.mxDataSeq.create() );
211 break;
213 case C_TOKEN( plus ):
214 case C_TOKEN( minus ):
215 case C_TOKEN( val ):
216 case C_TOKEN( yVal ):
217 case C_TOKEN( bubbleSize ):
218 switch( nElement )
220 case C_TOKEN( numLit ):
221 case C_TOKEN( numRef ):
222 OSL_ENSURE( !mrModel.mxDataSeq, "DataSourceContext::onCreateContext - multiple data sequences" );
223 return new DoubleSequenceContext( *this, mrModel.mxDataSeq.create() );
225 break;
227 return 0;
230 // ============================================================================
232 } // namespace chart
233 } // namespace drawingml
234 } // namespace oox