1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FillStyleContext.cxx,v $
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
)
63 // SetFamily( XML_STYLE_FAMILY_FILLSTYLE_GRADIENT_ID );
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() );
82 if( xGradient
->hasByName( maStrName
) )
84 xGradient
->replaceByName( maStrName
, maAny
);
88 xGradient
->insertByName( maStrName
, maAny
);
92 catch( container::ElementExistException
& )
96 BOOL
XMLGradientStyleContext::IsTransient() const
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
)
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() );
128 if( xHatch
->hasByName( maStrName
) )
130 xHatch
->replaceByName( maStrName
, maAny
);
134 xHatch
->insertByName( maStrName
, maAny
);
138 catch( container::ElementExistException
& )
142 BOOL
XMLHatchStyleContext::IsTransient() const
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
)
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
) )
173 if( !sURL
.getLength() && !mxBase64Stream
.is() )
175 mxBase64Stream
= GetImport().GetStreamForGraphicObjectURLFromBase64();
176 if( mxBase64Stream
.is() )
177 pContext
= new XMLBase64ImportContext( GetImport(), nPrefix
,
178 rLocalName
, xAttrList
,
184 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
190 void XMLBitmapStyleContext::EndElement()
195 if( !sURL
.getLength() && mxBase64Stream
.is() )
197 sURL
= GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream
);
202 uno::Reference
< container::XNameContainer
> xBitmap( GetImport().GetBitmapHelper() );
208 if( xBitmap
->hasByName( maStrName
) )
210 xBitmap
->replaceByName( maStrName
, maAny
);
214 xBitmap
->insertByName( maStrName
, maAny
);
218 catch( container::ElementExistException
& )
222 BOOL
XMLBitmapStyleContext::IsTransient() const
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
)
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
);
261 xTransGradient
->insertByName( maStrName
, maAny
);
265 catch( container::ElementExistException
& )
269 BOOL
XMLTransGradientStyleContext::IsTransient() const
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
)
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() );
301 if( xMarker
->hasByName( maStrName
) )
303 xMarker
->replaceByName( maStrName
, maAny
);
307 xMarker
->insertByName( maStrName
, maAny
);
311 catch( container::ElementExistException
& )
315 BOOL
XMLMarkerStyleContext::IsTransient() const
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
)
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() );
347 if( xDashes
->hasByName( maStrName
) )
349 xDashes
->replaceByName( maStrName
, maAny
);
353 xDashes
->insertByName( maStrName
, maAny
);
357 catch( container::ElementExistException
& )
361 BOOL
XMLDashStyleContext::IsTransient() const