bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / style / FillStyleContext.cxx
blobde9fda1e593ab00668303239bad090131cda6f65
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;
36 TYPEINIT1( XMLGradientStyleContext, SvXMLStyleContext );
38 XMLGradientStyleContext::XMLGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
39 const OUString& rLName,
40 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
41 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
44 // start import
45 XMLGradientStyleImport aGradientStyle( GetImport() );
46 aGradientStyle.importXML( xAttrList, maAny, maStrName );
49 XMLGradientStyleContext::~XMLGradientStyleContext()
53 void XMLGradientStyleContext::EndElement()
55 uno::Reference< container::XNameContainer > xGradient( GetImport().GetGradientHelper() );
57 try
59 if(xGradient.is())
61 if( xGradient->hasByName( maStrName ) )
63 xGradient->replaceByName( maStrName, maAny );
65 else
67 xGradient->insertByName( maStrName, maAny );
71 catch( container::ElementExistException& )
75 bool XMLGradientStyleContext::IsTransient() const
77 return true;
80 TYPEINIT1( XMLHatchStyleContext, SvXMLStyleContext );
82 XMLHatchStyleContext::XMLHatchStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
83 const OUString& rLName,
84 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
85 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
87 // start import
88 XMLHatchStyleImport aHatchStyle( GetImport() );
89 aHatchStyle.importXML( xAttrList, maAny, maStrName );
92 XMLHatchStyleContext::~XMLHatchStyleContext()
96 void XMLHatchStyleContext::EndElement()
98 uno::Reference< container::XNameContainer > xHatch( GetImport().GetHatchHelper() );
102 if(xHatch.is())
104 if( xHatch->hasByName( maStrName ) )
106 xHatch->replaceByName( maStrName, maAny );
108 else
110 xHatch->insertByName( maStrName, maAny );
114 catch( container::ElementExistException& )
118 bool XMLHatchStyleContext::IsTransient() const
120 return true;
123 TYPEINIT1( XMLBitmapStyleContext, SvXMLStyleContext );
125 XMLBitmapStyleContext::XMLBitmapStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
126 const OUString& rLName,
127 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
128 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
130 // start import
131 XMLImageStyle aBitmapStyle;
132 aBitmapStyle.importXML( xAttrList, maAny, maStrName, rImport );
135 XMLBitmapStyleContext::~XMLBitmapStyleContext()
139 SvXMLImportContext* XMLBitmapStyleContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList )
141 SvXMLImportContext *pContext = 0;
142 if( (XML_NAMESPACE_OFFICE == nPrefix) && xmloff::token::IsXMLToken( rLocalName, xmloff::token::XML_BINARY_DATA ) )
144 OUString sURL;
145 maAny >>= sURL;
146 if( sURL.isEmpty() && !mxBase64Stream.is() )
148 mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
149 if( mxBase64Stream.is() )
150 pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
151 rLocalName, xAttrList,
152 mxBase64Stream );
155 if( !pContext )
157 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
160 return pContext;
163 void XMLBitmapStyleContext::EndElement()
165 OUString sURL;
166 maAny >>= sURL;
168 if( sURL.isEmpty() && mxBase64Stream.is() )
170 sURL = GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream );
171 mxBase64Stream = 0;
172 maAny <<= sURL;
175 uno::Reference< container::XNameContainer > xBitmap( GetImport().GetBitmapHelper() );
179 if(xBitmap.is())
181 if( xBitmap->hasByName( maStrName ) )
183 xBitmap->replaceByName( maStrName, maAny );
185 else
187 xBitmap->insertByName( maStrName, maAny );
191 catch( container::ElementExistException& )
195 bool XMLBitmapStyleContext::IsTransient() const
197 return true;
200 TYPEINIT1( XMLTransGradientStyleContext, SvXMLStyleContext );
202 XMLTransGradientStyleContext::XMLTransGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
203 const OUString& rLName,
204 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
205 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
207 // start import
208 XMLTransGradientStyleImport aTransGradientStyle( GetImport() );
209 aTransGradientStyle.importXML( xAttrList, maAny, maStrName );
212 XMLTransGradientStyleContext::~XMLTransGradientStyleContext()
216 void XMLTransGradientStyleContext::EndElement()
218 uno::Reference< container::XNameContainer > xTransGradient( GetImport().GetTransGradientHelper() );
222 if(xTransGradient.is())
224 if( xTransGradient->hasByName( maStrName ) )
226 xTransGradient->replaceByName( maStrName, maAny );
228 else
230 xTransGradient->insertByName( maStrName, maAny );
234 catch( container::ElementExistException& )
238 bool XMLTransGradientStyleContext::IsTransient() const
240 return true;
243 TYPEINIT1( XMLMarkerStyleContext, SvXMLStyleContext );
245 XMLMarkerStyleContext::XMLMarkerStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
246 const OUString& rLName,
247 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
248 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
250 // start import
251 XMLMarkerStyleImport aMarkerStyle( GetImport() );
252 aMarkerStyle.importXML( xAttrList, maAny, maStrName );
255 XMLMarkerStyleContext::~XMLMarkerStyleContext()
259 void XMLMarkerStyleContext::EndElement()
261 uno::Reference< container::XNameContainer > xMarker( GetImport().GetMarkerHelper() );
265 if(xMarker.is())
267 if( xMarker->hasByName( maStrName ) )
269 xMarker->replaceByName( maStrName, maAny );
271 else
273 xMarker->insertByName( maStrName, maAny );
277 catch( container::ElementExistException& )
281 bool XMLMarkerStyleContext::IsTransient() const
283 return true;
286 TYPEINIT1( XMLDashStyleContext, SvXMLStyleContext );
288 XMLDashStyleContext::XMLDashStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
289 const OUString& rLName,
290 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
291 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
293 // start import
294 XMLDashStyleImport aDashStyle( GetImport() );
295 aDashStyle.importXML( xAttrList, maAny, maStrName );
298 XMLDashStyleContext::~XMLDashStyleContext()
302 void XMLDashStyleContext::EndElement()
304 uno::Reference< container::XNameContainer > xDashes( GetImport().GetDashHelper() );
308 if(xDashes.is())
310 if( xDashes->hasByName( maStrName ) )
312 xDashes->replaceByName( maStrName, maAny );
314 else
316 xDashes->insertByName( maStrName, maAny );
320 catch( container::ElementExistException& )
324 bool XMLDashStyleContext::IsTransient() const
326 return true;
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */