LCOV - code coverage report
Current view: top level - extensions/source/propctrlr - genericpropertyhandler.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 61 266 22.9 %
Date: 2014-11-03 Functions: 14 47 29.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include "genericpropertyhandler.hxx"
      21             : #include "formmetadata.hxx"
      22             : #include "handlerhelper.hxx"
      23             : #include "pcrservices.hxx"
      24             : 
      25             : #include <boost/noncopyable.hpp>
      26             : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      27             : #include <com/sun/star/reflection/XEnumTypeDescription.hpp>
      28             : #include <com/sun/star/beans/theIntrospection.hpp>
      29             : #include <com/sun/star/inspection/PropertyControlType.hpp>
      30             : #include <com/sun/star/inspection/XHyperlinkControl.hpp>
      31             : #include <com/sun/star/awt/XActionListener.hpp>
      32             : #include <com/sun/star/script/Converter.hpp>
      33             : #include <com/sun/star/util/URLTransformer.hpp>
      34             : #include <com/sun/star/util/XURLTransformer.hpp>
      35             : #include <com/sun/star/frame/Desktop.hpp>
      36             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      37             : 
      38             : #include <cppuhelper/supportsservice.hxx>
      39             : #include <comphelper/extract.hxx>
      40             : #include <tools/debug.hxx>
      41             : 
      42             : #include <algorithm>
      43             : #include <o3tl/compat_functional.hxx>
      44             : 
      45           4 : extern "C" void SAL_CALL createRegistryInfo_GenericPropertyHandler()
      46             : {
      47           4 :     ::pcr::OAutoRegistration< ::pcr::GenericPropertyHandler > aAutoRegistration;
      48           4 : }
      49             : 
      50             : namespace pcr
      51             : {
      52             : 
      53             :     using namespace ::com::sun::star::uno;
      54             :     using namespace ::com::sun::star::beans;
      55             :     using namespace ::com::sun::star::script;
      56             :     using namespace ::com::sun::star::frame;
      57             :     using namespace ::com::sun::star::lang;
      58             :     using namespace ::com::sun::star::util;
      59             :     using namespace ::com::sun::star::container;
      60             :     using namespace ::com::sun::star::reflection;
      61             :     using namespace ::com::sun::star::inspection;
      62             :     using ::com::sun::star::awt::XActionListener;
      63             :     using ::com::sun::star::awt::ActionEvent;
      64             : 
      65           0 :     class EnumRepresentation:
      66             :         public IPropertyEnumRepresentation, private boost::noncopyable
      67             :     {
      68             :     private:
      69             :         Reference< XEnumTypeDescription >   m_xTypeDescription;
      70             :         Type                                m_aEnumType;
      71             : 
      72             :     public:
      73             :         EnumRepresentation( const Reference< XComponentContext >& _rxContext, const Type& _rEnumType );
      74             : 
      75             :         // IPropertyEnumRepresentation implementqation
      76             :         virtual ::std::vector< OUString >
      77             :                                     SAL_CALL getDescriptions() const SAL_OVERRIDE;
      78             :         virtual void                SAL_CALL getValueFromDescription( const OUString& _rDescription, ::com::sun::star::uno::Any& _out_rValue ) const SAL_OVERRIDE;
      79             :         virtual OUString     SAL_CALL getDescriptionForValue( const ::com::sun::star::uno::Any& _rEnumValue ) const SAL_OVERRIDE;
      80             : 
      81             :     private:
      82             :         void            impl_getValues( Sequence< sal_Int32 >& _out_rValues ) const;
      83             :     };
      84             : 
      85           0 :     EnumRepresentation::EnumRepresentation( const Reference< XComponentContext >& _rxContext, const Type& _rEnumType )
      86           0 :         :m_aEnumType( _rEnumType )
      87             :     {
      88             :         try
      89             :         {
      90           0 :             if ( _rxContext.is() )
      91             :             {
      92             :                 Reference< XHierarchicalNameAccess > xTypeDescProv(
      93           0 :                     _rxContext->getValueByName("/singletons/com.sun.star.reflection.theTypeDescriptionManager"),
      94           0 :                     UNO_QUERY_THROW );
      95             : 
      96           0 :                 m_xTypeDescription = Reference< XEnumTypeDescription >( xTypeDescProv->getByHierarchicalName( m_aEnumType.getTypeName() ), UNO_QUERY_THROW );
      97             :             }
      98             :         }
      99           0 :         catch( const Exception& )
     100             :         {
     101             :             OSL_FAIL( "EnumRepresentation::EnumRepresentation: caught an exception!" );
     102             :         }
     103           0 :     }
     104             : 
     105           0 :     ::std::vector< OUString > EnumRepresentation::getDescriptions() const
     106             :     {
     107           0 :         Sequence< OUString > aNames;
     108             :         try
     109             :         {
     110           0 :             if ( m_xTypeDescription.is() )
     111           0 :                 aNames = m_xTypeDescription->getEnumNames();
     112             :         }
     113           0 :         catch( const Exception& )
     114             :         {
     115             :             OSL_FAIL( "EnumRepresentation::getDescriptions: caught an exception!" );
     116             :         }
     117             : 
     118           0 :         return ::std::vector< OUString >( aNames.getConstArray(), aNames.getConstArray() + aNames.getLength() );
     119             :     }
     120             : 
     121           0 :     void EnumRepresentation::impl_getValues( Sequence< sal_Int32 >& _out_rValues ) const
     122             :     {
     123           0 :         _out_rValues.realloc( 0 );
     124             :         try
     125             :         {
     126           0 :             if  ( m_xTypeDescription.is() )
     127           0 :                 _out_rValues = m_xTypeDescription->getEnumValues();
     128             :         }
     129           0 :         catch( const Exception& )
     130             :         {
     131             :             OSL_FAIL( "EnumRepresentation::impl_getValues: caught an exception!" );
     132             :         }
     133           0 :     }
     134             : 
     135           0 :     void EnumRepresentation::getValueFromDescription( const OUString& _rDescription, Any& _out_rValue ) const
     136             :     {
     137           0 :         ::std::vector< OUString > aDescriptions( getDescriptions() );
     138             : 
     139             :         sal_Int32 index = ::std::find( aDescriptions.begin(), aDescriptions.end(),
     140           0 :             _rDescription ) - aDescriptions.begin();
     141             : 
     142           0 :         Sequence< sal_Int32 > aValues;
     143           0 :         impl_getValues( aValues );
     144             : 
     145           0 :         if ( ( index >= 0 ) && ( index < aValues.getLength() ) )
     146           0 :             _out_rValue = ::cppu::int2enum( aValues[ index ], m_aEnumType );
     147             :         else
     148             :         {
     149             :             OSL_FAIL( "EnumRepresentation::getValueFromDescription: cannot convert!" );
     150           0 :             _out_rValue.clear();
     151           0 :         }
     152           0 :     }
     153             : 
     154           0 :     OUString EnumRepresentation::getDescriptionForValue( const Any& _rEnumValue ) const
     155             :     {
     156           0 :         OUString sDescription;
     157             : 
     158           0 :         sal_Int32 nAsInt = 0;
     159           0 :         OSL_VERIFY( ::cppu::enum2int( nAsInt, _rEnumValue ) );
     160             : 
     161           0 :         Sequence< sal_Int32 > aValues;
     162           0 :         impl_getValues( aValues );
     163             : 
     164           0 :         sal_Int32 index = ::std::find( aValues.getConstArray(), aValues.getConstArray() + aValues.getLength(),
     165           0 :             nAsInt ) - aValues.getConstArray();
     166             : 
     167           0 :         ::std::vector< OUString > aDescriptions( getDescriptions() );
     168           0 :         if ( ( index >= 0 ) && ( index < (sal_Int32)aDescriptions.size() ) )
     169           0 :             sDescription = aDescriptions[ index ];
     170             :         else
     171             :         {
     172             :              OSL_FAIL( "EnumRepresentation::getDescriptionForValue: cannot convert!" );
     173             :         }
     174           0 :         return sDescription;
     175             :     }
     176             : 
     177             :     typedef ::cppu::WeakImplHelper1 <   XActionListener
     178             :                                     >   UrlClickHandler_Base;
     179             :     class UrlClickHandler : public UrlClickHandler_Base
     180             :     {
     181             :         Reference<XComponentContext>    m_xContext;
     182             :     public:
     183             :         UrlClickHandler( const Reference<XComponentContext>& _rContext, const Reference< XHyperlinkControl >& _rxControl );
     184             : 
     185             :     protected:
     186             :         virtual ~UrlClickHandler();
     187             : 
     188             :         // XActionListener
     189             :         virtual void SAL_CALL actionPerformed( const ActionEvent& rEvent ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     190             : 
     191             :         // XEventListener
     192             :         virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     193             : 
     194             :     protected:
     195             :         void impl_dispatch_throw( const OUString& _rURL );
     196             :     };
     197             : 
     198             : 
     199           0 :     UrlClickHandler::UrlClickHandler( const Reference<XComponentContext>& _rContext, const Reference< XHyperlinkControl >& _rxControl )
     200           0 :         :m_xContext( _rContext )
     201             :     {
     202           0 :         if ( !_rxControl.is() )
     203           0 :             throw NullPointerException();
     204             : 
     205           0 :         osl_atomic_increment( &m_refCount );
     206             :         {
     207           0 :             _rxControl->addActionListener( this );
     208             :         }
     209           0 :         osl_atomic_decrement( &m_refCount );
     210             :         OSL_ENSURE( m_refCount > 0, "UrlClickHandler::UrlClickHandler: leaking!" );
     211             : 
     212           0 :     }
     213             : 
     214           0 :     UrlClickHandler::~UrlClickHandler()
     215             :     {
     216           0 :     }
     217             : 
     218           0 :     void SAL_CALL UrlClickHandler::actionPerformed( const ActionEvent& rEvent ) throw (RuntimeException, std::exception)
     219             :     {
     220           0 :         Reference< XPropertyControl > xControl( rEvent.Source, UNO_QUERY_THROW );
     221           0 :         Any aControlValue( xControl->getValue() );
     222             : 
     223           0 :         OUString sURL;
     224           0 :         if ( aControlValue.hasValue() && !( aControlValue >>= sURL ) )
     225           0 :             throw RuntimeException( OUString(), *this );
     226             : 
     227           0 :         if ( sURL.isEmpty() )
     228           0 :             return;
     229             : 
     230           0 :         impl_dispatch_throw( sURL );
     231             :     }
     232             : 
     233           0 :     void SAL_CALL UrlClickHandler::disposing( const EventObject& /*Source*/ ) throw (RuntimeException, std::exception)
     234             :     {
     235             :         // not interested in
     236           0 :     }
     237             : 
     238           0 :     void UrlClickHandler::impl_dispatch_throw( const OUString& _rURL )
     239             :     {
     240           0 :         Reference< XURLTransformer > xTransformer( URLTransformer::create(m_xContext) );
     241           0 :         URL aURL; aURL.Complete = ".uno:OpenHyperlink";
     242           0 :         xTransformer->parseStrict( aURL );
     243             : 
     244           0 :         Reference< XDesktop2 > xDispProv = Desktop::create( m_xContext );
     245           0 :         Reference< XDispatch > xDispatch( xDispProv->queryDispatch( aURL, OUString(), 0 ), UNO_QUERY_THROW );
     246             : 
     247           0 :         Sequence< PropertyValue > aDispatchArgs(1);
     248           0 :         aDispatchArgs[0].Name   = "URL";
     249           0 :         aDispatchArgs[0].Value  <<= _rURL;
     250             : 
     251           0 :         xDispatch->dispatch( aURL, aDispatchArgs );
     252           0 :     }
     253             : 
     254             : 
     255          10 :     GenericPropertyHandler::GenericPropertyHandler( const Reference< XComponentContext >& _rxContext )
     256             :         :GenericPropertyHandler_Base( m_aMutex )
     257             :         ,m_xContext( _rxContext )
     258             :         ,m_aPropertyListeners( m_aMutex )
     259          10 :         ,m_bPropertyMapInitialized( false )
     260             :     {
     261          10 :         m_xTypeConverter = Converter::create(_rxContext);
     262          10 :     }
     263             : 
     264          20 :     GenericPropertyHandler::~GenericPropertyHandler()
     265             :     {
     266          20 :     }
     267             : 
     268           0 :     OUString SAL_CALL GenericPropertyHandler::getImplementationName(  ) throw (RuntimeException, std::exception)
     269             :     {
     270           0 :         return getImplementationName_static();
     271             :     }
     272             : 
     273           0 :     sal_Bool SAL_CALL GenericPropertyHandler::supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception)
     274             :     {
     275           0 :         return cppu::supportsService(this, ServiceName);
     276             :     }
     277             : 
     278           0 :     Sequence< OUString > SAL_CALL GenericPropertyHandler::getSupportedServiceNames(  ) throw (RuntimeException, std::exception)
     279             :     {
     280           0 :         return getSupportedServiceNames_static();
     281             :     }
     282             : 
     283           4 :     OUString SAL_CALL GenericPropertyHandler::getImplementationName_static(  ) throw (RuntimeException)
     284             :     {
     285           4 :         return OUString( "com.sun.star.comp.extensions.GenericPropertyHandler" );
     286             :     }
     287             : 
     288           4 :     Sequence< OUString > SAL_CALL GenericPropertyHandler::getSupportedServiceNames_static(  ) throw (RuntimeException)
     289             :     {
     290           4 :         Sequence< OUString > aSupported( 1 );
     291           4 :         aSupported[0] = "com.sun.star.inspection.GenericPropertyHandler";
     292           4 :         return aSupported;
     293             :     }
     294             : 
     295          10 :     Reference< XInterface > SAL_CALL GenericPropertyHandler::Create( const Reference< XComponentContext >& _rxContext )
     296             :     {
     297          10 :         return *( new GenericPropertyHandler( _rxContext ) );
     298             :     }
     299             : 
     300           8 :     void SAL_CALL GenericPropertyHandler::inspect( const Reference< XInterface >& _rxIntrospectee ) throw (RuntimeException, NullPointerException, std::exception)
     301             :     {
     302           8 :         ::osl::MutexGuard aGuard( m_aMutex );
     303             : 
     304           8 :         if ( !_rxIntrospectee.is() )
     305           0 :             throw NullPointerException();
     306             : 
     307             :         // revoke old property change listeners
     308          16 :         ::cppu::OInterfaceIteratorHelper iterRemove( m_aPropertyListeners );
     309          16 :         ::cppu::OInterfaceIteratorHelper iterReAdd( m_aPropertyListeners ); // this holds a copy of the container ...
     310          16 :         while ( iterRemove.hasMoreElements() )
     311           0 :             m_xComponent->removePropertyChangeListener( OUString(), static_cast< XPropertyChangeListener* >( iterRemove.next() ) );
     312             : 
     313           8 :         m_xComponentIntrospectionAccess.clear();
     314           8 :         m_xComponent.clear();
     315           8 :         m_xPropertyState.clear();
     316             : 
     317             :         // create an introspection adapter for the component
     318          16 :         Reference< XIntrospection > xIntrospection = theIntrospection::get( m_xContext );
     319             : 
     320          16 :         Reference< XIntrospectionAccess > xIntrospectionAccess( xIntrospection->inspect( makeAny( _rxIntrospectee ) ) );
     321           8 :         if ( !xIntrospectionAccess.is() )
     322           0 :             throw RuntimeException("The introspection service could not handle the given component.", *this );
     323             : 
     324           8 :         m_xComponent = Reference< XPropertySet >( xIntrospectionAccess->queryAdapter( cppu::UnoType<XPropertySet>::get() ), UNO_QUERY_THROW );
     325             :         // now that we survived so far, remember m_xComponentIntrospectionAccess
     326           8 :         m_xComponentIntrospectionAccess = xIntrospectionAccess;
     327           8 :         m_xPropertyState.set(m_xComponent, css::uno::UNO_QUERY);
     328             : 
     329           8 :         m_bPropertyMapInitialized = false;
     330           8 :         m_aProperties.clear();
     331             : 
     332             :         // re-add the property change listeners
     333          16 :         while ( iterReAdd.hasMoreElements() )
     334           8 :             m_xComponent->addPropertyChangeListener( OUString(), static_cast< XPropertyChangeListener* >( iterReAdd.next() ) );
     335           8 :     }
     336             : 
     337           0 :     Any SAL_CALL GenericPropertyHandler::getPropertyValue( const OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException, std::exception)
     338             :     {
     339           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     340           0 :         if ( !m_xComponent.is() )
     341           0 :             throw UnknownPropertyException();
     342             : 
     343           0 :         return m_xComponent->getPropertyValue( _rPropertyName );
     344             :     }
     345             : 
     346           0 :     void SAL_CALL GenericPropertyHandler::setPropertyValue( const OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException, std::exception)
     347             :     {
     348           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     349           0 :         if ( !m_xComponent.is() )
     350           0 :             throw UnknownPropertyException();
     351             : 
     352           0 :         m_xComponent->setPropertyValue( _rPropertyName, _rValue );
     353           0 :     }
     354             : 
     355           0 :     ::rtl::Reference< IPropertyEnumRepresentation > GenericPropertyHandler::impl_getEnumConverter( const Type& _rEnumType )
     356             :     {
     357           0 :         ::rtl::Reference< IPropertyEnumRepresentation >& rConverter = m_aEnumConverters[ _rEnumType ];
     358           0 :         if ( !rConverter.is() )
     359           0 :             rConverter = new EnumRepresentation( m_xContext, _rEnumType );
     360           0 :         return rConverter;
     361             :     }
     362             : 
     363           0 :     Any SAL_CALL GenericPropertyHandler::convertToPropertyValue( const OUString& _rPropertyName, const Any& _rControlValue ) throw (UnknownPropertyException, RuntimeException, std::exception)
     364             :     {
     365           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     366           0 :         const_cast< GenericPropertyHandler* >( this )->impl_ensurePropertyMap();
     367             : 
     368           0 :         PropertyMap::const_iterator pos = m_aProperties.find( _rPropertyName );
     369           0 :         if ( pos == m_aProperties.end() )
     370           0 :             throw UnknownPropertyException();
     371             : 
     372           0 :         Any aPropertyValue;
     373           0 :         if ( !_rControlValue.hasValue() )
     374             :             // NULL is converted to NULL
     375           0 :             return aPropertyValue;
     376             : 
     377           0 :         if ( pos->second.Type.getTypeClass() == TypeClass_ENUM )
     378             :         {
     379           0 :             OUString sControlValue;
     380           0 :             OSL_VERIFY( _rControlValue >>= sControlValue );
     381           0 :             impl_getEnumConverter( pos->second.Type )->getValueFromDescription( sControlValue, aPropertyValue );
     382             :         }
     383             :         else
     384           0 :             aPropertyValue = PropertyHandlerHelper::convertToPropertyValue( m_xContext, m_xTypeConverter, pos->second, _rControlValue );
     385             : 
     386           0 :         return aPropertyValue;
     387             :     }
     388             : 
     389           0 :     Any SAL_CALL GenericPropertyHandler::convertToControlValue( const OUString& _rPropertyName, const Any& _rPropertyValue, const Type& _rControlValueType ) throw (UnknownPropertyException, RuntimeException, std::exception)
     390             :     {
     391           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     392           0 :         const_cast< GenericPropertyHandler* >( this )->impl_ensurePropertyMap();
     393             : 
     394           0 :         PropertyMap::const_iterator pos = m_aProperties.find( _rPropertyName );
     395           0 :         if ( pos == m_aProperties.end() )
     396           0 :             throw UnknownPropertyException();
     397             : 
     398           0 :         Any aControlValue;
     399           0 :         if ( !_rPropertyValue.hasValue() )
     400             :             // NULL is converted to NULL
     401           0 :             return aControlValue;
     402             : 
     403           0 :         if ( pos->second.Type.getTypeClass() == TypeClass_ENUM )
     404             :         {
     405           0 :             aControlValue <<= impl_getEnumConverter( pos->second.Type )->getDescriptionForValue( _rPropertyValue );
     406             :         }
     407             :         else
     408           0 :             aControlValue = PropertyHandlerHelper::convertToControlValue( m_xContext, m_xTypeConverter, _rPropertyValue, _rControlValueType );
     409           0 :         return aControlValue;
     410             :     }
     411             : 
     412           0 :     PropertyState SAL_CALL GenericPropertyHandler::getPropertyState( const OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException, std::exception)
     413             :     {
     414           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     415           0 :         PropertyState eState = PropertyState_DIRECT_VALUE;
     416           0 :         if ( m_xPropertyState.is() )
     417           0 :             eState = m_xPropertyState->getPropertyState( _rPropertyName );
     418           0 :         return eState;
     419             :     }
     420             : 
     421           0 :     void SAL_CALL GenericPropertyHandler::addPropertyChangeListener(const Reference< XPropertyChangeListener >& _rxListener)
     422             :         throw (NullPointerException, RuntimeException, std::exception)
     423             :     {
     424           0 :         if ( !_rxListener.is() )
     425           0 :             throw NullPointerException();
     426             : 
     427           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     428           0 :         m_aPropertyListeners.addInterface( _rxListener );
     429           0 :         if ( m_xComponent.is() )
     430             :         {
     431             :             try
     432             :             {
     433           0 :                 m_xComponent->addPropertyChangeListener( OUString(), _rxListener );
     434             :             }
     435           0 :             catch( const UnknownPropertyException& )
     436             :             {
     437             :                 OSL_FAIL( "GenericPropertyHandler::addPropertyChangeListener:\nThe inspected component does not allow registering for all properties at once! This violates the interface contract!" );
     438             :             }
     439           0 :         }
     440           0 :     }
     441             : 
     442           0 :     void SAL_CALL GenericPropertyHandler::removePropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener ) throw (RuntimeException, std::exception)
     443             :     {
     444           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     445           0 :         if ( m_xComponent.is() )
     446             :         {
     447             :             try
     448             :             {
     449           0 :                 m_xComponent->removePropertyChangeListener( OUString(), _rxListener );
     450             :             }
     451           0 :             catch( const UnknownPropertyException& )
     452             :             {
     453             :                 OSL_FAIL( "GenericPropertyHandler::removePropertyChangeListener:\nThe inspected component does not allow de-registering for all properties at once! This violates the interface contract!" );
     454             :             }
     455             :         }
     456           0 :         m_aPropertyListeners.removeInterface( _rxListener );
     457           0 :     }
     458             : 
     459           8 :     void GenericPropertyHandler::impl_ensurePropertyMap()
     460             :     {
     461           8 :         if ( !m_bPropertyMapInitialized )
     462             :         {
     463           8 :             m_bPropertyMapInitialized = true;
     464             :             try
     465             :             {
     466           8 :                 Reference< XPropertySetInfo > xPSI;
     467           8 :                 if ( m_xComponent.is() )
     468           8 :                     xPSI = m_xComponent->getPropertySetInfo();
     469          16 :                 Sequence< Property > aProperties;
     470           8 :                 if ( xPSI.is() )
     471           8 :                     aProperties = xPSI->getProperties();
     472             :                 DBG_ASSERT( aProperties.getLength(), "GenericPropertyHandler::getSupportedProperties: no properties!" );
     473             : 
     474          16 :                 for ( const Property* pProperties = aProperties.getConstArray();
     475           8 :                       pProperties != aProperties.getConstArray() + aProperties.getLength();
     476             :                       ++pProperties
     477             :                     )
     478             :                 {
     479           0 :                     switch ( pProperties->Type.getTypeClass() )
     480             :                     {
     481             :                     case TypeClass_BOOLEAN:
     482             :                     case TypeClass_BYTE:
     483             :                     case TypeClass_SHORT:
     484             :                     case TypeClass_UNSIGNED_SHORT:
     485             :                     case TypeClass_LONG:
     486             :                     case TypeClass_UNSIGNED_LONG:
     487             :                     case TypeClass_HYPER:
     488             :                     case TypeClass_UNSIGNED_HYPER:
     489             :                     case TypeClass_FLOAT:
     490             :                     case TypeClass_DOUBLE:
     491             :                     case TypeClass_ENUM:
     492             :                     case TypeClass_STRING:
     493             :                         // allowed, we can handle this type
     494           0 :                         break;
     495             : 
     496             :                     case TypeClass_SEQUENCE:
     497             :                     {
     498           0 :                         TypeClass eElementTypeClass = ::comphelper::getSequenceElementType( pProperties->Type ).getTypeClass();
     499           0 :                         if  (   ( eElementTypeClass != TypeClass_STRING )
     500           0 :                             &&  ( eElementTypeClass != TypeClass_BYTE )
     501           0 :                             &&  ( eElementTypeClass != TypeClass_SHORT )
     502           0 :                             &&  ( eElementTypeClass != TypeClass_UNSIGNED_SHORT )
     503           0 :                             &&  ( eElementTypeClass != TypeClass_LONG )
     504           0 :                             &&  ( eElementTypeClass != TypeClass_UNSIGNED_LONG )
     505             :                             )
     506             :                             // can only handle the above
     507           0 :                             continue;
     508             :                     }
     509           0 :                     break;
     510             : 
     511             :                     default:
     512             :                         // next property, we don't support this type
     513           0 :                         continue;
     514             :                     }
     515             : 
     516           0 :                     m_aProperties.insert( PropertyMap::value_type( pProperties->Name, *pProperties ) );
     517           8 :                 }
     518             :             }
     519           0 :             catch( const Exception& )
     520             :             {
     521             :                 OSL_FAIL( "GenericPropertyHandler::impl_ensurePropertyMap: caught an exception!" );
     522             :             }
     523             :         }
     524           8 :     }
     525             : 
     526           8 :     Sequence< Property > SAL_CALL GenericPropertyHandler::getSupportedProperties() throw (RuntimeException, std::exception)
     527             :     {
     528           8 :         ::osl::MutexGuard aGuard( m_aMutex );
     529           8 :         const_cast< GenericPropertyHandler* >( this )->impl_ensurePropertyMap();
     530             : 
     531           8 :         Sequence< Property > aReturn( m_aProperties.size() );
     532             :         ::std::transform( m_aProperties.begin(), m_aProperties.end(),
     533           8 :             aReturn.getArray(), ::o3tl::select2nd< PropertyMap::value_type >() );
     534           8 :         return aReturn;
     535             :     }
     536             : 
     537           0 :     Sequence< OUString > SAL_CALL GenericPropertyHandler::getSupersededProperties( ) throw (RuntimeException, std::exception)
     538             :     {
     539             :         // no superseded properties at all. This handler offers the very basic PropertyHandler
     540             :         // functionality, so it's much more likely that other handlers want to supersede
     541             :         // *our* properties ....
     542           0 :         return Sequence< OUString >( );
     543             :     }
     544             : 
     545           0 :     Sequence< OUString > SAL_CALL GenericPropertyHandler::getActuatingProperties( ) throw (RuntimeException, std::exception)
     546             :     {
     547             :         // This basic PropertyHandler implementation is too dumb^Wgeneric to know
     548             :         // anything about property dependencies
     549           0 :         return Sequence< OUString >( );
     550             :     }
     551             : 
     552           0 :     LineDescriptor SAL_CALL GenericPropertyHandler::describePropertyLine( const OUString& _rPropertyName,
     553             :         const Reference< XPropertyControlFactory >& _rxControlFactory )
     554             :         throw (UnknownPropertyException, NullPointerException, RuntimeException, std::exception)
     555             :     {
     556           0 :         if ( !_rxControlFactory.is() )
     557           0 :             throw NullPointerException();
     558             : 
     559           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     560           0 :         const_cast< GenericPropertyHandler* >( this )->impl_ensurePropertyMap();
     561             : 
     562           0 :         PropertyMap::const_iterator pos = m_aProperties.find( _rPropertyName );
     563           0 :         if ( pos == m_aProperties.end() )
     564           0 :             throw UnknownPropertyException();
     565             : 
     566           0 :         LineDescriptor aDescriptor;
     567           0 :         aDescriptor.DisplayName = _rPropertyName;
     568           0 :         switch ( pos->second.Type.getTypeClass() )
     569             :         {
     570             :         case TypeClass_ENUM:
     571           0 :             aDescriptor.Control = PropertyHandlerHelper::createListBoxControl( _rxControlFactory,
     572           0 :                 impl_getEnumConverter( pos->second.Type )->getDescriptions(),
     573           0 :                 PropertyHandlerHelper::requiresReadOnlyControl( pos->second.Attributes ),
     574           0 :                 false );
     575           0 :             break;
     576             :         case TypeClass_STRING:
     577             :         {
     578             :             // some special handling for URL properties
     579           0 :             bool bIsURLProperty = _rPropertyName.endsWithAsciiL( "URL", 3 );
     580           0 :             if ( bIsURLProperty )
     581             :             {
     582           0 :                 aDescriptor.Control = _rxControlFactory->createPropertyControl(
     583           0 :                     PropertyControlType::HyperlinkField, PropertyHandlerHelper::requiresReadOnlyControl( pos->second.Attributes ) );
     584             : 
     585           0 :                 Reference< XHyperlinkControl > xControl( aDescriptor.Control, UNO_QUERY_THROW );
     586           0 :                 Reference< XActionListener > xEnsureDelete( new UrlClickHandler( m_xContext, xControl ) );
     587             :             }
     588             :         }
     589           0 :         break;
     590             :         default:
     591           0 :             break;
     592             :         }
     593             :         // fallback
     594           0 :         if ( !aDescriptor.Control.is() )
     595           0 :             PropertyHandlerHelper::describePropertyLine( pos->second, aDescriptor, _rxControlFactory );
     596             : 
     597           0 :         aDescriptor.Category = "General";
     598           0 :         return aDescriptor;
     599             :     }
     600             : 
     601           0 :     sal_Bool SAL_CALL GenericPropertyHandler::isComposable( const OUString& /*_rPropertyName*/ ) throw (UnknownPropertyException, RuntimeException, std::exception)
     602             :     {
     603           0 :         return sal_False;
     604             :     }
     605             : 
     606           0 :     InteractiveSelectionResult SAL_CALL GenericPropertyHandler::onInteractivePropertySelection( const OUString& /*_rPropertyName*/, sal_Bool /*_bPrimary*/, Any& /*_rData*/, const Reference< XObjectInspectorUI >& /*_rxInspectorUI*/ ) throw (UnknownPropertyException, NullPointerException, RuntimeException, std::exception)
     607             :     {
     608             :         OSL_FAIL( "GenericPropertyHandler::onInteractivePropertySelection: I'm too dumb to know anything about property browse buttons!" );
     609           0 :         return InteractiveSelectionResult_Cancelled;
     610             :     }
     611             : 
     612           0 :     void SAL_CALL GenericPropertyHandler::actuatingPropertyChanged( const OUString& /*_rActuatingPropertyName*/, const Any& /*_rNewValue*/, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& /*_rxInspectorUI*/, sal_Bool /*_bFirstTimeInit*/ ) throw (NullPointerException, RuntimeException, std::exception)
     613             :     {
     614             :         OSL_FAIL( "GenericPropertyHandler::actuatingPropertyChanged: no no no, I did not register for any actuating properties!" );
     615           0 :     }
     616             : 
     617           0 :     sal_Bool SAL_CALL GenericPropertyHandler::suspend( sal_Bool /*_bSuspend*/ ) throw (RuntimeException, std::exception)
     618             :     {
     619           0 :         return sal_True;
     620             :     }
     621             : 
     622          10 :     void SAL_CALL GenericPropertyHandler::disposing()
     623             :     {
     624          10 :         m_aPropertyListeners.clear();
     625             :             // not disposeAndClear: the listeners are (virtually) listeners at our introspectee, not
     626             :             // at this handler instance
     627          10 :     }
     628             : 
     629          10 :     IMPLEMENT_FORWARD_XCOMPONENT( GenericPropertyHandler, GenericPropertyHandler_Base );
     630             : 
     631          12 : }   // namespace pcr
     632             : 
     633             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10