Update ooo320-m1
[ooovba.git] / extensions / source / propctrlr / genericpropertyhandler.cxx
blobfbad1a345e62514de6f89a6276d8f26a4bf96cf5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: genericpropertyhandler.cxx,v $
10 * $Revision: 1.8 $
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 "genericpropertyhandler.hxx"
34 #include "formmetadata.hxx"
35 #include "handlerhelper.hxx"
37 /** === begin UNO includes === **/
38 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
39 #include <com/sun/star/reflection/XEnumTypeDescription.hpp>
40 #include <com/sun/star/beans/XIntrospection.hpp>
41 #include <com/sun/star/inspection/PropertyControlType.hpp>
42 #include <com/sun/star/inspection/XHyperlinkControl.hpp>
43 #include <com/sun/star/awt/XActionListener.hpp>
44 #include <com/sun/star/util/XURLTransformer.hpp>
45 #include <com/sun/star/frame/XDispatchProvider.hpp>
46 /** === end UNO includes === **/
47 #include <tools/debug.hxx>
48 #include <cppuhelper/extract.hxx>
50 #include <algorithm>
52 //------------------------------------------------------------------------
53 extern "C" void SAL_CALL createRegistryInfo_GenericPropertyHandler()
55 ::pcr::OAutoRegistration< ::pcr::GenericPropertyHandler > aAutoRegistration;
58 //........................................................................
59 namespace pcr
61 //........................................................................
63 using namespace ::com::sun::star::uno;
64 using namespace ::com::sun::star::beans;
65 using namespace ::com::sun::star::script;
66 using namespace ::com::sun::star::frame;
67 using namespace ::com::sun::star::lang;
68 using namespace ::com::sun::star::util;
69 using namespace ::com::sun::star::container;
70 using namespace ::com::sun::star::reflection;
71 using namespace ::com::sun::star::inspection;
72 using ::com::sun::star::awt::XActionListener;
73 using ::com::sun::star::awt::ActionEvent;
75 //====================================================================
76 //= EnumRepresentation
77 //====================================================================
78 class EnumRepresentation : public IPropertyEnumRepresentation
80 private:
81 oslInterlockedCount m_refCount;
82 Reference< XEnumTypeDescription > m_xTypeDescription;
83 Type m_aEnumType;
85 public:
86 EnumRepresentation( const Reference< XComponentContext >& _rxContext, const Type& _rEnumType );
88 // IPropertyEnumRepresentation implementqation
89 virtual ::std::vector< ::rtl::OUString >
90 SAL_CALL getDescriptions() const;
91 virtual void SAL_CALL getValueFromDescription( const ::rtl::OUString& _rDescription, ::com::sun::star::uno::Any& _out_rValue ) const;
92 virtual ::rtl::OUString SAL_CALL getDescriptionForValue( const ::com::sun::star::uno::Any& _rEnumValue ) const;
94 // IReference implementqation
95 virtual oslInterlockedCount SAL_CALL acquire();
96 virtual oslInterlockedCount SAL_CALL release();
98 private:
99 void impl_getValues( Sequence< sal_Int32 >& _out_rValues ) const;
101 private:
102 EnumRepresentation(); // never implemented
103 EnumRepresentation( const EnumRepresentation& ); // never implemented
104 EnumRepresentation& operator=( const EnumRepresentation& ); // never implemented
107 //--------------------------------------------------------------------
108 EnumRepresentation::EnumRepresentation( const Reference< XComponentContext >& _rxContext, const Type& _rEnumType )
109 :m_refCount( 0 )
110 ,m_aEnumType( _rEnumType )
114 if ( _rxContext.is() )
116 Reference< XHierarchicalNameAccess > xTypeDescProv(
117 _rxContext->getValueByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/singletons/com.sun.star.reflection.theTypeDescriptionManager" ) ) ),
118 UNO_QUERY_THROW );
120 m_xTypeDescription = Reference< XEnumTypeDescription >( xTypeDescProv->getByHierarchicalName( m_aEnumType.getTypeName() ), UNO_QUERY_THROW );
123 catch( const Exception& )
125 OSL_ENSURE( sal_False, "EnumRepresentation::EnumRepresentation: caught an exception!" );
129 //--------------------------------------------------------------------
130 ::std::vector< ::rtl::OUString > EnumRepresentation::getDescriptions() const
132 Sequence< ::rtl::OUString > aNames;
135 if ( m_xTypeDescription.is() )
136 aNames = m_xTypeDescription->getEnumNames();
138 catch( const Exception& )
140 OSL_ENSURE( sal_False, "EnumRepresentation::getDescriptions: caught an exception!" );
143 return ::std::vector< ::rtl::OUString >( aNames.getConstArray(), aNames.getConstArray() + aNames.getLength() );
146 //--------------------------------------------------------------------
147 void EnumRepresentation::impl_getValues( Sequence< sal_Int32 >& _out_rValues ) const
149 _out_rValues.realloc( 0 );
152 if ( m_xTypeDescription.is() )
153 _out_rValues = m_xTypeDescription->getEnumValues();
155 catch( const Exception& )
157 OSL_ENSURE( sal_False, "EnumRepresentation::impl_getValues: caught an exception!" );
161 //--------------------------------------------------------------------
162 void EnumRepresentation::getValueFromDescription( const ::rtl::OUString& _rDescription, Any& _out_rValue ) const
164 ::std::vector< ::rtl::OUString > aDescriptions( getDescriptions() );
166 sal_Int32 index = ::std::find( aDescriptions.begin(), aDescriptions.end(),
167 _rDescription ) - aDescriptions.begin();
169 Sequence< sal_Int32 > aValues;
170 impl_getValues( aValues );
172 if ( ( index >= 0 ) && ( index < aValues.getLength() ) )
173 _out_rValue = ::cppu::int2enum( aValues[ index ], m_aEnumType );
174 else
176 DBG_ERROR( "EnumRepresentation::getValueFromDescription: cannot convert!" );
177 _out_rValue.clear();
181 //--------------------------------------------------------------------
182 ::rtl::OUString EnumRepresentation::getDescriptionForValue( const Any& _rEnumValue ) const
184 ::rtl::OUString sDescription;
186 sal_Int32 nAsInt = 0;
187 OSL_VERIFY( ::cppu::enum2int( nAsInt, _rEnumValue ) );
189 Sequence< sal_Int32 > aValues;
190 impl_getValues( aValues );
192 sal_Int32 index = ::std::find( aValues.getConstArray(), aValues.getConstArray() + aValues.getLength(),
193 nAsInt ) - aValues.getConstArray();
195 ::std::vector< ::rtl::OUString > aDescriptions( getDescriptions() );
196 if ( ( index >= 0 ) && ( index < (sal_Int32)aDescriptions.size() ) )
197 sDescription = aDescriptions[ index ];
198 else
200 DBG_ERROR( "EnumRepresentation::getDescriptionForValue: cannot convert!" );
202 return sDescription;
205 //--------------------------------------------------------------------
206 oslInterlockedCount SAL_CALL EnumRepresentation::acquire()
208 return osl_incrementInterlockedCount( &m_refCount );
211 //--------------------------------------------------------------------
212 oslInterlockedCount SAL_CALL EnumRepresentation::release()
214 if ( 0 == osl_decrementInterlockedCount( &m_refCount ) )
216 delete this;
217 return 0;
219 return m_refCount;
222 //====================================================================
223 //= UrlClickHandler
224 //====================================================================
225 typedef ::cppu::WeakImplHelper1 < XActionListener
226 > UrlClickHandler_Base;
227 class UrlClickHandler : public UrlClickHandler_Base
229 ComponentContext m_aContext;
230 public:
231 UrlClickHandler( const ComponentContext& _rContext, const Reference< XHyperlinkControl >& _rxControl );
233 protected:
234 ~UrlClickHandler();
236 // XActionListener
237 virtual void SAL_CALL actionPerformed( const ActionEvent& rEvent ) throw (RuntimeException);
239 // XEventListener
240 virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException);
242 protected:
243 void impl_dispatch_throw( const ::rtl::OUString& _rURL );
246 //--------------------------------------------------------------------
247 DBG_NAME( UrlClickHandler )
248 //--------------------------------------------------------------------
249 UrlClickHandler::UrlClickHandler( const ComponentContext& _rContext, const Reference< XHyperlinkControl >& _rxControl )
250 :m_aContext( _rContext )
252 if ( !_rxControl.is() )
253 throw NullPointerException();
255 osl_incrementInterlockedCount( &m_refCount );
257 _rxControl->addActionListener( this );
259 osl_decrementInterlockedCount( &m_refCount );
260 OSL_ENSURE( m_refCount > 0, "UrlClickHandler::UrlClickHandler: leaking!" );
262 DBG_CTOR( UrlClickHandler, NULL );
265 //--------------------------------------------------------------------
266 UrlClickHandler::~UrlClickHandler()
268 DBG_DTOR( UrlClickHandler, NULL );
271 //--------------------------------------------------------------------
272 void SAL_CALL UrlClickHandler::actionPerformed( const ActionEvent& rEvent ) throw (RuntimeException)
274 Reference< XPropertyControl > xControl( rEvent.Source, UNO_QUERY_THROW );
275 Any aControlValue( xControl->getValue() );
277 ::rtl::OUString sURL;
278 if ( aControlValue.hasValue() && !( aControlValue >>= sURL ) )
279 throw RuntimeException( ::rtl::OUString(), *this );
281 if ( !sURL.getLength() )
282 return;
284 impl_dispatch_throw( sURL );
287 //--------------------------------------------------------------------
288 void SAL_CALL UrlClickHandler::disposing( const EventObject& /*Source*/ ) throw (RuntimeException)
290 // not interested in
293 //--------------------------------------------------------------------
294 void UrlClickHandler::impl_dispatch_throw( const ::rtl::OUString& _rURL )
296 Reference< XURLTransformer > xTransformer( m_aContext.createComponent( "com.sun.star.util.URLTransformer" ), UNO_QUERY_THROW );
297 URL aURL; aURL.Complete = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:OpenHyperlink" ) );
298 xTransformer->parseStrict( aURL );
300 Reference< XDispatchProvider > xDispProv( m_aContext.createComponent( "com.sun.star.frame.Desktop" ), UNO_QUERY_THROW );
301 Reference< XDispatch > xDispatch( xDispProv->queryDispatch( aURL, ::rtl::OUString(), 0 ), UNO_QUERY_THROW );
303 Sequence< PropertyValue > aDispatchArgs(1);
304 aDispatchArgs[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URL"));
305 aDispatchArgs[0].Value <<= _rURL;
307 xDispatch->dispatch( aURL, aDispatchArgs );
310 //====================================================================
311 //= GenericPropertyHandler
312 //====================================================================
313 DBG_NAME( GenericPropertyHandler )
314 //--------------------------------------------------------------------
315 GenericPropertyHandler::GenericPropertyHandler( const Reference< XComponentContext >& _rxContext )
316 :GenericPropertyHandler_Base( m_aMutex )
317 ,m_aContext( _rxContext )
318 ,m_aPropertyListeners( m_aMutex )
319 ,m_bPropertyMapInitialized( false )
321 DBG_CTOR( GenericPropertyHandler, NULL );
323 m_xTypeConverter = Reference< XTypeConverter >(
324 m_aContext.createComponent( "com.sun.star.script.Converter" ),
325 UNO_QUERY_THROW
329 //--------------------------------------------------------------------
330 GenericPropertyHandler::~GenericPropertyHandler()
332 DBG_DTOR( GenericPropertyHandler, NULL );
335 //--------------------------------------------------------------------
336 ::rtl::OUString SAL_CALL GenericPropertyHandler::getImplementationName( ) throw (RuntimeException)
338 return getImplementationName_static();
341 //--------------------------------------------------------------------
342 ::sal_Bool SAL_CALL GenericPropertyHandler::supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException)
344 StlSyntaxSequence< ::rtl::OUString > aAllServices( getSupportedServiceNames() );
345 return ::std::find( aAllServices.begin(), aAllServices.end(), ServiceName ) != aAllServices.end();
348 //--------------------------------------------------------------------
349 Sequence< ::rtl::OUString > SAL_CALL GenericPropertyHandler::getSupportedServiceNames( ) throw (RuntimeException)
351 return getSupportedServiceNames_static();
354 //--------------------------------------------------------------------
355 ::rtl::OUString SAL_CALL GenericPropertyHandler::getImplementationName_static( ) throw (RuntimeException)
357 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.GenericPropertyHandler" ) );
360 //--------------------------------------------------------------------
361 Sequence< ::rtl::OUString > SAL_CALL GenericPropertyHandler::getSupportedServiceNames_static( ) throw (RuntimeException)
363 Sequence< ::rtl::OUString > aSupported( 1 );
364 aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.inspection.GenericPropertyHandler" ) );
365 return aSupported;
368 //--------------------------------------------------------------------
369 Reference< XInterface > SAL_CALL GenericPropertyHandler::Create( const Reference< XComponentContext >& _rxContext )
371 return *( new GenericPropertyHandler( _rxContext ) );
374 //--------------------------------------------------------------------
375 void SAL_CALL GenericPropertyHandler::inspect( const Reference< XInterface >& _rxIntrospectee ) throw (RuntimeException, NullPointerException)
377 ::osl::MutexGuard aGuard( m_aMutex );
379 if ( !_rxIntrospectee.is() )
380 throw NullPointerException();
382 // revoke old property change listeners
383 ::cppu::OInterfaceIteratorHelper iterRemove( m_aPropertyListeners );
384 ::cppu::OInterfaceIteratorHelper iterReAdd( m_aPropertyListeners ); // this holds a copy of the container ...
385 while ( iterRemove.hasMoreElements() )
386 m_xComponent->removePropertyChangeListener( ::rtl::OUString(), static_cast< XPropertyChangeListener* >( iterRemove.next() ) );
388 m_xComponentIntrospectionAccess.clear();
389 m_xComponent.clear();
390 m_xPropertyState.clear();
392 // create an introspection adapter for the component
393 Reference< XIntrospection > xIntrospection;
394 if ( !m_aContext.createComponent( "com.sun.star.beans.Introspection", xIntrospection ) )
395 throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Could not create an instance of the service com.sun.star.beans.Introspection." ) ), *this );
397 Reference< XIntrospectionAccess > xIntrospectionAccess( xIntrospection->inspect( makeAny( _rxIntrospectee ) ) );
398 if ( !xIntrospectionAccess.is() )
399 throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "The introspection service could not handle the given component." ) ), *this );
401 m_xComponent = Reference< XPropertySet >( xIntrospectionAccess->queryAdapter( XPropertySet::static_type() ), UNO_QUERY_THROW );
402 // now that we survived so far, remember m_xComponentIntrospectionAccess
403 m_xComponentIntrospectionAccess = xIntrospectionAccess;
404 m_xPropertyState = m_xPropertyState.query( m_xComponent );
406 m_bPropertyMapInitialized = false;
407 m_aProperties.clear();
409 // re-add the property change listeners
410 while ( iterReAdd.hasMoreElements() )
411 m_xComponent->addPropertyChangeListener( ::rtl::OUString(), static_cast< XPropertyChangeListener* >( iterReAdd.next() ) );
414 //--------------------------------------------------------------------
415 Any SAL_CALL GenericPropertyHandler::getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
417 ::osl::MutexGuard aGuard( m_aMutex );
418 if ( !m_xComponent.is() )
419 throw UnknownPropertyException();
421 return m_xComponent->getPropertyValue( _rPropertyName );
424 //--------------------------------------------------------------------
425 void SAL_CALL GenericPropertyHandler::setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException)
427 ::osl::MutexGuard aGuard( m_aMutex );
428 if ( !m_xComponent.is() )
429 throw UnknownPropertyException();
431 m_xComponent->setPropertyValue( _rPropertyName, _rValue );
434 //--------------------------------------------------------------------
435 ::rtl::Reference< IPropertyEnumRepresentation > GenericPropertyHandler::impl_getEnumConverter( const Type& _rEnumType )
437 ::rtl::Reference< IPropertyEnumRepresentation >& rConverter = m_aEnumConverters[ _rEnumType ];
438 if ( !rConverter.is() )
439 rConverter = new EnumRepresentation( m_aContext.getUNOContext(), _rEnumType );
440 return rConverter;
443 //--------------------------------------------------------------------
444 Any SAL_CALL GenericPropertyHandler::convertToPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rControlValue ) throw (UnknownPropertyException, RuntimeException)
446 ::osl::MutexGuard aGuard( m_aMutex );
447 const_cast< GenericPropertyHandler* >( this )->impl_ensurePropertyMap();
449 PropertyMap::const_iterator pos = m_aProperties.find( _rPropertyName );
450 if ( pos == m_aProperties.end() )
451 throw UnknownPropertyException();
453 Any aPropertyValue;
454 if ( !_rControlValue.hasValue() )
455 // NULL is converted to NULL
456 return aPropertyValue;
458 if ( pos->second.Type.getTypeClass() == TypeClass_ENUM )
460 ::rtl::OUString sControlValue;
461 OSL_VERIFY( _rControlValue >>= sControlValue );
462 impl_getEnumConverter( pos->second.Type )->getValueFromDescription( sControlValue, aPropertyValue );
464 else
465 aPropertyValue = PropertyHandlerHelper::convertToPropertyValue( m_aContext.getContext(),m_xTypeConverter, pos->second, _rControlValue );
467 return aPropertyValue;
470 //--------------------------------------------------------------------
471 Any SAL_CALL GenericPropertyHandler::convertToControlValue( const ::rtl::OUString& _rPropertyName, const Any& _rPropertyValue, const Type& _rControlValueType ) throw (UnknownPropertyException, RuntimeException)
473 ::osl::MutexGuard aGuard( m_aMutex );
474 const_cast< GenericPropertyHandler* >( this )->impl_ensurePropertyMap();
476 PropertyMap::const_iterator pos = m_aProperties.find( _rPropertyName );
477 if ( pos == m_aProperties.end() )
478 throw UnknownPropertyException();
480 Any aControlValue;
481 if ( !_rPropertyValue.hasValue() )
482 // NULL is converted to NULL
483 return aControlValue;
485 if ( pos->second.Type.getTypeClass() == TypeClass_ENUM )
487 aControlValue <<= impl_getEnumConverter( pos->second.Type )->getDescriptionForValue( _rPropertyValue );
489 else
490 aControlValue = PropertyHandlerHelper::convertToControlValue( m_aContext.getContext(),m_xTypeConverter, _rPropertyValue, _rControlValueType );
491 return aControlValue;
494 //--------------------------------------------------------------------
495 PropertyState SAL_CALL GenericPropertyHandler::getPropertyState( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
497 ::osl::MutexGuard aGuard( m_aMutex );
498 PropertyState eState = PropertyState_DIRECT_VALUE;
499 if ( m_xPropertyState.is() )
500 eState = m_xPropertyState->getPropertyState( _rPropertyName );
501 return eState;
504 //--------------------------------------------------------------------
505 void SAL_CALL GenericPropertyHandler::addPropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener ) throw (RuntimeException)
507 if ( !_rxListener.is() )
508 throw NullPointerException();
510 ::osl::MutexGuard aGuard( m_aMutex );
511 m_aPropertyListeners.addInterface( _rxListener );
512 if ( m_xComponent.is() )
516 m_xComponent->addPropertyChangeListener( ::rtl::OUString(), _rxListener );
518 catch( const UnknownPropertyException& )
520 OSL_ENSURE( false, "GenericPropertyHandler::addPropertyChangeListener:\nThe inspected component does not allow registering for all properties at once! This violates the interface contract!" );
525 //--------------------------------------------------------------------
526 void SAL_CALL GenericPropertyHandler::removePropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener ) throw (RuntimeException)
528 ::osl::MutexGuard aGuard( m_aMutex );
529 if ( m_xComponent.is() )
533 m_xComponent->removePropertyChangeListener( ::rtl::OUString(), _rxListener );
535 catch( const UnknownPropertyException& )
537 OSL_ENSURE( false, "GenericPropertyHandler::removePropertyChangeListener:\nThe inspected component does not allow de-registering for all properties at once! This violates the interface contract!" );
540 m_aPropertyListeners.removeInterface( _rxListener );
543 //--------------------------------------------------------------------
544 void GenericPropertyHandler::impl_ensurePropertyMap()
546 if ( !m_bPropertyMapInitialized )
548 m_bPropertyMapInitialized = true;
551 Reference< XPropertySetInfo > xPSI;
552 if ( m_xComponent.is() )
553 xPSI = m_xComponent->getPropertySetInfo();
554 Sequence< Property > aProperties;
555 if ( xPSI.is() )
556 aProperties = xPSI->getProperties();
557 DBG_ASSERT( aProperties.getLength(), "GenericPropertyHandler::getSupportedProperties: no properties!" );
559 for ( const Property* pProperties = aProperties.getConstArray();
560 pProperties != aProperties.getConstArray() + aProperties.getLength();
561 ++pProperties
564 switch ( pProperties->Type.getTypeClass() )
566 case TypeClass_BOOLEAN:
567 case TypeClass_BYTE:
568 case TypeClass_SHORT:
569 case TypeClass_UNSIGNED_SHORT:
570 case TypeClass_LONG:
571 case TypeClass_UNSIGNED_LONG:
572 case TypeClass_HYPER:
573 case TypeClass_UNSIGNED_HYPER:
574 case TypeClass_FLOAT:
575 case TypeClass_DOUBLE:
576 case TypeClass_ENUM:
577 case TypeClass_STRING:
578 // allowed, we can handle this type
579 break;
581 case TypeClass_SEQUENCE:
583 TypeClass eElementTypeClass = ::comphelper::getSequenceElementType( pProperties->Type ).getTypeClass();
584 if ( ( eElementTypeClass != TypeClass_STRING )
585 && ( eElementTypeClass != TypeClass_BYTE )
586 && ( eElementTypeClass != TypeClass_SHORT )
587 && ( eElementTypeClass != TypeClass_UNSIGNED_SHORT )
588 && ( eElementTypeClass != TypeClass_LONG )
589 && ( eElementTypeClass != TypeClass_UNSIGNED_LONG )
591 // can only handle the above
592 continue;
594 break;
596 default:
597 // next property, we don't support this type
598 continue;
601 m_aProperties.insert( PropertyMap::value_type( pProperties->Name, *pProperties ) );
604 catch( const Exception& )
606 OSL_ENSURE( sal_False, "GenericPropertyHandler::impl_ensurePropertyMap: caught an exception!" );
611 //--------------------------------------------------------------------
612 Sequence< Property > SAL_CALL GenericPropertyHandler::getSupportedProperties() throw (RuntimeException)
614 ::osl::MutexGuard aGuard( m_aMutex );
615 const_cast< GenericPropertyHandler* >( this )->impl_ensurePropertyMap();
617 Sequence< Property > aReturn( m_aProperties.size() );
618 ::std::transform( m_aProperties.begin(), m_aProperties.end(),
619 aReturn.getArray(), ::std::select2nd< PropertyMap::value_type >() );
620 return aReturn;
623 //--------------------------------------------------------------------
624 Sequence< ::rtl::OUString > SAL_CALL GenericPropertyHandler::getSupersededProperties( ) throw (RuntimeException)
626 // no superseded properties at all. This handler offers the very basic PropertyHandler
627 // functionality, so it's much more likely that other handlers want to supersede
628 // *our* properties ....
629 return Sequence< ::rtl::OUString >( );
632 //--------------------------------------------------------------------
633 Sequence< ::rtl::OUString > SAL_CALL GenericPropertyHandler::getActuatingProperties( ) throw (RuntimeException)
635 // This basic PropertyHandler implementation is too dumb^Wgeneric to know
636 // anything about property dependencies
637 return Sequence< ::rtl::OUString >( );
640 //--------------------------------------------------------------------
641 LineDescriptor SAL_CALL GenericPropertyHandler::describePropertyLine( const ::rtl::OUString& _rPropertyName,
642 const Reference< XPropertyControlFactory >& _rxControlFactory )
643 throw (UnknownPropertyException, NullPointerException, RuntimeException)
645 if ( !_rxControlFactory.is() )
646 throw NullPointerException();
648 ::osl::MutexGuard aGuard( m_aMutex );
649 const_cast< GenericPropertyHandler* >( this )->impl_ensurePropertyMap();
651 PropertyMap::const_iterator pos = m_aProperties.find( _rPropertyName );
652 if ( pos == m_aProperties.end() )
653 throw UnknownPropertyException();
655 LineDescriptor aDescriptor;
656 aDescriptor.DisplayName = _rPropertyName;
657 switch ( pos->second.Type.getTypeClass() )
659 case TypeClass_ENUM:
660 aDescriptor.Control = PropertyHandlerHelper::createListBoxControl( _rxControlFactory,
661 impl_getEnumConverter( pos->second.Type )->getDescriptions(),
662 PropertyHandlerHelper::requiresReadOnlyControl( pos->second.Attributes ),
663 sal_False );
664 break;
665 case TypeClass_STRING:
667 // some special handling for URL properties
668 bool bIsURLProperty = ( _rPropertyName.getLength() >= 3 ) && _rPropertyName.matchAsciiL( "URL", 3, _rPropertyName.getLength() - 3 );
669 if ( bIsURLProperty )
671 aDescriptor.Control = _rxControlFactory->createPropertyControl(
672 PropertyControlType::HyperlinkField, PropertyHandlerHelper::requiresReadOnlyControl( pos->second.Attributes ) );
674 Reference< XHyperlinkControl > xControl( aDescriptor.Control, UNO_QUERY_THROW );
675 Reference< XActionListener > xEnsureDelete( new UrlClickHandler( m_aContext, xControl ) );
678 break;
679 default:
680 break;
682 // fallback
683 if ( !aDescriptor.Control.is() )
684 PropertyHandlerHelper::describePropertyLine( pos->second, aDescriptor, _rxControlFactory );
686 aDescriptor.Category = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "General" ) );
687 return aDescriptor;
690 //--------------------------------------------------------------------
691 ::sal_Bool SAL_CALL GenericPropertyHandler::isComposable( const ::rtl::OUString& /*_rPropertyName*/ ) throw (UnknownPropertyException, RuntimeException)
693 return sal_False;
696 //--------------------------------------------------------------------
697 InteractiveSelectionResult SAL_CALL GenericPropertyHandler::onInteractivePropertySelection( const ::rtl::OUString& /*_rPropertyName*/, sal_Bool /*_bPrimary*/, Any& /*_rData*/, const Reference< XObjectInspectorUI >& /*_rxInspectorUI*/ ) throw (UnknownPropertyException, NullPointerException, RuntimeException)
699 DBG_ERROR( "GenericPropertyHandler::onInteractivePropertySelection: I'm too dumb to know anything about property browse buttons!" );
700 return InteractiveSelectionResult_Cancelled;
703 //--------------------------------------------------------------------
704 void SAL_CALL GenericPropertyHandler::actuatingPropertyChanged( const ::rtl::OUString& /*_rActuatingPropertyName*/, const Any& /*_rNewValue*/, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& /*_rxInspectorUI*/, sal_Bool /*_bFirstTimeInit*/ ) throw (NullPointerException, RuntimeException)
706 DBG_ERROR( "GenericPropertyHandler::actuatingPropertyChanged: no no no, I did not register for any actuating properties!" );
709 //--------------------------------------------------------------------
710 sal_Bool SAL_CALL GenericPropertyHandler::suspend( sal_Bool /*_bSuspend*/ ) throw (RuntimeException)
712 return sal_True;
715 //--------------------------------------------------------------------
716 void SAL_CALL GenericPropertyHandler::disposing()
718 m_aPropertyListeners.clear();
719 // not disposeAndClear: the listeners are (virtually) listeners at our introspectee, not
720 // at this handler instance
723 //--------------------------------------------------------------------
724 IMPLEMENT_FORWARD_XCOMPONENT( GenericPropertyHandler, GenericPropertyHandler_Base );
726 //........................................................................
727 } // namespace pcr
728 //........................................................................