LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/vba - vbaoleobjects.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 65 0.0 %
Date: 2012-12-27 Functions: 0 20 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 <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           0 : class IndexAccessWrapper : public XIndexAccess_BASE
      34             : {
      35             : typedef std::vector< uno::Reference< drawing::XControlShape > > OLEObjects;
      36             :     OLEObjects vObjects;
      37             : public:
      38           0 :         IndexAccessWrapper(  const uno::Reference< container::XIndexAccess >& xIndexAccess )
      39           0 :     {
      40           0 :         sal_Int32 nLen = xIndexAccess->getCount();
      41           0 :         for ( sal_Int32 index = 0; index < nLen; ++index )
      42             :         {
      43           0 :                 uno::Reference< drawing::XControlShape > xControlShape( xIndexAccess->getByIndex( index), uno::UNO_QUERY);
      44           0 :             if ( xControlShape.is() )
      45           0 :                 vObjects.push_back( xControlShape );
      46           0 :         }
      47           0 :     }
      48             : 
      49           0 :     virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException)
      50             :     {
      51           0 :         return vObjects.size();
      52             :     }
      53             : 
      54           0 :     virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
      55             :     {
      56           0 :         if ( Index < 0 || Index >= getCount() )
      57           0 :             throw lang::IndexOutOfBoundsException();
      58           0 :         return uno::makeAny( vObjects[ Index ] );
      59             :     }
      60             : 
      61             :         // Methods XElementAcess
      62           0 :         virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException)
      63             :         {
      64           0 :             return drawing::XControlShape::static_type(0);
      65             :         }
      66             : 
      67           0 :         virtual ::sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException)
      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)
      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)
      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           0 : uno::Reference< container::XIndexAccess > oleObjectIndexWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess )
     101             : {
     102           0 :     return new IndexAccessWrapper( xIndexAccess );
     103             : }
     104             : 
     105           0 : ScVbaOLEObjects::ScVbaOLEObjects( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext,
     106             :                 const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess )
     107           0 :             : OLEObjectsImpl_BASE( xParent, xContext, oleObjectIndexWrapper( xIndexAccess  ) )
     108             : {
     109           0 : }
     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           0 : ScVbaOLEObjects::createCollectionObject( const css::uno::Any& aSource )
     118             : {
     119           0 :     if( aSource.hasValue() )
     120             :     {
     121           0 :         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           0 :         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           0 : ScVbaOLEObjects::getItemByStringIndex( const rtl::OUString& sIndex ) throw (uno::RuntimeException)
     130             : {
     131             :     try
     132             :     {
     133           0 :         return OLEObjectsImpl_BASE::getItemByStringIndex( sIndex );
     134             :     }
     135           0 :     catch (const uno::RuntimeException&)
     136             :     {
     137           0 :         uno::Reference< container::XIndexAccess > xIndexAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
     138           0 :         sal_Int32 nCount = xIndexAccess->getCount();
     139           0 :         for( int index = 0; index < nCount; index++ )
     140             :         {
     141           0 :             uno::Any aUnoObj =  xIndexAccess->getByIndex( index );
     142           0 :             uno::Reference< drawing::XControlShape > xControlShape( aUnoObj, uno::UNO_QUERY_THROW );
     143           0 :             uno::Reference< awt::XControlModel > xControlModel( xControlShape->getControl() );
     144           0 :             uno::Reference< container::XNamed > xNamed( xControlModel, uno::UNO_QUERY_THROW );
     145           0 :             if( sIndex.equals( xNamed->getName() ))
     146             :             {
     147           0 :                 return createCollectionObject( aUnoObj );
     148             :             }
     149             : 
     150           0 :         }
     151           0 :         return uno::Any();
     152             :     }
     153             : }
     154             : 
     155             : uno::Type
     156           0 : ScVbaOLEObjects::getElementType() throw (uno::RuntimeException)
     157             : {
     158           0 :     return ooo::vba::excel::XOLEObject::static_type(0);
     159             : }
     160             : 
     161             : rtl::OUString
     162           0 : ScVbaOLEObjects::getServiceImplName()
     163             : {
     164           0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScVbaOLEObjects"));
     165             : }
     166             : 
     167             : uno::Sequence< rtl::OUString >
     168           0 : ScVbaOLEObjects::getServiceNames()
     169             : {
     170           0 :     static uno::Sequence< rtl::OUString > aServiceNames;
     171           0 :     if ( aServiceNames.getLength() == 0 )
     172             :     {
     173           0 :         aServiceNames.realloc( 1 );
     174           0 :         aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("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