update dev300-m58
[ooovba.git] / xmloff / source / text / XMLTextShapeStyleContext.cxx
blobd04fc57e52e05da0c97181a5aad21cd51d18a243
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLTextShapeStyleContext.cxx,v $
10 * $Revision: 1.13 $
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 <tools/debug.hxx>
34 #ifndef _COM_SUN_STAR_DOCUMENT_XEVENTSSUPPLIER_HPP
35 #include <com/sun/star/document/XEventsSupplier.hpp>
36 #endif
37 #include "xmlnmspe.hxx"
38 #include <xmloff/xmltoken.hxx>
39 #include "XMLTextPropertySetContext.hxx"
40 #include <xmloff/xmlimp.hxx>
41 #include <xmloff/XMLEventsImportContext.hxx>
42 #include "XMLShapePropertySetContext.hxx"
43 #include "XMLTextColumnsContext.hxx"
44 #include "XMLBackgroundImageContext.hxx"
45 #ifndef _XMLOFF_TXTPRMAP_HXX
46 #include <xmloff/txtprmap.hxx>
47 #endif
49 #ifndef _XMLOFF_XMLTEXTSHAPESTYLECONTEXT_HXX
50 #include <xmloff/XMLTextShapeStyleContext.hxx>
51 #endif
53 using ::rtl::OUString;
54 using ::rtl::OUStringBuffer;
56 using namespace ::com::sun::star::document;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::xml::sax;
59 using namespace ::com::sun::star::style;
60 using namespace ::com::sun::star::beans;
61 using namespace ::xmloff::token;
63 class XMLTextShapePropertySetContext_Impl : public XMLShapePropertySetContext
65 public:
66 XMLTextShapePropertySetContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
67 const OUString& rLName,
68 const Reference< XAttributeList >& xAttrList,
69 sal_uInt32 nFamily,
70 ::std::vector< XMLPropertyState > &rProps,
71 const UniReference < SvXMLImportPropertyMapper > &rMap );
73 virtual ~XMLTextShapePropertySetContext_Impl();
75 using SvXMLPropertySetContext::CreateChildContext;
76 virtual SvXMLImportContext *CreateChildContext( USHORT nPrefix,
77 const OUString& rLocalName,
78 const Reference< XAttributeList >& xAttrList,
79 ::std::vector< XMLPropertyState > &rProperties,
80 const XMLPropertyState& rProp);
83 XMLTextShapePropertySetContext_Impl::XMLTextShapePropertySetContext_Impl(
84 SvXMLImport& rImport, sal_uInt16 nPrfx,
85 const OUString& rLName,
86 const Reference< XAttributeList > & xAttrList,
87 sal_uInt32 nFamily,
88 ::std::vector< XMLPropertyState > &rProps,
89 const UniReference < SvXMLImportPropertyMapper > &rMap ) :
90 XMLShapePropertySetContext( rImport, nPrfx, rLName, xAttrList, nFamily,
91 rProps, rMap )
95 XMLTextShapePropertySetContext_Impl::~XMLTextShapePropertySetContext_Impl()
99 SvXMLImportContext *XMLTextShapePropertySetContext_Impl::CreateChildContext(
100 sal_uInt16 nPrefix,
101 const OUString& rLocalName,
102 const Reference< XAttributeList > & xAttrList,
103 ::std::vector< XMLPropertyState > &rProperties,
104 const XMLPropertyState& rProp )
106 SvXMLImportContext *pContext = 0;
108 switch( mxMapper->getPropertySetMapper()
109 ->GetEntryContextId( rProp.mnIndex ) )
111 case CTF_TEXTCOLUMNS:
112 pContext = new XMLTextColumnsContext( GetImport(), nPrefix,
113 rLocalName, xAttrList, rProp,
114 rProperties );
115 break;
117 case CTF_BACKGROUND_URL:
118 DBG_ASSERT( rProp.mnIndex >= 3 &&
119 CTF_BACKGROUND_TRANSPARENCY ==
120 mxMapper->getPropertySetMapper()
121 ->GetEntryContextId( rProp.mnIndex-3 ) &&
122 CTF_BACKGROUND_POS == mxMapper->getPropertySetMapper()
123 ->GetEntryContextId( rProp.mnIndex-2 ) &&
124 CTF_BACKGROUND_FILTER == mxMapper->getPropertySetMapper()
125 ->GetEntryContextId( rProp.mnIndex-1 ),
126 "invalid property map!");
127 pContext =
128 new XMLBackgroundImageContext( GetImport(), nPrefix,
129 rLocalName, xAttrList,
130 rProp,
131 rProp.mnIndex-2,
132 rProp.mnIndex-1,
133 rProp.mnIndex-3,
134 rProperties );
135 break;
138 if( !pContext )
139 pContext = XMLShapePropertySetContext::CreateChildContext(
140 nPrefix, rLocalName, xAttrList, rProperties, rProp );
142 return pContext;
145 //-----------------------------------------------------------------------------
147 void XMLTextShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
148 const OUString& rLocalName,
149 const OUString& rValue )
151 if( XML_NAMESPACE_STYLE == nPrefixKey &&
152 IsXMLToken( rLocalName, XML_AUTO_UPDATE ) )
154 if( IsXMLToken( rValue, XML_TRUE ) )
155 bAutoUpdate = sal_True;
157 else
159 XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
163 TYPEINIT1( XMLTextShapeStyleContext, XMLShapeStyleContext );
165 XMLTextShapeStyleContext::XMLTextShapeStyleContext( SvXMLImport& rImport,
166 sal_uInt16 nPrfx, const OUString& rLName,
167 const Reference< XAttributeList > & xAttrList,
168 SvXMLStylesContext& rStyles, sal_uInt16 nFamily,
169 sal_Bool /*bDefaultStyle*/ ) :
170 XMLShapeStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles,
171 nFamily ),
172 sIsAutoUpdate( RTL_CONSTASCII_USTRINGPARAM( "IsAutoUpdate" ) ),
173 bAutoUpdate( sal_False )
177 XMLTextShapeStyleContext::~XMLTextShapeStyleContext()
181 SvXMLImportContext *XMLTextShapeStyleContext::CreateChildContext(
182 sal_uInt16 nPrefix,
183 const OUString& rLocalName,
184 const Reference< XAttributeList > & xAttrList )
186 SvXMLImportContext *pContext = 0;
188 if( XML_NAMESPACE_STYLE == nPrefix )
190 sal_uInt32 nFamily = 0;
191 if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
192 nFamily = XML_TYPE_PROP_TEXT;
193 else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
194 nFamily = XML_TYPE_PROP_PARAGRAPH;
195 else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
196 nFamily = XML_TYPE_PROP_GRAPHIC;
197 if( nFamily )
199 UniReference < SvXMLImportPropertyMapper > xImpPrMap =
200 GetStyles()->GetImportPropertyMapper( GetFamily() );
201 if( xImpPrMap.is() )
203 pContext = new XMLTextShapePropertySetContext_Impl(
204 GetImport(), nPrefix, rLocalName, xAttrList, nFamily,
205 GetProperties(), xImpPrMap );
209 else if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
210 IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
212 // create and remember events import context
213 // (for delayed processing of events)
214 pContext = new XMLEventsImportContext( GetImport(), nPrefix,
215 rLocalName);
216 xEventContext = pContext;
219 if( !pContext )
220 pContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName,
221 xAttrList );
223 return pContext;
226 void XMLTextShapeStyleContext::CreateAndInsert( sal_Bool bOverwrite )
228 XMLShapeStyleContext::CreateAndInsert( bOverwrite );
229 Reference < XStyle > xStyle = GetStyle();
230 if( !xStyle.is() || !(bOverwrite || IsNew()) )
231 return;
233 Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
234 Reference< XPropertySetInfo > xPropSetInfo =
235 xPropSet->getPropertySetInfo();
236 if( xPropSetInfo->hasPropertyByName( sIsAutoUpdate ) )
238 Any aAny;
239 sal_Bool bTmp = bAutoUpdate;
240 aAny.setValue( &bTmp, ::getBooleanCppuType() );
241 xPropSet->setPropertyValue( sIsAutoUpdate, aAny );
244 // tell the style about it's events (if applicable)
245 if( xEventContext.Is() )
247 // set event suppplier and release reference to context
248 Reference<XEventsSupplier> xEventsSupplier(xStyle, UNO_QUERY);
249 ((XMLEventsImportContext *)&xEventContext)->SetEvents(xEventsSupplier);
250 xEventContext = 0;
255 void XMLTextShapeStyleContext::Finish( sal_Bool bOverwrite )
257 XMLPropStyleContext::Finish( bOverwrite );