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 <tools/debug.hxx>
31 #ifndef _COM_SUN_STAR_DOCUMENT_XEVENTSSUPPLIER_HPP
32 #include <com/sun/star/document/XEventsSupplier.hpp>
33 #endif
34 #include "xmloff/xmlnmspe.hxx"
35 #include <xmloff/xmltoken.hxx>
36 #include "XMLTextPropertySetContext.hxx"
37 #include <xmloff/xmlimp.hxx>
38 #include <xmloff/XMLEventsImportContext.hxx>
39 #include "XMLShapePropertySetContext.hxx"
40 #include "XMLTextColumnsContext.hxx"
41 #include "XMLBackgroundImageContext.hxx"
42 #ifndef _XMLOFF_TXTPRMAP_HXX
43 #include <xmloff/txtprmap.hxx>
44 #endif
45 
46 #ifndef _XMLOFF_XMLTEXTSHAPESTYLECONTEXT_HXX
47 #include <xmloff/XMLTextShapeStyleContext.hxx>
48 #endif
49 
50 using ::rtl::OUString;
51 using ::rtl::OUStringBuffer;
52 
53 using namespace ::com::sun::star::document;
54 using namespace ::com::sun::star::uno;
55 using namespace ::com::sun::star::xml::sax;
56 using namespace ::com::sun::star::style;
57 using namespace ::com::sun::star::beans;
58 using namespace ::xmloff::token;
59 
60 class XMLTextShapePropertySetContext_Impl : public XMLShapePropertySetContext
61 {
62 public:
63 	XMLTextShapePropertySetContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
64 		const OUString& rLName,
65 		const Reference< XAttributeList >& xAttrList,
66 				 sal_uInt32 nFamily,
67 		::std::vector< XMLPropertyState > &rProps,
68 		const UniReference < SvXMLImportPropertyMapper > &rMap );
69 
70 	virtual ~XMLTextShapePropertySetContext_Impl();
71 
72     using SvXMLPropertySetContext::CreateChildContext;
73 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
74 		const OUString& rLocalName,
75 		const Reference< XAttributeList >& xAttrList,
76 	    ::std::vector< XMLPropertyState > &rProperties,
77 	    const XMLPropertyState& rProp);
78 };
79 
80 XMLTextShapePropertySetContext_Impl::XMLTextShapePropertySetContext_Impl(
81 				 SvXMLImport& rImport, sal_uInt16 nPrfx,
82 				 const OUString& rLName,
83 				 const Reference< XAttributeList > & xAttrList,
84 				 sal_uInt32 nFamily,
85 				 ::std::vector< XMLPropertyState > &rProps,
86 				 const UniReference < SvXMLImportPropertyMapper > &rMap ) :
87 	XMLShapePropertySetContext( rImport, nPrfx, rLName, xAttrList, nFamily,
88 								rProps, rMap )
89 {
90 }
91 
92 XMLTextShapePropertySetContext_Impl::~XMLTextShapePropertySetContext_Impl()
93 {
94 }
95 
96 SvXMLImportContext *XMLTextShapePropertySetContext_Impl::CreateChildContext(
97 				   sal_uInt16 nPrefix,
98 				   const OUString& rLocalName,
99 				   const Reference< XAttributeList > & xAttrList,
100 				   ::std::vector< XMLPropertyState > &rProperties,
101 				   const XMLPropertyState& rProp )
102 {
103 	SvXMLImportContext *pContext = 0;
104 
105 	switch( mxMapper->getPropertySetMapper()
106 					->GetEntryContextId( rProp.mnIndex ) )
107 	{
108 	case CTF_TEXTCOLUMNS:
109 		pContext = new XMLTextColumnsContext( GetImport(), nPrefix,
110 												   rLocalName, xAttrList, rProp,
111 												   rProperties );
112 		break;
113 
114 	case CTF_BACKGROUND_URL:
115 		DBG_ASSERT( rProp.mnIndex >= 3 &&
116 					CTF_BACKGROUND_TRANSPARENCY ==
117                         mxMapper->getPropertySetMapper()
118 						->GetEntryContextId( rProp.mnIndex-3 ) &&
119 					CTF_BACKGROUND_POS  == mxMapper->getPropertySetMapper()
120 						->GetEntryContextId( rProp.mnIndex-2 ) &&
121 					CTF_BACKGROUND_FILTER  == mxMapper->getPropertySetMapper()
122 						->GetEntryContextId( rProp.mnIndex-1 ),
123 					"invalid property map!");
124 		pContext =
125 			new XMLBackgroundImageContext( GetImport(), nPrefix,
126 										   rLocalName, xAttrList,
127 										   rProp,
128 										   rProp.mnIndex-2,
129 										   rProp.mnIndex-1,
130                                            rProp.mnIndex-3,
131 										   rProperties );
132 		break;
133 	}
134 
135 	if( !pContext )
136 		pContext = XMLShapePropertySetContext::CreateChildContext(
137 						nPrefix, rLocalName, xAttrList, rProperties, rProp );
138 
139 	return pContext;
140 }
141 
142 //-----------------------------------------------------------------------------
143 
144 void XMLTextShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
145 										const OUString& rLocalName,
146 										const OUString& rValue )
147 {
148 	if( XML_NAMESPACE_STYLE == nPrefixKey &&
149 		IsXMLToken( rLocalName, XML_AUTO_UPDATE ) )
150 	{
151 	  	if( IsXMLToken( rValue, XML_TRUE ) )
152 			bAutoUpdate = sal_True;
153 	}
154 	else
155 	{
156 		XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
157 	}
158 }
159 
160 TYPEINIT1( XMLTextShapeStyleContext, XMLShapeStyleContext );
161 
162 XMLTextShapeStyleContext::XMLTextShapeStyleContext( SvXMLImport& rImport,
163 		sal_uInt16 nPrfx, const OUString& rLName,
164 		const Reference< XAttributeList > & xAttrList,
165 		SvXMLStylesContext& rStyles, sal_uInt16 nFamily,
166 		sal_Bool /*bDefaultStyle*/ ) :
167 	XMLShapeStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles,
168 					      nFamily ),
169 	sIsAutoUpdate( RTL_CONSTASCII_USTRINGPARAM( "IsAutoUpdate" ) ),
170 	bAutoUpdate( sal_False )
171 {
172 }
173 
174 XMLTextShapeStyleContext::~XMLTextShapeStyleContext()
175 {
176 }
177 
178 SvXMLImportContext *XMLTextShapeStyleContext::CreateChildContext(
179 		sal_uInt16 nPrefix,
180 		const OUString& rLocalName,
181 		const Reference< XAttributeList > & xAttrList )
182 {
183 	SvXMLImportContext *pContext = 0;
184 
185 	if( XML_NAMESPACE_STYLE == nPrefix )
186 	{
187 		sal_uInt32 nFamily = 0;
188 		if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
189 			nFamily = XML_TYPE_PROP_TEXT;
190 		else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
191 			nFamily = XML_TYPE_PROP_PARAGRAPH;
192 		else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
193 			nFamily = XML_TYPE_PROP_GRAPHIC;
194 		if( nFamily )
195 		{
196 			UniReference < SvXMLImportPropertyMapper > xImpPrMap =
197 				GetStyles()->GetImportPropertyMapper( GetFamily() );
198 			if( xImpPrMap.is() )
199 			{
200 				pContext = new XMLTextShapePropertySetContext_Impl(
201 						GetImport(), nPrefix, rLocalName, xAttrList, nFamily,
202 						GetProperties(), xImpPrMap );
203 			}
204 		}
205 	}
206 	else if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
207 			  IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
208 	{
209 		// create and remember events import context
210 		// (for delayed processing of events)
211 		pContext = new XMLEventsImportContext( GetImport(), nPrefix,
212 												   rLocalName);
213 		xEventContext = pContext;
214 	}
215 
216 	if( !pContext )
217 		pContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName,
218 														  xAttrList );
219 
220 	return pContext;
221 }
222 
223 void XMLTextShapeStyleContext::CreateAndInsert( sal_Bool bOverwrite )
224 {
225 	XMLShapeStyleContext::CreateAndInsert( bOverwrite );
226 	Reference < XStyle > xStyle = GetStyle();
227 	if( !xStyle.is() || !(bOverwrite || IsNew()) )
228 		return;
229 
230 	Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
231 	Reference< XPropertySetInfo > xPropSetInfo =
232 				xPropSet->getPropertySetInfo();
233 	if( xPropSetInfo->hasPropertyByName( sIsAutoUpdate ) )
234 	{
235 		Any aAny;
236 		sal_Bool bTmp = bAutoUpdate;
237 		aAny.setValue( &bTmp, ::getBooleanCppuType() );
238 		xPropSet->setPropertyValue( sIsAutoUpdate, aAny );
239 	}
240 
241 	// tell the style about it's events (if applicable)
242 	if( xEventContext.Is() )
243 	{
244 		// set event suppplier and release reference to context
245 		Reference<XEventsSupplier> xEventsSupplier(xStyle, UNO_QUERY);
246 		((XMLEventsImportContext *)&xEventContext)->SetEvents(xEventsSupplier);
247 		xEventContext = 0;
248 	}
249 }
250 
251 
252 void XMLTextShapeStyleContext::Finish( sal_Bool bOverwrite )
253 {
254     XMLPropStyleContext::Finish( bOverwrite );
255 }
256