LCOV - code coverage report
Current view: top level - vbahelper/source/vbahelper - vbashaperange.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 48 225 21.3 %
Date: 2015-06-13 12:38:46 Functions: 13 40 32.5 %
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 <com/sun/star/drawing/ShapeCollection.hpp>
      20             : #include <com/sun/star/drawing/XShapeGrouper.hpp>
      21             : #include <com/sun/star/drawing/XDrawPage.hpp>
      22             : #include <com/sun/star/view/XSelectionSupplier.hpp>
      23             : 
      24             : #include <vbahelper/vbahelper.hxx>
      25             : #include <vbahelper/vbashaperange.hxx>
      26             : #include <vbahelper/vbashape.hxx>
      27             : using namespace ::ooo::vba;
      28             : using namespace ::com::sun::star;
      29             : 
      30           4 : class VbShapeRangeEnumHelper : public EnumerationHelper_BASE
      31             : {
      32             :         uno::Reference< XCollection > m_xParent;
      33             :         uno::Reference<container::XIndexAccess > m_xIndexAccess;
      34             :         sal_Int32 nIndex;
      35             : public:
      36           2 :     VbShapeRangeEnumHelper( const uno::Reference< XCollection >& xParent,  const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xParent( xParent ), m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {}
      37          12 :         virtual sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      38             :         {
      39          12 :                 return ( nIndex < m_xIndexAccess->getCount() );
      40             :         }
      41           5 :         virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
      42             :         {
      43           5 :                 ScVbaShapeRange* pCollectionImpl = dynamic_cast< ScVbaShapeRange* >(m_xParent.get());
      44           5 :                 if ( pCollectionImpl && hasMoreElements() )
      45          10 :                     return pCollectionImpl->createCollectionObject(  m_xIndexAccess->getByIndex( nIndex++ ) );
      46           0 :                 throw container::NoSuchElementException();
      47             :         }
      48             : 
      49             : };
      50             : 
      51           6 : ScVbaShapeRange::ScVbaShapeRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xShapes, const uno::Reference< drawing::XDrawPage >& xDrawPage, const uno::Reference< frame::XModel >& xModel  ) : ScVbaShapeRange_BASE( xParent, xContext, xShapes ), m_xDrawPage( xDrawPage ), m_xModel( xModel )
      52             : {
      53           6 : }
      54             : 
      55             : // Methods
      56             : void SAL_CALL
      57           1 : ScVbaShapeRange::Select(  ) throw (uno::RuntimeException, std::exception)
      58             : {
      59           1 :     uno::Reference< view::XSelectionSupplier > xSelectSupp( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
      60           1 :     xSelectSupp->select( uno::makeAny( getShapes() ) );
      61           1 : }
      62             : 
      63             : uno::Reference< msforms::XShape > SAL_CALL
      64           0 : ScVbaShapeRange::Group() throw (uno::RuntimeException, std::exception)
      65             : {
      66           0 :     uno::Reference< drawing::XShapeGrouper > xShapeGrouper( m_xDrawPage, uno::UNO_QUERY_THROW );
      67           0 :     uno::Reference< drawing::XShapeGroup > xShapeGroup( xShapeGrouper->group( getShapes() ), uno::UNO_QUERY_THROW );
      68           0 :     uno::Reference< drawing::XShape > xShape( xShapeGroup, uno::UNO_QUERY_THROW );
      69           0 :     return uno::Reference< msforms::XShape >( new ScVbaShape( getParent(), mxContext, xShape, getShapes(), m_xModel, office::MsoShapeType::msoGroup ) );
      70             : }
      71             : 
      72             : uno::Reference< drawing::XShapes >
      73          14 : ScVbaShapeRange::getShapes() throw (uno::RuntimeException)
      74             : {
      75          14 :     if ( !m_xShapes.is() )
      76             :     {
      77           6 :         m_xShapes.set( drawing::ShapeCollection::create(mxContext) );
      78           6 :         sal_Int32 nLen = m_xIndexAccess->getCount();
      79          16 :         for ( sal_Int32 index = 0; index < nLen; ++index )
      80          10 :             m_xShapes->add( uno::Reference< drawing::XShape >( m_xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW ) );
      81             : 
      82             :     }
      83          14 :     return m_xShapes;
      84             : }
      85             : 
      86             : 
      87             : void SAL_CALL
      88           1 : ScVbaShapeRange::IncrementRotation( double Increment ) throw (uno::RuntimeException, std::exception)
      89             : {
      90           1 :     sal_Int32 nLen = getCount();
      91           3 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
      92             :     {
      93           2 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
      94           2 :         xShape->IncrementRotation( Increment );
      95           2 :     }
      96           1 : }
      97             : 
      98             : void SAL_CALL
      99           1 : ScVbaShapeRange::IncrementLeft( double Increment ) throw (uno::RuntimeException, std::exception)
     100             : {
     101           1 :     sal_Int32 nLen = getCount();
     102           3 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     103             :     {
     104           2 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     105           2 :         xShape->IncrementLeft( Increment );
     106           2 :     }
     107           1 : }
     108             : 
     109             : void SAL_CALL
     110           1 : ScVbaShapeRange::IncrementTop( double Increment ) throw (uno::RuntimeException, std::exception)
     111             : {
     112           1 :     sal_Int32 nLen = getCount();
     113           3 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     114             :     {
     115           2 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     116           2 :         xShape->IncrementTop( Increment );
     117           2 :     }
     118           1 : }
     119             : 
     120           0 : OUString SAL_CALL ScVbaShapeRange::getName() throw (uno::RuntimeException, std::exception)
     121             : {
     122           0 :     sal_Int32 nLen = getCount();
     123           0 :     sal_Int32 index = 1;
     124           0 :     if (index <= nLen)
     125             :     {
     126           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     127           0 :         return xShape->getName( );
     128             :     }
     129           0 :     throw uno::RuntimeException();
     130             : }
     131             : 
     132           0 : void SAL_CALL ScVbaShapeRange::setName( const OUString& _name ) throw (uno::RuntimeException, std::exception)
     133             : {
     134           0 :     sal_Int32 nLen = getCount();
     135           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     136             :     {
     137           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     138           0 :         xShape->setName( _name );
     139           0 :     }
     140           0 : }
     141             : 
     142           0 : double SAL_CALL ScVbaShapeRange::getHeight() throw (uno::RuntimeException, std::exception)
     143             : {
     144           0 :     sal_Int32 nLen = getCount();
     145           0 :     sal_Int32 index = 1;
     146           0 :     if (index <= nLen)
     147             :     {
     148           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     149           0 :         return xShape->getHeight( );
     150             :     }
     151           0 :     throw uno::RuntimeException();
     152             : }
     153             : 
     154           0 : void SAL_CALL ScVbaShapeRange::setHeight( double _height ) throw (uno::RuntimeException, std::exception)
     155             : {
     156           0 :     sal_Int32 nLen = getCount();
     157           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     158             :     {
     159           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     160           0 :         xShape->setHeight( _height );
     161           0 :     }
     162           0 : }
     163             : 
     164           0 : double SAL_CALL ScVbaShapeRange::getWidth() throw (uno::RuntimeException, std::exception)
     165             : {
     166           0 :     sal_Int32 nLen = getCount();
     167           0 :     sal_Int32 index = 1;
     168           0 :     if (index <= nLen)
     169             :     {
     170           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     171           0 :         return xShape->getWidth( );
     172             :     }
     173           0 :     throw uno::RuntimeException();
     174             : }
     175             : 
     176           0 : void SAL_CALL ScVbaShapeRange::setWidth( double _width ) throw (uno::RuntimeException, std::exception)
     177             : {
     178           0 :     sal_Int32 nLen = getCount();
     179           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     180             :     {
     181           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     182           0 :         xShape->setWidth( _width );
     183           0 :     }
     184           0 : }
     185             : 
     186           0 : double SAL_CALL ScVbaShapeRange::getLeft() throw (uno::RuntimeException, std::exception)
     187             : {
     188           0 :     sal_Int32 nLen = getCount();
     189           0 :     sal_Int32 index = 1;
     190           0 :     if (index <= nLen)
     191             :     {
     192           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     193           0 :         return xShape->getLeft();
     194             :     }
     195           0 :     throw uno::RuntimeException();
     196             : }
     197             : 
     198           0 : void SAL_CALL ScVbaShapeRange::setLeft( double _left ) throw (uno::RuntimeException, std::exception)
     199             : {
     200           0 :     sal_Int32 nLen = getCount();
     201           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     202             :     {
     203           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     204           0 :         xShape->setLeft( _left );
     205           0 :     }
     206           0 : }
     207             : 
     208           0 : double SAL_CALL ScVbaShapeRange::getTop() throw (uno::RuntimeException, std::exception)
     209             : {
     210           0 :     sal_Int32 nLen = getCount();
     211           0 :     sal_Int32 index = 1;
     212           0 :     if (index <= nLen)
     213             :     {
     214           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     215           0 :         return xShape->getTop();
     216             :     }
     217           0 :     throw uno::RuntimeException();
     218             : }
     219             : 
     220           0 : void SAL_CALL ScVbaShapeRange::setTop( double _top ) throw (uno::RuntimeException, std::exception)
     221             : {
     222           0 :     sal_Int32 nLen = getCount();
     223           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     224             :     {
     225           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     226           0 :         xShape->setTop( _top );
     227           0 :     }
     228           0 : }
     229             : 
     230           0 : uno::Reference< ov::msforms::XLineFormat > SAL_CALL ScVbaShapeRange::getLine() throw (css::uno::RuntimeException, std::exception)
     231             : {
     232           0 :     sal_Int32 nLen = getCount();
     233           0 :     sal_Int32 index = 1;
     234           0 :     if (index <= nLen)
     235             :     {
     236           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     237           0 :         return xShape->getLine();
     238             :     }
     239           0 :     throw uno::RuntimeException();
     240             : }
     241             : 
     242           0 : uno::Reference< ov::msforms::XFillFormat > SAL_CALL ScVbaShapeRange::getFill() throw (css::uno::RuntimeException, std::exception)
     243             : {
     244           0 :     sal_Int32 nLen = getCount();
     245           0 :     sal_Int32 index = 1;
     246           0 :     if (index <= nLen)
     247             :     {
     248           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     249           0 :         return xShape->getFill();
     250             :     }
     251           0 :     throw uno::RuntimeException();
     252             : }
     253             : 
     254           0 : sal_Bool SAL_CALL ScVbaShapeRange::getLockAspectRatio() throw (uno::RuntimeException, std::exception)
     255             : {
     256           0 :     sal_Int32 nLen = getCount();
     257           0 :     sal_Int32 index = 1;
     258           0 :     if (index <= nLen)
     259             :     {
     260           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     261           0 :         return xShape->getLockAspectRatio();
     262             :     }
     263           0 :     throw uno::RuntimeException();
     264             : }
     265             : 
     266           0 : void SAL_CALL ScVbaShapeRange::setLockAspectRatio( sal_Bool _lockaspectratio ) throw (uno::RuntimeException, std::exception)
     267             : {
     268           0 :     sal_Int32 nLen = getCount();
     269           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     270             :     {
     271           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     272           0 :         xShape->setLockAspectRatio( _lockaspectratio );
     273           0 :     }
     274           0 : }
     275             : 
     276           0 : sal_Bool SAL_CALL ScVbaShapeRange::getLockAnchor() throw (uno::RuntimeException, std::exception)
     277             : {
     278           0 :     sal_Int32 nLen = getCount();
     279           0 :     sal_Int32 index = 1;
     280           0 :     if (index <= nLen)
     281             :     {
     282           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     283           0 :         return xShape->getLockAnchor();
     284             :     }
     285           0 :     throw uno::RuntimeException();
     286             : }
     287             : 
     288           0 : void SAL_CALL ScVbaShapeRange::setLockAnchor( sal_Bool _lockanchor ) throw (uno::RuntimeException, std::exception)
     289             : {
     290           0 :     sal_Int32 nLen = getCount();
     291           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     292             :     {
     293           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     294           0 :         xShape->setLockAnchor( _lockanchor );
     295           0 :     }
     296           0 : }
     297             : 
     298           0 : ::sal_Int32 SAL_CALL ScVbaShapeRange::getRelativeHorizontalPosition() throw (uno::RuntimeException, std::exception)
     299             : {
     300           0 :     sal_Int32 nLen = getCount();
     301           0 :     sal_Int32 index = 1;
     302           0 :     if (index <= nLen)
     303             :     {
     304           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     305           0 :         return xShape->getRelativeHorizontalPosition();
     306             :     }
     307           0 :     throw uno::RuntimeException();
     308             : }
     309             : 
     310           0 : void SAL_CALL ScVbaShapeRange::setRelativeHorizontalPosition( ::sal_Int32 _relativehorizontalposition ) throw (uno::RuntimeException, std::exception)
     311             : {
     312           0 :     sal_Int32 nLen = getCount();
     313           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     314             :     {
     315           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     316           0 :         xShape->setRelativeHorizontalPosition( _relativehorizontalposition );
     317           0 :     }
     318           0 : }
     319             : 
     320           0 : ::sal_Int32 SAL_CALL ScVbaShapeRange::getRelativeVerticalPosition() throw (uno::RuntimeException, std::exception)
     321             : {
     322           0 :     sal_Int32 nLen = getCount();
     323           0 :     sal_Int32 index = 1;
     324           0 :     if (index <= nLen)
     325             :     {
     326           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     327           0 :         return xShape->getRelativeVerticalPosition();
     328             :     }
     329           0 :     throw uno::RuntimeException();
     330             : }
     331             : 
     332           0 : void SAL_CALL ScVbaShapeRange::setRelativeVerticalPosition( ::sal_Int32 _relativeverticalposition ) throw (uno::RuntimeException, std::exception)
     333             : {
     334           0 :     sal_Int32 nLen = getCount();
     335           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     336             :     {
     337           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     338           0 :         xShape->setRelativeVerticalPosition( _relativeverticalposition );
     339           0 :     }
     340           0 : }
     341             : 
     342           0 : uno::Any SAL_CALL ScVbaShapeRange::TextFrame(  ) throw (css::uno::RuntimeException, std::exception)
     343             : {
     344           0 :     sal_Int32 nLen = getCount();
     345           0 :     sal_Int32 index = 1;
     346           0 :     if (index <= nLen)
     347             :     {
     348           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     349           0 :         return xShape->TextFrame();
     350             :     }
     351           0 :     throw uno::RuntimeException();
     352             : }
     353             : 
     354           0 : uno::Any SAL_CALL ScVbaShapeRange::WrapFormat(  ) throw (css::uno::RuntimeException, std::exception)
     355             : {
     356           0 :     sal_Int32 nLen = getCount();
     357           0 :     sal_Int32 index = 1;
     358           0 :     if (index <= nLen)
     359             :     {
     360           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     361           0 :         return xShape->WrapFormat();
     362             :     }
     363           0 :     throw uno::RuntimeException();
     364             : }
     365             : 
     366           0 : void SAL_CALL ScVbaShapeRange::ZOrder( sal_Int32 ZOrderCmd ) throw (uno::RuntimeException, std::exception)
     367             : {
     368           0 :     sal_Int32 nLen = getCount();
     369           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     370             :     {
     371           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     372           0 :         xShape->ZOrder( ZOrderCmd );
     373           0 :     }
     374           0 : }
     375             : 
     376             : uno::Type SAL_CALL
     377           0 : ScVbaShapeRange::getElementType() throw (uno::RuntimeException)
     378             : {
     379           0 :     return cppu::UnoType<msforms::XShape>::get();
     380             : }
     381             : 
     382             : uno::Reference< container::XEnumeration > SAL_CALL
     383           2 : ScVbaShapeRange::createEnumeration() throw (uno::RuntimeException)
     384             : {
     385           2 :     return new VbShapeRangeEnumHelper( this, m_xIndexAccess );
     386             : }
     387             : 
     388             : uno::Any
     389          13 : ScVbaShapeRange:: createCollectionObject( const css::uno::Any& aSource )
     390             : {
     391          13 :     uno::Reference< drawing::XShape > xShape( aSource, uno::UNO_QUERY_THROW );
     392             :     // #TODO  #FIXME Shape parent should always be the sheet the shapes belong
     393             :     // to
     394          26 :     uno::Reference< msforms::XShape > xVbShape( new ScVbaShape( uno::Reference< XHelperInterface >(), mxContext, xShape, getShapes(), m_xModel, ScVbaShape::getType( xShape ) ) );
     395          26 :         return uno::makeAny( xVbShape );
     396             : }
     397             : 
     398             : OUString
     399           0 : ScVbaShapeRange::getServiceImplName()
     400             : {
     401           0 :     return OUString("ScVbaShapeRange");
     402             : }
     403             : 
     404             : uno::Sequence< OUString >
     405           0 : ScVbaShapeRange::getServiceNames()
     406             : {
     407           0 :     static uno::Sequence< OUString > aServiceNames;
     408           0 :     if ( aServiceNames.getLength() == 0 )
     409             :     {
     410           0 :         aServiceNames.realloc( 1 );
     411           0 :         aServiceNames[ 0 ] = "ooo.vba.msform.ShapeRange";
     412             :     }
     413           0 :     return aServiceNames;
     414             : }
     415             : 
     416             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11