Update ooo320-m1
[ooovba.git] / oox / source / drawingml / fillpropertiesgroupcontext.cxx
blobcdeed26f1678246328ae3482ca8f1df950f0b3d4
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: fillpropertiesgroupcontext.cxx,v $
10 * $Revision: 1.8.6.1 $
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/fillpropertiesgroupcontext.hxx"
32 #include "oox/helper/attributelist.hxx"
33 #include "oox/core/namespaces.hxx"
34 #include "oox/core/xmlfilterbase.hxx"
35 #include "oox/drawingml/drawingmltypes.hxx"
36 #include "oox/drawingml/fillproperties.hxx"
38 using ::rtl::OUString;
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::xml::sax;
42 using ::oox::core::ContextHandler;
43 using ::oox::core::XmlFilterBase;
45 namespace oox {
46 namespace drawingml {
48 // ============================================================================
50 SolidFillContext::SolidFillContext( ContextHandler& rParent,
51 const Reference< XFastAttributeList >&, FillProperties& rFillProps ) :
52 ColorContext( rParent, rFillProps.maFillColor )
56 // ============================================================================
58 GradientFillContext::GradientFillContext( ContextHandler& rParent,
59 const Reference< XFastAttributeList >& rxAttribs, GradientFillProperties& rGradientProps ) :
60 ContextHandler( rParent ),
61 mrGradientProps( rGradientProps )
63 AttributeList aAttribs( rxAttribs );
64 mrGradientProps.moShadeFlip = aAttribs.getToken( XML_flip );
65 mrGradientProps.moRotateWithShape = aAttribs.getBool( XML_rotWithShape );
68 Reference< XFastContextHandler > GradientFillContext::createFastChildContext(
69 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException)
71 AttributeList aAttribs( rxAttribs );
72 switch( nElement )
74 case A_TOKEN( gsLst ):
75 return this; // for gs elements
77 case A_TOKEN( gs ):
78 if( aAttribs.hasAttribute( XML_pos ) )
80 double fPosition = getLimitedValue< double >( aAttribs.getDouble( XML_pos, 0.0 ) / 100000.0, 0.0, 1.0 );
81 return new ColorContext( *this, mrGradientProps.maGradientStops[ fPosition ] );
83 break;
85 case A_TOKEN( lin ):
86 mrGradientProps.moShadeAngle = aAttribs.getInteger( XML_ang );
87 mrGradientProps.moShadeScaled = aAttribs.getBool( XML_scaled );
88 break;
90 case A_TOKEN( path ):
91 // always set a path type, this disables linear gradient in conversion
92 mrGradientProps.moGradientPath = aAttribs.getToken( XML_path, XML_rect );
93 return this; // for fillToRect element
95 case A_TOKEN( fillToRect ):
96 mrGradientProps.moFillToRect = GetRelativeRect( rxAttribs );
97 break;
99 case A_TOKEN( tileRect ):
100 mrGradientProps.moTileRect = GetRelativeRect( rxAttribs );
101 break;
103 return 0;
106 // ============================================================================
108 PatternFillContext::PatternFillContext( ContextHandler& rParent,
109 const Reference< XFastAttributeList >& rxAttribs, PatternFillProperties& rPatternProps ) :
110 ContextHandler( rParent ),
111 mrPatternProps( rPatternProps )
113 AttributeList aAttribs( rxAttribs );
114 mrPatternProps.moPattPreset = aAttribs.getToken( XML_prst );
117 Reference< XFastContextHandler > PatternFillContext::createFastChildContext(
118 sal_Int32 nElement, const Reference< XFastAttributeList >& ) throw (SAXException, RuntimeException)
120 switch( nElement )
122 case A_TOKEN( bgClr ):
123 return new ColorContext( *this, mrPatternProps.maPattBgColor );
124 case A_TOKEN( fgClr ):
125 return new ColorContext( *this, mrPatternProps.maPattFgColor );
127 return 0;
130 // ============================================================================
131 // ============================================================================
133 ColorChangeContext::ColorChangeContext( ContextHandler& rParent,
134 const Reference< XFastAttributeList >& rxAttribs, BlipFillProperties& rBlipProps ) :
135 ContextHandler( rParent ),
136 mrBlipProps( rBlipProps )
138 mrBlipProps.maColorChangeFrom.setUnused();
139 mrBlipProps.maColorChangeTo.setUnused();
140 AttributeList aAttribs( rxAttribs );
141 mbUseAlpha = aAttribs.getBool( XML_useA, true );
144 ColorChangeContext::~ColorChangeContext()
146 if( !mbUseAlpha )
147 mrBlipProps.maColorChangeTo.clearTransparence();
150 Reference< XFastContextHandler > ColorChangeContext::createFastChildContext(
151 sal_Int32 nElement, const Reference< XFastAttributeList >& ) throw (SAXException, RuntimeException)
153 switch( nElement )
155 case A_TOKEN( clrFrom ):
156 return new ColorContext( *this, mrBlipProps.maColorChangeFrom );
157 case A_TOKEN( clrTo ):
158 return new ColorContext( *this, mrBlipProps.maColorChangeTo );
160 return 0;
163 // ============================================================================
165 BlipContext::BlipContext( ContextHandler& rParent,
166 const Reference< XFastAttributeList >& rxAttribs, BlipFillProperties& rBlipProps ) :
167 ContextHandler( rParent ),
168 mrBlipProps( rBlipProps )
170 AttributeList aAttribs( rxAttribs );
171 if( aAttribs.hasAttribute( R_TOKEN( embed ) ) )
173 // internal picture URL
174 OUString aFragmentPath = getFragmentPathFromRelId( aAttribs.getString( R_TOKEN( embed ), OUString() ) );
175 if( aFragmentPath.getLength() > 0 )
176 mrBlipProps.mxGraphic = getFilter().importEmbeddedGraphic( aFragmentPath );
178 else if( aAttribs.hasAttribute( R_TOKEN( link ) ) )
180 // external URL
181 OUString aRelId = aAttribs.getString( R_TOKEN( link ), OUString() );
182 OUString aTargetLink = getFilter().getAbsoluteUrl( getRelations().getExternalTargetFromRelId( aRelId ) );
183 // TODO: load external picture
187 Reference< XFastContextHandler > BlipContext::createFastChildContext(
188 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException)
190 AttributeList aAttribs( rxAttribs );
191 switch( nElement )
193 case A_TOKEN( biLevel ):
194 case A_TOKEN( grayscl ):
195 mrBlipProps.moColorEffect = getToken( nElement );
196 break;
198 case A_TOKEN( clrChange ):
199 return new ColorChangeContext( *this, rxAttribs, mrBlipProps );
201 case A_TOKEN( lum ):
202 mrBlipProps.moBrightness = aAttribs.getInteger( XML_bright );
203 mrBlipProps.moContrast = aAttribs.getInteger( XML_contrast );
204 break;
206 return 0;
209 // ============================================================================
211 BlipFillContext::BlipFillContext( ContextHandler& rParent,
212 const Reference< XFastAttributeList >& rxAttribs, BlipFillProperties& rBlipProps ) :
213 ContextHandler( rParent ),
214 mrBlipProps( rBlipProps )
216 AttributeList aAttribs( rxAttribs );
217 mrBlipProps.moRotateWithShape = aAttribs.getBool( XML_rotWithShape );
220 Reference< XFastContextHandler > BlipFillContext::createFastChildContext(
221 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException)
223 AttributeList aAttribs( rxAttribs );
224 switch( nElement )
226 case A_TOKEN( blip ):
227 return new BlipContext( *this, rxAttribs, mrBlipProps );
229 case A_TOKEN( srcRect ):
230 // TODO
231 break;
233 case A_TOKEN( tile ):
234 mrBlipProps.moBitmapMode = getToken( nElement );
235 mrBlipProps.moTileOffsetX = aAttribs.getInteger( XML_tx );
236 mrBlipProps.moTileOffsetY = aAttribs.getInteger( XML_ty );
237 mrBlipProps.moTileScaleX = aAttribs.getInteger( XML_sx );
238 mrBlipProps.moTileScaleY = aAttribs.getInteger( XML_sy );
239 mrBlipProps.moTileAlign = aAttribs.getToken( XML_algn );
240 mrBlipProps.moTileFlip = aAttribs.getToken( XML_flip );
241 break;
243 case A_TOKEN( stretch ):
244 mrBlipProps.moBitmapMode = getToken( nElement );
245 return this; // for fillRect element
247 case A_TOKEN( fillRect ):
248 mrBlipProps.moFillRect = GetRelativeRect( rxAttribs );
249 break;
251 return 0;
254 // ============================================================================
255 // ============================================================================
257 FillPropertiesContext::FillPropertiesContext( ContextHandler& rParent, FillProperties& rFillProps ) :
258 ContextHandler( rParent ),
259 mrFillProps( rFillProps )
263 Reference< XFastContextHandler > FillPropertiesContext::createFastChildContext(
264 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs )
265 throw ( SAXException, RuntimeException )
267 return createFillContext( *this, nElement, rxAttribs, mrFillProps );
270 /*static*/ Reference< XFastContextHandler > FillPropertiesContext::createFillContext(
271 ContextHandler& rParent, sal_Int32 nElement,
272 const Reference< XFastAttributeList >& rxAttribs, FillProperties& rFillProps )
274 switch( nElement )
276 case A_TOKEN( noFill ): { rFillProps.moFillType = getToken( nElement ); return 0; };
277 case A_TOKEN( solidFill ): { rFillProps.moFillType = getToken( nElement ); return new SolidFillContext( rParent, rxAttribs, rFillProps ); };
278 case A_TOKEN( gradFill ): { rFillProps.moFillType = getToken( nElement ); return new GradientFillContext( rParent, rxAttribs, rFillProps.maGradientProps ); };
279 case A_TOKEN( pattFill ): { rFillProps.moFillType = getToken( nElement ); return new PatternFillContext( rParent, rxAttribs, rFillProps.maPatternProps ); };
280 case A_TOKEN( blipFill ): { rFillProps.moFillType = getToken( nElement ); return new BlipFillContext( rParent, rxAttribs, rFillProps.maBlipProps ); };
281 case A_TOKEN( grpFill ): { rFillProps.moFillType = getToken( nElement ); return 0; }; // TODO
283 return 0;
286 // ============================================================================
288 SimpleFillPropertiesContext::SimpleFillPropertiesContext( ContextHandler& rParent, Color& rColor ) :
289 FillPropertiesContext( rParent, *this ),
290 mrColor( rColor )
294 SimpleFillPropertiesContext::~SimpleFillPropertiesContext()
296 mrColor = getBestSolidColor();
299 // ============================================================================
301 } // namespace drawingml
302 } // namespace oox