Bump for 3.6-28
[LibreOffice.git] / extensions / source / propctrlr / eformshelper.cxx
blobdb5155b36d7fbda1cac2e64befae314a4f8b4033
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "eformshelper.hxx"
30 #include "formstrings.hxx"
31 #include "formresid.hrc"
32 #include "modulepcr.hxx"
33 #include "propeventtranslation.hxx"
34 #include "formbrowsertools.hxx"
36 /** === begin UNO includes === **/
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/form/FormComponentType.hpp>
39 #include <com/sun/star/xforms/XFormsUIHelper1.hpp>
40 #include <com/sun/star/xsd/DataTypeClass.hpp>
41 #include <com/sun/star/form/binding/XListEntrySink.hpp>
42 /** === end UNO includes === **/
43 #include <tools/diagnose_ex.h>
44 #include <rtl/ustrbuf.hxx>
46 #include <functional>
47 #include <algorithm>
48 #include <o3tl/compat_functional.hxx>
50 //........................................................................
51 namespace pcr
53 //........................................................................
55 using namespace ::com::sun::star;
56 using namespace ::com::sun::star::uno;
57 using namespace ::com::sun::star::beans;
58 using namespace ::com::sun::star::container;
59 using namespace ::com::sun::star::form::binding;
60 using namespace ::com::sun::star::xsd;
61 using namespace ::com::sun::star::lang;
62 using namespace ::com::sun::star::form;
64 //====================================================================
65 //= file-local helpers
66 //====================================================================
67 namespace
69 //--------------------------------------------------------------------
70 ::rtl::OUString composeModelElementUIName( const ::rtl::OUString& _rModelName, const ::rtl::OUString& _rElementName )
72 ::rtl::OUStringBuffer aBuffer;
73 aBuffer.appendAscii( "[" );
74 aBuffer.append( _rModelName );
75 aBuffer.appendAscii( "] " );
76 aBuffer.append( _rElementName );
77 return aBuffer.makeStringAndClear();
81 //====================================================================
82 //= EFormsHelper
83 //====================================================================
84 //--------------------------------------------------------------------
85 EFormsHelper::EFormsHelper( ::osl::Mutex& _rMutex, const Reference< XPropertySet >& _rxControlModel, const Reference< frame::XModel >& _rxContextDocument )
86 :m_xControlModel( _rxControlModel )
87 ,m_aPropertyListeners( _rMutex )
89 OSL_ENSURE( _rxControlModel.is(), "EFormsHelper::EFormsHelper: invalid control model!" );
90 m_xBindableControl = m_xBindableControl.query( _rxControlModel );
92 m_xDocument = m_xDocument.query( _rxContextDocument );
93 OSL_ENSURE( m_xDocument.is(), "EFormsHelper::EFormsHelper: invalid document!" );
97 //--------------------------------------------------------------------
98 bool EFormsHelper::isEForm( const Reference< frame::XModel >& _rxContextDocument )
102 Reference< xforms::XFormsSupplier > xDocument( _rxContextDocument, UNO_QUERY );
103 if ( !xDocument.is() )
104 return false;
106 return xDocument->getXForms().is();
108 catch( const Exception& )
110 OSL_FAIL( "EFormsHelper::isEForm: caught an exception!" );
112 return false;
115 //--------------------------------------------------------------------
116 bool EFormsHelper::canBindToDataType( sal_Int32 _nDataType ) const SAL_THROW(())
118 if ( !m_xBindableControl.is() )
119 // cannot bind at all
120 return false;
122 // some types cannot be bound, independent from the control type
123 if ( ( DataTypeClass::hexBinary == _nDataType )
124 || ( DataTypeClass::base64Binary == _nDataType )
125 || ( DataTypeClass::QName == _nDataType )
126 || ( DataTypeClass::NOTATION == _nDataType )
128 return false;
130 bool bCan = false;
133 // classify the control model
134 sal_Int16 nControlType = FormComponentType::CONTROL;
135 OSL_VERIFY( m_xControlModel->getPropertyValue( PROPERTY_CLASSID ) >>= nControlType );
137 // some lists
138 sal_Int16 nNumericCompatibleTypes[] = { DataTypeClass::DECIMAL, DataTypeClass::FLOAT, DataTypeClass::DOUBLE, 0 };
139 sal_Int16 nDateCompatibleTypes[] = { DataTypeClass::DATE, 0 };
140 sal_Int16 nTimeCompatibleTypes[] = { DataTypeClass::TIME, 0 };
141 sal_Int16 nCheckboxCompatibleTypes[] = { DataTypeClass::BOOLEAN, DataTypeClass::STRING, DataTypeClass::anyURI, 0 };
142 sal_Int16 nRadiobuttonCompatibleTypes[] = { DataTypeClass::STRING, DataTypeClass::anyURI, 0 };
143 sal_Int16 nFormattedCompatibleTypes[] = { DataTypeClass::DECIMAL, DataTypeClass::FLOAT, DataTypeClass::DOUBLE, DataTypeClass::DATETIME, DataTypeClass::DATE, DataTypeClass::TIME, 0 };
145 sal_Int16* pCompatibleTypes = NULL;
146 switch ( nControlType )
148 case FormComponentType::SPINBUTTON:
149 case FormComponentType::NUMERICFIELD:
150 pCompatibleTypes = nNumericCompatibleTypes;
151 break;
152 case FormComponentType::DATEFIELD:
153 pCompatibleTypes = nDateCompatibleTypes;
154 break;
155 case FormComponentType::TIMEFIELD:
156 pCompatibleTypes = nTimeCompatibleTypes;
157 break;
158 case FormComponentType::CHECKBOX:
159 pCompatibleTypes = nCheckboxCompatibleTypes;
160 break;
161 case FormComponentType::RADIOBUTTON:
162 pCompatibleTypes = nRadiobuttonCompatibleTypes;
163 break;
165 case FormComponentType::TEXTFIELD:
167 // both the normal text field, and the formatted field, claim to be a TEXTFIELD
168 // need to distinguish by service name
169 Reference< XServiceInfo > xSI( m_xControlModel, UNO_QUERY );
170 OSL_ENSURE( xSI.is(), "EFormsHelper::canBindToDataType: a control model which has no service info?" );
171 if ( xSI.is() )
173 if ( xSI->supportsService( SERVICE_COMPONENT_FORMATTEDFIELD ) )
175 pCompatibleTypes = nFormattedCompatibleTypes;
176 break;
179 // NO break here!
181 case FormComponentType::LISTBOX:
182 case FormComponentType::COMBOBOX:
183 // edit fields and list/combo boxes can be bound to anything
184 bCan = true;
187 if ( !bCan && pCompatibleTypes )
189 if ( _nDataType == -1 )
191 // the control can be bound to at least one type, and exactly this is being asked for
192 bCan = true;
194 else
196 while ( *pCompatibleTypes && !bCan )
197 bCan = ( *pCompatibleTypes++ == _nDataType );
201 catch( const Exception& )
203 OSL_FAIL( "EFormsHelper::canBindToDataType: caught an exception!" );
206 return bCan;
209 //--------------------------------------------------------------------
210 bool EFormsHelper::isListEntrySink() const SAL_THROW(())
212 bool bIs = false;
215 Reference< XListEntrySink > xAsSink( m_xControlModel, UNO_QUERY );
216 bIs = xAsSink.is();
218 catch( const Exception& )
220 OSL_FAIL( "EFormsHelper::isListEntrySink: caught an exception!" );
222 return bIs;
225 //--------------------------------------------------------------------
226 void EFormsHelper::impl_switchBindingListening_throw( bool _bDoListening, const Reference< XPropertyChangeListener >& _rxListener )
228 Reference< XPropertySet > xBindingProps;
229 if ( m_xBindableControl.is() )
230 xBindingProps = xBindingProps.query( m_xBindableControl->getValueBinding() );
231 if ( !xBindingProps.is() )
232 return;
234 if ( _bDoListening )
236 xBindingProps->addPropertyChangeListener( ::rtl::OUString(), _rxListener );
238 else
240 xBindingProps->removePropertyChangeListener( ::rtl::OUString(), _rxListener );
244 //--------------------------------------------------------------------
245 void EFormsHelper::registerBindingListener( const Reference< XPropertyChangeListener >& _rxBindingListener )
247 if ( !_rxBindingListener.is() )
248 return;
249 impl_toggleBindingPropertyListening_throw( true, _rxBindingListener );
252 //--------------------------------------------------------------------
253 void EFormsHelper::impl_toggleBindingPropertyListening_throw( bool _bDoListen, const Reference< XPropertyChangeListener >& _rxConcreteListenerOrNull )
255 if ( !_bDoListen )
257 SAL_WNODEPRECATED_DECLARATIONS_PUSH
258 ::std::auto_ptr< ::cppu::OInterfaceIteratorHelper > pListenerIterator = m_aPropertyListeners.createIterator();
259 SAL_WNODEPRECATED_DECLARATIONS_POP
260 while ( pListenerIterator->hasMoreElements() )
262 PropertyEventTranslation* pTranslator = dynamic_cast< PropertyEventTranslation* >( pListenerIterator->next() );
263 OSL_ENSURE( pTranslator, "EFormsHelper::impl_toggleBindingPropertyListening_throw: invalid listener element in my container!" );
264 if ( !pTranslator )
265 continue;
267 Reference< XPropertyChangeListener > xEventSourceTranslator( pTranslator );
268 if ( _rxConcreteListenerOrNull.is() )
270 if ( pTranslator->getDelegator() == _rxConcreteListenerOrNull )
272 impl_switchBindingListening_throw( false, xEventSourceTranslator );
273 m_aPropertyListeners.removeListener( xEventSourceTranslator );
274 break;
277 else
279 impl_switchBindingListening_throw( false, xEventSourceTranslator );
283 else
285 if ( _rxConcreteListenerOrNull.is() )
287 Reference< XPropertyChangeListener > xEventSourceTranslator( new PropertyEventTranslation( _rxConcreteListenerOrNull, m_xBindableControl ) );
288 m_aPropertyListeners.addListener( xEventSourceTranslator );
289 impl_switchBindingListening_throw( true, xEventSourceTranslator );
291 else
293 SAL_WNODEPRECATED_DECLARATIONS_PUSH
294 ::std::auto_ptr< ::cppu::OInterfaceIteratorHelper > pListenerIterator = m_aPropertyListeners.createIterator();
295 SAL_WNODEPRECATED_DECLARATIONS_POP
296 while ( pListenerIterator->hasMoreElements() )
298 Reference< XPropertyChangeListener > xListener( pListenerIterator->next(), UNO_QUERY );
299 impl_switchBindingListening_throw( true, xListener );
305 //--------------------------------------------------------------------
306 void EFormsHelper::revokeBindingListener( const Reference< XPropertyChangeListener >& _rxBindingListener )
308 impl_toggleBindingPropertyListening_throw( false, _rxBindingListener );
311 //--------------------------------------------------------------------
312 void EFormsHelper::getFormModelNames( ::std::vector< ::rtl::OUString >& /* [out] */ _rModelNames ) const SAL_THROW(())
314 if ( m_xDocument.is() )
318 _rModelNames.resize( 0 );
320 Reference< XNameContainer > xForms( m_xDocument->getXForms() );
321 OSL_ENSURE( xForms.is(), "EFormsHelper::getFormModelNames: invalid forms container!" );
322 if ( xForms.is() )
324 Sequence< ::rtl::OUString > aModelNames = xForms->getElementNames();
325 _rModelNames.resize( aModelNames.getLength() );
326 ::std::copy( aModelNames.getConstArray(), aModelNames.getConstArray() + aModelNames.getLength(),
327 _rModelNames.begin()
331 catch( const Exception& )
333 OSL_FAIL( "EFormsHelper::getFormModelNames: caught an exception!" );
338 //--------------------------------------------------------------------
339 void EFormsHelper::getBindingNames( const ::rtl::OUString& _rModelName, ::std::vector< ::rtl::OUString >& /* [out] */ _rBindingNames ) const SAL_THROW(())
341 _rBindingNames.resize( 0 );
344 Reference< xforms::XModel > xModel( getFormModelByName( _rModelName ) );
345 if ( xModel.is() )
347 Reference< XNameAccess > xBindings( xModel->getBindings(), UNO_QUERY );
348 OSL_ENSURE( xBindings.is(), "EFormsHelper::getBindingNames: invalid bindings container obtained from the model!" );
349 if ( xBindings.is() )
351 Sequence< ::rtl::OUString > aNames = xBindings->getElementNames();
352 _rBindingNames.resize( aNames.getLength() );
353 ::std::copy( aNames.getConstArray(), aNames.getConstArray() + aNames.getLength(), _rBindingNames.begin() );
357 catch( const Exception& )
359 OSL_FAIL( "EFormsHelper::getBindingNames: caught an exception!" );
363 //--------------------------------------------------------------------
364 Reference< xforms::XModel > EFormsHelper::getFormModelByName( const ::rtl::OUString& _rModelName ) const SAL_THROW(())
366 Reference< xforms::XModel > xReturn;
369 Reference< XNameContainer > xForms( m_xDocument->getXForms() );
370 OSL_ENSURE( xForms.is(), "EFormsHelper::getFormModelByName: invalid forms container!" );
371 if ( xForms.is() )
372 OSL_VERIFY( xForms->getByName( _rModelName ) >>= xReturn );
374 catch( const Exception& )
376 OSL_FAIL( "EFormsHelper::getFormModelByName: caught an exception!" );
378 return xReturn;
381 //--------------------------------------------------------------------
382 Reference< xforms::XModel > EFormsHelper::getCurrentFormModel() const SAL_THROW(())
384 Reference< xforms::XModel > xModel;
387 Reference< XPropertySet > xBinding( getCurrentBinding() );
388 if ( xBinding.is() )
390 OSL_VERIFY( xBinding->getPropertyValue( PROPERTY_MODEL ) >>= xModel );
393 catch( const Exception& )
395 OSL_FAIL( "EFormsHelper::getCurrentFormModel: caught an exception!" );
397 return xModel;
400 //--------------------------------------------------------------------
401 ::rtl::OUString EFormsHelper::getCurrentFormModelName() const SAL_THROW(())
403 ::rtl::OUString sModelName;
406 Reference< xforms::XModel > xFormsModel( getCurrentFormModel() );
407 if ( xFormsModel.is() )
408 sModelName = xFormsModel->getID();
410 catch( const Exception& )
412 OSL_FAIL( "EFormsHelper::getCurrentFormModel: caught an exception!" );
414 return sModelName;
417 //--------------------------------------------------------------------
418 Reference< XPropertySet > EFormsHelper::getCurrentBinding() const SAL_THROW(())
420 Reference< XPropertySet > xBinding;
424 if ( m_xBindableControl.is() )
425 xBinding = xBinding.query( m_xBindableControl->getValueBinding() );
427 catch( const Exception& )
429 OSL_FAIL( "EFormsHelper::getCurrentBinding: caught an exception!" );
432 return xBinding;
435 //--------------------------------------------------------------------
436 ::rtl::OUString EFormsHelper::getCurrentBindingName() const SAL_THROW(())
438 ::rtl::OUString sBindingName;
441 Reference< XPropertySet > xBinding( getCurrentBinding() );
442 if ( xBinding.is() )
443 xBinding->getPropertyValue( PROPERTY_BINDING_ID ) >>= sBindingName;
445 catch( const Exception& )
447 OSL_FAIL( "EFormsHelper::getCurrentBindingName: caught an exception!" );
449 return sBindingName;
452 //--------------------------------------------------------------------
453 Reference< XListEntrySource > EFormsHelper::getCurrentListSourceBinding() const SAL_THROW(())
455 Reference< XListEntrySource > xReturn;
458 Reference< XListEntrySink > xAsSink( m_xControlModel, UNO_QUERY );
459 OSL_ENSURE( xAsSink.is(), "EFormsHelper::getCurrentListSourceBinding: you should have used isListEntrySink before!" );
460 if ( xAsSink.is() )
461 xReturn = xAsSink->getListEntrySource();
463 catch( const Exception& )
465 OSL_FAIL( "EFormsHelper::getCurrentListSourceBinding: caught an exception!" );
467 return xReturn;
470 //--------------------------------------------------------------------
471 void EFormsHelper::setListSourceBinding( const Reference< XListEntrySource >& _rxListSource ) SAL_THROW(())
475 Reference< XListEntrySink > xAsSink( m_xControlModel, UNO_QUERY );
476 OSL_ENSURE( xAsSink.is(), "EFormsHelper::setListSourceBinding: you should have used isListEntrySink before!" );
477 if ( xAsSink.is() )
478 xAsSink->setListEntrySource( _rxListSource );
480 catch( const Exception& )
482 OSL_FAIL( "EFormsHelper::setListSourceBinding: caught an exception!" );
486 //--------------------------------------------------------------------
487 void EFormsHelper::setBinding( const Reference< ::com::sun::star::beans::XPropertySet >& _rxBinding ) SAL_THROW(())
489 if ( !m_xBindableControl.is() )
490 return;
494 Reference< XPropertySet > xOldBinding( m_xBindableControl->getValueBinding(), UNO_QUERY );
496 Reference< XValueBinding > xBinding( _rxBinding, UNO_QUERY );
497 OSL_ENSURE( xBinding.is() || !_rxBinding.is(), "EFormsHelper::setBinding: invalid binding!" );
499 impl_toggleBindingPropertyListening_throw( false, NULL );
500 m_xBindableControl->setValueBinding( xBinding );
501 impl_toggleBindingPropertyListening_throw( true, NULL );
503 ::std::set< ::rtl::OUString > aSet;
504 firePropertyChanges( xOldBinding, _rxBinding, aSet );
506 catch( const Exception& )
508 OSL_FAIL( "EFormsHelper::setBinding: caught an exception!" );
512 //--------------------------------------------------------------------
513 Reference< XPropertySet > EFormsHelper::getOrCreateBindingForModel( const ::rtl::OUString& _rTargetModel, const ::rtl::OUString& _rBindingName ) const SAL_THROW(())
515 OSL_ENSURE( !_rBindingName.isEmpty(), "EFormsHelper::getOrCreateBindingForModel: invalid binding name!" );
516 return implGetOrCreateBinding( _rTargetModel, _rBindingName );
519 //--------------------------------------------------------------------
520 Reference< XPropertySet > EFormsHelper::implGetOrCreateBinding( const ::rtl::OUString& _rTargetModel, const ::rtl::OUString& _rBindingName ) const SAL_THROW(())
522 OSL_ENSURE( !( _rTargetModel.isEmpty() && !_rBindingName.isEmpty() ), "EFormsHelper::implGetOrCreateBinding: no model, but a binding name?" );
524 Reference< XPropertySet > xBinding;
527 ::rtl::OUString sTargetModel( _rTargetModel );
528 // determine the model which the binding should belong to
529 if ( sTargetModel.isEmpty() )
531 ::std::vector< ::rtl::OUString > aModelNames;
532 getFormModelNames( aModelNames );
533 if ( !aModelNames.empty() )
534 sTargetModel = *aModelNames.begin();
535 OSL_ENSURE( !sTargetModel.isEmpty(), "EFormsHelper::implGetOrCreateBinding: unable to obtain a default model!" );
537 Reference< xforms::XModel > xModel( getFormModelByName( sTargetModel ) );
538 Reference< XNameAccess > xBindingNames( xModel.is() ? xModel->getBindings() : Reference< XSet >(), UNO_QUERY );
539 if ( xBindingNames.is() )
541 // get or create the binding instance
542 if ( !_rBindingName.isEmpty() )
544 if ( xBindingNames->hasByName( _rBindingName ) )
545 OSL_VERIFY( xBindingNames->getByName( _rBindingName ) >>= xBinding );
546 else
548 xBinding = xModel->createBinding( );
549 if ( xBinding.is() )
551 xBinding->setPropertyValue( PROPERTY_BINDING_ID, makeAny( _rBindingName ) );
552 xModel->getBindings()->insert( makeAny( xBinding ) );
556 else
558 xBinding = xModel->createBinding( );
559 if ( xBinding.is() )
561 // find a nice name for it
562 String sBaseName( PcrRes( RID_STR_BINDING_UI_NAME ) );
563 sBaseName += String::CreateFromAscii( " " );
564 String sNewName;
565 sal_Int32 nNumber = 1;
568 sNewName = sBaseName + ::rtl::OUString::valueOf( nNumber++ );
570 while ( xBindingNames->hasByName( sNewName ) );
571 Reference< XNamed > xName( xBinding, UNO_QUERY_THROW );
572 xName->setName( sNewName );
573 // and insert into the model
574 xModel->getBindings()->insert( makeAny( xBinding ) );
579 catch( const Exception& )
581 DBG_UNHANDLED_EXCEPTION();
584 return xBinding;
587 //--------------------------------------------------------------------
588 namespace
590 //................................................................
591 struct PropertyBagInserter : public ::std::unary_function< Property, void >
593 private:
594 PropertyBag& m_rProperties;
596 public:
597 PropertyBagInserter( PropertyBag& rProperties ) : m_rProperties( rProperties ) { }
599 void operator()( const Property& _rProp )
601 m_rProperties.insert( _rProp );
605 //................................................................
606 Reference< XPropertySetInfo > collectPropertiesGetInfo( const Reference< XPropertySet >& _rxProps, PropertyBag& _rBag )
608 Reference< XPropertySetInfo > xInfo;
609 if ( _rxProps.is() )
610 xInfo = _rxProps->getPropertySetInfo();
611 if ( xInfo.is() )
613 Sequence< Property > aProperties = xInfo->getProperties();
614 ::std::for_each( aProperties.getConstArray(), aProperties.getConstArray() + aProperties.getLength(),
615 PropertyBagInserter( _rBag )
618 return xInfo;
622 //--------------------------------------------------------------------
623 ::rtl::OUString EFormsHelper::getModelElementUIName( const EFormsHelper::ModelElementType _eType, const Reference< XPropertySet >& _rxElement ) const SAL_THROW(())
625 ::rtl::OUString sUIName;
628 // determine the model which the element belongs to
629 Reference< xforms::XFormsUIHelper1 > xHelper;
630 if ( _rxElement.is() )
631 _rxElement->getPropertyValue( PROPERTY_MODEL ) >>= xHelper;
632 OSL_ENSURE( xHelper.is(), "EFormsHelper::getModelElementUIName: invalid element or model!" );
633 if ( xHelper.is() )
635 ::rtl::OUString sElementName = ( _eType == Submission ) ? xHelper->getSubmissionName( _rxElement, sal_True ) : xHelper->getBindingName( _rxElement, sal_True );
636 Reference< xforms::XModel > xModel( xHelper, UNO_QUERY_THROW );
637 sUIName = composeModelElementUIName( xModel->getID(), sElementName );
640 catch( const Exception& )
642 OSL_FAIL( "EFormsHelper::getModelElementUIName: caught an exception!" );
645 return sUIName;
648 //--------------------------------------------------------------------
649 Reference< XPropertySet > EFormsHelper::getModelElementFromUIName( const EFormsHelper::ModelElementType _eType, const ::rtl::OUString& _rUIName ) const SAL_THROW(())
651 const MapStringToPropertySet& rMapUINameToElement( ( _eType == Submission ) ? m_aSubmissionUINames : m_aBindingUINames );
652 MapStringToPropertySet::const_iterator pos = rMapUINameToElement.find( _rUIName );
653 OSL_ENSURE( pos != rMapUINameToElement.end(), "EFormsHelper::getModelElementFromUIName: didn't find it!" );
655 return ( pos != rMapUINameToElement.end() ) ? pos->second : Reference< XPropertySet >();
658 //--------------------------------------------------------------------
659 void EFormsHelper::getAllElementUINames( const ModelElementType _eType, ::std::vector< ::rtl::OUString >& /* [out] */ _rElementNames, bool _bPrepentEmptyEntry )
661 MapStringToPropertySet& rMapUINameToElement( ( _eType == Submission ) ? m_aSubmissionUINames : m_aBindingUINames );
662 rMapUINameToElement.clear();
663 _rElementNames.resize( 0 );
665 if ( _bPrepentEmptyEntry )
666 rMapUINameToElement[ ::rtl::OUString() ] = Reference< XPropertySet >();
670 // obtain the model names
671 ::std::vector< ::rtl::OUString > aModels;
672 getFormModelNames( aModels );
673 _rElementNames.reserve( aModels.size() * 2 ); // heuristics
675 // for every model, obtain the element
676 for ( ::std::vector< ::rtl::OUString >::const_iterator pModelName = aModels.begin();
677 pModelName != aModels.end();
678 ++pModelName
681 Reference< xforms::XModel > xModel = getFormModelByName( *pModelName );
682 OSL_ENSURE( xModel.is(), "EFormsHelper::getAllElementUINames: inconsistency in the models!" );
683 Reference< xforms::XFormsUIHelper1 > xHelper( xModel, UNO_QUERY );
685 Reference< XIndexAccess > xElements;
686 if ( xModel.is() )
687 xElements = xElements.query( ( _eType == Submission ) ? xModel->getSubmissions() : xModel->getBindings() );
688 if ( !xElements.is() )
689 break;
691 sal_Int32 nElementCount = xElements->getCount();
692 for ( sal_Int32 i = 0; i < nElementCount; ++i )
694 Reference< XPropertySet > xElement( xElements->getByIndex( i ), UNO_QUERY );
695 OSL_ENSURE( xElement.is(), "EFormsHelper::getAllElementUINames: empty element!" );
696 if ( !xElement.is() )
697 continue;
698 #if OSL_DEBUG_LEVEL > 0
700 Reference< xforms::XModel > xElementsModel;
701 xElement->getPropertyValue( PROPERTY_MODEL ) >>= xElementsModel;
702 OSL_ENSURE( xElementsModel == xModel, "EFormsHelper::getAllElementUINames: inconsistency in the model-element relationship!" );
703 if ( !( xElementsModel == xModel ) )
704 xElement->setPropertyValue( PROPERTY_MODEL, makeAny( xModel ) );
706 #endif
707 ::rtl::OUString sElementName = ( _eType == Submission ) ? xHelper->getSubmissionName( xElement, sal_True ) : xHelper->getBindingName( xElement, sal_True );
708 ::rtl::OUString sUIName = composeModelElementUIName( *pModelName, sElementName );
710 OSL_ENSURE( rMapUINameToElement.find( sUIName ) == rMapUINameToElement.end(), "EFormsHelper::getAllElementUINames: duplicate name!" );
711 rMapUINameToElement.insert( MapStringToPropertySet::value_type( sUIName, xElement ) );
715 catch( const Exception& )
717 OSL_FAIL( "EFormsHelper::getAllElementUINames: caught an exception!" );
720 _rElementNames.resize( rMapUINameToElement.size() );
721 ::std::transform( rMapUINameToElement.begin(), rMapUINameToElement.end(), _rElementNames.begin(), ::o3tl::select1st< MapStringToPropertySet::value_type >() );
724 //--------------------------------------------------------------------
725 void EFormsHelper::firePropertyChange( const ::rtl::OUString& _rName, const Any& _rOldValue, const Any& _rNewValue ) const
727 if ( m_aPropertyListeners.empty() )
728 return;
730 if ( _rOldValue == _rNewValue )
731 return;
735 PropertyChangeEvent aEvent;
737 aEvent.Source = m_xBindableControl.get();
738 aEvent.PropertyName = _rName;
739 aEvent.OldValue = _rOldValue;
740 aEvent.NewValue = _rNewValue;
742 const_cast< EFormsHelper* >( this )->m_aPropertyListeners.notify( aEvent, &XPropertyChangeListener::propertyChange );
744 catch( const Exception& )
746 OSL_FAIL( "EFormsHelper::firePropertyChange: caught an exception!" );
750 //--------------------------------------------------------------------
751 void EFormsHelper::firePropertyChanges( const Reference< XPropertySet >& _rxOldProps, const Reference< XPropertySet >& _rxNewProps, ::std::set< ::rtl::OUString >& _rFilter ) const
753 if ( m_aPropertyListeners.empty() )
754 return;
758 PropertyBag aProperties;
759 Reference< XPropertySetInfo > xOldInfo = collectPropertiesGetInfo( _rxOldProps, aProperties );
760 Reference< XPropertySetInfo > xNewInfo = collectPropertiesGetInfo( _rxNewProps, aProperties );
762 for ( PropertyBag::const_iterator aProp = aProperties.begin();
763 aProp != aProperties.end();
764 ++aProp
767 if ( _rFilter.find( aProp->Name ) != _rFilter.end() )
768 continue;
770 Any aOldValue( NULL, aProp->Type );
771 if ( xOldInfo.is() && xOldInfo->hasPropertyByName( aProp->Name ) )
772 aOldValue = _rxOldProps->getPropertyValue( aProp->Name );
774 Any aNewValue( NULL, aProp->Type );
775 if ( xNewInfo.is() && xNewInfo->hasPropertyByName( aProp->Name ) )
776 aNewValue = _rxNewProps->getPropertyValue( aProp->Name );
778 firePropertyChange( aProp->Name, aOldValue, aNewValue );
781 catch( const Exception& )
783 OSL_FAIL( "EFormsHelper::firePropertyChanges: caught an exception!" );
787 //........................................................................
788 } // namespace pcr
789 //........................................................................
791 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */