xref: /trunk/main/xmloff/source/style/FillStyleContext.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include <com/sun/star/container/XNameContainer.hpp>
31 #include "FillStyleContext.hxx"
32 #include <xmloff/xmlimp.hxx>
33 #include "xmloff/GradientStyle.hxx"
34 #include "xmloff/HatchStyle.hxx"
35 #include "xmloff/ImageStyle.hxx"
36 #include "TransGradientStyle.hxx"
37 #include "xmloff/MarkerStyle.hxx"
38 #include "xmloff/DashStyle.hxx"
39 #include <xmloff/families.hxx>
40 #include <xmloff/nmspmap.hxx>
41 #include "xmloff/xmlnmspe.hxx"
42 #include <xmloff/XMLBase64ImportContext.hxx>
43 
44 using namespace ::com::sun::star;
45 using ::rtl::OUString;
46 using ::rtl::OUStringBuffer;
47 
48 
49 //////////////////////////////////////////////////////////////////////////////
50 //////////////////////////////////////////////////////////////////////////////
51 
52 TYPEINIT1( XMLGradientStyleContext, SvXMLStyleContext );
53 
54 XMLGradientStyleContext::XMLGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
55                                               const OUString& rLName,
56                                               const uno::Reference< xml::sax::XAttributeList >& xAttrList)
57 :   SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
58 {
59     // set Family
60 //  SetFamily( XML_STYLE_FAMILY_FILLSTYLE_GRADIENT_ID );
61 
62     // start import
63     XMLGradientStyleImport aGradientStyle( GetImport() );
64     aGradientStyle.importXML( xAttrList, maAny, maStrName );
65 }
66 
67 XMLGradientStyleContext::~XMLGradientStyleContext()
68 {
69 }
70 
71 void XMLGradientStyleContext::EndElement()
72 {
73     uno::Reference< container::XNameContainer > xGradient( GetImport().GetGradientHelper() );
74 
75     try
76     {
77         if(xGradient.is())
78         {
79             if( xGradient->hasByName( maStrName ) )
80             {
81                 xGradient->replaceByName( maStrName, maAny );
82             }
83             else
84             {
85                 xGradient->insertByName( maStrName, maAny );
86             }
87         }
88     }
89     catch( container::ElementExistException& )
90     {}
91 }
92 
93 sal_Bool XMLGradientStyleContext::IsTransient() const
94 {
95     return sal_True;
96 }
97 
98 //////////////////////////////////////////////////////////////////////////////
99 //////////////////////////////////////////////////////////////////////////////
100 
101 TYPEINIT1( XMLHatchStyleContext, SvXMLStyleContext );
102 
103 XMLHatchStyleContext::XMLHatchStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
104                                               const OUString& rLName,
105                                               const uno::Reference< xml::sax::XAttributeList >& xAttrList)
106 :   SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
107 {
108     // start import
109     XMLHatchStyleImport aHatchStyle( GetImport() );
110     aHatchStyle.importXML( xAttrList, maAny, maStrName );
111 }
112 
113 XMLHatchStyleContext::~XMLHatchStyleContext()
114 {
115 }
116 
117 void XMLHatchStyleContext::EndElement()
118 {
119     uno::Reference< container::XNameContainer > xHatch( GetImport().GetHatchHelper() );
120 
121     try
122     {
123         if(xHatch.is())
124         {
125             if( xHatch->hasByName( maStrName ) )
126             {
127                 xHatch->replaceByName( maStrName, maAny );
128             }
129             else
130             {
131                 xHatch->insertByName( maStrName, maAny );
132             }
133         }
134     }
135     catch( container::ElementExistException& )
136     {}
137 }
138 
139 sal_Bool XMLHatchStyleContext::IsTransient() const
140 {
141     return sal_True;
142 }
143 
144 //////////////////////////////////////////////////////////////////////////////
145 //////////////////////////////////////////////////////////////////////////////
146 
147 TYPEINIT1( XMLBitmapStyleContext, SvXMLStyleContext );
148 
149 XMLBitmapStyleContext::XMLBitmapStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
150                                               const OUString& rLName,
151                                               const uno::Reference< xml::sax::XAttributeList >& xAttrList)
152 :   SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
153 {
154     // start import
155     XMLImageStyle aBitmapStyle;
156     aBitmapStyle.importXML( xAttrList, maAny, maStrName, rImport );
157 }
158 
159 XMLBitmapStyleContext::~XMLBitmapStyleContext()
160 {
161 }
162 
163 SvXMLImportContext* XMLBitmapStyleContext::CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList )
164 {
165     SvXMLImportContext *pContext = 0;
166     if( (XML_NAMESPACE_OFFICE == nPrefix) && xmloff::token::IsXMLToken( rLocalName, xmloff::token::XML_BINARY_DATA ) )
167     {
168         OUString sURL;
169         maAny >>= sURL;
170         if( !sURL.getLength() && !mxBase64Stream.is() )
171         {
172             mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
173             if( mxBase64Stream.is() )
174                 pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
175                                                     rLocalName, xAttrList,
176                                                     mxBase64Stream );
177         }
178     }
179     if( !pContext )
180     {
181         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
182     }
183 
184     return pContext;
185 }
186 
187 void XMLBitmapStyleContext::EndElement()
188 {
189     OUString sURL;
190     maAny >>= sURL;
191 
192     if( !sURL.getLength() && mxBase64Stream.is() )
193     {
194         sURL = GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream );
195         mxBase64Stream = 0;
196         maAny <<= sURL;
197     }
198 
199     uno::Reference< container::XNameContainer > xBitmap( GetImport().GetBitmapHelper() );
200 
201     try
202     {
203         if(xBitmap.is())
204         {
205             if( xBitmap->hasByName( maStrName ) )
206             {
207                 xBitmap->replaceByName( maStrName, maAny );
208             }
209             else
210             {
211                 xBitmap->insertByName( maStrName, maAny );
212             }
213         }
214     }
215     catch( container::ElementExistException& )
216     {}
217 }
218 
219 sal_Bool XMLBitmapStyleContext::IsTransient() const
220 {
221     return sal_True;
222 }
223 
224 
225 //////////////////////////////////////////////////////////////////////////////
226 //////////////////////////////////////////////////////////////////////////////
227 
228 TYPEINIT1( XMLTransGradientStyleContext, SvXMLStyleContext );
229 
230 XMLTransGradientStyleContext::XMLTransGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
231                                               const OUString& rLName,
232                                               const uno::Reference< xml::sax::XAttributeList >& xAttrList)
233 :   SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
234 {
235     // start import
236     XMLTransGradientStyleImport aTransGradientStyle( GetImport() );
237     aTransGradientStyle.importXML( xAttrList, maAny, maStrName );
238 }
239 
240 XMLTransGradientStyleContext::~XMLTransGradientStyleContext()
241 {
242 }
243 
244 void XMLTransGradientStyleContext::EndElement()
245 {
246     uno::Reference< container::XNameContainer > xTransGradient( GetImport().GetTransGradientHelper() );
247 
248     try
249     {
250         if(xTransGradient.is())
251         {
252             if( xTransGradient->hasByName( maStrName ) )
253             {
254                 xTransGradient->replaceByName( maStrName, maAny );
255             }
256             else
257             {
258                 xTransGradient->insertByName( maStrName, maAny );
259             }
260         }
261     }
262     catch( container::ElementExistException& )
263     {}
264 }
265 
266 sal_Bool XMLTransGradientStyleContext::IsTransient() const
267 {
268     return sal_True;
269 }
270 
271 //////////////////////////////////////////////////////////////////////////////
272 //////////////////////////////////////////////////////////////////////////////
273 
274 TYPEINIT1( XMLMarkerStyleContext, SvXMLStyleContext );
275 
276 XMLMarkerStyleContext::XMLMarkerStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
277                                               const OUString& rLName,
278                                               const uno::Reference< xml::sax::XAttributeList >& xAttrList)
279 :   SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
280 {
281     // start import
282     XMLMarkerStyleImport aMarkerStyle( GetImport() );
283     aMarkerStyle.importXML( xAttrList, maAny, maStrName );
284 }
285 
286 XMLMarkerStyleContext::~XMLMarkerStyleContext()
287 {
288 }
289 
290 void XMLMarkerStyleContext::EndElement()
291 {
292     uno::Reference< container::XNameContainer > xMarker( GetImport().GetMarkerHelper() );
293 
294     try
295     {
296         if(xMarker.is())
297         {
298             if( xMarker->hasByName( maStrName ) )
299             {
300                 xMarker->replaceByName( maStrName, maAny );
301             }
302             else
303             {
304                 xMarker->insertByName( maStrName, maAny );
305             }
306         }
307     }
308     catch( container::ElementExistException& )
309     {}
310 }
311 
312 sal_Bool XMLMarkerStyleContext::IsTransient() const
313 {
314     return sal_True;
315 }
316 
317 //////////////////////////////////////////////////////////////////////////////
318 //////////////////////////////////////////////////////////////////////////////
319 
320 TYPEINIT1( XMLDashStyleContext, SvXMLStyleContext );
321 
322 XMLDashStyleContext::XMLDashStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
323                                           const OUString& rLName,
324                                           const uno::Reference< xml::sax::XAttributeList >& xAttrList)
325 :   SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
326 {
327     // start import
328     XMLDashStyleImport aDashStyle( GetImport() );
329     aDashStyle.importXML( xAttrList, maAny, maStrName );
330 }
331 
332 XMLDashStyleContext::~XMLDashStyleContext()
333 {
334 }
335 
336 void XMLDashStyleContext::EndElement()
337 {
338     uno::Reference< container::XNameContainer > xDashes( GetImport().GetDashHelper() );
339 
340     try
341     {
342         if(xDashes.is())
343         {
344             if( xDashes->hasByName( maStrName ) )
345             {
346                 xDashes->replaceByName( maStrName, maAny );
347             }
348             else
349             {
350                 xDashes->insertByName( maStrName, maAny );
351             }
352         }
353     }
354     catch( container::ElementExistException& )
355     {}
356 }
357 
358 sal_Bool XMLDashStyleContext::IsTransient() const
359 {
360     return sal_True;
361 }
362