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