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

Generated by: LCOV version 1.10