1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: eformshelper.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "eformshelper.hxx"
34 #include "formstrings.hxx"
35 #ifndef _EXTENSIONS_FORMCTRLR_PROPRESID_HRC_
36 #include "formresid.hrc"
38 #ifndef _EXTENSIONS_PROPCTRLR_MODULEPRC_HXX_
39 #include "modulepcr.hxx"
41 #include "propeventtranslation.hxx"
42 #include "formbrowsertools.hxx"
44 /** === begin UNO includes === **/
45 #include <com/sun/star/lang/XServiceInfo.hpp>
46 #include <com/sun/star/form/FormComponentType.hpp>
47 #include <com/sun/star/xforms/XFormsUIHelper1.hpp>
48 #include <com/sun/star/xsd/DataTypeClass.hpp>
49 #include <com/sun/star/form/binding/XListEntrySink.hpp>
50 /** === end UNO includes === **/
51 #include <tools/diagnose_ex.h>
52 #include <rtl/ustrbuf.hxx>
57 //........................................................................
60 //........................................................................
62 using namespace ::com::sun::star
;
63 using namespace ::com::sun::star::uno
;
64 using namespace ::com::sun::star::beans
;
65 using namespace ::com::sun::star::container
;
66 using namespace ::com::sun::star::form::binding
;
67 using namespace ::com::sun::star::xsd
;
68 using namespace ::com::sun::star::lang
;
69 using namespace ::com::sun::star::form
;
71 //====================================================================
72 //= file-local helpers
73 //====================================================================
76 //--------------------------------------------------------------------
77 ::rtl::OUString
composeModelElementUIName( const ::rtl::OUString
& _rModelName
, const ::rtl::OUString
& _rElementName
)
79 ::rtl::OUStringBuffer aBuffer
;
80 aBuffer
.appendAscii( "[" );
81 aBuffer
.append( _rModelName
);
82 aBuffer
.appendAscii( "] " );
83 aBuffer
.append( _rElementName
);
84 return aBuffer
.makeStringAndClear();
88 //====================================================================
90 //====================================================================
91 //--------------------------------------------------------------------
92 EFormsHelper::EFormsHelper( ::osl::Mutex
& _rMutex
, const Reference
< XPropertySet
>& _rxControlModel
, const Reference
< frame::XModel
>& _rxContextDocument
)
93 :m_xControlModel( _rxControlModel
)
94 ,m_aPropertyListeners( _rMutex
)
96 OSL_ENSURE( _rxControlModel
.is(), "EFormsHelper::EFormsHelper: invalid control model!" );
97 m_xBindableControl
= m_xBindableControl
.query( _rxControlModel
);
99 m_xDocument
= m_xDocument
.query( _rxContextDocument
);
100 OSL_ENSURE( m_xDocument
.is(), "EFormsHelper::EFormsHelper: invalid document!" );
104 //--------------------------------------------------------------------
105 bool EFormsHelper::isEForm( const Reference
< frame::XModel
>& _rxContextDocument
)
109 Reference
< xforms::XFormsSupplier
> xDocument( _rxContextDocument
, UNO_QUERY
);
110 if ( !xDocument
.is() )
113 return xDocument
->getXForms().is();
115 catch( const Exception
& )
117 OSL_ENSURE( sal_False
, "EFormsHelper::isEForm: caught an exception!" );
122 //--------------------------------------------------------------------
123 bool EFormsHelper::canBindToDataType( sal_Int32 _nDataType
) const SAL_THROW(())
125 if ( !m_xBindableControl
.is() )
126 // cannot bind at all
129 // some types cannot be bound, independent from the control type
130 if ( ( DataTypeClass::hexBinary
== _nDataType
)
131 || ( DataTypeClass::base64Binary
== _nDataType
)
132 || ( DataTypeClass::QName
== _nDataType
)
133 || ( DataTypeClass::NOTATION
== _nDataType
)
140 // classify the control model
141 sal_Int16 nControlType
= FormComponentType::CONTROL
;
142 OSL_VERIFY( m_xControlModel
->getPropertyValue( PROPERTY_CLASSID
) >>= nControlType
);
145 sal_Int16 nNumericCompatibleTypes
[] = { DataTypeClass::DECIMAL
, DataTypeClass::FLOAT
, DataTypeClass::DOUBLE
, 0 };
146 sal_Int16 nDateCompatibleTypes
[] = { DataTypeClass::DATE
, 0 };
147 sal_Int16 nTimeCompatibleTypes
[] = { DataTypeClass::TIME
, 0 };
148 sal_Int16 nCheckboxCompatibleTypes
[] = { DataTypeClass::BOOLEAN
, DataTypeClass::STRING
, DataTypeClass::anyURI
, 0 };
149 sal_Int16 nRadiobuttonCompatibleTypes
[] = { DataTypeClass::STRING
, DataTypeClass::anyURI
, 0 };
150 sal_Int16 nFormattedCompatibleTypes
[] = { DataTypeClass::DECIMAL
, DataTypeClass::FLOAT
, DataTypeClass::DOUBLE
, DataTypeClass::DATETIME
, DataTypeClass::DATE
, DataTypeClass::TIME
, 0 };
152 sal_Int16
* pCompatibleTypes
= NULL
;
153 switch ( nControlType
)
155 case FormComponentType::SPINBUTTON
:
156 case FormComponentType::NUMERICFIELD
:
157 pCompatibleTypes
= nNumericCompatibleTypes
;
159 case FormComponentType::DATEFIELD
:
160 pCompatibleTypes
= nDateCompatibleTypes
;
162 case FormComponentType::TIMEFIELD
:
163 pCompatibleTypes
= nTimeCompatibleTypes
;
165 case FormComponentType::CHECKBOX
:
166 pCompatibleTypes
= nCheckboxCompatibleTypes
;
168 case FormComponentType::RADIOBUTTON
:
169 pCompatibleTypes
= nRadiobuttonCompatibleTypes
;
172 case FormComponentType::TEXTFIELD
:
174 // both the normal text field, and the formatted field, claim to be a TEXTFIELD
175 // need to distinguish by service name
176 Reference
< XServiceInfo
> xSI( m_xControlModel
, UNO_QUERY
);
177 OSL_ENSURE( xSI
.is(), "EFormsHelper::canBindToDataType: a control model which has no service info?" );
180 if ( xSI
->supportsService( SERVICE_COMPONENT_FORMATTEDFIELD
) )
182 pCompatibleTypes
= nFormattedCompatibleTypes
;
188 case FormComponentType::LISTBOX
:
189 case FormComponentType::COMBOBOX
:
190 // edit fields and list/combo boxes can be bound to anything
194 if ( !bCan
&& pCompatibleTypes
)
196 if ( _nDataType
== -1 )
198 // the control can be bound to at least one type, and exactly this is being asked for
203 while ( *pCompatibleTypes
&& !bCan
)
204 bCan
= ( *pCompatibleTypes
++ == _nDataType
);
208 catch( const Exception
& )
210 OSL_ENSURE( sal_False
, "EFormsHelper::canBindToDataType: caught an exception!" );
216 //--------------------------------------------------------------------
217 bool EFormsHelper::isListEntrySink() const SAL_THROW(())
222 Reference
< XListEntrySink
> xAsSink( m_xControlModel
, UNO_QUERY
);
225 catch( const Exception
& )
227 OSL_ENSURE( sal_False
, "EFormsHelper::isListEntrySink: caught an exception!" );
232 //--------------------------------------------------------------------
233 void EFormsHelper::impl_switchBindingListening_throw( bool _bDoListening
, const Reference
< XPropertyChangeListener
>& _rxListener
)
235 Reference
< XPropertySet
> xBindingProps
;
236 if ( m_xBindableControl
.is() )
237 xBindingProps
= xBindingProps
.query( m_xBindableControl
->getValueBinding() );
238 if ( !xBindingProps
.is() )
243 xBindingProps
->addPropertyChangeListener( ::rtl::OUString(), _rxListener
);
247 xBindingProps
->removePropertyChangeListener( ::rtl::OUString(), _rxListener
);
251 //--------------------------------------------------------------------
252 void EFormsHelper::registerBindingListener( const Reference
< XPropertyChangeListener
>& _rxBindingListener
)
254 if ( !_rxBindingListener
.is() )
256 impl_toggleBindingPropertyListening_throw( true, _rxBindingListener
);
259 //--------------------------------------------------------------------
260 void EFormsHelper::impl_toggleBindingPropertyListening_throw( bool _bDoListen
, const Reference
< XPropertyChangeListener
>& _rxConcreteListenerOrNull
)
264 ::std::auto_ptr
< ::cppu::OInterfaceIteratorHelper
> pListenerIterator
= m_aPropertyListeners
.createIterator();
265 while ( pListenerIterator
->hasMoreElements() )
267 PropertyEventTranslation
* pTranslator
= dynamic_cast< PropertyEventTranslation
* >( pListenerIterator
->next() );
268 OSL_ENSURE( pTranslator
, "EFormsHelper::impl_toggleBindingPropertyListening_throw: invalid listener element in my container!" );
272 Reference
< XPropertyChangeListener
> xEventSourceTranslator( pTranslator
);
273 if ( _rxConcreteListenerOrNull
.is() )
275 if ( pTranslator
->getDelegator() == _rxConcreteListenerOrNull
)
277 impl_switchBindingListening_throw( false, xEventSourceTranslator
);
278 m_aPropertyListeners
.removeListener( xEventSourceTranslator
);
284 impl_switchBindingListening_throw( false, xEventSourceTranslator
);
290 if ( _rxConcreteListenerOrNull
.is() )
292 Reference
< XPropertyChangeListener
> xEventSourceTranslator( new PropertyEventTranslation( _rxConcreteListenerOrNull
, m_xBindableControl
) );
293 m_aPropertyListeners
.addListener( xEventSourceTranslator
);
294 impl_switchBindingListening_throw( true, xEventSourceTranslator
);
298 ::std::auto_ptr
< ::cppu::OInterfaceIteratorHelper
> pListenerIterator
= m_aPropertyListeners
.createIterator();
299 while ( pListenerIterator
->hasMoreElements() )
301 Reference
< XPropertyChangeListener
> xListener( pListenerIterator
->next(), UNO_QUERY
);
302 impl_switchBindingListening_throw( true, xListener
);
308 //--------------------------------------------------------------------
309 void EFormsHelper::revokeBindingListener( const Reference
< XPropertyChangeListener
>& _rxBindingListener
)
311 impl_toggleBindingPropertyListening_throw( false, _rxBindingListener
);
314 //--------------------------------------------------------------------
315 void EFormsHelper::getFormModelNames( ::std::vector
< ::rtl::OUString
>& /* [out] */ _rModelNames
) const SAL_THROW(())
317 if ( m_xDocument
.is() )
321 _rModelNames
.resize( 0 );
323 Reference
< XNameContainer
> xForms( m_xDocument
->getXForms() );
324 OSL_ENSURE( xForms
.is(), "EFormsHelper::getFormModelNames: invalid forms container!" );
327 Sequence
< ::rtl::OUString
> aModelNames
= xForms
->getElementNames();
328 _rModelNames
.resize( aModelNames
.getLength() );
329 ::std::copy( aModelNames
.getConstArray(), aModelNames
.getConstArray() + aModelNames
.getLength(),
334 catch( const Exception
& )
336 OSL_ENSURE( sal_False
, "EFormsHelper::getFormModelNames: caught an exception!" );
341 //--------------------------------------------------------------------
342 void EFormsHelper::getBindingNames( const ::rtl::OUString
& _rModelName
, ::std::vector
< ::rtl::OUString
>& /* [out] */ _rBindingNames
) const SAL_THROW(())
344 _rBindingNames
.resize( 0 );
347 Reference
< xforms::XModel
> xModel( getFormModelByName( _rModelName
) );
350 Reference
< XNameAccess
> xBindings( xModel
->getBindings(), UNO_QUERY
);
351 OSL_ENSURE( xBindings
.is(), "EFormsHelper::getBindingNames: invalid bindings container obtained from the model!" );
352 if ( xBindings
.is() )
354 Sequence
< ::rtl::OUString
> aNames
= xBindings
->getElementNames();
355 _rBindingNames
.resize( aNames
.getLength() );
356 ::std::copy( aNames
.getConstArray(), aNames
.getConstArray() + aNames
.getLength(), _rBindingNames
.begin() );
360 catch( const Exception
& )
362 OSL_ENSURE( sal_False
, "EFormsHelper::getBindingNames: caught an exception!" );
366 //--------------------------------------------------------------------
367 Reference
< xforms::XModel
> EFormsHelper::getFormModelByName( const ::rtl::OUString
& _rModelName
) const SAL_THROW(())
369 Reference
< xforms::XModel
> xReturn
;
372 Reference
< XNameContainer
> xForms( m_xDocument
->getXForms() );
373 OSL_ENSURE( xForms
.is(), "EFormsHelper::getFormModelByName: invalid forms container!" );
375 OSL_VERIFY( xForms
->getByName( _rModelName
) >>= xReturn
);
377 catch( const Exception
& )
379 OSL_ENSURE( sal_False
, "EFormsHelper::getFormModelByName: caught an exception!" );
384 //--------------------------------------------------------------------
385 Reference
< xforms::XModel
> EFormsHelper::getCurrentFormModel() const SAL_THROW(())
387 Reference
< xforms::XModel
> xModel
;
390 Reference
< XPropertySet
> xBinding( getCurrentBinding() );
393 OSL_VERIFY( xBinding
->getPropertyValue( PROPERTY_MODEL
) >>= xModel
);
396 catch( const Exception
& )
398 OSL_ENSURE( sal_False
, "EFormsHelper::getCurrentFormModel: caught an exception!" );
403 //--------------------------------------------------------------------
404 ::rtl::OUString
EFormsHelper::getCurrentFormModelName() const SAL_THROW(())
406 ::rtl::OUString sModelName
;
409 Reference
< xforms::XModel
> xFormsModel( getCurrentFormModel() );
410 if ( xFormsModel
.is() )
411 sModelName
= xFormsModel
->getID();
413 catch( const Exception
& )
415 OSL_ENSURE( sal_False
, "EFormsHelper::getCurrentFormModel: caught an exception!" );
420 //--------------------------------------------------------------------
421 Reference
< XPropertySet
> EFormsHelper::getCurrentBinding() const SAL_THROW(())
423 Reference
< XPropertySet
> xBinding
;
427 if ( m_xBindableControl
.is() )
428 xBinding
= xBinding
.query( m_xBindableControl
->getValueBinding() );
430 catch( const Exception
& )
432 OSL_ENSURE( sal_False
, "EFormsHelper::getCurrentBinding: caught an exception!" );
438 //--------------------------------------------------------------------
439 ::rtl::OUString
EFormsHelper::getCurrentBindingName() const SAL_THROW(())
441 ::rtl::OUString sBindingName
;
444 Reference
< XPropertySet
> xBinding( getCurrentBinding() );
446 xBinding
->getPropertyValue( PROPERTY_BINDING_ID
) >>= sBindingName
;
448 catch( const Exception
& )
450 OSL_ENSURE( sal_False
, "EFormsHelper::getCurrentBindingName: caught an exception!" );
455 //--------------------------------------------------------------------
456 Reference
< XListEntrySource
> EFormsHelper::getCurrentListSourceBinding() const SAL_THROW(())
458 Reference
< XListEntrySource
> xReturn
;
461 Reference
< XListEntrySink
> xAsSink( m_xControlModel
, UNO_QUERY
);
462 OSL_ENSURE( xAsSink
.is(), "EFormsHelper::getCurrentListSourceBinding: you should have used isListEntrySink before!" );
464 xReturn
= xAsSink
->getListEntrySource();
466 catch( const Exception
& )
468 OSL_ENSURE( sal_False
, "EFormsHelper::getCurrentListSourceBinding: caught an exception!" );
473 //--------------------------------------------------------------------
474 void EFormsHelper::setListSourceBinding( const Reference
< XListEntrySource
>& _rxListSource
) SAL_THROW(())
478 Reference
< XListEntrySink
> xAsSink( m_xControlModel
, UNO_QUERY
);
479 OSL_ENSURE( xAsSink
.is(), "EFormsHelper::setListSourceBinding: you should have used isListEntrySink before!" );
481 xAsSink
->setListEntrySource( _rxListSource
);
483 catch( const Exception
& )
485 OSL_ENSURE( sal_False
, "EFormsHelper::setListSourceBinding: caught an exception!" );
489 //--------------------------------------------------------------------
490 void EFormsHelper::setBinding( const Reference
< ::com::sun::star::beans::XPropertySet
>& _rxBinding
) SAL_THROW(())
492 if ( !m_xBindableControl
.is() )
497 Reference
< XPropertySet
> xOldBinding( m_xBindableControl
->getValueBinding(), UNO_QUERY
);
499 Reference
< XValueBinding
> xBinding( _rxBinding
, UNO_QUERY
);
500 OSL_ENSURE( xBinding
.is() || !_rxBinding
.is(), "EFormsHelper::setBinding: invalid binding!" );
502 impl_toggleBindingPropertyListening_throw( false, NULL
);
503 m_xBindableControl
->setValueBinding( xBinding
);
504 impl_toggleBindingPropertyListening_throw( true, NULL
);
506 ::std::set
< ::rtl::OUString
> aSet
;
507 firePropertyChanges( xOldBinding
, _rxBinding
, aSet
);
509 catch( const Exception
& )
511 OSL_ENSURE( sal_False
, "EFormsHelper::setBinding: caught an exception!" );
515 //--------------------------------------------------------------------
516 Reference
< XPropertySet
> EFormsHelper::getOrCreateBindingForModel( const ::rtl::OUString
& _rTargetModel
, const ::rtl::OUString
& _rBindingName
) const SAL_THROW(())
518 OSL_ENSURE( _rBindingName
.getLength(), "EFormsHelper::getOrCreateBindingForModel: invalid binding name!" );
519 return implGetOrCreateBinding( _rTargetModel
, _rBindingName
);
522 //--------------------------------------------------------------------
523 Reference
< XPropertySet
> EFormsHelper::implGetOrCreateBinding( const ::rtl::OUString
& _rTargetModel
, const ::rtl::OUString
& _rBindingName
) const SAL_THROW(())
525 OSL_ENSURE( !( !_rTargetModel
.getLength() && _rBindingName
.getLength() ), "EFormsHelper::implGetOrCreateBinding: no model, but a binding name?" );
527 Reference
< XPropertySet
> xBinding
;
530 ::rtl::OUString
sTargetModel( _rTargetModel
);
531 // determine the model which the binding should belong to
532 if ( !sTargetModel
.getLength() )
534 ::std::vector
< ::rtl::OUString
> aModelNames
;
535 getFormModelNames( aModelNames
);
536 if ( !aModelNames
.empty() )
537 sTargetModel
= *aModelNames
.begin();
538 OSL_ENSURE( sTargetModel
.getLength(), "EFormsHelper::implGetOrCreateBinding: unable to obtain a default model!" );
540 Reference
< xforms::XModel
> xModel( getFormModelByName( sTargetModel
) );
541 Reference
< XNameAccess
> xBindingNames( xModel
.is() ? xModel
->getBindings() : Reference
< XSet
>(), UNO_QUERY
);
542 if ( xBindingNames
.is() )
544 // get or create the binding instance
545 if ( _rBindingName
.getLength() )
547 if ( xBindingNames
->hasByName( _rBindingName
) )
548 OSL_VERIFY( xBindingNames
->getByName( _rBindingName
) >>= xBinding
);
551 xBinding
= xModel
->createBinding( );
554 xBinding
->setPropertyValue( PROPERTY_BINDING_ID
, makeAny( _rBindingName
) );
555 xModel
->getBindings()->insert( makeAny( xBinding
) );
561 xBinding
= xModel
->createBinding( );
564 // find a nice name for it
565 String
sBaseName( PcrRes( RID_STR_BINDING_UI_NAME
) );
566 sBaseName
+= String::CreateFromAscii( " " );
568 sal_Int32 nNumber
= 1;
571 sNewName
= sBaseName
+ ::rtl::OUString::valueOf( nNumber
++ );
573 while ( xBindingNames
->hasByName( sNewName
) );
574 Reference
< XNamed
> xName( xBinding
, UNO_QUERY_THROW
);
575 xName
->setName( sNewName
);
576 // and insert into the model
577 xModel
->getBindings()->insert( makeAny( xBinding
) );
582 catch( const Exception
& )
584 DBG_UNHANDLED_EXCEPTION();
590 //--------------------------------------------------------------------
593 //................................................................
594 struct PropertyBagInserter
: public ::std::unary_function
< Property
, void >
597 PropertyBag
& m_rProperties
;
600 PropertyBagInserter( PropertyBag
& rProperties
) : m_rProperties( rProperties
) { }
602 void operator()( const Property
& _rProp
)
604 m_rProperties
.insert( _rProp
);
608 //................................................................
609 Reference
< XPropertySetInfo
> collectPropertiesGetInfo( const Reference
< XPropertySet
>& _rxProps
, PropertyBag
& _rBag
)
611 Reference
< XPropertySetInfo
> xInfo
;
613 xInfo
= _rxProps
->getPropertySetInfo();
616 Sequence
< Property
> aProperties
= xInfo
->getProperties();
617 ::std::for_each( aProperties
.getConstArray(), aProperties
.getConstArray() + aProperties
.getLength(),
618 PropertyBagInserter( _rBag
)
625 //--------------------------------------------------------------------
626 ::rtl::OUString
EFormsHelper::getModelElementUIName( const EFormsHelper::ModelElementType _eType
, const Reference
< XPropertySet
>& _rxElement
) const SAL_THROW(())
628 ::rtl::OUString sUIName
;
631 // determine the model which the element belongs to
632 Reference
< xforms::XFormsUIHelper1
> xHelper
;
633 if ( _rxElement
.is() )
634 _rxElement
->getPropertyValue( PROPERTY_MODEL
) >>= xHelper
;
635 OSL_ENSURE( xHelper
.is(), "EFormsHelper::getModelElementUIName: invalid element or model!" );
638 ::rtl::OUString sElementName
= ( _eType
== Submission
) ? xHelper
->getSubmissionName( _rxElement
, sal_True
) : xHelper
->getBindingName( _rxElement
, sal_True
);
639 Reference
< xforms::XModel
> xModel( xHelper
, UNO_QUERY_THROW
);
640 sUIName
= composeModelElementUIName( xModel
->getID(), sElementName
);
643 catch( const Exception
& )
645 OSL_ENSURE( sal_False
, "EFormsHelper::getModelElementUIName: caught an exception!" );
651 //--------------------------------------------------------------------
652 Reference
< XPropertySet
> EFormsHelper::getModelElementFromUIName( const EFormsHelper::ModelElementType _eType
, const ::rtl::OUString
& _rUIName
) const SAL_THROW(())
654 const MapStringToPropertySet
& rMapUINameToElement( ( _eType
== Submission
) ? m_aSubmissionUINames
: m_aBindingUINames
);
655 MapStringToPropertySet::const_iterator pos
= rMapUINameToElement
.find( _rUIName
);
656 OSL_ENSURE( pos
!= rMapUINameToElement
.end(), "EFormsHelper::getModelElementFromUIName: didn't find it!" );
658 return ( pos
!= rMapUINameToElement
.end() ) ? pos
->second
: Reference
< XPropertySet
>();
661 //--------------------------------------------------------------------
662 void EFormsHelper::getAllElementUINames( const ModelElementType _eType
, ::std::vector
< ::rtl::OUString
>& /* [out] */ _rElementNames
, bool _bPrepentEmptyEntry
)
664 MapStringToPropertySet
& rMapUINameToElement( ( _eType
== Submission
) ? m_aSubmissionUINames
: m_aBindingUINames
);
665 rMapUINameToElement
.clear();
666 _rElementNames
.resize( 0 );
668 if ( _bPrepentEmptyEntry
)
669 rMapUINameToElement
[ ::rtl::OUString() ] = Reference
< XPropertySet
>();
673 // obtain the model names
674 ::std::vector
< ::rtl::OUString
> aModels
;
675 getFormModelNames( aModels
);
676 _rElementNames
.reserve( aModels
.size() * 2 ); // heuristics
678 // for every model, obtain the element
679 for ( ::std::vector
< ::rtl::OUString
>::const_iterator pModelName
= aModels
.begin();
680 pModelName
!= aModels
.end();
684 Reference
< xforms::XModel
> xModel
= getFormModelByName( *pModelName
);
685 OSL_ENSURE( xModel
.is(), "EFormsHelper::getAllElementUINames: inconsistency in the models!" );
686 Reference
< xforms::XFormsUIHelper1
> xHelper( xModel
, UNO_QUERY
);
688 Reference
< XIndexAccess
> xElements
;
690 xElements
= xElements
.query( ( _eType
== Submission
) ? xModel
->getSubmissions() : xModel
->getBindings() );
691 if ( !xElements
.is() )
694 sal_Int32 nElementCount
= xElements
->getCount();
695 for ( sal_Int32 i
= 0; i
< nElementCount
; ++i
)
697 Reference
< XPropertySet
> xElement( xElements
->getByIndex( i
), UNO_QUERY
);
698 OSL_ENSURE( xElement
.is(), "EFormsHelper::getAllElementUINames: empty element!" );
699 if ( !xElement
.is() )
701 #if OSL_DEBUG_LEVEL > 0
703 Reference
< xforms::XModel
> xElementsModel
;
704 xElement
->getPropertyValue( PROPERTY_MODEL
) >>= xElementsModel
;
705 OSL_ENSURE( xElementsModel
== xModel
, "EFormsHelper::getAllElementUINames: inconsistency in the model-element relationship!" );
706 if ( !( xElementsModel
== xModel
) )
707 xElement
->setPropertyValue( PROPERTY_MODEL
, makeAny( xModel
) );
710 ::rtl::OUString sElementName
= ( _eType
== Submission
) ? xHelper
->getSubmissionName( xElement
, sal_True
) : xHelper
->getBindingName( xElement
, sal_True
);
711 ::rtl::OUString sUIName
= composeModelElementUIName( *pModelName
, sElementName
);
713 OSL_ENSURE( rMapUINameToElement
.find( sUIName
) == rMapUINameToElement
.end(), "EFormsHelper::getAllElementUINames: duplicate name!" );
714 rMapUINameToElement
.insert( MapStringToPropertySet::value_type( sUIName
, xElement
) );
718 catch( const Exception
& )
720 OSL_ENSURE( sal_False
, "EFormsHelper::getAllElementUINames: caught an exception!" );
723 _rElementNames
.resize( rMapUINameToElement
.size() );
724 ::std::transform( rMapUINameToElement
.begin(), rMapUINameToElement
.end(), _rElementNames
.begin(), ::std::select1st
< MapStringToPropertySet::value_type
>() );
727 //--------------------------------------------------------------------
728 void EFormsHelper::firePropertyChange( const ::rtl::OUString
& _rName
, const Any
& _rOldValue
, const Any
& _rNewValue
) const
730 if ( m_aPropertyListeners
.empty() )
733 if ( _rOldValue
== _rNewValue
)
738 PropertyChangeEvent aEvent
;
740 aEvent
.Source
= m_xBindableControl
.get();
741 aEvent
.PropertyName
= _rName
;
742 aEvent
.OldValue
= _rOldValue
;
743 aEvent
.NewValue
= _rNewValue
;
745 const_cast< EFormsHelper
* >( this )->m_aPropertyListeners
.notify( aEvent
, &XPropertyChangeListener::propertyChange
);
747 catch( const Exception
& )
749 OSL_ENSURE( sal_False
, "EFormsHelper::firePropertyChange: caught an exception!" );
753 //--------------------------------------------------------------------
754 void EFormsHelper::firePropertyChanges( const Reference
< XPropertySet
>& _rxOldProps
, const Reference
< XPropertySet
>& _rxNewProps
, ::std::set
< ::rtl::OUString
>& _rFilter
) const
756 if ( m_aPropertyListeners
.empty() )
761 PropertyBag aProperties
;
762 Reference
< XPropertySetInfo
> xOldInfo
= collectPropertiesGetInfo( _rxOldProps
, aProperties
);
763 Reference
< XPropertySetInfo
> xNewInfo
= collectPropertiesGetInfo( _rxNewProps
, aProperties
);
765 for ( PropertyBag::const_iterator aProp
= aProperties
.begin();
766 aProp
!= aProperties
.end();
770 if ( _rFilter
.find( aProp
->Name
) != _rFilter
.end() )
773 Any
aOldValue( NULL
, aProp
->Type
);
774 if ( xOldInfo
.is() && xOldInfo
->hasPropertyByName( aProp
->Name
) )
775 aOldValue
= _rxOldProps
->getPropertyValue( aProp
->Name
);
777 Any
aNewValue( NULL
, aProp
->Type
);
778 if ( xNewInfo
.is() && xNewInfo
->hasPropertyByName( aProp
->Name
) )
779 aNewValue
= _rxNewProps
->getPropertyValue( aProp
->Name
);
781 firePropertyChange( aProp
->Name
, aOldValue
, aNewValue
);
784 catch( const Exception
& )
786 OSL_ENSURE( sal_False
, "EFormsHelper::firePropertyChanges: caught an exception!" );
790 //........................................................................
792 //........................................................................