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