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