merge the formfield patch from ooo-build
[ooovba.git] / oox / source / drawingml / themeelementscontext.cxx
blob5b382db345e32a78f6ee9811227e138453fdbb91
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: themeelementscontext.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/drawingml/themeelementscontext.hxx"
32 #include "oox/drawingml/clrschemecontext.hxx"
33 #include "oox/drawingml/lineproperties.hxx"
34 #include "oox/drawingml/linepropertiescontext.hxx"
35 #include "oox/drawingml/fillproperties.hxx"
36 #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
37 #include "oox/drawingml/theme.hxx"
38 #include "oox/core/namespaces.hxx"
39 #include "oox/helper/attributelist.hxx"
40 #include "tokens.hxx"
42 using ::rtl::OUString;
43 using namespace ::oox::core;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::xml::sax;
47 namespace oox {
48 namespace drawingml {
50 // ============================================================================
52 class FillStyleListContext : public ContextHandler
54 public:
55 FillStyleListContext( ContextHandler& rParent, FillStyleList& rFillStyleList );
56 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& Attribs ) throw (SAXException, RuntimeException);
58 private:
59 FillStyleList& mrFillStyleList;
62 FillStyleListContext::FillStyleListContext( ContextHandler& rParent, FillStyleList& rFillStyleList ) :
63 ContextHandler( rParent ),
64 mrFillStyleList( rFillStyleList )
68 Reference< XFastContextHandler > FillStyleListContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttribs )
69 throw (SAXException, RuntimeException)
71 switch( nElement )
73 case NMSP_DRAWINGML|XML_noFill:
74 case NMSP_DRAWINGML|XML_solidFill:
75 case NMSP_DRAWINGML|XML_gradFill:
76 case NMSP_DRAWINGML|XML_blipFill:
77 case NMSP_DRAWINGML|XML_pattFill:
78 case NMSP_DRAWINGML|XML_grpFill:
79 mrFillStyleList.push_back( FillPropertiesPtr( new FillProperties ) );
80 return FillPropertiesContext::createFillContext( *this, nElement, xAttribs, *mrFillStyleList.back() );
82 return 0;
85 // ============================================================================
87 class LineStyleListContext : public ContextHandler
89 public:
90 LineStyleListContext( ContextHandler& rParent, LineStyleList& rLineStyleList );
91 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& Attribs ) throw (SAXException, RuntimeException);
93 private:
94 LineStyleList& mrLineStyleList;
97 LineStyleListContext::LineStyleListContext( ContextHandler& rParent, LineStyleList& rLineStyleList ) :
98 ContextHandler( rParent ),
99 mrLineStyleList( rLineStyleList )
103 Reference< XFastContextHandler > LineStyleListContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttribs )
104 throw (SAXException, RuntimeException)
106 switch( nElement )
108 case NMSP_DRAWINGML|XML_ln:
109 mrLineStyleList.push_back( LinePropertiesPtr( new LineProperties ) );
110 return new LinePropertiesContext( *this, xAttribs, *mrLineStyleList.back() );
112 return 0;
115 // ============================================================================
117 class EffectStyleListContext : public ContextHandler
119 public:
120 EffectStyleListContext( ContextHandler& rParent, EffectStyleList& rEffectStyleList );
121 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& Attribs ) throw (SAXException, RuntimeException);
123 private:
124 EffectStyleList& mrEffectStyleList;
127 EffectStyleListContext::EffectStyleListContext( ContextHandler& rParent, EffectStyleList& rEffectStyleList ) :
128 ContextHandler( rParent ),
129 mrEffectStyleList( rEffectStyleList )
133 Reference< XFastContextHandler > EffectStyleListContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& /*xAttribs*/ ) throw (SAXException, RuntimeException)
135 switch( nElement )
137 case NMSP_DRAWINGML|XML_effectStyle:
138 mrEffectStyleList.push_back( EffectStyleList::value_type( new PropertyMap ) );
139 // TODO: import effect styles
140 return 0;
142 return 0;
145 // ============================================================================
147 class FontSchemeContext : public ContextHandler
149 public:
150 FontSchemeContext( ContextHandler& rParent, FontScheme& rFontScheme );
151 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& Attribs ) throw (SAXException, RuntimeException);
152 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) throw (SAXException, RuntimeException);
154 private:
155 FontScheme& mrFontScheme;
156 TextCharacterPropertiesPtr mxCharProps;
159 FontSchemeContext::FontSchemeContext( ContextHandler& rParent, FontScheme& rFontScheme ) :
160 ContextHandler( rParent ),
161 mrFontScheme( rFontScheme )
165 Reference< XFastContextHandler > FontSchemeContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs )
166 throw (SAXException, RuntimeException)
168 AttributeList aAttribs( rxAttribs );
169 switch( nElement )
171 case NMSP_DRAWINGML|XML_majorFont:
172 mxCharProps.reset( new TextCharacterProperties );
173 mrFontScheme[ XML_major ] = mxCharProps;
174 return this;
175 case NMSP_DRAWINGML|XML_minorFont:
176 mxCharProps.reset( new TextCharacterProperties );
177 mrFontScheme[ XML_minor ] = mxCharProps;
178 return this;
180 case NMSP_DRAWINGML|XML_latin:
181 if( mxCharProps.get() )
182 mxCharProps->maLatinFont.setAttributes( aAttribs );
183 break;
184 case NMSP_DRAWINGML|XML_ea:
185 if( mxCharProps.get() )
186 mxCharProps->maAsianFont.setAttributes( aAttribs );
187 break;
188 case NMSP_DRAWINGML|XML_cs:
189 if( mxCharProps.get() )
190 mxCharProps->maComplexFont.setAttributes( aAttribs );
191 break;
193 return 0;
196 void FontSchemeContext::endFastElement( sal_Int32 nElement ) throw (SAXException, RuntimeException)
198 switch( nElement )
200 case NMSP_DRAWINGML|XML_majorFont:
201 case NMSP_DRAWINGML|XML_minorFont:
202 mxCharProps.reset();
203 break;
207 // ============================================================================
209 ThemeElementsContext::ThemeElementsContext( ContextHandler& rParent, Theme& rTheme ) :
210 ContextHandler( rParent ),
211 mrTheme( rTheme )
215 Reference< XFastContextHandler > ThemeElementsContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
217 // CT_BaseStyles
218 Reference< XFastContextHandler > xRet;
219 switch( nElement )
221 case NMSP_DRAWINGML|XML_clrScheme: // CT_ColorScheme
222 return new clrSchemeContext( *this, mrTheme.getClrScheme() );
223 case NMSP_DRAWINGML|XML_fontScheme: // CT_FontScheme
224 return new FontSchemeContext( *this, mrTheme.getFontScheme() );
226 case NMSP_DRAWINGML|XML_fmtScheme: // CT_StyleMatrix
227 mrTheme.setStyleName( xAttribs->getOptionalValue( XML_name ) );
228 return this;
230 case NMSP_DRAWINGML|XML_fillStyleLst: // CT_FillStyleList
231 return new FillStyleListContext( *this, mrTheme.getFillStyleList() );
232 case NMSP_DRAWINGML|XML_lnStyleLst: // CT_LineStyleList
233 return new LineStyleListContext( *this, mrTheme.getLineStyleList() );
234 case NMSP_DRAWINGML|XML_effectStyleLst: // CT_EffectStyleList
235 return new EffectStyleListContext( *this, mrTheme.getEffectStyleList() );
236 case NMSP_DRAWINGML|XML_bgFillStyleLst: // CT_BackgroundFillStyleList
237 return new FillStyleListContext( *this, mrTheme.getBgFillStyleList() );
239 return 0;
242 // ============================================================================
244 } // namespace drawingml
245 } // namespace oox