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

Generated by: LCOV version 1.10