LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbaoleobjects.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 37 65 56.9 %
Date: 2014-04-11 Functions: 9 20 45.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 <com/sun/star/container/XEnumerationAccess.hpp>
      21             : #include <com/sun/star/drawing/XControlShape.hpp>
      22             : #include <com/sun/star/container/XNamed.hpp>
      23             : #include <ooo/vba/excel/XOLEObject.hpp>
      24             : 
      25             : #include "vbaoleobject.hxx"
      26             : #include "vbaoleobjects.hxx"
      27             : 
      28             : using namespace com::sun::star;
      29             : using namespace ooo::vba;
      30             : 
      31             : typedef ::cppu::WeakImplHelper1< container::XIndexAccess > XIndexAccess_BASE;
      32             : 
      33           2 : class IndexAccessWrapper : public XIndexAccess_BASE
      34             : {
      35             : typedef std::vector< uno::Reference< drawing::XControlShape > > OLEObjects;
      36             :     OLEObjects vObjects;
      37             : public:
      38           1 :         IndexAccessWrapper(  const uno::Reference< container::XIndexAccess >& xIndexAccess )
      39           1 :     {
      40           1 :         sal_Int32 nLen = xIndexAccess->getCount();
      41           5 :         for ( sal_Int32 index = 0; index < nLen; ++index )
      42             :         {
      43           4 :                 uno::Reference< drawing::XControlShape > xControlShape( xIndexAccess->getByIndex( index), uno::UNO_QUERY);
      44           4 :             if ( xControlShape.is() )
      45           4 :                 vObjects.push_back( xControlShape );
      46           4 :         }
      47           1 :     }
      48             : 
      49           5 :     virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      50             :     {
      51           5 :         return vObjects.size();
      52             :     }
      53             : 
      54           4 :     virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
      55             :     {
      56           4 :         if ( Index < 0 || Index >= getCount() )
      57           0 :             throw lang::IndexOutOfBoundsException();
      58           4 :         return uno::makeAny( vObjects[ Index ] );
      59             :     }
      60             : 
      61             :         // Methods XElementAcess
      62           0 :         virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      63             :         {
      64           0 :             return cppu::UnoType<drawing::XControlShape>::get();
      65             :         }
      66             : 
      67           0 :         virtual sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      68             :         {
      69           0 :             return ( getCount() > 0 );
      70             :         }
      71             : 
      72             : };
      73             : 
      74           0 : class EnumWrapper : public EnumerationHelper_BASE
      75             : {
      76             : 
      77             :         uno::Reference<XHelperInterface > m_xParent;
      78             :         uno::Reference<uno::XComponentContext > m_xContext;
      79             :         uno::Reference<container::XIndexAccess > m_xIndexAccess;
      80             :         sal_Int32 nIndex;
      81             : public:
      82           0 :         EnumWrapper(  const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< container::XIndexAccess >& xIndexAccess ) :  m_xParent( xParent ), m_xContext( xContext), m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {}
      83             : 
      84           0 :         virtual sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      85             :         {
      86           0 :                 return ( nIndex < m_xIndexAccess->getCount() );
      87             :         }
      88             : 
      89           0 :         virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
      90             :         {
      91           0 :                 if ( nIndex < m_xIndexAccess->getCount() )
      92             :         {
      93           0 :             uno::Reference< drawing::XControlShape > xControlShape (  m_xIndexAccess->getByIndex( nIndex++ ), uno::UNO_QUERY_THROW );
      94           0 :                 return uno::makeAny( uno::Reference< ov::excel::XOLEObject >( new ScVbaOLEObject( m_xParent, m_xContext, xControlShape ) ) );
      95             :         }
      96           0 :                 throw container::NoSuchElementException();
      97             :         }
      98             : };
      99             : 
     100           1 : uno::Reference< container::XIndexAccess > oleObjectIndexWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess )
     101             : {
     102           1 :     return new IndexAccessWrapper( xIndexAccess );
     103             : }
     104             : 
     105           1 : ScVbaOLEObjects::ScVbaOLEObjects( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext,
     106             :                 const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess )
     107           1 :             : OLEObjectsImpl_BASE( xParent, xContext, oleObjectIndexWrapper( xIndexAccess  ) )
     108             : {
     109           1 : }
     110             : uno::Reference< container::XEnumeration >
     111           0 : ScVbaOLEObjects::createEnumeration() throw (uno::RuntimeException)
     112             : {
     113           0 :     return new EnumWrapper( getParent(), mxContext, m_xIndexAccess );
     114             : }
     115             : 
     116             : uno::Any
     117           1 : ScVbaOLEObjects::createCollectionObject( const css::uno::Any& aSource )
     118             : {
     119           1 :     if( aSource.hasValue() )
     120             :     {
     121           1 :         uno::Reference< drawing::XControlShape > xControlShape( aSource, uno::UNO_QUERY_THROW );
     122             :     // parent of OLEObject is the same parent as the collection ( e.g. the sheet )
     123           1 :         return uno::makeAny( uno::Reference< ov::excel::XOLEObject >( new ScVbaOLEObject( getParent(), mxContext, xControlShape ) ) );
     124             :     }
     125           0 :     return uno::Any();
     126             : }
     127             : 
     128             : uno::Any
     129           1 : ScVbaOLEObjects::getItemByStringIndex( const OUString& sIndex ) throw (uno::RuntimeException)
     130             : {
     131             :     try
     132             :     {
     133           1 :         return OLEObjectsImpl_BASE::getItemByStringIndex( sIndex );
     134             :     }
     135           1 :     catch (const uno::RuntimeException&)
     136             :     {
     137           1 :         uno::Reference< container::XIndexAccess > xIndexAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
     138           1 :         sal_Int32 nCount = xIndexAccess->getCount();
     139           4 :         for( int index = 0; index < nCount; index++ )
     140             :         {
     141           4 :             uno::Any aUnoObj =  xIndexAccess->getByIndex( index );
     142           7 :             uno::Reference< drawing::XControlShape > xControlShape( aUnoObj, uno::UNO_QUERY_THROW );
     143           7 :             uno::Reference< awt::XControlModel > xControlModel( xControlShape->getControl() );
     144           7 :             uno::Reference< container::XNamed > xNamed( xControlModel, uno::UNO_QUERY_THROW );
     145           4 :             if( sIndex.equals( xNamed->getName() ))
     146             :             {
     147           1 :                 return createCollectionObject( aUnoObj );
     148             :             }
     149             : 
     150           3 :         }
     151           0 :         return uno::Any();
     152             :     }
     153             : }
     154             : 
     155             : uno::Type
     156           0 : ScVbaOLEObjects::getElementType() throw (uno::RuntimeException)
     157             : {
     158           0 :     return cppu::UnoType<ooo::vba::excel::XOLEObject>::get();
     159             : }
     160             : 
     161             : OUString
     162           0 : ScVbaOLEObjects::getServiceImplName()
     163             : {
     164           0 :     return OUString("ScVbaOLEObjects");
     165             : }
     166             : 
     167             : uno::Sequence< OUString >
     168           0 : ScVbaOLEObjects::getServiceNames()
     169             : {
     170           0 :     static uno::Sequence< OUString > aServiceNames;
     171           0 :     if ( aServiceNames.getLength() == 0 )
     172             :     {
     173           0 :         aServiceNames.realloc( 1 );
     174           0 :         aServiceNames[ 0 ] = "ooo.vba.excel.OLEObjects";
     175             :     }
     176           0 :     return aServiceNames;
     177             : }
     178             : 
     179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10