24#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
25#include <com/sun/star/lang/NullPointerException.hpp>
26#include <com/sun/star/reflection/XEnumTypeDescription.hpp>
27#include <com/sun/star/beans/theIntrospection.hpp>
28#include <com/sun/star/inspection/PropertyControlType.hpp>
29#include <com/sun/star/inspection/XHyperlinkControl.hpp>
30#include <com/sun/star/awt/XActionListener.hpp>
31#include <com/sun/star/script/Converter.hpp>
32#include <com/sun/star/util/URLTransformer.hpp>
33#include <com/sun/star/util/XURLTransformer.hpp>
34#include <com/sun/star/frame/Desktop.hpp>
60 using ::com::sun::star::awt::XActionListener;
61 using ::com::sun::star::awt::ActionEvent;
65 class EnumRepresentation :
public IPropertyEnumRepresentation
68 Reference< XEnumTypeDescription > m_xTypeDescription;
72 EnumRepresentation(
const Reference< XComponentContext >& _rxContext,
const Type& _rEnumType );
73 EnumRepresentation(
const EnumRepresentation&) =
delete;
74 EnumRepresentation& operator=(
const EnumRepresentation&) =
delete;
77 virtual std::vector< OUString >
78 getDescriptions()
const override;
79 virtual void getValueFromDescription(
const OUString& _rDescription, css::uno::Any& _out_rValue )
const override;
80 virtual OUString getDescriptionForValue(
const css::uno::Any& _rEnumValue )
const override;
83 void impl_getValues( Sequence< sal_Int32 >& _out_rValues )
const;
88 EnumRepresentation::EnumRepresentation(
const Reference< XComponentContext >& _rxContext,
const Type& _rEnumType )
89 :m_aEnumType( _rEnumType )
93 if ( _rxContext.is() )
95 Reference< XHierarchicalNameAccess > xTypeDescProv(
96 _rxContext->getValueByName(
"/singletons/com.sun.star.reflection.theTypeDescriptionManager"),
99 m_xTypeDescription.set( xTypeDescProv->getByHierarchicalName( m_aEnumType.getTypeName() ), UNO_QUERY_THROW );
102 catch(
const Exception& )
108 std::vector< OUString > EnumRepresentation::getDescriptions()
const
110 Sequence< OUString > aNames;
113 if ( m_xTypeDescription.is() )
114 aNames = m_xTypeDescription->getEnumNames();
116 catch(
const Exception& )
121 return std::vector< OUString >( std::cbegin(aNames), std::cend(aNames) );
124 void EnumRepresentation::impl_getValues( Sequence< sal_Int32 >& _out_rValues )
const
126 _out_rValues.realloc( 0 );
129 if ( m_xTypeDescription.is() )
130 _out_rValues = m_xTypeDescription->getEnumValues();
132 catch(
const Exception& )
138 void EnumRepresentation::getValueFromDescription(
const OUString& _rDescription, Any& _out_rValue )
const
140 std::vector< OUString > aDescriptions( getDescriptions() );
142 sal_Int32
index = std::find( aDescriptions.begin(), aDescriptions.end(),
143 _rDescription ) - aDescriptions.begin();
145 Sequence< sal_Int32 > aValues;
146 impl_getValues( aValues );
148 if ( ( index >= 0 ) && ( index < aValues.getLength() ) )
149 _out_rValue = ::cppu::int2enum( aValues[ index ], m_aEnumType );
152 OSL_FAIL(
"EnumRepresentation::getValueFromDescription: cannot convert!" );
157 OUString EnumRepresentation::getDescriptionForValue(
const Any& _rEnumValue )
const
159 OUString sDescription;
161 sal_Int32 nAsInt = 0;
162 OSL_VERIFY( ::cppu::enum2int( nAsInt, _rEnumValue ) );
164 Sequence< sal_Int32 > aValues;
165 impl_getValues( aValues );
167 sal_Int32
index = std::find( std::cbegin(aValues), std::cend(aValues), nAsInt ) - std::cbegin(aValues);
169 std::vector< OUString > aDescriptions( getDescriptions() );
171 sDescription = aDescriptions[
index ];
174 OSL_FAIL(
"EnumRepresentation::getDescriptionForValue: cannot convert!" );
179 typedef ::cppu::WeakImplHelper < XActionListener
188 UrlClickHandler(
const Reference<XComponentContext>& _rContext,
const Reference< XHyperlinkControl >& _rxControl );
191 virtual ~UrlClickHandler()
override;
194 virtual void SAL_CALL
actionPerformed(
const ActionEvent& rEvent )
override;
197 virtual void SAL_CALL disposing(
const EventObject&
Source )
override;
200 void impl_dispatch_throw(
const OUString& _rURL );
205 UrlClickHandler::UrlClickHandler(
const Reference<XComponentContext>& _rContext,
const Reference< XHyperlinkControl >& _rxControl )
208 if ( !_rxControl.is() )
209 throw NullPointerException();
211 osl_atomic_increment( &m_refCount );
213 _rxControl->addActionListener(
this );
215 osl_atomic_decrement( &m_refCount );
216 OSL_ENSURE( m_refCount > 0,
"UrlClickHandler::UrlClickHandler: leaking!" );
220 UrlClickHandler::~UrlClickHandler()
224 void SAL_CALL UrlClickHandler::actionPerformed(
const ActionEvent& rEvent )
226 Reference< XPropertyControl > xControl( rEvent.Source, UNO_QUERY_THROW );
227 Any aControlValue( xControl->getValue() );
230 if ( aControlValue.hasValue() && !( aControlValue >>= sURL ) )
233 if ( sURL.isEmpty() )
236 impl_dispatch_throw( sURL );
239 void SAL_CALL UrlClickHandler::disposing(
const EventObject& )
244 void UrlClickHandler::impl_dispatch_throw(
const OUString& _rURL )
246 Reference< XURLTransformer > xTransformer( URLTransformer::create(
m_xContext) );
248 xTransformer->parseStrict( aURL );
250 Reference< XDesktop2 > xDispProv = Desktop::create(
m_xContext );
251 Reference< XDispatch >
xDispatch( xDispProv->queryDispatch( aURL, OUString(), 0 ), UNO_SET_THROW );
255 xDispatch->dispatch( aURL, aDispatchArgs );
259 GenericPropertyHandler::GenericPropertyHandler(
const Reference< XComponentContext >& _rxContext )
263 ,m_bPropertyMapInitialized( false )
265 m_xTypeConverter = Converter::create(_rxContext);
268 GenericPropertyHandler::~GenericPropertyHandler()
272 OUString SAL_CALL GenericPropertyHandler::getImplementationName( )
274 return "com.sun.star.comp.extensions.GenericPropertyHandler";
277 sal_Bool SAL_CALL GenericPropertyHandler::supportsService(
const OUString& ServiceName )
282 Sequence< OUString > SAL_CALL GenericPropertyHandler::getSupportedServiceNames( )
284 return {
"com.sun.star.inspection.GenericPropertyHandler" };
289 ::osl::MutexGuard aGuard(
m_aMutex );
291 if ( !_rxIntrospectee.is() )
292 throw NullPointerException();
298 m_xComponent->removePropertyChangeListener( OUString(),
static_cast< XPropertyChangeListener*
>( iterRemove.
next() ) );
300 m_xComponentIntrospectionAccess.clear();
301 m_xComponent.clear();
302 m_xPropertyState.clear();
307 Reference< XIntrospectionAccess > xIntrospectionAccess(
xIntrospection->inspect(
Any( _rxIntrospectee ) ) );
308 if ( !xIntrospectionAccess.is() )
309 throw RuntimeException(
"The introspection service could not handle the given component.", *
this );
313 m_xComponentIntrospectionAccess = xIntrospectionAccess;
314 m_xPropertyState.set(m_xComponent, css::uno::UNO_QUERY);
316 m_bPropertyMapInitialized =
false;
317 m_aProperties.clear();
321 m_xComponent->addPropertyChangeListener( OUString(),
static_cast< XPropertyChangeListener*
>( iterReAdd.
next() ) );
324 Any SAL_CALL GenericPropertyHandler::getPropertyValue(
const OUString& _rPropertyName )
326 ::osl::MutexGuard aGuard(
m_aMutex );
327 if ( !m_xComponent.is() )
328 throw UnknownPropertyException(_rPropertyName);
330 return m_xComponent->getPropertyValue( _rPropertyName );
333 void SAL_CALL GenericPropertyHandler::setPropertyValue(
const OUString& _rPropertyName,
const Any& _rValue )
335 ::osl::MutexGuard aGuard(
m_aMutex );
336 if ( !m_xComponent.is() )
337 throw UnknownPropertyException(_rPropertyName);
339 m_xComponent->setPropertyValue( _rPropertyName, _rValue );
345 if ( !rConverter.is() )
346 rConverter =
new EnumRepresentation(
m_xContext, _rEnumType );
350 Any SAL_CALL GenericPropertyHandler::convertToPropertyValue(
const OUString& _rPropertyName,
const Any& _rControlValue )
352 ::osl::MutexGuard aGuard(
m_aMutex );
353 impl_ensurePropertyMap();
355 PropertyMap::const_iterator
pos = m_aProperties.find( _rPropertyName );
356 if (
pos == m_aProperties.end() )
357 throw UnknownPropertyException(_rPropertyName);
360 if ( !_rControlValue.hasValue() )
362 return aPropertyValue;
364 if (
pos->second.Type.getTypeClass() == TypeClass_ENUM )
366 OUString sControlValue;
367 OSL_VERIFY( _rControlValue >>= sControlValue );
368 impl_getEnumConverter(
pos->second.Type )->getValueFromDescription( sControlValue, aPropertyValue );
371 aPropertyValue = PropertyHandlerHelper::convertToPropertyValue(
m_xContext, m_xTypeConverter,
pos->second, _rControlValue );
373 return aPropertyValue;
376 Any SAL_CALL GenericPropertyHandler::convertToControlValue(
const OUString& _rPropertyName,
const Any& _rPropertyValue,
const Type& _rControlValueType )
378 ::osl::MutexGuard aGuard(
m_aMutex );
379 impl_ensurePropertyMap();
381 PropertyMap::const_iterator
pos = m_aProperties.find( _rPropertyName );
382 if (
pos == m_aProperties.end() )
383 throw UnknownPropertyException(_rPropertyName);
386 if ( !_rPropertyValue.hasValue() )
388 return aControlValue;
390 if (
pos->second.Type.getTypeClass() == TypeClass_ENUM )
392 aControlValue <<= impl_getEnumConverter(
pos->second.Type )->getDescriptionForValue( _rPropertyValue );
395 aControlValue = PropertyHandlerHelper::convertToControlValue(
m_xContext, m_xTypeConverter, _rPropertyValue, _rControlValueType );
396 return aControlValue;
399 PropertyState SAL_CALL GenericPropertyHandler::getPropertyState(
const OUString& _rPropertyName )
401 ::osl::MutexGuard aGuard(
m_aMutex );
402 PropertyState eState = PropertyState_DIRECT_VALUE;
403 if ( m_xPropertyState.is() )
404 eState = m_xPropertyState->getPropertyState( _rPropertyName );
408 void SAL_CALL GenericPropertyHandler::addPropertyChangeListener(
const Reference< XPropertyChangeListener >& _rxListener)
410 if ( !_rxListener.is() )
411 throw NullPointerException();
413 ::osl::MutexGuard aGuard(
m_aMutex );
414 m_aPropertyListeners.addInterface( _rxListener );
415 if ( m_xComponent.is() )
419 m_xComponent->addPropertyChangeListener( OUString(), _rxListener );
421 catch(
const UnknownPropertyException& )
423 OSL_FAIL(
"GenericPropertyHandler::addPropertyChangeListener:\nThe inspected component does not allow registering for all properties at once! This violates the interface contract!" );
428 void SAL_CALL GenericPropertyHandler::removePropertyChangeListener(
const Reference< XPropertyChangeListener >& _rxListener )
430 ::osl::MutexGuard aGuard(
m_aMutex );
431 if ( m_xComponent.is() )
435 m_xComponent->removePropertyChangeListener( OUString(), _rxListener );
437 catch(
const UnknownPropertyException& )
439 OSL_FAIL(
"GenericPropertyHandler::removePropertyChangeListener:\nThe inspected component does not allow de-registering for all properties at once! This violates the interface contract!" );
442 m_aPropertyListeners.removeInterface( _rxListener );
445 void GenericPropertyHandler::impl_ensurePropertyMap()
447 if ( m_bPropertyMapInitialized )
450 m_bPropertyMapInitialized =
true;
453 Reference< XPropertySetInfo > xPSI;
454 if ( m_xComponent.is() )
455 xPSI = m_xComponent->getPropertySetInfo();
459 DBG_ASSERT(
aProperties.hasElements(),
"GenericPropertyHandler::getSupportedProperties: no properties!" );
463 switch (
property.Type.getTypeClass() )
465 case TypeClass_BOOLEAN:
467 case TypeClass_SHORT:
468 case TypeClass_UNSIGNED_SHORT:
470 case TypeClass_UNSIGNED_LONG:
471 case TypeClass_HYPER:
472 case TypeClass_UNSIGNED_HYPER:
473 case TypeClass_FLOAT:
474 case TypeClass_DOUBLE:
476 case TypeClass_STRING:
480 case TypeClass_SEQUENCE:
482 TypeClass eElementTypeClass = ::comphelper::getSequenceElementType(
property.Type ).getTypeClass();
483 if ( ( eElementTypeClass != TypeClass_STRING )
484 && ( eElementTypeClass != TypeClass_BYTE )
485 && ( eElementTypeClass != TypeClass_SHORT )
486 && ( eElementTypeClass != TypeClass_UNSIGNED_SHORT )
487 && ( eElementTypeClass != TypeClass_LONG )
488 && ( eElementTypeClass != TypeClass_UNSIGNED_LONG )
505 TOOLS_WARN_EXCEPTION(
"extensions.propctrlr",
"GenericPropertyHandler::impl_ensurePropertyMap" );
509 Sequence< Property > SAL_CALL GenericPropertyHandler::getSupportedProperties()
511 ::osl::MutexGuard aGuard(
m_aMutex );
512 impl_ensurePropertyMap();
517 Sequence< OUString > SAL_CALL GenericPropertyHandler::getSupersededProperties( )
522 return Sequence< OUString >( );
525 Sequence< OUString > SAL_CALL GenericPropertyHandler::getActuatingProperties( )
529 return Sequence< OUString >( );
532 LineDescriptor SAL_CALL GenericPropertyHandler::describePropertyLine(
const OUString& _rPropertyName,
533 const Reference< XPropertyControlFactory >& _rxControlFactory )
535 if ( !_rxControlFactory.is() )
536 throw NullPointerException();
538 ::osl::MutexGuard aGuard(
m_aMutex );
539 impl_ensurePropertyMap();
541 PropertyMap::const_iterator
pos = m_aProperties.find( _rPropertyName );
542 if (
pos == m_aProperties.end() )
543 throw UnknownPropertyException(_rPropertyName);
545 LineDescriptor aDescriptor;
546 aDescriptor.DisplayName = _rPropertyName;
547 switch (
pos->second.Type.getTypeClass() )
550 aDescriptor.Control = PropertyHandlerHelper::createListBoxControl( _rxControlFactory,
551 impl_getEnumConverter(
pos->second.Type )->getDescriptions(),
552 PropertyHandlerHelper::requiresReadOnlyControl(
pos->second.Attributes ),
555 case TypeClass_STRING:
558 bool bIsURLProperty = _rPropertyName.endsWith(
"URL" );
559 if ( bIsURLProperty )
561 aDescriptor.Control = _rxControlFactory->createPropertyControl(
562 PropertyControlType::HyperlinkField, PropertyHandlerHelper::requiresReadOnlyControl(
pos->second.Attributes ) );
564 Reference< XHyperlinkControl > xControl( aDescriptor.Control, UNO_QUERY_THROW );
573 if ( !aDescriptor.Control.is() )
574 PropertyHandlerHelper::describePropertyLine(
pos->second, aDescriptor, _rxControlFactory );
576 aDescriptor.Category =
"General";
580 sal_Bool SAL_CALL GenericPropertyHandler::isComposable(
const OUString& )
585 InteractiveSelectionResult SAL_CALL GenericPropertyHandler::onInteractivePropertySelection(
const OUString& ,
sal_Bool , Any& ,
const Reference< XObjectInspectorUI >& )
587 OSL_FAIL(
"GenericPropertyHandler::onInteractivePropertySelection: I'm too dumb to know anything about property browse buttons!" );
588 return InteractiveSelectionResult_Cancelled;
591 void SAL_CALL GenericPropertyHandler::actuatingPropertyChanged(
const OUString& ,
const Any& ,
const Any& ,
const Reference< XObjectInspectorUI >& ,
sal_Bool )
593 OSL_FAIL(
"GenericPropertyHandler::actuatingPropertyChanged: no no no, I did not register for any actuating properties!" );
601 void SAL_CALL GenericPropertyHandler::disposing()
603 m_aPropertyListeners.clear();
612extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
614 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any>
const&)
PropertiesInfo aProperties
css::uno::XInterface * next()
bool hasMoreElements() const
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XDispatch > xDispatch
Reference< XComponentContext > m_xContext
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * extensions_propctrlr_GenericPropertyHandler_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Reference< XIntrospection > xIntrospection
DECL_LISTENERMULTIPLEXER_END void SAL_CALL actionPerformed(const css::awt::ActionEvent &rEvent) override
css::uno::Sequence< typename M::mapped_type > mapValuesToSequence(M const &map)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
a property handler for any virtual string properties
::cppu::WeakComponentImplHelper< css::inspection::XPropertyHandler, css::lang::XServiceInfo > GenericPropertyHandler_Base
::cppu::WeakImplHelper< XActionListener > UrlClickHandler_Base
#define IMPLEMENT_FORWARD_XCOMPONENT(classname, baseclass)