LCOV - code coverage report
Current view: top level - xmloff/source/forms - elementimport.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 383 886 43.2 %
Date: 2014-11-03 Functions: 49 96 51.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10