1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_xmloff.hxx"
24 #include <tools/debug.hxx>
25 #ifndef _COM_SUN_STAR_DOCUMENT_XEVENTSSUPPLIER_HPP
26 #include <com/sun/star/document/XEventsSupplier.hpp>
27 #endif
28 #include "xmloff/xmlnmspe.hxx"
29 #include <xmloff/xmltoken.hxx>
30 #include "XMLTextPropertySetContext.hxx"
31 #include <xmloff/xmlimp.hxx>
32 #include <xmloff/XMLEventsImportContext.hxx>
33 #include "XMLShapePropertySetContext.hxx"
34 #include "XMLTextColumnsContext.hxx"
35 #include "XMLBackgroundImageContext.hxx"
36 #ifndef _XMLOFF_TXTPRMAP_HXX
37 #include <xmloff/txtprmap.hxx>
38 #endif
39
40 #ifndef _XMLOFF_XMLTEXTSHAPESTYLECONTEXT_HXX
41 #include <xmloff/XMLTextShapeStyleContext.hxx>
42 #endif
43
44 using ::rtl::OUString;
45 using ::rtl::OUStringBuffer;
46
47 using namespace ::com::sun::star::document;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::xml::sax;
50 using namespace ::com::sun::star::style;
51 using namespace ::com::sun::star::beans;
52 using namespace ::xmloff::token;
53
54 class XMLTextShapePropertySetContext_Impl : public XMLShapePropertySetContext
55 {
56 public:
57 XMLTextShapePropertySetContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
58 const OUString& rLName,
59 const Reference< XAttributeList >& xAttrList,
60 sal_uInt32 nFamily,
61 ::std::vector< XMLPropertyState > &rProps,
62 const UniReference < SvXMLImportPropertyMapper > &rMap );
63
64 virtual ~XMLTextShapePropertySetContext_Impl();
65
66 using SvXMLPropertySetContext::CreateChildContext;
67 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
68 const OUString& rLocalName,
69 const Reference< XAttributeList >& xAttrList,
70 ::std::vector< XMLPropertyState > &rProperties,
71 const XMLPropertyState& rProp);
72 };
73
XMLTextShapePropertySetContext_Impl(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<XAttributeList> & xAttrList,sal_uInt32 nFamily,::std::vector<XMLPropertyState> & rProps,const UniReference<SvXMLImportPropertyMapper> & rMap)74 XMLTextShapePropertySetContext_Impl::XMLTextShapePropertySetContext_Impl(
75 SvXMLImport& rImport, sal_uInt16 nPrfx,
76 const OUString& rLName,
77 const Reference< XAttributeList > & xAttrList,
78 sal_uInt32 nFamily,
79 ::std::vector< XMLPropertyState > &rProps,
80 const UniReference < SvXMLImportPropertyMapper > &rMap ) :
81 XMLShapePropertySetContext( rImport, nPrfx, rLName, xAttrList, nFamily,
82 rProps, rMap )
83 {
84 }
85
~XMLTextShapePropertySetContext_Impl()86 XMLTextShapePropertySetContext_Impl::~XMLTextShapePropertySetContext_Impl()
87 {
88 }
89
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList,::std::vector<XMLPropertyState> & rProperties,const XMLPropertyState & rProp)90 SvXMLImportContext *XMLTextShapePropertySetContext_Impl::CreateChildContext(
91 sal_uInt16 nPrefix,
92 const OUString& rLocalName,
93 const Reference< XAttributeList > & xAttrList,
94 ::std::vector< XMLPropertyState > &rProperties,
95 const XMLPropertyState& rProp )
96 {
97 SvXMLImportContext *pContext = 0;
98
99 switch( mxMapper->getPropertySetMapper()
100 ->GetEntryContextId( rProp.mnIndex ) )
101 {
102 case CTF_TEXTCOLUMNS:
103 pContext = new XMLTextColumnsContext( GetImport(), nPrefix,
104 rLocalName, xAttrList, rProp,
105 rProperties );
106 break;
107
108 case CTF_BACKGROUND_URL:
109 DBG_ASSERT( rProp.mnIndex >= 3 &&
110 CTF_BACKGROUND_TRANSPARENCY ==
111 mxMapper->getPropertySetMapper()
112 ->GetEntryContextId( rProp.mnIndex-3 ) &&
113 CTF_BACKGROUND_POS == mxMapper->getPropertySetMapper()
114 ->GetEntryContextId( rProp.mnIndex-2 ) &&
115 CTF_BACKGROUND_FILTER == mxMapper->getPropertySetMapper()
116 ->GetEntryContextId( rProp.mnIndex-1 ),
117 "invalid property map!");
118 pContext =
119 new XMLBackgroundImageContext( GetImport(), nPrefix,
120 rLocalName, xAttrList,
121 rProp,
122 rProp.mnIndex-2,
123 rProp.mnIndex-1,
124 rProp.mnIndex-3,
125 rProperties );
126 break;
127 }
128
129 if( !pContext )
130 pContext = XMLShapePropertySetContext::CreateChildContext(
131 nPrefix, rLocalName, xAttrList, rProperties, rProp );
132
133 return pContext;
134 }
135
136 //-----------------------------------------------------------------------------
137
SetAttribute(sal_uInt16 nPrefixKey,const OUString & rLocalName,const OUString & rValue)138 void XMLTextShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
139 const OUString& rLocalName,
140 const OUString& rValue )
141 {
142 if( XML_NAMESPACE_STYLE == nPrefixKey &&
143 IsXMLToken( rLocalName, XML_AUTO_UPDATE ) )
144 {
145 if( IsXMLToken( rValue, XML_TRUE ) )
146 bAutoUpdate = sal_True;
147 }
148 else
149 {
150 XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
151 }
152 }
153
154 TYPEINIT1( XMLTextShapeStyleContext, XMLShapeStyleContext );
155
XMLTextShapeStyleContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<XAttributeList> & xAttrList,SvXMLStylesContext & rStyles,sal_uInt16 nFamily,sal_Bool)156 XMLTextShapeStyleContext::XMLTextShapeStyleContext( SvXMLImport& rImport,
157 sal_uInt16 nPrfx, const OUString& rLName,
158 const Reference< XAttributeList > & xAttrList,
159 SvXMLStylesContext& rStyles, sal_uInt16 nFamily,
160 sal_Bool /*bDefaultStyle*/ ) :
161 XMLShapeStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles,
162 nFamily ),
163 sIsAutoUpdate( RTL_CONSTASCII_USTRINGPARAM( "IsAutoUpdate" ) ),
164 bAutoUpdate( sal_False )
165 {
166 }
167
~XMLTextShapeStyleContext()168 XMLTextShapeStyleContext::~XMLTextShapeStyleContext()
169 {
170 }
171
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)172 SvXMLImportContext *XMLTextShapeStyleContext::CreateChildContext(
173 sal_uInt16 nPrefix,
174 const OUString& rLocalName,
175 const Reference< XAttributeList > & xAttrList )
176 {
177 SvXMLImportContext *pContext = 0;
178
179 if( XML_NAMESPACE_STYLE == nPrefix )
180 {
181 sal_uInt32 nFamily = 0;
182 if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
183 nFamily = XML_TYPE_PROP_TEXT;
184 else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
185 nFamily = XML_TYPE_PROP_PARAGRAPH;
186 else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
187 nFamily = XML_TYPE_PROP_GRAPHIC;
188 if( nFamily )
189 {
190 UniReference < SvXMLImportPropertyMapper > xImpPrMap =
191 GetStyles()->GetImportPropertyMapper( GetFamily() );
192 if( xImpPrMap.is() )
193 {
194 pContext = new XMLTextShapePropertySetContext_Impl(
195 GetImport(), nPrefix, rLocalName, xAttrList, nFamily,
196 GetProperties(), xImpPrMap );
197 }
198 }
199 }
200 else if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
201 IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
202 {
203 // create and remember events import context
204 // (for delayed processing of events)
205 pContext = new XMLEventsImportContext( GetImport(), nPrefix,
206 rLocalName);
207 xEventContext = pContext;
208 }
209
210 if( !pContext )
211 pContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName,
212 xAttrList );
213
214 return pContext;
215 }
216
CreateAndInsert(sal_Bool bOverwrite)217 void XMLTextShapeStyleContext::CreateAndInsert( sal_Bool bOverwrite )
218 {
219 XMLShapeStyleContext::CreateAndInsert( bOverwrite );
220 Reference < XStyle > xStyle = GetStyle();
221 if( !xStyle.is() || !(bOverwrite || IsNew()) )
222 return;
223
224 Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
225 Reference< XPropertySetInfo > xPropSetInfo =
226 xPropSet->getPropertySetInfo();
227 if( xPropSetInfo->hasPropertyByName( sIsAutoUpdate ) )
228 {
229 Any aAny;
230 sal_Bool bTmp = bAutoUpdate;
231 aAny.setValue( &bTmp, ::getBooleanCppuType() );
232 xPropSet->setPropertyValue( sIsAutoUpdate, aAny );
233 }
234
235 // tell the style about it's events (if applicable)
236 if( xEventContext.Is() )
237 {
238 // set event suppplier and release reference to context
239 Reference<XEventsSupplier> xEventsSupplier(xStyle, UNO_QUERY);
240 ((XMLEventsImportContext *)&xEventContext)->SetEvents(xEventsSupplier);
241 xEventContext = 0;
242 }
243 }
244
245
Finish(sal_Bool bOverwrite)246 void XMLTextShapeStyleContext::Finish( sal_Bool bOverwrite )
247 {
248 XMLPropStyleContext::Finish( bOverwrite );
249 }
250
251 /* vim: set noet sw=4 ts=4: */
252