LCOV - code coverage report
Current view: top level - extensions/source/propctrlr - propertyhandler.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 191 0.0 %
Date: 2014-04-14 Functions: 0 40 0.0 %
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 "propertyhandler.hxx"
      21             : #include "formmetadata.hxx"
      22             : #include "formbrowsertools.hxx"
      23             : #include "handlerhelper.hxx"
      24             : #include "formstrings.hxx"
      25             : 
      26             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      27             : #include <com/sun/star/lang/NullPointerException.hpp>
      28             : #include <com/sun/star/util/XModifiable.hpp>
      29             : #include <com/sun/star/script/Converter.hpp>
      30             : 
      31             : #include <cppuhelper/supportsservice.hxx>
      32             : #include <tools/debug.hxx>
      33             : #include <unotools/confignode.hxx>
      34             : #include <unotools/localedatawrapper.hxx>
      35             : #include <unotools/syslocale.hxx>
      36             : #include <toolkit/helper/vclunohelper.hxx>
      37             : 
      38             : #include <algorithm>
      39             : 
      40             : namespace pcr
      41             : {
      42             : 
      43             :     using namespace ::com::sun::star::uno;
      44             :     using namespace ::com::sun::star::awt;
      45             :     using namespace ::com::sun::star::beans;
      46             :     using namespace ::com::sun::star::script;
      47             :     using namespace ::com::sun::star::lang;
      48             :     using namespace ::com::sun::star::util;
      49             :     using namespace ::com::sun::star::frame;
      50             :     using namespace ::com::sun::star::inspection;
      51             :     using namespace ::comphelper;
      52             : 
      53             : 
      54           0 :     PropertyHandler::PropertyHandler( const Reference< XComponentContext >& _rxContext )
      55             :         :PropertyHandler_Base( m_aMutex )
      56             :         ,m_bSupportedPropertiesAreKnown( false )
      57             :         ,m_aPropertyListeners( m_aMutex )
      58             :         ,m_xContext( _rxContext )
      59           0 :         ,m_pInfoService  ( new OPropertyInfoService )
      60             :     {
      61             : 
      62           0 :         m_xTypeConverter = Converter::create(_rxContext);
      63           0 :     }
      64             : 
      65           0 :     PropertyHandler::~PropertyHandler()
      66             :     {
      67           0 :     }
      68             : 
      69           0 :     void SAL_CALL PropertyHandler::inspect( const Reference< XInterface >& _rxIntrospectee ) throw (RuntimeException, NullPointerException, std::exception)
      70             :     {
      71           0 :         if ( !_rxIntrospectee.is() )
      72           0 :             throw NullPointerException();
      73             : 
      74           0 :         ::osl::MutexGuard aGuard( m_aMutex );
      75             : 
      76           0 :         Reference< XPropertySet > xNewComponent( _rxIntrospectee, UNO_QUERY );
      77           0 :         if ( xNewComponent == m_xComponent )
      78           0 :             return;
      79             : 
      80             :         // remove all old property change listeners
      81             :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
      82           0 :         ::std::auto_ptr< ::cppu::OInterfaceIteratorHelper > removeListener = m_aPropertyListeners.createIterator();
      83           0 :         ::std::auto_ptr< ::cppu::OInterfaceIteratorHelper > readdListener = m_aPropertyListeners.createIterator();  // will copy the container as needed
      84             :         SAL_WNODEPRECATED_DECLARATIONS_POP
      85           0 :         while ( removeListener->hasMoreElements() )
      86           0 :             removePropertyChangeListener( static_cast< XPropertyChangeListener* >( removeListener->next() ) );
      87             :         OSL_ENSURE( m_aPropertyListeners.empty(), "PropertyHandler::inspect: derived classes are expected to forward the removePropertyChangeListener call to their base class (me)!" );
      88             : 
      89             :         // remember the new component, and give derived classes the chance to react on it
      90           0 :         m_xComponent = xNewComponent;
      91           0 :         onNewComponent();
      92             : 
      93             :         // add the listeners, again
      94           0 :         while ( readdListener->hasMoreElements() )
      95           0 :             addPropertyChangeListener( static_cast< XPropertyChangeListener* >( readdListener->next() ) );
      96             :     }
      97             : 
      98           0 :     void PropertyHandler::onNewComponent()
      99             :     {
     100           0 :         if ( m_xComponent.is() )
     101           0 :             m_xComponentPropertyInfo = m_xComponent->getPropertySetInfo();
     102             :         else
     103           0 :             m_xComponentPropertyInfo.clear();
     104             : 
     105           0 :         m_bSupportedPropertiesAreKnown = false;
     106           0 :         m_aSupportedProperties.realloc( 0 );
     107           0 :     }
     108             : 
     109           0 :     Sequence< Property > SAL_CALL PropertyHandler::getSupportedProperties() throw (RuntimeException, std::exception)
     110             :     {
     111           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     112           0 :         if ( !m_bSupportedPropertiesAreKnown )
     113             :         {
     114           0 :             m_aSupportedProperties = doDescribeSupportedProperties();
     115           0 :             m_bSupportedPropertiesAreKnown = true;
     116             :         }
     117           0 :         return (Sequence< Property >)m_aSupportedProperties;
     118             :     }
     119             : 
     120           0 :     Sequence< OUString > SAL_CALL PropertyHandler::getSupersededProperties( ) throw (RuntimeException, std::exception)
     121             :     {
     122           0 :         return Sequence< OUString >();
     123             :     }
     124             : 
     125           0 :     Sequence< OUString > SAL_CALL PropertyHandler::getActuatingProperties( ) throw (RuntimeException, std::exception)
     126             :     {
     127           0 :         return Sequence< OUString >();
     128             :     }
     129             : 
     130           0 :     Any SAL_CALL PropertyHandler::convertToPropertyValue( const OUString& _rPropertyName, const Any& _rControlValue ) throw (UnknownPropertyException, RuntimeException, std::exception)
     131             :     {
     132           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     133           0 :         PropertyId nPropId = m_pInfoService->getPropertyId( _rPropertyName );
     134           0 :         Property aProperty( impl_getPropertyFromName_throw( _rPropertyName ) );
     135             : 
     136           0 :         Any aPropertyValue;
     137           0 :         if ( !_rControlValue.hasValue() )
     138             :             // NULL is converted to NULL
     139           0 :             return aPropertyValue;
     140             : 
     141           0 :         if ( ( m_pInfoService->getPropertyUIFlags( nPropId ) & PROP_FLAG_ENUM ) != 0 )
     142             :         {
     143           0 :             OUString sControlValue;
     144           0 :             OSL_VERIFY( _rControlValue >>= sControlValue );
     145             :             ::rtl::Reference< IPropertyEnumRepresentation > aEnumConversion(
     146           0 :                 new DefaultEnumRepresentation( *m_pInfoService, aProperty.Type, nPropId ) );
     147             :             // TODO/UNOize: cache those converters?
     148           0 :             aEnumConversion->getValueFromDescription( sControlValue, aPropertyValue );
     149             :         }
     150             :         else
     151           0 :             aPropertyValue = PropertyHandlerHelper::convertToPropertyValue(
     152           0 :                 m_xContext, m_xTypeConverter, aProperty, _rControlValue );
     153           0 :         return aPropertyValue;
     154             :     }
     155             : 
     156           0 :     Any SAL_CALL PropertyHandler::convertToControlValue( const OUString& _rPropertyName, const Any& _rPropertyValue, const Type& _rControlValueType ) throw (UnknownPropertyException, RuntimeException, std::exception)
     157             :     {
     158           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     159           0 :         PropertyId nPropId = m_pInfoService->getPropertyId( _rPropertyName );
     160             : 
     161           0 :         if ( ( m_pInfoService->getPropertyUIFlags( nPropId ) & PROP_FLAG_ENUM ) != 0 )
     162             :         {
     163             :             DBG_ASSERT( _rControlValueType.getTypeClass() == TypeClass_STRING, "PropertyHandler::convertToControlValue: ENUM, but not STRING?" );
     164             : 
     165             :             ::rtl::Reference< IPropertyEnumRepresentation > aEnumConversion(
     166           0 :                 new DefaultEnumRepresentation( *m_pInfoService, _rPropertyValue.getValueType(), nPropId ) );
     167             :             // TODO/UNOize: cache those converters?
     168           0 :             return makeAny( aEnumConversion->getDescriptionForValue( _rPropertyValue ) );
     169             :         }
     170             : 
     171             :         return PropertyHandlerHelper::convertToControlValue(
     172           0 :             m_xContext, m_xTypeConverter, _rPropertyValue, _rControlValueType );
     173             :     }
     174             : 
     175           0 :     PropertyState SAL_CALL PropertyHandler::getPropertyState( const OUString& /*_rPropertyName*/ ) throw (UnknownPropertyException, RuntimeException, std::exception)
     176             :     {
     177           0 :         return PropertyState_DIRECT_VALUE;
     178             :     }
     179             : 
     180           0 :     LineDescriptor SAL_CALL PropertyHandler::describePropertyLine( const OUString& _rPropertyName,
     181             :         const Reference< XPropertyControlFactory >& _rxControlFactory )
     182             :         throw (UnknownPropertyException, NullPointerException, RuntimeException, std::exception)
     183             :     {
     184           0 :         if ( !_rxControlFactory.is() )
     185           0 :             throw NullPointerException();
     186             : 
     187           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     188           0 :         PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
     189           0 :         const Property& rProperty( impl_getPropertyFromId_throw( nPropId ) );
     190             : 
     191           0 :         LineDescriptor aDescriptor;
     192           0 :         if ( ( m_pInfoService->getPropertyUIFlags( nPropId ) & PROP_FLAG_ENUM ) != 0 )
     193             :         {
     194           0 :             aDescriptor.Control = PropertyHandlerHelper::createListBoxControl(
     195           0 :                 _rxControlFactory, m_pInfoService->getPropertyEnumRepresentations( nPropId ),
     196           0 :                 PropertyHandlerHelper::requiresReadOnlyControl( rProperty.Attributes ), sal_False );
     197             :         }
     198             :         else
     199           0 :             PropertyHandlerHelper::describePropertyLine( rProperty, aDescriptor, _rxControlFactory );
     200             : 
     201           0 :         aDescriptor.HelpURL = HelpIdUrl::getHelpURL( m_pInfoService->getPropertyHelpId( nPropId ) );
     202           0 :         aDescriptor.DisplayName = m_pInfoService->getPropertyTranslation( nPropId );
     203             : 
     204           0 :         if ( ( m_pInfoService->getPropertyUIFlags( nPropId ) & PROP_FLAG_DATA_PROPERTY ) != 0 )
     205           0 :             aDescriptor.Category = "Data";
     206             :         else
     207           0 :             aDescriptor.Category = "General";
     208           0 :         return aDescriptor;
     209             :     }
     210             : 
     211           0 :     sal_Bool SAL_CALL PropertyHandler::isComposable( const OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException, std::exception)
     212             :     {
     213           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     214           0 :         return m_pInfoService->isComposeable( _rPropertyName );
     215             :     }
     216             : 
     217           0 :     InteractiveSelectionResult SAL_CALL PropertyHandler::onInteractivePropertySelection( const OUString& /*_rPropertyName*/, sal_Bool /*_bPrimary*/, Any& /*_rData*/, const Reference< XObjectInspectorUI >& /*_rxInspectorUI*/ ) throw (UnknownPropertyException, NullPointerException, RuntimeException, std::exception)
     218             :     {
     219             :         OSL_FAIL( "PropertyHandler::onInteractivePropertySelection: not implemented!" );
     220           0 :         return InteractiveSelectionResult_Cancelled;
     221             :     }
     222             : 
     223           0 :     void SAL_CALL PropertyHandler::actuatingPropertyChanged( const OUString& /*_rActuatingPropertyName*/, const Any& /*_rNewValue*/, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& /*_rxInspectorUI*/, sal_Bool /*_bFirstTimeInit*/ ) throw (NullPointerException, RuntimeException, std::exception)
     224             :     {
     225             :         OSL_FAIL( "PropertyHandler::actuatingPropertyChanged: not implemented!" );
     226           0 :     }
     227             : 
     228           0 :     void SAL_CALL PropertyHandler::addPropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener ) throw (NullPointerException, RuntimeException, std::exception)
     229             :     {
     230           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     231           0 :         if ( !_rxListener.is() )
     232           0 :             throw NullPointerException();
     233           0 :         m_aPropertyListeners.addListener( _rxListener );
     234           0 :     }
     235             : 
     236           0 :     void SAL_CALL PropertyHandler::removePropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener ) throw (RuntimeException, std::exception)
     237             :     {
     238           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     239           0 :         m_aPropertyListeners.removeListener( _rxListener );
     240           0 :     }
     241             : 
     242           0 :     sal_Bool SAL_CALL PropertyHandler::suspend( sal_Bool /*_bSuspend*/ ) throw (RuntimeException, std::exception)
     243             :     {
     244           0 :         return sal_True;
     245             :     }
     246             : 
     247           0 :     IMPLEMENT_FORWARD_XCOMPONENT( PropertyHandler, PropertyHandler_Base )
     248             : 
     249           0 :     void SAL_CALL PropertyHandler::disposing()
     250             :     {
     251           0 :         m_xComponent.clear();
     252           0 :         m_aPropertyListeners.clear();
     253           0 :         m_xTypeConverter.clear();
     254           0 :         m_aSupportedProperties.realloc( 0 );
     255           0 :     }
     256             : 
     257           0 :     void PropertyHandler::firePropertyChange( const OUString& _rPropName, PropertyId _nPropId, const Any& _rOldValue, const Any& _rNewValue ) SAL_THROW(())
     258             :     {
     259           0 :         PropertyChangeEvent aEvent;
     260           0 :         aEvent.Source = m_xComponent;
     261           0 :         aEvent.PropertyHandle = _nPropId;
     262           0 :         aEvent.PropertyName = _rPropName;
     263           0 :         aEvent.OldValue = _rOldValue;
     264           0 :         aEvent.NewValue = _rNewValue;
     265           0 :         m_aPropertyListeners.notify( aEvent, &XPropertyChangeListener::propertyChange );
     266           0 :     }
     267             : 
     268           0 :     const Property* PropertyHandler::impl_getPropertyFromId_nothrow( PropertyId _nPropId ) const
     269             :     {
     270           0 :         const_cast< PropertyHandler* >( this )->getSupportedProperties();
     271             :         const Property* pFound = ::std::find_if( m_aSupportedProperties.begin(), m_aSupportedProperties.end(),
     272             :             FindPropertyByHandle( _nPropId )
     273           0 :         );
     274           0 :         if ( pFound != m_aSupportedProperties.end() )
     275           0 :             return &(*pFound);
     276           0 :         return NULL;
     277             :     }
     278             : 
     279           0 :     const Property& PropertyHandler::impl_getPropertyFromId_throw( PropertyId _nPropId ) const
     280             :     {
     281           0 :         const Property* pProperty = impl_getPropertyFromId_nothrow( _nPropId );
     282           0 :         if ( !pProperty )
     283           0 :             throw UnknownPropertyException();
     284             : 
     285           0 :         return *pProperty;
     286             :     }
     287             : 
     288           0 :     const Property& PropertyHandler::impl_getPropertyFromName_throw( const OUString& _rPropertyName ) const
     289             :     {
     290           0 :         const_cast< PropertyHandler* >( this )->getSupportedProperties();
     291             :         StlSyntaxSequence< Property >::const_iterator pFound = ::std::find_if( m_aSupportedProperties.begin(), m_aSupportedProperties.end(),
     292             :             FindPropertyByName( _rPropertyName )
     293           0 :         );
     294           0 :         if ( pFound == m_aSupportedProperties.end() )
     295           0 :             throw UnknownPropertyException();
     296             : 
     297           0 :         return *pFound;
     298             :     }
     299             : 
     300           0 :     void PropertyHandler::implAddPropertyDescription( ::std::vector< Property >& _rProperties, const OUString& _rPropertyName, const Type& _rType, sal_Int16 _nAttribs ) const
     301             :     {
     302             :         _rProperties.push_back( Property(
     303             :             _rPropertyName,
     304           0 :             m_pInfoService->getPropertyId( _rPropertyName ),
     305             :             _rType,
     306             :             _nAttribs
     307           0 :         ) );
     308           0 :     }
     309             : 
     310           0 :     Window* PropertyHandler::impl_getDefaultDialogParent_nothrow() const
     311             :     {
     312           0 :         return PropertyHandlerHelper::getDialogParentWindow( m_xContext );
     313             :     }
     314             : 
     315           0 :     PropertyId PropertyHandler::impl_getPropertyId_throw( const OUString& _rPropertyName ) const
     316             :     {
     317           0 :         PropertyId nPropId = m_pInfoService->getPropertyId( _rPropertyName );
     318           0 :         if ( nPropId == -1 )
     319           0 :             throw UnknownPropertyException();
     320           0 :         return nPropId;
     321             :     }
     322             : 
     323           0 :     PropertyId PropertyHandler::impl_getPropertyId_nothrow( const OUString& _rPropertyName ) const
     324             :     {
     325           0 :         return m_pInfoService->getPropertyId( _rPropertyName );
     326             :     }
     327             : 
     328           0 :     void PropertyHandler::impl_setContextDocumentModified_nothrow() const
     329             :     {
     330           0 :         Reference< XModifiable > xModifiable( impl_getContextDocument_nothrow(), UNO_QUERY );
     331           0 :         if ( xModifiable.is() )
     332           0 :             xModifiable->setModified( sal_True );
     333           0 :     }
     334             : 
     335           0 :     bool PropertyHandler::impl_componentHasProperty_throw( const OUString& _rPropName ) const
     336             :     {
     337           0 :         return m_xComponentPropertyInfo.is() && m_xComponentPropertyInfo->hasPropertyByName( _rPropName );
     338             :     }
     339             : 
     340           0 :     sal_Int16 PropertyHandler::impl_getDocumentMeasurementUnit_throw() const
     341             :     {
     342           0 :         FieldUnit eUnit = FUNIT_NONE;
     343             : 
     344           0 :         Reference< XServiceInfo > xDocumentSI( impl_getContextDocument_nothrow(), UNO_QUERY );
     345             :         OSL_ENSURE( xDocumentSI.is(), "PropertyHandlerHelper::impl_getDocumentMeasurementUnit_throw: No context document - where do I live?" );
     346           0 :         if ( xDocumentSI.is() )
     347             :         {
     348             :             // determine the application type we live in
     349           0 :             OUString sConfigurationLocation;
     350           0 :             OUString sConfigurationProperty;
     351           0 :             if ( xDocumentSI->supportsService( SERVICE_WEB_DOCUMENT ) )
     352             :             {   // writer
     353           0 :                 sConfigurationLocation = "/org.openoffice.Office.WriterWeb/Layout/Other";
     354           0 :                 sConfigurationProperty = "MeasureUnit";
     355             :             }
     356           0 :             else if ( xDocumentSI->supportsService( SERVICE_TEXT_DOCUMENT ) )
     357             :             {   // writer
     358           0 :                 sConfigurationLocation = "/org.openoffice.Office.Writer/Layout/Other";
     359           0 :                 sConfigurationProperty = "MeasureUnit";
     360             :             }
     361           0 :             else if ( xDocumentSI->supportsService( SERVICE_SPREADSHEET_DOCUMENT ) )
     362             :             {   // calc
     363           0 :                 sConfigurationLocation = "/org.openoffice.Office.Calc/Layout/Other/MeasureUnit";
     364           0 :                 sConfigurationProperty = "Metric";
     365             :             }
     366           0 :             else if ( xDocumentSI->supportsService( SERVICE_DRAWING_DOCUMENT ) )
     367             :             {
     368           0 :                 sConfigurationLocation = "/org.openoffice.Office.Draw/Layout/Other/MeasureUnit";
     369           0 :                 sConfigurationProperty = "Metric";
     370             :             }
     371           0 :             else if ( xDocumentSI->supportsService( SERVICE_PRESENTATION_DOCUMENT ) )
     372             :             {
     373           0 :                 sConfigurationLocation = "/org.openoffice.Office.Impress/Layout/Other/MeasureUnit";
     374           0 :                 sConfigurationProperty = "Metric";
     375             :             }
     376             : 
     377             :             // read the measurement unit from the configuration
     378           0 :             if ( !(sConfigurationLocation.isEmpty() || sConfigurationProperty.isEmpty()) )
     379             :             {
     380             :                 ::utl::OConfigurationTreeRoot aConfigTree( ::utl::OConfigurationTreeRoot::createWithComponentContext(
     381           0 :                     m_xContext, sConfigurationLocation, -1, ::utl::OConfigurationTreeRoot::CM_READONLY ) );
     382           0 :                 sal_Int32 nUnitAsInt = (sal_Int32)FUNIT_NONE;
     383           0 :                 aConfigTree.getNodeValue( sConfigurationProperty ) >>= nUnitAsInt;
     384             : 
     385             :                 // if this denotes a valid (and accepted) unit, then use it
     386           0 :                 if  ( ( nUnitAsInt > FUNIT_NONE ) && ( nUnitAsInt <= FUNIT_100TH_MM ) )
     387           0 :                     eUnit = static_cast< FieldUnit >( nUnitAsInt );
     388           0 :             }
     389             :         }
     390             : 
     391           0 :         if ( FUNIT_NONE == eUnit )
     392             :         {
     393           0 :             MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
     394           0 :             eUnit = MEASURE_METRIC == eSystem ? FUNIT_CM : FUNIT_INCH;
     395             :         }
     396             : 
     397           0 :         return VCLUnoHelper::ConvertToMeasurementUnit( eUnit, 1 );
     398             :     }
     399             : 
     400           0 :     PropertyHandlerComponent::PropertyHandlerComponent( const Reference< XComponentContext >& _rxContext )
     401           0 :         :PropertyHandler( _rxContext )
     402             :     {
     403           0 :     }
     404             : 
     405           0 :     IMPLEMENT_FORWARD_XINTERFACE2( PropertyHandlerComponent, PropertyHandler, PropertyHandlerComponent_Base )
     406           0 :     IMPLEMENT_FORWARD_XTYPEPROVIDER2( PropertyHandlerComponent, PropertyHandler, PropertyHandlerComponent_Base )
     407             : 
     408           0 :     sal_Bool SAL_CALL PropertyHandlerComponent::supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception)
     409             :     {
     410           0 :         return cppu::supportsService(this, ServiceName);
     411             :     }
     412             : 
     413             : }   // namespace pcr
     414             : 
     415             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10