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/titlecontext.hxx"
25
26 #include "oox/drawingml/shapepropertiescontext.hxx"
27 #include "oox/drawingml/textbodycontext.hxx"
28 #include "oox/drawingml/chart/datasourcecontext.hxx"
29 #include "oox/drawingml/chart/titlemodel.hxx"
30
31 namespace oox {
32 namespace drawingml {
33 namespace chart {
34
35 // ============================================================================
36
37 using ::oox::core::ContextHandler2Helper;
38 using ::oox::core::ContextHandlerRef;
39 using ::rtl::OUString;
40
41 // ============================================================================
42
TextContext(ContextHandler2Helper & rParent,TextModel & rModel)43 TextContext::TextContext( ContextHandler2Helper& rParent, TextModel& rModel ) :
44 ContextBase< TextModel >( rParent, rModel )
45 {
46 }
47
~TextContext()48 TextContext::~TextContext()
49 {
50 }
51
onCreateContext(sal_Int32 nElement,const AttributeList &)52 ContextHandlerRef TextContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
53 {
54 // this context handler is used for <c:tx> and embedded <c:v> elements
55 if( isCurrentElement( C_TOKEN( tx ) ) ) switch( nElement )
56 {
57 case C_TOKEN( rich ):
58 return new TextBodyContext( *this, mrModel.mxTextBody.create() );
59
60 case C_TOKEN( strRef ):
61 OSL_ENSURE( !mrModel.mxDataSeq, "TextContext::onCreateContext - multiple data sequences" );
62 return new StringSequenceContext( *this, mrModel.mxDataSeq.create() );
63
64 case C_TOKEN( v ):
65 OSL_ENSURE( !mrModel.mxDataSeq, "TextContext::onCreateContext - multiple data sequences" );
66 return this; // collect value in onCharacters()
67 }
68 return 0;
69 }
70
onCharacters(const OUString & rChars)71 void TextContext::onCharacters( const OUString& rChars )
72 {
73 // store as single string sequence element
74 if( isCurrentElement( C_TOKEN( v ) ) )
75 mrModel.mxDataSeq.create().maData[ 0 ] <<= rChars;
76 }
77
78 // ============================================================================
79
TitleContext(ContextHandler2Helper & rParent,TitleModel & rModel)80 TitleContext::TitleContext( ContextHandler2Helper& rParent, TitleModel& rModel ) :
81 ContextBase< TitleModel >( rParent, rModel )
82 {
83 }
84
~TitleContext()85 TitleContext::~TitleContext()
86 {
87 }
88
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)89 ContextHandlerRef TitleContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
90 {
91 // this context handler is used for <c:title> only
92 switch( nElement )
93 {
94 case C_TOKEN( layout ):
95 return new LayoutContext( *this, mrModel.mxLayout.create() );
96
97 case C_TOKEN( overlay ):
98 // default is 'false', not 'true' as specified
99 mrModel.mbOverlay = rAttribs.getBool( XML_val, false );
100 return 0;
101
102 case C_TOKEN( spPr ):
103 return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() );
104
105 case C_TOKEN( tx ):
106 return new TextContext( *this, mrModel.mxText.create() );
107
108 case C_TOKEN( txPr ):
109 return new TextBodyContext( *this, mrModel.mxTextProp.create() );
110 }
111 return 0;
112 }
113
114 // ============================================================================
115
LegendContext(ContextHandler2Helper & rParent,LegendModel & rModel)116 LegendContext::LegendContext( ContextHandler2Helper& rParent, LegendModel& rModel ) :
117 ContextBase< LegendModel >( rParent, rModel )
118 {
119 }
120
~LegendContext()121 LegendContext::~LegendContext()
122 {
123 }
124
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)125 ContextHandlerRef LegendContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
126 {
127 // this context handler is used for <c:legend> only
128 switch( nElement )
129 {
130 case C_TOKEN( layout ):
131 return new LayoutContext( *this, mrModel.mxLayout.create() );
132
133 case C_TOKEN( legendPos ):
134 mrModel.mnPosition = rAttribs.getToken( XML_val, XML_r );
135 return 0;
136
137 case C_TOKEN( overlay ):
138 // default is 'false', not 'true' as specified
139 mrModel.mbOverlay = rAttribs.getBool( XML_val, false );
140 return 0;
141
142 case C_TOKEN( spPr ):
143 return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() );
144
145 case C_TOKEN( txPr ):
146 return new TextBodyContext( *this, mrModel.mxTextProp.create() );
147 }
148 return 0;
149 }
150
151 // ============================================================================
152
153 } // namespace chart
154 } // namespace drawingml
155 } // namespace oox
156