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