LCOV - code coverage report
Current view: top level - libreoffice/comphelper/source/property - propstate.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 8 93 8.6 %
Date: 2012-12-27 Functions: 3 21 14.3 %
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 <comphelper/propstate.hxx>
      21             : #include <com/sun/star/uno/genfunc.h>
      22             : #include <cppuhelper/queryinterface.hxx>
      23             : #include <comphelper/sequence.hxx>
      24             : #include <rtl/instance.hxx>
      25             : 
      26             : //.........................................................................
      27             : namespace comphelper
      28             : {
      29             : //.........................................................................
      30             : 
      31             :     using ::com::sun::star::uno::Reference;
      32             :     using ::com::sun::star::uno::Type;
      33             :     using ::com::sun::star::uno::RuntimeException;
      34             :     using ::com::sun::star::uno::Sequence;
      35             :     using ::com::sun::star::lang::XTypeProvider;
      36             :     using ::com::sun::star::uno::Any;
      37             :     using ::com::sun::star::uno::cpp_queryInterface;
      38             :     using ::com::sun::star::uno::cpp_release;
      39             :     using ::com::sun::star::beans::PropertyState_DEFAULT_VALUE;
      40             :     using ::com::sun::star::beans::PropertyState_DIRECT_VALUE;
      41             : 
      42             :     //=====================================================================
      43             :     // OPropertyStateHelper
      44             :     //=====================================================================
      45             : 
      46             :     //---------------------------------------------------------------------
      47         486 :     ::com::sun::star::uno::Any SAL_CALL OPropertyStateHelper::queryInterface(const  ::com::sun::star::uno::Type& _rType) throw( ::com::sun::star::uno::RuntimeException)
      48             :     {
      49         486 :         ::com::sun::star::uno::Any aReturn = OPropertySetHelper2::queryInterface(_rType);
      50             :         // our own ifaces
      51         486 :         if ( !aReturn.hasValue() )
      52         208 :             aReturn = ::cppu::queryInterface(_rType, static_cast< ::com::sun::star::beans::XPropertyState*>(this));
      53             : 
      54         486 :         return aReturn;
      55             :     }
      56             : 
      57             :     //---------------------------------------------------------------------
      58           0 :     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> OPropertyStateHelper::getTypes() throw( ::com::sun::star::uno::RuntimeException)
      59             :     {
      60           0 :         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> aTypes(4);
      61           0 :         ::com::sun::star::uno::Type* pTypes = aTypes.getArray();
      62             :         // base class types
      63           0 :         pTypes[0] = getCppuType(( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>*)NULL);
      64           0 :         pTypes[1] = getCppuType(( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet>*)NULL);
      65           0 :         pTypes[2] = getCppuType(( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet>*)NULL);
      66             :         // my own type
      67           0 :         pTypes[3] = getCppuType(( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState>*)NULL);
      68           0 :         return aTypes;
      69             :     }
      70             : 
      71         133 :     OPropertyStateHelper::OPropertyStateHelper(
      72             :         ::cppu::OBroadcastHelper& rBHlp,
      73             :         ::cppu::IEventNotificationHook *i_pFireEvents)
      74         133 :         :   ::cppu::OPropertySetHelper2(rBHlp, i_pFireEvents) { }
      75             : 
      76          83 :     OPropertyStateHelper::~OPropertyStateHelper() {}
      77             : 
      78             :     //---------------------------------------------------------------------
      79           0 :     void OPropertyStateHelper::firePropertyChange(sal_Int32 nHandle, const  ::com::sun::star::uno::Any& aNewValue, const  ::com::sun::star::uno::Any& aOldValue)
      80             :     {
      81           0 :         fire(&nHandle, &aNewValue, &aOldValue, 1, sal_False);
      82           0 :     }
      83             : 
      84             :     // XPropertyState
      85             :     //---------------------------------------------------------------------
      86           0 :     ::com::sun::star::beans::PropertyState SAL_CALL OPropertyStateHelper::getPropertyState(const ::rtl::OUString& _rsName) throw( ::com::sun::star::beans::UnknownPropertyException,  ::com::sun::star::uno::RuntimeException)
      87             :     {
      88           0 :         cppu::IPropertyArrayHelper& rPH = getInfoHelper();
      89           0 :         sal_Int32 nHandle = rPH.getHandleByName(_rsName);
      90             : 
      91           0 :         if (nHandle == -1)
      92           0 :             throw  ::com::sun::star::beans::UnknownPropertyException();
      93             : 
      94           0 :         return getPropertyStateByHandle(nHandle);
      95             :     }
      96             : 
      97             :     //---------------------------------------------------------------------
      98           0 :     void SAL_CALL OPropertyStateHelper::setPropertyToDefault(const ::rtl::OUString& _rsName) throw( ::com::sun::star::beans::UnknownPropertyException,  ::com::sun::star::uno::RuntimeException)
      99             :     {
     100           0 :         cppu::IPropertyArrayHelper& rPH = getInfoHelper();
     101           0 :         sal_Int32 nHandle = rPH.getHandleByName(_rsName);
     102             : 
     103           0 :         if (nHandle == -1)
     104           0 :             throw  ::com::sun::star::beans::UnknownPropertyException();
     105             : 
     106           0 :         setPropertyToDefaultByHandle(nHandle);
     107           0 :     }
     108             : 
     109             :     //---------------------------------------------------------------------
     110           0 :     ::com::sun::star::uno::Any SAL_CALL OPropertyStateHelper::getPropertyDefault(const ::rtl::OUString& _rsName) throw( ::com::sun::star::beans::UnknownPropertyException,  ::com::sun::star::lang::WrappedTargetException,  ::com::sun::star::uno::RuntimeException)
     111             :     {
     112           0 :         cppu::IPropertyArrayHelper& rPH = getInfoHelper();
     113           0 :         sal_Int32 nHandle = rPH.getHandleByName(_rsName);
     114             : 
     115           0 :         if (nHandle == -1)
     116           0 :             throw  ::com::sun::star::beans::UnknownPropertyException();
     117             : 
     118           0 :         return getPropertyDefaultByHandle(nHandle);
     119             :     }
     120             : 
     121             :     //---------------------------------------------------------------------
     122           0 :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState> SAL_CALL OPropertyStateHelper::getPropertyStates(const  ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rPropertyNames) throw( ::com::sun::star::beans::UnknownPropertyException,  ::com::sun::star::uno::RuntimeException)
     123             :     {
     124           0 :         sal_Int32 nLen = _rPropertyNames.getLength();
     125           0 :         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState> aRet(nLen);
     126           0 :         ::com::sun::star::beans::PropertyState* pValues = aRet.getArray();
     127           0 :         const ::rtl::OUString* pNames = _rPropertyNames.getConstArray();
     128             : 
     129           0 :         cppu::IPropertyArrayHelper& rHelper = getInfoHelper();
     130             : 
     131           0 :         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> aProps = rHelper.getProperties();
     132           0 :         const  ::com::sun::star::beans::Property* pProps = aProps.getConstArray();
     133           0 :         sal_Int32 nPropCount       = aProps.getLength();
     134             : 
     135           0 :         osl::MutexGuard aGuard(rBHelper.rMutex);
     136           0 :         for (sal_Int32 i=0, j=0; i<nPropCount && j<nLen; ++i, ++pProps)
     137             :         {
     138             :             // get the values only for valid properties
     139           0 :             if (pProps->Name.equals(*pNames))
     140             :             {
     141           0 :                 *pValues = getPropertyState(*pNames);
     142           0 :                 ++pValues;
     143           0 :                 ++pNames;
     144           0 :                 ++j;
     145             :             }
     146             :         }
     147             : 
     148           0 :         return aRet;
     149             :     }
     150             : 
     151             :     //---------------------------------------------------------------------
     152           0 :     ::com::sun::star::beans::PropertyState OPropertyStateHelper::getPropertyStateByHandle( sal_Int32 _nHandle )
     153             :     {
     154             :         // simply compare the current and the default value
     155           0 :         Any aCurrentValue = getPropertyDefaultByHandle( _nHandle );
     156           0 :         Any aDefaultValue;  getFastPropertyValue( aDefaultValue, _nHandle );
     157             : 
     158             :         sal_Bool bEqual = uno_type_equalData(
     159           0 :                 const_cast< void* >( aCurrentValue.getValue() ), aCurrentValue.getValueType().getTypeLibType(),
     160           0 :                 const_cast< void* >( aDefaultValue.getValue() ), aDefaultValue.getValueType().getTypeLibType(),
     161             :                 reinterpret_cast< uno_QueryInterfaceFunc >(cpp_queryInterface),
     162             :                 reinterpret_cast< uno_ReleaseFunc >(cpp_release)
     163           0 :             );
     164           0 :         return bEqual ? PropertyState_DEFAULT_VALUE : PropertyState_DIRECT_VALUE;
     165             :     }
     166             : 
     167             :     //---------------------------------------------------------------------
     168           0 :     void OPropertyStateHelper::setPropertyToDefaultByHandle( sal_Int32 _nHandle )
     169             :     {
     170           0 :         setFastPropertyValue( _nHandle, getPropertyDefaultByHandle( _nHandle ) );
     171           0 :     }
     172             : 
     173             :     //---------------------------------------------------------------------
     174           0 :     ::com::sun::star::uno::Any OPropertyStateHelper::getPropertyDefaultByHandle( sal_Int32 ) const
     175             :     {
     176           0 :         return  ::com::sun::star::uno::Any();
     177             :     }
     178             : 
     179             :     //=====================================================================
     180             :     // OStatefulPropertySet
     181             :     //=====================================================================
     182             :     //---------------------------------------------------------------------
     183           0 :     OStatefulPropertySet::OStatefulPropertySet()
     184           0 :         :OPropertyStateHelper( GetBroadcastHelper() )
     185             :     {
     186           0 :     }
     187             : 
     188             :     //---------------------------------------------------------------------
     189           0 :     OStatefulPropertySet::~OStatefulPropertySet()
     190             :     {
     191           0 :     }
     192             : 
     193             :     //---------------------------------------------------------------------
     194           0 :     Sequence< Type > SAL_CALL OStatefulPropertySet::getTypes() throw(RuntimeException)
     195             :     {
     196           0 :         Sequence< Type > aOwnTypes( 2 );
     197           0 :         aOwnTypes[0] = XWeak::static_type();
     198           0 :         aOwnTypes[1] = XTypeProvider::static_type();
     199             : 
     200             :         return concatSequences(
     201             :             aOwnTypes,
     202             :             OPropertyStateHelper::getTypes()
     203           0 :         );
     204             :     }
     205             : 
     206             :     namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; }
     207             : 
     208             :     //---------------------------------------------------------------------
     209           0 :     Sequence< sal_Int8 > SAL_CALL OStatefulPropertySet::getImplementationId() throw(RuntimeException)
     210             :     {
     211           0 :         ::cppu::OImplementationId &rID = lcl_ImplId::get();
     212           0 :         return rID.getImplementationId();
     213             :     }
     214             : 
     215             :     //---------------------------------------------------------------------
     216           0 :     Any SAL_CALL OStatefulPropertySet::queryInterface( const Type& _rType ) throw(RuntimeException)
     217             :     {
     218           0 :         Any aReturn = OWeakObject::queryInterface( _rType );
     219           0 :         if ( !aReturn.hasValue() )
     220           0 :             aReturn = ::cppu::queryInterface( _rType, static_cast< XTypeProvider* >( this ) );
     221           0 :         if ( !aReturn.hasValue() )
     222           0 :             aReturn = OPropertyStateHelper::queryInterface( _rType );
     223           0 :         return aReturn;
     224             :     }
     225             : 
     226             :     //---------------------------------------------------------------------
     227           0 :     void SAL_CALL OStatefulPropertySet::acquire() throw()
     228             :     {
     229           0 :         ::cppu::OWeakObject::acquire();
     230           0 :     }
     231             : 
     232             :     //---------------------------------------------------------------------
     233           0 :     void SAL_CALL OStatefulPropertySet::release() throw()
     234             :     {
     235           0 :         ::cppu::OWeakObject::release();
     236           0 :     }
     237             : 
     238             : //.........................................................................
     239             : }
     240             : //.........................................................................
     241             : 
     242             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10