1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "elementimport.hxx"
22 #include <xmloff/xmlimp.hxx>
23 #include <xmloff/namespacemap.hxx>
24 #include "strings.hxx"
25 #include "callbacks.hxx"
26 #include <xmloff/xmlnamespace.hxx>
27 #include "eventimport.hxx"
28 #include <xmloff/txtstyli.hxx>
29 #include "formenums.hxx"
30 #include <xmloff/xmltoken.hxx>
31 #include "gridcolumnproptranslator.hxx"
32 #include "property_description.hxx"
33 #include "property_meta_data.hxx"
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>
45 #include <sax/tools/converter.hxx>
46 #include <tools/urlobj.hxx>
47 #include <comphelper/diagnose_ex.hxx>
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 #include <o3tl/string_view.hxx>
60 using namespace ::xmloff::token
;
61 using namespace ::com::sun::star
;
62 using namespace ::com::sun::star::uno
;
63 using namespace ::com::sun::star::awt
;
64 using namespace ::com::sun::star::container
;
65 using namespace ::com::sun::star::beans
;
66 using namespace ::com::sun::star::script
;
67 using namespace ::com::sun::star::lang
;
68 using namespace ::com::sun::star::form
;
69 using namespace ::com::sun::star::xml
;
70 using namespace ::com::sun::star::xml::sax
;
71 using namespace ::com::sun::star::util
;
72 using namespace ::com::sun::star::text
;
73 using namespace ::comphelper
;
75 #define PROPID_VALUE 1
76 #define PROPID_CURRENT_VALUE 2
77 #define PROPID_MIN_VALUE 3
78 #define PROPID_MAX_VALUE 4
82 struct PropertyValueLess
84 bool operator()(const PropertyValue
& _rLeft
, const PropertyValue
& _rRight
)
86 return _rLeft
.Name
< _rRight
.Name
;
93 std::map
<sal_Int32
, OControlElement::ElementType
> OElementNameMap::s_sElementTranslations2
;
95 const OControlElement::ElementType
& operator ++(OControlElement::ElementType
& _e
)
97 OControlElement::ElementType e
= _e
;
98 sal_Int32 nAsInt
= static_cast<sal_Int32
>(e
);
99 _e
= static_cast<OControlElement::ElementType
>( ++nAsInt
);
103 OControlElement::ElementType
OElementNameMap::getElementType(sal_Int32 nElement
)
105 if ( s_sElementTranslations2
.empty() )
107 for (ElementType eType
=ElementType(0); eType
<UNKNOWN
; ++eType
)
108 s_sElementTranslations2
[getElementToken(eType
)] = eType
;
110 auto aPos
= s_sElementTranslations2
.find(nElement
& TOKEN_MASK
);
111 if (s_sElementTranslations2
.end() != aPos
)
118 OElementImport::OElementImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
,
119 const Reference
< XNameContainer
>& _rxParentContainer
)
120 :OPropertyImport(_rImport
)
121 ,m_rFormImport(_rImport
)
122 ,m_rEventManager(_rEventManager
)
123 ,m_pStyleElement( nullptr )
124 ,m_xParentContainer(_rxParentContainer
)
125 ,m_bImplicitGenericAttributeHandling( true )
127 OSL_ENSURE(m_xParentContainer
.is(), "OElementImport::OElementImport: invalid parent container!");
130 OElementImport::~OElementImport()
134 OUString
OElementImport::determineDefaultServiceName() const
139 void OElementImport::startFastElement(sal_Int32 nElement
, const Reference
< css::xml::sax::XFastAttributeList
>& _rxAttrList
)
141 ENTER_LOG_CONTEXT( "xmloff::OElementImport - importing one element" );
143 const OUString sControlImplementation
= _rxAttrList
->getOptionalValue( XML_ELEMENT(FORM
, XML_CONTROL_IMPLEMENTATION
) );
145 // retrieve the service name
146 if ( !sControlImplementation
.isEmpty() )
148 OUString sOOoImplementationName
;
149 const sal_uInt16 nImplPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrValueQName( sControlImplementation
, &sOOoImplementationName
);
150 m_sServiceName
= ( nImplPrefix
== XML_NAMESPACE_OOO
) ? sOOoImplementationName
: sControlImplementation
;
153 if ( m_sServiceName
.isEmpty() )
154 m_sServiceName
= determineDefaultServiceName();
156 // create the object *now*. This allows setting properties in the various handleAttribute methods.
157 // (Though currently not all code is migrated to this pattern, most attributes are still handled
158 // by remembering the value (via implPushBackPropertyValue), and setting the correct property value
159 // later (in OControlImport::StartElement).)
160 m_xElement
= createElement();
161 if ( m_xElement
.is() )
162 m_xInfo
= m_xElement
->getPropertySetInfo();
164 // call the base class
165 OPropertyImport::startFastElement( nElement
, _rxAttrList
);
168 css::uno::Reference
< css::xml::sax::XFastContextHandler
> OElementImport::createFastChildContext(
170 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& _rxAttrList
)
172 if( nElement
== XML_ELEMENT(OFFICE
, XML_EVENT_LISTENERS
) )
173 return new OFormEventsImportContext(m_rFormImport
.getGlobalContext(), *this);
175 return OPropertyImport::createFastChildContext(nElement
, _rxAttrList
);
178 void OElementImport::endFastElement(sal_Int32
)
180 OSL_ENSURE(m_xElement
.is(), "OElementImport::EndElement: invalid element created!");
181 if (!m_xElement
.is())
184 // apply the non-generic properties
185 implApplySpecificProperties();
187 // set the generic properties
188 implApplyGenericProperties();
190 // set the style properties
191 if ( m_pStyleElement
&& m_xElement
.is() )
193 Reference
< XPropertySet
> xPropTranslation
=
194 new OGridColumnPropertyTranslator( Reference
< XMultiPropertySet
>( m_xElement
, UNO_QUERY
) );
195 const_cast< XMLTextStyleContext
* >( m_pStyleElement
)->FillPropertySet( xPropTranslation
);
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
);
203 // insert the element into the parent container
204 if (m_sName
.isEmpty())
206 OSL_FAIL("OElementImport::EndElement: did not find a name attribute!");
207 m_sName
= implGetDefaultName();
210 if (m_xParentContainer
.is())
211 m_xParentContainer
->insertByName(m_sName
, Any(m_xElement
));
213 LEAVE_LOG_CONTEXT( );
216 void OElementImport::implApplySpecificProperties()
218 if ( m_aValues
.empty() )
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)
227 for ( const auto& rCheck
: m_aValues
)
229 OSL_ENSURE(m_xInfo
->hasPropertyByName(rCheck
.Name
),
230 OStringBuffer("OElementImport::implApplySpecificProperties: read a property (" +
231 OUStringToOString(rCheck
.Name
, RTL_TEXTENCODING_ASCII_US
) +
232 ") which does not exist on the element!").getStr());
237 // set the properties
238 const Reference
< XMultiPropertySet
> xMultiProps(m_xElement
, UNO_QUERY
);
239 bool bSuccess
= false;
240 if (xMultiProps
.is())
242 // translate our properties so that the XMultiPropertySet can handle them
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());
248 Sequence
< OUString
> aNames(m_aValues
.size());
249 OUString
* pNames
= aNames
.getArray();
251 Sequence
< Any
> aValues(m_aValues
.size());
252 Any
* pValues
= aValues
.getArray();
255 for ( const auto& rPropValues
: m_aValues
)
257 *pNames
= rPropValues
.Name
;
258 *pValues
= rPropValues
.Value
;
265 xMultiProps
->setPropertyValues(aNames
, aValues
);
268 catch(const Exception
&)
270 DBG_UNHANDLED_EXCEPTION("xmloff.forms");
271 OSL_FAIL("OElementImport::implApplySpecificProperties: could not set the properties (using the XMultiPropertySet)!");
278 // no XMultiPropertySet or setting all properties at once failed
279 for ( const auto& rPropValues
: m_aValues
)
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 ...
285 m_xElement
->setPropertyValue(rPropValues
.Name
, rPropValues
.Value
);
287 catch(const Exception
&)
289 DBG_UNHANDLED_EXCEPTION("xmloff.forms");
290 OSL_FAIL(OStringBuffer("OElementImport::implApplySpecificProperties: could not set the property \"" +
291 OUStringToOString(rPropValues
.Name
, RTL_TEXTENCODING_ASCII_US
) +
297 void OElementImport::implApplyGenericProperties()
299 if ( m_aGenericValues
.empty() )
302 Reference
< XPropertyContainer
> xDynamicProperties( m_xElement
, UNO_QUERY
);
304 // PropertyValueArray::iterator aEnd = m_aGenericValues.end();
305 for ( auto& rPropValues
: m_aGenericValues
)
307 // check property type for numeric types before setting
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
)
315 if ( !xDynamicProperties
.is() )
317 SAL_WARN( "xmloff", "OElementImport::implApplyGenericProperties: encountered an unknown property ("
318 << rPropValues
.Name
<< "), but component is no PropertyBag!");
322 xDynamicProperties
->addProperty(
324 PropertyAttribute::BOUND
| PropertyAttribute::REMOVABLE
,
328 // re-fetch the PropertySetInfo
329 m_xInfo
= m_xElement
->getPropertySetInfo();
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
)
337 uno::Type
aSimpleType( getSequenceElementType( rPropValues
.Value
.getValueType() ) );
338 eValueTypeClass
= aSimpleType
.getTypeClass();
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
)
347 uno::Type
aSimpleType( ::comphelper::getSequenceElementType( aProperty
.Type
) );
348 ePropTypeClass
= aSimpleType
.getTypeClass();
351 if ( bPropIsSequence
!= bValueIsSequence
)
353 OSL_FAIL( "OElementImport::implImportGenericProperties: either both value and property should be a sequence, or none of them!" );
357 if ( bValueIsSequence
)
359 Sequence
< Any
> aXMLValueList
;
360 rPropValues
.Value
>>= aXMLValueList
;
361 // just skip this part if empty sequence
362 if (!aXMLValueList
.getLength())
365 Sequence
< sal_Int16
> aPropertyValueList( aXMLValueList
.getLength() );
367 SAL_WARN_IF( eValueTypeClass
!= TypeClass_ANY
, "xmloff",
368 "OElementImport::implApplyGenericProperties: only ANYs should have been imported as generic list property!" );
369 // (OPropertyImport should produce only Sequencer< Any >, since it cannot know the real type
371 SAL_WARN_IF( ePropTypeClass
!= TypeClass_SHORT
, "xmloff",
372 "OElementImport::implApplyGenericProperties: conversion to sequences other than 'sequence< short >' not implemented, yet!" );
375 std::transform(std::cbegin(aXMLValueList
), std::cend(aXMLValueList
), aPropertyValueList
.getArray(),
376 [](const Any
& rXMLValue
) -> sal_Int16
{
377 // only value sequences of numeric types implemented so far.
379 OSL_VERIFY( rXMLValue
>>= nVal
);
380 return static_cast< sal_Int16
>( nVal
);
383 rPropValues
.Value
<<= aPropertyValueList
;
385 else if ( ePropTypeClass
!= eValueTypeClass
)
387 switch ( eValueTypeClass
)
389 case TypeClass_DOUBLE
:
392 rPropValues
.Value
>>= nVal
;
393 switch( ePropTypeClass
)
396 rPropValues
.Value
<<= static_cast< sal_Int8
>( nVal
);
398 case TypeClass_SHORT
:
399 rPropValues
.Value
<<= static_cast< sal_Int16
>( nVal
);
401 case TypeClass_UNSIGNED_SHORT
:
402 rPropValues
.Value
<<= static_cast< sal_uInt16
>( nVal
);
406 rPropValues
.Value
<<= static_cast< sal_Int32
>( nVal
);
408 case TypeClass_UNSIGNED_LONG
:
409 rPropValues
.Value
<<= static_cast< sal_uInt32
>( nVal
);
411 case TypeClass_UNSIGNED_HYPER
:
412 rPropValues
.Value
<<= static_cast< sal_uInt64
>( nVal
);
414 case TypeClass_HYPER
:
415 rPropValues
.Value
<<= static_cast< sal_Int64
>( nVal
);
418 OSL_FAIL( "OElementImport::implImportGenericProperties: unsupported value type!" );
424 OSL_FAIL( "OElementImport::implImportGenericProperties: non-double values not supported!" );
429 m_xElement
->setPropertyValue( rPropValues
.Name
, rPropValues
.Value
);
431 catch(const Exception
&)
433 DBG_UNHANDLED_EXCEPTION("xmloff.forms");
434 OSL_FAIL(OStringBuffer("OElementImport::EndElement: could not set the property \"" +
435 OUStringToOString(rPropValues
.Name
, RTL_TEXTENCODING_ASCII_US
) +
441 OUString
OElementImport::implGetDefaultName() const
443 // no optimization here. If this method gets called, the XML stream did not contain a name for the
444 // element, which is a heavy error. So in this case we don't care for performance
445 static constexpr OUString sUnnamedName
= u
"unnamed"_ustr
;
446 OSL_ENSURE(m_xParentContainer
.is(), "OElementImport::implGetDefaultName: no parent container!");
447 if (!m_xParentContainer
.is())
449 Sequence
< OUString
> aNames
= m_xParentContainer
->getElementNames();
451 for (sal_Int32 i
=0; i
<32768; ++i
) // the limit is nearly arbitrary...
453 // assemble the new name (suggestion)
454 OUString sReturn
= sUnnamedName
+ OUString::number(i
);
455 // check the existence (this is the bad performance part...)
456 if (comphelper::findValue(aNames
, sReturn
) == -1)
457 // not found the name
460 OSL_FAIL("OElementImport::implGetDefaultName: did not find a free name!");
464 PropertyGroups::const_iterator
OElementImport::impl_matchPropertyGroup( const PropertyGroups
& i_propertyGroups
) const
466 ENSURE_OR_RETURN( m_xInfo
.is(), "OElementImport::impl_matchPropertyGroup: no property set info!", i_propertyGroups
.end() );
468 return std::find_if(i_propertyGroups
.cbegin(), i_propertyGroups
.cend(), [&](const PropertyDescriptionList
& rGroup
) {
469 return std::all_of(rGroup
.cbegin(), rGroup
.cend(), [&](const PropertyDescription
* prop
) {
470 return m_xInfo
->hasPropertyByName( prop
->propertyName
);
475 bool OElementImport::tryGenericAttribute( sal_Int32 nElement
, const OUString
& _rValue
)
477 // the generic approach (which I hope all props will be migrated to, on the medium term): property handlers
478 const AttributeDescription
attribute( metadata::getAttributeDescription( nElement
) );
479 if ( attribute
.attributeToken
!= XML_TOKEN_INVALID
)
481 PropertyGroups propertyGroups
;
482 metadata::getPropertyGroupList( attribute
, propertyGroups
);
483 const PropertyGroups::const_iterator pos
= impl_matchPropertyGroup( propertyGroups
);
484 if ( pos
== propertyGroups
.end() )
489 const PropertyDescriptionList
& rProperties( *pos
);
490 const PropertyDescription
* first
= *rProperties
.begin();
493 SAL_WARN( "xmloff.forms", "OElementImport::handleAttribute: invalid property description!" );
497 const PPropertyHandler handler
= (*first
->factory
)( first
->propertyId
);
500 SAL_WARN( "xmloff.forms", "OElementImport::handleAttribute: invalid property handler!" );
504 PropertyValues aValues
;
505 for ( const auto& propDesc
: rProperties
)
507 aValues
[ propDesc
->propertyId
] = Any();
509 if ( handler
->getPropertyValues( _rValue
, aValues
) )
511 for ( const auto& propDesc
: rProperties
)
513 implPushBackPropertyValue( propDesc
->propertyName
, aValues
[ propDesc
->propertyId
] );
525 bool OElementImport::handleAttribute(sal_Int32 nElement
, const OUString
& _rValue
)
527 auto nLocal
= nElement
& TOKEN_MASK
;
528 if ( nLocal
== XML_CONTROL_IMPLEMENTATION
)
529 // ignore this, it has already been handled in OElementImport::StartElement
532 if ( nLocal
== XML_NAME
)
534 if ( m_sName
.isEmpty() )
535 // remember the name for later use in EndElement
540 // maybe it's the style attribute?
541 if ( nLocal
== XML_TEXT_STYLE_NAME
)
543 const SvXMLStyleContext
* pStyleContext
= m_rContext
.getStyleElement( _rValue
);
544 OSL_ENSURE( pStyleContext
, "OElementImport::handleAttribute: do not know the style!" );
545 // remember the element for later usage.
546 m_pStyleElement
= dynamic_cast<const XMLTextStyleContext
*>( pStyleContext
);
550 if ( m_bImplicitGenericAttributeHandling
)
551 if ( tryGenericAttribute( nElement
, _rValue
) )
554 // let the base class handle it
555 return OPropertyImport::handleAttribute( nElement
, _rValue
);
558 Reference
< XPropertySet
> OElementImport::createElement()
560 Reference
< XPropertySet
> xReturn
;
561 if (!m_sServiceName
.isEmpty())
563 Reference
< XComponentContext
> xContext
= m_rFormImport
.getGlobalContext().GetComponentContext();
564 Reference
< XInterface
> xPure
= xContext
->getServiceManager()->createInstanceWithContext(m_sServiceName
, xContext
);
565 OSL_ENSURE(xPure
.is(),
566 OStringBuffer("OElementImport::createElement: service factory gave me no object (service name: " +
567 OUStringToOString(m_sServiceName
, RTL_TEXTENCODING_ASCII_US
) +
569 xReturn
.set(xPure
, UNO_QUERY
);
570 if (auto const props
= Reference
<css::beans::XPropertySet
>(xPure
, css::uno::UNO_QUERY
))
573 props
->setPropertyValue(
574 u
"Referer"_ustr
, css::uno::Any(m_rFormImport
.getGlobalContext().GetBaseURL()));
575 } catch (css::uno::Exception
&) {
576 TOOLS_INFO_EXCEPTION("xmloff.forms", "setPropertyValue Referer failed");
581 OSL_FAIL("OElementImport::createElement: no service name to create an element!");
586 void OElementImport::registerEvents(const Sequence
< ScriptEventDescriptor
>& _rEvents
)
588 OSL_ENSURE(m_xElement
.is(), "OElementImport::registerEvents: no element to register events for!");
589 m_rEventManager
.registerEvents(m_xElement
, _rEvents
);
592 void OElementImport::simulateDefaultedAttribute(sal_Int32 nElement
, const OUString
& _rPropertyName
, const OUString
& _pAttributeDefault
)
594 OSL_ENSURE( m_xInfo
.is(), "OPropertyImport::simulateDefaultedAttribute: the component should be more gossipy about it's properties!" );
596 if ( !m_xInfo
.is() || m_xInfo
->hasPropertyByName( _rPropertyName
) )
598 if ( !encounteredAttribute( nElement
) )
599 OSL_VERIFY( handleAttribute( XML_ELEMENT(FORM
, (nElement
& TOKEN_MASK
)), _pAttributeDefault
) );
604 OControlImport::OControlImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
,
605 const Reference
< XNameContainer
>& _rxParentContainer
)
606 :OElementImport(_rImport
, _rEventManager
, _rxParentContainer
)
607 ,m_eElementType(OControlElement::UNKNOWN
)
609 disableImplicitGenericAttributeHandling();
612 OControlImport::OControlImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
,
613 const Reference
< XNameContainer
>& _rxParentContainer
, OControlElement::ElementType _eType
)
614 :OElementImport(_rImport
, _rEventManager
, _rxParentContainer
)
615 ,m_eElementType(_eType
)
617 disableImplicitGenericAttributeHandling();
620 OUString
OControlImport::determineDefaultServiceName() const
622 const char* pServiceName
= nullptr;
623 switch ( m_eElementType
)
625 case OControlElement::TEXT
:
626 case OControlElement::TEXT_AREA
:
627 case OControlElement::PASSWORD
: pServiceName
= "com.sun.star.form.component.TextField"; break;
628 case OControlElement::FILE: pServiceName
= "com.sun.star.form.component.FileControl"; break;
629 case OControlElement::FORMATTED_TEXT
: pServiceName
= "com.sun.star.form.component.FormattedField"; break;
630 case OControlElement::FIXED_TEXT
: pServiceName
= "com.sun.star.form.component.FixedText"; break;
631 case OControlElement::COMBOBOX
: pServiceName
= "com.sun.star.form.component.ComboBox"; break;
632 case OControlElement::LISTBOX
: pServiceName
= "com.sun.star.form.component.ListBox"; break;
633 case OControlElement::BUTTON
: pServiceName
= "com.sun.star.form.component.CommandButton"; break;
634 case OControlElement::IMAGE
: pServiceName
= "com.sun.star.form.component.ImageButton"; break;
635 case OControlElement::CHECKBOX
: pServiceName
= "com.sun.star.form.component.CheckBox"; break;
636 case OControlElement::RADIO
: pServiceName
= "com.sun.star.form.component.RadioButton"; break;
637 case OControlElement::FRAME
: pServiceName
= "com.sun.star.form.component.GroupBox"; break;
638 case OControlElement::IMAGE_FRAME
: pServiceName
= "com.sun.star.form.component.DatabaseImageControl"; break;
639 case OControlElement::HIDDEN
: pServiceName
= "com.sun.star.form.component.HiddenControl"; break;
640 case OControlElement::GRID
: pServiceName
= "com.sun.star.form.component.GridControl"; break;
641 case OControlElement::VALUERANGE
: pServiceName
= "com.sun.star.form.component.ScrollBar"; break;
642 case OControlElement::TIME
: pServiceName
= "com.sun.star.form.component.TimeField"; break;
643 case OControlElement::DATE
: pServiceName
= "com.sun.star.form.component.DateField"; break;
646 if ( pServiceName
!= nullptr )
647 return OUString::createFromAscii( pServiceName
);
651 void OControlImport::addOuterAttributes(const Reference
< XFastAttributeList
>& _rxOuterAttribs
)
653 OSL_ENSURE(!m_xOuterAttributes
.is(), "OControlImport::addOuterAttributes: already have these attributes!");
654 m_xOuterAttributes
= _rxOuterAttribs
;
657 bool OControlImport::handleAttribute(sal_Int32 nElement
, const OUString
& _rValue
)
659 static sal_Int32 nLinkedCellAttributeName
= OAttributeMetaData::getBindingAttributeToken(BAFlags::LinkedCell
);
661 if ((nElement
& TOKEN_MASK
) == XML_ID
)
662 { // it's the control id
663 if (IsTokenInNamespace(nElement
, XML_NAMESPACE_XML
))
665 m_sControlId
= _rValue
;
667 else if (IsTokenInNamespace(nElement
, XML_NAMESPACE_FORM
))
669 if (m_sControlId
.isEmpty())
671 m_sControlId
= _rValue
;
677 if ( (nElement
& TOKEN_MASK
) == nLinkedCellAttributeName
)
678 { // it's the address of a spreadsheet cell
679 m_sBoundCellAddress
= _rValue
;
683 if ( nElement
== XML_ELEMENT(XFORMS
, XML_BIND
) )
685 m_sBindingID
= _rValue
;
689 if ( nElement
== XML_ELEMENT(FORM
, XML_XFORMS_LIST_SOURCE
) )
691 m_sListBindingID
= _rValue
;
695 if ( nElement
== XML_ELEMENT(FORM
, XML_XFORMS_SUBMISSION
)
696 || nElement
== XML_ELEMENT(XFORMS
, XML_SUBMISSION
) )
698 m_sSubmissionID
= _rValue
;
702 if ( OElementImport::tryGenericAttribute( nElement
, _rValue
) )
705 static const sal_Int32 nValueAttributeName
= OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Value
);
706 static const sal_Int32 nCurrentValueAttributeName
= OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::CurrentValue
);
707 static const sal_Int32 nMinValueAttributeName
= OAttributeMetaData::getSpecialAttributeToken(SCAFlags::MinValue
);
708 static const sal_Int32 nMaxValueAttributeName
= OAttributeMetaData::getSpecialAttributeToken(SCAFlags::MaxValue
);
709 static const sal_Int32 nRepeatDelayAttributeName
= OAttributeMetaData::getSpecialAttributeToken( SCAFlags::RepeatDelay
);
711 sal_Int32 nHandle
= -1;
712 if ( (nElement
& TOKEN_MASK
) == nValueAttributeName
)
713 nHandle
= PROPID_VALUE
;
714 else if ( (nElement
& TOKEN_MASK
) == nCurrentValueAttributeName
)
715 nHandle
= PROPID_CURRENT_VALUE
;
716 else if ( (nElement
& TOKEN_MASK
) == nMinValueAttributeName
)
717 nHandle
= PROPID_MIN_VALUE
;
718 else if ( (nElement
& TOKEN_MASK
) == nMaxValueAttributeName
)
719 nHandle
= PROPID_MAX_VALUE
;
722 // for the moment, simply remember the name and the value
724 aProp
.Name
= SvXMLImport::getNameFromToken(nElement
);
725 aProp
.Handle
= nHandle
;
726 aProp
.Value
<<= _rValue
;
727 m_aValueProperties
.push_back(aProp
);
731 if ( (nElement
& TOKEN_MASK
) == nRepeatDelayAttributeName
)
733 util::Duration aDuration
;
734 if (::sax::Converter::convertDuration(aDuration
, _rValue
))
737 aProp
.Name
= PROPERTY_REPEAT_DELAY
;
738 sal_Int32
const nMS
=
739 ((aDuration
.Hours
* 60 + aDuration
.Minutes
) * 60
740 + aDuration
.Seconds
) * 1000 + aDuration
.NanoSeconds
/1000000;
743 implPushBackPropertyValue(aProp
);
748 return OElementImport::handleAttribute( nElement
, _rValue
);
751 void OControlImport::startFastElement(sal_Int32 nElement
, const Reference
< css::xml::sax::XFastAttributeList
>& _rxAttrList
)
753 css::uno::Reference
< css::xml::sax::XFastAttributeList
> xMergedAttributes
;
754 if( m_xOuterAttributes
.is() )
756 // merge the attribute lists, our own one
757 rtl::Reference
<sax_fastparser::FastAttributeList
> xMerger(new sax_fastparser::FastAttributeList(_rxAttrList
));
758 // and the ones of our enclosing element
759 xMerger
->add(m_xOuterAttributes
);
760 xMergedAttributes
= xMerger
.get();
764 xMergedAttributes
= _rxAttrList
;
767 // let the base class handle all the attributes
768 OElementImport::startFastElement(nElement
, xMergedAttributes
);
770 if ( m_aValueProperties
.empty() || !m_xElement
.is())
773 // get the property set info
776 OSL_FAIL("OControlImport::StartElement: no PropertySetInfo!");
780 OUString pValueProperty
;
781 OUString pCurrentValueProperty
;
782 OUString pMinValueProperty
;
783 OUString pMaxValueProperty
;
785 bool bRetrievedValues
= false;
786 bool bRetrievedValueLimits
= false;
788 // get the class id of our element
789 sal_Int16 nClassId
= FormComponentType::CONTROL
;
790 m_xElement
->getPropertyValue(PROPERTY_CLASSID
) >>= nClassId
;
792 // translate the value properties we collected in handleAttributes
793 for ( auto& rValueProps
: m_aValueProperties
)
795 bool bSuccess
= false;
796 switch (rValueProps
.Handle
)
799 case PROPID_CURRENT_VALUE
:
801 // get the property names
802 if (!bRetrievedValues
)
804 getValuePropertyNames(m_eElementType
, nClassId
, pCurrentValueProperty
, pValueProperty
);
805 if ( pCurrentValueProperty
.isEmpty() && pValueProperty
.isEmpty() )
807 SAL_WARN( "xmloff.forms", "OControlImport::StartElement: illegal value property names!" );
811 bRetrievedValues
= true;
813 if ( PROPID_VALUE
== rValueProps
.Handle
&& pValueProperty
.isEmpty() )
815 SAL_WARN( "xmloff.forms", "OControlImport::StartElement: the control does not have a value property!");
819 if ( PROPID_CURRENT_VALUE
== rValueProps
.Handle
&& pCurrentValueProperty
.isEmpty() )
821 SAL_WARN( "xmloff.forms", "OControlImport::StartElement: the control does not have a current-value property!");
826 if (PROPID_VALUE
== rValueProps
.Handle
)
827 rValueProps
.Name
= pValueProperty
;
829 rValueProps
.Name
= pCurrentValueProperty
;
833 case PROPID_MIN_VALUE
:
834 case PROPID_MAX_VALUE
:
836 // get the property names
837 if (!bRetrievedValueLimits
)
839 getValueLimitPropertyNames(nClassId
, pMinValueProperty
, pMaxValueProperty
);
840 if ( pMinValueProperty
.isEmpty() || pMaxValueProperty
.isEmpty() )
842 SAL_WARN( "xmloff.forms", "OControlImport::StartElement: illegal value limit property names!" );
846 bRetrievedValueLimits
= true;
848 OSL_ENSURE((PROPID_MIN_VALUE
!= rValueProps
.Handle
) || !pMinValueProperty
.isEmpty(),
849 "OControlImport::StartElement: the control does not have a value property!");
850 OSL_ENSURE((PROPID_MAX_VALUE
!= rValueProps
.Handle
) || !pMaxValueProperty
.isEmpty(),
851 "OControlImport::StartElement: the control does not have a current-value property!");
854 if (PROPID_MIN_VALUE
== rValueProps
.Handle
)
855 rValueProps
.Name
= pMinValueProperty
;
857 rValueProps
.Name
= pMaxValueProperty
;
866 // translate the value
867 implTranslateValueProperty(m_xInfo
, rValueProps
);
868 // add the property to the base class' array
869 implPushBackPropertyValue(rValueProps
);
874 void OControlImport::implTranslateValueProperty(const Reference
< XPropertySetInfo
>& _rxPropInfo
,
875 PropertyValue
& _rPropValue
)
877 OSL_ENSURE(_rxPropInfo
->hasPropertyByName(_rPropValue
.Name
),
878 "OControlImport::implTranslateValueProperty: invalid property name!");
880 // retrieve the type of the property
881 Property aProp
= _rxPropInfo
->getPropertyByName(_rPropValue
.Name
);
882 // the untranslated string value as read in handleAttribute
884 bool bSuccess
= _rPropValue
.Value
>>= sValue
;
885 OSL_ENSURE(bSuccess
, "OControlImport::implTranslateValueProperty: supposed to be called with non-translated string values!");
887 if (TypeClass_ANY
== aProp
.Type
.getTypeClass())
889 // we have exactly 2 properties where this type class is allowed:
891 _rPropValue
.Name
!= PROPERTY_EFFECTIVE_VALUE
892 && _rPropValue
.Name
!= PROPERTY_EFFECTIVE_DEFAULT
, "xmloff",
893 "OControlImport::implTranslateValueProperty: invalid property type/name combination, Any and " << _rPropValue
.Name
);
895 // Both properties are allowed to have a double or a string value,
896 // so first try to convert the string into a number
898 if (::sax::Converter::convertDouble(nValue
, sValue
))
899 _rPropValue
.Value
<<= nValue
;
901 _rPropValue
.Value
<<= sValue
;
904 _rPropValue
.Value
= PropertyConversion::convertString(aProp
.Type
, sValue
);
907 void OControlImport::endFastElement(sal_Int32 nElement
)
909 OSL_ENSURE(m_xElement
.is(), "OControlImport::EndElement: invalid control!");
910 if ( !m_xElement
.is() )
913 // register our control with its id
914 if (!m_sControlId
.isEmpty())
915 m_rFormImport
.registerControlId(m_xElement
, m_sControlId
);
916 // it's allowed to have no control id. In this case we're importing a column
918 // one more pre-work to do:
919 // when we set default values, then by definition the respective value is set
920 // to this default value, too. This means if the sequence contains for example
921 // a DefaultText value, then the Text will be affected by this, too.
922 // In case the Text is not part of the property sequence (or occurs _before_
923 // the DefaultText, which can happen for other value/default-value property names),
924 // this means that the Text (the value property) is incorrectly imported.
926 bool bRestoreValuePropertyValue
= false;
927 Any aValuePropertyValue
;
929 sal_Int16 nClassId
= FormComponentType::CONTROL
;
932 // get the class id of our element
933 m_xElement
->getPropertyValue(PROPERTY_CLASSID
) >>= nClassId
;
935 catch( const Exception
& )
937 TOOLS_WARN_EXCEPTION("xmloff.forms",
938 "caught an exception while retrieving the class id!");
941 OUString pValueProperty
;
942 OUString pDefaultValueProperty
;
943 getRuntimeValuePropertyNames(m_eElementType
, nClassId
, pValueProperty
, pDefaultValueProperty
);
944 if ( !pDefaultValueProperty
.isEmpty() && !pValueProperty
.isEmpty() )
946 bool bNonDefaultValuePropertyValue
= false;
947 // is the "value property" part of the sequence?
949 // look up this property in our sequence
950 for ( const auto& rCheck
: m_aValues
)
952 if ( rCheck
.Name
== pDefaultValueProperty
)
953 bRestoreValuePropertyValue
= true;
954 else if ( rCheck
.Name
== pValueProperty
)
956 bNonDefaultValuePropertyValue
= true;
957 // we need to restore the value property we found here, nothing else
958 aValuePropertyValue
= rCheck
.Value
;
962 if ( bRestoreValuePropertyValue
&& !bNonDefaultValuePropertyValue
)
964 // found it -> need to remember (and restore) the "value property value", which is not set explicitly
967 aValuePropertyValue
= m_xElement
->getPropertyValue( pValueProperty
);
969 catch( const Exception
& )
971 TOOLS_WARN_EXCEPTION(
973 "caught an exception while retrieving the current value property!");
978 // let the base class set all the values
979 OElementImport::endFastElement(nElement
);
981 // restore the "value property value", if necessary
982 if ( bRestoreValuePropertyValue
&& !pValueProperty
.isEmpty() )
986 m_xElement
->setPropertyValue( pValueProperty
, aValuePropertyValue
);
988 catch( const Exception
& )
990 TOOLS_WARN_EXCEPTION("xmloff.forms",
991 "caught an exception while restoring the value property!");
995 // the external cell binding, if applicable
996 if ( m_xElement
.is() && !m_sBoundCellAddress
.isEmpty() )
997 doRegisterCellValueBinding( m_sBoundCellAddress
);
999 // XForms binding, if applicable
1000 if ( m_xElement
.is() && !m_sBindingID
.isEmpty() )
1001 doRegisterXFormsValueBinding( m_sBindingID
);
1003 // XForms list binding, if applicable
1004 if ( m_xElement
.is() && !m_sListBindingID
.isEmpty() )
1005 doRegisterXFormsListBinding( m_sListBindingID
);
1007 // XForms submission, if applicable
1008 if ( m_xElement
.is() && !m_sSubmissionID
.isEmpty() )
1009 doRegisterXFormsSubmission( m_sSubmissionID
);
1012 void OControlImport::doRegisterCellValueBinding( const OUString
& _rBoundCellAddress
)
1014 OSL_PRECOND( m_xElement
.is(), "OControlImport::doRegisterCellValueBinding: invalid element!" );
1015 OSL_PRECOND( !_rBoundCellAddress
.isEmpty(),
1016 "OControlImport::doRegisterCellValueBinding: invalid address!" );
1018 m_rContext
.registerCellValueBinding( m_xElement
, _rBoundCellAddress
);
1021 void OControlImport::doRegisterXFormsValueBinding( const OUString
& _rBindingID
)
1023 OSL_PRECOND( m_xElement
.is(), "need element" );
1024 OSL_PRECOND( !_rBindingID
.isEmpty(), "binding ID is not valid" );
1026 m_rContext
.registerXFormsValueBinding( m_xElement
, _rBindingID
);
1029 void OControlImport::doRegisterXFormsListBinding( const OUString
& _rBindingID
)
1031 OSL_PRECOND( m_xElement
.is(), "need element" );
1032 OSL_PRECOND( !_rBindingID
.isEmpty(), "binding ID is not valid" );
1034 m_rContext
.registerXFormsListBinding( m_xElement
, _rBindingID
);
1037 void OControlImport::doRegisterXFormsSubmission( const OUString
& _rSubmissionID
)
1039 OSL_PRECOND( m_xElement
.is(), "need element" );
1040 OSL_PRECOND( !_rSubmissionID
.isEmpty(), "binding ID is not valid" );
1042 m_rContext
.registerXFormsSubmission( m_xElement
, _rSubmissionID
);
1045 Reference
< XPropertySet
> OControlImport::createElement()
1047 const Reference
<XPropertySet
> xPropSet
= OElementImport::createElement();
1048 if ( xPropSet
.is() )
1050 m_xInfo
= xPropSet
->getPropertySetInfo();
1051 if ( m_xInfo
.is() && m_xInfo
->hasPropertyByName(PROPERTY_ALIGN
) )
1054 xPropSet
->setPropertyValue(PROPERTY_ALIGN
,aValue
);
1060 //= OImagePositionImport
1061 OImagePositionImport::OImagePositionImport( OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
,
1062 const Reference
< XNameContainer
>& _rxParentContainer
,
1063 OControlElement::ElementType _eType
)
1064 :OControlImport( _rImport
, _rEventManager
, _rxParentContainer
, _eType
)
1065 ,m_nImagePosition( -1 )
1067 ,m_bHaveImagePosition( false )
1071 bool OImagePositionImport::handleAttribute( sal_Int32 nElement
,
1072 const OUString
& _rValue
)
1074 static const sal_Int32 s_nImageDataAttributeName
= OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::ImageData
);
1076 if ( (nElement
& TOKEN_MASK
) == s_nImageDataAttributeName
)
1078 m_xGraphic
= m_rContext
.getGlobalContext().loadGraphicByURL(_rValue
);
1081 else if ( (nElement
& TOKEN_MASK
) == XML_IMAGE_POSITION
)
1083 OSL_VERIFY( PropertyConversion::convertString(
1084 cppu::UnoType
<decltype(m_nImagePosition
)>::get(),
1085 _rValue
, aImagePositionMap
1086 ) >>= m_nImagePosition
);
1087 m_bHaveImagePosition
= true;
1090 else if ( (nElement
& TOKEN_MASK
) == XML_IMAGE_ALIGN
)
1092 OSL_VERIFY( PropertyConversion::convertString(
1093 cppu::UnoType
<decltype(m_nImageAlign
)>::get(),
1094 _rValue
, aImageAlignMap
1095 ) >>= m_nImageAlign
);
1099 return OControlImport::handleAttribute( nElement
, _rValue
);
1102 void OImagePositionImport::startFastElement(sal_Int32 nElement
, const Reference
< XFastAttributeList
>& _rxAttrList
)
1104 OControlImport::startFastElement( nElement
, _rxAttrList
);
1106 if (m_xGraphic
.is())
1108 PropertyValue aGraphicProperty
;
1109 aGraphicProperty
.Name
= PROPERTY_GRAPHIC
;
1110 aGraphicProperty
.Value
<<= m_xGraphic
;
1111 implPushBackPropertyValue(aGraphicProperty
);
1113 if ( !m_bHaveImagePosition
)
1116 sal_Int16 nUnoImagePosition
= ImagePosition::Centered
;
1117 if ( m_nImagePosition
>= 0 )
1119 OSL_ENSURE( ( m_nImagePosition
<= 3 ) && ( m_nImageAlign
>= 0 ) && ( m_nImageAlign
< 3 ),
1120 "OImagePositionImport::StartElement: unknown image align and/or position!" );
1121 nUnoImagePosition
= m_nImagePosition
* 3 + m_nImageAlign
;
1124 PropertyValue aImagePosition
;
1125 aImagePosition
.Name
= PROPERTY_IMAGE_POSITION
;
1126 aImagePosition
.Value
<<= nUnoImagePosition
;
1127 implPushBackPropertyValue( aImagePosition
);
1130 //= OReferredControlImport
1131 OReferredControlImport::OReferredControlImport(
1132 OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
,
1133 const Reference
< XNameContainer
>& _rxParentContainer
)
1134 :OControlImport(_rImport
, _rEventManager
, _rxParentContainer
)
1138 void OReferredControlImport::startFastElement(sal_Int32 nElement
, const Reference
< XFastAttributeList
>& _rxAttrList
)
1140 OControlImport::startFastElement(nElement
, _rxAttrList
);
1142 // the base class should have created the control, so we can register it
1143 if ( !m_sReferringControls
.isEmpty() )
1144 m_rFormImport
.registerControlReferences(m_xElement
, m_sReferringControls
);
1147 bool OReferredControlImport::handleAttribute(sal_Int32 nElement
,
1148 const OUString
& _rValue
)
1150 static const sal_Int32 s_nReferenceAttributeName
= OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::For
);
1151 if ((nElement
& TOKEN_MASK
) == s_nReferenceAttributeName
)
1153 m_sReferringControls
= _rValue
;
1156 return OControlImport::handleAttribute(nElement
, _rValue
);
1160 OPasswordImport::OPasswordImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
,
1161 const Reference
< XNameContainer
>& _rxParentContainer
, OControlElement::ElementType _eType
)
1162 :OControlImport(_rImport
, _rEventManager
, _rxParentContainer
, _eType
)
1166 bool OPasswordImport::handleAttribute(sal_Int32 nElement
, const OUString
& _rValue
)
1168 static const sal_Int32 s_nEchoCharAttributeName
= OAttributeMetaData::getSpecialAttributeToken(SCAFlags::EchoChar
);
1169 if ((nElement
& TOKEN_MASK
) == s_nEchoCharAttributeName
)
1171 // need a special handling for the EchoChar property
1172 PropertyValue aEchoChar
;
1173 aEchoChar
.Name
= PROPERTY_ECHOCHAR
;
1174 OSL_ENSURE(_rValue
.getLength() == 1, "OPasswordImport::handleAttribute: invalid echo char attribute!");
1175 // we ourself should not have written values other than of length 1
1176 if (_rValue
.getLength() >= 1)
1177 aEchoChar
.Value
<<= static_cast<sal_Int16
>(_rValue
[0]);
1179 aEchoChar
.Value
<<= sal_Int16(0);
1180 implPushBackPropertyValue(aEchoChar
);
1183 return OControlImport::handleAttribute(nElement
, _rValue
);
1187 ORadioImport::ORadioImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
,
1188 const Reference
< XNameContainer
>& _rxParentContainer
, OControlElement::ElementType _eType
)
1189 :OImagePositionImport( _rImport
, _rEventManager
, _rxParentContainer
, _eType
)
1193 bool ORadioImport::handleAttribute(sal_Int32 nElement
, const OUString
& _rValue
)
1195 // need special handling for the State & CurrentState properties:
1196 // they're stored as booleans, but expected to be int16 properties
1197 static const sal_Int32 nCurrentSelectedAttributeName
= OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::CurrentSelected
);
1198 static const sal_Int32 nSelectedAttributeName
= OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Selected
);
1199 if ( (nElement
& TOKEN_MASK
) == nCurrentSelectedAttributeName
1200 || (nElement
& TOKEN_MASK
) == nSelectedAttributeName
1203 const OAttribute2Property::AttributeAssignment
* pProperty
= m_rContext
.getAttributeMap().getAttributeTranslation(nElement
& TOKEN_MASK
);
1204 assert(pProperty
&& "ORadioImport::handleAttribute: invalid property map!");
1207 const Any
aBooleanValue( PropertyConversion::convertString(pProperty
->aPropertyType
, _rValue
, pProperty
->pEnumMap
) );
1209 // create and store a new PropertyValue
1210 PropertyValue aNewValue
;
1211 aNewValue
.Name
= pProperty
->sPropertyName
;
1212 aNewValue
.Value
<<= static_cast<sal_Int16
>(::cppu::any2bool(aBooleanValue
));
1214 implPushBackPropertyValue(aNewValue
);
1218 return OImagePositionImport::handleAttribute( nElement
, _rValue
);
1221 //= OURLReferenceImport
1222 OURLReferenceImport::OURLReferenceImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
,
1223 const Reference
< XNameContainer
>& _rxParentContainer
,
1224 OControlElement::ElementType _eType
)
1225 :OImagePositionImport(_rImport
, _rEventManager
, _rxParentContainer
, _eType
)
1229 bool OURLReferenceImport::handleAttribute(sal_Int32 nElement
, const OUString
& _rValue
)
1231 static const sal_Int32 s_nTargetLocationAttributeName
= OAttributeMetaData::getCommonControlAttributeToken( CCAFlags::TargetLocation
);
1232 static const sal_Int32 s_nImageDataAttributeName
= OAttributeMetaData::getCommonControlAttributeToken( CCAFlags::ImageData
);
1234 // need to make the URL absolute if
1235 // * it's the image-data attribute
1236 // * it's the target-location attribute, and we're dealing with an object which has the respective property
1237 bool bMakeAbsolute
=
1238 (nElement
& TOKEN_MASK
) == s_nImageDataAttributeName
1239 || ( (nElement
& TOKEN_MASK
) == s_nTargetLocationAttributeName
1240 && ( ( OControlElement::BUTTON
== m_eElementType
)
1241 || ( OControlElement::IMAGE
== m_eElementType
)
1245 if (bMakeAbsolute
&& !_rValue
.isEmpty())
1247 OUString sAdjustedValue
= _rValue
;
1248 if ((nElement
& TOKEN_MASK
) != s_nImageDataAttributeName
)
1249 sAdjustedValue
= m_rContext
.getGlobalContext().GetAbsoluteReference( _rValue
);
1250 return OImagePositionImport::handleAttribute( nElement
, sAdjustedValue
);
1253 return OImagePositionImport::handleAttribute( nElement
, _rValue
);
1257 OButtonImport::OButtonImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
,
1258 const Reference
< XNameContainer
>& _rxParentContainer
,
1259 OControlElement::ElementType _eType
)
1260 :OURLReferenceImport(_rImport
, _rEventManager
, _rxParentContainer
, _eType
)
1262 enableTrackAttributes();
1265 void OButtonImport::startFastElement(sal_Int32 nElement
, const Reference
< XFastAttributeList
>& _rxAttrList
)
1267 OURLReferenceImport::startFastElement(nElement
, _rxAttrList
);
1269 // handle the target-frame attribute
1270 simulateDefaultedAttribute(OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::TargetFrame
), PROPERTY_TARGETFRAME
, u
"_blank"_ustr
);
1273 //= OValueRangeImport
1274 OValueRangeImport::OValueRangeImport( OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
,
1275 const Reference
< XNameContainer
>& _rxParentContainer
, OControlElement::ElementType _eType
)
1276 :OControlImport( _rImport
, _rEventManager
, _rxParentContainer
, _eType
)
1277 ,m_nStepSizeValue( 1 )
1282 bool OValueRangeImport::handleAttribute( sal_Int32 nElement
, const OUString
& _rValue
)
1284 if ( (nElement
& TOKEN_MASK
) == OAttributeMetaData::getSpecialAttributeToken( SCAFlags::StepSize
) )
1286 ::sax::Converter::convertNumber( m_nStepSizeValue
, _rValue
);
1289 return OControlImport::handleAttribute( nElement
, _rValue
);
1292 void OValueRangeImport::startFastElement( sal_Int32 nElement
, const Reference
< XFastAttributeList
>& _rxAttrList
)
1294 OControlImport::startFastElement( nElement
, _rxAttrList
);
1298 if ( m_xInfo
->hasPropertyByName( PROPERTY_SPIN_INCREMENT
) )
1299 m_xElement
->setPropertyValue( PROPERTY_SPIN_INCREMENT
, Any( m_nStepSizeValue
) );
1300 else if ( m_xInfo
->hasPropertyByName( PROPERTY_LINE_INCREMENT
) )
1301 m_xElement
->setPropertyValue( PROPERTY_LINE_INCREMENT
, Any( m_nStepSizeValue
) );
1306 OTextLikeImport::OTextLikeImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
,
1307 const Reference
< XNameContainer
>& _rxParentContainer
,
1308 OControlElement::ElementType _eType
)
1309 :OControlImport(_rImport
, _rEventManager
, _rxParentContainer
, _eType
)
1310 ,m_bEncounteredTextPara( false )
1312 enableTrackAttributes();
1315 css::uno::Reference
< css::xml::sax::XFastContextHandler
> OTextLikeImport::createFastChildContext(
1317 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
1319 if ( nElement
== XML_ELEMENT(TEXT
, XML_P
) )
1321 OSL_ENSURE( m_eElementType
== OControlElement::TEXT_AREA
,
1322 "OTextLikeImport::CreateChildContext: text paragraphs in a non-text-area?" );
1324 if ( m_eElementType
== OControlElement::TEXT_AREA
)
1326 Reference
< XText
> xTextElement( m_xElement
, UNO_QUERY
);
1327 if ( xTextElement
.is() )
1329 rtl::Reference
< XMLTextImportHelper
> xTextImportHelper( m_rContext
.getGlobalContext().GetTextImport() );
1331 if ( !m_xCursor
.is() )
1333 m_xOldCursor
= xTextImportHelper
->GetCursor();
1334 m_xCursor
= xTextElement
->createTextCursor();
1336 if ( m_xCursor
.is() )
1337 xTextImportHelper
->SetCursor( m_xCursor
);
1339 if ( m_xCursor
.is() )
1341 m_bEncounteredTextPara
= true;
1342 return xTextImportHelper
->CreateTextChildContext( m_rContext
.getGlobalContext(), nElement
, xAttrList
);
1347 // in theory, we could accumulate all the text portions (without formatting),
1348 // and set it as Text property at the model ...
1353 return OControlImport::createFastChildContext( nElement
, xAttrList
);
1356 void OTextLikeImport::startFastElement(sal_Int32 nElement
, const Reference
< css::xml::sax::XFastAttributeList
>& _rxAttrList
)
1358 OControlImport::startFastElement(nElement
, _rxAttrList
);
1360 // handle the convert-empty-to-null attribute, whose default is different from the property default
1361 // unfortunately, different classes are imported by this class ('cause they're represented by the
1362 // same XML element), though not all of them know this property.
1363 // So we have to do a check ...
1364 if (m_xElement
.is() && m_xInfo
.is() && m_xInfo
->hasPropertyByName(PROPERTY_EMPTY_IS_NULL
) )
1365 simulateDefaultedAttribute(OAttributeMetaData::getDatabaseAttributeToken(DAFlags::ConvertEmpty
), PROPERTY_EMPTY_IS_NULL
, u
"false"_ustr
);
1372 const sal_Int32 m_nHandle
;
1373 explicit EqualHandle( sal_Int32 _nHandle
) : m_nHandle( _nHandle
) { }
1375 bool operator()( const PropertyValue
& _rProp
)
1377 return _rProp
.Handle
== m_nHandle
;
1383 void OTextLikeImport::removeRedundantCurrentValue()
1385 if ( !m_bEncounteredTextPara
)
1388 // In case the text is written in the text:p elements, we need to ignore what we read as
1389 // current-value attribute, since it's redundant.
1390 // fortunately, OElementImport tagged the value property with the PROPID_CURRENT_VALUE
1391 // handle, so we do not need to determine the name of our value property here
1392 // (normally, it should be "Text", since no other controls than the edit field should
1393 // have the text:p elements)
1394 PropertyValueArray::iterator aValuePropertyPos
= ::std::find_if(
1397 EqualHandle( PROPID_CURRENT_VALUE
)
1399 if ( aValuePropertyPos
!= m_aValues
.end() )
1401 OSL_ENSURE( aValuePropertyPos
->Name
== PROPERTY_TEXT
, "OTextLikeImport::EndElement: text:p was present, but our value property is *not* 'Text'!" );
1402 if ( aValuePropertyPos
->Name
== PROPERTY_TEXT
)
1404 m_aValues
.erase(aValuePropertyPos
);
1408 // additionally, we need to set the "RichText" property of our element to sal_True
1409 // (the presence of the text:p is used as indicator for the value of the RichText property)
1410 bool bHasRichTextProperty
= false;
1412 bHasRichTextProperty
= m_xInfo
->hasPropertyByName( PROPERTY_RICH_TEXT
);
1413 OSL_ENSURE( bHasRichTextProperty
, "OTextLikeImport::EndElement: text:p, but no rich text control?" );
1414 if ( bHasRichTextProperty
)
1415 m_xElement
->setPropertyValue( PROPERTY_RICH_TEXT
, Any( true ) );
1416 // Note that we do *not* set the RichText property (in case our element has one) to sal_False here
1417 // since this is the default of this property, anyway.
1424 const OUString
& m_sName
;
1425 explicit EqualName( const OUString
& _rName
) : m_sName( _rName
) { }
1427 bool operator()( const PropertyValue
& _rProp
)
1429 return _rProp
.Name
== m_sName
;
1435 void OTextLikeImport::adjustDefaultControlProperty()
1437 // In OpenOffice.org 2.0, we changed the implementation of the css.form.component.TextField (the model of a text field control),
1438 // so that it now uses another default control. So if we encounter a text field where the *old* default
1439 // control property is writing, we are not allowed to use it
1440 PropertyValueArray::iterator aDefaultControlPropertyPos
= ::std::find_if(
1443 EqualName( u
"DefaultControl"_ustr
)
1445 if ( aDefaultControlPropertyPos
!= m_aValues
.end() )
1447 OUString sDefaultControl
;
1448 OSL_VERIFY( aDefaultControlPropertyPos
->Value
>>= sDefaultControl
);
1449 if ( sDefaultControl
== "stardiv.one.form.control.Edit" )
1451 // complete remove this property value from the array. Today's "default value" of the "DefaultControl"
1452 // property is sufficient
1453 m_aValues
.erase(aDefaultControlPropertyPos
);
1458 void OTextLikeImport::endFastElement(sal_Int32 nElement
)
1460 removeRedundantCurrentValue();
1461 adjustDefaultControlProperty();
1463 // let the base class do the stuff
1464 OControlImport::endFastElement(nElement
);
1467 rtl::Reference
< XMLTextImportHelper
> xTextImportHelper( m_rContext
.getGlobalContext().GetTextImport() );
1468 if ( m_xCursor
.is() )
1470 // delete the newline which has been imported erroneously
1471 // TODO (fs): stole this code somewhere - why don't we fix the text import??
1472 m_xCursor
->gotoEnd( false );
1473 m_xCursor
->goLeft( 1, true );
1474 m_xCursor
->setString( OUString() );
1477 xTextImportHelper
->ResetCursor();
1480 if ( m_xOldCursor
.is() )
1481 xTextImportHelper
->SetCursor( m_xOldCursor
);
1485 //= OListAndComboImport
1486 OListAndComboImport::OListAndComboImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
,
1487 const Reference
< XNameContainer
>& _rxParentContainer
,
1488 OControlElement::ElementType _eType
)
1489 :OControlImport(_rImport
, _rEventManager
, _rxParentContainer
, _eType
)
1490 ,m_nEmptyListItems( 0 )
1491 ,m_nEmptyValueItems( 0 )
1492 ,m_bEncounteredLSAttrib( false )
1493 ,m_bLinkWithIndexes( false )
1495 if (OControlElement::COMBOBOX
== m_eElementType
)
1496 enableTrackAttributes();
1499 css::uno::Reference
< css::xml::sax::XFastContextHandler
> OListAndComboImport::createFastChildContext(
1501 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& _rxAttrList
)
1503 // is it the "option" sub tag of a listbox ?
1504 if ((nElement
& TOKEN_MASK
) == XML_OPTION
)
1505 return new OListOptionImport(GetImport(), this);
1507 // is it the "item" sub tag of a combobox ?
1508 if ((nElement
& TOKEN_MASK
) == XML_ITEM
)
1509 return new OComboItemImport(GetImport(), this);
1512 return OControlImport::createFastChildContext(nElement
, _rxAttrList
);
1515 void OListAndComboImport::startFastElement(sal_Int32 nElement
, const Reference
< XFastAttributeList
>& _rxAttrList
)
1517 m_bLinkWithIndexes
= false;
1519 OControlImport::startFastElement(nElement
, _rxAttrList
);
1521 if (OControlElement::COMBOBOX
== m_eElementType
)
1523 // for the auto-completion
1524 // the attribute default does not equal the property default, so in case we did not read this attribute,
1525 // we have to simulate it
1526 simulateDefaultedAttribute( OAttributeMetaData::getSpecialAttributeToken( SCAFlags::AutoCompletion
), PROPERTY_AUTOCOMPLETE
, u
"false"_ustr
);
1528 // same for the convert-empty-to-null attribute, which's default is different from the property default
1529 simulateDefaultedAttribute( OAttributeMetaData::getDatabaseAttributeToken( DAFlags::ConvertEmpty
), PROPERTY_EMPTY_IS_NULL
, u
"false"_ustr
);
1533 void OListAndComboImport::endFastElement(sal_Int32 nElement
)
1535 // append the list source property the properties sequence of our importer
1536 // the string item list
1537 PropertyValue aItemList
;
1538 aItemList
.Name
= PROPERTY_STRING_ITEM_LIST
;
1539 aItemList
.Value
<<= comphelper::containerToSequence(m_aListSource
);
1540 implPushBackPropertyValue(aItemList
);
1542 if (OControlElement::LISTBOX
== m_eElementType
)
1544 OSL_ENSURE((m_aListSource
.size() + m_nEmptyListItems
) == (m_aValueList
.size() + m_nEmptyValueItems
),
1545 "OListAndComboImport::EndElement: inconsistence between labels and values!");
1547 if ( !m_bEncounteredLSAttrib
)
1549 // the value sequence
1550 PropertyValue aValueList
;
1551 aValueList
.Name
= PROPERTY_LISTSOURCE
;
1552 aValueList
.Value
<<= comphelper::containerToSequence(m_aValueList
);
1553 implPushBackPropertyValue(aValueList
);
1556 // the select sequence
1557 PropertyValue aSelected
;
1558 aSelected
.Name
= PROPERTY_SELECT_SEQ
;
1559 aSelected
.Value
<<= comphelper::containerToSequence(m_aSelectedSeq
);
1560 implPushBackPropertyValue(aSelected
);
1562 // the default select sequence
1563 PropertyValue aDefaultSelected
;
1564 aDefaultSelected
.Name
= PROPERTY_DEFAULT_SELECT_SEQ
;
1565 aDefaultSelected
.Value
<<= comphelper::containerToSequence(m_aDefaultSelectedSeq
);
1566 implPushBackPropertyValue(aDefaultSelected
);
1569 OControlImport::endFastElement(nElement
);
1571 // the external list source, if applicable
1572 if ( m_xElement
.is() && !m_sCellListSource
.isEmpty() )
1573 m_rContext
.registerCellRangeListSource( m_xElement
, m_sCellListSource
);
1576 void OListAndComboImport::doRegisterCellValueBinding( const OUString
& _rBoundCellAddress
)
1578 OUString
sBoundCellAddress( _rBoundCellAddress
);
1579 if ( m_bLinkWithIndexes
)
1581 // This is a HACK. We register a string which is no valid address, but allows
1582 // (somewhere else) to determine that a non-standard binding should be created.
1583 // This hack is acceptable for OOo 1.1.1, since the file format for value
1584 // bindings of form controls is to be changed afterwards, anyway.
1585 sBoundCellAddress
+= ":index";
1588 OControlImport::doRegisterCellValueBinding( sBoundCellAddress
);
1591 bool OListAndComboImport::handleAttribute(sal_Int32 nElement
, const OUString
& _rValue
)
1593 static const sal_Int32 nListSourceAttributeName
= OAttributeMetaData::getDatabaseAttributeToken(DAFlags::ListSource
);
1594 if ( (nElement
& TOKEN_MASK
) == nListSourceAttributeName
)
1596 PropertyValue aListSource
;
1597 aListSource
.Name
= PROPERTY_LISTSOURCE
;
1599 // it's the ListSource attribute
1600 m_bEncounteredLSAttrib
= true;
1601 if ( OControlElement::COMBOBOX
== m_eElementType
)
1603 aListSource
.Value
<<= _rValue
;
1607 // a listbox which has a list-source attribute must have a list-source-type of something
1608 // not equal to ValueList.
1609 // In this case, the list-source value is simply the one and only element of the ListSource property.
1610 Sequence
<OUString
> aListSourcePropValue
{ _rValue
};
1611 aListSource
.Value
<<= aListSourcePropValue
;
1614 implPushBackPropertyValue( aListSource
);
1618 if ( (nElement
& TOKEN_MASK
) == OAttributeMetaData::getBindingAttributeToken( BAFlags::ListCellRange
) )
1620 m_sCellListSource
= _rValue
;
1624 if ( (nElement
& TOKEN_MASK
) == OAttributeMetaData::getBindingAttributeToken( BAFlags::ListLinkingType
) )
1626 sal_Int16 nLinkageType
= 0;
1627 PropertyConversion::convertString(
1628 ::cppu::UnoType
<sal_Int16
>::get(),
1633 m_bLinkWithIndexes
= ( nLinkageType
!= 0 );
1637 return OControlImport::handleAttribute(nElement
, _rValue
);
1640 void OListAndComboImport::implPushBackLabel(const OUString
& _rLabel
)
1642 OSL_ENSURE(!m_nEmptyListItems
, "OListAndComboImport::implPushBackValue: label list is already done!");
1643 if (!m_nEmptyListItems
)
1644 m_aListSource
.push_back(_rLabel
);
1647 void OListAndComboImport::implPushBackValue(const OUString
& _rValue
)
1649 OSL_ENSURE(!m_nEmptyValueItems
, "OListAndComboImport::implPushBackValue: value list is already done!");
1650 if (!m_nEmptyValueItems
)
1652 OSL_ENSURE( !m_bEncounteredLSAttrib
, "OListAndComboImport::implPushBackValue: invalid structure! Did you save this document with a version prior SRC641 m?" );
1653 // We already had the list-source attribute, which means that the ListSourceType is
1654 // not ValueList, which means that the ListSource should contain only one string in
1655 // the first element of the sequence
1656 // All other values in the file are invalid
1658 m_aValueList
.push_back( _rValue
);
1662 void OListAndComboImport::implEmptyLabelFound()
1664 ++m_nEmptyListItems
;
1667 void OListAndComboImport::implEmptyValueFound()
1669 ++m_nEmptyValueItems
;
1672 void OListAndComboImport::implSelectCurrentItem()
1674 OSL_ENSURE((m_aListSource
.size() + m_nEmptyListItems
) == (m_aValueList
.size() + m_nEmptyValueItems
),
1675 "OListAndComboImport::implSelectCurrentItem: inconsistence between labels and values!");
1677 sal_Int16 nItemNumber
= static_cast<sal_Int16
>(m_aListSource
.size() - 1 + m_nEmptyListItems
);
1678 m_aSelectedSeq
.push_back(nItemNumber
);
1681 void OListAndComboImport::implDefaultSelectCurrentItem()
1683 OSL_ENSURE((m_aListSource
.size() + m_nEmptyListItems
) == (m_aValueList
.size() + m_nEmptyValueItems
),
1684 "OListAndComboImport::implDefaultSelectCurrentItem: inconsistence between labels and values!");
1686 sal_Int16 nItemNumber
= static_cast<sal_Int16
>(m_aListSource
.size() - 1 + m_nEmptyListItems
);
1687 m_aDefaultSelectedSeq
.push_back(nItemNumber
);
1690 //= OListOptionImport
1691 OListOptionImport::OListOptionImport(SvXMLImport
& _rImport
,
1692 OListAndComboImportRef _xListBox
)
1693 :SvXMLImportContext(_rImport
)
1694 ,m_xListBoxImport(std::move(_xListBox
))
1698 void OListOptionImport::startFastElement(sal_Int32 nElement
, const Reference
< XFastAttributeList
>& _rxAttrList
)
1700 // the label and the value
1701 const sal_Int32 nLabelAttribute
= (nElement
& ~TOKEN_MASK
) | XML_LABEL
;
1702 const sal_Int32 nValueAttribute
= (nElement
& ~TOKEN_MASK
) | XML_VALUE
;
1704 // the label attribute
1705 OUString sValue
= _rxAttrList
->getOptionalValue(nLabelAttribute
);
1706 bool bNonexistentAttribute
= !_rxAttrList
->hasAttribute(nLabelAttribute
);
1708 if (bNonexistentAttribute
)
1709 m_xListBoxImport
->implEmptyLabelFound();
1711 m_xListBoxImport
->implPushBackLabel( sValue
);
1713 // the value attribute
1714 sValue
= _rxAttrList
->getOptionalValue(nValueAttribute
);
1715 bNonexistentAttribute
= !_rxAttrList
->hasAttribute(nValueAttribute
);
1717 if (bNonexistentAttribute
)
1718 m_xListBoxImport
->implEmptyValueFound();
1720 m_xListBoxImport
->implPushBackValue( sValue
);
1722 // the current-selected and selected
1723 const sal_Int32 nSelectedAttribute
= (nElement
& ~TOKEN_MASK
) | OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::CurrentSelected
);
1724 const sal_Int32 nDefaultSelectedAttribute
= (nElement
& ~TOKEN_MASK
) | OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Selected
);
1726 // propagate the selected flag
1727 bool bSelected(false);
1728 (void)::sax::Converter::convertBool(bSelected
,
1729 _rxAttrList
->getOptionalValue(nSelectedAttribute
));
1731 m_xListBoxImport
->implSelectCurrentItem();
1733 // same for the default selected
1734 bool bDefaultSelected(false);
1735 (void)::sax::Converter::convertBool(bDefaultSelected
,
1736 _rxAttrList
->getOptionalValue(nDefaultSelectedAttribute
));
1737 if (bDefaultSelected
)
1738 m_xListBoxImport
->implDefaultSelectCurrentItem();
1741 //= OComboItemImport
1742 OComboItemImport::OComboItemImport(SvXMLImport
& _rImport
,
1743 OListAndComboImportRef _xListBox
)
1744 :SvXMLImportContext(_rImport
)
1745 ,m_xListBoxImport(std::move(_xListBox
))
1749 void OComboItemImport::startFastElement(sal_Int32 nElement
, const Reference
< XFastAttributeList
>& _rxAttrList
)
1751 const sal_Int32 nLabelAttributeName
= (nElement
& ~TOKEN_MASK
) |
1752 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Label
);
1753 m_xListBoxImport
->implPushBackLabel(_rxAttrList
->getOptionalValue(nLabelAttributeName
));
1756 //= OColumnWrapperImport
1757 OColumnWrapperImport::OColumnWrapperImport(OFormLayerXMLImport_Impl
& _rImport
,
1758 IEventAttacherManager
& _rEventManager
, sal_Int32
/*nElement*/,
1759 const Reference
< XNameContainer
>& _rxParentContainer
)
1760 :SvXMLImportContext(_rImport
.getGlobalContext())
1761 ,m_xParentContainer(_rxParentContainer
)
1762 ,m_rFormImport(_rImport
)
1763 ,m_rEventManager(_rEventManager
)
1766 css::uno::Reference
< css::xml::sax::XFastContextHandler
> OColumnWrapperImport::createFastChildContext(
1768 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& )
1770 OControlImport
* pReturn
= implCreateChildContext(nElement
, OElementNameMap::getElementType(nElement
& TOKEN_MASK
));
1773 OSL_ENSURE(m_xOwnAttributes
.is(), "OColumnWrapperImport::CreateChildContext: had no form:column element!");
1774 pReturn
->addOuterAttributes(m_xOwnAttributes
);
1778 void OColumnWrapperImport::startFastElement(sal_Int32
/*nElement*/, const Reference
< XFastAttributeList
>& _rxAttrList
)
1780 OSL_ENSURE(!m_xOwnAttributes
.is(), "OColumnWrapperImport::StartElement: already have the cloned list!");
1782 // clone the attributes
1783 Reference
< XCloneable
> xCloneList(_rxAttrList
, UNO_QUERY_THROW
);
1784 m_xOwnAttributes
.set(xCloneList
->createClone(), UNO_QUERY_THROW
);
1787 OControlImport
* OColumnWrapperImport::implCreateChildContext(
1788 sal_Int32
/*nElement*/,
1789 OControlElement::ElementType _eType
)
1791 OSL_ENSURE( (OControlElement::TEXT
== _eType
)
1792 || (OControlElement::TEXT_AREA
== _eType
)
1793 || (OControlElement::FORMATTED_TEXT
== _eType
)
1794 || (OControlElement::CHECKBOX
== _eType
)
1795 || (OControlElement::LISTBOX
== _eType
)
1796 || (OControlElement::COMBOBOX
== _eType
)
1797 || (OControlElement::TIME
== _eType
)
1798 || (OControlElement::DATE
== _eType
),
1799 "OColumnWrapperImport::implCreateChildContext: invalid or unrecognized sub element!");
1803 case OControlElement::COMBOBOX
:
1804 case OControlElement::LISTBOX
:
1805 return new OColumnImport
<OListAndComboImport
>(m_rFormImport
, m_rEventManager
, m_xParentContainer
, _eType
);
1807 case OControlElement::PASSWORD
:
1808 return new OColumnImport
<OPasswordImport
>(m_rFormImport
, m_rEventManager
, m_xParentContainer
, _eType
);
1810 case OControlElement::TEXT
:
1811 case OControlElement::TEXT_AREA
:
1812 case OControlElement::FORMATTED_TEXT
:
1813 return new OColumnImport
< OTextLikeImport
>( m_rFormImport
, m_rEventManager
, m_xParentContainer
, _eType
);
1816 return new OColumnImport
<OControlImport
>(m_rFormImport
, m_rEventManager
, m_xParentContainer
, _eType
);
1821 OGridImport::OGridImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
,
1822 const Reference
< XNameContainer
>& _rxParentContainer
,
1823 OControlElement::ElementType _eType
)
1824 :OControlImport(_rImport
, _rEventManager
, _rxParentContainer
)
1826 setElementType(_eType
);
1829 css::uno::Reference
< css::xml::sax::XFastContextHandler
> OGridImport::createFastChildContext(
1831 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
1833 // maybe it's a sub control
1834 if ((nElement
& TOKEN_MASK
) == XML_COLUMN
)
1836 if (m_xMeAsContainer
.is())
1837 return new OColumnWrapperImport(m_rFormImport
, *this, nElement
, m_xMeAsContainer
);
1840 OSL_FAIL("OGridImport::CreateChildContext: don't have an element!");
1845 return OControlImport::createFastChildContext(nElement
, xAttrList
);
1848 void OGridImport::endFastElement(sal_Int32 nElement
)
1850 OControlImport::endFastElement(nElement
);
1852 // now that we have all children, attach the events
1853 css::uno::Reference
< css::container::XIndexAccess
> xIndexContainer(m_xMeAsContainer
, css::uno::UNO_QUERY
);
1854 if (xIndexContainer
.is())
1855 ODefaultEventAttacherManager::setEvents(xIndexContainer
);
1858 css::uno::Reference
< css::beans::XPropertySet
> OGridImport::createElement()
1860 // let the base class create the object
1861 css::uno::Reference
< css::beans::XPropertySet
> xReturn
= OControlImport::createElement();
1865 // ensure that the object is a XNameContainer (we strongly need this for inserting child elements)
1866 m_xMeAsContainer
.set(xReturn
, css::uno::UNO_QUERY
);
1867 if (!m_xMeAsContainer
.is())
1869 OSL_FAIL("OContainerImport::createElement: invalid element (no XNameContainer) created!");
1877 OFormImport::OFormImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
,
1878 const Reference
< XNameContainer
>& _rxParentContainer
)
1879 :OElementImport(_rImport
, _rEventManager
, _rxParentContainer
)
1881 enableTrackAttributes();
1884 css::uno::Reference
< css::xml::sax::XFastContextHandler
> OFormImport::createFastChildContext(
1886 const uno::Reference
< xml::sax::XFastAttributeList
>& _rxAttrList
)
1888 auto nToken
= (nElement
& TOKEN_MASK
);
1889 if( nToken
== XML_FORM
)
1890 return new OFormImport( m_rFormImport
, *this, m_xMeAsContainer
);
1891 else if ( nToken
== XML_CONNECTION_RESOURCE
)
1892 return new OXMLDataSourceImport(GetImport(), _rxAttrList
, m_xElement
);
1893 else if( nElement
== XML_ELEMENT(OFFICE
, XML_EVENT_LISTENERS
) ||
1894 nToken
== XML_PROPERTIES
)
1895 return OElementImport::createFastChildContext( nElement
, _rxAttrList
);
1898 OControlElement::ElementType eType
= OElementNameMap::getElementType(nToken
);
1901 case OControlElement::TEXT
:
1902 case OControlElement::TEXT_AREA
:
1903 case OControlElement::FORMATTED_TEXT
:
1904 return new OTextLikeImport(m_rFormImport
, *this, m_xMeAsContainer
, eType
);
1905 case OControlElement::GRID
:
1906 return new OGridImport(m_rFormImport
, *this, m_xMeAsContainer
, eType
);
1907 case OControlElement::COMBOBOX
:
1908 case OControlElement::LISTBOX
:
1909 return new OListAndComboImport(m_rFormImport
, *this, m_xMeAsContainer
, eType
);
1910 case OControlElement::PASSWORD
:
1911 return new OPasswordImport(m_rFormImport
, *this, m_xMeAsContainer
, eType
);
1912 case OControlElement::BUTTON
:
1913 case OControlElement::IMAGE
:
1914 case OControlElement::IMAGE_FRAME
:
1915 return new OButtonImport( m_rFormImport
, *this, m_xMeAsContainer
, eType
);
1916 case OControlElement::RADIO
:
1917 return new ORadioImport(m_rFormImport
, *this, m_xMeAsContainer
, eType
);
1918 case OControlElement::CHECKBOX
:
1919 return new OImagePositionImport(m_rFormImport
, *this, m_xMeAsContainer
, eType
);
1920 case OControlElement::FRAME
:
1921 case OControlElement::FIXED_TEXT
:
1922 return new OReferredControlImport(m_rFormImport
, *this, m_xMeAsContainer
);
1923 case OControlElement::VALUERANGE
:
1924 return new OValueRangeImport( m_rFormImport
, *this, m_xMeAsContainer
, eType
);
1926 return new OControlImport(m_rFormImport
, *this, m_xMeAsContainer
, eType
);
1931 void OFormImport::startFastElement(sal_Int32 nElement
, const Reference
< XFastAttributeList
>& _rxAttrList
)
1933 m_rFormImport
.enterEventContext();
1934 OElementImport::startFastElement(nElement
, _rxAttrList
);
1936 // handle the target-frame attribute
1937 simulateDefaultedAttribute(OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::TargetFrame
), PROPERTY_TARGETFRAME
, u
"_blank"_ustr
);
1940 void OFormImport::endFastElement(sal_Int32 nElement
)
1942 OElementImport::endFastElement(nElement
);
1944 // now that we have all children, attach the events
1945 css::uno::Reference
< css::container::XIndexAccess
> xIndexContainer(m_xMeAsContainer
, css::uno::UNO_QUERY
);
1946 if (xIndexContainer
.is())
1947 ODefaultEventAttacherManager::setEvents(xIndexContainer
);
1949 m_rFormImport
.leaveEventContext();
1952 css::uno::Reference
< css::beans::XPropertySet
> OFormImport::createElement()
1954 // let the base class create the object
1955 css::uno::Reference
< css::beans::XPropertySet
> xReturn
= OElementImport::createElement();
1959 // ensure that the object is a XNameContainer (we strongly need this for inserting child elements)
1960 m_xMeAsContainer
.set(xReturn
, css::uno::UNO_QUERY
);
1961 if (!m_xMeAsContainer
.is())
1963 OSL_FAIL("OContainerImport::createElement: invalid element (no XNameContainer) created!");
1970 bool OFormImport::handleAttribute(sal_Int32 nElement
, const OUString
& _rValue
)
1972 // handle the master/details field attributes (they're way too special to let the OPropertyImport handle them)
1973 static const sal_Int32 s_nMasterFieldsAttributeName
= OAttributeMetaData::getFormAttributeToken(faMasterFields
);
1974 static const sal_Int32 s_nDetailFieldsAttributeName
= OAttributeMetaData::getFormAttributeToken(faDetailFields
);
1976 if ( (nElement
& TOKEN_MASK
) == s_nMasterFieldsAttributeName
)
1978 implTranslateStringListProperty(PROPERTY_MASTERFIELDS
, _rValue
);
1982 if ( (nElement
& TOKEN_MASK
) == s_nDetailFieldsAttributeName
)
1984 implTranslateStringListProperty(PROPERTY_DETAILFIELDS
, _rValue
);
1988 return OElementImport::handleAttribute(nElement
, _rValue
);
1991 void OFormImport::implTranslateStringListProperty(const OUString
& _rPropertyName
, const OUString
& _rValue
)
1993 PropertyValue aProp
;
1994 aProp
.Name
= _rPropertyName
;
1996 Sequence
< OUString
> aList
;
1998 // split up the value string
1999 if (!_rValue
.isEmpty())
2001 // For the moment, we build a vector instead of a Sequence. It's easier to handle because of its
2003 ::std::vector
< OUString
> aElements
;
2004 // estimate the number of tokens
2005 sal_Int32 nEstimate
= 0, nLength
= _rValue
.getLength();
2006 const sal_Unicode
* pChars
= _rValue
.getStr();
2007 for (sal_Int32 i
=0; i
<nLength
; ++i
, ++pChars
)
2010 aElements
.reserve(nEstimate
+ 1);
2011 // that's the worst case. If the string contains the separator character _quoted_, we reserved too much...
2013 sal_Int32 nElementStart
= 0;
2014 sal_Int32 nNextSep
= 0;
2017 // extract the current element
2018 nNextSep
= ::sax::Converter::indexOfComma(
2019 _rValue
, nElementStart
);
2022 std::u16string_view sElement
= _rValue
.subView(nElementStart
, nNextSep
- nElementStart
);
2024 size_t nElementLength
= sElement
.size();
2025 // when writing the sequence, we quoted the single elements with " characters
2026 OSL_ENSURE( o3tl::starts_with(sElement
, u
"\"") && o3tl::ends_with(sElement
, u
"\""),
2027 "OFormImport::implTranslateStringListProperty: invalid quoted element name.");
2028 sElement
= sElement
.substr(1, nElementLength
- 2);
2030 aElements
.emplace_back(sElement
);
2032 // switch to the next element
2033 nElementStart
= 1 + nNextSep
;
2035 while (nElementStart
< nLength
);
2037 aList
= Sequence
< OUString
>(aElements
.data(), aElements
.size());
2041 OSL_FAIL("OFormImport::implTranslateStringListProperty: invalid value (empty)!");
2044 aProp
.Value
<<= aList
;
2046 // add the property to the base class' array
2047 implPushBackPropertyValue(aProp
);
2049 //= OXMLDataSourceImport
2050 OXMLDataSourceImport::OXMLDataSourceImport(
2051 SvXMLImport
& _rImport
2052 ,const Reference
< css::xml::sax::XFastAttributeList
> & _xAttrList
2053 ,const css::uno::Reference
< css::beans::XPropertySet
>& _xElement
) :
2054 SvXMLImportContext( _rImport
)
2056 for( auto& aIter
: sax_fastparser::castToFastAttributeList(_xAttrList
) )
2058 if ( aIter
.getToken() ==
2059 XML_ELEMENT(XLINK
, OAttributeMetaData::getCommonControlAttributeToken( CCAFlags::TargetLocation
) ) )
2061 OUString sValue
= aIter
.toString();
2062 sValue
= _rImport
.GetAbsoluteReference(sValue
);
2063 INetURLObject
aURL(sValue
);
2064 if ( aURL
.GetProtocol() == INetProtocol::File
)
2065 _xElement
->setPropertyValue(PROPERTY_DATASOURCENAME
,Any(sValue
));
2067 _xElement
->setPropertyValue(PROPERTY_URL
,Any(sValue
)); // the url is the "sdbc:" string
2071 SAL_WARN("xmloff", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter
.getToken()) << "=" << aIter
.toString());
2075 OUString
OFormImport::determineDefaultServiceName() const
2077 return u
"com.sun.star.form.component.Form"_ustr
;
2080 } // namespace xmloff
2082 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */