LCOV - code coverage report
Current view: top level - framework/source/fwi/uielement - constitemcontainer.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 57 144 39.6 %
Date: 2015-06-13 12:38:46 Functions: 10 32 31.2 %
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 <string.h>
      21             : 
      22             : #include <uielement/constitemcontainer.hxx>
      23             : #include <uielement/rootitemcontainer.hxx>
      24             : #include <uielement/itemcontainer.hxx>
      25             : 
      26             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      27             : 
      28             : #include <cppuhelper/implbase1.hxx>
      29             : #include <comphelper/servicehelper.hxx>
      30             : 
      31             : using namespace cppu;
      32             : using namespace com::sun::star::uno;
      33             : using namespace com::sun::star::lang;
      34             : using namespace com::sun::star::beans;
      35             : using namespace com::sun::star::container;
      36             : 
      37             : const int PROPHANDLE_UINAME     = 1;
      38             : const int PROPCOUNT             = 1;
      39             : const char PROPNAME_UINAME[]    = "UIName";
      40             : 
      41             : namespace framework
      42             : {
      43             : 
      44             : /**
      45             :  * The class which implements the PropertySetInfo interface.
      46             :  */
      47             : extern "C"
      48             : {
      49           0 : static int SAL_CALL compare_OUString_Property_Impl( const void *arg1, const void *arg2 )
      50             : {
      51           0 :    return static_cast<OUString const *>(arg1)->compareTo( static_cast<Property const *>(arg2)->Name );
      52             : }
      53             : }
      54             : 
      55           0 : class OPropertySetHelperInfo_Impl
      56             :     : public WeakImplHelper1< ::com::sun::star::beans::XPropertySetInfo >
      57             : {
      58             :     Sequence < Property > aInfos;
      59             : 
      60             : public:
      61             :     OPropertySetHelperInfo_Impl( IPropertyArrayHelper & rHelper_ );
      62             : 
      63             :     // XPropertySetInfo-Methoden
      64             :     virtual Sequence< Property > SAL_CALL getProperties() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      65             :     virtual Property SAL_CALL getPropertyByName(const OUString& PropertyName) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      66             :     virtual sal_Bool SAL_CALL hasPropertyByName(const OUString& PropertyName) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      67             : };
      68             : 
      69             : /**
      70             :  * Create an object that implements XPropertySetInfo IPropertyArrayHelper.
      71             :  */
      72           0 : OPropertySetHelperInfo_Impl::OPropertySetHelperInfo_Impl(
      73             :     IPropertyArrayHelper & rHelper_ )
      74           0 :     :aInfos( rHelper_.getProperties() )
      75             : {
      76           0 : }
      77             : 
      78             : /**
      79             :  * Return the sequence of properties, which are provided through the constructor.
      80             :  */
      81           0 : Sequence< Property > OPropertySetHelperInfo_Impl::getProperties() throw(::com::sun::star::uno::RuntimeException, std::exception)
      82             : {
      83           0 :     return aInfos;
      84             : }
      85             : 
      86             : /**
      87             :  * Return the sequence of properties, which are provided through the constructor.
      88             :  */
      89           0 : Property OPropertySetHelperInfo_Impl::getPropertyByName( const OUString & PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException, std::exception)
      90             : {
      91             :     Property * pR;
      92           0 :     pR = static_cast<Property *>(bsearch( &PropertyName, aInfos.getConstArray(), aInfos.getLength(),
      93             :                               sizeof( Property ),
      94           0 :                               compare_OUString_Property_Impl ));
      95           0 :     if( !pR ) {
      96           0 :         throw UnknownPropertyException();
      97             :     }
      98             : 
      99           0 :     return *pR;
     100             : }
     101             : 
     102             : /**
     103             :  * Return the sequence of properties, which are provided through the constructor.
     104             :  */
     105           0 : sal_Bool OPropertySetHelperInfo_Impl::hasPropertyByName( const OUString & PropertyName ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     106             : {
     107             :     Property * pR;
     108           0 :     pR = static_cast<Property *>(bsearch( &PropertyName, aInfos.getConstArray(), aInfos.getLength(),
     109             :                               sizeof( Property ),
     110           0 :                               compare_OUString_Property_Impl ));
     111           0 :     return pR != NULL;
     112             : }
     113             : 
     114           0 : ConstItemContainer::ConstItemContainer()
     115             : {
     116           0 : }
     117             : 
     118           0 : ConstItemContainer::ConstItemContainer( const ItemContainer& rItemContainer )
     119             : {
     120           0 :     ShareGuard aLock( rItemContainer.m_aShareMutex );
     121           0 :     copyItemContainer( rItemContainer.m_aItemVector );
     122           0 : }
     123             : 
     124         411 : ConstItemContainer::ConstItemContainer( const Reference< XIndexAccess >& rSourceContainer, bool bFastCopy )
     125             : {
     126             :     // We also have to copy the UIName property
     127             :     try
     128             :     {
     129         411 :         Reference< XPropertySet > xPropSet( rSourceContainer, UNO_QUERY );
     130         411 :         if ( xPropSet.is() )
     131             :         {
     132         248 :             xPropSet->getPropertyValue("UIName") >>= m_aUIName;
     133         411 :         }
     134             :     }
     135           0 :     catch ( const Exception& )
     136             :     {
     137             :     }
     138             : 
     139         411 :     if ( rSourceContainer.is() )
     140             :     {
     141             :         try
     142             :         {
     143         411 :             sal_Int32 nCount = rSourceContainer->getCount();
     144         411 :             m_aItemVector.reserve(nCount);
     145         411 :             if ( bFastCopy )
     146             :             {
     147        7814 :                 for ( sal_Int32 i = 0; i < nCount; i++ )
     148             :                 {
     149        7570 :                     Sequence< PropertyValue > aPropSeq;
     150        7570 :                     if ( rSourceContainer->getByIndex( i ) >>= aPropSeq )
     151        7570 :                         m_aItemVector.push_back( aPropSeq );
     152        7570 :                 }
     153             :             }
     154             :             else
     155             :             {
     156        1690 :                 for ( sal_Int32 i = 0; i < nCount; i++ )
     157             :                 {
     158        1523 :                     Sequence< PropertyValue > aPropSeq;
     159        1523 :                     if ( rSourceContainer->getByIndex( i ) >>= aPropSeq )
     160             :                     {
     161        1523 :                         sal_Int32 nContainerIndex = -1;
     162        1523 :                         Reference< XIndexAccess > xIndexAccess;
     163        4337 :                         for ( sal_Int32 j = 0; j < aPropSeq.getLength(); j++ )
     164             :                         {
     165        4093 :                             if ( aPropSeq[j].Name == "ItemDescriptorContainer" )
     166             :                             {
     167        1279 :                                 aPropSeq[j].Value >>= xIndexAccess;
     168        1279 :                                 nContainerIndex = j;
     169        1279 :                                 break;
     170             :                             }
     171             :                         }
     172             : 
     173        1523 :                         if ( xIndexAccess.is() && nContainerIndex >= 0 )
     174         163 :                             aPropSeq[nContainerIndex].Value <<= deepCopyContainer( xIndexAccess );
     175             : 
     176        1523 :                         m_aItemVector.push_back( aPropSeq );
     177             :                     }
     178        1523 :                 }
     179             :             }
     180             :         }
     181           0 :         catch ( const IndexOutOfBoundsException& )
     182             :         {
     183             :         }
     184             :     }
     185         411 : }
     186             : 
     187         816 : ConstItemContainer::~ConstItemContainer()
     188             : {
     189         816 : }
     190             : 
     191             : // private
     192           0 : void ConstItemContainer::copyItemContainer( const std::vector< Sequence< PropertyValue > >& rSourceVector )
     193             : {
     194           0 :     const sal_uInt32 nCount = rSourceVector.size();
     195           0 :     for ( sal_uInt32 i = 0; i < nCount; i++ )
     196             :     {
     197           0 :         sal_Int32 nContainerIndex = -1;
     198           0 :         Sequence< PropertyValue > aPropSeq( rSourceVector[i] );
     199           0 :         Reference< XIndexAccess > xIndexAccess;
     200           0 :         for ( sal_Int32 j = 0; j < aPropSeq.getLength(); j++ )
     201             :         {
     202           0 :             if ( aPropSeq[j].Name == "ItemDescriptorContainer" )
     203             :             {
     204           0 :                 aPropSeq[j].Value >>= xIndexAccess;
     205           0 :                 nContainerIndex = j;
     206           0 :                 break;
     207             :             }
     208             :         }
     209             : 
     210           0 :         if ( xIndexAccess.is() && nContainerIndex >= 0 )
     211           0 :             aPropSeq[nContainerIndex].Value <<= deepCopyContainer( xIndexAccess );
     212             : 
     213           0 :         m_aItemVector.push_back( aPropSeq );
     214           0 :     }
     215           0 : }
     216             : 
     217         163 : Reference< XIndexAccess > ConstItemContainer::deepCopyContainer( const Reference< XIndexAccess >& rSubContainer )
     218             : {
     219         163 :     Reference< XIndexAccess > xReturn;
     220         163 :     if ( rSubContainer.is() )
     221             :     {
     222         163 :         ItemContainer*      pSource = ItemContainer::GetImplementation( rSubContainer );
     223         163 :         ConstItemContainer* pSubContainer( 0 );
     224         163 :         if ( pSource )
     225           0 :             pSubContainer = new ConstItemContainer( *pSource );
     226             :         else
     227         163 :             pSubContainer = new ConstItemContainer( rSubContainer );
     228         163 :         xReturn = Reference< XIndexAccess >( static_cast< OWeakObject* >( pSubContainer ), UNO_QUERY );
     229             :     }
     230             : 
     231         163 :     return xReturn;
     232             : }
     233             : 
     234             : // XUnoTunnel
     235          54 : sal_Int64 ConstItemContainer::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rIdentifier ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     236             : {
     237          54 :     if( ( rIdentifier.getLength() == 16 ) && ( 0 == memcmp( ConstItemContainer::GetUnoTunnelId().getConstArray(), rIdentifier.getConstArray(), 16 ) ) )
     238             :     {
     239          54 :         return reinterpret_cast< sal_Int64 >( this );
     240             :     }
     241           0 :     return 0;
     242             : }
     243             : 
     244             : namespace
     245             : {
     246             :     class theConstItemContainerUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theConstItemContainerUnoTunnelId > {};
     247             : }
     248             : 
     249         108 : const Sequence< sal_Int8 >& ConstItemContainer::GetUnoTunnelId() throw()
     250             : {
     251         108 :     return theConstItemContainerUnoTunnelId::get().getSeq();
     252             : }
     253             : 
     254         266 : ConstItemContainer* ConstItemContainer::GetImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxIFace ) throw()
     255             : {
     256         266 :     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( rxIFace, ::com::sun::star::uno::UNO_QUERY );
     257         266 :     return xUT.is() ? reinterpret_cast< ConstItemContainer* >(sal::static_int_cast< sal_IntPtr >(
     258         266 :                           xUT->getSomething( ConstItemContainer::GetUnoTunnelId() ))) : NULL;
     259             : }
     260             : 
     261             : // XElementAccess
     262           0 : sal_Bool SAL_CALL ConstItemContainer::hasElements()
     263             : throw ( RuntimeException, std::exception )
     264             : {
     265           0 :     return ( !m_aItemVector.empty() );
     266             : }
     267             : 
     268             : // XIndexAccess
     269       84546 : sal_Int32 SAL_CALL ConstItemContainer::getCount()
     270             : throw ( RuntimeException, std::exception )
     271             : {
     272       84546 :     return m_aItemVector.size();
     273             : }
     274             : 
     275       81983 : Any SAL_CALL ConstItemContainer::getByIndex( sal_Int32 Index )
     276             : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
     277             : {
     278       81983 :     if ( sal_Int32( m_aItemVector.size()) > Index )
     279      163966 :         return makeAny( m_aItemVector[Index] );
     280             :     else
     281           0 :         throw IndexOutOfBoundsException( OUString(), static_cast<OWeakObject *>(this) );
     282             : }
     283             : 
     284             : // XPropertySet
     285           0 : Reference< XPropertySetInfo > SAL_CALL ConstItemContainer::getPropertySetInfo()
     286             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     287             : {
     288             :     // Optimize this method !
     289             :     // We initialize a static variable only one time. And we don't must use a mutex at every call!
     290             :     // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
     291             :     static Reference< XPropertySetInfo >* pInfo = NULL;
     292             : 
     293           0 :     if( pInfo == NULL )
     294             :     {
     295             :         // Ready for multithreading
     296           0 :         osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() );
     297             :         // Control this pointer again, another instance can be faster then these!
     298           0 :         if( pInfo == NULL )
     299             :         {
     300             :             // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
     301             :             // (Use method "getInfoHelper()".)
     302           0 :             static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
     303           0 :             pInfo = &xInfo;
     304           0 :         }
     305             :     }
     306             : 
     307           0 :     return (*pInfo);
     308             : }
     309             : 
     310           0 : void SAL_CALL ConstItemContainer::setPropertyValue( const OUString&, const Any& )
     311             : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     312             : {
     313           0 : }
     314             : 
     315        1241 : Any SAL_CALL ConstItemContainer::getPropertyValue( const OUString& PropertyName )
     316             : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     317             : {
     318        1241 :     if ( PropertyName == PROPNAME_UINAME )
     319        2482 :         return makeAny( m_aUIName );
     320             : 
     321           0 :     throw UnknownPropertyException();
     322             : }
     323             : 
     324           0 : void SAL_CALL ConstItemContainer::addPropertyChangeListener( const OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& )
     325             : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     326             : {
     327           0 : }
     328             : 
     329           0 : void SAL_CALL ConstItemContainer::removePropertyChangeListener( const OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& )
     330             : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     331             : {
     332             :     // Only read-only properties - do nothing
     333           0 : }
     334             : 
     335           0 : void SAL_CALL ConstItemContainer::addVetoableChangeListener( const OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& )
     336             : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     337             : {
     338             :     // Only read-only properties - do nothing
     339           0 : }
     340             : 
     341           0 : void SAL_CALL ConstItemContainer::removeVetoableChangeListener( const OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& )
     342             : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     343             : {
     344             :     // Only read-only properties - do nothing
     345           0 : }
     346             : 
     347             : // XFastPropertySet
     348           0 : void SAL_CALL ConstItemContainer::setFastPropertyValue( sal_Int32, const ::com::sun::star::uno::Any& )
     349             : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     350             : {
     351           0 : }
     352             : 
     353           0 : Any SAL_CALL ConstItemContainer::getFastPropertyValue( sal_Int32 nHandle )
     354             : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     355             : {
     356           0 :     if ( nHandle == PROPHANDLE_UINAME )
     357           0 :         return makeAny( m_aUIName );
     358             : 
     359           0 :     throw UnknownPropertyException();
     360             : }
     361             : 
     362           0 : ::cppu::IPropertyArrayHelper& SAL_CALL ConstItemContainer::getInfoHelper()
     363             : {
     364             :     // Optimize this method !
     365             :     // We initialize a static variable only one time. And we don't must use a mutex at every call!
     366             :     // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
     367             :     static ::cppu::OPropertyArrayHelper* pInfoHelper = NULL;
     368             : 
     369           0 :     if( pInfoHelper == NULL )
     370             :     {
     371             :         // Ready for multithreading
     372           0 :         osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() );
     373             : 
     374             :         // Control this pointer again, another instance can be faster then these!
     375           0 :         if( pInfoHelper == NULL )
     376             :         {
     377             :             // Define static member to give structure of properties to baseclass "OPropertySetHelper".
     378             :             // "impl_getStaticPropertyDescriptor" is a non exported and static function, who will define a static propertytable.
     379             :             // "sal_True" say: Table is sorted by name.
     380           0 :             static ::cppu::OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True );
     381           0 :             pInfoHelper = &aInfoHelper;
     382           0 :         }
     383             :     }
     384             : 
     385           0 :     return(*pInfoHelper);
     386             : }
     387             : 
     388           0 : const com::sun::star::uno::Sequence< com::sun::star::beans::Property > ConstItemContainer::impl_getStaticPropertyDescriptor()
     389             : {
     390             :     // Create a property array to initialize sequence!
     391             :     // Table of all predefined properties of this class. Its used from OPropertySetHelper-class!
     392             :     // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!!
     393             :     // It's necessary for methods of OPropertySetHelper.
     394             :     // ATTENTION:
     395             :     //      YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!!
     396             : 
     397             :     const com::sun::star::beans::Property pProperties[] =
     398             :     {
     399             :         com::sun::star::beans::Property( OUString(PROPNAME_UINAME), PROPHANDLE_UINAME ,
     400           0 :                                          cppu::UnoType<OUString>::get(),
     401             :                                          com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY  )
     402           0 :     };
     403             :     // Use it to initialize sequence!
     404           0 :     const com::sun::star::uno::Sequence< com::sun::star::beans::Property > lPropertyDescriptor( pProperties, PROPCOUNT );
     405             :     // Return "PropertyDescriptor"
     406           0 :     return lPropertyDescriptor;
     407             : }
     408             : 
     409           0 : Reference < XPropertySetInfo > ConstItemContainer::createPropertySetInfo(
     410             :     IPropertyArrayHelper & rProperties )
     411             : {
     412           0 :     return static_cast< XPropertySetInfo * >( new OPropertySetHelperInfo_Impl( rProperties ) );
     413             : }
     414             : 
     415             : } // namespace framework
     416             : 
     417             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11