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 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_extensions.hxx"
31 #include "eformshelper.hxx"
32 #include "formstrings.hxx"
33 #include "formresid.hrc"
34 #include "modulepcr.hxx"
35 #include "propeventtranslation.hxx"
36 #include "formbrowsertools.hxx"
38 /** === begin UNO includes === **/
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/form/FormComponentType.hpp>
41 #include <com/sun/star/xforms/XFormsUIHelper1.hpp>
42 #include <com/sun/star/xsd/DataTypeClass.hpp>
43 #include <com/sun/star/form/binding/XListEntrySink.hpp>
44 /** === end UNO includes === **/
45 #include <tools/diagnose_ex.h>
46 #include <rtl/ustrbuf.hxx>
51 //........................................................................
54 //........................................................................
56 using namespace ::com::sun::star
;
57 using namespace ::com::sun::star::uno
;
58 using namespace ::com::sun::star::beans
;
59 using namespace ::com::sun::star::container
;
60 using namespace ::com::sun::star::form::binding
;
61 using namespace ::com::sun::star::xsd
;
62 using namespace ::com::sun::star::lang
;
63 using namespace ::com::sun::star::form
;
65 //====================================================================
66 //= file-local helpers
67 //====================================================================
70 //--------------------------------------------------------------------
71 ::rtl::OUString
composeModelElementUIName( const ::rtl::OUString
& _rModelName
, const ::rtl::OUString
& _rElementName
)
73 ::rtl::OUStringBuffer aBuffer
;
74 aBuffer
.appendAscii( "[" );
75 aBuffer
.append( _rModelName
);
76 aBuffer
.appendAscii( "] " );
77 aBuffer
.append( _rElementName
);
78 return aBuffer
.makeStringAndClear();
82 //====================================================================
84 //====================================================================
85 //--------------------------------------------------------------------
86 EFormsHelper::EFormsHelper( ::osl::Mutex
& _rMutex
, const Reference
< XPropertySet
>& _rxControlModel
, const Reference
< frame::XModel
>& _rxContextDocument
)
87 :m_xControlModel( _rxControlModel
)
88 ,m_aPropertyListeners( _rMutex
)
90 OSL_ENSURE( _rxControlModel
.is(), "EFormsHelper::EFormsHelper: invalid control model!" );
91 m_xBindableControl
= m_xBindableControl
.query( _rxControlModel
);
93 m_xDocument
= m_xDocument
.query( _rxContextDocument
);
94 OSL_ENSURE( m_xDocument
.is(), "EFormsHelper::EFormsHelper: invalid document!" );
98 //--------------------------------------------------------------------
99 bool EFormsHelper::isEForm( const Reference
< frame::XModel
>& _rxContextDocument
)
103 Reference
< xforms::XFormsSupplier
> xDocument( _rxContextDocument
, UNO_QUERY
);
104 if ( !xDocument
.is() )
107 return xDocument
->getXForms().is();
109 catch( const Exception
& )
111 OSL_ENSURE( sal_False
, "EFormsHelper::isEForm: caught an exception!" );
116 //--------------------------------------------------------------------
117 bool EFormsHelper::canBindToDataType( sal_Int32 _nDataType
) const SAL_THROW(())
119 if ( !m_xBindableControl
.is() )
120 // cannot bind at all
123 // some types cannot be bound, independent from the control type
124 if ( ( DataTypeClass::hexBinary
== _nDataType
)
125 || ( DataTypeClass::base64Binary
== _nDataType
)
126 || ( DataTypeClass::QName
== _nDataType
)
127 || ( DataTypeClass::NOTATION
== _nDataType
)
134 // classify the control model
135 sal_Int16 nControlType
= FormComponentType::CONTROL
;
136 OSL_VERIFY( m_xControlModel
->getPropertyValue( PROPERTY_CLASSID
) >>= nControlType
);
139 sal_Int16 nNumericCompatibleTypes
[] = { DataTypeClass::DECIMAL
, DataTypeClass::FLOAT
, DataTypeClass::DOUBLE
, 0 };
140 sal_Int16 nDateCompatibleTypes
[] = { DataTypeClass::DATE
, 0 };
141 sal_Int16 nTimeCompatibleTypes
[] = { DataTypeClass::TIME
, 0 };
142 sal_Int16 nCheckboxCompatibleTypes
[] = { DataTypeClass::BOOLEAN
, DataTypeClass::STRING
, DataTypeClass::anyURI
, 0 };
143 sal_Int16 nRadiobuttonCompatibleTypes
[] = { DataTypeClass::STRING
, DataTypeClass::anyURI
, 0 };
144 sal_Int16 nFormattedCompatibleTypes
[] = { DataTypeClass::DECIMAL
, DataTypeClass::FLOAT
, DataTypeClass::DOUBLE
, DataTypeClass::DATETIME
, DataTypeClass::DATE
, DataTypeClass::TIME
, 0 };
146 sal_Int16
* pCompatibleTypes
= NULL
;
147 switch ( nControlType
)
149 case FormComponentType::SPINBUTTON
:
150 case FormComponentType::NUMERICFIELD
:
151 pCompatibleTypes
= nNumericCompatibleTypes
;
153 case FormComponentType::DATEFIELD
:
154 pCompatibleTypes
= nDateCompatibleTypes
;
156 case FormComponentType::TIMEFIELD
:
157 pCompatibleTypes
= nTimeCompatibleTypes
;
159 case FormComponentType::CHECKBOX
:
160 pCompatibleTypes
= nCheckboxCompatibleTypes
;
162 case FormComponentType::RADIOBUTTON
:
163 pCompatibleTypes
= nRadiobuttonCompatibleTypes
;
166 case FormComponentType::TEXTFIELD
:
168 // both the normal text field, and the formatted field, claim to be a TEXTFIELD
169 // need to distinguish by service name
170 Reference
< XServiceInfo
> xSI( m_xControlModel
, UNO_QUERY
);
171 OSL_ENSURE( xSI
.is(), "EFormsHelper::canBindToDataType: a control model which has no service info?" );
174 if ( xSI
->supportsService( SERVICE_COMPONENT_FORMATTEDFIELD
) )
176 pCompatibleTypes
= nFormattedCompatibleTypes
;
182 case FormComponentType::LISTBOX
:
183 case FormComponentType::COMBOBOX
:
184 // edit fields and list/combo boxes can be bound to anything
188 if ( !bCan
&& pCompatibleTypes
)
190 if ( _nDataType
== -1 )
192 // the control can be bound to at least one type, and exactly this is being asked for
197 while ( *pCompatibleTypes
&& !bCan
)
198 bCan
= ( *pCompatibleTypes
++ == _nDataType
);
202 catch( const Exception
& )
204 OSL_ENSURE( sal_False
, "EFormsHelper::canBindToDataType: caught an exception!" );
210 //--------------------------------------------------------------------
211 bool EFormsHelper::isListEntrySink() const SAL_THROW(())
216 Reference
< XListEntrySink
> xAsSink( m_xControlModel
, UNO_QUERY
);
219 catch( const Exception
& )
221 OSL_ENSURE( sal_False
, "EFormsHelper::isListEntrySink: caught an exception!" );
226 //--------------------------------------------------------------------
227 void EFormsHelper::impl_switchBindingListening_throw( bool _bDoListening
, const Reference
< XPropertyChangeListener
>& _rxListener
)
229 Reference
< XPropertySet
> xBindingProps
;
230 if ( m_xBindableControl
.is() )
231 xBindingProps
= xBindingProps
.query( m_xBindableControl
->getValueBinding() );
232 if ( !xBindingProps
.is() )
237 xBindingProps
->addPropertyChangeListener( ::rtl::OUString(), _rxListener
);
241 xBindingProps
->removePropertyChangeListener( ::rtl::OUString(), _rxListener
);
245 //--------------------------------------------------------------------
246 void EFormsHelper::registerBindingListener( const Reference
< XPropertyChangeListener
>& _rxBindingListener
)
248 if ( !_rxBindingListener
.is() )
250 impl_toggleBindingPropertyListening_throw( true, _rxBindingListener
);
253 //--------------------------------------------------------------------
254 void EFormsHelper::impl_toggleBindingPropertyListening_throw( bool _bDoListen
, const Reference
< XPropertyChangeListener
>& _rxConcreteListenerOrNull
)
258 ::std::auto_ptr
< ::cppu::OInterfaceIteratorHelper
> pListenerIterator
= m_aPropertyListeners
.createIterator();
259 while ( pListenerIterator
->hasMoreElements() )
261 PropertyEventTranslation
* pTranslator
= dynamic_cast< PropertyEventTranslation
* >( pListenerIterator
->next() );
262 OSL_ENSURE( pTranslator
, "EFormsHelper::impl_toggleBindingPropertyListening_throw: invalid listener element in my container!" );
266 Reference
< XPropertyChangeListener
> xEventSourceTranslator( pTranslator
);
267 if ( _rxConcreteListenerOrNull
.is() )
269 if ( pTranslator
->getDelegator() == _rxConcreteListenerOrNull
)
271 impl_switchBindingListening_throw( false, xEventSourceTranslator
);
272 m_aPropertyListeners
.removeListener( xEventSourceTranslator
);
278 impl_switchBindingListening_throw( false, xEventSourceTranslator
);
284 if ( _rxConcreteListenerOrNull
.is() )
286 Reference
< XPropertyChangeListener
> xEventSourceTranslator( new PropertyEventTranslation( _rxConcreteListenerOrNull
, m_xBindableControl
) );
287 m_aPropertyListeners
.addListener( xEventSourceTranslator
);
288 impl_switchBindingListening_throw( true, xEventSourceTranslator
);
292 ::std::auto_ptr
< ::cppu::OInterfaceIteratorHelper
> pListenerIterator
= m_aPropertyListeners
.createIterator();
293 while ( pListenerIterator
->hasMoreElements() )
295 Reference
< XPropertyChangeListener
> xListener( pListenerIterator
->next(), UNO_QUERY
);
296 impl_switchBindingListening_throw( true, xListener
);
302 //--------------------------------------------------------------------
303 void EFormsHelper::revokeBindingListener( const Reference
< XPropertyChangeListener
>& _rxBindingListener
)
305 impl_toggleBindingPropertyListening_throw( false, _rxBindingListener
);
308 //--------------------------------------------------------------------
309 void EFormsHelper::getFormModelNames( ::std::vector
< ::rtl::OUString
>& /* [out] */ _rModelNames
) const SAL_THROW(())
311 if ( m_xDocument
.is() )
315 _rModelNames
.resize( 0 );
317 Reference
< XNameContainer
> xForms( m_xDocument
->getXForms() );
318 OSL_ENSURE( xForms
.is(), "EFormsHelper::getFormModelNames: invalid forms container!" );
321 Sequence
< ::rtl::OUString
> aModelNames
= xForms
->getElementNames();
322 _rModelNames
.resize( aModelNames
.getLength() );
323 ::std::copy( aModelNames
.getConstArray(), aModelNames
.getConstArray() + aModelNames
.getLength(),
328 catch( const Exception
& )
330 OSL_ENSURE( sal_False
, "EFormsHelper::getFormModelNames: caught an exception!" );
335 //--------------------------------------------------------------------
336 void EFormsHelper::getBindingNames( const ::rtl::OUString
& _rModelName
, ::std::vector
< ::rtl::OUString
>& /* [out] */ _rBindingNames
) const SAL_THROW(())
338 _rBindingNames
.resize( 0 );
341 Reference
< xforms::XModel
> xModel( getFormModelByName( _rModelName
) );
344 Reference
< XNameAccess
> xBindings( xModel
->getBindings(), UNO_QUERY
);
345 OSL_ENSURE( xBindings
.is(), "EFormsHelper::getBindingNames: invalid bindings container obtained from the model!" );
346 if ( xBindings
.is() )
348 Sequence
< ::rtl::OUString
> aNames
= xBindings
->getElementNames();
349 _rBindingNames
.resize( aNames
.getLength() );
350 ::std::copy( aNames
.getConstArray(), aNames
.getConstArray() + aNames
.getLength(), _rBindingNames
.begin() );
354 catch( const Exception
& )
356 OSL_ENSURE( sal_False
, "EFormsHelper::getBindingNames: caught an exception!" );
360 //--------------------------------------------------------------------
361 Reference
< xforms::XModel
> EFormsHelper::getFormModelByName( const ::rtl::OUString
& _rModelName
) const SAL_THROW(())
363 Reference
< xforms::XModel
> xReturn
;
366 Reference
< XNameContainer
> xForms( m_xDocument
->getXForms() );
367 OSL_ENSURE( xForms
.is(), "EFormsHelper::getFormModelByName: invalid forms container!" );
369 OSL_VERIFY( xForms
->getByName( _rModelName
) >>= xReturn
);
371 catch( const Exception
& )
373 OSL_ENSURE( sal_False
, "EFormsHelper::getFormModelByName: caught an exception!" );
378 //--------------------------------------------------------------------
379 Reference
< xforms::XModel
> EFormsHelper::getCurrentFormModel() const SAL_THROW(())
381 Reference
< xforms::XModel
> xModel
;
384 Reference
< XPropertySet
> xBinding( getCurrentBinding() );
387 OSL_VERIFY( xBinding
->getPropertyValue( PROPERTY_MODEL
) >>= xModel
);
390 catch( const Exception
& )
392 OSL_ENSURE( sal_False
, "EFormsHelper::getCurrentFormModel: caught an exception!" );
397 //--------------------------------------------------------------------
398 ::rtl::OUString
EFormsHelper::getCurrentFormModelName() const SAL_THROW(())
400 ::rtl::OUString sModelName
;
403 Reference
< xforms::XModel
> xFormsModel( getCurrentFormModel() );
404 if ( xFormsModel
.is() )
405 sModelName
= xFormsModel
->getID();
407 catch( const Exception
& )
409 OSL_ENSURE( sal_False
, "EFormsHelper::getCurrentFormModel: caught an exception!" );
414 //--------------------------------------------------------------------
415 Reference
< XPropertySet
> EFormsHelper::getCurrentBinding() const SAL_THROW(())
417 Reference
< XPropertySet
> xBinding
;
421 if ( m_xBindableControl
.is() )
422 xBinding
= xBinding
.query( m_xBindableControl
->getValueBinding() );
424 catch( const Exception
& )
426 OSL_ENSURE( sal_False
, "EFormsHelper::getCurrentBinding: caught an exception!" );
432 //--------------------------------------------------------------------
433 ::rtl::OUString
EFormsHelper::getCurrentBindingName() const SAL_THROW(())
435 ::rtl::OUString sBindingName
;
438 Reference
< XPropertySet
> xBinding( getCurrentBinding() );
440 xBinding
->getPropertyValue( PROPERTY_BINDING_ID
) >>= sBindingName
;
442 catch( const Exception
& )
444 OSL_ENSURE( sal_False
, "EFormsHelper::getCurrentBindingName: caught an exception!" );
449 //--------------------------------------------------------------------
450 Reference
< XListEntrySource
> EFormsHelper::getCurrentListSourceBinding() const SAL_THROW(())
452 Reference
< XListEntrySource
> xReturn
;
455 Reference
< XListEntrySink
> xAsSink( m_xControlModel
, UNO_QUERY
);
456 OSL_ENSURE( xAsSink
.is(), "EFormsHelper::getCurrentListSourceBinding: you should have used isListEntrySink before!" );
458 xReturn
= xAsSink
->getListEntrySource();
460 catch( const Exception
& )
462 OSL_ENSURE( sal_False
, "EFormsHelper::getCurrentListSourceBinding: caught an exception!" );
467 //--------------------------------------------------------------------
468 void EFormsHelper::setListSourceBinding( const Reference
< XListEntrySource
>& _rxListSource
) SAL_THROW(())
472 Reference
< XListEntrySink
> xAsSink( m_xControlModel
, UNO_QUERY
);
473 OSL_ENSURE( xAsSink
.is(), "EFormsHelper::setListSourceBinding: you should have used isListEntrySink before!" );
475 xAsSink
->setListEntrySource( _rxListSource
);
477 catch( const Exception
& )
479 OSL_ENSURE( sal_False
, "EFormsHelper::setListSourceBinding: caught an exception!" );
483 //--------------------------------------------------------------------
484 void EFormsHelper::setBinding( const Reference
< ::com::sun::star::beans::XPropertySet
>& _rxBinding
) SAL_THROW(())
486 if ( !m_xBindableControl
.is() )
491 Reference
< XPropertySet
> xOldBinding( m_xBindableControl
->getValueBinding(), UNO_QUERY
);
493 Reference
< XValueBinding
> xBinding( _rxBinding
, UNO_QUERY
);
494 OSL_ENSURE( xBinding
.is() || !_rxBinding
.is(), "EFormsHelper::setBinding: invalid binding!" );
496 impl_toggleBindingPropertyListening_throw( false, NULL
);
497 m_xBindableControl
->setValueBinding( xBinding
);
498 impl_toggleBindingPropertyListening_throw( true, NULL
);
500 ::std::set
< ::rtl::OUString
> aSet
;
501 firePropertyChanges( xOldBinding
, _rxBinding
, aSet
);
503 catch( const Exception
& )
505 OSL_ENSURE( sal_False
, "EFormsHelper::setBinding: caught an exception!" );
509 //--------------------------------------------------------------------
510 Reference
< XPropertySet
> EFormsHelper::getOrCreateBindingForModel( const ::rtl::OUString
& _rTargetModel
, const ::rtl::OUString
& _rBindingName
) const SAL_THROW(())
512 OSL_ENSURE( _rBindingName
.getLength(), "EFormsHelper::getOrCreateBindingForModel: invalid binding name!" );
513 return implGetOrCreateBinding( _rTargetModel
, _rBindingName
);
516 //--------------------------------------------------------------------
517 Reference
< XPropertySet
> EFormsHelper::implGetOrCreateBinding( const ::rtl::OUString
& _rTargetModel
, const ::rtl::OUString
& _rBindingName
) const SAL_THROW(())
519 OSL_ENSURE( !( !_rTargetModel
.getLength() && _rBindingName
.getLength() ), "EFormsHelper::implGetOrCreateBinding: no model, but a binding name?" );
521 Reference
< XPropertySet
> xBinding
;
524 ::rtl::OUString
sTargetModel( _rTargetModel
);
525 // determine the model which the binding should belong to
526 if ( !sTargetModel
.getLength() )
528 ::std::vector
< ::rtl::OUString
> aModelNames
;
529 getFormModelNames( aModelNames
);
530 if ( !aModelNames
.empty() )
531 sTargetModel
= *aModelNames
.begin();
532 OSL_ENSURE( sTargetModel
.getLength(), "EFormsHelper::implGetOrCreateBinding: unable to obtain a default model!" );
534 Reference
< xforms::XModel
> xModel( getFormModelByName( sTargetModel
) );
535 Reference
< XNameAccess
> xBindingNames( xModel
.is() ? xModel
->getBindings() : Reference
< XSet
>(), UNO_QUERY
);
536 if ( xBindingNames
.is() )
538 // get or create the binding instance
539 if ( _rBindingName
.getLength() )
541 if ( xBindingNames
->hasByName( _rBindingName
) )
542 OSL_VERIFY( xBindingNames
->getByName( _rBindingName
) >>= xBinding
);
545 xBinding
= xModel
->createBinding( );
548 xBinding
->setPropertyValue( PROPERTY_BINDING_ID
, makeAny( _rBindingName
) );
549 xModel
->getBindings()->insert( makeAny( xBinding
) );
555 xBinding
= xModel
->createBinding( );
558 // find a nice name for it
559 String
sBaseName( PcrRes( RID_STR_BINDING_UI_NAME
) );
560 sBaseName
+= String::CreateFromAscii( " " );
562 sal_Int32 nNumber
= 1;
565 sNewName
= sBaseName
+ ::rtl::OUString::valueOf( nNumber
++ );
567 while ( xBindingNames
->hasByName( sNewName
) );
568 Reference
< XNamed
> xName( xBinding
, UNO_QUERY_THROW
);
569 xName
->setName( sNewName
);
570 // and insert into the model
571 xModel
->getBindings()->insert( makeAny( xBinding
) );
576 catch( const Exception
& )
578 DBG_UNHANDLED_EXCEPTION();
584 //--------------------------------------------------------------------
587 //................................................................
588 struct PropertyBagInserter
: public ::std::unary_function
< Property
, void >
591 PropertyBag
& m_rProperties
;
594 PropertyBagInserter( PropertyBag
& rProperties
) : m_rProperties( rProperties
) { }
596 void operator()( const Property
& _rProp
)
598 m_rProperties
.insert( _rProp
);
602 //................................................................
603 Reference
< XPropertySetInfo
> collectPropertiesGetInfo( const Reference
< XPropertySet
>& _rxProps
, PropertyBag
& _rBag
)
605 Reference
< XPropertySetInfo
> xInfo
;
607 xInfo
= _rxProps
->getPropertySetInfo();
610 Sequence
< Property
> aProperties
= xInfo
->getProperties();
611 ::std::for_each( aProperties
.getConstArray(), aProperties
.getConstArray() + aProperties
.getLength(),
612 PropertyBagInserter( _rBag
)
619 //--------------------------------------------------------------------
620 ::rtl::OUString
EFormsHelper::getModelElementUIName( const EFormsHelper::ModelElementType _eType
, const Reference
< XPropertySet
>& _rxElement
) const SAL_THROW(())
622 ::rtl::OUString sUIName
;
625 // determine the model which the element belongs to
626 Reference
< xforms::XFormsUIHelper1
> xHelper
;
627 if ( _rxElement
.is() )
628 _rxElement
->getPropertyValue( PROPERTY_MODEL
) >>= xHelper
;
629 OSL_ENSURE( xHelper
.is(), "EFormsHelper::getModelElementUIName: invalid element or model!" );
632 ::rtl::OUString sElementName
= ( _eType
== Submission
) ? xHelper
->getSubmissionName( _rxElement
, sal_True
) : xHelper
->getBindingName( _rxElement
, sal_True
);
633 Reference
< xforms::XModel
> xModel( xHelper
, UNO_QUERY_THROW
);
634 sUIName
= composeModelElementUIName( xModel
->getID(), sElementName
);
637 catch( const Exception
& )
639 OSL_ENSURE( sal_False
, "EFormsHelper::getModelElementUIName: caught an exception!" );
645 //--------------------------------------------------------------------
646 Reference
< XPropertySet
> EFormsHelper::getModelElementFromUIName( const EFormsHelper::ModelElementType _eType
, const ::rtl::OUString
& _rUIName
) const SAL_THROW(())
648 const MapStringToPropertySet
& rMapUINameToElement( ( _eType
== Submission
) ? m_aSubmissionUINames
: m_aBindingUINames
);
649 MapStringToPropertySet::const_iterator pos
= rMapUINameToElement
.find( _rUIName
);
650 OSL_ENSURE( pos
!= rMapUINameToElement
.end(), "EFormsHelper::getModelElementFromUIName: didn't find it!" );
652 return ( pos
!= rMapUINameToElement
.end() ) ? pos
->second
: Reference
< XPropertySet
>();
655 //--------------------------------------------------------------------
656 void EFormsHelper::getAllElementUINames( const ModelElementType _eType
, ::std::vector
< ::rtl::OUString
>& /* [out] */ _rElementNames
, bool _bPrepentEmptyEntry
)
658 MapStringToPropertySet
& rMapUINameToElement( ( _eType
== Submission
) ? m_aSubmissionUINames
: m_aBindingUINames
);
659 rMapUINameToElement
.clear();
660 _rElementNames
.resize( 0 );
662 if ( _bPrepentEmptyEntry
)
663 rMapUINameToElement
[ ::rtl::OUString() ] = Reference
< XPropertySet
>();
667 // obtain the model names
668 ::std::vector
< ::rtl::OUString
> aModels
;
669 getFormModelNames( aModels
);
670 _rElementNames
.reserve( aModels
.size() * 2 ); // heuristics
672 // for every model, obtain the element
673 for ( ::std::vector
< ::rtl::OUString
>::const_iterator pModelName
= aModels
.begin();
674 pModelName
!= aModels
.end();
678 Reference
< xforms::XModel
> xModel
= getFormModelByName( *pModelName
);
679 OSL_ENSURE( xModel
.is(), "EFormsHelper::getAllElementUINames: inconsistency in the models!" );
680 Reference
< xforms::XFormsUIHelper1
> xHelper( xModel
, UNO_QUERY
);
682 Reference
< XIndexAccess
> xElements
;
684 xElements
= xElements
.query( ( _eType
== Submission
) ? xModel
->getSubmissions() : xModel
->getBindings() );
685 if ( !xElements
.is() )
688 sal_Int32 nElementCount
= xElements
->getCount();
689 for ( sal_Int32 i
= 0; i
< nElementCount
; ++i
)
691 Reference
< XPropertySet
> xElement( xElements
->getByIndex( i
), UNO_QUERY
);
692 OSL_ENSURE( xElement
.is(), "EFormsHelper::getAllElementUINames: empty element!" );
693 if ( !xElement
.is() )
695 #if OSL_DEBUG_LEVEL > 0
697 Reference
< xforms::XModel
> xElementsModel
;
698 xElement
->getPropertyValue( PROPERTY_MODEL
) >>= xElementsModel
;
699 OSL_ENSURE( xElementsModel
== xModel
, "EFormsHelper::getAllElementUINames: inconsistency in the model-element relationship!" );
700 if ( !( xElementsModel
== xModel
) )
701 xElement
->setPropertyValue( PROPERTY_MODEL
, makeAny( xModel
) );
704 ::rtl::OUString sElementName
= ( _eType
== Submission
) ? xHelper
->getSubmissionName( xElement
, sal_True
) : xHelper
->getBindingName( xElement
, sal_True
);
705 ::rtl::OUString sUIName
= composeModelElementUIName( *pModelName
, sElementName
);
707 OSL_ENSURE( rMapUINameToElement
.find( sUIName
) == rMapUINameToElement
.end(), "EFormsHelper::getAllElementUINames: duplicate name!" );
708 rMapUINameToElement
.insert( MapStringToPropertySet::value_type( sUIName
, xElement
) );
712 catch( const Exception
& )
714 OSL_ENSURE( sal_False
, "EFormsHelper::getAllElementUINames: caught an exception!" );
717 _rElementNames
.resize( rMapUINameToElement
.size() );
718 ::std::transform( rMapUINameToElement
.begin(), rMapUINameToElement
.end(), _rElementNames
.begin(), ::std::select1st
< MapStringToPropertySet::value_type
>() );
721 //--------------------------------------------------------------------
722 void EFormsHelper::firePropertyChange( const ::rtl::OUString
& _rName
, const Any
& _rOldValue
, const Any
& _rNewValue
) const
724 if ( m_aPropertyListeners
.empty() )
727 if ( _rOldValue
== _rNewValue
)
732 PropertyChangeEvent aEvent
;
734 aEvent
.Source
= m_xBindableControl
.get();
735 aEvent
.PropertyName
= _rName
;
736 aEvent
.OldValue
= _rOldValue
;
737 aEvent
.NewValue
= _rNewValue
;
739 const_cast< EFormsHelper
* >( this )->m_aPropertyListeners
.notify( aEvent
, &XPropertyChangeListener::propertyChange
);
741 catch( const Exception
& )
743 OSL_ENSURE( sal_False
, "EFormsHelper::firePropertyChange: caught an exception!" );
747 //--------------------------------------------------------------------
748 void EFormsHelper::firePropertyChanges( const Reference
< XPropertySet
>& _rxOldProps
, const Reference
< XPropertySet
>& _rxNewProps
, ::std::set
< ::rtl::OUString
>& _rFilter
) const
750 if ( m_aPropertyListeners
.empty() )
755 PropertyBag aProperties
;
756 Reference
< XPropertySetInfo
> xOldInfo
= collectPropertiesGetInfo( _rxOldProps
, aProperties
);
757 Reference
< XPropertySetInfo
> xNewInfo
= collectPropertiesGetInfo( _rxNewProps
, aProperties
);
759 for ( PropertyBag::const_iterator aProp
= aProperties
.begin();
760 aProp
!= aProperties
.end();
764 if ( _rFilter
.find( aProp
->Name
) != _rFilter
.end() )
767 Any
aOldValue( NULL
, aProp
->Type
);
768 if ( xOldInfo
.is() && xOldInfo
->hasPropertyByName( aProp
->Name
) )
769 aOldValue
= _rxOldProps
->getPropertyValue( aProp
->Name
);
771 Any
aNewValue( NULL
, aProp
->Type
);
772 if ( xNewInfo
.is() && xNewInfo
->hasPropertyByName( aProp
->Name
) )
773 aNewValue
= _rxNewProps
->getPropertyValue( aProp
->Name
);
775 firePropertyChange( aProp
->Name
, aOldValue
, aNewValue
);
778 catch( const Exception
& )
780 OSL_ENSURE( sal_False
, "EFormsHelper::firePropertyChanges: caught an exception!" );
784 //........................................................................
786 //........................................................................
788 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */