bump product version to 4.1.6.2
[LibreOffice.git] / extensions / source / propctrlr / genericpropertyhandler.cxx
blobcb9d4704e8c9fd8da1beffd383d7f265eb633b98
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "genericpropertyhandler.hxx"
21 #include "formmetadata.hxx"
22 #include "handlerhelper.hxx"
24 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
25 #include <com/sun/star/reflection/XEnumTypeDescription.hpp>
26 #include <com/sun/star/beans/Introspection.hpp>
27 #include <com/sun/star/inspection/PropertyControlType.hpp>
28 #include <com/sun/star/inspection/XHyperlinkControl.hpp>
29 #include <com/sun/star/awt/XActionListener.hpp>
30 #include <com/sun/star/script/Converter.hpp>
31 #include <com/sun/star/util/URLTransformer.hpp>
32 #include <com/sun/star/util/XURLTransformer.hpp>
33 #include <com/sun/star/frame/Desktop.hpp>
34 #include <com/sun/star/frame/XDispatchProvider.hpp>
35 #include <tools/debug.hxx>
36 #include <comphelper/extract.hxx>
38 #include <algorithm>
39 #include <o3tl/compat_functional.hxx>
41 //------------------------------------------------------------------------
42 extern "C" void SAL_CALL createRegistryInfo_GenericPropertyHandler()
44 ::pcr::OAutoRegistration< ::pcr::GenericPropertyHandler > aAutoRegistration;
47 //........................................................................
48 namespace pcr
50 //........................................................................
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::beans;
54 using namespace ::com::sun::star::script;
55 using namespace ::com::sun::star::frame;
56 using namespace ::com::sun::star::lang;
57 using namespace ::com::sun::star::util;
58 using namespace ::com::sun::star::container;
59 using namespace ::com::sun::star::reflection;
60 using namespace ::com::sun::star::inspection;
61 using ::com::sun::star::awt::XActionListener;
62 using ::com::sun::star::awt::ActionEvent;
64 //====================================================================
65 //= EnumRepresentation
66 //====================================================================
67 class EnumRepresentation : public IPropertyEnumRepresentation
69 private:
70 oslInterlockedCount m_refCount;
71 Reference< XEnumTypeDescription > m_xTypeDescription;
72 Type m_aEnumType;
74 public:
75 EnumRepresentation( const Reference< XComponentContext >& _rxContext, const Type& _rEnumType );
77 // IPropertyEnumRepresentation implementqation
78 virtual ::std::vector< OUString >
79 SAL_CALL getDescriptions() const;
80 virtual void SAL_CALL getValueFromDescription( const OUString& _rDescription, ::com::sun::star::uno::Any& _out_rValue ) const;
81 virtual OUString SAL_CALL getDescriptionForValue( const ::com::sun::star::uno::Any& _rEnumValue ) const;
83 // IReference implementqation
84 virtual oslInterlockedCount SAL_CALL acquire();
85 virtual oslInterlockedCount SAL_CALL release();
87 private:
88 void impl_getValues( Sequence< sal_Int32 >& _out_rValues ) const;
90 private:
91 EnumRepresentation(); // never implemented
92 EnumRepresentation( const EnumRepresentation& ); // never implemented
93 EnumRepresentation& operator=( const EnumRepresentation& ); // never implemented
96 //--------------------------------------------------------------------
97 EnumRepresentation::EnumRepresentation( const Reference< XComponentContext >& _rxContext, const Type& _rEnumType )
98 :m_refCount( 0 )
99 ,m_aEnumType( _rEnumType )
103 if ( _rxContext.is() )
105 Reference< XHierarchicalNameAccess > xTypeDescProv(
106 _rxContext->getValueByName( OUString( "/singletons/com.sun.star.reflection.theTypeDescriptionManager" ) ),
107 UNO_QUERY_THROW );
109 m_xTypeDescription = Reference< XEnumTypeDescription >( xTypeDescProv->getByHierarchicalName( m_aEnumType.getTypeName() ), UNO_QUERY_THROW );
112 catch( const Exception& )
114 OSL_FAIL( "EnumRepresentation::EnumRepresentation: caught an exception!" );
118 //--------------------------------------------------------------------
119 ::std::vector< OUString > EnumRepresentation::getDescriptions() const
121 Sequence< OUString > aNames;
124 if ( m_xTypeDescription.is() )
125 aNames = m_xTypeDescription->getEnumNames();
127 catch( const Exception& )
129 OSL_FAIL( "EnumRepresentation::getDescriptions: caught an exception!" );
132 return ::std::vector< OUString >( aNames.getConstArray(), aNames.getConstArray() + aNames.getLength() );
135 //--------------------------------------------------------------------
136 void EnumRepresentation::impl_getValues( Sequence< sal_Int32 >& _out_rValues ) const
138 _out_rValues.realloc( 0 );
141 if ( m_xTypeDescription.is() )
142 _out_rValues = m_xTypeDescription->getEnumValues();
144 catch( const Exception& )
146 OSL_FAIL( "EnumRepresentation::impl_getValues: caught an exception!" );
150 //--------------------------------------------------------------------
151 void EnumRepresentation::getValueFromDescription( const OUString& _rDescription, Any& _out_rValue ) const
153 ::std::vector< OUString > aDescriptions( getDescriptions() );
155 sal_Int32 index = ::std::find( aDescriptions.begin(), aDescriptions.end(),
156 _rDescription ) - aDescriptions.begin();
158 Sequence< sal_Int32 > aValues;
159 impl_getValues( aValues );
161 if ( ( index >= 0 ) && ( index < aValues.getLength() ) )
162 _out_rValue = ::cppu::int2enum( aValues[ index ], m_aEnumType );
163 else
165 OSL_FAIL( "EnumRepresentation::getValueFromDescription: cannot convert!" );
166 _out_rValue.clear();
170 //--------------------------------------------------------------------
171 OUString EnumRepresentation::getDescriptionForValue( const Any& _rEnumValue ) const
173 OUString sDescription;
175 sal_Int32 nAsInt = 0;
176 OSL_VERIFY( ::cppu::enum2int( nAsInt, _rEnumValue ) );
178 Sequence< sal_Int32 > aValues;
179 impl_getValues( aValues );
181 sal_Int32 index = ::std::find( aValues.getConstArray(), aValues.getConstArray() + aValues.getLength(),
182 nAsInt ) - aValues.getConstArray();
184 ::std::vector< OUString > aDescriptions( getDescriptions() );
185 if ( ( index >= 0 ) && ( index < (sal_Int32)aDescriptions.size() ) )
186 sDescription = aDescriptions[ index ];
187 else
189 OSL_FAIL( "EnumRepresentation::getDescriptionForValue: cannot convert!" );
191 return sDescription;
194 //--------------------------------------------------------------------
195 oslInterlockedCount SAL_CALL EnumRepresentation::acquire()
197 return osl_atomic_increment( &m_refCount );
200 //--------------------------------------------------------------------
201 oslInterlockedCount SAL_CALL EnumRepresentation::release()
203 if ( 0 == osl_atomic_decrement( &m_refCount ) )
205 delete this;
206 return 0;
208 return m_refCount;
211 //====================================================================
212 //= UrlClickHandler
213 //====================================================================
214 typedef ::cppu::WeakImplHelper1 < XActionListener
215 > UrlClickHandler_Base;
216 class UrlClickHandler : public UrlClickHandler_Base
218 ComponentContext m_aContext;
219 public:
220 UrlClickHandler( const ComponentContext& _rContext, const Reference< XHyperlinkControl >& _rxControl );
222 protected:
223 ~UrlClickHandler();
225 // XActionListener
226 virtual void SAL_CALL actionPerformed( const ActionEvent& rEvent ) throw (RuntimeException);
228 // XEventListener
229 virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException);
231 protected:
232 void impl_dispatch_throw( const OUString& _rURL );
235 //--------------------------------------------------------------------
236 DBG_NAME( UrlClickHandler )
237 //--------------------------------------------------------------------
238 UrlClickHandler::UrlClickHandler( const ComponentContext& _rContext, const Reference< XHyperlinkControl >& _rxControl )
239 :m_aContext( _rContext )
241 if ( !_rxControl.is() )
242 throw NullPointerException();
244 osl_atomic_increment( &m_refCount );
246 _rxControl->addActionListener( this );
248 osl_atomic_decrement( &m_refCount );
249 OSL_ENSURE( m_refCount > 0, "UrlClickHandler::UrlClickHandler: leaking!" );
251 DBG_CTOR( UrlClickHandler, NULL );
254 //--------------------------------------------------------------------
255 UrlClickHandler::~UrlClickHandler()
257 DBG_DTOR( UrlClickHandler, NULL );
260 //--------------------------------------------------------------------
261 void SAL_CALL UrlClickHandler::actionPerformed( const ActionEvent& rEvent ) throw (RuntimeException)
263 Reference< XPropertyControl > xControl( rEvent.Source, UNO_QUERY_THROW );
264 Any aControlValue( xControl->getValue() );
266 OUString sURL;
267 if ( aControlValue.hasValue() && !( aControlValue >>= sURL ) )
268 throw RuntimeException( OUString(), *this );
270 if ( sURL.isEmpty() )
271 return;
273 impl_dispatch_throw( sURL );
276 //--------------------------------------------------------------------
277 void SAL_CALL UrlClickHandler::disposing( const EventObject& /*Source*/ ) throw (RuntimeException)
279 // not interested in
282 //--------------------------------------------------------------------
283 void UrlClickHandler::impl_dispatch_throw( const OUString& _rURL )
285 Reference< XURLTransformer > xTransformer( URLTransformer::create(m_aContext.getUNOContext()) );
286 URL aURL; aURL.Complete = OUString( ".uno:OpenHyperlink" );
287 xTransformer->parseStrict( aURL );
289 Reference< XDesktop2 > xDispProv = Desktop::create( m_aContext.getUNOContext() );
290 Reference< XDispatch > xDispatch( xDispProv->queryDispatch( aURL, OUString(), 0 ), UNO_QUERY_THROW );
292 Sequence< PropertyValue > aDispatchArgs(1);
293 aDispatchArgs[0].Name = OUString("URL");
294 aDispatchArgs[0].Value <<= _rURL;
296 xDispatch->dispatch( aURL, aDispatchArgs );
299 //====================================================================
300 //= GenericPropertyHandler
301 //====================================================================
302 DBG_NAME( GenericPropertyHandler )
303 //--------------------------------------------------------------------
304 GenericPropertyHandler::GenericPropertyHandler( const Reference< XComponentContext >& _rxContext )
305 :GenericPropertyHandler_Base( m_aMutex )
306 ,m_aContext( _rxContext )
307 ,m_aPropertyListeners( m_aMutex )
308 ,m_bPropertyMapInitialized( false )
310 DBG_CTOR( GenericPropertyHandler, NULL );
312 m_xTypeConverter = Converter::create(_rxContext);
315 //--------------------------------------------------------------------
316 GenericPropertyHandler::~GenericPropertyHandler()
318 DBG_DTOR( GenericPropertyHandler, NULL );
321 //--------------------------------------------------------------------
322 OUString SAL_CALL GenericPropertyHandler::getImplementationName( ) throw (RuntimeException)
324 return getImplementationName_static();
327 //--------------------------------------------------------------------
328 ::sal_Bool SAL_CALL GenericPropertyHandler::supportsService( const OUString& ServiceName ) throw (RuntimeException)
330 StlSyntaxSequence< OUString > aAllServices( getSupportedServiceNames() );
331 return ::std::find( aAllServices.begin(), aAllServices.end(), ServiceName ) != aAllServices.end();
334 //--------------------------------------------------------------------
335 Sequence< OUString > SAL_CALL GenericPropertyHandler::getSupportedServiceNames( ) throw (RuntimeException)
337 return getSupportedServiceNames_static();
340 //--------------------------------------------------------------------
341 OUString SAL_CALL GenericPropertyHandler::getImplementationName_static( ) throw (RuntimeException)
343 return OUString( "com.sun.star.comp.extensions.GenericPropertyHandler" );
346 //--------------------------------------------------------------------
347 Sequence< OUString > SAL_CALL GenericPropertyHandler::getSupportedServiceNames_static( ) throw (RuntimeException)
349 Sequence< OUString > aSupported( 1 );
350 aSupported[0] = OUString( "com.sun.star.inspection.GenericPropertyHandler" );
351 return aSupported;
354 //--------------------------------------------------------------------
355 Reference< XInterface > SAL_CALL GenericPropertyHandler::Create( const Reference< XComponentContext >& _rxContext )
357 return *( new GenericPropertyHandler( _rxContext ) );
360 //--------------------------------------------------------------------
361 void SAL_CALL GenericPropertyHandler::inspect( const Reference< XInterface >& _rxIntrospectee ) throw (RuntimeException, NullPointerException)
363 ::osl::MutexGuard aGuard( m_aMutex );
365 if ( !_rxIntrospectee.is() )
366 throw NullPointerException();
368 // revoke old property change listeners
369 ::cppu::OInterfaceIteratorHelper iterRemove( m_aPropertyListeners );
370 ::cppu::OInterfaceIteratorHelper iterReAdd( m_aPropertyListeners ); // this holds a copy of the container ...
371 while ( iterRemove.hasMoreElements() )
372 m_xComponent->removePropertyChangeListener( OUString(), static_cast< XPropertyChangeListener* >( iterRemove.next() ) );
374 m_xComponentIntrospectionAccess.clear();
375 m_xComponent.clear();
376 m_xPropertyState.clear();
378 // create an introspection adapter for the component
379 Reference< XIntrospection > xIntrospection = Introspection::create( m_aContext.getUNOContext() );
381 Reference< XIntrospectionAccess > xIntrospectionAccess( xIntrospection->inspect( makeAny( _rxIntrospectee ) ) );
382 if ( !xIntrospectionAccess.is() )
383 throw RuntimeException( OUString( "The introspection service could not handle the given component." ), *this );
385 m_xComponent = Reference< XPropertySet >( xIntrospectionAccess->queryAdapter( XPropertySet::static_type() ), UNO_QUERY_THROW );
386 // now that we survived so far, remember m_xComponentIntrospectionAccess
387 m_xComponentIntrospectionAccess = xIntrospectionAccess;
388 m_xPropertyState = m_xPropertyState.query( m_xComponent );
390 m_bPropertyMapInitialized = false;
391 m_aProperties.clear();
393 // re-add the property change listeners
394 while ( iterReAdd.hasMoreElements() )
395 m_xComponent->addPropertyChangeListener( OUString(), static_cast< XPropertyChangeListener* >( iterReAdd.next() ) );
398 //--------------------------------------------------------------------
399 Any SAL_CALL GenericPropertyHandler::getPropertyValue( const OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
401 ::osl::MutexGuard aGuard( m_aMutex );
402 if ( !m_xComponent.is() )
403 throw UnknownPropertyException();
405 return m_xComponent->getPropertyValue( _rPropertyName );
408 //--------------------------------------------------------------------
409 void SAL_CALL GenericPropertyHandler::setPropertyValue( const OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException)
411 ::osl::MutexGuard aGuard( m_aMutex );
412 if ( !m_xComponent.is() )
413 throw UnknownPropertyException();
415 m_xComponent->setPropertyValue( _rPropertyName, _rValue );
418 //--------------------------------------------------------------------
419 ::rtl::Reference< IPropertyEnumRepresentation > GenericPropertyHandler::impl_getEnumConverter( const Type& _rEnumType )
421 ::rtl::Reference< IPropertyEnumRepresentation >& rConverter = m_aEnumConverters[ _rEnumType ];
422 if ( !rConverter.is() )
423 rConverter = new EnumRepresentation( m_aContext.getUNOContext(), _rEnumType );
424 return rConverter;
427 //--------------------------------------------------------------------
428 Any SAL_CALL GenericPropertyHandler::convertToPropertyValue( const OUString& _rPropertyName, const Any& _rControlValue ) throw (UnknownPropertyException, RuntimeException)
430 ::osl::MutexGuard aGuard( m_aMutex );
431 const_cast< GenericPropertyHandler* >( this )->impl_ensurePropertyMap();
433 PropertyMap::const_iterator pos = m_aProperties.find( _rPropertyName );
434 if ( pos == m_aProperties.end() )
435 throw UnknownPropertyException();
437 Any aPropertyValue;
438 if ( !_rControlValue.hasValue() )
439 // NULL is converted to NULL
440 return aPropertyValue;
442 if ( pos->second.Type.getTypeClass() == TypeClass_ENUM )
444 OUString sControlValue;
445 OSL_VERIFY( _rControlValue >>= sControlValue );
446 impl_getEnumConverter( pos->second.Type )->getValueFromDescription( sControlValue, aPropertyValue );
448 else
449 aPropertyValue = PropertyHandlerHelper::convertToPropertyValue( m_aContext.getContext(),m_xTypeConverter, pos->second, _rControlValue );
451 return aPropertyValue;
454 //--------------------------------------------------------------------
455 Any SAL_CALL GenericPropertyHandler::convertToControlValue( const OUString& _rPropertyName, const Any& _rPropertyValue, const Type& _rControlValueType ) throw (UnknownPropertyException, RuntimeException)
457 ::osl::MutexGuard aGuard( m_aMutex );
458 const_cast< GenericPropertyHandler* >( this )->impl_ensurePropertyMap();
460 PropertyMap::const_iterator pos = m_aProperties.find( _rPropertyName );
461 if ( pos == m_aProperties.end() )
462 throw UnknownPropertyException();
464 Any aControlValue;
465 if ( !_rPropertyValue.hasValue() )
466 // NULL is converted to NULL
467 return aControlValue;
469 if ( pos->second.Type.getTypeClass() == TypeClass_ENUM )
471 aControlValue <<= impl_getEnumConverter( pos->second.Type )->getDescriptionForValue( _rPropertyValue );
473 else
474 aControlValue = PropertyHandlerHelper::convertToControlValue( m_aContext.getContext(),m_xTypeConverter, _rPropertyValue, _rControlValueType );
475 return aControlValue;
478 //--------------------------------------------------------------------
479 PropertyState SAL_CALL GenericPropertyHandler::getPropertyState( const OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
481 ::osl::MutexGuard aGuard( m_aMutex );
482 PropertyState eState = PropertyState_DIRECT_VALUE;
483 if ( m_xPropertyState.is() )
484 eState = m_xPropertyState->getPropertyState( _rPropertyName );
485 return eState;
488 //--------------------------------------------------------------------
489 void SAL_CALL GenericPropertyHandler::addPropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener ) throw (RuntimeException)
491 if ( !_rxListener.is() )
492 throw NullPointerException();
494 ::osl::MutexGuard aGuard( m_aMutex );
495 m_aPropertyListeners.addInterface( _rxListener );
496 if ( m_xComponent.is() )
500 m_xComponent->addPropertyChangeListener( OUString(), _rxListener );
502 catch( const UnknownPropertyException& )
504 OSL_FAIL( "GenericPropertyHandler::addPropertyChangeListener:\nThe inspected component does not allow registering for all properties at once! This violates the interface contract!" );
509 //--------------------------------------------------------------------
510 void SAL_CALL GenericPropertyHandler::removePropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener ) throw (RuntimeException)
512 ::osl::MutexGuard aGuard( m_aMutex );
513 if ( m_xComponent.is() )
517 m_xComponent->removePropertyChangeListener( OUString(), _rxListener );
519 catch( const UnknownPropertyException& )
521 OSL_FAIL( "GenericPropertyHandler::removePropertyChangeListener:\nThe inspected component does not allow de-registering for all properties at once! This violates the interface contract!" );
524 m_aPropertyListeners.removeInterface( _rxListener );
527 //--------------------------------------------------------------------
528 void GenericPropertyHandler::impl_ensurePropertyMap()
530 if ( !m_bPropertyMapInitialized )
532 m_bPropertyMapInitialized = true;
535 Reference< XPropertySetInfo > xPSI;
536 if ( m_xComponent.is() )
537 xPSI = m_xComponent->getPropertySetInfo();
538 Sequence< Property > aProperties;
539 if ( xPSI.is() )
540 aProperties = xPSI->getProperties();
541 DBG_ASSERT( aProperties.getLength(), "GenericPropertyHandler::getSupportedProperties: no properties!" );
543 for ( const Property* pProperties = aProperties.getConstArray();
544 pProperties != aProperties.getConstArray() + aProperties.getLength();
545 ++pProperties
548 switch ( pProperties->Type.getTypeClass() )
550 case TypeClass_BOOLEAN:
551 case TypeClass_BYTE:
552 case TypeClass_SHORT:
553 case TypeClass_UNSIGNED_SHORT:
554 case TypeClass_LONG:
555 case TypeClass_UNSIGNED_LONG:
556 case TypeClass_HYPER:
557 case TypeClass_UNSIGNED_HYPER:
558 case TypeClass_FLOAT:
559 case TypeClass_DOUBLE:
560 case TypeClass_ENUM:
561 case TypeClass_STRING:
562 // allowed, we can handle this type
563 break;
565 case TypeClass_SEQUENCE:
567 TypeClass eElementTypeClass = ::comphelper::getSequenceElementType( pProperties->Type ).getTypeClass();
568 if ( ( eElementTypeClass != TypeClass_STRING )
569 && ( eElementTypeClass != TypeClass_BYTE )
570 && ( eElementTypeClass != TypeClass_SHORT )
571 && ( eElementTypeClass != TypeClass_UNSIGNED_SHORT )
572 && ( eElementTypeClass != TypeClass_LONG )
573 && ( eElementTypeClass != TypeClass_UNSIGNED_LONG )
575 // can only handle the above
576 continue;
578 break;
580 default:
581 // next property, we don't support this type
582 continue;
585 m_aProperties.insert( PropertyMap::value_type( pProperties->Name, *pProperties ) );
588 catch( const Exception& )
590 OSL_FAIL( "GenericPropertyHandler::impl_ensurePropertyMap: caught an exception!" );
595 //--------------------------------------------------------------------
596 Sequence< Property > SAL_CALL GenericPropertyHandler::getSupportedProperties() throw (RuntimeException)
598 ::osl::MutexGuard aGuard( m_aMutex );
599 const_cast< GenericPropertyHandler* >( this )->impl_ensurePropertyMap();
601 Sequence< Property > aReturn( m_aProperties.size() );
602 ::std::transform( m_aProperties.begin(), m_aProperties.end(),
603 aReturn.getArray(), ::o3tl::select2nd< PropertyMap::value_type >() );
604 return aReturn;
607 //--------------------------------------------------------------------
608 Sequence< OUString > SAL_CALL GenericPropertyHandler::getSupersededProperties( ) throw (RuntimeException)
610 // no superseded properties at all. This handler offers the very basic PropertyHandler
611 // functionality, so it's much more likely that other handlers want to supersede
612 // *our* properties ....
613 return Sequence< OUString >( );
616 //--------------------------------------------------------------------
617 Sequence< OUString > SAL_CALL GenericPropertyHandler::getActuatingProperties( ) throw (RuntimeException)
619 // This basic PropertyHandler implementation is too dumb^Wgeneric to know
620 // anything about property dependencies
621 return Sequence< OUString >( );
624 //--------------------------------------------------------------------
625 LineDescriptor SAL_CALL GenericPropertyHandler::describePropertyLine( const OUString& _rPropertyName,
626 const Reference< XPropertyControlFactory >& _rxControlFactory )
627 throw (UnknownPropertyException, NullPointerException, RuntimeException)
629 if ( !_rxControlFactory.is() )
630 throw NullPointerException();
632 ::osl::MutexGuard aGuard( m_aMutex );
633 const_cast< GenericPropertyHandler* >( this )->impl_ensurePropertyMap();
635 PropertyMap::const_iterator pos = m_aProperties.find( _rPropertyName );
636 if ( pos == m_aProperties.end() )
637 throw UnknownPropertyException();
639 LineDescriptor aDescriptor;
640 aDescriptor.DisplayName = _rPropertyName;
641 switch ( pos->second.Type.getTypeClass() )
643 case TypeClass_ENUM:
644 aDescriptor.Control = PropertyHandlerHelper::createListBoxControl( _rxControlFactory,
645 impl_getEnumConverter( pos->second.Type )->getDescriptions(),
646 PropertyHandlerHelper::requiresReadOnlyControl( pos->second.Attributes ),
647 sal_False );
648 break;
649 case TypeClass_STRING:
651 // some special handling for URL properties
652 bool bIsURLProperty = ( _rPropertyName.getLength() >= 3 ) && _rPropertyName.matchAsciiL( "URL", 3, _rPropertyName.getLength() - 3 );
653 if ( bIsURLProperty )
655 aDescriptor.Control = _rxControlFactory->createPropertyControl(
656 PropertyControlType::HyperlinkField, PropertyHandlerHelper::requiresReadOnlyControl( pos->second.Attributes ) );
658 Reference< XHyperlinkControl > xControl( aDescriptor.Control, UNO_QUERY_THROW );
659 Reference< XActionListener > xEnsureDelete( new UrlClickHandler( m_aContext, xControl ) );
662 break;
663 default:
664 break;
666 // fallback
667 if ( !aDescriptor.Control.is() )
668 PropertyHandlerHelper::describePropertyLine( pos->second, aDescriptor, _rxControlFactory );
670 aDescriptor.Category = OUString( "General" );
671 return aDescriptor;
674 //--------------------------------------------------------------------
675 ::sal_Bool SAL_CALL GenericPropertyHandler::isComposable( const OUString& /*_rPropertyName*/ ) throw (UnknownPropertyException, RuntimeException)
677 return sal_False;
680 //--------------------------------------------------------------------
681 InteractiveSelectionResult SAL_CALL GenericPropertyHandler::onInteractivePropertySelection( const OUString& /*_rPropertyName*/, sal_Bool /*_bPrimary*/, Any& /*_rData*/, const Reference< XObjectInspectorUI >& /*_rxInspectorUI*/ ) throw (UnknownPropertyException, NullPointerException, RuntimeException)
683 OSL_FAIL( "GenericPropertyHandler::onInteractivePropertySelection: I'm too dumb to know anything about property browse buttons!" );
684 return InteractiveSelectionResult_Cancelled;
687 //--------------------------------------------------------------------
688 void SAL_CALL GenericPropertyHandler::actuatingPropertyChanged( const OUString& /*_rActuatingPropertyName*/, const Any& /*_rNewValue*/, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& /*_rxInspectorUI*/, sal_Bool /*_bFirstTimeInit*/ ) throw (NullPointerException, RuntimeException)
690 OSL_FAIL( "GenericPropertyHandler::actuatingPropertyChanged: no no no, I did not register for any actuating properties!" );
693 //--------------------------------------------------------------------
694 sal_Bool SAL_CALL GenericPropertyHandler::suspend( sal_Bool /*_bSuspend*/ ) throw (RuntimeException)
696 return sal_True;
699 //--------------------------------------------------------------------
700 void SAL_CALL GenericPropertyHandler::disposing()
702 m_aPropertyListeners.clear();
703 // not disposeAndClear: the listeners are (virtually) listeners at our introspectee, not
704 // at this handler instance
707 //--------------------------------------------------------------------
708 IMPLEMENT_FORWARD_XCOMPONENT( GenericPropertyHandler, GenericPropertyHandler_Base );
710 //........................................................................
711 } // namespace pcr
712 //........................................................................
714 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */