bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / style / FillStyleContext.cxx
blob015629e628b888d5cdbfa80ad86519530f0b37ae
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/container/XNameContainer.hpp>
21 #include "FillStyleContext.hxx"
22 #include <xmloff/xmlimp.hxx>
23 #include "xmloff/GradientStyle.hxx"
24 #include "xmloff/HatchStyle.hxx"
25 #include "xmloff/ImageStyle.hxx"
26 #include "TransGradientStyle.hxx"
27 #include "xmloff/MarkerStyle.hxx"
28 #include "xmloff/DashStyle.hxx"
29 #include <xmloff/families.hxx>
30 #include <xmloff/nmspmap.hxx>
31 #include "xmloff/xmlnmspe.hxx"
32 #include <xmloff/XMLBase64ImportContext.hxx>
34 using namespace ::com::sun::star;
37 //////////////////////////////////////////////////////////////////////////////
38 //////////////////////////////////////////////////////////////////////////////
40 TYPEINIT1( XMLGradientStyleContext, SvXMLStyleContext );
42 XMLGradientStyleContext::XMLGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
43 const OUString& rLName,
44 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
45 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
48 // start import
49 XMLGradientStyleImport aGradientStyle( GetImport() );
50 aGradientStyle.importXML( xAttrList, maAny, maStrName );
53 XMLGradientStyleContext::~XMLGradientStyleContext()
57 void XMLGradientStyleContext::EndElement()
59 uno::Reference< container::XNameContainer > xGradient( GetImport().GetGradientHelper() );
61 try
63 if(xGradient.is())
65 if( xGradient->hasByName( maStrName ) )
67 xGradient->replaceByName( maStrName, maAny );
69 else
71 xGradient->insertByName( maStrName, maAny );
75 catch( container::ElementExistException& )
79 sal_Bool XMLGradientStyleContext::IsTransient() const
81 return sal_True;
84 //////////////////////////////////////////////////////////////////////////////
85 //////////////////////////////////////////////////////////////////////////////
87 TYPEINIT1( XMLHatchStyleContext, SvXMLStyleContext );
89 XMLHatchStyleContext::XMLHatchStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
90 const OUString& rLName,
91 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
92 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
94 // start import
95 XMLHatchStyleImport aHatchStyle( GetImport() );
96 aHatchStyle.importXML( xAttrList, maAny, maStrName );
99 XMLHatchStyleContext::~XMLHatchStyleContext()
103 void XMLHatchStyleContext::EndElement()
105 uno::Reference< container::XNameContainer > xHatch( GetImport().GetHatchHelper() );
109 if(xHatch.is())
111 if( xHatch->hasByName( maStrName ) )
113 xHatch->replaceByName( maStrName, maAny );
115 else
117 xHatch->insertByName( maStrName, maAny );
121 catch( container::ElementExistException& )
125 sal_Bool XMLHatchStyleContext::IsTransient() const
127 return sal_True;
130 //////////////////////////////////////////////////////////////////////////////
131 //////////////////////////////////////////////////////////////////////////////
133 TYPEINIT1( XMLBitmapStyleContext, SvXMLStyleContext );
135 XMLBitmapStyleContext::XMLBitmapStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
136 const OUString& rLName,
137 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
138 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
140 // start import
141 XMLImageStyle aBitmapStyle;
142 aBitmapStyle.importXML( xAttrList, maAny, maStrName, rImport );
145 XMLBitmapStyleContext::~XMLBitmapStyleContext()
149 SvXMLImportContext* XMLBitmapStyleContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList )
151 SvXMLImportContext *pContext = 0;
152 if( (XML_NAMESPACE_OFFICE == nPrefix) && xmloff::token::IsXMLToken( rLocalName, xmloff::token::XML_BINARY_DATA ) )
154 OUString sURL;
155 maAny >>= sURL;
156 if( sURL.isEmpty() && !mxBase64Stream.is() )
158 mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
159 if( mxBase64Stream.is() )
160 pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
161 rLocalName, xAttrList,
162 mxBase64Stream );
165 if( !pContext )
167 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
170 return pContext;
173 void XMLBitmapStyleContext::EndElement()
175 OUString sURL;
176 maAny >>= sURL;
178 if( sURL.isEmpty() && mxBase64Stream.is() )
180 sURL = GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream );
181 mxBase64Stream = 0;
182 maAny <<= sURL;
185 uno::Reference< container::XNameContainer > xBitmap( GetImport().GetBitmapHelper() );
189 if(xBitmap.is())
191 if( xBitmap->hasByName( maStrName ) )
193 xBitmap->replaceByName( maStrName, maAny );
195 else
197 xBitmap->insertByName( maStrName, maAny );
201 catch( container::ElementExistException& )
205 sal_Bool XMLBitmapStyleContext::IsTransient() const
207 return sal_True;
211 //////////////////////////////////////////////////////////////////////////////
212 //////////////////////////////////////////////////////////////////////////////
214 TYPEINIT1( XMLTransGradientStyleContext, SvXMLStyleContext );
216 XMLTransGradientStyleContext::XMLTransGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
217 const OUString& rLName,
218 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
219 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
221 // start import
222 XMLTransGradientStyleImport aTransGradientStyle( GetImport() );
223 aTransGradientStyle.importXML( xAttrList, maAny, maStrName );
226 XMLTransGradientStyleContext::~XMLTransGradientStyleContext()
230 void XMLTransGradientStyleContext::EndElement()
232 uno::Reference< container::XNameContainer > xTransGradient( GetImport().GetTransGradientHelper() );
236 if(xTransGradient.is())
238 if( xTransGradient->hasByName( maStrName ) )
240 xTransGradient->replaceByName( maStrName, maAny );
242 else
244 xTransGradient->insertByName( maStrName, maAny );
248 catch( container::ElementExistException& )
252 sal_Bool XMLTransGradientStyleContext::IsTransient() const
254 return sal_True;
257 //////////////////////////////////////////////////////////////////////////////
258 //////////////////////////////////////////////////////////////////////////////
260 TYPEINIT1( XMLMarkerStyleContext, SvXMLStyleContext );
262 XMLMarkerStyleContext::XMLMarkerStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
263 const OUString& rLName,
264 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
265 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
267 // start import
268 XMLMarkerStyleImport aMarkerStyle( GetImport() );
269 aMarkerStyle.importXML( xAttrList, maAny, maStrName );
272 XMLMarkerStyleContext::~XMLMarkerStyleContext()
276 void XMLMarkerStyleContext::EndElement()
278 uno::Reference< container::XNameContainer > xMarker( GetImport().GetMarkerHelper() );
282 if(xMarker.is())
284 if( xMarker->hasByName( maStrName ) )
286 xMarker->replaceByName( maStrName, maAny );
288 else
290 xMarker->insertByName( maStrName, maAny );
294 catch( container::ElementExistException& )
298 sal_Bool XMLMarkerStyleContext::IsTransient() const
300 return sal_True;
303 //////////////////////////////////////////////////////////////////////////////
304 //////////////////////////////////////////////////////////////////////////////
306 TYPEINIT1( XMLDashStyleContext, SvXMLStyleContext );
308 XMLDashStyleContext::XMLDashStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
309 const OUString& rLName,
310 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
311 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
313 // start import
314 XMLDashStyleImport aDashStyle( GetImport() );
315 aDashStyle.importXML( xAttrList, maAny, maStrName );
318 XMLDashStyleContext::~XMLDashStyleContext()
322 void XMLDashStyleContext::EndElement()
324 uno::Reference< container::XNameContainer > xDashes( GetImport().GetDashHelper() );
328 if(xDashes.is())
330 if( xDashes->hasByName( maStrName ) )
332 xDashes->replaceByName( maStrName, maAny );
334 else
336 xDashes->insertByName( maStrName, maAny );
340 catch( container::ElementExistException& )
344 sal_Bool XMLDashStyleContext::IsTransient() const
346 return sal_True;
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */