update dev300-m58
[ooovba.git] / xmloff / source / style / FillStyleContext.cxx
blob55556433d418eee777bf619fcb2917b11b1db632
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FillStyleContext.cxx,v $
10 * $Revision: 1.13 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <com/sun/star/container/XNameContainer.hpp>
34 #include "FillStyleContext.hxx"
35 #include <xmloff/xmlimp.hxx>
36 #include "GradientStyle.hxx"
37 #include "HatchStyle.hxx"
38 #include "ImageStyle.hxx"
39 #include "TransGradientStyle.hxx"
40 #include "MarkerStyle.hxx"
41 #include "DashStyle.hxx"
42 #include <xmloff/families.hxx>
43 #include <xmloff/nmspmap.hxx>
44 #include "xmlnmspe.hxx"
45 #include <xmloff/XMLBase64ImportContext.hxx>
47 using namespace ::com::sun::star;
48 using ::rtl::OUString;
49 using ::rtl::OUStringBuffer;
52 //////////////////////////////////////////////////////////////////////////////
53 //////////////////////////////////////////////////////////////////////////////
55 TYPEINIT1( XMLGradientStyleContext, SvXMLStyleContext );
57 XMLGradientStyleContext::XMLGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
58 const OUString& rLName,
59 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
60 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
62 // set Family
63 // SetFamily( XML_STYLE_FAMILY_FILLSTYLE_GRADIENT_ID );
65 // start import
66 XMLGradientStyleImport aGradientStyle( GetImport() );
67 aGradientStyle.importXML( xAttrList, maAny, maStrName );
70 XMLGradientStyleContext::~XMLGradientStyleContext()
74 void XMLGradientStyleContext::EndElement()
76 uno::Reference< container::XNameContainer > xGradient( GetImport().GetGradientHelper() );
78 try
80 if(xGradient.is())
82 if( xGradient->hasByName( maStrName ) )
84 xGradient->replaceByName( maStrName, maAny );
86 else
88 xGradient->insertByName( maStrName, maAny );
92 catch( container::ElementExistException& )
96 BOOL XMLGradientStyleContext::IsTransient() const
98 return sal_True;
101 //////////////////////////////////////////////////////////////////////////////
102 //////////////////////////////////////////////////////////////////////////////
104 TYPEINIT1( XMLHatchStyleContext, SvXMLStyleContext );
106 XMLHatchStyleContext::XMLHatchStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
107 const OUString& rLName,
108 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
109 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
111 // start import
112 XMLHatchStyleImport aHatchStyle( GetImport() );
113 aHatchStyle.importXML( xAttrList, maAny, maStrName );
116 XMLHatchStyleContext::~XMLHatchStyleContext()
120 void XMLHatchStyleContext::EndElement()
122 uno::Reference< container::XNameContainer > xHatch( GetImport().GetHatchHelper() );
126 if(xHatch.is())
128 if( xHatch->hasByName( maStrName ) )
130 xHatch->replaceByName( maStrName, maAny );
132 else
134 xHatch->insertByName( maStrName, maAny );
138 catch( container::ElementExistException& )
142 BOOL XMLHatchStyleContext::IsTransient() const
144 return sal_True;
147 //////////////////////////////////////////////////////////////////////////////
148 //////////////////////////////////////////////////////////////////////////////
150 TYPEINIT1( XMLBitmapStyleContext, SvXMLStyleContext );
152 XMLBitmapStyleContext::XMLBitmapStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
153 const OUString& rLName,
154 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
155 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
157 // start import
158 XMLImageStyle aBitmapStyle;
159 aBitmapStyle.importXML( xAttrList, maAny, maStrName, rImport );
162 XMLBitmapStyleContext::~XMLBitmapStyleContext()
166 SvXMLImportContext* XMLBitmapStyleContext::CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList )
168 SvXMLImportContext *pContext = 0;
169 if( (XML_NAMESPACE_OFFICE == nPrefix) && xmloff::token::IsXMLToken( rLocalName, xmloff::token::XML_BINARY_DATA ) )
171 OUString sURL;
172 maAny >>= sURL;
173 if( !sURL.getLength() && !mxBase64Stream.is() )
175 mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
176 if( mxBase64Stream.is() )
177 pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
178 rLocalName, xAttrList,
179 mxBase64Stream );
182 if( !pContext )
184 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
187 return pContext;
190 void XMLBitmapStyleContext::EndElement()
192 OUString sURL;
193 maAny >>= sURL;
195 if( !sURL.getLength() && mxBase64Stream.is() )
197 sURL = GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream );
198 mxBase64Stream = 0;
199 maAny <<= sURL;
202 uno::Reference< container::XNameContainer > xBitmap( GetImport().GetBitmapHelper() );
206 if(xBitmap.is())
208 if( xBitmap->hasByName( maStrName ) )
210 xBitmap->replaceByName( maStrName, maAny );
212 else
214 xBitmap->insertByName( maStrName, maAny );
218 catch( container::ElementExistException& )
222 BOOL XMLBitmapStyleContext::IsTransient() const
224 return sal_True;
228 //////////////////////////////////////////////////////////////////////////////
229 //////////////////////////////////////////////////////////////////////////////
231 TYPEINIT1( XMLTransGradientStyleContext, SvXMLStyleContext );
233 XMLTransGradientStyleContext::XMLTransGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
234 const OUString& rLName,
235 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
236 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
238 // start import
239 XMLTransGradientStyleImport aTransGradientStyle( GetImport() );
240 aTransGradientStyle.importXML( xAttrList, maAny, maStrName );
243 XMLTransGradientStyleContext::~XMLTransGradientStyleContext()
247 void XMLTransGradientStyleContext::EndElement()
249 uno::Reference< container::XNameContainer > xTransGradient( GetImport().GetTransGradientHelper() );
253 if(xTransGradient.is())
255 if( xTransGradient->hasByName( maStrName ) )
257 xTransGradient->replaceByName( maStrName, maAny );
259 else
261 xTransGradient->insertByName( maStrName, maAny );
265 catch( container::ElementExistException& )
269 BOOL XMLTransGradientStyleContext::IsTransient() const
271 return sal_True;
274 //////////////////////////////////////////////////////////////////////////////
275 //////////////////////////////////////////////////////////////////////////////
277 TYPEINIT1( XMLMarkerStyleContext, SvXMLStyleContext );
279 XMLMarkerStyleContext::XMLMarkerStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
280 const OUString& rLName,
281 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
282 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
284 // start import
285 XMLMarkerStyleImport aMarkerStyle( GetImport() );
286 aMarkerStyle.importXML( xAttrList, maAny, maStrName );
289 XMLMarkerStyleContext::~XMLMarkerStyleContext()
293 void XMLMarkerStyleContext::EndElement()
295 uno::Reference< container::XNameContainer > xMarker( GetImport().GetMarkerHelper() );
299 if(xMarker.is())
301 if( xMarker->hasByName( maStrName ) )
303 xMarker->replaceByName( maStrName, maAny );
305 else
307 xMarker->insertByName( maStrName, maAny );
311 catch( container::ElementExistException& )
315 BOOL XMLMarkerStyleContext::IsTransient() const
317 return sal_True;
320 //////////////////////////////////////////////////////////////////////////////
321 //////////////////////////////////////////////////////////////////////////////
323 TYPEINIT1( XMLDashStyleContext, SvXMLStyleContext );
325 XMLDashStyleContext::XMLDashStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
326 const OUString& rLName,
327 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
328 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
330 // start import
331 XMLDashStyleImport aDashStyle( GetImport() );
332 aDashStyle.importXML( xAttrList, maAny, maStrName );
335 XMLDashStyleContext::~XMLDashStyleContext()
339 void XMLDashStyleContext::EndElement()
341 uno::Reference< container::XNameContainer > xDashes( GetImport().GetDashHelper() );
345 if(xDashes.is())
347 if( xDashes->hasByName( maStrName ) )
349 xDashes->replaceByName( maStrName, maAny );
351 else
353 xDashes->insertByName( maStrName, maAny );
357 catch( container::ElementExistException& )
361 BOOL XMLDashStyleContext::IsTransient() const
363 return sal_True;