LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/vbahelper/source/vbahelper - vbashaperange.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 49 226 21.7 %
Date: 2013-07-09 Functions: 15 42 35.7 %
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)
      38             :         {
      39          12 :                 return ( nIndex < m_xIndexAccess->getCount() );
      40             :         }
      41           5 :         virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
      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)
      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)
      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)
      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)
     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)
     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)
     121             : {
     122           0 :     sal_Int32 nLen = getCount();
     123           0 :     for ( sal_Int32 index = 1; index <= nLen; /* ++index unreachable */ )
     124             :     {
     125           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     126           0 :         return xShape->getName( );
     127           0 :     }
     128           0 :     throw uno::RuntimeException();
     129             : }
     130             : 
     131           0 : void SAL_CALL ScVbaShapeRange::setName( const OUString& _name ) throw (uno::RuntimeException)
     132             : {
     133           0 :     sal_Int32 nLen = getCount();
     134           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     135             :     {
     136           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     137           0 :         xShape->setName( _name );
     138           0 :     }
     139           0 : }
     140             : 
     141           0 : double SAL_CALL ScVbaShapeRange::getHeight() throw (uno::RuntimeException)
     142             : {
     143           0 :     sal_Int32 nLen = getCount();
     144           0 :     for ( sal_Int32 index = 1; index <= nLen; /* ++index unreachable */ )
     145             :     {
     146           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     147           0 :         return xShape->getHeight( );
     148           0 :     }
     149           0 :     throw uno::RuntimeException();
     150             : }
     151             : 
     152           0 : void SAL_CALL ScVbaShapeRange::setHeight( double _height ) throw (uno::RuntimeException)
     153             : {
     154           0 :     sal_Int32 nLen = getCount();
     155           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     156             :     {
     157           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     158           0 :         xShape->setHeight( _height );
     159           0 :     }
     160           0 : }
     161             : 
     162           0 : double SAL_CALL ScVbaShapeRange::getWidth() throw (uno::RuntimeException)
     163             : {
     164           0 :     sal_Int32 nLen = getCount();
     165           0 :     for ( sal_Int32 index = 1; index <= nLen; /* ++index unreachable */ )
     166             :     {
     167           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     168           0 :         return xShape->getWidth( );
     169           0 :     }
     170           0 :     throw uno::RuntimeException();
     171             : }
     172             : 
     173           0 : void SAL_CALL ScVbaShapeRange::setWidth( double _width ) throw (uno::RuntimeException)
     174             : {
     175           0 :     sal_Int32 nLen = getCount();
     176           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     177             :     {
     178           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     179           0 :         xShape->setWidth( _width );
     180           0 :     }
     181           0 : }
     182             : 
     183           0 : double SAL_CALL ScVbaShapeRange::getLeft() throw (uno::RuntimeException)
     184             : {
     185           0 :     sal_Int32 nLen = getCount();
     186           0 :     for ( sal_Int32 index = 1; index <= nLen; /* ++index unreachable */ )
     187             :     {
     188           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     189           0 :         return xShape->getLeft();
     190           0 :     }
     191           0 :     throw uno::RuntimeException();
     192             : }
     193             : 
     194           0 : void SAL_CALL ScVbaShapeRange::setLeft( double _left ) throw (uno::RuntimeException)
     195             : {
     196           0 :     sal_Int32 nLen = getCount();
     197           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     198             :     {
     199           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     200           0 :         xShape->setLeft( _left );
     201           0 :     }
     202           0 : }
     203             : 
     204           0 : double SAL_CALL ScVbaShapeRange::getTop() throw (uno::RuntimeException)
     205             : {
     206           0 :     sal_Int32 nLen = getCount();
     207           0 :     for ( sal_Int32 index = 1; index <= nLen; /* ++index unreachable */ )
     208             :     {
     209           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     210           0 :         return xShape->getTop();
     211           0 :     }
     212           0 :     throw uno::RuntimeException();
     213             : }
     214             : 
     215           0 : void SAL_CALL ScVbaShapeRange::setTop( double _top ) throw (uno::RuntimeException)
     216             : {
     217           0 :     sal_Int32 nLen = getCount();
     218           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     219             :     {
     220           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     221           0 :         xShape->setTop( _top );
     222           0 :     }
     223           0 : }
     224             : 
     225           0 : uno::Reference< ov::msforms::XLineFormat > SAL_CALL ScVbaShapeRange::getLine() throw (css::uno::RuntimeException)
     226             : {
     227           0 :     sal_Int32 nLen = getCount();
     228           0 :     for ( sal_Int32 index = 1; index <= nLen; /* ++index unreachable */ )
     229             :     {
     230           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     231           0 :         return xShape->getLine();
     232           0 :     }
     233           0 :     throw uno::RuntimeException();
     234             : }
     235             : 
     236           0 : uno::Reference< ov::msforms::XFillFormat > SAL_CALL ScVbaShapeRange::getFill() throw (css::uno::RuntimeException)
     237             : {
     238           0 :     sal_Int32 nLen = getCount();
     239           0 :     for ( sal_Int32 index = 1; index <= nLen; /* ++index unreachable */ )
     240             :     {
     241           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     242           0 :         return xShape->getFill();
     243           0 :     }
     244           0 :     throw uno::RuntimeException();
     245             : }
     246             : 
     247           0 : ::sal_Bool SAL_CALL ScVbaShapeRange::getLockAspectRatio() throw (uno::RuntimeException)
     248             : {
     249           0 :     sal_Int32 nLen = getCount();
     250           0 :     for ( sal_Int32 index = 1; index <= nLen; /* ++index unreachable */ )
     251             :     {
     252           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     253           0 :         return xShape->getLockAspectRatio();
     254           0 :     }
     255           0 :     throw uno::RuntimeException();
     256             : }
     257             : 
     258           0 : void SAL_CALL ScVbaShapeRange::setLockAspectRatio( ::sal_Bool _lockaspectratio ) throw (uno::RuntimeException)
     259             : {
     260           0 :     sal_Int32 nLen = getCount();
     261           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     262             :     {
     263           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     264           0 :         xShape->setLockAspectRatio( _lockaspectratio );
     265           0 :     }
     266           0 : }
     267             : 
     268           0 : ::sal_Bool SAL_CALL ScVbaShapeRange::getLockAnchor() throw (uno::RuntimeException)
     269             : {
     270           0 :     sal_Int32 nLen = getCount();
     271           0 :     for ( sal_Int32 index = 1; index <= nLen; /* ++index unreachable */ )
     272             :     {
     273           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     274           0 :         return xShape->getLockAnchor();
     275           0 :     }
     276           0 :     throw uno::RuntimeException();
     277             : }
     278             : 
     279           0 : void SAL_CALL ScVbaShapeRange::setLockAnchor( ::sal_Bool _lockanchor ) throw (uno::RuntimeException)
     280             : {
     281           0 :     sal_Int32 nLen = getCount();
     282           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     283             :     {
     284           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     285           0 :         xShape->setLockAnchor( _lockanchor );
     286           0 :     }
     287           0 : }
     288             : 
     289           0 : ::sal_Int32 SAL_CALL ScVbaShapeRange::getRelativeHorizontalPosition() throw (uno::RuntimeException)
     290             : {
     291           0 :     sal_Int32 nLen = getCount();
     292           0 :     for ( sal_Int32 index = 1; index <= nLen; /* ++index unreachable */ )
     293             :     {
     294           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     295           0 :         return xShape->getRelativeHorizontalPosition();
     296           0 :     }
     297           0 :     throw uno::RuntimeException();
     298             : }
     299             : 
     300           0 : void SAL_CALL ScVbaShapeRange::setRelativeHorizontalPosition( ::sal_Int32 _relativehorizontalposition ) throw (uno::RuntimeException)
     301             : {
     302           0 :     sal_Int32 nLen = getCount();
     303           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     304             :     {
     305           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     306           0 :         xShape->setRelativeHorizontalPosition( _relativehorizontalposition );
     307           0 :     }
     308           0 : }
     309             : 
     310           0 : ::sal_Int32 SAL_CALL ScVbaShapeRange::getRelativeVerticalPosition() throw (uno::RuntimeException)
     311             : {
     312           0 :     sal_Int32 nLen = getCount();
     313           0 :     for ( sal_Int32 index = 1; index <= nLen; /* ++index unreachable */ )
     314             :     {
     315           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     316           0 :         return xShape->getRelativeVerticalPosition();
     317           0 :     }
     318           0 :     throw uno::RuntimeException();
     319             : }
     320             : 
     321           0 : void SAL_CALL ScVbaShapeRange::setRelativeVerticalPosition( ::sal_Int32 _relativeverticalposition ) throw (uno::RuntimeException)
     322             : {
     323           0 :     sal_Int32 nLen = getCount();
     324           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     325             :     {
     326           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     327           0 :         xShape->setRelativeVerticalPosition( _relativeverticalposition );
     328           0 :     }
     329           0 : }
     330             : 
     331           0 : uno::Any SAL_CALL ScVbaShapeRange::TextFrame(  ) throw (css::uno::RuntimeException)
     332             : {
     333           0 :     sal_Int32 nLen = getCount();
     334           0 :     for ( sal_Int32 index = 1; index <= nLen; /* ++index unreachable */ )
     335             :     {
     336           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     337           0 :         return xShape->TextFrame();
     338           0 :     }
     339           0 :     throw uno::RuntimeException();
     340             : }
     341             : 
     342           0 : uno::Any SAL_CALL ScVbaShapeRange::WrapFormat(  ) throw (css::uno::RuntimeException)
     343             : {
     344           0 :     sal_Int32 nLen = getCount();
     345           0 :     for ( sal_Int32 index = 1; index <= nLen; /* ++index unreachable */ )
     346             :     {
     347           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     348           0 :         return xShape->WrapFormat();
     349           0 :     }
     350           0 :     throw uno::RuntimeException();
     351             : }
     352             : 
     353           0 : void SAL_CALL ScVbaShapeRange::ZOrder( sal_Int32 ZOrderCmd ) throw (uno::RuntimeException)
     354             : {
     355           0 :     sal_Int32 nLen = getCount();
     356           0 :     for ( sal_Int32 index = 1; index <= nLen; ++index )
     357             :     {
     358           0 :         uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
     359           0 :         xShape->ZOrder( ZOrderCmd );
     360           0 :     }
     361           0 : }
     362             : 
     363             : uno::Type SAL_CALL
     364           0 : ScVbaShapeRange::getElementType() throw (uno::RuntimeException)
     365             : {
     366           0 :     return msforms::XShape::static_type(0);
     367             : }
     368             : 
     369             : uno::Reference< container::XEnumeration > SAL_CALL
     370           2 : ScVbaShapeRange::createEnumeration() throw (uno::RuntimeException)
     371             : {
     372           2 :     return new VbShapeRangeEnumHelper( this, m_xIndexAccess );
     373             : }
     374             : 
     375             : uno::Any
     376          13 : ScVbaShapeRange:: createCollectionObject( const css::uno::Any& aSource )
     377             : {
     378          13 :     uno::Reference< drawing::XShape > xShape( aSource, uno::UNO_QUERY_THROW );
     379             :     // #TODO  #FIXME Shape parent should always be the sheet the shapes belong
     380             :     // to
     381          26 :     uno::Reference< msforms::XShape > xVbShape( new ScVbaShape( uno::Reference< XHelperInterface >(), mxContext, xShape, getShapes(), m_xModel, ScVbaShape::getType( xShape ) ) );
     382          26 :         return uno::makeAny( xVbShape );
     383             : }
     384             : 
     385             : OUString
     386           0 : ScVbaShapeRange::getServiceImplName()
     387             : {
     388           0 :     return OUString("ScVbaShapeRange");
     389             : }
     390             : 
     391             : uno::Sequence< OUString >
     392           0 : ScVbaShapeRange::getServiceNames()
     393             : {
     394           0 :     static uno::Sequence< OUString > aServiceNames;
     395           0 :     if ( aServiceNames.getLength() == 0 )
     396             :     {
     397           0 :         aServiceNames.realloc( 1 );
     398           0 :         aServiceNames[ 0 ] = "ooo.vba.msform.ShapeRange";
     399             :     }
     400           0 :     return aServiceNames;
     401         186 : }
     402             : 
     403             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10