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

Generated by: LCOV version 1.10