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

Generated by: LCOV version 1.10