xref: /AOO41X/main/xmloff/source/forms/elementimport.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 
31*cdf0e10cSrcweir #include "elementimport.hxx"
32*cdf0e10cSrcweir #include "xmloff/xmlimp.hxx"
33*cdf0e10cSrcweir #include "xmloff/nmspmap.hxx"
34*cdf0e10cSrcweir #include "xmloff/xmluconv.hxx"
35*cdf0e10cSrcweir #include "strings.hxx"
36*cdf0e10cSrcweir #include "callbacks.hxx"
37*cdf0e10cSrcweir #include "attriblistmerge.hxx"
38*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
39*cdf0e10cSrcweir #include "eventimport.hxx"
40*cdf0e10cSrcweir #include "xmloff/txtstyli.hxx"
41*cdf0e10cSrcweir #include "formenums.hxx"
42*cdf0e10cSrcweir #include "xmloff/xmltoken.hxx"
43*cdf0e10cSrcweir #include "gridcolumnproptranslator.hxx"
44*cdf0e10cSrcweir #include "property_description.hxx"
45*cdf0e10cSrcweir #include "property_meta_data.hxx"
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir /** === begin UNO includes === **/
48*cdf0e10cSrcweir #include <com/sun/star/text/XText.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/util/XCloneable.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/form/FormComponentType.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/awt/ImagePosition.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertySet.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyContainer.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
55*cdf0e10cSrcweir /** === end UNO includes === **/
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir #include <tools/urlobj.hxx>
58*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
59*cdf0e10cSrcweir #include <tools/time.hxx>
60*cdf0e10cSrcweir #include <rtl/logfile.hxx>
61*cdf0e10cSrcweir #include <comphelper/extract.hxx>
62*cdf0e10cSrcweir #include <comphelper/types.hxx>
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir #include <algorithm>
65*cdf0e10cSrcweir #include <functional>
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir //.........................................................................
68*cdf0e10cSrcweir namespace xmloff
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir //.........................................................................
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir     using namespace ::xmloff::token;
73*cdf0e10cSrcweir 	using namespace ::com::sun::star;
74*cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
75*cdf0e10cSrcweir 	using namespace ::com::sun::star::awt;
76*cdf0e10cSrcweir 	using namespace ::com::sun::star::container;
77*cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
78*cdf0e10cSrcweir 	using namespace ::com::sun::star::script;
79*cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
80*cdf0e10cSrcweir 	using namespace ::com::sun::star::form;
81*cdf0e10cSrcweir 	using namespace ::com::sun::star::xml;
82*cdf0e10cSrcweir 	using namespace ::com::sun::star::util;
83*cdf0e10cSrcweir 	using namespace ::com::sun::star::text;
84*cdf0e10cSrcweir     using namespace ::comphelper;
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir #define PROPID_VALUE			1
87*cdf0e10cSrcweir #define PROPID_CURRENT_VALUE	2
88*cdf0e10cSrcweir #define PROPID_MIN_VALUE		3
89*cdf0e10cSrcweir #define PROPID_MAX_VALUE		4
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 	//=====================================================================
92*cdf0e10cSrcweir 	struct PropertyValueLess
93*cdf0e10cSrcweir 	{
94*cdf0e10cSrcweir 		sal_Bool operator()(const PropertyValue& _rLeft, const PropertyValue& _rRight)
95*cdf0e10cSrcweir 		{
96*cdf0e10cSrcweir 			return _rLeft.Name < _rRight.Name;
97*cdf0e10cSrcweir 		}
98*cdf0e10cSrcweir 	};
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 	//=====================================================================
101*cdf0e10cSrcweir 	struct PropertyValueCompare : public ::std::binary_function< PropertyValue, ::rtl::OUString, bool>
102*cdf0e10cSrcweir 	{
103*cdf0e10cSrcweir 		bool operator() (const PropertyValue& lhs, const ::rtl::OUString& rhs) const
104*cdf0e10cSrcweir 		{
105*cdf0e10cSrcweir 			return lhs.Name == rhs;
106*cdf0e10cSrcweir 		}
107*cdf0e10cSrcweir 		bool operator() (const ::rtl::OUString& lhs, const PropertyValue& rhs) const
108*cdf0e10cSrcweir 		{
109*cdf0e10cSrcweir 			return lhs == rhs.Name;
110*cdf0e10cSrcweir 		}
111*cdf0e10cSrcweir 	};
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 	//=====================================================================
114*cdf0e10cSrcweir 	template <class ELEMENT>
115*cdf0e10cSrcweir 	void pushBackSequenceElement(Sequence< ELEMENT >& _rContainer, const ELEMENT& _rElement)
116*cdf0e10cSrcweir 	{
117*cdf0e10cSrcweir 		sal_Int32 nLen = _rContainer.getLength();
118*cdf0e10cSrcweir 		_rContainer.realloc(nLen + 1);
119*cdf0e10cSrcweir 		_rContainer[nLen] = _rElement;
120*cdf0e10cSrcweir 	}
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 	//=====================================================================
123*cdf0e10cSrcweir 	//= OElementNameMap
124*cdf0e10cSrcweir 	//=====================================================================
125*cdf0e10cSrcweir 	//---------------------------------------------------------------------
126*cdf0e10cSrcweir 	OElementNameMap::MapString2Element	OElementNameMap::s_sElementTranslations;
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir 	//---------------------------------------------------------------------
129*cdf0e10cSrcweir 	const OControlElement::ElementType& operator ++(OControlElement::ElementType& _e)
130*cdf0e10cSrcweir 	{
131*cdf0e10cSrcweir 		OControlElement::ElementType e = _e;
132*cdf0e10cSrcweir 		sal_Int32 nAsInt = static_cast<sal_Int32>(e);
133*cdf0e10cSrcweir 		_e = static_cast<OControlElement::ElementType>( ++nAsInt );
134*cdf0e10cSrcweir 		return _e;
135*cdf0e10cSrcweir 	}
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 	//---------------------------------------------------------------------
138*cdf0e10cSrcweir 	OControlElement::ElementType OElementNameMap::getElementType(const ::rtl::OUString& _rName)
139*cdf0e10cSrcweir 	{
140*cdf0e10cSrcweir 		if ( s_sElementTranslations.empty() )
141*cdf0e10cSrcweir 		{	// initialize
142*cdf0e10cSrcweir 			for (ElementType eType=(ElementType)0; eType<UNKNOWN; ++eType)
143*cdf0e10cSrcweir 				s_sElementTranslations[::rtl::OUString::createFromAscii(getElementName(eType))] = eType;
144*cdf0e10cSrcweir 		}
145*cdf0e10cSrcweir 		ConstMapString2ElementIterator aPos = s_sElementTranslations.find(_rName);
146*cdf0e10cSrcweir 		if (s_sElementTranslations.end() != aPos)
147*cdf0e10cSrcweir 			return aPos->second;
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 		return UNKNOWN;
150*cdf0e10cSrcweir 	}
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 	//=====================================================================
153*cdf0e10cSrcweir 	//= OElementImport
154*cdf0e10cSrcweir 	//=====================================================================
155*cdf0e10cSrcweir 	//---------------------------------------------------------------------
156*cdf0e10cSrcweir 	OElementImport::OElementImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
157*cdf0e10cSrcweir 			const Reference< XNameContainer >& _rxParentContainer)
158*cdf0e10cSrcweir 		:OPropertyImport(_rImport, _nPrefix, _rName)
159*cdf0e10cSrcweir 		,m_rFormImport(_rImport)
160*cdf0e10cSrcweir 		,m_rEventManager(_rEventManager)
161*cdf0e10cSrcweir 		,m_pStyleElement( NULL )
162*cdf0e10cSrcweir         ,m_xParentContainer(_rxParentContainer)
163*cdf0e10cSrcweir         ,m_bImplicitGenericAttributeHandling( true )
164*cdf0e10cSrcweir 	{
165*cdf0e10cSrcweir 		OSL_ENSURE(m_xParentContainer.is(), "OElementImport::OElementImport: invalid parent container!");
166*cdf0e10cSrcweir 	}
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir     //---------------------------------------------------------------------
169*cdf0e10cSrcweir     OElementImport::~OElementImport()
170*cdf0e10cSrcweir     {
171*cdf0e10cSrcweir     }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 	//---------------------------------------------------------------------
174*cdf0e10cSrcweir     ::rtl::OUString OElementImport::determineDefaultServiceName() const
175*cdf0e10cSrcweir     {
176*cdf0e10cSrcweir         return ::rtl::OUString();
177*cdf0e10cSrcweir     }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 	//---------------------------------------------------------------------
180*cdf0e10cSrcweir 	void OElementImport::StartElement(const Reference< sax::XAttributeList >& _rxAttrList)
181*cdf0e10cSrcweir 	{
182*cdf0e10cSrcweir 		ENTER_LOG_CONTEXT( "xmloff::OElementImport - importing one element" );
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir         const SvXMLNamespaceMap& rMap = m_rContext.getGlobalContext().GetNamespaceMap();
185*cdf0e10cSrcweir         const ::rtl::OUString sImplNameAttribute = rMap.GetQNameByKey( XML_NAMESPACE_FORM, GetXMLToken( XML_CONTROL_IMPLEMENTATION ) );
186*cdf0e10cSrcweir         const ::rtl::OUString sControlImplementation = _rxAttrList->getValueByName( sImplNameAttribute );
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir         // retrieve the service name
189*cdf0e10cSrcweir 		if ( sControlImplementation.getLength() > 0 )
190*cdf0e10cSrcweir         {
191*cdf0e10cSrcweir 		    ::rtl::OUString sOOoImplementationName;
192*cdf0e10cSrcweir 		    const sal_uInt16 nImplPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sControlImplementation, &sOOoImplementationName );
193*cdf0e10cSrcweir 		    m_sServiceName = ( nImplPrefix == XML_NAMESPACE_OOO ) ? sOOoImplementationName : sControlImplementation;
194*cdf0e10cSrcweir         }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir         if ( !m_sServiceName.getLength() )
197*cdf0e10cSrcweir             determineDefaultServiceName();
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir         // create the object *now*. This allows setting properties in the various handleAttribute methods.
200*cdf0e10cSrcweir         // (Though currently not all code is migrated to this pattern, most attributes are still handled
201*cdf0e10cSrcweir         // by remembering the value (via implPushBackPropertyValue), and setting the correct property value
202*cdf0e10cSrcweir         // later (in OControlImport::StartElement).)
203*cdf0e10cSrcweir 		m_xElement = createElement();
204*cdf0e10cSrcweir         if ( m_xElement.is() )
205*cdf0e10cSrcweir             m_xInfo = m_xElement->getPropertySetInfo();
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir         // call the base class
208*cdf0e10cSrcweir 		OPropertyImport::StartElement( _rxAttrList );
209*cdf0e10cSrcweir 	}
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 	//---------------------------------------------------------------------
212*cdf0e10cSrcweir 	SvXMLImportContext* OElementImport::CreateChildContext(sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
213*cdf0e10cSrcweir 		const Reference< sax::XAttributeList >& _rxAttrList)
214*cdf0e10cSrcweir 	{
215*cdf0e10cSrcweir 		if( token::IsXMLToken(_rLocalName, token::XML_EVENT_LISTENERS) && (XML_NAMESPACE_OFFICE == _nPrefix))
216*cdf0e10cSrcweir 			return new OFormEventsImportContext(m_rFormImport.getGlobalContext(), _nPrefix, _rLocalName, *this);
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir 		return OPropertyImport::CreateChildContext(_nPrefix, _rLocalName, _rxAttrList);
219*cdf0e10cSrcweir 	}
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 	//---------------------------------------------------------------------
222*cdf0e10cSrcweir 	void OElementImport::EndElement()
223*cdf0e10cSrcweir 	{
224*cdf0e10cSrcweir 		OSL_ENSURE(m_xElement.is(), "OElementImport::EndElement: invalid element created!");
225*cdf0e10cSrcweir 		if (!m_xElement.is())
226*cdf0e10cSrcweir 			return;
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir         // apply the non-generic properties
229*cdf0e10cSrcweir         implApplySpecificProperties();
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 		// set the generic properties
232*cdf0e10cSrcweir 		implApplyGenericProperties();
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir 		// set the style properties
235*cdf0e10cSrcweir 		if ( m_pStyleElement && m_xElement.is() )
236*cdf0e10cSrcweir 		{
237*cdf0e10cSrcweir             Reference< XPropertySet > xPropTranslation =
238*cdf0e10cSrcweir                 new OGridColumnPropertyTranslator( Reference< XMultiPropertySet >( m_xElement, UNO_QUERY ) );
239*cdf0e10cSrcweir 			const_cast< XMLTextStyleContext* >( m_pStyleElement )->FillPropertySet( xPropTranslation );
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir 			const ::rtl::OUString sNumberStyleName = const_cast< XMLTextStyleContext* >( m_pStyleElement )->GetDataStyleName( );
242*cdf0e10cSrcweir 			if ( sNumberStyleName.getLength() )
243*cdf0e10cSrcweir 				// the style also has a number (sub) style
244*cdf0e10cSrcweir 				m_rContext.applyControlNumberStyle( m_xElement, sNumberStyleName );
245*cdf0e10cSrcweir 		}
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 		// insert the element into the parent container
248*cdf0e10cSrcweir 		if (!m_sName.getLength())
249*cdf0e10cSrcweir 		{
250*cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "OElementImport::EndElement: did not find a name attribute!");
251*cdf0e10cSrcweir 			m_sName = implGetDefaultName();
252*cdf0e10cSrcweir 		}
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 		m_xParentContainer->insertByName(m_sName, makeAny(m_xElement));
255*cdf0e10cSrcweir 		LEAVE_LOG_CONTEXT( );
256*cdf0e10cSrcweir 	}
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 	//---------------------------------------------------------------------
259*cdf0e10cSrcweir 	void OElementImport::implApplySpecificProperties()
260*cdf0e10cSrcweir     {
261*cdf0e10cSrcweir         if ( m_aValues.empty() )
262*cdf0e10cSrcweir             return;
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 		// set all the properties we collected
265*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
266*cdf0e10cSrcweir 		// check if the object has all the properties
267*cdf0e10cSrcweir 		// (We do this in the non-pro version only. Doing it all the time would be much to expensive)
268*cdf0e10cSrcweir 		if ( m_xInfo.is() )
269*cdf0e10cSrcweir 		{
270*cdf0e10cSrcweir             PropertyValueArray::const_iterator aEnd = m_aValues.end();
271*cdf0e10cSrcweir 			for (	PropertyValueArray::iterator aCheck = m_aValues.begin();
272*cdf0e10cSrcweir 					aCheck != aEnd;
273*cdf0e10cSrcweir 					++aCheck
274*cdf0e10cSrcweir 				)
275*cdf0e10cSrcweir 			{
276*cdf0e10cSrcweir 				OSL_ENSURE(m_xInfo->hasPropertyByName(aCheck->Name),
277*cdf0e10cSrcweir 						::rtl::OString("OElementImport::implApplySpecificProperties: read a property (")
278*cdf0e10cSrcweir 					+=	::rtl::OString(aCheck->Name.getStr(), aCheck->Name.getLength(), RTL_TEXTENCODING_ASCII_US)
279*cdf0e10cSrcweir 					+=	::rtl::OString(") which does not exist on the element!"));
280*cdf0e10cSrcweir 			}
281*cdf0e10cSrcweir 		}
282*cdf0e10cSrcweir #endif
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 		// set the properties
285*cdf0e10cSrcweir 		const Reference< XMultiPropertySet > xMultiProps(m_xElement, UNO_QUERY);
286*cdf0e10cSrcweir 		sal_Bool bSuccess = sal_False;
287*cdf0e10cSrcweir 		if (xMultiProps.is())
288*cdf0e10cSrcweir 		{
289*cdf0e10cSrcweir 			// translate our properties so that the XMultiPropertySet can handle them
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir 			// sort our property value array so that we can use it in a setPropertyValues
292*cdf0e10cSrcweir 			::std::sort( m_aValues.begin(), m_aValues.end(), PropertyValueLess());
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 			// the names
295*cdf0e10cSrcweir 			Sequence< ::rtl::OUString > aNames(m_aValues.size());
296*cdf0e10cSrcweir 			::rtl::OUString* pNames = aNames.getArray();
297*cdf0e10cSrcweir 			// the values
298*cdf0e10cSrcweir 			Sequence< Any > aValues(m_aValues.size());
299*cdf0e10cSrcweir 			Any* pValues = aValues.getArray();
300*cdf0e10cSrcweir 			// copy
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir             PropertyValueArray::iterator aEnd = m_aValues.end();
303*cdf0e10cSrcweir 			for	(	PropertyValueArray::iterator aPropValues = m_aValues.begin();
304*cdf0e10cSrcweir 					aPropValues != aEnd;
305*cdf0e10cSrcweir 					++aPropValues, ++pNames, ++pValues
306*cdf0e10cSrcweir 				)
307*cdf0e10cSrcweir 			{
308*cdf0e10cSrcweir 				*pNames = aPropValues->Name;
309*cdf0e10cSrcweir 				*pValues = aPropValues->Value;
310*cdf0e10cSrcweir 			}
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir 			try
313*cdf0e10cSrcweir 			{
314*cdf0e10cSrcweir 				xMultiProps->setPropertyValues(aNames, aValues);
315*cdf0e10cSrcweir 				bSuccess = sal_True;
316*cdf0e10cSrcweir 			}
317*cdf0e10cSrcweir 			catch(Exception&)
318*cdf0e10cSrcweir 			{
319*cdf0e10cSrcweir 				OSL_ENSURE(sal_False, "OElementImport::implApplySpecificProperties: could not set the properties (using the XMultiPropertySet)!");
320*cdf0e10cSrcweir 			}
321*cdf0e10cSrcweir 		}
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir 		if (!bSuccess)
324*cdf0e10cSrcweir 		{	// no XMultiPropertySet or setting all properties at once failed
325*cdf0e10cSrcweir             PropertyValueArray::iterator aEnd = m_aValues.end();
326*cdf0e10cSrcweir 			for	(	PropertyValueArray::iterator aPropValues = m_aValues.begin();
327*cdf0e10cSrcweir 					aPropValues != aEnd;
328*cdf0e10cSrcweir 					++aPropValues
329*cdf0e10cSrcweir 				)
330*cdf0e10cSrcweir 			{
331*cdf0e10cSrcweir 				// this try/catch here is expensive, but because this is just a fallback which should normally not be
332*cdf0e10cSrcweir 				// used it's acceptable this way ...
333*cdf0e10cSrcweir 				try
334*cdf0e10cSrcweir 				{
335*cdf0e10cSrcweir 					m_xElement->setPropertyValue(aPropValues->Name, aPropValues->Value);
336*cdf0e10cSrcweir 				}
337*cdf0e10cSrcweir 				catch(Exception&)
338*cdf0e10cSrcweir 				{
339*cdf0e10cSrcweir 					OSL_ENSURE(sal_False,
340*cdf0e10cSrcweir 							::rtl::OString("OElementImport::implApplySpecificProperties: could not set the property \"")
341*cdf0e10cSrcweir 						+=	::rtl::OString(aPropValues->Name.getStr(), aPropValues->Name.getLength(), RTL_TEXTENCODING_ASCII_US)
342*cdf0e10cSrcweir 						+=	::rtl::OString("\"!"));
343*cdf0e10cSrcweir 				}
344*cdf0e10cSrcweir 			}
345*cdf0e10cSrcweir 		}
346*cdf0e10cSrcweir     }
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir 	//---------------------------------------------------------------------
349*cdf0e10cSrcweir 	void OElementImport::implApplyGenericProperties()
350*cdf0e10cSrcweir 	{
351*cdf0e10cSrcweir         if ( m_aGenericValues.empty() )
352*cdf0e10cSrcweir             return;
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir         Reference< XPropertyContainer > xDynamicProperties( m_xElement, UNO_QUERY );
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir         PropertyValueArray::iterator aEnd = m_aGenericValues.end();
357*cdf0e10cSrcweir 		for (   PropertyValueArray::iterator aPropValues =
358*cdf0e10cSrcweir 				m_aGenericValues.begin();
359*cdf0e10cSrcweir 				aPropValues != aEnd;
360*cdf0e10cSrcweir 				++aPropValues
361*cdf0e10cSrcweir 			)
362*cdf0e10cSrcweir 		{
363*cdf0e10cSrcweir 			// check property type for numeric types before setting
364*cdf0e10cSrcweir 			// the property
365*cdf0e10cSrcweir 			try
366*cdf0e10cSrcweir 			{
367*cdf0e10cSrcweir                 // if such a property does not yet exist at the element, create it if necessary
368*cdf0e10cSrcweir                 const bool bExistentProperty = m_xInfo->hasPropertyByName( aPropValues->Name );
369*cdf0e10cSrcweir                 if ( !bExistentProperty )
370*cdf0e10cSrcweir                 {
371*cdf0e10cSrcweir                     if ( !xDynamicProperties.is() )
372*cdf0e10cSrcweir                     {
373*cdf0e10cSrcweir                     #if OSL_DEBUG_LEVEL > 0
374*cdf0e10cSrcweir                         ::rtl::OString aMessage( "OElementImport::implApplyGenericProperties: encountered an unknown property (" );
375*cdf0e10cSrcweir                         aMessage += ::rtl::OUStringToOString( aPropValues->Name, RTL_TEXTENCODING_ASCII_US );
376*cdf0e10cSrcweir                         aMessage += "), but component is no PropertyBag!";
377*cdf0e10cSrcweir                         OSL_ENSURE( false, aMessage.getStr() );
378*cdf0e10cSrcweir                     #endif
379*cdf0e10cSrcweir                         continue;
380*cdf0e10cSrcweir                     }
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir                     xDynamicProperties->addProperty(
383*cdf0e10cSrcweir                         aPropValues->Name,
384*cdf0e10cSrcweir                         PropertyAttribute::BOUND | PropertyAttribute::REMOVEABLE,
385*cdf0e10cSrcweir                         aPropValues->Value
386*cdf0e10cSrcweir                     );
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir                     // re-fetch the PropertySetInfo
389*cdf0e10cSrcweir                     m_xInfo = m_xElement->getPropertySetInfo();
390*cdf0e10cSrcweir                 }
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir                 // determine the type of the value (source for the following conversion)
393*cdf0e10cSrcweir 				TypeClass eValueTypeClass = aPropValues->Value.getValueTypeClass();
394*cdf0e10cSrcweir 				const sal_Bool bValueIsSequence = TypeClass_SEQUENCE == eValueTypeClass;
395*cdf0e10cSrcweir 				if ( bValueIsSequence )
396*cdf0e10cSrcweir 				{
397*cdf0e10cSrcweir                     uno::Type aSimpleType( getSequenceElementType( aPropValues->Value.getValueType() ) );
398*cdf0e10cSrcweir 					eValueTypeClass = aSimpleType.getTypeClass();
399*cdf0e10cSrcweir 				}
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir                 // determine the type of the property (target for the following conversion)
402*cdf0e10cSrcweir                 const Property aProperty( m_xInfo->getPropertyByName( aPropValues->Name ) );
403*cdf0e10cSrcweir 				TypeClass ePropTypeClass = aProperty.Type.getTypeClass();
404*cdf0e10cSrcweir 				const sal_Bool bPropIsSequence = TypeClass_SEQUENCE == ePropTypeClass;
405*cdf0e10cSrcweir 				if( bPropIsSequence )
406*cdf0e10cSrcweir 				{
407*cdf0e10cSrcweir                     uno::Type aSimpleType( ::comphelper::getSequenceElementType( aProperty.Type ) );
408*cdf0e10cSrcweir 					ePropTypeClass = aSimpleType.getTypeClass();
409*cdf0e10cSrcweir 				}
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir                 if ( bPropIsSequence != bValueIsSequence )
412*cdf0e10cSrcweir                 {
413*cdf0e10cSrcweir                     OSL_ENSURE( false, "OElementImport::implApplyGenericProperties: either both value and property should be a sequence, or none of them!" );
414*cdf0e10cSrcweir                     continue;
415*cdf0e10cSrcweir                 }
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir                 if ( bValueIsSequence )
418*cdf0e10cSrcweir                 {
419*cdf0e10cSrcweir                     OSL_ENSURE( eValueTypeClass == TypeClass_ANY,
420*cdf0e10cSrcweir                         "OElementImport::implApplyGenericProperties: only ANYs should have been imported as generic list property!" );
421*cdf0e10cSrcweir                         // (OPropertyImport should produce only Sequencer< Any >, since it cannot know the real type
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir                     OSL_ENSURE( ePropTypeClass == TypeClass_SHORT,
424*cdf0e10cSrcweir                         "OElementImport::implApplyGenericProperties: conversion to sequences other than 'sequence< short >' not implemented, yet!" );
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir                     Sequence< Any > aXMLValueList;
427*cdf0e10cSrcweir                     aPropValues->Value >>= aXMLValueList;
428*cdf0e10cSrcweir                     Sequence< sal_Int16 > aPropertyValueList( aXMLValueList.getLength() );
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir                     const Any*       pXMLValue = aXMLValueList.getConstArray();
431*cdf0e10cSrcweir                           sal_Int16* pPropValue = aPropertyValueList.getArray();
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir                     for ( sal_Int32 i=0; i<aXMLValueList.getLength(); ++i, ++pXMLValue, ++pPropValue )
434*cdf0e10cSrcweir                     {
435*cdf0e10cSrcweir                         // only value sequences of numeric types implemented so far.
436*cdf0e10cSrcweir                         double nVal( 0 );
437*cdf0e10cSrcweir                         OSL_VERIFY( *pXMLValue >>= nVal );
438*cdf0e10cSrcweir                         *pPropValue = static_cast< sal_Int16 >( nVal );
439*cdf0e10cSrcweir                     }
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir                     aPropValues->Value <<= aPropertyValueList;
442*cdf0e10cSrcweir                 }
443*cdf0e10cSrcweir                 else if ( ePropTypeClass != eValueTypeClass )
444*cdf0e10cSrcweir 				{
445*cdf0e10cSrcweir                     switch ( eValueTypeClass )
446*cdf0e10cSrcweir                     {
447*cdf0e10cSrcweir                     case TypeClass_DOUBLE:
448*cdf0e10cSrcweir                     {
449*cdf0e10cSrcweir 					    double nVal = 0;
450*cdf0e10cSrcweir 					    aPropValues->Value >>= nVal;
451*cdf0e10cSrcweir 					    switch( ePropTypeClass )
452*cdf0e10cSrcweir 					    {
453*cdf0e10cSrcweir 					    case TypeClass_BYTE:
454*cdf0e10cSrcweir                             aPropValues->Value <<= static_cast< sal_Int8 >( nVal );
455*cdf0e10cSrcweir                             break;
456*cdf0e10cSrcweir 					    case TypeClass_SHORT:
457*cdf0e10cSrcweir                             aPropValues->Value <<= static_cast< sal_Int16 >( nVal );
458*cdf0e10cSrcweir 						    break;
459*cdf0e10cSrcweir 					    case TypeClass_LONG:
460*cdf0e10cSrcweir 					    case TypeClass_ENUM:
461*cdf0e10cSrcweir                             aPropValues->Value <<= static_cast< sal_Int32 >( nVal );
462*cdf0e10cSrcweir 						    break;
463*cdf0e10cSrcweir 					    case TypeClass_HYPER:
464*cdf0e10cSrcweir                             aPropValues->Value <<= static_cast< sal_Int64 >( nVal );
465*cdf0e10cSrcweir 						    break;
466*cdf0e10cSrcweir                         default:
467*cdf0e10cSrcweir                             OSL_ENSURE( false, "OElementImport::implApplyGenericProperties: unsupported value type!" );
468*cdf0e10cSrcweir                             break;
469*cdf0e10cSrcweir 					    }
470*cdf0e10cSrcweir                     }
471*cdf0e10cSrcweir                     break;
472*cdf0e10cSrcweir                     default:
473*cdf0e10cSrcweir                         OSL_ENSURE( false, "OElementImport::implApplyGenericProperties: non-double values not supported!" );
474*cdf0e10cSrcweir                         break;
475*cdf0e10cSrcweir                     }
476*cdf0e10cSrcweir 				}
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir                 m_xElement->setPropertyValue( aPropValues->Name, aPropValues->Value );
479*cdf0e10cSrcweir 			}
480*cdf0e10cSrcweir 			catch(Exception&)
481*cdf0e10cSrcweir 			{
482*cdf0e10cSrcweir 				OSL_ENSURE(sal_False,
483*cdf0e10cSrcweir 						::rtl::OString("OElementImport::EndElement: could not set the property \"")
484*cdf0e10cSrcweir 					+=	::rtl::OString(aPropValues->Name.getStr(), aPropValues->Name.getLength(), RTL_TEXTENCODING_ASCII_US)
485*cdf0e10cSrcweir 					+=	::rtl::OString("\"!"));
486*cdf0e10cSrcweir 			}
487*cdf0e10cSrcweir 		}
488*cdf0e10cSrcweir 	}
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir 	//---------------------------------------------------------------------
491*cdf0e10cSrcweir 	::rtl::OUString OElementImport::implGetDefaultName() const
492*cdf0e10cSrcweir 	{
493*cdf0e10cSrcweir 		// no optimization here. If this method gets called, the XML stream did not contain a name for the
494*cdf0e10cSrcweir 		// element, which is a heavy error. So in this case we don't care for performance
495*cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aNames = m_xParentContainer->getElementNames();
496*cdf0e10cSrcweir 		static const ::rtl::OUString sUnnamedName = ::rtl::OUString::createFromAscii("unnamed");
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir 		::rtl::OUString sReturn;
499*cdf0e10cSrcweir 		const ::rtl::OUString* pNames = NULL;
500*cdf0e10cSrcweir 		const ::rtl::OUString* pNamesEnd = aNames.getConstArray() + aNames.getLength();
501*cdf0e10cSrcweir 		for (sal_Int32 i=0; i<32768; ++i)	// the limit is nearly arbitrary ...
502*cdf0e10cSrcweir 		{
503*cdf0e10cSrcweir 			// assemble the new name (suggestion)
504*cdf0e10cSrcweir 			sReturn = sUnnamedName;
505*cdf0e10cSrcweir 			sReturn += ::rtl::OUString::valueOf(i);
506*cdf0e10cSrcweir 			// check the existence (this is the bad performance part ....)
507*cdf0e10cSrcweir 			for (pNames = aNames.getConstArray(); pNames<pNamesEnd; ++pNames)
508*cdf0e10cSrcweir 			{
509*cdf0e10cSrcweir 				if (*pNames == sReturn)
510*cdf0e10cSrcweir 				{
511*cdf0e10cSrcweir 					break;
512*cdf0e10cSrcweir 				}
513*cdf0e10cSrcweir 			}
514*cdf0e10cSrcweir 			if (pNames<pNamesEnd)
515*cdf0e10cSrcweir 				// found the name
516*cdf0e10cSrcweir 				continue;
517*cdf0e10cSrcweir 			return sReturn;
518*cdf0e10cSrcweir 		}
519*cdf0e10cSrcweir 		OSL_ENSURE(sal_False, "OElementImport::implGetDefaultName: did not find a free name!");
520*cdf0e10cSrcweir 		return sUnnamedName;
521*cdf0e10cSrcweir 	}
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir 	//---------------------------------------------------------------------
524*cdf0e10cSrcweir     PropertyGroups::const_iterator OElementImport::impl_matchPropertyGroup( const PropertyGroups& i_propertyGroups ) const
525*cdf0e10cSrcweir     {
526*cdf0e10cSrcweir         ENSURE_OR_RETURN( m_xInfo.is(), "OElementImport::impl_matchPropertyGroup: no property set info!", i_propertyGroups.end() );
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir         for (   PropertyGroups::const_iterator group = i_propertyGroups.begin();
529*cdf0e10cSrcweir                 group != i_propertyGroups.end();
530*cdf0e10cSrcweir                 ++group
531*cdf0e10cSrcweir             )
532*cdf0e10cSrcweir         {
533*cdf0e10cSrcweir             bool missingProp = false;
534*cdf0e10cSrcweir             for (   PropertyDescriptionList::const_iterator prop = group->begin();
535*cdf0e10cSrcweir                     prop != group->end();
536*cdf0e10cSrcweir                     ++prop
537*cdf0e10cSrcweir                 )
538*cdf0e10cSrcweir             {
539*cdf0e10cSrcweir                 if ( !m_xInfo->hasPropertyByName( (*prop)->propertyName ) )
540*cdf0e10cSrcweir                 {
541*cdf0e10cSrcweir                     missingProp = true;
542*cdf0e10cSrcweir                     break;
543*cdf0e10cSrcweir                 }
544*cdf0e10cSrcweir             }
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir             if ( missingProp )
547*cdf0e10cSrcweir                 // try next group
548*cdf0e10cSrcweir                 continue;
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir             return group;
551*cdf0e10cSrcweir         }
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir         return i_propertyGroups.end();
554*cdf0e10cSrcweir     }
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir 	//---------------------------------------------------------------------
557*cdf0e10cSrcweir     bool OElementImport::tryGenericAttribute( sal_uInt16 _nNamespaceKey, const ::rtl::OUString& _rLocalName, const ::rtl::OUString& _rValue )
558*cdf0e10cSrcweir     {
559*cdf0e10cSrcweir         // the generic approach (which I hope all props will be migrated to, on the medium term): property handlers
560*cdf0e10cSrcweir         const AttributeDescription attribute( metadata::getAttributeDescription( _nNamespaceKey, _rLocalName ) );
561*cdf0e10cSrcweir         if ( attribute.attributeToken != XML_TOKEN_INVALID )
562*cdf0e10cSrcweir         {
563*cdf0e10cSrcweir             PropertyGroups propertyGroups;
564*cdf0e10cSrcweir             metadata::getPropertyGroupList( attribute, propertyGroups );
565*cdf0e10cSrcweir             const PropertyGroups::const_iterator pos = impl_matchPropertyGroup( propertyGroups );
566*cdf0e10cSrcweir             if ( pos == propertyGroups.end() )
567*cdf0e10cSrcweir                 return false;
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir             do
570*cdf0e10cSrcweir             {
571*cdf0e10cSrcweir                 const PropertyDescriptionList& rProperties( *pos );
572*cdf0e10cSrcweir                 const PropertyDescription* first = *rProperties.begin();
573*cdf0e10cSrcweir                 ENSURE_OR_BREAK( first != NULL, "OElementImport::handleAttribute: invalid property description!" );
574*cdf0e10cSrcweir                 const PPropertyHandler handler = (*first->factory)( first->propertyId );
575*cdf0e10cSrcweir                 ENSURE_OR_BREAK( handler.get() != NULL, "OElementImport::handleAttribute: invalid property handler!" );
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir                 PropertyValues aValues;
578*cdf0e10cSrcweir                 for (   PropertyDescriptionList::const_iterator propDesc = rProperties.begin();
579*cdf0e10cSrcweir                         propDesc != rProperties.end();
580*cdf0e10cSrcweir                         ++propDesc
581*cdf0e10cSrcweir                     )
582*cdf0e10cSrcweir                 {
583*cdf0e10cSrcweir                     aValues[ (*propDesc)->propertyId ] = Any();
584*cdf0e10cSrcweir                 }
585*cdf0e10cSrcweir                 if ( handler->getPropertyValues( _rValue, aValues ) )
586*cdf0e10cSrcweir                 {
587*cdf0e10cSrcweir                     for (   PropertyDescriptionList::const_iterator propDesc = rProperties.begin();
588*cdf0e10cSrcweir                             propDesc != rProperties.end();
589*cdf0e10cSrcweir                             ++propDesc
590*cdf0e10cSrcweir                         )
591*cdf0e10cSrcweir                     {
592*cdf0e10cSrcweir                         implPushBackPropertyValue( (*propDesc)->propertyName, aValues[ (*propDesc)->propertyId ] );
593*cdf0e10cSrcweir                     }
594*cdf0e10cSrcweir                 }
595*cdf0e10cSrcweir             }
596*cdf0e10cSrcweir             while ( false );
597*cdf0e10cSrcweir 
598*cdf0e10cSrcweir             // handled
599*cdf0e10cSrcweir             return true;
600*cdf0e10cSrcweir         }
601*cdf0e10cSrcweir         return false;
602*cdf0e10cSrcweir     }
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir 	//---------------------------------------------------------------------
605*cdf0e10cSrcweir 	bool OElementImport::handleAttribute(sal_uInt16 _nNamespaceKey, const ::rtl::OUString& _rLocalName, const ::rtl::OUString& _rValue)
606*cdf0e10cSrcweir 	{
607*cdf0e10cSrcweir 		if ( token::IsXMLToken( _rLocalName, token::XML_CONTROL_IMPLEMENTATION ) )
608*cdf0e10cSrcweir             // ignore this, it has already been handled in OElementImport::StartElement
609*cdf0e10cSrcweir             return true;
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir 		if ( token::IsXMLToken( _rLocalName, token::XML_NAME ) )
612*cdf0e10cSrcweir         {
613*cdf0e10cSrcweir             if ( !m_sName.getLength() )
614*cdf0e10cSrcweir 			    // remember the name for later use in EndElement
615*cdf0e10cSrcweir 				m_sName = _rValue;
616*cdf0e10cSrcweir             return true;
617*cdf0e10cSrcweir         }
618*cdf0e10cSrcweir 
619*cdf0e10cSrcweir 		// maybe it's the style attribute?
620*cdf0e10cSrcweir 		if ( token::IsXMLToken( _rLocalName, token::XML_TEXT_STYLE_NAME ) )
621*cdf0e10cSrcweir 		{
622*cdf0e10cSrcweir 			const SvXMLStyleContext* pStyleContext = m_rContext.getStyleElement( _rValue );
623*cdf0e10cSrcweir 			OSL_ENSURE( pStyleContext, "OElementImport::handleAttribute: do not know the style!" );
624*cdf0e10cSrcweir 			// remember the element for later usage.
625*cdf0e10cSrcweir 			m_pStyleElement = PTR_CAST( XMLTextStyleContext, pStyleContext );
626*cdf0e10cSrcweir             return true;
627*cdf0e10cSrcweir 		}
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir         if ( m_bImplicitGenericAttributeHandling )
630*cdf0e10cSrcweir             if ( tryGenericAttribute( _nNamespaceKey, _rLocalName, _rValue ) )
631*cdf0e10cSrcweir                 return true;
632*cdf0e10cSrcweir 
633*cdf0e10cSrcweir 		// let the base class handle it
634*cdf0e10cSrcweir 		return OPropertyImport::handleAttribute(_nNamespaceKey, _rLocalName, _rValue);
635*cdf0e10cSrcweir 	}
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir 	//---------------------------------------------------------------------
638*cdf0e10cSrcweir 	Reference< XPropertySet > OElementImport::createElement()
639*cdf0e10cSrcweir 	{
640*cdf0e10cSrcweir 		Reference< XPropertySet > xReturn;
641*cdf0e10cSrcweir 		if (m_sServiceName.getLength())
642*cdf0e10cSrcweir 		{
643*cdf0e10cSrcweir 			Reference< XInterface > xPure = m_rFormImport.getGlobalContext().getServiceFactory()->createInstance(m_sServiceName);
644*cdf0e10cSrcweir 			OSL_ENSURE(xPure.is(),
645*cdf0e10cSrcweir 						::rtl::OString("OElementImport::createElement: service factory gave me no object (service name: ")
646*cdf0e10cSrcweir 					+=	::rtl::OString(m_sServiceName.getStr(), m_sServiceName.getLength(), RTL_TEXTENCODING_ASCII_US)
647*cdf0e10cSrcweir 					+=	::rtl::OString(")!"));
648*cdf0e10cSrcweir 			xReturn = Reference< XPropertySet >(xPure, UNO_QUERY);
649*cdf0e10cSrcweir 		}
650*cdf0e10cSrcweir 		else
651*cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "OElementImport::createElement: no service name to create an element!");
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir 		return xReturn;
654*cdf0e10cSrcweir 	}
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir 	//---------------------------------------------------------------------
657*cdf0e10cSrcweir 	void OElementImport::registerEvents(const Sequence< ScriptEventDescriptor >& _rEvents)
658*cdf0e10cSrcweir 	{
659*cdf0e10cSrcweir 		OSL_ENSURE(m_xElement.is(), "OElementImport::registerEvents: no element to register events for!");
660*cdf0e10cSrcweir 		m_rEventManager.registerEvents(m_xElement, _rEvents);
661*cdf0e10cSrcweir 	}
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir 	//---------------------------------------------------------------------
664*cdf0e10cSrcweir 	void OElementImport::simulateDefaultedAttribute(const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName, const sal_Char* _pAttributeDefault)
665*cdf0e10cSrcweir 	{
666*cdf0e10cSrcweir 		OSL_ENSURE( m_xInfo.is(), "OPropertyImport::simulateDefaultedAttribute: the component should be more gossipy about it's properties!" );
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir 		if ( !m_xInfo.is() || m_xInfo->hasPropertyByName( _rPropertyName ) )
669*cdf0e10cSrcweir 		{
670*cdf0e10cSrcweir 			::rtl::OUString sLocalAttrName = ::rtl::OUString::createFromAscii(_pAttributeName);
671*cdf0e10cSrcweir 			if ( !encounteredAttribute( sLocalAttrName ) )
672*cdf0e10cSrcweir 				OSL_VERIFY( handleAttribute( XML_NAMESPACE_FORM, sLocalAttrName, ::rtl::OUString::createFromAscii( _pAttributeDefault ) ) );
673*cdf0e10cSrcweir 		}
674*cdf0e10cSrcweir 	}
675*cdf0e10cSrcweir 
676*cdf0e10cSrcweir 	//=====================================================================
677*cdf0e10cSrcweir 	//= OControlImport
678*cdf0e10cSrcweir 	//=====================================================================
679*cdf0e10cSrcweir 	//---------------------------------------------------------------------
680*cdf0e10cSrcweir 	OControlImport::OControlImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
681*cdf0e10cSrcweir 			const Reference< XNameContainer >& _rxParentContainer)
682*cdf0e10cSrcweir 		:OElementImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer)
683*cdf0e10cSrcweir 		,m_eElementType(OControlElement::UNKNOWN)
684*cdf0e10cSrcweir 	{
685*cdf0e10cSrcweir         disableImplicitGenericAttributeHandling();
686*cdf0e10cSrcweir 	}
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir 	//---------------------------------------------------------------------
689*cdf0e10cSrcweir 	OControlImport::OControlImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
690*cdf0e10cSrcweir 			const Reference< XNameContainer >& _rxParentContainer, OControlElement::ElementType _eType)
691*cdf0e10cSrcweir 		:OElementImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer)
692*cdf0e10cSrcweir 		,m_eElementType(_eType)
693*cdf0e10cSrcweir 	{
694*cdf0e10cSrcweir         disableImplicitGenericAttributeHandling();
695*cdf0e10cSrcweir 	}
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir 	//---------------------------------------------------------------------
698*cdf0e10cSrcweir     ::rtl::OUString OControlImport::determineDefaultServiceName() const
699*cdf0e10cSrcweir     {
700*cdf0e10cSrcweir         const sal_Char* pServiceName = NULL;
701*cdf0e10cSrcweir         switch ( m_eElementType )
702*cdf0e10cSrcweir         {
703*cdf0e10cSrcweir         case OControlElement::TEXT:
704*cdf0e10cSrcweir         case OControlElement::TEXT_AREA:
705*cdf0e10cSrcweir         case OControlElement::PASSWORD:          pServiceName = "com.sun.star.form.component.TextField"; break;
706*cdf0e10cSrcweir         case OControlElement::FILE:              pServiceName = "com.sun.star.form.component.FileControl"; break;
707*cdf0e10cSrcweir         case OControlElement::FORMATTED_TEXT:    pServiceName = "com.sun.star.form.component.FormattedField"; break;
708*cdf0e10cSrcweir         case OControlElement::FIXED_TEXT:        pServiceName = "com.sun.star.form.component.FixedText"; break;
709*cdf0e10cSrcweir         case OControlElement::COMBOBOX:          pServiceName = "com.sun.star.form.component.ComboBox"; break;
710*cdf0e10cSrcweir         case OControlElement::LISTBOX:           pServiceName = "com.sun.star.form.component.ListBox"; break;
711*cdf0e10cSrcweir         case OControlElement::BUTTON:            pServiceName = "com.sun.star.form.component.CommandButton"; break;
712*cdf0e10cSrcweir         case OControlElement::IMAGE:             pServiceName = "com.sun.star.form.component.ImageButton"; break;
713*cdf0e10cSrcweir         case OControlElement::CHECKBOX:          pServiceName = "com.sun.star.form.component.CheckBox"; break;
714*cdf0e10cSrcweir         case OControlElement::RADIO:             pServiceName = "com.sun.star.form.component.RadioButton"; break;
715*cdf0e10cSrcweir         case OControlElement::FRAME:             pServiceName = "com.sun.star.form.component.GroupBox"; break;
716*cdf0e10cSrcweir         case OControlElement::IMAGE_FRAME:       pServiceName = "com.sun.star.form.component.DatabaseImageControl"; break;
717*cdf0e10cSrcweir         case OControlElement::HIDDEN:            pServiceName = "com.sun.star.form.component.HiddenControl"; break;
718*cdf0e10cSrcweir         case OControlElement::GRID:              pServiceName = "com.sun.star.form.component.GridControl"; break;
719*cdf0e10cSrcweir         case OControlElement::TIME:              pServiceName = "com.sun.star.form.component.DateField"; break;
720*cdf0e10cSrcweir         case OControlElement::DATE:              pServiceName = "com.sun.star.form.component.TimeField"; break;
721*cdf0e10cSrcweir         default:                                 break;
722*cdf0e10cSrcweir         }
723*cdf0e10cSrcweir         if ( pServiceName != NULL )
724*cdf0e10cSrcweir             return ::rtl::OUString::createFromAscii( pServiceName );
725*cdf0e10cSrcweir         return ::rtl::OUString();
726*cdf0e10cSrcweir     }
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir 	//---------------------------------------------------------------------
729*cdf0e10cSrcweir 	void OControlImport::addOuterAttributes(const Reference< sax::XAttributeList >& _rxOuterAttribs)
730*cdf0e10cSrcweir 	{
731*cdf0e10cSrcweir 		OSL_ENSURE(!m_xOuterAttributes.is(), "OControlImport::addOuterAttributes: already have these attributes!");
732*cdf0e10cSrcweir 		m_xOuterAttributes = _rxOuterAttribs;
733*cdf0e10cSrcweir 	}
734*cdf0e10cSrcweir 
735*cdf0e10cSrcweir 	//---------------------------------------------------------------------
736*cdf0e10cSrcweir 	bool OControlImport::handleAttribute(sal_uInt16 _nNamespaceKey, const ::rtl::OUString& _rLocalName, const ::rtl::OUString& _rValue)
737*cdf0e10cSrcweir 	{
738*cdf0e10cSrcweir 		static const sal_Char* pLinkedCellAttributeName = OAttributeMetaData::getBindingAttributeName(BA_LINKED_CELL);
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir         if (IsXMLToken(_rLocalName, XML_ID))
741*cdf0e10cSrcweir         {   // it's the control id
742*cdf0e10cSrcweir             if (XML_NAMESPACE_XML == _nNamespaceKey)
743*cdf0e10cSrcweir             {
744*cdf0e10cSrcweir                 m_sControlId = _rValue;
745*cdf0e10cSrcweir             }
746*cdf0e10cSrcweir             else if (XML_NAMESPACE_FORM == _nNamespaceKey)
747*cdf0e10cSrcweir             {
748*cdf0e10cSrcweir                 if (!m_sControlId.getLength())
749*cdf0e10cSrcweir                 {
750*cdf0e10cSrcweir                     m_sControlId = _rValue;
751*cdf0e10cSrcweir                 }
752*cdf0e10cSrcweir             }
753*cdf0e10cSrcweir             return true;
754*cdf0e10cSrcweir         }
755*cdf0e10cSrcweir 
756*cdf0e10cSrcweir         if ( _rLocalName.equalsAscii( pLinkedCellAttributeName ) )
757*cdf0e10cSrcweir         {   // it's the address of a spreadsheet cell
758*cdf0e10cSrcweir             m_sBoundCellAddress = _rValue;
759*cdf0e10cSrcweir             return true;
760*cdf0e10cSrcweir         }
761*cdf0e10cSrcweir 
762*cdf0e10cSrcweir         if ( _nNamespaceKey == XML_NAMESPACE_XFORMS && IsXMLToken( _rLocalName, XML_BIND ) )
763*cdf0e10cSrcweir         {
764*cdf0e10cSrcweir             m_sBindingID = _rValue;
765*cdf0e10cSrcweir             return true;
766*cdf0e10cSrcweir         }
767*cdf0e10cSrcweir 
768*cdf0e10cSrcweir         if ( _nNamespaceKey == XML_NAMESPACE_FORM && IsXMLToken( _rLocalName, XML_XFORMS_LIST_SOURCE )  )
769*cdf0e10cSrcweir         {
770*cdf0e10cSrcweir             m_sListBindingID = _rValue;
771*cdf0e10cSrcweir             return true;
772*cdf0e10cSrcweir         }
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir         if  (   (   ( _nNamespaceKey == XML_NAMESPACE_FORM )
775*cdf0e10cSrcweir                 &&  IsXMLToken( _rLocalName, XML_XFORMS_SUBMISSION )
776*cdf0e10cSrcweir                 )
777*cdf0e10cSrcweir             ||  (   ( _nNamespaceKey == XML_NAMESPACE_XFORMS )
778*cdf0e10cSrcweir                 &&  IsXMLToken( _rLocalName, XML_SUBMISSION )
779*cdf0e10cSrcweir                 )
780*cdf0e10cSrcweir             )
781*cdf0e10cSrcweir         {
782*cdf0e10cSrcweir             m_sSubmissionID = _rValue;
783*cdf0e10cSrcweir             return true;
784*cdf0e10cSrcweir         }
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir         if ( OElementImport::tryGenericAttribute( _nNamespaceKey, _rLocalName, _rValue ) )
787*cdf0e10cSrcweir             return true;
788*cdf0e10cSrcweir 
789*cdf0e10cSrcweir 		static const sal_Char* pValueAttributeName = OAttributeMetaData::getCommonControlAttributeName(CCA_VALUE);
790*cdf0e10cSrcweir 		static const sal_Char* pCurrentValueAttributeName = OAttributeMetaData::getCommonControlAttributeName(CCA_CURRENT_VALUE);
791*cdf0e10cSrcweir         static const sal_Char* pMinValueAttributeName = OAttributeMetaData::getSpecialAttributeName(SCA_MIN_VALUE);
792*cdf0e10cSrcweir 		static const sal_Char* pMaxValueAttributeName = OAttributeMetaData::getSpecialAttributeName(SCA_MAX_VALUE);
793*cdf0e10cSrcweir         static const sal_Char* pRepeatDelayAttributeName = OAttributeMetaData::getSpecialAttributeName( SCA_REPEAT_DELAY );
794*cdf0e10cSrcweir 
795*cdf0e10cSrcweir 		sal_Int32 nHandle = -1;
796*cdf0e10cSrcweir         if ( _rLocalName.equalsAscii( pValueAttributeName ) )
797*cdf0e10cSrcweir             nHandle = PROPID_VALUE;
798*cdf0e10cSrcweir         else if ( _rLocalName.equalsAscii( pCurrentValueAttributeName ) )
799*cdf0e10cSrcweir             nHandle = PROPID_CURRENT_VALUE;
800*cdf0e10cSrcweir         else if ( _rLocalName.equalsAscii( pMinValueAttributeName ) )
801*cdf0e10cSrcweir             nHandle = PROPID_MIN_VALUE;
802*cdf0e10cSrcweir         else if ( _rLocalName.equalsAscii( pMaxValueAttributeName ) )
803*cdf0e10cSrcweir             nHandle = PROPID_MAX_VALUE;
804*cdf0e10cSrcweir         if ( nHandle != -1 )
805*cdf0e10cSrcweir 		{
806*cdf0e10cSrcweir 			// for the moment, simply remember the name and the value
807*cdf0e10cSrcweir 			PropertyValue aProp;
808*cdf0e10cSrcweir 			aProp.Name = _rLocalName;
809*cdf0e10cSrcweir 			aProp.Handle = nHandle;
810*cdf0e10cSrcweir 			aProp.Value <<= _rValue;
811*cdf0e10cSrcweir 			m_aValueProperties.push_back(aProp);
812*cdf0e10cSrcweir             return true;
813*cdf0e10cSrcweir 		}
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir 		if ( _rLocalName.equalsAscii( pRepeatDelayAttributeName ) )
816*cdf0e10cSrcweir         {
817*cdf0e10cSrcweir             ::Time aTime;
818*cdf0e10cSrcweir             sal_Int32 nFractions = 0;
819*cdf0e10cSrcweir             if ( SvXMLUnitConverter::convertTimeDuration( _rValue, aTime, &nFractions ) )
820*cdf0e10cSrcweir             {
821*cdf0e10cSrcweir 			    PropertyValue aProp;
822*cdf0e10cSrcweir 			    aProp.Name = PROPERTY_REPEAT_DELAY;
823*cdf0e10cSrcweir 			    aProp.Value <<= (sal_Int32)( ( ( aTime.GetMSFromTime() / 1000 ) * 1000 ) + nFractions );
824*cdf0e10cSrcweir 
825*cdf0e10cSrcweir 			    implPushBackPropertyValue(aProp);
826*cdf0e10cSrcweir             }
827*cdf0e10cSrcweir             return true;
828*cdf0e10cSrcweir         }
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir 		return OElementImport::handleAttribute( _nNamespaceKey, _rLocalName, _rValue );
831*cdf0e10cSrcweir 	}
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir 	//---------------------------------------------------------------------
834*cdf0e10cSrcweir 	void OControlImport::StartElement(const Reference< sax::XAttributeList >& _rxAttrList)
835*cdf0e10cSrcweir 	{
836*cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > xAttributes;
837*cdf0e10cSrcweir 		if( m_xOuterAttributes.is() )
838*cdf0e10cSrcweir 		{
839*cdf0e10cSrcweir 			// merge the attribute lists
840*cdf0e10cSrcweir 			OAttribListMerger* pMerger = new OAttribListMerger;
841*cdf0e10cSrcweir 			// our own one
842*cdf0e10cSrcweir 			pMerger->addList(_rxAttrList);
843*cdf0e10cSrcweir 			// and the ones of our enclosing element
844*cdf0e10cSrcweir 			pMerger->addList(m_xOuterAttributes);
845*cdf0e10cSrcweir 			xAttributes = pMerger;
846*cdf0e10cSrcweir 		}
847*cdf0e10cSrcweir 		else
848*cdf0e10cSrcweir 		{
849*cdf0e10cSrcweir 			xAttributes = _rxAttrList;
850*cdf0e10cSrcweir 		}
851*cdf0e10cSrcweir 
852*cdf0e10cSrcweir 		// let the base class handle all the attributes
853*cdf0e10cSrcweir 		OElementImport::StartElement(xAttributes);
854*cdf0e10cSrcweir 
855*cdf0e10cSrcweir 		if ( !m_aValueProperties.empty() && m_xElement.is())
856*cdf0e10cSrcweir 		{
857*cdf0e10cSrcweir 			// get the property set info
858*cdf0e10cSrcweir 			if (!m_xInfo.is())
859*cdf0e10cSrcweir 			{
860*cdf0e10cSrcweir 				OSL_ENSURE(sal_False, "OControlImport::StartElement: no PropertySetInfo!");
861*cdf0e10cSrcweir 				return;
862*cdf0e10cSrcweir 			}
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir 			const sal_Char* pValueProperty = NULL;
865*cdf0e10cSrcweir 			const sal_Char* pCurrentValueProperty = NULL;
866*cdf0e10cSrcweir 			const sal_Char* pMinValueProperty = NULL;
867*cdf0e10cSrcweir 			const sal_Char* pMaxValueProperty = NULL;
868*cdf0e10cSrcweir 
869*cdf0e10cSrcweir 			sal_Bool bRetrievedValues = sal_False;
870*cdf0e10cSrcweir 			sal_Bool bRetrievedValueLimits = sal_False;
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir 			// get the class id of our element
873*cdf0e10cSrcweir 			sal_Int16 nClassId = FormComponentType::CONTROL;
874*cdf0e10cSrcweir 			m_xElement->getPropertyValue(PROPERTY_CLASSID) >>= nClassId;
875*cdf0e10cSrcweir 
876*cdf0e10cSrcweir 			// translate the value properties we collected in handleAttributes
877*cdf0e10cSrcweir             PropertyValueArray::iterator aEnd = m_aValueProperties.end();
878*cdf0e10cSrcweir             for	(	PropertyValueArray::iterator aValueProps = m_aValueProperties.begin();
879*cdf0e10cSrcweir 					aValueProps != aEnd;
880*cdf0e10cSrcweir 					++aValueProps
881*cdf0e10cSrcweir 				)
882*cdf0e10cSrcweir 			{
883*cdf0e10cSrcweir                 bool bSuccess = false;
884*cdf0e10cSrcweir 				switch (aValueProps->Handle)
885*cdf0e10cSrcweir 				{
886*cdf0e10cSrcweir 					case PROPID_VALUE:
887*cdf0e10cSrcweir 					case PROPID_CURRENT_VALUE:
888*cdf0e10cSrcweir 					{
889*cdf0e10cSrcweir 						// get the property names
890*cdf0e10cSrcweir 						if (!bRetrievedValues)
891*cdf0e10cSrcweir 						{
892*cdf0e10cSrcweir 							getValuePropertyNames(m_eElementType, nClassId, pCurrentValueProperty, pValueProperty);
893*cdf0e10cSrcweir                             ENSURE_OR_BREAK( pValueProperty, "OControlImport::StartElement: illegal value property names!" );
894*cdf0e10cSrcweir 							bRetrievedValues = sal_True;
895*cdf0e10cSrcweir 						}
896*cdf0e10cSrcweir 						ENSURE_OR_BREAK((PROPID_VALUE != aValueProps->Handle) || pValueProperty,
897*cdf0e10cSrcweir 							"OControlImport::StartElement: the control does not have a value property!");
898*cdf0e10cSrcweir 						ENSURE_OR_BREAK((PROPID_CURRENT_VALUE != aValueProps->Handle) || pCurrentValueProperty,
899*cdf0e10cSrcweir 							"OControlImport::StartElement: the control does not have a current-value property!");
900*cdf0e10cSrcweir 
901*cdf0e10cSrcweir 						// transfer the name
902*cdf0e10cSrcweir 						if (PROPID_VALUE == aValueProps->Handle)
903*cdf0e10cSrcweir 							aValueProps->Name = ::rtl::OUString::createFromAscii(pValueProperty);
904*cdf0e10cSrcweir 						else
905*cdf0e10cSrcweir 							aValueProps->Name = ::rtl::OUString::createFromAscii(pCurrentValueProperty);
906*cdf0e10cSrcweir                         bSuccess = true;
907*cdf0e10cSrcweir 					}
908*cdf0e10cSrcweir 					break;
909*cdf0e10cSrcweir 					case PROPID_MIN_VALUE:
910*cdf0e10cSrcweir 					case PROPID_MAX_VALUE:
911*cdf0e10cSrcweir 					{
912*cdf0e10cSrcweir 						// get the property names
913*cdf0e10cSrcweir 						if (!bRetrievedValueLimits)
914*cdf0e10cSrcweir 						{
915*cdf0e10cSrcweir 							getValueLimitPropertyNames(nClassId, pMinValueProperty, pMaxValueProperty);
916*cdf0e10cSrcweir                             ENSURE_OR_BREAK( pMinValueProperty && pMaxValueProperty, "OControlImport::StartElement: illegal value limit property names!" );
917*cdf0e10cSrcweir 							bRetrievedValueLimits = sal_True;
918*cdf0e10cSrcweir 						}
919*cdf0e10cSrcweir 						OSL_ENSURE((PROPID_MIN_VALUE != aValueProps->Handle) || pMinValueProperty,
920*cdf0e10cSrcweir 							"OControlImport::StartElement: the control does not have a value property!");
921*cdf0e10cSrcweir 						OSL_ENSURE((PROPID_MAX_VALUE != aValueProps->Handle) || pMaxValueProperty,
922*cdf0e10cSrcweir 							"OControlImport::StartElement: the control does not have a current-value property!");
923*cdf0e10cSrcweir 
924*cdf0e10cSrcweir 						// transfer the name
925*cdf0e10cSrcweir 						if (PROPID_MIN_VALUE == aValueProps->Handle)
926*cdf0e10cSrcweir 							aValueProps->Name = ::rtl::OUString::createFromAscii(pMinValueProperty);
927*cdf0e10cSrcweir 						else
928*cdf0e10cSrcweir 							aValueProps->Name = ::rtl::OUString::createFromAscii(pMaxValueProperty);
929*cdf0e10cSrcweir                         bSuccess = true;
930*cdf0e10cSrcweir 					}
931*cdf0e10cSrcweir 					break;
932*cdf0e10cSrcweir 				}
933*cdf0e10cSrcweir 
934*cdf0e10cSrcweir                 if ( !bSuccess )
935*cdf0e10cSrcweir                     continue;
936*cdf0e10cSrcweir 
937*cdf0e10cSrcweir 				// translate the value
938*cdf0e10cSrcweir 				implTranslateValueProperty(m_xInfo, *aValueProps);
939*cdf0e10cSrcweir 				// add the property to the base class' array
940*cdf0e10cSrcweir 				implPushBackPropertyValue(*aValueProps);
941*cdf0e10cSrcweir 			}
942*cdf0e10cSrcweir 		}
943*cdf0e10cSrcweir 	}
944*cdf0e10cSrcweir 
945*cdf0e10cSrcweir 	//---------------------------------------------------------------------
946*cdf0e10cSrcweir 	void OControlImport::implTranslateValueProperty(const Reference< XPropertySetInfo >& _rxPropInfo,
947*cdf0e10cSrcweir 		PropertyValue& _rPropValue)
948*cdf0e10cSrcweir 	{
949*cdf0e10cSrcweir 		OSL_ENSURE(_rxPropInfo->hasPropertyByName(_rPropValue.Name),
950*cdf0e10cSrcweir 			"OControlImport::implTranslateValueProperty: invalid property name!");
951*cdf0e10cSrcweir 
952*cdf0e10cSrcweir 		// retrieve the type of the property
953*cdf0e10cSrcweir 		Property aProp = _rxPropInfo->getPropertyByName(_rPropValue.Name);
954*cdf0e10cSrcweir 		// the untranslated string value as read in handleAttribute
955*cdf0e10cSrcweir 		::rtl::OUString sValue;
956*cdf0e10cSrcweir     #if OSL_DEBUG_LEVEL > 0
957*cdf0e10cSrcweir 		sal_Bool bSuccess =
958*cdf0e10cSrcweir 	#endif
959*cdf0e10cSrcweir 		_rPropValue.Value >>= sValue;
960*cdf0e10cSrcweir 		OSL_ENSURE(bSuccess, "OControlImport::implTranslateValueProperty: supposed to be called with non-translated string values!");
961*cdf0e10cSrcweir 
962*cdf0e10cSrcweir 		if (TypeClass_ANY == aProp.Type.getTypeClass())
963*cdf0e10cSrcweir 		{
964*cdf0e10cSrcweir 			// we have exactly 2 properties where this type class is allowed:
965*cdf0e10cSrcweir 			OSL_ENSURE(
966*cdf0e10cSrcweir 					(0 == _rPropValue.Name.compareToAscii(PROPERTY_EFFECTIVE_VALUE))
967*cdf0e10cSrcweir 				||	(0 == _rPropValue.Name.compareToAscii(PROPERTY_EFFECTIVE_DEFAULT)),
968*cdf0e10cSrcweir 				"OControlImport::implTranslateValueProperty: invalid property type/name combination!");
969*cdf0e10cSrcweir 
970*cdf0e10cSrcweir 			// Both properties are allowed to have a double or a string value,
971*cdf0e10cSrcweir 			// so first try to convert the string into a number
972*cdf0e10cSrcweir 			double nValue;
973*cdf0e10cSrcweir 			if (GetImport().GetMM100UnitConverter().convertDouble(nValue, sValue))
974*cdf0e10cSrcweir 				_rPropValue.Value <<= nValue;
975*cdf0e10cSrcweir 			else
976*cdf0e10cSrcweir 				_rPropValue.Value <<= sValue;
977*cdf0e10cSrcweir 		}
978*cdf0e10cSrcweir 		else
979*cdf0e10cSrcweir 			_rPropValue.Value = PropertyConversion::convertString(GetImport(), aProp.Type, sValue);
980*cdf0e10cSrcweir 	}
981*cdf0e10cSrcweir 
982*cdf0e10cSrcweir 	//---------------------------------------------------------------------
983*cdf0e10cSrcweir 	void OControlImport::EndElement()
984*cdf0e10cSrcweir 	{
985*cdf0e10cSrcweir 		OSL_ENSURE(m_xElement.is(), "OControlImport::EndElement: invalid control!");
986*cdf0e10cSrcweir 		if ( !m_xElement.is() )
987*cdf0e10cSrcweir 			return;
988*cdf0e10cSrcweir 
989*cdf0e10cSrcweir 		// register our control with it's id
990*cdf0e10cSrcweir 		if (m_sControlId.getLength())
991*cdf0e10cSrcweir 			m_rFormImport.registerControlId(m_xElement, m_sControlId);
992*cdf0e10cSrcweir 		// it's allowed to have no control id. In this case we're importing a column
993*cdf0e10cSrcweir 
994*cdf0e10cSrcweir 		// one more pre-work to do:
995*cdf0e10cSrcweir 		// when we set default values, then by definition the respective value is set
996*cdf0e10cSrcweir 		// to this default value, too. This means if the sequence contains for example
997*cdf0e10cSrcweir 		// a DefaultText value, then the Text will be affected by this, too.
998*cdf0e10cSrcweir 		// In case the Text is not part of the property sequence (or occurs _before_
999*cdf0e10cSrcweir 		// the DefaultText, which can happen for other value/default-value property names),
1000*cdf0e10cSrcweir 		// this means that the Text (the value property) is incorrectly imported.
1001*cdf0e10cSrcweir 		// #102475# - 04.09.2002 - fs@openoffice.org
1002*cdf0e10cSrcweir 
1003*cdf0e10cSrcweir 		sal_Bool bRestoreValuePropertyValue = sal_False;
1004*cdf0e10cSrcweir 		Any aValuePropertyValue;
1005*cdf0e10cSrcweir 
1006*cdf0e10cSrcweir 		sal_Int16 nClassId = FormComponentType::CONTROL;
1007*cdf0e10cSrcweir 		try
1008*cdf0e10cSrcweir 		{
1009*cdf0e10cSrcweir 			// get the class id of our element
1010*cdf0e10cSrcweir 			m_xElement->getPropertyValue(PROPERTY_CLASSID) >>= nClassId;
1011*cdf0e10cSrcweir 		}
1012*cdf0e10cSrcweir 		catch( const Exception& )
1013*cdf0e10cSrcweir 		{
1014*cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "OControlImport::EndElement: caught an exception while retrieving the class id!" );
1015*cdf0e10cSrcweir 		}
1016*cdf0e10cSrcweir 
1017*cdf0e10cSrcweir 		const sal_Char* pValueProperty = NULL;
1018*cdf0e10cSrcweir 		const sal_Char* pDefaultValueProperty = NULL;
1019*cdf0e10cSrcweir 		getRuntimeValuePropertyNames(m_eElementType, nClassId, pValueProperty, pDefaultValueProperty);
1020*cdf0e10cSrcweir 		if ( pDefaultValueProperty && pValueProperty )
1021*cdf0e10cSrcweir 		{
1022*cdf0e10cSrcweir 			sal_Bool bNonDefaultValuePropertyValue = sal_False;
1023*cdf0e10cSrcweir 				// is the "value property" part of the sequence?
1024*cdf0e10cSrcweir 
1025*cdf0e10cSrcweir 			// look up this property in our sequence
1026*cdf0e10cSrcweir             PropertyValueArray::iterator aEnd = m_aValues.end();
1027*cdf0e10cSrcweir 			for (	PropertyValueArray::iterator aCheck = m_aValues.begin();
1028*cdf0e10cSrcweir 					( aCheck != aEnd );
1029*cdf0e10cSrcweir 					++aCheck
1030*cdf0e10cSrcweir 				)
1031*cdf0e10cSrcweir 			{
1032*cdf0e10cSrcweir 				if ( aCheck->Name.equalsAscii( pDefaultValueProperty ) )
1033*cdf0e10cSrcweir 					bRestoreValuePropertyValue = sal_True;
1034*cdf0e10cSrcweir 				else if ( aCheck->Name.equalsAscii( pValueProperty ) )
1035*cdf0e10cSrcweir 				{
1036*cdf0e10cSrcweir 					bNonDefaultValuePropertyValue = sal_True;
1037*cdf0e10cSrcweir 					// we need to restore the value property we found here, nothing else
1038*cdf0e10cSrcweir 					aValuePropertyValue = aCheck->Value;
1039*cdf0e10cSrcweir 				}
1040*cdf0e10cSrcweir 			}
1041*cdf0e10cSrcweir 
1042*cdf0e10cSrcweir 			if ( bRestoreValuePropertyValue && !bNonDefaultValuePropertyValue )
1043*cdf0e10cSrcweir 			{
1044*cdf0e10cSrcweir 				// found it -> need to remember (and restore) the "value property value", which is not set explicitly
1045*cdf0e10cSrcweir 				try
1046*cdf0e10cSrcweir 				{
1047*cdf0e10cSrcweir 					aValuePropertyValue = m_xElement->getPropertyValue( ::rtl::OUString::createFromAscii( pValueProperty ) );
1048*cdf0e10cSrcweir 				}
1049*cdf0e10cSrcweir 				catch( const Exception& )
1050*cdf0e10cSrcweir 				{
1051*cdf0e10cSrcweir 					OSL_ENSURE( sal_False, "OControlImport::EndElement: caught an exception while retrieving the current value property!" );
1052*cdf0e10cSrcweir 				}
1053*cdf0e10cSrcweir 			}
1054*cdf0e10cSrcweir 		}
1055*cdf0e10cSrcweir 
1056*cdf0e10cSrcweir 		// let the base class set all the values
1057*cdf0e10cSrcweir 		OElementImport::EndElement();
1058*cdf0e10cSrcweir 
1059*cdf0e10cSrcweir 		// restore the "value property value", if necessary
1060*cdf0e10cSrcweir 		if ( bRestoreValuePropertyValue && pValueProperty )
1061*cdf0e10cSrcweir 		{
1062*cdf0e10cSrcweir 			try
1063*cdf0e10cSrcweir 			{
1064*cdf0e10cSrcweir 				m_xElement->setPropertyValue( ::rtl::OUString::createFromAscii( pValueProperty ), aValuePropertyValue );
1065*cdf0e10cSrcweir 			}
1066*cdf0e10cSrcweir 			catch( const Exception& )
1067*cdf0e10cSrcweir 			{
1068*cdf0e10cSrcweir 				OSL_ENSURE( sal_False, "OControlImport::EndElement: caught an exception while restoring the value property!" );
1069*cdf0e10cSrcweir 			}
1070*cdf0e10cSrcweir 		}
1071*cdf0e10cSrcweir 
1072*cdf0e10cSrcweir         // the external cell binding, if applicable
1073*cdf0e10cSrcweir         if ( m_xElement.is() && m_sBoundCellAddress.getLength() )
1074*cdf0e10cSrcweir             doRegisterCellValueBinding( m_sBoundCellAddress );
1075*cdf0e10cSrcweir 
1076*cdf0e10cSrcweir         // XForms binding, if applicable
1077*cdf0e10cSrcweir         if ( m_xElement.is() && m_sBindingID.getLength() )
1078*cdf0e10cSrcweir             doRegisterXFormsValueBinding( m_sBindingID );
1079*cdf0e10cSrcweir 
1080*cdf0e10cSrcweir         // XForms list binding, if applicable
1081*cdf0e10cSrcweir         if ( m_xElement.is() && m_sListBindingID.getLength() )
1082*cdf0e10cSrcweir             doRegisterXFormsListBinding( m_sListBindingID );
1083*cdf0e10cSrcweir 
1084*cdf0e10cSrcweir         // XForms submission, if applicable
1085*cdf0e10cSrcweir         if ( m_xElement.is() && m_sSubmissionID.getLength() )
1086*cdf0e10cSrcweir             doRegisterXFormsSubmission( m_sSubmissionID );
1087*cdf0e10cSrcweir 	}
1088*cdf0e10cSrcweir 
1089*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1090*cdf0e10cSrcweir     void OControlImport::doRegisterCellValueBinding( const ::rtl::OUString& _rBoundCellAddress )
1091*cdf0e10cSrcweir     {
1092*cdf0e10cSrcweir         OSL_PRECOND( m_xElement.is(), "OControlImport::doRegisterCellValueBinding: invalid element!" );
1093*cdf0e10cSrcweir         OSL_PRECOND( _rBoundCellAddress.getLength(),
1094*cdf0e10cSrcweir             "OControlImport::doRegisterCellValueBinding: invalid address!" );
1095*cdf0e10cSrcweir 
1096*cdf0e10cSrcweir         m_rContext.registerCellValueBinding( m_xElement, _rBoundCellAddress );
1097*cdf0e10cSrcweir     }
1098*cdf0e10cSrcweir 
1099*cdf0e10cSrcweir     //---------------------------------------------------------------------
1100*cdf0e10cSrcweir     void OControlImport::doRegisterXFormsValueBinding( const ::rtl::OUString& _rBindingID )
1101*cdf0e10cSrcweir     {
1102*cdf0e10cSrcweir         OSL_PRECOND( m_xElement.is(), "need element" );
1103*cdf0e10cSrcweir         OSL_PRECOND( _rBindingID.getLength() > 0, "binding ID is not valid" );
1104*cdf0e10cSrcweir 
1105*cdf0e10cSrcweir         m_rContext.registerXFormsValueBinding( m_xElement, _rBindingID );
1106*cdf0e10cSrcweir     }
1107*cdf0e10cSrcweir 
1108*cdf0e10cSrcweir     //---------------------------------------------------------------------
1109*cdf0e10cSrcweir     void OControlImport::doRegisterXFormsListBinding( const ::rtl::OUString& _rBindingID )
1110*cdf0e10cSrcweir     {
1111*cdf0e10cSrcweir         OSL_PRECOND( m_xElement.is(), "need element" );
1112*cdf0e10cSrcweir         OSL_PRECOND( _rBindingID.getLength() > 0, "binding ID is not valid" );
1113*cdf0e10cSrcweir 
1114*cdf0e10cSrcweir         m_rContext.registerXFormsListBinding( m_xElement, _rBindingID );
1115*cdf0e10cSrcweir     }
1116*cdf0e10cSrcweir 
1117*cdf0e10cSrcweir     //---------------------------------------------------------------------
1118*cdf0e10cSrcweir     void OControlImport::doRegisterXFormsSubmission( const ::rtl::OUString& _rSubmissionID )
1119*cdf0e10cSrcweir     {
1120*cdf0e10cSrcweir         OSL_PRECOND( m_xElement.is(), "need element" );
1121*cdf0e10cSrcweir         OSL_PRECOND( _rSubmissionID.getLength() > 0, "binding ID is not valid" );
1122*cdf0e10cSrcweir 
1123*cdf0e10cSrcweir         m_rContext.registerXFormsSubmission( m_xElement, _rSubmissionID );
1124*cdf0e10cSrcweir     }
1125*cdf0e10cSrcweir 
1126*cdf0e10cSrcweir     //---------------------------------------------------------------------
1127*cdf0e10cSrcweir 	//added by BerryJia for fixing bug102407 2002-11-5
1128*cdf0e10cSrcweir 	Reference< XPropertySet > OControlImport::createElement()
1129*cdf0e10cSrcweir 	{
1130*cdf0e10cSrcweir 		const Reference<XPropertySet> xPropSet = OElementImport::createElement();
1131*cdf0e10cSrcweir 		if ( xPropSet.is() )
1132*cdf0e10cSrcweir 		{
1133*cdf0e10cSrcweir             m_xInfo = xPropSet->getPropertySetInfo();
1134*cdf0e10cSrcweir 			if ( m_xInfo.is() && m_xInfo->hasPropertyByName(PROPERTY_ALIGN) )
1135*cdf0e10cSrcweir 			{
1136*cdf0e10cSrcweir 				Any aValue;
1137*cdf0e10cSrcweir 				xPropSet->setPropertyValue(PROPERTY_ALIGN,aValue);
1138*cdf0e10cSrcweir 			}
1139*cdf0e10cSrcweir 		}
1140*cdf0e10cSrcweir 		return xPropSet;
1141*cdf0e10cSrcweir 	}
1142*cdf0e10cSrcweir 
1143*cdf0e10cSrcweir 	//=====================================================================
1144*cdf0e10cSrcweir 	//= OImagePositionImport
1145*cdf0e10cSrcweir 	//=====================================================================
1146*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1147*cdf0e10cSrcweir     OImagePositionImport::OImagePositionImport( OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
1148*cdf0e10cSrcweir         sal_uInt16 _nPrefix, const ::rtl::OUString& _rName, const Reference< XNameContainer >& _rxParentContainer,
1149*cdf0e10cSrcweir 		OControlElement::ElementType _eType )
1150*cdf0e10cSrcweir         :OControlImport( _rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType )
1151*cdf0e10cSrcweir         ,m_nImagePosition( -1 )
1152*cdf0e10cSrcweir         ,m_nImageAlign( 0 )
1153*cdf0e10cSrcweir         ,m_bHaveImagePosition( sal_False )
1154*cdf0e10cSrcweir     {
1155*cdf0e10cSrcweir     }
1156*cdf0e10cSrcweir 
1157*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1158*cdf0e10cSrcweir     bool OImagePositionImport::handleAttribute( sal_uInt16 _nNamespaceKey, const ::rtl::OUString& _rLocalName,
1159*cdf0e10cSrcweir         const ::rtl::OUString& _rValue )
1160*cdf0e10cSrcweir     {
1161*cdf0e10cSrcweir         if ( _rLocalName == GetXMLToken( XML_IMAGE_POSITION ) )
1162*cdf0e10cSrcweir         {
1163*cdf0e10cSrcweir             OSL_VERIFY( PropertyConversion::convertString(
1164*cdf0e10cSrcweir                 m_rContext.getGlobalContext(), ::getCppuType( &m_nImagePosition ),
1165*cdf0e10cSrcweir                 _rValue, OEnumMapper::getEnumMap( OEnumMapper::epImagePosition )
1166*cdf0e10cSrcweir             ) >>= m_nImagePosition );
1167*cdf0e10cSrcweir             m_bHaveImagePosition = sal_True;
1168*cdf0e10cSrcweir             return true;
1169*cdf0e10cSrcweir         }
1170*cdf0e10cSrcweir 
1171*cdf0e10cSrcweir         if ( _rLocalName == GetXMLToken( XML_IMAGE_ALIGN ) )
1172*cdf0e10cSrcweir         {
1173*cdf0e10cSrcweir             OSL_VERIFY( PropertyConversion::convertString(
1174*cdf0e10cSrcweir                 m_rContext.getGlobalContext(), ::getCppuType( &m_nImageAlign ),
1175*cdf0e10cSrcweir                 _rValue, OEnumMapper::getEnumMap( OEnumMapper::epImageAlign )
1176*cdf0e10cSrcweir             ) >>= m_nImageAlign );
1177*cdf0e10cSrcweir             return true;
1178*cdf0e10cSrcweir         }
1179*cdf0e10cSrcweir 
1180*cdf0e10cSrcweir         return OControlImport::handleAttribute( _nNamespaceKey, _rLocalName, _rValue );
1181*cdf0e10cSrcweir     }
1182*cdf0e10cSrcweir 
1183*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1184*cdf0e10cSrcweir 	void OImagePositionImport::StartElement(const Reference< sax::XAttributeList >& _rxAttrList)
1185*cdf0e10cSrcweir 	{
1186*cdf0e10cSrcweir 		OControlImport::StartElement( _rxAttrList );
1187*cdf0e10cSrcweir 
1188*cdf0e10cSrcweir         if ( m_bHaveImagePosition )
1189*cdf0e10cSrcweir         {
1190*cdf0e10cSrcweir             sal_Int16 nUnoImagePosition = ImagePosition::Centered;
1191*cdf0e10cSrcweir             if ( m_nImagePosition >= 0 )
1192*cdf0e10cSrcweir             {
1193*cdf0e10cSrcweir                 OSL_ENSURE( ( m_nImagePosition <= 3 ) && ( m_nImageAlign >= 0 ) && ( m_nImageAlign < 3 ),
1194*cdf0e10cSrcweir                     "OImagePositionImport::StartElement: unknown image align and/or position!" );
1195*cdf0e10cSrcweir                 nUnoImagePosition = m_nImagePosition * 3 + m_nImageAlign;
1196*cdf0e10cSrcweir             }
1197*cdf0e10cSrcweir 
1198*cdf0e10cSrcweir             PropertyValue aImagePosition;
1199*cdf0e10cSrcweir 		    aImagePosition.Name = PROPERTY_IMAGE_POSITION;
1200*cdf0e10cSrcweir 		    aImagePosition.Value <<= nUnoImagePosition;
1201*cdf0e10cSrcweir 		    implPushBackPropertyValue( aImagePosition );
1202*cdf0e10cSrcweir         }
1203*cdf0e10cSrcweir 	}
1204*cdf0e10cSrcweir 
1205*cdf0e10cSrcweir     //=====================================================================
1206*cdf0e10cSrcweir 	//= OReferredControlImport
1207*cdf0e10cSrcweir 	//=====================================================================
1208*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1209*cdf0e10cSrcweir 	OReferredControlImport::OReferredControlImport(
1210*cdf0e10cSrcweir 			OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
1211*cdf0e10cSrcweir 			const Reference< XNameContainer >& _rxParentContainer,
1212*cdf0e10cSrcweir 			OControlElement::ElementType )
1213*cdf0e10cSrcweir 		:OControlImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer)
1214*cdf0e10cSrcweir 	{
1215*cdf0e10cSrcweir 	}
1216*cdf0e10cSrcweir 
1217*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1218*cdf0e10cSrcweir 	void OReferredControlImport::StartElement(const Reference< sax::XAttributeList >& _rxAttrList)
1219*cdf0e10cSrcweir 	{
1220*cdf0e10cSrcweir 		OControlImport::StartElement(_rxAttrList);
1221*cdf0e10cSrcweir 
1222*cdf0e10cSrcweir 		// the base class should have created the control, so we can register it
1223*cdf0e10cSrcweir 		if ( m_sReferringControls.getLength() )
1224*cdf0e10cSrcweir 			m_rFormImport.registerControlReferences(m_xElement, m_sReferringControls);
1225*cdf0e10cSrcweir 	}
1226*cdf0e10cSrcweir 
1227*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1228*cdf0e10cSrcweir 	bool OReferredControlImport::handleAttribute(sal_uInt16 _nNamespaceKey, const ::rtl::OUString& _rLocalName,
1229*cdf0e10cSrcweir 		const ::rtl::OUString& _rValue)
1230*cdf0e10cSrcweir 	{
1231*cdf0e10cSrcweir 		static const ::rtl::OUString s_sReferenceAttributeName = ::rtl::OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_FOR));
1232*cdf0e10cSrcweir 		if (_rLocalName == s_sReferenceAttributeName)
1233*cdf0e10cSrcweir         {
1234*cdf0e10cSrcweir 			m_sReferringControls = _rValue;
1235*cdf0e10cSrcweir             return true;
1236*cdf0e10cSrcweir         }
1237*cdf0e10cSrcweir 		return OControlImport::handleAttribute(_nNamespaceKey, _rLocalName, _rValue);
1238*cdf0e10cSrcweir 	}
1239*cdf0e10cSrcweir 
1240*cdf0e10cSrcweir 	//=====================================================================
1241*cdf0e10cSrcweir 	//= OPasswordImport
1242*cdf0e10cSrcweir 	//=====================================================================
1243*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1244*cdf0e10cSrcweir 	OPasswordImport::OPasswordImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
1245*cdf0e10cSrcweir 			const Reference< XNameContainer >& _rxParentContainer, OControlElement::ElementType _eType)
1246*cdf0e10cSrcweir 		:OControlImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType)
1247*cdf0e10cSrcweir 	{
1248*cdf0e10cSrcweir 	}
1249*cdf0e10cSrcweir 
1250*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1251*cdf0e10cSrcweir 	bool OPasswordImport::handleAttribute(sal_uInt16 _nNamespaceKey, const ::rtl::OUString& _rLocalName, const ::rtl::OUString& _rValue)
1252*cdf0e10cSrcweir 	{
1253*cdf0e10cSrcweir 		static const ::rtl::OUString s_sEchoCharAttributeName = ::rtl::OUString::createFromAscii(OAttributeMetaData::getSpecialAttributeName(SCA_ECHO_CHAR));
1254*cdf0e10cSrcweir 		if (_rLocalName == s_sEchoCharAttributeName)
1255*cdf0e10cSrcweir 		{
1256*cdf0e10cSrcweir 			// need a special handling for the EchoChar property
1257*cdf0e10cSrcweir 			PropertyValue aEchoChar;
1258*cdf0e10cSrcweir 			aEchoChar.Name = PROPERTY_ECHOCHAR;
1259*cdf0e10cSrcweir 			OSL_ENSURE(_rValue.getLength() == 1, "OPasswordImport::handleAttribute: invalid echo char attribute!");
1260*cdf0e10cSrcweir 				// we ourself should not have written values other than of length 1
1261*cdf0e10cSrcweir 			if (_rValue.getLength() >= 1)
1262*cdf0e10cSrcweir 				aEchoChar.Value <<= (sal_Int16)_rValue.getStr()[0];
1263*cdf0e10cSrcweir 			else
1264*cdf0e10cSrcweir 				aEchoChar.Value <<= (sal_Int16)0;
1265*cdf0e10cSrcweir 			implPushBackPropertyValue(aEchoChar);
1266*cdf0e10cSrcweir             return true;
1267*cdf0e10cSrcweir 		}
1268*cdf0e10cSrcweir 		return OControlImport::handleAttribute(_nNamespaceKey, _rLocalName, _rValue);
1269*cdf0e10cSrcweir 	}
1270*cdf0e10cSrcweir 
1271*cdf0e10cSrcweir 	//=====================================================================
1272*cdf0e10cSrcweir 	//= ORadioImport
1273*cdf0e10cSrcweir 	//=====================================================================
1274*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1275*cdf0e10cSrcweir 	ORadioImport::ORadioImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
1276*cdf0e10cSrcweir 			const Reference< XNameContainer >& _rxParentContainer, OControlElement::ElementType _eType)
1277*cdf0e10cSrcweir 		:OImagePositionImport( _rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType )
1278*cdf0e10cSrcweir 	{
1279*cdf0e10cSrcweir 	}
1280*cdf0e10cSrcweir 
1281*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1282*cdf0e10cSrcweir 	bool ORadioImport::handleAttribute(sal_uInt16 _nNamespaceKey, const ::rtl::OUString& _rLocalName, const ::rtl::OUString& _rValue)
1283*cdf0e10cSrcweir 	{
1284*cdf0e10cSrcweir 		// need special handling for the State & CurrentState properties:
1285*cdf0e10cSrcweir 		// they're stored as booleans, but expected to be int16 properties
1286*cdf0e10cSrcweir         static const sal_Char* pCurrentSelectedAttributeName = OAttributeMetaData::getCommonControlAttributeName(CCA_CURRENT_SELECTED);
1287*cdf0e10cSrcweir 		static const sal_Char* pSelectedAttributeName = OAttributeMetaData::getCommonControlAttributeName(CCA_SELECTED);
1288*cdf0e10cSrcweir 		if  (  _rLocalName.equalsAscii( pCurrentSelectedAttributeName )
1289*cdf0e10cSrcweir             || _rLocalName.equalsAscii( pSelectedAttributeName )
1290*cdf0e10cSrcweir             )
1291*cdf0e10cSrcweir 		{
1292*cdf0e10cSrcweir 			const OAttribute2Property::AttributeAssignment* pProperty = m_rContext.getAttributeMap().getAttributeTranslation(_rLocalName);
1293*cdf0e10cSrcweir 			OSL_ENSURE(pProperty, "ORadioImport::handleAttribute: invalid property map!");
1294*cdf0e10cSrcweir 			if (pProperty)
1295*cdf0e10cSrcweir 			{
1296*cdf0e10cSrcweir 				const Any aBooleanValue( PropertyConversion::convertString(m_rContext.getGlobalContext(), pProperty->aPropertyType, _rValue, pProperty->pEnumMap) );
1297*cdf0e10cSrcweir 
1298*cdf0e10cSrcweir 				// create and store a new PropertyValue
1299*cdf0e10cSrcweir 				PropertyValue aNewValue;
1300*cdf0e10cSrcweir 				aNewValue.Name = pProperty->sPropertyName;
1301*cdf0e10cSrcweir 				aNewValue.Value <<= (sal_Int16)::cppu::any2bool(aBooleanValue);
1302*cdf0e10cSrcweir 
1303*cdf0e10cSrcweir 				implPushBackPropertyValue(aNewValue);
1304*cdf0e10cSrcweir 			}
1305*cdf0e10cSrcweir             return true;
1306*cdf0e10cSrcweir 		}
1307*cdf0e10cSrcweir 		return OImagePositionImport::handleAttribute( _nNamespaceKey, _rLocalName, _rValue );
1308*cdf0e10cSrcweir 	}
1309*cdf0e10cSrcweir 
1310*cdf0e10cSrcweir 	//=====================================================================
1311*cdf0e10cSrcweir 	//= OURLReferenceImport
1312*cdf0e10cSrcweir 	//=====================================================================
1313*cdf0e10cSrcweir 	OURLReferenceImport::OURLReferenceImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
1314*cdf0e10cSrcweir 			const Reference< XNameContainer >& _rxParentContainer,
1315*cdf0e10cSrcweir 			OControlElement::ElementType _eType)
1316*cdf0e10cSrcweir 		:OImagePositionImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType)
1317*cdf0e10cSrcweir 	{
1318*cdf0e10cSrcweir 	}
1319*cdf0e10cSrcweir 
1320*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1321*cdf0e10cSrcweir 	bool OURLReferenceImport::handleAttribute(sal_uInt16 _nNamespaceKey, const ::rtl::OUString& _rLocalName, const ::rtl::OUString& _rValue)
1322*cdf0e10cSrcweir 	{
1323*cdf0e10cSrcweir 		static const sal_Char* s_pTargetLocationAttributeName	= OAttributeMetaData::getCommonControlAttributeName( CCA_TARGET_LOCATION );
1324*cdf0e10cSrcweir 		static const sal_Char* s_pImageDataAttributeName		= OAttributeMetaData::getCommonControlAttributeName( CCA_IMAGE_DATA );
1325*cdf0e10cSrcweir 
1326*cdf0e10cSrcweir 		// need to make the URL absolute if
1327*cdf0e10cSrcweir 		// * it's the image-data attribute
1328*cdf0e10cSrcweir 		// * it's the target-location attribute, and we're dealign with an object which has the respective property
1329*cdf0e10cSrcweir 		sal_Bool bMakeAbsolute =
1330*cdf0e10cSrcweir 				( 0 == _rLocalName.compareToAscii( s_pImageDataAttributeName ) )
1331*cdf0e10cSrcweir 			||	(	( 0 == _rLocalName.compareToAscii( s_pTargetLocationAttributeName ) )
1332*cdf0e10cSrcweir 				&&	(	( OControlElement::BUTTON == m_eElementType )
1333*cdf0e10cSrcweir 					||	( OControlElement::IMAGE == m_eElementType )
1334*cdf0e10cSrcweir 					)
1335*cdf0e10cSrcweir 				);
1336*cdf0e10cSrcweir 
1337*cdf0e10cSrcweir 		if ( bMakeAbsolute && ( _rValue.getLength() > 0  ) )
1338*cdf0e10cSrcweir 		{
1339*cdf0e10cSrcweir 			// make a global URL out of the local one
1340*cdf0e10cSrcweir             ::rtl::OUString sAdjustedValue;
1341*cdf0e10cSrcweir             // only resolve image related url
1342*cdf0e10cSrcweir             // we don't want say form url targets to be resolved
1343*cdf0e10cSrcweir             // using ResolveGraphicObjectURL
1344*cdf0e10cSrcweir             if ( 0 == _rLocalName.compareToAscii( s_pImageDataAttributeName ) )
1345*cdf0e10cSrcweir                 sAdjustedValue = m_rContext.getGlobalContext().ResolveGraphicObjectURL( _rValue, sal_False );
1346*cdf0e10cSrcweir             else
1347*cdf0e10cSrcweir                 sAdjustedValue = m_rContext.getGlobalContext().GetAbsoluteReference( _rValue );
1348*cdf0e10cSrcweir             return OImagePositionImport::handleAttribute( _nNamespaceKey, _rLocalName, sAdjustedValue );
1349*cdf0e10cSrcweir 		}
1350*cdf0e10cSrcweir 
1351*cdf0e10cSrcweir 		return OImagePositionImport::handleAttribute( _nNamespaceKey, _rLocalName, _rValue );
1352*cdf0e10cSrcweir 	}
1353*cdf0e10cSrcweir 
1354*cdf0e10cSrcweir 	//=====================================================================
1355*cdf0e10cSrcweir 	//= OButtonImport
1356*cdf0e10cSrcweir 	//=====================================================================
1357*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1358*cdf0e10cSrcweir 	OButtonImport::OButtonImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
1359*cdf0e10cSrcweir 			const Reference< XNameContainer >& _rxParentContainer,
1360*cdf0e10cSrcweir 			OControlElement::ElementType _eType)
1361*cdf0e10cSrcweir 		:OURLReferenceImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType)
1362*cdf0e10cSrcweir 	{
1363*cdf0e10cSrcweir 		enableTrackAttributes();
1364*cdf0e10cSrcweir 	}
1365*cdf0e10cSrcweir 
1366*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1367*cdf0e10cSrcweir 	void OButtonImport::StartElement(const Reference< sax::XAttributeList >& _rxAttrList)
1368*cdf0e10cSrcweir 	{
1369*cdf0e10cSrcweir 		OURLReferenceImport::StartElement(_rxAttrList);
1370*cdf0e10cSrcweir 
1371*cdf0e10cSrcweir 		// handle the target-frame attribute
1372*cdf0e10cSrcweir 		simulateDefaultedAttribute(OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_FRAME), PROPERTY_TARGETFRAME, "_blank");
1373*cdf0e10cSrcweir 	}
1374*cdf0e10cSrcweir 
1375*cdf0e10cSrcweir 	//=====================================================================
1376*cdf0e10cSrcweir 	//= OValueRangeImport
1377*cdf0e10cSrcweir 	//=====================================================================
1378*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1379*cdf0e10cSrcweir 	OValueRangeImport::OValueRangeImport( OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
1380*cdf0e10cSrcweir 			const Reference< XNameContainer >& _rxParentContainer, OControlElement::ElementType _eType )
1381*cdf0e10cSrcweir 		:OControlImport( _rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType )
1382*cdf0e10cSrcweir         ,m_nStepSizeValue( 1 )
1383*cdf0e10cSrcweir 	{
1384*cdf0e10cSrcweir 
1385*cdf0e10cSrcweir 	}
1386*cdf0e10cSrcweir 
1387*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1388*cdf0e10cSrcweir 	bool OValueRangeImport::handleAttribute( sal_uInt16 _nNamespaceKey, const ::rtl::OUString& _rLocalName, const ::rtl::OUString& _rValue )
1389*cdf0e10cSrcweir     {
1390*cdf0e10cSrcweir         if ( _rLocalName.equalsAscii( OAttributeMetaData::getSpecialAttributeName( SCA_STEP_SIZE ) ) )
1391*cdf0e10cSrcweir         {
1392*cdf0e10cSrcweir     		GetImport().GetMM100UnitConverter().convertNumber( m_nStepSizeValue, _rValue );
1393*cdf0e10cSrcweir             return true;
1394*cdf0e10cSrcweir         }
1395*cdf0e10cSrcweir         return OControlImport::handleAttribute( _nNamespaceKey, _rLocalName, _rValue );
1396*cdf0e10cSrcweir     }
1397*cdf0e10cSrcweir 
1398*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1399*cdf0e10cSrcweir 	void OValueRangeImport::StartElement( const Reference< sax::XAttributeList >& _rxAttrList )
1400*cdf0e10cSrcweir 	{
1401*cdf0e10cSrcweir 		OControlImport::StartElement( _rxAttrList );
1402*cdf0e10cSrcweir 
1403*cdf0e10cSrcweir         if ( m_xInfo.is() )
1404*cdf0e10cSrcweir         {
1405*cdf0e10cSrcweir             if ( m_xInfo->hasPropertyByName( PROPERTY_SPIN_INCREMENT ) )
1406*cdf0e10cSrcweir                 m_xElement->setPropertyValue( PROPERTY_SPIN_INCREMENT, makeAny( m_nStepSizeValue ) );
1407*cdf0e10cSrcweir             else if ( m_xInfo->hasPropertyByName( PROPERTY_LINE_INCREMENT ) )
1408*cdf0e10cSrcweir                 m_xElement->setPropertyValue( PROPERTY_LINE_INCREMENT, makeAny( m_nStepSizeValue ) );
1409*cdf0e10cSrcweir 		}
1410*cdf0e10cSrcweir 	}
1411*cdf0e10cSrcweir 
1412*cdf0e10cSrcweir 	//=====================================================================
1413*cdf0e10cSrcweir 	//= OTextLikeImport
1414*cdf0e10cSrcweir 	//=====================================================================
1415*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1416*cdf0e10cSrcweir 	OTextLikeImport::OTextLikeImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
1417*cdf0e10cSrcweir 			const Reference< XNameContainer >& _rxParentContainer,
1418*cdf0e10cSrcweir 			OControlElement::ElementType _eType)
1419*cdf0e10cSrcweir 		:OControlImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType)
1420*cdf0e10cSrcweir         ,m_bEncounteredTextPara( false )
1421*cdf0e10cSrcweir 	{
1422*cdf0e10cSrcweir 		enableTrackAttributes();
1423*cdf0e10cSrcweir 	}
1424*cdf0e10cSrcweir 
1425*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1426*cdf0e10cSrcweir     SvXMLImportContext* OTextLikeImport::CreateChildContext( sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
1427*cdf0e10cSrcweir         const Reference< sax::XAttributeList >& _rxAttrList )
1428*cdf0e10cSrcweir     {
1429*cdf0e10cSrcweir 		if ( ( XML_NAMESPACE_TEXT == _nPrefix ) && _rLocalName.equalsIgnoreAsciiCaseAscii( "p" ) )
1430*cdf0e10cSrcweir         {
1431*cdf0e10cSrcweir             OSL_ENSURE( m_eElementType == OControlElement::TEXT_AREA,
1432*cdf0e10cSrcweir                 "OTextLikeImport::CreateChildContext: text paragraphs in a non-text-area?" );
1433*cdf0e10cSrcweir 
1434*cdf0e10cSrcweir             if ( m_eElementType == OControlElement::TEXT_AREA )
1435*cdf0e10cSrcweir             {
1436*cdf0e10cSrcweir                 Reference< XText > xTextElement( m_xElement, UNO_QUERY );
1437*cdf0e10cSrcweir                 if ( xTextElement.is() )
1438*cdf0e10cSrcweir                 {
1439*cdf0e10cSrcweir                     UniReference < XMLTextImportHelper > xTextImportHelper( m_rContext.getGlobalContext().GetTextImport() );
1440*cdf0e10cSrcweir 
1441*cdf0e10cSrcweir                     if ( !m_xCursor.is() )
1442*cdf0e10cSrcweir                     {
1443*cdf0e10cSrcweir 				        m_xOldCursor = xTextImportHelper->GetCursor();
1444*cdf0e10cSrcweir 				        m_xCursor = xTextElement->createTextCursor();
1445*cdf0e10cSrcweir 
1446*cdf0e10cSrcweir                         if ( m_xCursor.is() )
1447*cdf0e10cSrcweir 					        xTextImportHelper->SetCursor( m_xCursor );
1448*cdf0e10cSrcweir                     }
1449*cdf0e10cSrcweir                     if ( m_xCursor.is() )
1450*cdf0e10cSrcweir                     {
1451*cdf0e10cSrcweir                         m_bEncounteredTextPara = true;
1452*cdf0e10cSrcweir 			            return xTextImportHelper->CreateTextChildContext( m_rContext.getGlobalContext(), _nPrefix, _rLocalName, _rxAttrList );
1453*cdf0e10cSrcweir                     }
1454*cdf0e10cSrcweir                 }
1455*cdf0e10cSrcweir                 else
1456*cdf0e10cSrcweir                 {
1457*cdf0e10cSrcweir                     // in theory, we could accumulate all the text portions (without formatting),
1458*cdf0e10cSrcweir                     // and set it as Text property at the model ...
1459*cdf0e10cSrcweir                 }
1460*cdf0e10cSrcweir             }
1461*cdf0e10cSrcweir         }
1462*cdf0e10cSrcweir 
1463*cdf0e10cSrcweir         return OControlImport::CreateChildContext( _nPrefix, _rLocalName, _rxAttrList );
1464*cdf0e10cSrcweir     }
1465*cdf0e10cSrcweir 
1466*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1467*cdf0e10cSrcweir 	void OTextLikeImport::StartElement(const Reference< sax::XAttributeList >& _rxAttrList)
1468*cdf0e10cSrcweir 	{
1469*cdf0e10cSrcweir 		OControlImport::StartElement(_rxAttrList);
1470*cdf0e10cSrcweir 
1471*cdf0e10cSrcweir 		// handle the convert-empty-to-null attribute, whose default is different from the property default
1472*cdf0e10cSrcweir 		// unfortunately, different classes are imported by this class ('cause they're represented by the
1473*cdf0e10cSrcweir 		// same XML element), though not all of them know this property.
1474*cdf0e10cSrcweir 		// So we have to do a check ...
1475*cdf0e10cSrcweir 		if (m_xElement.is() && m_xInfo.is() && m_xInfo->hasPropertyByName(PROPERTY_EMPTY_IS_NULL) )
1476*cdf0e10cSrcweir 			simulateDefaultedAttribute(OAttributeMetaData::getDatabaseAttributeName(DA_CONVERT_EMPTY), PROPERTY_EMPTY_IS_NULL, "false");
1477*cdf0e10cSrcweir 	}
1478*cdf0e10cSrcweir 
1479*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1480*cdf0e10cSrcweir     struct EqualHandle : public ::std::unary_function< PropertyValue, bool >
1481*cdf0e10cSrcweir     {
1482*cdf0e10cSrcweir         const sal_Int32 m_nHandle;
1483*cdf0e10cSrcweir         EqualHandle( sal_Int32 _nHandle ) : m_nHandle( _nHandle ) { }
1484*cdf0e10cSrcweir 
1485*cdf0e10cSrcweir         inline bool operator()( const PropertyValue& _rProp )
1486*cdf0e10cSrcweir         {
1487*cdf0e10cSrcweir             return _rProp.Handle == m_nHandle;
1488*cdf0e10cSrcweir         }
1489*cdf0e10cSrcweir     };
1490*cdf0e10cSrcweir 
1491*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1492*cdf0e10cSrcweir 	void OTextLikeImport::removeRedundantCurrentValue()
1493*cdf0e10cSrcweir     {
1494*cdf0e10cSrcweir         if ( m_bEncounteredTextPara )
1495*cdf0e10cSrcweir         {
1496*cdf0e10cSrcweir             // In case the text is written in the text:p elements, we need to ignore what we read as
1497*cdf0e10cSrcweir             // current-value attribute, since it's redundant.
1498*cdf0e10cSrcweir             // fortunately, OElementImport tagged the value property with the PROPID_CURRENT_VALUE
1499*cdf0e10cSrcweir             // handle, so we do not need to determine the name of our value property here
1500*cdf0e10cSrcweir             // (normally, it should be "Text", since no other controls than the edit field should
1501*cdf0e10cSrcweir             // have the text:p elements)
1502*cdf0e10cSrcweir             PropertyValueArray::iterator aValuePropertyPos = ::std::find_if(
1503*cdf0e10cSrcweir                 m_aValues.begin(),
1504*cdf0e10cSrcweir                 m_aValues.end(),
1505*cdf0e10cSrcweir                 EqualHandle( PROPID_CURRENT_VALUE )
1506*cdf0e10cSrcweir             );
1507*cdf0e10cSrcweir             if ( aValuePropertyPos != m_aValues.end() )
1508*cdf0e10cSrcweir             {
1509*cdf0e10cSrcweir                 OSL_ENSURE( aValuePropertyPos->Name == PROPERTY_TEXT, "OTextLikeImport::EndElement: text:p was present, but our value property is *not* 'Text'!" );
1510*cdf0e10cSrcweir                 if ( aValuePropertyPos->Name == PROPERTY_TEXT )
1511*cdf0e10cSrcweir                 {
1512*cdf0e10cSrcweir                     ::std::copy(
1513*cdf0e10cSrcweir                         aValuePropertyPos + 1,
1514*cdf0e10cSrcweir                         m_aValues.end(),
1515*cdf0e10cSrcweir                         aValuePropertyPos
1516*cdf0e10cSrcweir                     );
1517*cdf0e10cSrcweir                     m_aValues.resize( m_aValues.size() - 1 );
1518*cdf0e10cSrcweir                 }
1519*cdf0e10cSrcweir             }
1520*cdf0e10cSrcweir 
1521*cdf0e10cSrcweir             // additionally, we need to set the "RichText" property of our element to sal_True
1522*cdf0e10cSrcweir             // (the presence of the text:p is used as indicator for the value of the RichText property)
1523*cdf0e10cSrcweir             sal_Bool bHasRichTextProperty = sal_False;
1524*cdf0e10cSrcweir 			if ( m_xInfo.is() )
1525*cdf0e10cSrcweir 				bHasRichTextProperty = m_xInfo->hasPropertyByName( PROPERTY_RICH_TEXT );
1526*cdf0e10cSrcweir             OSL_ENSURE( bHasRichTextProperty, "OTextLikeImport::EndElement: text:p, but no rich text control?" );
1527*cdf0e10cSrcweir             if ( bHasRichTextProperty )
1528*cdf0e10cSrcweir                 m_xElement->setPropertyValue( PROPERTY_RICH_TEXT, makeAny( (sal_Bool)sal_True ) );
1529*cdf0e10cSrcweir         }
1530*cdf0e10cSrcweir         // Note that we do *not* set the RichText property (in case our element has one) to sal_False here
1531*cdf0e10cSrcweir         // since this is the default of this property, anyway.
1532*cdf0e10cSrcweir     }
1533*cdf0e10cSrcweir 
1534*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1535*cdf0e10cSrcweir     struct EqualName : public ::std::unary_function< PropertyValue, bool >
1536*cdf0e10cSrcweir     {
1537*cdf0e10cSrcweir         const ::rtl::OUString m_sName;
1538*cdf0e10cSrcweir         EqualName( const ::rtl::OUString& _rName ) : m_sName( _rName ) { }
1539*cdf0e10cSrcweir 
1540*cdf0e10cSrcweir         inline bool operator()( const PropertyValue& _rProp )
1541*cdf0e10cSrcweir         {
1542*cdf0e10cSrcweir             return _rProp.Name == m_sName;
1543*cdf0e10cSrcweir         }
1544*cdf0e10cSrcweir     };
1545*cdf0e10cSrcweir 
1546*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1547*cdf0e10cSrcweir     void OTextLikeImport::adjustDefaultControlProperty()
1548*cdf0e10cSrcweir     {
1549*cdf0e10cSrcweir         // In OpenOffice.org 2.0, we changed the implementation of the css.form.component.TextField (the model of a text field control),
1550*cdf0e10cSrcweir         // so that it now uses another default control. So if we encounter a text field where the *old* default
1551*cdf0e10cSrcweir         // control property is writting, we are not allowed to use it
1552*cdf0e10cSrcweir         PropertyValueArray::iterator aDefaultControlPropertyPos = ::std::find_if(
1553*cdf0e10cSrcweir             m_aValues.begin(),
1554*cdf0e10cSrcweir             m_aValues.end(),
1555*cdf0e10cSrcweir             EqualName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultControl" ) ) )
1556*cdf0e10cSrcweir         );
1557*cdf0e10cSrcweir         if ( aDefaultControlPropertyPos != m_aValues.end() )
1558*cdf0e10cSrcweir         {
1559*cdf0e10cSrcweir             ::rtl::OUString sDefaultControl;
1560*cdf0e10cSrcweir             OSL_VERIFY( aDefaultControlPropertyPos->Value >>= sDefaultControl );
1561*cdf0e10cSrcweir             if ( sDefaultControl.equalsAscii( "stardiv.one.form.control.Edit" ) )
1562*cdf0e10cSrcweir             {
1563*cdf0e10cSrcweir                 // complete remove this property value from the array. Today's "default value" of the "DefaultControl"
1564*cdf0e10cSrcweir                 // property is sufficient
1565*cdf0e10cSrcweir                 ::std::copy(
1566*cdf0e10cSrcweir                     aDefaultControlPropertyPos + 1,
1567*cdf0e10cSrcweir                     m_aValues.end(),
1568*cdf0e10cSrcweir                     aDefaultControlPropertyPos
1569*cdf0e10cSrcweir                 );
1570*cdf0e10cSrcweir                 m_aValues.resize( m_aValues.size() - 1 );
1571*cdf0e10cSrcweir             }
1572*cdf0e10cSrcweir         }
1573*cdf0e10cSrcweir     }
1574*cdf0e10cSrcweir 
1575*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1576*cdf0e10cSrcweir 	void OTextLikeImport::EndElement()
1577*cdf0e10cSrcweir     {
1578*cdf0e10cSrcweir         removeRedundantCurrentValue();
1579*cdf0e10cSrcweir         adjustDefaultControlProperty();
1580*cdf0e10cSrcweir 
1581*cdf0e10cSrcweir         // let the base class do the stuff
1582*cdf0e10cSrcweir         OControlImport::EndElement();
1583*cdf0e10cSrcweir 
1584*cdf0e10cSrcweir         // some cleanups
1585*cdf0e10cSrcweir         UniReference < XMLTextImportHelper > xTextImportHelper( m_rContext.getGlobalContext().GetTextImport() );
1586*cdf0e10cSrcweir         if ( m_xCursor.is() )
1587*cdf0e10cSrcweir 	    {
1588*cdf0e10cSrcweir 		    // delete the newline which has been imported errornously
1589*cdf0e10cSrcweir             // TODO (fs): stole this code somewhere - why don't we fix the text import??
1590*cdf0e10cSrcweir 		    m_xCursor->gotoEnd( sal_False );
1591*cdf0e10cSrcweir 		    m_xCursor->goLeft( 1, sal_True );
1592*cdf0e10cSrcweir             m_xCursor->setString( ::rtl::OUString() );
1593*cdf0e10cSrcweir 
1594*cdf0e10cSrcweir 		    // reset cursor
1595*cdf0e10cSrcweir 		    xTextImportHelper->ResetCursor();
1596*cdf0e10cSrcweir 	    }
1597*cdf0e10cSrcweir 
1598*cdf0e10cSrcweir         if ( m_xOldCursor.is() )
1599*cdf0e10cSrcweir 		    xTextImportHelper->SetCursor( m_xOldCursor );
1600*cdf0e10cSrcweir 
1601*cdf0e10cSrcweir     }
1602*cdf0e10cSrcweir 
1603*cdf0e10cSrcweir 	//=====================================================================
1604*cdf0e10cSrcweir 	//= OListAndComboImport
1605*cdf0e10cSrcweir 	//=====================================================================
1606*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1607*cdf0e10cSrcweir 	OListAndComboImport::OListAndComboImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
1608*cdf0e10cSrcweir 			const Reference< XNameContainer >& _rxParentContainer,
1609*cdf0e10cSrcweir 			OControlElement::ElementType _eType)
1610*cdf0e10cSrcweir 		:OControlImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType)
1611*cdf0e10cSrcweir 		,m_nEmptyListItems( 0 )
1612*cdf0e10cSrcweir 		,m_nEmptyValueItems( 0 )
1613*cdf0e10cSrcweir 		,m_bEncounteredLSAttrib( sal_False )
1614*cdf0e10cSrcweir         ,m_bLinkWithIndexes( sal_False )
1615*cdf0e10cSrcweir 	{
1616*cdf0e10cSrcweir 		if (OControlElement::COMBOBOX == m_eElementType)
1617*cdf0e10cSrcweir 			enableTrackAttributes();
1618*cdf0e10cSrcweir 	}
1619*cdf0e10cSrcweir 
1620*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1621*cdf0e10cSrcweir 	SvXMLImportContext* OListAndComboImport::CreateChildContext(sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
1622*cdf0e10cSrcweir 			const Reference< sax::XAttributeList >& _rxAttrList)
1623*cdf0e10cSrcweir 	{
1624*cdf0e10cSrcweir 		// is it the "option" sub tag of a listbox ?
1625*cdf0e10cSrcweir 		static const ::rtl::OUString s_sOptionElementName = ::rtl::OUString::createFromAscii("option");
1626*cdf0e10cSrcweir 		if (s_sOptionElementName == _rLocalName)
1627*cdf0e10cSrcweir 			return new OListOptionImport(GetImport(), _nPrefix, _rLocalName, this);
1628*cdf0e10cSrcweir 
1629*cdf0e10cSrcweir 		// is it the "item" sub tag of a combobox ?
1630*cdf0e10cSrcweir 		static const ::rtl::OUString s_sItemElementName = ::rtl::OUString::createFromAscii("item");
1631*cdf0e10cSrcweir 		if (s_sItemElementName == _rLocalName)
1632*cdf0e10cSrcweir 			return new OComboItemImport(GetImport(), _nPrefix, _rLocalName, this);
1633*cdf0e10cSrcweir 
1634*cdf0e10cSrcweir 		// everything else
1635*cdf0e10cSrcweir 		return OControlImport::CreateChildContext(_nPrefix, _rLocalName, _rxAttrList);
1636*cdf0e10cSrcweir 	}
1637*cdf0e10cSrcweir 
1638*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1639*cdf0e10cSrcweir 	void OListAndComboImport::StartElement(const Reference< sax::XAttributeList >& _rxAttrList)
1640*cdf0e10cSrcweir 	{
1641*cdf0e10cSrcweir         m_bLinkWithIndexes = sal_False;
1642*cdf0e10cSrcweir 
1643*cdf0e10cSrcweir 		OControlImport::StartElement(_rxAttrList);
1644*cdf0e10cSrcweir 
1645*cdf0e10cSrcweir 		if (OControlElement::COMBOBOX == m_eElementType)
1646*cdf0e10cSrcweir 		{
1647*cdf0e10cSrcweir 			// for the auto-completion
1648*cdf0e10cSrcweir 			// the attribute default does not equal the property default, so in case we did not read this attribute,
1649*cdf0e10cSrcweir 			// we have to simulate it
1650*cdf0e10cSrcweir 			simulateDefaultedAttribute( OAttributeMetaData::getSpecialAttributeName( SCA_AUTOMATIC_COMPLETION ), PROPERTY_AUTOCOMPLETE, "false");
1651*cdf0e10cSrcweir 
1652*cdf0e10cSrcweir 			// same for the convert-empty-to-null attribute, which's default is different from the property default
1653*cdf0e10cSrcweir 			simulateDefaultedAttribute( OAttributeMetaData::getDatabaseAttributeName( DA_CONVERT_EMPTY ), PROPERTY_EMPTY_IS_NULL, "false");
1654*cdf0e10cSrcweir 		}
1655*cdf0e10cSrcweir 	}
1656*cdf0e10cSrcweir 
1657*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1658*cdf0e10cSrcweir 	void OListAndComboImport::EndElement()
1659*cdf0e10cSrcweir 	{
1660*cdf0e10cSrcweir 		// append the list source property the the properties sequence of our importer
1661*cdf0e10cSrcweir 		// the string item list
1662*cdf0e10cSrcweir 		PropertyValue aItemList;
1663*cdf0e10cSrcweir 		aItemList.Name = PROPERTY_STRING_ITEM_LIST;
1664*cdf0e10cSrcweir 		aItemList.Value <<= m_aListSource;
1665*cdf0e10cSrcweir 		implPushBackPropertyValue(aItemList);
1666*cdf0e10cSrcweir 
1667*cdf0e10cSrcweir 		if (OControlElement::LISTBOX == m_eElementType)
1668*cdf0e10cSrcweir 		{
1669*cdf0e10cSrcweir 			OSL_ENSURE((m_aListSource.getLength() + m_nEmptyListItems) == (m_aValueList.getLength() + m_nEmptyValueItems),
1670*cdf0e10cSrcweir 				"OListAndComboImport::EndElement: inconsistence between labels and values!");
1671*cdf0e10cSrcweir 
1672*cdf0e10cSrcweir 			if ( !m_bEncounteredLSAttrib )
1673*cdf0e10cSrcweir 			{
1674*cdf0e10cSrcweir 				// the value sequence
1675*cdf0e10cSrcweir 				PropertyValue aValueList;
1676*cdf0e10cSrcweir 				aValueList.Name = PROPERTY_LISTSOURCE;
1677*cdf0e10cSrcweir 				aValueList.Value <<= m_aValueList;
1678*cdf0e10cSrcweir 				implPushBackPropertyValue(aValueList);
1679*cdf0e10cSrcweir 			}
1680*cdf0e10cSrcweir 
1681*cdf0e10cSrcweir 			// the select sequence
1682*cdf0e10cSrcweir 			PropertyValue aSelected;
1683*cdf0e10cSrcweir 			aSelected.Name = PROPERTY_SELECT_SEQ;
1684*cdf0e10cSrcweir 			aSelected.Value <<= m_aSelectedSeq;
1685*cdf0e10cSrcweir 			implPushBackPropertyValue(aSelected);
1686*cdf0e10cSrcweir 
1687*cdf0e10cSrcweir 			// the default select sequence
1688*cdf0e10cSrcweir 			PropertyValue aDefaultSelected;
1689*cdf0e10cSrcweir 			aDefaultSelected.Name = PROPERTY_DEFAULT_SELECT_SEQ;
1690*cdf0e10cSrcweir 			aDefaultSelected.Value <<= m_aDefaultSelectedSeq;
1691*cdf0e10cSrcweir 			implPushBackPropertyValue(aDefaultSelected);
1692*cdf0e10cSrcweir 		}
1693*cdf0e10cSrcweir 
1694*cdf0e10cSrcweir 		OControlImport::EndElement();
1695*cdf0e10cSrcweir 
1696*cdf0e10cSrcweir         // the external list source, if applicable
1697*cdf0e10cSrcweir         if ( m_xElement.is() && m_sCellListSource.getLength() )
1698*cdf0e10cSrcweir             m_rContext.registerCellRangeListSource( m_xElement, m_sCellListSource );
1699*cdf0e10cSrcweir 	}
1700*cdf0e10cSrcweir 
1701*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1702*cdf0e10cSrcweir 	void OListAndComboImport::doRegisterCellValueBinding( const ::rtl::OUString& _rBoundCellAddress )
1703*cdf0e10cSrcweir     {
1704*cdf0e10cSrcweir         ::rtl::OUString sBoundCellAddress( _rBoundCellAddress );
1705*cdf0e10cSrcweir         if ( m_bLinkWithIndexes )
1706*cdf0e10cSrcweir         {
1707*cdf0e10cSrcweir             // This is a HACK. We register a string which is no valid address, but allows
1708*cdf0e10cSrcweir             // (somewhere else) to determine that a non-standard binding should be created.
1709*cdf0e10cSrcweir             // This hack is acceptable for OOo 1.1.1, since the file format for value
1710*cdf0e10cSrcweir             // bindings of form controls is to be changed afterwards, anyway.
1711*cdf0e10cSrcweir             sBoundCellAddress += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":index" ) );
1712*cdf0e10cSrcweir         }
1713*cdf0e10cSrcweir 
1714*cdf0e10cSrcweir         OControlImport::doRegisterCellValueBinding( sBoundCellAddress );
1715*cdf0e10cSrcweir     }
1716*cdf0e10cSrcweir 
1717*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1718*cdf0e10cSrcweir 	bool OListAndComboImport::handleAttribute(sal_uInt16 _nNamespaceKey, const ::rtl::OUString& _rLocalName, const ::rtl::OUString& _rValue)
1719*cdf0e10cSrcweir 	{
1720*cdf0e10cSrcweir         static const sal_Char* pListSourceAttributeName = OAttributeMetaData::getDatabaseAttributeName(DA_LIST_SOURCE);
1721*cdf0e10cSrcweir 		if ( _rLocalName.equalsAscii(pListSourceAttributeName) )
1722*cdf0e10cSrcweir 		{
1723*cdf0e10cSrcweir 			PropertyValue aListSource;
1724*cdf0e10cSrcweir 			aListSource.Name = PROPERTY_LISTSOURCE;
1725*cdf0e10cSrcweir 
1726*cdf0e10cSrcweir 			// it's the ListSource attribute
1727*cdf0e10cSrcweir 			m_bEncounteredLSAttrib = sal_True;
1728*cdf0e10cSrcweir 			if ( OControlElement::COMBOBOX == m_eElementType )
1729*cdf0e10cSrcweir 			{
1730*cdf0e10cSrcweir 				aListSource.Value <<= _rValue;
1731*cdf0e10cSrcweir 			}
1732*cdf0e10cSrcweir 			else
1733*cdf0e10cSrcweir 			{
1734*cdf0e10cSrcweir 				// a listbox which has a list-source attribute must have a list-source-type of something
1735*cdf0e10cSrcweir 				// not equal to ValueList.
1736*cdf0e10cSrcweir 				// In this case, the list-source value is simply the one and only element of the ListSource property.
1737*cdf0e10cSrcweir 				Sequence< ::rtl::OUString > aListSourcePropValue( 1 );
1738*cdf0e10cSrcweir 				aListSourcePropValue[0] = _rValue;
1739*cdf0e10cSrcweir 				aListSource.Value <<= aListSourcePropValue;
1740*cdf0e10cSrcweir 			}
1741*cdf0e10cSrcweir 
1742*cdf0e10cSrcweir 			implPushBackPropertyValue( aListSource );
1743*cdf0e10cSrcweir             return true;
1744*cdf0e10cSrcweir 		}
1745*cdf0e10cSrcweir 
1746*cdf0e10cSrcweir         if ( _rLocalName.equalsAscii( OAttributeMetaData::getBindingAttributeName( BA_LIST_CELL_RANGE ) ) )
1747*cdf0e10cSrcweir         {
1748*cdf0e10cSrcweir             m_sCellListSource = _rValue;
1749*cdf0e10cSrcweir             return true;
1750*cdf0e10cSrcweir         }
1751*cdf0e10cSrcweir 
1752*cdf0e10cSrcweir 		if ( _rLocalName.equalsAscii( OAttributeMetaData::getBindingAttributeName( BA_LIST_LINKING_TYPE ) ) )
1753*cdf0e10cSrcweir         {
1754*cdf0e10cSrcweir             sal_Int16 nLinkageType = 0;
1755*cdf0e10cSrcweir             PropertyConversion::convertString(
1756*cdf0e10cSrcweir                 m_rContext.getGlobalContext(),
1757*cdf0e10cSrcweir                 ::getCppuType( static_cast< sal_Int16* >( NULL ) ),
1758*cdf0e10cSrcweir                 _rValue,
1759*cdf0e10cSrcweir                 OEnumMapper::getEnumMap( OEnumMapper::epListLinkageType )
1760*cdf0e10cSrcweir             ) >>= nLinkageType;
1761*cdf0e10cSrcweir 
1762*cdf0e10cSrcweir             m_bLinkWithIndexes = ( nLinkageType != 0 );
1763*cdf0e10cSrcweir             return true;
1764*cdf0e10cSrcweir         }
1765*cdf0e10cSrcweir 
1766*cdf0e10cSrcweir 		return OControlImport::handleAttribute(_nNamespaceKey, _rLocalName, _rValue);
1767*cdf0e10cSrcweir 	}
1768*cdf0e10cSrcweir 
1769*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1770*cdf0e10cSrcweir 	void OListAndComboImport::implPushBackLabel(const ::rtl::OUString& _rLabel)
1771*cdf0e10cSrcweir 	{
1772*cdf0e10cSrcweir 		OSL_ENSURE(!m_nEmptyListItems, "OListAndComboImport::implPushBackValue: label list is already done!");
1773*cdf0e10cSrcweir 		if (!m_nEmptyListItems)
1774*cdf0e10cSrcweir 			pushBackSequenceElement(m_aListSource, _rLabel);
1775*cdf0e10cSrcweir 	}
1776*cdf0e10cSrcweir 
1777*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1778*cdf0e10cSrcweir 	void OListAndComboImport::implPushBackValue(const ::rtl::OUString& _rValue)
1779*cdf0e10cSrcweir 	{
1780*cdf0e10cSrcweir 		OSL_ENSURE(!m_nEmptyValueItems, "OListAndComboImport::implPushBackValue: value list is already done!");
1781*cdf0e10cSrcweir 		if (!m_nEmptyValueItems)
1782*cdf0e10cSrcweir 		{
1783*cdf0e10cSrcweir 			OSL_ENSURE( !m_bEncounteredLSAttrib, "OListAndComboImport::implPushBackValue: invalid structure! Did you save this document with a version prior SRC641 m?" );
1784*cdf0e10cSrcweir 				// We already had the list-source attribute, which means that the ListSourceType is
1785*cdf0e10cSrcweir 				// not ValueList, which means that the ListSource should contain only one string in
1786*cdf0e10cSrcweir 				// the first element of the sequence
1787*cdf0e10cSrcweir 				// All other values in the file are invalid
1788*cdf0e10cSrcweir 
1789*cdf0e10cSrcweir 			pushBackSequenceElement( m_aValueList, _rValue );
1790*cdf0e10cSrcweir 		}
1791*cdf0e10cSrcweir 	}
1792*cdf0e10cSrcweir 
1793*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1794*cdf0e10cSrcweir 	void OListAndComboImport::implEmptyLabelFound()
1795*cdf0e10cSrcweir 	{
1796*cdf0e10cSrcweir 		++m_nEmptyListItems;
1797*cdf0e10cSrcweir 	}
1798*cdf0e10cSrcweir 
1799*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1800*cdf0e10cSrcweir 	void OListAndComboImport::implEmptyValueFound()
1801*cdf0e10cSrcweir 	{
1802*cdf0e10cSrcweir 		++m_nEmptyValueItems;
1803*cdf0e10cSrcweir 	}
1804*cdf0e10cSrcweir 
1805*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1806*cdf0e10cSrcweir 	void OListAndComboImport::implSelectCurrentItem()
1807*cdf0e10cSrcweir 	{
1808*cdf0e10cSrcweir 		OSL_ENSURE((m_aListSource.getLength() + m_nEmptyListItems) == (m_aValueList.getLength() + m_nEmptyValueItems),
1809*cdf0e10cSrcweir 			"OListAndComboImport::implSelectCurrentItem: inconsistence between labels and values!");
1810*cdf0e10cSrcweir 
1811*cdf0e10cSrcweir 		sal_Int16 nItemNumber = (sal_Int16)(m_aListSource.getLength() - 1 + m_nEmptyListItems);
1812*cdf0e10cSrcweir 		pushBackSequenceElement(m_aSelectedSeq, nItemNumber);
1813*cdf0e10cSrcweir 	}
1814*cdf0e10cSrcweir 
1815*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1816*cdf0e10cSrcweir 	void OListAndComboImport::implDefaultSelectCurrentItem()
1817*cdf0e10cSrcweir 	{
1818*cdf0e10cSrcweir 		OSL_ENSURE((m_aListSource.getLength() + m_nEmptyListItems) == (m_aValueList.getLength() + m_nEmptyValueItems),
1819*cdf0e10cSrcweir 			"OListAndComboImport::implDefaultSelectCurrentItem: inconsistence between labels and values!");
1820*cdf0e10cSrcweir 
1821*cdf0e10cSrcweir 		sal_Int16 nItemNumber = (sal_Int16)(m_aListSource.getLength() - 1 + m_nEmptyListItems);
1822*cdf0e10cSrcweir 		pushBackSequenceElement(m_aDefaultSelectedSeq, nItemNumber);
1823*cdf0e10cSrcweir 	}
1824*cdf0e10cSrcweir 
1825*cdf0e10cSrcweir 	//=====================================================================
1826*cdf0e10cSrcweir 	//= OListOptionImport
1827*cdf0e10cSrcweir 	//=====================================================================
1828*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1829*cdf0e10cSrcweir 	OListOptionImport::OListOptionImport(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
1830*cdf0e10cSrcweir 			const OListAndComboImportRef& _rListBox)
1831*cdf0e10cSrcweir 		:SvXMLImportContext(_rImport, _nPrefix, _rName)
1832*cdf0e10cSrcweir 		,m_xListBoxImport(_rListBox)
1833*cdf0e10cSrcweir 	{
1834*cdf0e10cSrcweir 	}
1835*cdf0e10cSrcweir 
1836*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1837*cdf0e10cSrcweir 	void OListOptionImport::StartElement(const Reference< sax::XAttributeList >& _rxAttrList)
1838*cdf0e10cSrcweir 	{
1839*cdf0e10cSrcweir 		// the label and the value
1840*cdf0e10cSrcweir         const SvXMLNamespaceMap& rMap = GetImport().GetNamespaceMap();
1841*cdf0e10cSrcweir 		const ::rtl::OUString sLabelAttribute = rMap.GetQNameByKey(
1842*cdf0e10cSrcweir 			GetPrefix(), ::rtl::OUString::createFromAscii("label"));
1843*cdf0e10cSrcweir 		const ::rtl::OUString sValueAttribute = rMap.GetQNameByKey(
1844*cdf0e10cSrcweir 			GetPrefix(), ::rtl::OUString::createFromAscii("value"));
1845*cdf0e10cSrcweir 
1846*cdf0e10cSrcweir 		// -------------------
1847*cdf0e10cSrcweir 		// the label attribute
1848*cdf0e10cSrcweir 		::rtl::OUString sValue = _rxAttrList->getValueByName(sLabelAttribute);
1849*cdf0e10cSrcweir 		sal_Bool bNonexistentAttribute = sal_False;
1850*cdf0e10cSrcweir 		if (!sValue.getLength())
1851*cdf0e10cSrcweir 			if (0 == _rxAttrList->getTypeByName(sLabelAttribute).getLength())
1852*cdf0e10cSrcweir 				// this attribute does not really exist
1853*cdf0e10cSrcweir 				bNonexistentAttribute = sal_True;
1854*cdf0e10cSrcweir 
1855*cdf0e10cSrcweir 		if (bNonexistentAttribute)
1856*cdf0e10cSrcweir 			m_xListBoxImport->implEmptyLabelFound();
1857*cdf0e10cSrcweir 		else
1858*cdf0e10cSrcweir 			m_xListBoxImport->implPushBackLabel( sValue );
1859*cdf0e10cSrcweir 
1860*cdf0e10cSrcweir 		// -------------------
1861*cdf0e10cSrcweir 		// the value attribute
1862*cdf0e10cSrcweir 		sValue = _rxAttrList->getValueByName(sValueAttribute);
1863*cdf0e10cSrcweir 		bNonexistentAttribute = sal_False;
1864*cdf0e10cSrcweir 		if (!sValue.getLength())
1865*cdf0e10cSrcweir 			if (0 == _rxAttrList->getTypeByName(sValueAttribute).getLength())
1866*cdf0e10cSrcweir 				// this attribute does not really exist
1867*cdf0e10cSrcweir 				bNonexistentAttribute = sal_True;
1868*cdf0e10cSrcweir 
1869*cdf0e10cSrcweir 		if (bNonexistentAttribute)
1870*cdf0e10cSrcweir 			m_xListBoxImport->implEmptyValueFound();
1871*cdf0e10cSrcweir 		else
1872*cdf0e10cSrcweir 			m_xListBoxImport->implPushBackValue( sValue );
1873*cdf0e10cSrcweir 
1874*cdf0e10cSrcweir 		// the current-selected and selected
1875*cdf0e10cSrcweir 		const ::rtl::OUString sSelectedAttribute = rMap.GetQNameByKey(
1876*cdf0e10cSrcweir 			GetPrefix(), ::rtl::OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_CURRENT_SELECTED)));
1877*cdf0e10cSrcweir 		const ::rtl::OUString sDefaultSelectedAttribute = rMap.GetQNameByKey(
1878*cdf0e10cSrcweir 			GetPrefix(), ::rtl::OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_SELECTED)));
1879*cdf0e10cSrcweir 
1880*cdf0e10cSrcweir 		// propagate the selected flag
1881*cdf0e10cSrcweir 		sal_Bool bSelected;
1882*cdf0e10cSrcweir 		GetImport().GetMM100UnitConverter().convertBool(bSelected, _rxAttrList->getValueByName(sSelectedAttribute));
1883*cdf0e10cSrcweir 		if (bSelected)
1884*cdf0e10cSrcweir 			m_xListBoxImport->implSelectCurrentItem();
1885*cdf0e10cSrcweir 
1886*cdf0e10cSrcweir 		// same for the default selected
1887*cdf0e10cSrcweir 		sal_Bool bDefaultSelected;
1888*cdf0e10cSrcweir 		GetImport().GetMM100UnitConverter().convertBool(bDefaultSelected, _rxAttrList->getValueByName(sDefaultSelectedAttribute));
1889*cdf0e10cSrcweir 		if (bDefaultSelected)
1890*cdf0e10cSrcweir 			m_xListBoxImport->implDefaultSelectCurrentItem();
1891*cdf0e10cSrcweir 
1892*cdf0e10cSrcweir 		SvXMLImportContext::StartElement(_rxAttrList);
1893*cdf0e10cSrcweir 	}
1894*cdf0e10cSrcweir 
1895*cdf0e10cSrcweir 	//=====================================================================
1896*cdf0e10cSrcweir 	//= OComboItemImport
1897*cdf0e10cSrcweir 	//=====================================================================
1898*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1899*cdf0e10cSrcweir 	OComboItemImport::OComboItemImport(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
1900*cdf0e10cSrcweir 			const OListAndComboImportRef& _rListBox)
1901*cdf0e10cSrcweir 		:SvXMLImportContext(_rImport, _nPrefix, _rName)
1902*cdf0e10cSrcweir 		,m_xListBoxImport(_rListBox)
1903*cdf0e10cSrcweir 	{
1904*cdf0e10cSrcweir 	}
1905*cdf0e10cSrcweir 
1906*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1907*cdf0e10cSrcweir 	void OComboItemImport::StartElement(const Reference< sax::XAttributeList >& _rxAttrList)
1908*cdf0e10cSrcweir 	{
1909*cdf0e10cSrcweir 		const ::rtl::OUString sLabelAttributeName = GetImport().GetNamespaceMap().GetQNameByKey(
1910*cdf0e10cSrcweir 			GetPrefix(), ::rtl::OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_LABEL)));
1911*cdf0e10cSrcweir 		m_xListBoxImport->implPushBackLabel(_rxAttrList->getValueByName(sLabelAttributeName));
1912*cdf0e10cSrcweir 
1913*cdf0e10cSrcweir 		SvXMLImportContext::StartElement(_rxAttrList);
1914*cdf0e10cSrcweir 	}
1915*cdf0e10cSrcweir 
1916*cdf0e10cSrcweir 
1917*cdf0e10cSrcweir 	//=====================================================================
1918*cdf0e10cSrcweir 	//= OColumnWrapperImport
1919*cdf0e10cSrcweir 	//=====================================================================
1920*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1921*cdf0e10cSrcweir 	OColumnWrapperImport::OColumnWrapperImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
1922*cdf0e10cSrcweir 			const Reference< XNameContainer >& _rxParentContainer)
1923*cdf0e10cSrcweir 		:SvXMLImportContext(_rImport.getGlobalContext(), _nPrefix, _rName)
1924*cdf0e10cSrcweir 		,m_xParentContainer(_rxParentContainer)
1925*cdf0e10cSrcweir         ,m_rFormImport(_rImport)
1926*cdf0e10cSrcweir 		,m_rEventManager(_rEventManager)
1927*cdf0e10cSrcweir 	{
1928*cdf0e10cSrcweir 	}
1929*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1930*cdf0e10cSrcweir 	SvXMLImportContext* OColumnWrapperImport::CreateChildContext(sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
1931*cdf0e10cSrcweir 		const Reference< sax::XAttributeList >&)
1932*cdf0e10cSrcweir 	{
1933*cdf0e10cSrcweir 		OControlImport* pReturn = implCreateChildContext(_nPrefix, _rLocalName, OElementNameMap::getElementType(_rLocalName));
1934*cdf0e10cSrcweir 		if (pReturn)
1935*cdf0e10cSrcweir 		{
1936*cdf0e10cSrcweir 			OSL_ENSURE(m_xOwnAttributes.is(), "OColumnWrapperImport::CreateChildContext: had no form:column element!");
1937*cdf0e10cSrcweir 			pReturn->addOuterAttributes(m_xOwnAttributes);
1938*cdf0e10cSrcweir 		}
1939*cdf0e10cSrcweir 		return pReturn;
1940*cdf0e10cSrcweir 	}
1941*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1942*cdf0e10cSrcweir 	void OColumnWrapperImport::StartElement(const Reference< sax::XAttributeList >& _rxAttrList)
1943*cdf0e10cSrcweir 	{
1944*cdf0e10cSrcweir 		OSL_ENSURE(!m_xOwnAttributes.is(), "OColumnWrapperImport::StartElement: aready have the cloned list!");
1945*cdf0e10cSrcweir 
1946*cdf0e10cSrcweir 		// clone the attributes
1947*cdf0e10cSrcweir 		Reference< XCloneable > xCloneList(_rxAttrList, UNO_QUERY);
1948*cdf0e10cSrcweir 		OSL_ENSURE(xCloneList.is(), "OColumnWrapperImport::StartElement: AttributeList not cloneable!");
1949*cdf0e10cSrcweir         if ( xCloneList.is() )
1950*cdf0e10cSrcweir 		    m_xOwnAttributes = Reference< sax::XAttributeList >(xCloneList->createClone(), UNO_QUERY);
1951*cdf0e10cSrcweir 		OSL_ENSURE(m_xOwnAttributes.is(), "OColumnWrapperImport::StartElement: no cloned list!");
1952*cdf0e10cSrcweir 	}
1953*cdf0e10cSrcweir 
1954*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1955*cdf0e10cSrcweir 	OControlImport* OColumnWrapperImport::implCreateChildContext(
1956*cdf0e10cSrcweir 			sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
1957*cdf0e10cSrcweir 			OControlElement::ElementType _eType)
1958*cdf0e10cSrcweir 	{
1959*cdf0e10cSrcweir 		OSL_ENSURE(	(OControlElement::TEXT == _eType)
1960*cdf0e10cSrcweir 				||	(OControlElement::TEXT_AREA == _eType)
1961*cdf0e10cSrcweir 				||	(OControlElement::FORMATTED_TEXT == _eType)
1962*cdf0e10cSrcweir 				||	(OControlElement::CHECKBOX == _eType)
1963*cdf0e10cSrcweir 				||	(OControlElement::LISTBOX == _eType)
1964*cdf0e10cSrcweir 				||	(OControlElement::COMBOBOX == _eType)
1965*cdf0e10cSrcweir 				||	(OControlElement::TIME == _eType)
1966*cdf0e10cSrcweir 				||	(OControlElement::DATE == _eType),
1967*cdf0e10cSrcweir 				"OColumnWrapperImport::implCreateChildContext: invalid or unrecognized sub element!");
1968*cdf0e10cSrcweir 
1969*cdf0e10cSrcweir 		switch (_eType)
1970*cdf0e10cSrcweir 		{
1971*cdf0e10cSrcweir 			case OControlElement::COMBOBOX:
1972*cdf0e10cSrcweir 			case OControlElement::LISTBOX:
1973*cdf0e10cSrcweir 				return new OColumnImport<OListAndComboImport>(m_rFormImport, m_rEventManager, _nPrefix, _rLocalName, m_xParentContainer, _eType );
1974*cdf0e10cSrcweir 
1975*cdf0e10cSrcweir 			case OControlElement::PASSWORD:
1976*cdf0e10cSrcweir 				return new OColumnImport<OPasswordImport>(m_rFormImport, m_rEventManager, _nPrefix, _rLocalName, m_xParentContainer, _eType );
1977*cdf0e10cSrcweir 
1978*cdf0e10cSrcweir 			case OControlElement::TEXT:
1979*cdf0e10cSrcweir 			case OControlElement::TEXT_AREA:
1980*cdf0e10cSrcweir 			case OControlElement::FORMATTED_TEXT:
1981*cdf0e10cSrcweir 				return new OColumnImport< OTextLikeImport >( m_rFormImport, m_rEventManager, _nPrefix, _rLocalName, m_xParentContainer, _eType );
1982*cdf0e10cSrcweir 
1983*cdf0e10cSrcweir 			default:
1984*cdf0e10cSrcweir 				return new OColumnImport<OControlImport>(m_rFormImport, m_rEventManager, _nPrefix, _rLocalName, m_xParentContainer, _eType );
1985*cdf0e10cSrcweir 		}
1986*cdf0e10cSrcweir 	}
1987*cdf0e10cSrcweir 
1988*cdf0e10cSrcweir 	//=====================================================================
1989*cdf0e10cSrcweir 	//= OGridImport
1990*cdf0e10cSrcweir 	//=====================================================================
1991*cdf0e10cSrcweir 	//---------------------------------------------------------------------
1992*cdf0e10cSrcweir 	OGridImport::OGridImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
1993*cdf0e10cSrcweir 			const Reference< XNameContainer >& _rxParentContainer,
1994*cdf0e10cSrcweir 			OControlElement::ElementType _eType)
1995*cdf0e10cSrcweir 		:OGridImport_Base(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, "column")
1996*cdf0e10cSrcweir 	{
1997*cdf0e10cSrcweir 		setElementType(_eType);
1998*cdf0e10cSrcweir 	}
1999*cdf0e10cSrcweir 
2000*cdf0e10cSrcweir 	//---------------------------------------------------------------------
2001*cdf0e10cSrcweir 	SvXMLImportContext*	OGridImport::implCreateControlWrapper(sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName)
2002*cdf0e10cSrcweir 	{
2003*cdf0e10cSrcweir 		return new OColumnWrapperImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer);
2004*cdf0e10cSrcweir 	}
2005*cdf0e10cSrcweir 
2006*cdf0e10cSrcweir 	//=====================================================================
2007*cdf0e10cSrcweir 	//= OFormImport
2008*cdf0e10cSrcweir 	//=====================================================================
2009*cdf0e10cSrcweir 	//---------------------------------------------------------------------
2010*cdf0e10cSrcweir 	OFormImport::OFormImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
2011*cdf0e10cSrcweir 			const Reference< XNameContainer >& _rxParentContainer)
2012*cdf0e10cSrcweir 		:OFormImport_Base(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, "control")
2013*cdf0e10cSrcweir 	{
2014*cdf0e10cSrcweir 		enableTrackAttributes();
2015*cdf0e10cSrcweir 	}
2016*cdf0e10cSrcweir 
2017*cdf0e10cSrcweir 	//---------------------------------------------------------------------
2018*cdf0e10cSrcweir 	SvXMLImportContext* OFormImport::CreateChildContext(sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
2019*cdf0e10cSrcweir 		const Reference< sax::XAttributeList >& _rxAttrList)
2020*cdf0e10cSrcweir 	{
2021*cdf0e10cSrcweir 		if( token::IsXMLToken(_rLocalName, token::XML_FORM) )
2022*cdf0e10cSrcweir 			return new OFormImport( m_rFormImport, *this, _nPrefix, _rLocalName,
2023*cdf0e10cSrcweir 									m_xMeAsContainer);
2024*cdf0e10cSrcweir 		else if ( token::IsXMLToken(_rLocalName, token::XML_CONNECTION_RESOURCE) )
2025*cdf0e10cSrcweir 			return new OXMLDataSourceImport(GetImport(), _nPrefix, _rLocalName, _rxAttrList,m_xElement);
2026*cdf0e10cSrcweir 		else if( (token::IsXMLToken(_rLocalName, token::XML_EVENT_LISTENERS) &&
2027*cdf0e10cSrcweir 				 (XML_NAMESPACE_OFFICE == _nPrefix)) ||
2028*cdf0e10cSrcweir 			     token::IsXMLToken( _rLocalName, token::XML_PROPERTIES) )
2029*cdf0e10cSrcweir 			return OElementImport::CreateChildContext( _nPrefix, _rLocalName,
2030*cdf0e10cSrcweir 													   _rxAttrList );
2031*cdf0e10cSrcweir 		else
2032*cdf0e10cSrcweir 			return implCreateChildContext( _nPrefix, _rLocalName,
2033*cdf0e10cSrcweir 						OElementNameMap::getElementType(_rLocalName) );
2034*cdf0e10cSrcweir 	}
2035*cdf0e10cSrcweir 
2036*cdf0e10cSrcweir 	//---------------------------------------------------------------------
2037*cdf0e10cSrcweir 	void OFormImport::StartElement(const Reference< sax::XAttributeList >& _rxAttrList)
2038*cdf0e10cSrcweir 	{
2039*cdf0e10cSrcweir 		m_rFormImport.enterEventContext();
2040*cdf0e10cSrcweir 		OFormImport_Base::StartElement(_rxAttrList);
2041*cdf0e10cSrcweir 
2042*cdf0e10cSrcweir 		// handle the target-frame attribute
2043*cdf0e10cSrcweir 		simulateDefaultedAttribute(OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_FRAME), PROPERTY_TARGETFRAME, "_blank");
2044*cdf0e10cSrcweir 	}
2045*cdf0e10cSrcweir 
2046*cdf0e10cSrcweir 	//---------------------------------------------------------------------
2047*cdf0e10cSrcweir 	void OFormImport::EndElement()
2048*cdf0e10cSrcweir 	{
2049*cdf0e10cSrcweir 		OFormImport_Base::EndElement();
2050*cdf0e10cSrcweir 		m_rFormImport.leaveEventContext();
2051*cdf0e10cSrcweir 	}
2052*cdf0e10cSrcweir 
2053*cdf0e10cSrcweir 	//---------------------------------------------------------------------
2054*cdf0e10cSrcweir 	SvXMLImportContext*	OFormImport::implCreateControlWrapper(sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName)
2055*cdf0e10cSrcweir 	{
2056*cdf0e10cSrcweir 		OSL_ENSURE( !this, "illegal call to OFormImport::implCreateControlWrapper" );
2057*cdf0e10cSrcweir 		return new SvXMLImportContext(GetImport(), _nPrefix, _rLocalName );
2058*cdf0e10cSrcweir 	}
2059*cdf0e10cSrcweir 
2060*cdf0e10cSrcweir 	//---------------------------------------------------------------------
2061*cdf0e10cSrcweir 	bool OFormImport::handleAttribute(sal_uInt16 _nNamespaceKey, const ::rtl::OUString& _rLocalName, const ::rtl::OUString& _rValue)
2062*cdf0e10cSrcweir 	{
2063*cdf0e10cSrcweir 		// handle the master/details field attributes (they're way too special to let the OPropertyImport handle them)
2064*cdf0e10cSrcweir 		static const ::rtl::OUString s_sMasterFieldsAttributeName = ::rtl::OUString::createFromAscii(OAttributeMetaData::getFormAttributeName(faMasterFields));
2065*cdf0e10cSrcweir 		static const ::rtl::OUString s_sDetailFieldsAttributeName = ::rtl::OUString::createFromAscii(OAttributeMetaData::getFormAttributeName(faDetailFiels));
2066*cdf0e10cSrcweir 
2067*cdf0e10cSrcweir 		if ( s_sMasterFieldsAttributeName == _rLocalName )
2068*cdf0e10cSrcweir         {
2069*cdf0e10cSrcweir 			implTranslateStringListProperty(PROPERTY_MASTERFIELDS, _rValue);
2070*cdf0e10cSrcweir             return true;
2071*cdf0e10cSrcweir         }
2072*cdf0e10cSrcweir 
2073*cdf0e10cSrcweir         if ( s_sDetailFieldsAttributeName == _rLocalName )
2074*cdf0e10cSrcweir         {
2075*cdf0e10cSrcweir 			implTranslateStringListProperty(PROPERTY_DETAILFIELDS, _rValue);
2076*cdf0e10cSrcweir             return true;
2077*cdf0e10cSrcweir         }
2078*cdf0e10cSrcweir 
2079*cdf0e10cSrcweir 		return OFormImport_Base::handleAttribute(_nNamespaceKey, _rLocalName, _rValue);
2080*cdf0e10cSrcweir 	}
2081*cdf0e10cSrcweir 
2082*cdf0e10cSrcweir 	//---------------------------------------------------------------------
2083*cdf0e10cSrcweir 	void OFormImport::implTranslateStringListProperty(const ::rtl::OUString& _rPropertyName, const ::rtl::OUString& _rValue)
2084*cdf0e10cSrcweir 	{
2085*cdf0e10cSrcweir 		PropertyValue aProp;
2086*cdf0e10cSrcweir 		aProp.Name = _rPropertyName;
2087*cdf0e10cSrcweir 
2088*cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aList;
2089*cdf0e10cSrcweir 
2090*cdf0e10cSrcweir 		// split up the value string
2091*cdf0e10cSrcweir 		if (_rValue.getLength())
2092*cdf0e10cSrcweir 		{
2093*cdf0e10cSrcweir 			// For the moment, we build a vector instead of a Sequence. It's easier to handle because of it's
2094*cdf0e10cSrcweir 			// push_back method
2095*cdf0e10cSrcweir 			::std::vector< ::rtl::OUString > aElements;
2096*cdf0e10cSrcweir 			// estimate the number of tokens
2097*cdf0e10cSrcweir 			sal_Int32 nEstimate = 0, nLength = _rValue.getLength();
2098*cdf0e10cSrcweir 			const sal_Unicode* pChars = _rValue.getStr();
2099*cdf0e10cSrcweir 			for (sal_Int32 i=0; i<nLength; ++i, ++pChars)
2100*cdf0e10cSrcweir 				if (*pChars == ',')
2101*cdf0e10cSrcweir 					++nEstimate;
2102*cdf0e10cSrcweir 			aElements.reserve(nEstimate + 1);
2103*cdf0e10cSrcweir 				// that's the worst case. If the string contains the separator character _quoted_, we reserved to much ...
2104*cdf0e10cSrcweir 
2105*cdf0e10cSrcweir 
2106*cdf0e10cSrcweir 			sal_Int32 nElementStart = 0;
2107*cdf0e10cSrcweir 			sal_Int32 nNextSep = 0;
2108*cdf0e10cSrcweir 			sal_Int32 nElementLength;
2109*cdf0e10cSrcweir 			::rtl::OUString sElement;
2110*cdf0e10cSrcweir 			do
2111*cdf0e10cSrcweir 			{
2112*cdf0e10cSrcweir 				// extract the current element
2113*cdf0e10cSrcweir 				nNextSep = SvXMLUnitConverter::indexOfComma(
2114*cdf0e10cSrcweir                     _rValue, nElementStart);
2115*cdf0e10cSrcweir 				if (-1 == nNextSep)
2116*cdf0e10cSrcweir 					nNextSep = nLength;
2117*cdf0e10cSrcweir 				sElement = _rValue.copy(nElementStart, nNextSep - nElementStart);
2118*cdf0e10cSrcweir 
2119*cdf0e10cSrcweir 				nElementLength = sElement.getLength();
2120*cdf0e10cSrcweir 				// when writing the sequence, we quoted the single elements with " characters
2121*cdf0e10cSrcweir 				OSL_ENSURE(	(nElementLength >= 2)
2122*cdf0e10cSrcweir 						&&	(sElement.getStr()[0] == '"')
2123*cdf0e10cSrcweir 						&&	(sElement.getStr()[nElementLength - 1] == '"'),
2124*cdf0e10cSrcweir 						"OFormImport::implTranslateStringListProperty: invalid quoted element name.");
2125*cdf0e10cSrcweir 				sElement = sElement.copy(1, nElementLength - 2);
2126*cdf0e10cSrcweir 
2127*cdf0e10cSrcweir 				aElements.push_back(sElement);
2128*cdf0e10cSrcweir 
2129*cdf0e10cSrcweir 				// swith to the next element
2130*cdf0e10cSrcweir 				nElementStart = 1 + nNextSep;
2131*cdf0e10cSrcweir 			}
2132*cdf0e10cSrcweir 			while (nElementStart < nLength);
2133*cdf0e10cSrcweir 
2134*cdf0e10cSrcweir 			::rtl::OUString *pElements = aElements.empty() ? 0 : &aElements[0];
2135*cdf0e10cSrcweir 			aList = Sequence< ::rtl::OUString >(pElements, aElements.size());
2136*cdf0e10cSrcweir 		}
2137*cdf0e10cSrcweir 		else
2138*cdf0e10cSrcweir 		{
2139*cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "OFormImport::implTranslateStringListProperty: invalid value (empty)!");
2140*cdf0e10cSrcweir 		}
2141*cdf0e10cSrcweir 
2142*cdf0e10cSrcweir 		aProp.Value <<= aList;
2143*cdf0e10cSrcweir 
2144*cdf0e10cSrcweir 		// add the property to the base class' array
2145*cdf0e10cSrcweir 		implPushBackPropertyValue(aProp);
2146*cdf0e10cSrcweir 	}
2147*cdf0e10cSrcweir 	//=====================================================================
2148*cdf0e10cSrcweir 	//= OXMLDataSourceImport
2149*cdf0e10cSrcweir 	//=====================================================================
2150*cdf0e10cSrcweir 	OXMLDataSourceImport::OXMLDataSourceImport(
2151*cdf0e10cSrcweir 					SvXMLImport& _rImport
2152*cdf0e10cSrcweir 					,sal_uInt16 nPrfx
2153*cdf0e10cSrcweir 					, const ::rtl::OUString& _sLocalName
2154*cdf0e10cSrcweir 					,const Reference< ::com::sun::star::xml::sax::XAttributeList > & _xAttrList
2155*cdf0e10cSrcweir 					,const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xElement) :
2156*cdf0e10cSrcweir 		SvXMLImportContext( _rImport, nPrfx, _sLocalName )
2157*cdf0e10cSrcweir 	{
2158*cdf0e10cSrcweir 		OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
2159*cdf0e10cSrcweir         const SvXMLNamespaceMap& rMap = _rImport.GetNamespaceMap();
2160*cdf0e10cSrcweir 
2161*cdf0e10cSrcweir 		sal_Int16 nLength = (_xElement.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
2162*cdf0e10cSrcweir 		for(sal_Int16 i = 0; i < nLength; ++i)
2163*cdf0e10cSrcweir 		{
2164*cdf0e10cSrcweir 			::rtl::OUString sLocalName;
2165*cdf0e10cSrcweir 			::rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
2166*cdf0e10cSrcweir             sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName, &sLocalName );
2167*cdf0e10cSrcweir 
2168*cdf0e10cSrcweir 			if  (   ( nPrefix == OAttributeMetaData::getCommonControlAttributeNamespace( CCA_TARGET_LOCATION ) )
2169*cdf0e10cSrcweir                 &&  ( sLocalName.equalsAscii( OAttributeMetaData::getCommonControlAttributeName( CCA_TARGET_LOCATION ) ) )
2170*cdf0e10cSrcweir                 )
2171*cdf0e10cSrcweir 			{
2172*cdf0e10cSrcweir                 ::rtl::OUString sValue = _xAttrList->getValueByIndex( i );
2173*cdf0e10cSrcweir 
2174*cdf0e10cSrcweir 				INetURLObject aURL(sValue);
2175*cdf0e10cSrcweir 				if ( aURL.GetProtocol() == INET_PROT_FILE )
2176*cdf0e10cSrcweir 					_xElement->setPropertyValue(PROPERTY_DATASOURCENAME,makeAny(sValue));
2177*cdf0e10cSrcweir 				else
2178*cdf0e10cSrcweir 					_xElement->setPropertyValue(PROPERTY_URL,makeAny(sValue)); // the url is the "sdbc:" string
2179*cdf0e10cSrcweir 				break;
2180*cdf0e10cSrcweir 			}
2181*cdf0e10cSrcweir 		}
2182*cdf0e10cSrcweir 	}
2183*cdf0e10cSrcweir 	//---------------------------------------------------------------------
2184*cdf0e10cSrcweir 	OControlImport* OFormImport::implCreateChildContext(
2185*cdf0e10cSrcweir 			sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
2186*cdf0e10cSrcweir 			OControlElement::ElementType _eType )
2187*cdf0e10cSrcweir 	{
2188*cdf0e10cSrcweir 		switch (_eType)
2189*cdf0e10cSrcweir 		{
2190*cdf0e10cSrcweir 			case OControlElement::TEXT:
2191*cdf0e10cSrcweir 			case OControlElement::TEXT_AREA:
2192*cdf0e10cSrcweir 			case OControlElement::FORMATTED_TEXT:
2193*cdf0e10cSrcweir 				return new OTextLikeImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType);
2194*cdf0e10cSrcweir 
2195*cdf0e10cSrcweir 			case OControlElement::BUTTON:
2196*cdf0e10cSrcweir 			case OControlElement::IMAGE:
2197*cdf0e10cSrcweir 			case OControlElement::IMAGE_FRAME:
2198*cdf0e10cSrcweir 				return new OButtonImport( m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType );
2199*cdf0e10cSrcweir 
2200*cdf0e10cSrcweir 			case OControlElement::COMBOBOX:
2201*cdf0e10cSrcweir 			case OControlElement::LISTBOX:
2202*cdf0e10cSrcweir 				return new OListAndComboImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType);
2203*cdf0e10cSrcweir 
2204*cdf0e10cSrcweir 			case OControlElement::RADIO:
2205*cdf0e10cSrcweir 				return new ORadioImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType);
2206*cdf0e10cSrcweir 
2207*cdf0e10cSrcweir             case OControlElement::CHECKBOX:
2208*cdf0e10cSrcweir 				return new OImagePositionImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType);
2209*cdf0e10cSrcweir 
2210*cdf0e10cSrcweir 			case OControlElement::PASSWORD:
2211*cdf0e10cSrcweir 				return new OPasswordImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType);
2212*cdf0e10cSrcweir 
2213*cdf0e10cSrcweir 			case OControlElement::FRAME:
2214*cdf0e10cSrcweir 			case OControlElement::FIXED_TEXT:
2215*cdf0e10cSrcweir 				return new OReferredControlImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType);
2216*cdf0e10cSrcweir 
2217*cdf0e10cSrcweir 			case OControlElement::GRID:
2218*cdf0e10cSrcweir 				return new OGridImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType);
2219*cdf0e10cSrcweir 
2220*cdf0e10cSrcweir             case OControlElement::VALUERANGE:
2221*cdf0e10cSrcweir                 return new OValueRangeImport( m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType );
2222*cdf0e10cSrcweir 
2223*cdf0e10cSrcweir 			default:
2224*cdf0e10cSrcweir 				return new OControlImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType);
2225*cdf0e10cSrcweir 		}
2226*cdf0e10cSrcweir 	}
2227*cdf0e10cSrcweir 
2228*cdf0e10cSrcweir //.........................................................................
2229*cdf0e10cSrcweir }	// namespace xmloff
2230*cdf0e10cSrcweir //.........................................................................
2231*cdf0e10cSrcweir 
2232