Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / extensions / source / propctrlr / eformshelper.cxx
blobe3bf4bf07a539426e19febea455acaba55ce42a9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <memory>
21 #include "eformshelper.hxx"
22 #include "formstrings.hxx"
23 #include <strings.hrc>
24 #include "modulepcr.hxx"
25 #include "propeventtranslation.hxx"
26 #include "formbrowsertools.hxx"
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/form/FormComponentType.hpp>
30 #include <com/sun/star/xforms/XFormsUIHelper1.hpp>
31 #include <com/sun/star/xsd/DataTypeClass.hpp>
32 #include <com/sun/star/form/binding/XListEntrySink.hpp>
33 #include <tools/diagnose_ex.h>
34 #include <rtl/ustrbuf.hxx>
36 #include <algorithm>
37 #include <o3tl/functional.hxx>
39 namespace pcr
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::beans;
46 using namespace ::com::sun::star::container;
47 using namespace ::com::sun::star::form::binding;
48 using namespace ::com::sun::star::xsd;
49 using namespace ::com::sun::star::lang;
50 using namespace ::com::sun::star::form;
53 //= file-local helpers
55 namespace
58 OUString composeModelElementUIName( const OUString& _rModelName, const OUString& _rElementName )
60 OUString a = "["
61 + _rModelName + "] "
62 + _rElementName;
63 return a;
68 //= EFormsHelper
71 EFormsHelper::EFormsHelper( ::osl::Mutex& _rMutex, const Reference< XPropertySet >& _rxControlModel, const Reference< frame::XModel >& _rxContextDocument )
72 :m_xControlModel( _rxControlModel )
73 ,m_aPropertyListeners( _rMutex )
75 OSL_ENSURE( _rxControlModel.is(), "EFormsHelper::EFormsHelper: invalid control model!" );
76 m_xBindableControl.set(_rxControlModel, css::uno::UNO_QUERY);
78 m_xDocument.set(_rxContextDocument, css::uno::UNO_QUERY);
79 OSL_ENSURE( m_xDocument.is(), "EFormsHelper::EFormsHelper: invalid document!" );
84 bool EFormsHelper::isEForm( const Reference< frame::XModel >& _rxContextDocument )
86 try
88 Reference< xforms::XFormsSupplier > xDocument( _rxContextDocument, UNO_QUERY );
89 if ( !xDocument.is() )
90 return false;
92 return xDocument->getXForms().is();
94 catch( const Exception& )
96 OSL_FAIL( "EFormsHelper::isEForm: caught an exception!" );
98 return false;
102 bool EFormsHelper::canBindToDataType( sal_Int32 _nDataType ) const
104 if ( !m_xBindableControl.is() )
105 // cannot bind at all
106 return false;
108 // some types cannot be bound, independent from the control type
109 if ( ( DataTypeClass::hexBinary == _nDataType )
110 || ( DataTypeClass::base64Binary == _nDataType )
111 || ( DataTypeClass::QName == _nDataType )
112 || ( DataTypeClass::NOTATION == _nDataType )
114 return false;
116 bool bCan = false;
119 // classify the control model
120 sal_Int16 nControlType = FormComponentType::CONTROL;
121 OSL_VERIFY( m_xControlModel->getPropertyValue( PROPERTY_CLASSID ) >>= nControlType );
123 // some lists
124 sal_Int16 const nNumericCompatibleTypes[] = { DataTypeClass::DECIMAL, DataTypeClass::FLOAT, DataTypeClass::DOUBLE, 0 };
125 sal_Int16 const nDateCompatibleTypes[] = { DataTypeClass::DATE, 0 };
126 sal_Int16 const nTimeCompatibleTypes[] = { DataTypeClass::TIME, 0 };
127 sal_Int16 const nCheckboxCompatibleTypes[] = { DataTypeClass::BOOLEAN, DataTypeClass::STRING, DataTypeClass::anyURI, 0 };
128 sal_Int16 const nRadiobuttonCompatibleTypes[] = { DataTypeClass::STRING, DataTypeClass::anyURI, 0 };
129 sal_Int16 const nFormattedCompatibleTypes[] = { DataTypeClass::DECIMAL, DataTypeClass::FLOAT, DataTypeClass::DOUBLE, DataTypeClass::DATETIME, DataTypeClass::DATE, DataTypeClass::TIME, 0 };
131 sal_Int16 const * pCompatibleTypes = nullptr;
132 switch ( nControlType )
134 case FormComponentType::SPINBUTTON:
135 case FormComponentType::NUMERICFIELD:
136 pCompatibleTypes = nNumericCompatibleTypes;
137 break;
138 case FormComponentType::DATEFIELD:
139 pCompatibleTypes = nDateCompatibleTypes;
140 break;
141 case FormComponentType::TIMEFIELD:
142 pCompatibleTypes = nTimeCompatibleTypes;
143 break;
144 case FormComponentType::CHECKBOX:
145 pCompatibleTypes = nCheckboxCompatibleTypes;
146 break;
147 case FormComponentType::RADIOBUTTON:
148 pCompatibleTypes = nRadiobuttonCompatibleTypes;
149 break;
151 case FormComponentType::TEXTFIELD:
153 // both the normal text field, and the formatted field, claim to be a TEXTFIELD
154 // need to distinguish by service name
155 Reference< XServiceInfo > xSI( m_xControlModel, UNO_QUERY );
156 OSL_ENSURE( xSI.is(), "EFormsHelper::canBindToDataType: a control model which has no service info?" );
157 if ( xSI.is() )
159 if ( xSI->supportsService( SERVICE_COMPONENT_FORMATTEDFIELD ) )
161 pCompatibleTypes = nFormattedCompatibleTypes;
162 break;
165 [[fallthrough]];
167 case FormComponentType::LISTBOX:
168 case FormComponentType::COMBOBOX:
169 // edit fields and list/combo boxes can be bound to anything
170 bCan = true;
173 if ( !bCan && pCompatibleTypes )
175 if ( _nDataType == -1 )
177 // the control can be bound to at least one type, and exactly this is being asked for
178 bCan = true;
180 else
182 while ( *pCompatibleTypes && !bCan )
183 bCan = ( *pCompatibleTypes++ == _nDataType );
187 catch( const Exception& )
189 OSL_FAIL( "EFormsHelper::canBindToDataType: caught an exception!" );
192 return bCan;
196 bool EFormsHelper::isListEntrySink() const
198 bool bIs = false;
201 Reference< XListEntrySink > xAsSink( m_xControlModel, UNO_QUERY );
202 bIs = xAsSink.is();
204 catch( const Exception& )
206 OSL_FAIL( "EFormsHelper::isListEntrySink: caught an exception!" );
208 return bIs;
212 void EFormsHelper::impl_switchBindingListening_throw( bool _bDoListening, const Reference< XPropertyChangeListener >& _rxListener )
214 Reference< XPropertySet > xBindingProps;
215 if ( m_xBindableControl.is() )
216 xBindingProps.set(m_xBindableControl->getValueBinding(), css::uno::UNO_QUERY);
217 if ( !xBindingProps.is() )
218 return;
220 if ( _bDoListening )
222 xBindingProps->addPropertyChangeListener( OUString(), _rxListener );
224 else
226 xBindingProps->removePropertyChangeListener( OUString(), _rxListener );
231 void EFormsHelper::registerBindingListener( const Reference< XPropertyChangeListener >& _rxBindingListener )
233 if ( !_rxBindingListener.is() )
234 return;
235 impl_toggleBindingPropertyListening_throw( true, _rxBindingListener );
239 void EFormsHelper::impl_toggleBindingPropertyListening_throw( bool _bDoListen, const Reference< XPropertyChangeListener >& _rxConcreteListenerOrNull )
241 if ( !_bDoListen )
243 std::unique_ptr< ::comphelper::OInterfaceIteratorHelper2 > pListenerIterator = m_aPropertyListeners.createIterator();
244 while ( pListenerIterator->hasMoreElements() )
246 PropertyEventTranslation* pTranslator = dynamic_cast< PropertyEventTranslation* >( pListenerIterator->next() );
247 OSL_ENSURE( pTranslator, "EFormsHelper::impl_toggleBindingPropertyListening_throw: invalid listener element in my container!" );
248 if ( !pTranslator )
249 continue;
251 Reference< XPropertyChangeListener > xEventSourceTranslator( pTranslator );
252 if ( _rxConcreteListenerOrNull.is() )
254 if ( pTranslator->getDelegator() == _rxConcreteListenerOrNull )
256 impl_switchBindingListening_throw( false, xEventSourceTranslator );
257 m_aPropertyListeners.removeListener( xEventSourceTranslator );
258 break;
261 else
263 impl_switchBindingListening_throw( false, xEventSourceTranslator );
267 else
269 if ( _rxConcreteListenerOrNull.is() )
271 Reference< XPropertyChangeListener > xEventSourceTranslator( new PropertyEventTranslation( _rxConcreteListenerOrNull, m_xBindableControl ) );
272 m_aPropertyListeners.addListener( xEventSourceTranslator );
273 impl_switchBindingListening_throw( true, xEventSourceTranslator );
275 else
277 std::unique_ptr< ::comphelper::OInterfaceIteratorHelper2 > pListenerIterator = m_aPropertyListeners.createIterator();
278 while ( pListenerIterator->hasMoreElements() )
280 Reference< XPropertyChangeListener > xListener( pListenerIterator->next(), UNO_QUERY );
281 impl_switchBindingListening_throw( true, xListener );
288 void EFormsHelper::revokeBindingListener( const Reference< XPropertyChangeListener >& _rxBindingListener )
290 impl_toggleBindingPropertyListening_throw( false, _rxBindingListener );
294 void EFormsHelper::getFormModelNames( std::vector< OUString >& /* [out] */ _rModelNames ) const
296 if ( m_xDocument.is() )
300 _rModelNames.resize( 0 );
302 Reference< XNameContainer > xForms( m_xDocument->getXForms() );
303 OSL_ENSURE( xForms.is(), "EFormsHelper::getFormModelNames: invalid forms container!" );
304 if ( xForms.is() )
306 Sequence< OUString > aModelNames = xForms->getElementNames();
307 _rModelNames.resize( aModelNames.getLength() );
308 std::copy( aModelNames.begin(), aModelNames.end(), _rModelNames.begin() );
311 catch( const Exception& )
313 OSL_FAIL( "EFormsHelper::getFormModelNames: caught an exception!" );
319 void EFormsHelper::getBindingNames( const OUString& _rModelName, std::vector< OUString >& /* [out] */ _rBindingNames ) const
321 _rBindingNames.resize( 0 );
324 Reference< xforms::XModel > xModel( getFormModelByName( _rModelName ) );
325 if ( xModel.is() )
327 Reference< XNameAccess > xBindings( xModel->getBindings(), UNO_QUERY );
328 OSL_ENSURE( xBindings.is(), "EFormsHelper::getBindingNames: invalid bindings container obtained from the model!" );
329 if ( xBindings.is() )
331 Sequence< OUString > aNames = xBindings->getElementNames();
332 _rBindingNames.resize( aNames.getLength() );
333 std::copy( aNames.begin(), aNames.end(), _rBindingNames.begin() );
337 catch( const Exception& )
339 OSL_FAIL( "EFormsHelper::getBindingNames: caught an exception!" );
344 Reference< xforms::XModel > EFormsHelper::getFormModelByName( const OUString& _rModelName ) const
346 Reference< xforms::XModel > xReturn;
349 Reference< XNameContainer > xForms( m_xDocument->getXForms() );
350 OSL_ENSURE( xForms.is(), "EFormsHelper::getFormModelByName: invalid forms container!" );
351 if ( xForms.is() )
352 OSL_VERIFY( xForms->getByName( _rModelName ) >>= xReturn );
354 catch( const Exception& )
356 OSL_FAIL( "EFormsHelper::getFormModelByName: caught an exception!" );
358 return xReturn;
362 Reference< xforms::XModel > EFormsHelper::getCurrentFormModel() const
364 Reference< xforms::XModel > xModel;
367 Reference< XPropertySet > xBinding( getCurrentBinding() );
368 if ( xBinding.is() )
370 OSL_VERIFY( xBinding->getPropertyValue( PROPERTY_MODEL ) >>= xModel );
373 catch( const Exception& )
375 OSL_FAIL( "EFormsHelper::getCurrentFormModel: caught an exception!" );
377 return xModel;
381 OUString EFormsHelper::getCurrentFormModelName() const
383 OUString sModelName;
386 Reference< xforms::XModel > xFormsModel( getCurrentFormModel() );
387 if ( xFormsModel.is() )
388 sModelName = xFormsModel->getID();
390 catch( const Exception& )
392 OSL_FAIL( "EFormsHelper::getCurrentFormModel: caught an exception!" );
394 return sModelName;
398 Reference< XPropertySet > EFormsHelper::getCurrentBinding() const
400 Reference< XPropertySet > xBinding;
404 if ( m_xBindableControl.is() )
405 xBinding.set(m_xBindableControl->getValueBinding(), css::uno::UNO_QUERY);
407 catch( const Exception& )
409 OSL_FAIL( "EFormsHelper::getCurrentBinding: caught an exception!" );
412 return xBinding;
416 OUString EFormsHelper::getCurrentBindingName() const
418 OUString sBindingName;
421 Reference< XPropertySet > xBinding( getCurrentBinding() );
422 if ( xBinding.is() )
423 xBinding->getPropertyValue( PROPERTY_BINDING_ID ) >>= sBindingName;
425 catch( const Exception& )
427 OSL_FAIL( "EFormsHelper::getCurrentBindingName: caught an exception!" );
429 return sBindingName;
433 Reference< XListEntrySource > EFormsHelper::getCurrentListSourceBinding() const
435 Reference< XListEntrySource > xReturn;
438 Reference< XListEntrySink > xAsSink( m_xControlModel, UNO_QUERY );
439 OSL_ENSURE( xAsSink.is(), "EFormsHelper::getCurrentListSourceBinding: you should have used isListEntrySink before!" );
440 if ( xAsSink.is() )
441 xReturn = xAsSink->getListEntrySource();
443 catch( const Exception& )
445 OSL_FAIL( "EFormsHelper::getCurrentListSourceBinding: caught an exception!" );
447 return xReturn;
451 void EFormsHelper::setListSourceBinding( const Reference< XListEntrySource >& _rxListSource )
455 Reference< XListEntrySink > xAsSink( m_xControlModel, UNO_QUERY );
456 OSL_ENSURE( xAsSink.is(), "EFormsHelper::setListSourceBinding: you should have used isListEntrySink before!" );
457 if ( xAsSink.is() )
458 xAsSink->setListEntrySource( _rxListSource );
460 catch( const Exception& )
462 OSL_FAIL( "EFormsHelper::setListSourceBinding: caught an exception!" );
467 void EFormsHelper::setBinding( const Reference< css::beans::XPropertySet >& _rxBinding )
469 if ( !m_xBindableControl.is() )
470 return;
474 Reference< XPropertySet > xOldBinding( m_xBindableControl->getValueBinding(), UNO_QUERY );
476 Reference< XValueBinding > xBinding( _rxBinding, UNO_QUERY );
477 OSL_ENSURE( xBinding.is() || !_rxBinding.is(), "EFormsHelper::setBinding: invalid binding!" );
479 impl_toggleBindingPropertyListening_throw( false, nullptr );
480 m_xBindableControl->setValueBinding( xBinding );
481 impl_toggleBindingPropertyListening_throw( true, nullptr );
483 std::set< OUString > aSet;
484 firePropertyChanges( xOldBinding, _rxBinding, aSet );
486 catch( const Exception& )
488 OSL_FAIL( "EFormsHelper::setBinding: caught an exception!" );
493 Reference< XPropertySet > EFormsHelper::getOrCreateBindingForModel( const OUString& _rTargetModel, const OUString& _rBindingName ) const
495 OSL_ENSURE( !_rBindingName.isEmpty(), "EFormsHelper::getOrCreateBindingForModel: invalid binding name!" );
496 return implGetOrCreateBinding( _rTargetModel, _rBindingName );
500 Reference< XPropertySet > EFormsHelper::implGetOrCreateBinding( const OUString& _rTargetModel, const OUString& _rBindingName ) const
502 OSL_ENSURE( !( _rTargetModel.isEmpty() && !_rBindingName.isEmpty() ), "EFormsHelper::implGetOrCreateBinding: no model, but a binding name?" );
504 Reference< XPropertySet > xBinding;
507 OUString sTargetModel( _rTargetModel );
508 // determine the model which the binding should belong to
509 if ( sTargetModel.isEmpty() )
511 std::vector< OUString > aModelNames;
512 getFormModelNames( aModelNames );
513 if ( !aModelNames.empty() )
514 sTargetModel = *aModelNames.begin();
515 OSL_ENSURE( !sTargetModel.isEmpty(), "EFormsHelper::implGetOrCreateBinding: unable to obtain a default model!" );
517 Reference< xforms::XModel > xModel( getFormModelByName( sTargetModel ) );
518 Reference< XNameAccess > xBindingNames( xModel.is() ? xModel->getBindings() : Reference< XSet >(), UNO_QUERY );
519 if ( xBindingNames.is() )
521 // get or create the binding instance
522 if ( !_rBindingName.isEmpty() )
524 if ( xBindingNames->hasByName( _rBindingName ) )
525 OSL_VERIFY( xBindingNames->getByName( _rBindingName ) >>= xBinding );
526 else
528 xBinding = xModel->createBinding( );
529 if ( xBinding.is() )
531 xBinding->setPropertyValue( PROPERTY_BINDING_ID, makeAny( _rBindingName ) );
532 xModel->getBindings()->insert( makeAny( xBinding ) );
536 else
538 xBinding = xModel->createBinding( );
539 if ( xBinding.is() )
541 // find a nice name for it
542 OUString sBaseName(PcrRes(RID_STR_BINDING_NAME) + " ");
543 OUString sNewName;
544 sal_Int32 nNumber = 1;
547 sNewName = sBaseName + OUString::number( nNumber++ );
549 while ( xBindingNames->hasByName( sNewName ) );
550 Reference< XNamed > xName( xBinding, UNO_QUERY_THROW );
551 xName->setName( sNewName );
552 // and insert into the model
553 xModel->getBindings()->insert( makeAny( xBinding ) );
558 catch( const Exception& )
560 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr");
563 return xBinding;
567 namespace
570 struct PropertyBagInserter
572 private:
573 PropertyBag& m_rProperties;
575 public:
576 explicit PropertyBagInserter( PropertyBag& rProperties ) : m_rProperties( rProperties ) { }
578 void operator()( const Property& _rProp )
580 m_rProperties.insert( _rProp );
585 Reference< XPropertySetInfo > collectPropertiesGetInfo( const Reference< XPropertySet >& _rxProps, PropertyBag& _rBag )
587 Reference< XPropertySetInfo > xInfo;
588 if ( _rxProps.is() )
589 xInfo = _rxProps->getPropertySetInfo();
590 if ( xInfo.is() )
592 Sequence< Property > aProperties = xInfo->getProperties();
593 std::for_each( aProperties.begin(), aProperties.end(),
594 PropertyBagInserter( _rBag )
597 return xInfo;
602 OUString EFormsHelper::getModelElementUIName( const EFormsHelper::ModelElementType _eType, const Reference< XPropertySet >& _rxElement )
604 OUString sUIName;
607 // determine the model which the element belongs to
608 Reference< xforms::XFormsUIHelper1 > xHelper;
609 if ( _rxElement.is() )
610 _rxElement->getPropertyValue( PROPERTY_MODEL ) >>= xHelper;
611 OSL_ENSURE( xHelper.is(), "EFormsHelper::getModelElementUIName: invalid element or model!" );
612 if ( xHelper.is() )
614 OUString sElementName = ( _eType == Submission ) ? xHelper->getSubmissionName( _rxElement, true ) : xHelper->getBindingName( _rxElement, true );
615 Reference< xforms::XModel > xModel( xHelper, UNO_QUERY_THROW );
616 sUIName = composeModelElementUIName( xModel->getID(), sElementName );
619 catch( const Exception& )
621 OSL_FAIL( "EFormsHelper::getModelElementUIName: caught an exception!" );
624 return sUIName;
628 Reference< XPropertySet > EFormsHelper::getModelElementFromUIName( const EFormsHelper::ModelElementType _eType, const OUString& _rUIName ) const
630 const MapStringToPropertySet& rMapUINameToElement( ( _eType == Submission ) ? m_aSubmissionUINames : m_aBindingUINames );
631 MapStringToPropertySet::const_iterator pos = rMapUINameToElement.find( _rUIName );
632 OSL_ENSURE( pos != rMapUINameToElement.end(), "EFormsHelper::getModelElementFromUIName: didn't find it!" );
634 return ( pos != rMapUINameToElement.end() ) ? pos->second : Reference< XPropertySet >();
638 void EFormsHelper::getAllElementUINames( const ModelElementType _eType, std::vector< OUString >& /* [out] */ _rElementNames, bool _bPrepentEmptyEntry )
640 MapStringToPropertySet& rMapUINameToElement( ( _eType == Submission ) ? m_aSubmissionUINames : m_aBindingUINames );
641 rMapUINameToElement.clear();
642 _rElementNames.resize( 0 );
644 if ( _bPrepentEmptyEntry )
645 rMapUINameToElement[ OUString() ].clear();
649 // obtain the model names
650 std::vector< OUString > aModels;
651 getFormModelNames( aModels );
652 _rElementNames.reserve( aModels.size() * 2 ); // heuristics
654 // for every model, obtain the element
655 for (auto const& modelName : aModels)
657 Reference< xforms::XModel > xModel = getFormModelByName(modelName);
658 OSL_ENSURE( xModel.is(), "EFormsHelper::getAllElementUINames: inconsistency in the models!" );
659 Reference< xforms::XFormsUIHelper1 > xHelper( xModel, UNO_QUERY );
661 Reference< XIndexAccess > xElements;
662 if ( xModel.is() )
663 xElements.set(( _eType == Submission ) ? xModel->getSubmissions() : xModel->getBindings(), css::uno::UNO_QUERY);
664 if ( !xElements.is() )
665 break;
667 sal_Int32 nElementCount = xElements->getCount();
668 for ( sal_Int32 i = 0; i < nElementCount; ++i )
670 Reference< XPropertySet > xElement( xElements->getByIndex( i ), UNO_QUERY );
671 OSL_ENSURE( xElement.is(), "EFormsHelper::getAllElementUINames: empty element!" );
672 if ( !xElement.is() )
673 continue;
674 #if OSL_DEBUG_LEVEL > 0
676 Reference< xforms::XModel > xElementsModel;
677 xElement->getPropertyValue( PROPERTY_MODEL ) >>= xElementsModel;
678 OSL_ENSURE( xElementsModel == xModel, "EFormsHelper::getAllElementUINames: inconsistency in the model-element relationship!" );
679 if ( xElementsModel != xModel )
680 xElement->setPropertyValue( PROPERTY_MODEL, makeAny( xModel ) );
682 #endif
683 OUString sElementName = ( _eType == Submission ) ? xHelper->getSubmissionName( xElement, true ) : xHelper->getBindingName( xElement, true );
684 OUString sUIName = composeModelElementUIName( modelName, sElementName );
686 OSL_ENSURE( rMapUINameToElement.find( sUIName ) == rMapUINameToElement.end(), "EFormsHelper::getAllElementUINames: duplicate name!" );
687 rMapUINameToElement.emplace( sUIName, xElement );
691 catch( const Exception& )
693 OSL_FAIL( "EFormsHelper::getAllElementUINames: caught an exception!" );
696 _rElementNames.resize( rMapUINameToElement.size() );
697 std::transform( rMapUINameToElement.begin(), rMapUINameToElement.end(), _rElementNames.begin(),
698 ::o3tl::select1st< MapStringToPropertySet::value_type >() );
702 void EFormsHelper::firePropertyChange( const OUString& _rName, const Any& _rOldValue, const Any& _rNewValue ) const
704 if ( m_aPropertyListeners.empty() )
705 return;
707 if ( _rOldValue == _rNewValue )
708 return;
712 PropertyChangeEvent aEvent;
714 aEvent.Source = m_xBindableControl.get();
715 aEvent.PropertyName = _rName;
716 aEvent.OldValue = _rOldValue;
717 aEvent.NewValue = _rNewValue;
719 const_cast< EFormsHelper* >( this )->m_aPropertyListeners.notify( aEvent, &XPropertyChangeListener::propertyChange );
721 catch( const Exception& )
723 OSL_FAIL( "EFormsHelper::firePropertyChange: caught an exception!" );
728 void EFormsHelper::firePropertyChanges( const Reference< XPropertySet >& _rxOldProps, const Reference< XPropertySet >& _rxNewProps, std::set< OUString >& _rFilter ) const
730 if ( m_aPropertyListeners.empty() )
731 return;
735 PropertyBag aProperties;
736 Reference< XPropertySetInfo > xOldInfo = collectPropertiesGetInfo( _rxOldProps, aProperties );
737 Reference< XPropertySetInfo > xNewInfo = collectPropertiesGetInfo( _rxNewProps, aProperties );
739 for (auto const& property : aProperties)
741 if ( _rFilter.find( property.Name ) != _rFilter.end() )
742 continue;
744 Any aOldValue( nullptr, property.Type );
745 if ( xOldInfo.is() && xOldInfo->hasPropertyByName( property.Name ) )
746 aOldValue = _rxOldProps->getPropertyValue( property.Name );
748 Any aNewValue( nullptr, property.Type );
749 if ( xNewInfo.is() && xNewInfo->hasPropertyByName( property.Name ) )
750 aNewValue = _rxNewProps->getPropertyValue( property.Name );
752 firePropertyChange( property.Name, aOldValue, aNewValue );
755 catch( const Exception& )
757 OSL_FAIL( "EFormsHelper::firePropertyChanges: caught an exception!" );
762 } // namespace pcr
765 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */