LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/tools - OPropertySet.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 40 126 31.7 %
Date: 2012-12-27 Functions: 9 24 37.5 %
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 "OPropertySet.hxx"
      21             : #include "ImplOPropertySet.hxx"
      22             : #include "ContainerHelper.hxx"
      23             : #include <cppuhelper/queryinterface.hxx>
      24             : #include <comphelper/servicehelper.hxx>
      25             : 
      26             : #include <vector>
      27             : #include <algorithm>
      28             : 
      29             : using namespace ::com::sun::star;
      30             : 
      31             : using ::com::sun::star::style::XStyleSupplier;
      32             : 
      33             : using ::com::sun::star::uno::Reference;
      34             : using ::com::sun::star::uno::Sequence;
      35             : using ::com::sun::star::uno::Any;
      36             : using ::rtl::OUString;
      37             : using ::osl::MutexGuard;
      38             : 
      39             : // needed for MS compiler
      40             : using ::cppu::OBroadcastHelper;
      41             : using ::cppu::OPropertySetHelper;
      42             : using ::cppu::OWeakObject;
      43             : 
      44             : namespace property
      45             : {
      46             : 
      47        1866 : OPropertySet::OPropertySet( ::osl::Mutex & par_rMutex ) :
      48             :         OBroadcastHelper( par_rMutex ),
      49             :         // the following causes a warning; there seems to be no way to avoid it
      50             :         OPropertySetHelper( static_cast< OBroadcastHelper & >( *this )),
      51             :         m_rMutex( par_rMutex ),
      52           0 :         m_pImplProperties( new impl::ImplOPropertySet() ),
      53        1866 :         m_bSetNewValuesExplicitlyEvenIfTheyEqualDefault(false)
      54             : {
      55        1866 : }
      56             : 
      57           0 : OPropertySet::OPropertySet( const OPropertySet & rOther, ::osl::Mutex & par_rMutex ) :
      58             :         OBroadcastHelper( par_rMutex ),
      59             :         // the following causes a warning; there seems to be no way to avoid it
      60             :         OPropertySetHelper( static_cast< OBroadcastHelper & >( *this )),
      61             :         m_rMutex( par_rMutex ),
      62           0 :         m_bSetNewValuesExplicitlyEvenIfTheyEqualDefault(false)
      63             : {
      64           0 :     MutexGuard aGuard( m_rMutex );
      65           0 :     if( rOther.m_pImplProperties.get())
      66           0 :         m_pImplProperties.reset( new impl::ImplOPropertySet( * rOther.m_pImplProperties.get()));
      67           0 : }
      68             : 
      69          57 : void OPropertySet::SetNewValuesExplicitlyEvenIfTheyEqualDefault()
      70             : {
      71          57 :     m_bSetNewValuesExplicitlyEvenIfTheyEqualDefault = true;
      72          57 : }
      73             : 
      74        1866 : OPropertySet::~OPropertySet()
      75        1866 : {}
      76             : 
      77           0 : void OPropertySet::disposePropertySet()
      78             : {
      79           0 :     m_pImplProperties.reset( 0 );
      80           0 : }
      81             : 
      82       10140 : Any SAL_CALL OPropertySet::queryInterface( const uno::Type& aType )
      83             :     throw (uno::RuntimeException)
      84             : {
      85             :     return ::cppu::queryInterface(
      86             :         aType,
      87             :         static_cast< lang::XTypeProvider * >( this ),
      88             :         static_cast< beans::XPropertySet * >( this ),
      89             :         static_cast< beans::XMultiPropertySet * >( this ),
      90             :         static_cast< beans::XFastPropertySet * >( this ),
      91             :         static_cast< beans::XPropertyState * >( this ),
      92             :         static_cast< beans::XMultiPropertyStates * >( this ),
      93       10140 :         static_cast< XStyleSupplier * >( this ) );
      94             : }
      95             : 
      96             : #define LCL_PROP_CPPUTYPE(t) (::getCppuType( reinterpret_cast< const Reference<t> *>(0)))
      97             : 
      98             : // // ____ XTypeProvider ____
      99             : Sequence< uno::Type > SAL_CALL
     100           0 :     OPropertySet::getTypes()
     101             :     throw (uno::RuntimeException)
     102             : {
     103           0 :     static Sequence< uno::Type > aTypeList;
     104             : 
     105           0 :     MutexGuard aGuard( m_rMutex );
     106             : 
     107           0 :     if( aTypeList.getLength() == 0 )
     108             :     {
     109           0 :         ::std::vector< uno::Type > aTypes;
     110             : 
     111           0 :         aTypes.push_back( LCL_PROP_CPPUTYPE( lang::XTypeProvider ));
     112           0 :         aTypes.push_back( LCL_PROP_CPPUTYPE( beans::XPropertySet ));
     113           0 :         aTypes.push_back( LCL_PROP_CPPUTYPE( beans::XMultiPropertySet ));
     114           0 :         aTypes.push_back( LCL_PROP_CPPUTYPE( beans::XFastPropertySet ));
     115           0 :         aTypes.push_back( LCL_PROP_CPPUTYPE( beans::XPropertyState ));
     116           0 :         aTypes.push_back( LCL_PROP_CPPUTYPE( beans::XMultiPropertyStates ));
     117           0 :         aTypes.push_back( LCL_PROP_CPPUTYPE( XStyleSupplier ));
     118             : 
     119           0 :         aTypeList = ::chart::ContainerHelper::ContainerToSequence( aTypes );
     120             :     }
     121             : 
     122           0 :     return aTypeList;
     123             : }
     124             : 
     125             : namespace
     126             : {
     127             :     class theOPropertySetImplementationId : public rtl::Static< UnoTunnelIdInit, theOPropertySetImplementationId > {};
     128             : }
     129             : 
     130             : Sequence< sal_Int8 > SAL_CALL
     131           0 :     OPropertySet::getImplementationId()
     132             :     throw (uno::RuntimeException)
     133             : {
     134           0 :     return theOPropertySetImplementationId::get().getSeq();
     135             : }
     136             : 
     137             : // ____ XPropertyState ____
     138             : beans::PropertyState SAL_CALL
     139           0 :     OPropertySet::getPropertyState( const OUString& PropertyName )
     140             :     throw (beans::UnknownPropertyException,
     141             :            uno::RuntimeException)
     142             : {
     143           0 :     cppu::IPropertyArrayHelper & rPH = getInfoHelper();
     144             : 
     145             :     return m_pImplProperties->GetPropertyStateByHandle(
     146           0 :         rPH.getHandleByName( PropertyName ));
     147             : }
     148             : 
     149             : Sequence< beans::PropertyState > SAL_CALL
     150           0 :     OPropertySet::getPropertyStates( const Sequence< OUString >& aPropertyName )
     151             :     throw (beans::UnknownPropertyException,
     152             :            uno::RuntimeException)
     153             : {
     154           0 :     cppu::IPropertyArrayHelper & rPH = getInfoHelper();
     155             : 
     156           0 :     sal_Int32 * pHandles = new sal_Int32[ aPropertyName.getLength() ];
     157           0 :     rPH.fillHandles( pHandles, aPropertyName );
     158             : 
     159           0 :     ::std::vector< sal_Int32 > aHandles( pHandles, pHandles + aPropertyName.getLength());
     160           0 :     delete[] pHandles;
     161             : 
     162           0 :     return m_pImplProperties->GetPropertyStatesByHandle( aHandles );
     163             : }
     164             : 
     165             : void SAL_CALL
     166           0 :     OPropertySet::setPropertyToDefault( const OUString& PropertyName )
     167             :     throw (beans::UnknownPropertyException,
     168             :            uno::RuntimeException)
     169             : {
     170           0 :     cppu::IPropertyArrayHelper & rPH = getInfoHelper();
     171             : 
     172           0 :     m_pImplProperties->SetPropertyToDefault( rPH.getHandleByName( PropertyName ));
     173           0 :     firePropertyChangeEvent();
     174           0 : }
     175             : 
     176             : Any SAL_CALL
     177           0 :     OPropertySet::getPropertyDefault( const OUString& aPropertyName )
     178             :     throw (beans::UnknownPropertyException,
     179             :            lang::WrappedTargetException,
     180             :            uno::RuntimeException)
     181             : {
     182           0 :     cppu::IPropertyArrayHelper & rPH = getInfoHelper();
     183             : 
     184           0 :     return GetDefaultValue( rPH.getHandleByName( aPropertyName ) );
     185             : }
     186             : 
     187             : 
     188             : // ____ XMultiPropertyStates ____
     189             : 
     190             : // Note: getPropertyStates() is already implemented in XPropertyState with the
     191             : // same signature
     192             : 
     193             : void SAL_CALL
     194           0 :     OPropertySet::setAllPropertiesToDefault()
     195             :     throw (uno::RuntimeException)
     196             : {
     197           0 :     m_pImplProperties->SetAllPropertiesToDefault();
     198           0 :     firePropertyChangeEvent();
     199           0 : }
     200             : 
     201             : void SAL_CALL
     202           0 :     OPropertySet::setPropertiesToDefault( const Sequence< OUString >& aPropertyNames )
     203             :     throw (beans::UnknownPropertyException,
     204             :            uno::RuntimeException)
     205             : {
     206           0 :     cppu::IPropertyArrayHelper & rPH = getInfoHelper();
     207             : 
     208           0 :     sal_Int32 * pHandles = new sal_Int32[ aPropertyNames.getLength() ];
     209           0 :     rPH.fillHandles( pHandles, aPropertyNames );
     210             : 
     211           0 :     ::std::vector< sal_Int32 > aHandles( pHandles, pHandles + aPropertyNames.getLength());
     212           0 :     delete[] pHandles;
     213             : 
     214           0 :     m_pImplProperties->SetPropertiesToDefault( aHandles );
     215           0 : }
     216             : 
     217             : Sequence< Any > SAL_CALL
     218           0 :     OPropertySet::getPropertyDefaults( const Sequence< OUString >& aPropertyNames )
     219             :     throw (beans::UnknownPropertyException,
     220             :            lang::WrappedTargetException,
     221             :            uno::RuntimeException)
     222             : {
     223           0 :     ::cppu::IPropertyArrayHelper & rPH = getInfoHelper();
     224           0 :     const sal_Int32 nElements = aPropertyNames.getLength();
     225             : 
     226           0 :     Sequence< Any > aResult( nElements );
     227           0 :     Any * pResultArray = aResult.getArray();
     228           0 :     sal_Int32 nI = 0;
     229             : 
     230           0 :     for( ; nI < nElements; ++nI )
     231             :     {
     232             :         pResultArray[ nI ] = GetDefaultValue(
     233           0 :             rPH.getHandleByName( aPropertyNames[ nI ] ));
     234             :     }
     235             : 
     236           0 :     return aResult;
     237             : }
     238             : 
     239       14539 : sal_Bool SAL_CALL OPropertySet::convertFastPropertyValue
     240             :     ( Any & rConvertedValue,
     241             :       Any & rOldValue,
     242             :       sal_Int32 nHandle,
     243             :       const Any& rValue )
     244             :     throw (lang::IllegalArgumentException)
     245             : {
     246       14539 :     getFastPropertyValue( rOldValue, nHandle );
     247             :     //accept longs also for short values
     248             :     {
     249             :         sal_Int16 nValue;
     250       14539 :         if( (rOldValue>>=nValue) && !(rValue>>=nValue) )
     251             :         {
     252           0 :             sal_Int32 n32Value = 0;
     253           0 :             if( rValue>>=n32Value )
     254             :             {
     255           0 :                 rConvertedValue = uno::makeAny( static_cast<sal_Int16>(n32Value) );
     256           0 :                 return sal_True;
     257             :             }
     258             : 
     259           0 :             sal_Int64 n64Value = 0;
     260           0 :             if( rValue>>=n64Value )
     261             :             {
     262           0 :                 rConvertedValue = uno::makeAny( static_cast<sal_Int16>(n64Value) );
     263           0 :                 return sal_True;
     264             :             }
     265             :         }
     266             :     }
     267       14539 :     rConvertedValue = rValue;
     268       14539 :     if( !m_bSetNewValuesExplicitlyEvenIfTheyEqualDefault && rOldValue == rConvertedValue )
     269        9756 :         return sal_False;//no change necessary
     270        4783 :     return sal_True;
     271             : }
     272             : 
     273        5187 : void SAL_CALL OPropertySet::setFastPropertyValue_NoBroadcast
     274             :     ( sal_Int32 nHandle,
     275             :       const Any& rValue )
     276             :     throw (uno::Exception)
     277             : {
     278             : #if OSL_DEBUG_LEVEL > 0
     279             :     if( rValue.hasValue())
     280             :     {
     281             :         cppu::IPropertyArrayHelper & rPH = getInfoHelper();
     282             :         OUString aName;
     283             :         rPH.fillPropertyMembersByHandle( &aName, 0, nHandle );
     284             :         OSL_ENSURE( rValue.isExtractableTo( rPH.getPropertyByName( aName ).Type ),
     285             :                     "Property type is wrong" );
     286             :     }
     287             : #endif
     288             : 
     289        5187 :     Any aDefault;
     290             :     try
     291             :     {
     292        5187 :         aDefault = GetDefaultValue( nHandle );
     293             :     }
     294           0 :     catch( const beans::UnknownPropertyException& )
     295             :     {
     296           0 :         aDefault.clear();
     297             :     }
     298        5187 :     m_pImplProperties->SetPropertyValueByHandle( nHandle, rValue );
     299        5187 :     if( !m_bSetNewValuesExplicitlyEvenIfTheyEqualDefault && aDefault.hasValue() && aDefault == rValue ) //#i98893# don't export defaults to file
     300         161 :         m_pImplProperties->SetPropertyToDefault( nHandle );
     301             :     else
     302        5026 :         m_pImplProperties->SetPropertyValueByHandle( nHandle, rValue );
     303        5187 : }
     304             : 
     305       55098 : void SAL_CALL OPropertySet::getFastPropertyValue
     306             :     ( Any& rValue,
     307             :       sal_Int32 nHandle ) const
     308             : {
     309       55098 :     if( ! m_pImplProperties->GetPropertyValueByHandle( rValue, nHandle ))
     310             :     {
     311             :         // property was not set -> try style
     312       52283 :         uno::Reference< beans::XFastPropertySet > xStylePropSet( m_pImplProperties->GetStyle(), uno::UNO_QUERY );
     313       52283 :         if( xStylePropSet.is() )
     314             :         {
     315             : #ifdef DBG_UTIL
     316             :             {
     317             :                 // check if the handle of the style points to the same property
     318             :                 // name as the handle in this property set
     319             :                 uno::Reference< beans::XPropertySet > xPropSet( xStylePropSet, uno::UNO_QUERY );
     320             :                 if( xPropSet.is())
     321             :                 {
     322             :                     uno::Reference< beans::XPropertySetInfo > xInfo( xPropSet->getPropertySetInfo(),
     323             :                                                                      uno::UNO_QUERY );
     324             :                     if( xInfo.is() )
     325             :                     {
     326             :                         // for some reason the virtual method getInfoHelper() is
     327             :                         // not const
     328             :                         ::cppu::IPropertyArrayHelper & rPH =
     329             :                               const_cast< OPropertySet * >( this )->getInfoHelper();
     330             : 
     331             :                         // find the Property with Handle nHandle in Style
     332             :                         Sequence< beans::Property > aProps( xInfo->getProperties() );
     333             :                         sal_Int32 nI = aProps.getLength() - 1;
     334             :                         while( ( nI >= 0 ) && nHandle != aProps[ nI ].Handle )
     335             :                             --nI;
     336             : 
     337             :                         if( nI >= 0 ) // => nHandle == aProps[nI].Handle
     338             :                         {
     339             :                             // check whether the handle in this property set is
     340             :                             // the same as the one in the style
     341             :                             beans::Property aProp( rPH.getPropertyByName( aProps[ nI ].Name ) );
     342             :                             OSL_ENSURE( nHandle == aProp.Handle,
     343             :                                         "HandleCheck: Handles for same property differ!" );
     344             : 
     345             :                             if( nHandle == aProp.Handle )
     346             :                             {
     347             :                                 OSL_ENSURE( aProp.Type == aProps[nI].Type,
     348             :                                             "HandleCheck: Types differ!" );
     349             :                                 OSL_ENSURE( aProp.Attributes == aProps[nI].Attributes,
     350             :                                             "HandleCheck: Attributes differ!" );
     351             :                             }
     352             :                         }
     353             :                         else
     354             :                         {
     355             :                             OSL_FAIL(  "HandleCheck: Handle not found in Style" );
     356             :                         }
     357             :                     }
     358             :                     else
     359             :                         OSL_FAIL( "HandleCheck: Invalid XPropertySetInfo returned" );
     360             :                 }
     361             :                 else
     362             :                     OSL_FAIL( "HandleCheck: XPropertySet not supported" );
     363             :             }
     364             : #endif
     365           0 :             rValue = xStylePropSet->getFastPropertyValue( nHandle );
     366             :         }
     367             :         else
     368             :         {
     369             :             // there is no style (or the style does not support XFastPropertySet)
     370             :             // => take the default value
     371             :             try
     372             :             {
     373       52283 :                 rValue = GetDefaultValue( nHandle );
     374             :             }
     375           0 :             catch( const beans::UnknownPropertyException& )
     376             :             {
     377           0 :                 rValue.clear();
     378             :             }
     379       52283 :         }
     380             :     }
     381       55098 : }
     382             : 
     383           0 : void OPropertySet::firePropertyChangeEvent()
     384             : {
     385             :     // nothing in base class
     386           0 : }
     387             : 
     388             : // ____ XStyleSupplier ____
     389           0 : Reference< style::XStyle > SAL_CALL OPropertySet::getStyle()
     390             :     throw (uno::RuntimeException)
     391             : {
     392           0 :     return m_pImplProperties->GetStyle();
     393             : }
     394             : 
     395           0 : void SAL_CALL OPropertySet::setStyle( const Reference< style::XStyle >& xStyle )
     396             :     throw (lang::IllegalArgumentException,
     397             :            uno::RuntimeException)
     398             : {
     399           0 :     if( ! m_pImplProperties->SetStyle( xStyle ))
     400             :         throw lang::IllegalArgumentException(
     401             :             OUString( RTL_CONSTASCII_USTRINGPARAM( "Empty Style" )),
     402             :             static_cast< beans::XPropertySet * >( this ),
     403           0 :             0 );
     404           0 : }
     405             : 
     406             : // ____ XMultiPropertySet ____
     407        1294 : void SAL_CALL OPropertySet::setPropertyValues(
     408             :     const Sequence< OUString >& PropertyNames, const Sequence< Any >& Values )
     409             :     throw(beans::PropertyVetoException,
     410             :           lang::IllegalArgumentException,
     411             :           lang::WrappedTargetException,
     412             :           uno::RuntimeException)
     413             : {
     414        1294 :     ::cppu::OPropertySetHelper::setPropertyValues( PropertyNames, Values );
     415             : 
     416        1294 :     firePropertyChangeEvent();
     417        1294 : }
     418             : 
     419             : // ____ XFastPropertySet ____
     420        9343 : void SAL_CALL OPropertySet::setFastPropertyValue( sal_Int32 nHandle, const Any& rValue )
     421             :     throw(beans::UnknownPropertyException,
     422             :           beans::PropertyVetoException,
     423             :           lang::IllegalArgumentException,
     424             :           lang::WrappedTargetException, uno::RuntimeException)
     425             : {
     426        9343 :     ::cppu::OPropertySetHelper::setFastPropertyValue( nHandle, rValue );
     427             : 
     428        9343 :     firePropertyChangeEvent();
     429        9343 : }
     430             : 
     431             : 
     432             : } //  namespace property
     433             : 
     434             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10