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/themeelementscontext.hxx"
25 #include "oox/drawingml/clrschemecontext.hxx"
26 #include "oox/drawingml/lineproperties.hxx"
27 #include "oox/drawingml/linepropertiescontext.hxx"
28 #include "oox/drawingml/fillproperties.hxx"
29 #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
30 #include "oox/drawingml/theme.hxx"
31 #include "oox/helper/attributelist.hxx"
32
33 using ::rtl::OUString;
34 using namespace ::oox::core;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::xml::sax;
37
38 namespace oox {
39 namespace drawingml {
40
41 // ============================================================================
42
43 class FillStyleListContext : public ContextHandler
44 {
45 public:
46 FillStyleListContext( ContextHandler& rParent, FillStyleList& rFillStyleList );
47 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& Attribs );
48
49 private:
50 FillStyleList& mrFillStyleList;
51 };
52
FillStyleListContext(ContextHandler & rParent,FillStyleList & rFillStyleList)53 FillStyleListContext::FillStyleListContext( ContextHandler& rParent, FillStyleList& rFillStyleList ) :
54 ContextHandler( rParent ),
55 mrFillStyleList( rFillStyleList )
56 {
57 }
58
createFastChildContext(sal_Int32 nElement,const Reference<XFastAttributeList> & xAttribs)59 Reference< XFastContextHandler > FillStyleListContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttribs )
60 {
61 switch( nElement )
62 {
63 case A_TOKEN( noFill ):
64 case A_TOKEN( solidFill ):
65 case A_TOKEN( gradFill ):
66 case A_TOKEN( blipFill ):
67 case A_TOKEN( pattFill ):
68 case A_TOKEN( grpFill ):
69 mrFillStyleList.push_back( FillPropertiesPtr( new FillProperties ) );
70 return FillPropertiesContext::createFillContext( *this, nElement, xAttribs, *mrFillStyleList.back() );
71 }
72 return 0;
73 }
74
75 // ============================================================================
76
77 class LineStyleListContext : public ContextHandler
78 {
79 public:
80 LineStyleListContext( ContextHandler& rParent, LineStyleList& rLineStyleList );
81 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& Attribs );
82
83 private:
84 LineStyleList& mrLineStyleList;
85 };
86
LineStyleListContext(ContextHandler & rParent,LineStyleList & rLineStyleList)87 LineStyleListContext::LineStyleListContext( ContextHandler& rParent, LineStyleList& rLineStyleList ) :
88 ContextHandler( rParent ),
89 mrLineStyleList( rLineStyleList )
90 {
91 }
92
createFastChildContext(sal_Int32 nElement,const Reference<XFastAttributeList> & xAttribs)93 Reference< XFastContextHandler > LineStyleListContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttribs )
94 {
95 switch( nElement )
96 {
97 case A_TOKEN( ln ):
98 mrLineStyleList.push_back( LinePropertiesPtr( new LineProperties ) );
99 return new LinePropertiesContext( *this, xAttribs, *mrLineStyleList.back() );
100 }
101 return 0;
102 }
103
104 // ============================================================================
105
106 class EffectStyleListContext : public ContextHandler
107 {
108 public:
109 EffectStyleListContext( ContextHandler& rParent, EffectStyleList& rEffectStyleList );
110 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& Attribs );
111
112 private:
113 EffectStyleList& mrEffectStyleList;
114 };
115
EffectStyleListContext(ContextHandler & rParent,EffectStyleList & rEffectStyleList)116 EffectStyleListContext::EffectStyleListContext( ContextHandler& rParent, EffectStyleList& rEffectStyleList ) :
117 ContextHandler( rParent ),
118 mrEffectStyleList( rEffectStyleList )
119 {
120 }
121
createFastChildContext(sal_Int32 nElement,const Reference<XFastAttributeList> &)122 Reference< XFastContextHandler > EffectStyleListContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& /*xAttribs*/ )
123 {
124 switch( nElement )
125 {
126 case A_TOKEN( effectStyle ):
127 mrEffectStyleList.push_back( EffectStyleList::value_type( new PropertyMap ) );
128 // TODO: import effect styles
129 return 0;
130 }
131 return 0;
132 }
133
134 // ============================================================================
135
136 class FontSchemeContext : public ContextHandler
137 {
138 public:
139 FontSchemeContext( ContextHandler& rParent, FontScheme& rFontScheme );
140 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& Attribs );
141 virtual void SAL_CALL endFastElement( sal_Int32 nElement );
142
143 private:
144 FontScheme& mrFontScheme;
145 TextCharacterPropertiesPtr mxCharProps;
146 };
147
FontSchemeContext(ContextHandler & rParent,FontScheme & rFontScheme)148 FontSchemeContext::FontSchemeContext( ContextHandler& rParent, FontScheme& rFontScheme ) :
149 ContextHandler( rParent ),
150 mrFontScheme( rFontScheme )
151 {
152 }
153
createFastChildContext(sal_Int32 nElement,const Reference<XFastAttributeList> & rxAttribs)154 Reference< XFastContextHandler > FontSchemeContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs )
155 {
156 AttributeList aAttribs( rxAttribs );
157 switch( nElement )
158 {
159 case A_TOKEN( majorFont ):
160 mxCharProps.reset( new TextCharacterProperties );
161 mrFontScheme[ XML_major ] = mxCharProps;
162 return this;
163 case A_TOKEN( minorFont ):
164 mxCharProps.reset( new TextCharacterProperties );
165 mrFontScheme[ XML_minor ] = mxCharProps;
166 return this;
167
168 case A_TOKEN( latin ):
169 if( mxCharProps.get() )
170 mxCharProps->maLatinFont.setAttributes( aAttribs );
171 break;
172 case A_TOKEN( ea ):
173 if( mxCharProps.get() )
174 mxCharProps->maAsianFont.setAttributes( aAttribs );
175 break;
176 case A_TOKEN( cs ):
177 if( mxCharProps.get() )
178 mxCharProps->maComplexFont.setAttributes( aAttribs );
179 break;
180 }
181 return 0;
182 }
183
endFastElement(sal_Int32 nElement)184 void FontSchemeContext::endFastElement( sal_Int32 nElement )
185 {
186 switch( nElement )
187 {
188 case A_TOKEN( majorFont ):
189 case A_TOKEN( minorFont ):
190 mxCharProps.reset();
191 break;
192 }
193 }
194
195 // ============================================================================
196
ThemeElementsContext(ContextHandler & rParent,Theme & rTheme)197 ThemeElementsContext::ThemeElementsContext( ContextHandler& rParent, Theme& rTheme ) :
198 ContextHandler( rParent ),
199 mrTheme( rTheme )
200 {
201 }
202
createFastChildContext(sal_Int32 nElement,const Reference<XFastAttributeList> & xAttribs)203 Reference< XFastContextHandler > ThemeElementsContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttribs )
204 {
205 // CT_BaseStyles
206 Reference< XFastContextHandler > xRet;
207 switch( nElement )
208 {
209 case A_TOKEN( clrScheme ): // CT_ColorScheme
210 return new clrSchemeContext( *this, mrTheme.getClrScheme() );
211 case A_TOKEN( fontScheme ): // CT_FontScheme
212 return new FontSchemeContext( *this, mrTheme.getFontScheme() );
213
214 case A_TOKEN( fmtScheme ): // CT_StyleMatrix
215 mrTheme.setStyleName( xAttribs->getOptionalValue( XML_name ) );
216 return this;
217
218 case A_TOKEN( fillStyleLst ): // CT_FillStyleList
219 return new FillStyleListContext( *this, mrTheme.getFillStyleList() );
220 case A_TOKEN( lnStyleLst ): // CT_LineStyleList
221 return new LineStyleListContext( *this, mrTheme.getLineStyleList() );
222 case A_TOKEN( effectStyleLst ): // CT_EffectStyleList
223 return new EffectStyleListContext( *this, mrTheme.getEffectStyleList() );
224 case A_TOKEN( bgFillStyleLst ): // CT_BackgroundFillStyleList
225 return new FillStyleListContext( *this, mrTheme.getBgFillStyleList() );
226 }
227 return 0;
228 }
229
230 // ============================================================================
231
232 } // namespace drawingml
233 } // namespace oox
234