LCOV - code coverage report
Current view: top level - libreoffice/framework/source/fwi/uielement - itemcontainer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 101 0.0 %
Date: 2012-12-27 Functions: 0 15 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 <uielement/itemcontainer.hxx>
      21             : #include <uielement/constitemcontainer.hxx>
      22             : #include <threadhelp/resetableguard.hxx>
      23             : #include <comphelper/servicehelper.hxx>
      24             : 
      25             : using namespace cppu;
      26             : using namespace com::sun::star::uno;
      27             : using namespace com::sun::star::lang;
      28             : using namespace com::sun::star::beans;
      29             : using namespace com::sun::star::container;
      30             : 
      31             : const char WRONG_TYPE_EXCEPTION[] = "Type must be com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >";
      32             : 
      33             : namespace framework
      34             : {
      35             : 
      36             : //*****************************************************************************************************************
      37             : //  XInterface, XTypeProvider
      38             : //*****************************************************************************************************************
      39             : 
      40           0 : ItemContainer::ItemContainer( const ShareableMutex& rMutex ) :
      41           0 :     m_aShareMutex( rMutex )
      42             : {
      43           0 : }
      44             : 
      45             : 
      46           0 : ItemContainer::ItemContainer( const ConstItemContainer& rConstItemContainer, const ShareableMutex& rMutex ) : m_aShareMutex( rMutex )
      47             : {
      48           0 :     copyItemContainer( rConstItemContainer.m_aItemVector, rMutex );
      49           0 : }
      50             : 
      51           0 : ItemContainer::ItemContainer( const Reference< XIndexAccess >& rSourceContainer, const ShareableMutex& rMutex ) :
      52           0 :     m_aShareMutex( rMutex )
      53             : {
      54           0 :     if ( rSourceContainer.is() )
      55             :     {
      56           0 :         sal_Int32 nCount = rSourceContainer->getCount();
      57             :         try
      58             :         {
      59           0 :             for ( sal_Int32 i = 0; i < nCount; i++ )
      60             :             {
      61           0 :                 Sequence< PropertyValue > aPropSeq;
      62           0 :                 if ( rSourceContainer->getByIndex( i ) >>= aPropSeq )
      63             :                 {
      64           0 :                     sal_Int32 nContainerIndex = -1;
      65           0 :                     Reference< XIndexAccess > xIndexAccess;
      66           0 :                     for ( sal_Int32 j = 0; j < aPropSeq.getLength(); j++ )
      67             :                     {
      68           0 :                         if ( aPropSeq[j].Name == "ItemDescriptorContainer" )
      69             :                         {
      70           0 :                             aPropSeq[j].Value >>= xIndexAccess;
      71           0 :                             nContainerIndex = j;
      72           0 :                             break;
      73             :                         }
      74             :                     }
      75             : 
      76           0 :                     if ( xIndexAccess.is() && nContainerIndex >= 0 )
      77           0 :                         aPropSeq[nContainerIndex].Value <<= deepCopyContainer( xIndexAccess, rMutex );
      78             : 
      79           0 :                     m_aItemVector.push_back( aPropSeq );
      80             :                 }
      81           0 :             }
      82             :         }
      83           0 :         catch ( const IndexOutOfBoundsException& )
      84             :         {
      85             :         }
      86             :     }
      87           0 : }
      88             : 
      89           0 : ItemContainer::~ItemContainer()
      90             : {
      91           0 : }
      92             : 
      93             : // private
      94           0 : void ItemContainer::copyItemContainer( const std::vector< Sequence< PropertyValue > >& rSourceVector, const ShareableMutex& rMutex )
      95             : {
      96           0 :     const sal_uInt32 nCount = rSourceVector.size();
      97           0 :     for ( sal_uInt32 i = 0; i < nCount; ++i )
      98             :     {
      99           0 :         sal_Int32 nContainerIndex = -1;
     100           0 :         Sequence< PropertyValue > aPropSeq( rSourceVector[i] );
     101           0 :         Reference< XIndexAccess > xIndexAccess;
     102           0 :         for ( sal_Int32 j = 0; j < aPropSeq.getLength(); j++ )
     103             :         {
     104           0 :             if ( aPropSeq[j].Name == "ItemDescriptorContainer" )
     105             :             {
     106           0 :                 aPropSeq[j].Value >>= xIndexAccess;
     107           0 :                 nContainerIndex = j;
     108           0 :                 break;
     109             :             }
     110             :         }
     111             : 
     112           0 :         if ( xIndexAccess.is() && nContainerIndex >= 0 )
     113           0 :             aPropSeq[nContainerIndex].Value <<= deepCopyContainer( xIndexAccess, rMutex );
     114             : 
     115           0 :         m_aItemVector.push_back( aPropSeq );
     116           0 :     }
     117           0 : }
     118             : 
     119           0 : Reference< XIndexAccess > ItemContainer::deepCopyContainer( const Reference< XIndexAccess >& rSubContainer, const ShareableMutex& rMutex )
     120             : {
     121           0 :     Reference< XIndexAccess > xReturn;
     122           0 :     if ( rSubContainer.is() )
     123             :     {
     124           0 :         ConstItemContainer* pSource = ConstItemContainer::GetImplementation( rSubContainer );
     125           0 :         ItemContainer* pSubContainer( 0 );
     126           0 :         if ( pSource )
     127           0 :             pSubContainer = new ItemContainer( *pSource, rMutex );
     128             :         else
     129           0 :             pSubContainer = new ItemContainer( rSubContainer, rMutex );
     130           0 :         xReturn = Reference< XIndexAccess >( static_cast< OWeakObject* >( pSubContainer ), UNO_QUERY );
     131             :     }
     132             : 
     133           0 :     return xReturn;
     134             : }
     135             : 
     136             : namespace
     137             : {
     138             :     class theItemContainerUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theItemContainerUnoTunnelId > {};
     139             : }
     140             : 
     141           0 : const Sequence< sal_Int8 >& ItemContainer::GetUnoTunnelId() throw()
     142             : {
     143           0 :     return theItemContainerUnoTunnelId::get().getSeq();
     144             : }
     145             : 
     146           0 : ItemContainer* ItemContainer::GetImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxIFace ) throw()
     147             : {
     148           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( rxIFace, ::com::sun::star::uno::UNO_QUERY );
     149           0 :     return xUT.is() ? reinterpret_cast< ItemContainer* >(sal::static_int_cast< sal_IntPtr >(
     150           0 :                           xUT->getSomething( ItemContainer::GetUnoTunnelId() ))) : NULL;
     151             : }
     152             : 
     153             : // XElementAccess
     154           0 : sal_Bool SAL_CALL ItemContainer::hasElements()
     155             : throw ( RuntimeException )
     156             : {
     157           0 :     ShareGuard aLock( m_aShareMutex );
     158           0 :     return ( !m_aItemVector.empty() );
     159             : }
     160             : 
     161             : // XIndexAccess
     162           0 : sal_Int32 SAL_CALL ItemContainer::getCount()
     163             : throw ( RuntimeException )
     164             : {
     165           0 :     ShareGuard aLock( m_aShareMutex );
     166           0 :     return m_aItemVector.size();
     167             : }
     168             : 
     169           0 : Any SAL_CALL ItemContainer::getByIndex( sal_Int32 Index )
     170             : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
     171             : {
     172           0 :     ShareGuard aLock( m_aShareMutex );
     173           0 :     if ( sal_Int32( m_aItemVector.size()) > Index )
     174           0 :         return makeAny( m_aItemVector[Index] );
     175             :     else
     176           0 :         throw IndexOutOfBoundsException( ::rtl::OUString(), (OWeakObject *)this );
     177             : }
     178             : 
     179             : // XIndexContainer
     180           0 : void SAL_CALL ItemContainer::insertByIndex( sal_Int32 Index, const Any& aItem )
     181             : throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
     182             : {
     183           0 :     Sequence< PropertyValue > aSeq;
     184           0 :     if ( aItem >>= aSeq )
     185             :     {
     186           0 :         ShareGuard aLock( m_aShareMutex );
     187           0 :         if ( sal_Int32( m_aItemVector.size()) == Index )
     188           0 :             m_aItemVector.push_back( aSeq );
     189           0 :         else if ( sal_Int32( m_aItemVector.size()) >Index )
     190             :         {
     191           0 :             std::vector< Sequence< PropertyValue > >::iterator aIter = m_aItemVector.begin();
     192           0 :             aIter += Index;
     193           0 :             m_aItemVector.insert( aIter, aSeq );
     194             :         }
     195             :         else
     196           0 :             throw IndexOutOfBoundsException( ::rtl::OUString(), (OWeakObject *)this );
     197             :     }
     198             :     else
     199             :         throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION )),
     200           0 :                                         (OWeakObject *)this, 2 );
     201           0 : }
     202             : 
     203           0 : void SAL_CALL ItemContainer::removeByIndex( sal_Int32 Index )
     204             : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
     205             : {
     206           0 :     ShareGuard aLock( m_aShareMutex );
     207           0 :     if ( (sal_Int32)m_aItemVector.size() > Index )
     208             :     {
     209           0 :         std::vector< Sequence< PropertyValue > >::iterator aIter = m_aItemVector.begin();
     210           0 :         aIter += Index;
     211           0 :         m_aItemVector.erase( aIter );
     212             :     }
     213             :     else
     214           0 :         throw IndexOutOfBoundsException( ::rtl::OUString(), (OWeakObject *)this );
     215           0 : }
     216             : 
     217           0 : void SAL_CALL ItemContainer::replaceByIndex( sal_Int32 Index, const Any& aItem )
     218             : throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
     219             : {
     220           0 :     Sequence< PropertyValue > aSeq;
     221           0 :     if ( aItem >>= aSeq )
     222             :     {
     223           0 :         ShareGuard aLock( m_aShareMutex );
     224           0 :         if ( sal_Int32( m_aItemVector.size()) > Index )
     225           0 :             m_aItemVector[Index] = aSeq;
     226             :         else
     227           0 :             throw IndexOutOfBoundsException( ::rtl::OUString(), (OWeakObject *)this );
     228             :     }
     229             :     else
     230             :         throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION )),
     231           0 :                                         (OWeakObject *)this, 2 );
     232           0 : }
     233             : 
     234             : } // namespace framework
     235             : 
     236             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10