LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbacells.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 86 0.0 %
Date: 2015-06-13 12:38:46 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             : #include "vbacells.hxx"
      20             : #include "vbacell.hxx"
      21             : #include "wordvbahelper.hxx"
      22             : #include "vbatablehelper.hxx"
      23             : #include "vbarow.hxx"
      24             : #include <cppuhelper/implbase.hxx>
      25             : 
      26             : using namespace ::ooo::vba;
      27             : using namespace ::com::sun::star;
      28             : 
      29             : typedef ::cppu::WeakImplHelper< container::XIndexAccess, container::XEnumerationAccess > CellCollectionHelper_Base;
      30             : 
      31           0 : class CellsEnumWrapper : public EnumerationHelper_BASE
      32             : {
      33             :     uno::Reference< container::XIndexAccess > mxIndexAccess;
      34             :     sal_Int32 nIndex;
      35             : 
      36             : public:
      37           0 :     explicit CellsEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : mxIndexAccess( xIndexAccess ), nIndex( 0 )
      38             :     {
      39           0 :     }
      40           0 :     virtual sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      41             :     {
      42           0 :         return ( nIndex < mxIndexAccess->getCount() );
      43             :     }
      44             : 
      45           0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
      46             :     {
      47           0 :         if( nIndex < mxIndexAccess->getCount() )
      48             :         {
      49           0 :             return mxIndexAccess->getByIndex( nIndex++ );
      50             :         }
      51           0 :         throw container::NoSuchElementException();
      52             :     }
      53             : };
      54             : 
      55             : class CellCollectionHelper : public CellCollectionHelper_Base
      56             : {
      57             : private:
      58             :     uno::Reference< XHelperInterface > mxParent;
      59             :     uno::Reference< uno::XComponentContext > mxContext;
      60             :     uno::Reference< css::text::XTextTable > mxTextTable;
      61             :     sal_Int32 mnLeft;
      62             :     sal_Int32 mnTop;
      63             :     sal_Int32 mnRight;
      64             :     sal_Int32 mnBottom;
      65             : 
      66             : public:
      67           0 :     CellCollectionHelper( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::text::XTextTable >& xTextTable, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw ( css::uno::RuntimeException ): mxParent( xParent ), mxContext( xContext ), mxTextTable( xTextTable ), mnLeft( nLeft ), mnTop( nTop ), mnRight( nRight ), mnBottom( nBottom )
      68             :     {
      69           0 :     }
      70           0 :     virtual ~CellCollectionHelper() {}
      71             : 
      72           0 :     virtual sal_Int32 SAL_CALL getCount(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      73             :     {
      74           0 :         return ( mnRight - mnLeft + 1 ) * ( mnBottom - mnTop + 1 );
      75             :     }
      76           0 :     virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
      77             :     {
      78           0 :         if ( Index < 0 || Index >= getCount() )
      79           0 :             throw css::lang::IndexOutOfBoundsException();
      80             : 
      81           0 :         for( sal_Int32 row = mnTop; row <= mnBottom; row++ )
      82             :         {
      83           0 :             for( sal_Int32 col = mnLeft; col <= mnRight; col++ )
      84             :             {
      85           0 :                 if( Index == ( ( row - mnTop ) * ( mnRight - mnLeft + 1 ) + ( col - mnLeft ) ) )
      86           0 :                     return uno::makeAny( uno::Reference< word::XCell >( new SwVbaCell( mxParent, mxContext, mxTextTable, col, row ) ) );
      87             :             }
      88             :         }
      89           0 :         throw css::lang::IndexOutOfBoundsException();
      90             : 
      91             :     }
      92           0 :     virtual uno::Type SAL_CALL getElementType(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      93             :     {
      94           0 :         return cppu::UnoType<word::XCell>::get();
      95             :     }
      96           0 :     virtual sal_Bool SAL_CALL hasElements(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      97             :     {
      98           0 :         return sal_True;
      99             :     }
     100             :     // XEnumerationAccess
     101           0 :     virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     102             :     {
     103           0 :         return new CellsEnumWrapper( this );
     104             :     }
     105             : };
     106             : 
     107           0 : SwVbaCells::SwVbaCells( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< text::XTextTable >& xTextTable, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw (uno::RuntimeException) : SwVbaCells_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new CellCollectionHelper( xParent, xContext, xTextTable, nLeft, nTop, nRight, nBottom ) ) ), mxTextTable( xTextTable ), mnTop( nTop ), mnBottom( nBottom )
     108             : {
     109           0 : }
     110             : 
     111           0 : ::sal_Int32 SAL_CALL SwVbaCells::getWidth() throw (css::uno::RuntimeException, std::exception)
     112             : {
     113           0 :     uno::Reference< word::XCell > xCell( m_xIndexAccess->getByIndex( 0 ), uno::UNO_QUERY_THROW );
     114           0 :     return xCell->getWidth();
     115             : }
     116             : 
     117           0 : void SAL_CALL SwVbaCells::setWidth( ::sal_Int32 _width ) throw (css::uno::RuntimeException, std::exception)
     118             : {
     119           0 :     sal_Int32 nIndex = 0;
     120           0 :     while( nIndex < m_xIndexAccess->getCount() )
     121             :     {
     122           0 :         uno::Reference< word::XCell > xCell( m_xIndexAccess->getByIndex( nIndex++ ), uno::UNO_QUERY_THROW );
     123           0 :         xCell->setWidth( _width );
     124           0 :     }
     125           0 : }
     126             : 
     127           0 : uno::Any SAL_CALL SwVbaCells::getHeight() throw (css::uno::RuntimeException, std::exception)
     128             : {
     129           0 :     uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, mnTop ) );
     130           0 :     return xRow->getHeight();
     131             : }
     132             : 
     133           0 : void SAL_CALL SwVbaCells::setHeight( const uno::Any& _height ) throw (css::uno::RuntimeException, std::exception)
     134             : {
     135           0 :     for( sal_Int32 row = mnTop; row <= mnBottom; row++ )
     136             :     {
     137           0 :         uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, row ) );
     138           0 :         xRow->setHeight( _height );
     139           0 :     }
     140           0 : }
     141             : 
     142           0 : ::sal_Int32 SAL_CALL SwVbaCells::getHeightRule() throw (css::uno::RuntimeException, std::exception)
     143             : {
     144           0 :     uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, mnTop ) );
     145           0 :     return xRow->getHeightRule();
     146             : }
     147             : 
     148           0 : void SAL_CALL SwVbaCells::setHeightRule( ::sal_Int32 _heightrule ) throw (css::uno::RuntimeException, std::exception)
     149             : {
     150           0 :     for( sal_Int32 row = mnTop; row <= mnBottom; row++ )
     151             :     {
     152           0 :         uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, row ) );
     153           0 :         xRow->setHeightRule( _heightrule );
     154           0 :     }
     155           0 : }
     156             : 
     157           0 : void SAL_CALL SwVbaCells::SetWidth( float width, sal_Int32 rulestyle ) throw (css::uno::RuntimeException, std::exception)
     158             : {
     159           0 :     sal_Int32 nIndex = 0;
     160           0 :     while( nIndex < m_xIndexAccess->getCount() )
     161             :     {
     162           0 :         uno::Reference< word::XCell > xCell( m_xIndexAccess->getByIndex( nIndex++ ), uno::UNO_QUERY_THROW );
     163           0 :         xCell->SetWidth( width, rulestyle );
     164           0 :     }
     165           0 : }
     166             : 
     167           0 : void SAL_CALL SwVbaCells::SetHeight( float height, sal_Int32 heightrule ) throw (css::uno::RuntimeException, std::exception)
     168             : {
     169           0 :     for( sal_Int32 row = mnTop; row <= mnBottom; row++ )
     170             :     {
     171           0 :         uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, row ) );
     172           0 :         xRow->SetHeight( height, heightrule );
     173           0 :     }
     174           0 : }
     175             : 
     176             : // XEnumerationAccess
     177             : uno::Type
     178           0 : SwVbaCells::getElementType() throw (uno::RuntimeException)
     179             : {
     180           0 :     return cppu::UnoType<word::XCell>::get();
     181             : }
     182             : 
     183             : uno::Reference< container::XEnumeration >
     184           0 : SwVbaCells::createEnumeration() throw (uno::RuntimeException)
     185             : {
     186           0 :     uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
     187           0 :     return xEnumAccess->createEnumeration();
     188             : }
     189             : 
     190             : uno::Any
     191           0 : SwVbaCells::createCollectionObject( const uno::Any& aSource )
     192             : {
     193           0 :     return aSource;
     194             : }
     195             : 
     196             : OUString
     197           0 : SwVbaCells::getServiceImplName()
     198             : {
     199           0 :     return OUString("SwVbaCells");
     200             : }
     201             : 
     202             : uno::Sequence<OUString>
     203           0 : SwVbaCells::getServiceNames()
     204             : {
     205           0 :     static uno::Sequence< OUString > sNames;
     206           0 :     if ( sNames.getLength() == 0 )
     207             :     {
     208           0 :         sNames.realloc( 1 );
     209           0 :         sNames[0] = "ooo.vba.word.Cells";
     210             :     }
     211           0 :     return sNames;
     212             : }
     213             : 
     214             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11