LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbasheetobjects.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 151 0.0 %
Date: 2014-04-14 Functions: 0 52 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 "vbasheetobjects.hxx"
      21             : #include <vector>
      22             : #include <rtl/math.hxx>
      23             : #include <com/sun/star/beans/XPropertySet.hpp>
      24             : #include <com/sun/star/container/XIndexContainer.hpp>
      25             : #include <com/sun/star/container/XNamed.hpp>
      26             : #include <com/sun/star/drawing/XControlShape.hpp>
      27             : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      28             : #include <com/sun/star/drawing/XShapes.hpp>
      29             : #include <com/sun/star/form/FormComponentType.hpp>
      30             : #include <com/sun/star/form/XForm.hpp>
      31             : #include <com/sun/star/form/XFormComponent.hpp>
      32             : #include <com/sun/star/form/XFormsSupplier.hpp>
      33             : #include "vbasheetobject.hxx"
      34             : 
      35             : using namespace ::com::sun::star;
      36             : using namespace ::ooo::vba;
      37             : 
      38             : namespace {
      39             : 
      40             : template< typename Type >
      41           0 : inline bool lclGetProperty( Type& orValue, const uno::Reference< beans::XPropertySet >& rxPropSet, const OUString& rPropName )
      42             : {
      43             :     try
      44             :     {
      45           0 :         return rxPropSet->getPropertyValue( rPropName ) >>= orValue;
      46             :     }
      47           0 :     catch( uno::Exception& )
      48             :     {
      49             :     }
      50           0 :     return false;
      51             : }
      52             : 
      53             : /** Rounds the passed value to a multiple of 0.75 and converts it to 1/100 mm. */
      54           0 : inline double lclPointsToHmm( const uno::Any& rPoints ) throw (uno::RuntimeException)
      55             : {
      56           0 :     return PointsToHmm( ::rtl::math::approxFloor( rPoints.get< double >() / 0.75 ) * 0.75 );
      57             : }
      58             : 
      59             : } // namespace
      60             : 
      61             : 
      62             : // Base implementations
      63             : 
      64             : 
      65             : /** Container for a specific type of drawing object in a spreadsheet.
      66             : 
      67             :     Derived classes provide all required functionality specific to the type of
      68             :     shapes covered by the container.
      69             :  */
      70           0 : class ScVbaObjectContainer : public ::cppu::WeakImplHelper1< container::XIndexAccess >
      71             : {
      72             : public:
      73             :     explicit ScVbaObjectContainer(
      74             :         const uno::Reference< XHelperInterface >& rxParent,
      75             :         const uno::Reference< uno::XComponentContext >& rxContext,
      76             :         const uno::Reference< frame::XModel >& rxModel,
      77             :         const uno::Reference< sheet::XSpreadsheet >& rxSheet,
      78             :         const uno::Type& rVbaType ) throw (uno::RuntimeException);
      79             : 
      80             :     /** Returns the VBA helper interface of the VBA collection object. */
      81           0 :     inline const uno::Reference< XHelperInterface >& getParent() const { return mxParent; }
      82             :     /** Returns the component context of the VBA collection object. */
      83           0 :     inline const uno::Reference< uno::XComponentContext >& getContext() const { return mxContext; }
      84             :     /** Returns the VBA type information of the objects in this container. */
      85           0 :     inline const uno::Type& getVbaType() const { return maVbaType; }
      86             : 
      87             :     /** Collects all shapes supported by this instance and inserts them into
      88             :         the internal shape vector. */
      89             :     void collectShapes() throw (uno::RuntimeException);
      90             :     /** Creates and returns a new UNO shape. */
      91             :     uno::Reference< drawing::XShape > createShape( const awt::Point& rPos, const awt::Size& rSize ) throw (uno::RuntimeException);
      92             :     /** Inserts the passed shape into the draw page and into this container, and returns its index in the draw page. */
      93             :     sal_Int32 insertShape( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException);
      94             :     /** Creates and returns a new VBA implementation object for the passed shape. */
      95             :     ::rtl::Reference< ScVbaSheetObjectBase > createVbaObject( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException);
      96             :     /** Creates and returns a new VBA implementation object for the passed shape in an Any. */
      97             :     uno::Any createCollectionObject( const uno::Any& rSource ) throw (uno::RuntimeException);
      98             :     /** Returns the VBA implementation object with the specified name. */
      99             :     uno::Any getItemByStringIndex( const OUString& rIndex ) throw (uno::RuntimeException);
     100             : 
     101             :     // XIndexAccess
     102             :     virtual sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
     103             :     virtual uno::Any SAL_CALL getByIndex( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
     104             : 
     105             :     // XElementAccess
     106             :     virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
     107             :     virtual sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
     108             : 
     109             : protected:
     110             :     /** Derived classes return true, if the passed shape is supported by the instance. */
     111             :     virtual bool implPickShape( const uno::Reference< drawing::XShape >& rxShape ) const = 0;
     112             :     /** Derived classes create and return a new VBA implementation object for the passed shape. */
     113             :     virtual ScVbaSheetObjectBase* implCreateVbaObject( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException) = 0;
     114             :     /** Derived classes return the service name of the UNO shape. */
     115             :     virtual OUString implGetShapeServiceName() const = 0;
     116             : 
     117             :     /** Returns the shape name via 'Name' property of the UNO shape. May be overwritten. */
     118             :     virtual OUString implGetShapeName( const uno::Reference< drawing::XShape >& rxShape ) const throw (uno::RuntimeException);
     119             :     /** Is called when a new UNO shape has been created but not yet inserted into the drawing page. */
     120             :     virtual void implOnShapeCreated( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException);
     121             : 
     122             : protected:
     123             :     uno::Reference< XHelperInterface > mxParent;
     124             :     uno::Reference< uno::XComponentContext > mxContext;
     125             :     uno::Reference< frame::XModel > mxModel;
     126             :     uno::Reference< lang::XMultiServiceFactory > mxFactory;
     127             :     uno::Reference< drawing::XShapes > mxShapes;
     128             : 
     129             : private:
     130             :     typedef ::std::vector< uno::Reference< drawing::XShape > > ShapeVector;
     131             :     const uno::Type maVbaType;
     132             :     ShapeVector maShapes;
     133             : };
     134             : 
     135           0 : ScVbaObjectContainer::ScVbaObjectContainer(
     136             :         const uno::Reference< XHelperInterface >& rxParent,
     137             :         const uno::Reference< uno::XComponentContext >& rxContext,
     138             :         const uno::Reference< frame::XModel >& rxModel,
     139             :         const uno::Reference< sheet::XSpreadsheet >& rxSheet,
     140             :         const uno::Type& rVbaType ) throw (uno::RuntimeException) :
     141             :     mxParent( rxParent ),
     142             :     mxContext( rxContext ),
     143             :     mxModel( rxModel, uno::UNO_SET_THROW ),
     144             :     mxFactory( rxModel, uno::UNO_QUERY_THROW ),
     145           0 :     maVbaType( rVbaType )
     146             : {
     147           0 :     uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupp( rxSheet, uno::UNO_QUERY_THROW );
     148           0 :     mxShapes.set( xDrawPageSupp->getDrawPage(), uno::UNO_QUERY_THROW );
     149           0 : }
     150             : 
     151           0 : void ScVbaObjectContainer::collectShapes() throw (uno::RuntimeException)
     152             : {
     153           0 :     maShapes.clear();
     154           0 :     for( sal_Int32 nIndex = 0, nCount = mxShapes->getCount(); nIndex < nCount; ++nIndex )
     155             :     {
     156           0 :         uno::Reference< drawing::XShape > xShape( mxShapes->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
     157           0 :         if( implPickShape( xShape ) )
     158           0 :             maShapes.push_back( xShape );
     159           0 :     }
     160           0 : }
     161             : 
     162           0 : uno::Reference< drawing::XShape > ScVbaObjectContainer::createShape( const awt::Point& rPos, const awt::Size& rSize ) throw (uno::RuntimeException)
     163             : {
     164           0 :     uno::Reference< drawing::XShape > xShape( mxFactory->createInstance( implGetShapeServiceName() ), uno::UNO_QUERY_THROW );
     165           0 :     xShape->setPosition( rPos );
     166           0 :     xShape->setSize( rSize );
     167           0 :     implOnShapeCreated( xShape );
     168           0 :     return xShape;
     169             : }
     170             : 
     171           0 : sal_Int32 ScVbaObjectContainer::insertShape( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException)
     172             : {
     173           0 :     mxShapes->add( rxShape );
     174           0 :     maShapes.push_back( rxShape );
     175           0 :     return mxShapes->getCount() - 1;
     176             : }
     177             : 
     178           0 : ::rtl::Reference< ScVbaSheetObjectBase > ScVbaObjectContainer::createVbaObject(
     179             :     const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException)
     180             : {
     181           0 :     return implCreateVbaObject( rxShape );
     182             : }
     183             : 
     184           0 : uno::Any ScVbaObjectContainer::createCollectionObject( const uno::Any& rSource ) throw (uno::RuntimeException)
     185             : {
     186           0 :     uno::Reference< drawing::XShape > xShape( rSource, uno::UNO_QUERY_THROW );
     187           0 :     uno::Reference< excel::XSheetObject > xSheetObject( implCreateVbaObject( xShape ) );
     188           0 :     return uno::Any( xSheetObject );
     189             : }
     190             : 
     191           0 : uno::Any ScVbaObjectContainer::getItemByStringIndex( const OUString& rIndex ) throw (uno::RuntimeException)
     192             : {
     193           0 :     for( ShapeVector::iterator aIt = maShapes.begin(), aEnd = maShapes.end(); aIt != aEnd; ++aIt )
     194           0 :         if( rIndex == implGetShapeName( *aIt ) )
     195           0 :             return createCollectionObject( uno::Any( *aIt ) );
     196           0 :     throw uno::RuntimeException();
     197             : }
     198             : 
     199             : // XIndexAccess
     200             : 
     201           0 : sal_Int32 SAL_CALL ScVbaObjectContainer::getCount() throw (uno::RuntimeException, std::exception)
     202             : {
     203           0 :     return static_cast< sal_Int32 >( maShapes.size() );
     204             : }
     205             : 
     206           0 : uno::Any SAL_CALL ScVbaObjectContainer::getByIndex( sal_Int32 nIndex )
     207             :         throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     208             : {
     209           0 :     if( (0 <= nIndex) && (nIndex < getCount()) )
     210           0 :         return uno::Any( maShapes[ static_cast< size_t >( nIndex ) ] );
     211           0 :     throw lang::IndexOutOfBoundsException();
     212             : }
     213             : 
     214             : // XElementAccess
     215             : 
     216           0 : uno::Type SAL_CALL ScVbaObjectContainer::getElementType() throw (uno::RuntimeException, std::exception)
     217             : {
     218           0 :     return cppu::UnoType<drawing::XShape>::get();
     219             : }
     220             : 
     221           0 : sal_Bool SAL_CALL ScVbaObjectContainer::hasElements() throw (uno::RuntimeException, std::exception)
     222             : {
     223           0 :     return !maShapes.empty();
     224             : }
     225             : 
     226             : // private
     227             : 
     228           0 : OUString ScVbaObjectContainer::implGetShapeName( const uno::Reference< drawing::XShape >& rxShape ) const throw (uno::RuntimeException)
     229             : {
     230           0 :     uno::Reference< beans::XPropertySet > xPropSet( rxShape, uno::UNO_QUERY_THROW );
     231           0 :     return xPropSet->getPropertyValue( "Name" ).get< OUString >();
     232             : }
     233             : 
     234           0 : void ScVbaObjectContainer::implOnShapeCreated( const uno::Reference< drawing::XShape >& /*rxShape*/ ) throw (uno::RuntimeException)
     235             : {
     236           0 : }
     237             : 
     238           0 : class ScVbaObjectEnumeration : public SimpleEnumerationBase
     239             : {
     240             : public:
     241             :     explicit ScVbaObjectEnumeration( const ScVbaObjectContainerRef& rxContainer );
     242             :     virtual uno::Any createCollectionObject( const uno::Any& rSource ) SAL_OVERRIDE;
     243             : 
     244             : private:
     245             :     ScVbaObjectContainerRef mxContainer;
     246             : };
     247             : 
     248           0 : ScVbaObjectEnumeration::ScVbaObjectEnumeration( const ScVbaObjectContainerRef& rxContainer ) :
     249           0 :     SimpleEnumerationBase( rxContainer->getParent(), rxContainer->getContext(), rxContainer.get() ),
     250           0 :     mxContainer( rxContainer )
     251             : {
     252           0 : }
     253             : 
     254           0 : uno::Any ScVbaObjectEnumeration::createCollectionObject( const uno::Any& rSource )
     255             : {
     256           0 :     return mxContainer->createCollectionObject( rSource );
     257             : }
     258             : 
     259           0 : ScVbaSheetObjectsBase::ScVbaSheetObjectsBase( const ScVbaObjectContainerRef& rxContainer ) throw (css::uno::RuntimeException) :
     260           0 :     ScVbaSheetObjects_BASE( rxContainer->getParent(), rxContainer->getContext(), rxContainer.get() ),
     261           0 :     mxContainer( rxContainer )
     262             : {
     263           0 :     mxContainer->collectShapes();
     264           0 : }
     265             : 
     266           0 : ScVbaSheetObjectsBase::~ScVbaSheetObjectsBase()
     267             : {
     268           0 : }
     269             : 
     270           0 : void ScVbaSheetObjectsBase::collectShapes() throw (uno::RuntimeException)
     271             : {
     272           0 :     mxContainer->collectShapes();
     273           0 : }
     274             : 
     275             : // XEnumerationAccess
     276             : 
     277           0 : uno::Reference< container::XEnumeration > SAL_CALL ScVbaSheetObjectsBase::createEnumeration() throw (uno::RuntimeException)
     278             : {
     279           0 :     return new ScVbaObjectEnumeration( mxContainer );
     280             : }
     281             : 
     282             : // XElementAccess
     283             : 
     284           0 : uno::Type SAL_CALL ScVbaSheetObjectsBase::getElementType() throw (uno::RuntimeException)
     285             : {
     286           0 :     return mxContainer->getVbaType();
     287             : }
     288             : 
     289             : // ScVbaCollectionBase
     290             : 
     291           0 : uno::Any ScVbaSheetObjectsBase::createCollectionObject( const uno::Any& rSource )
     292             : {
     293           0 :     return mxContainer->createCollectionObject( rSource );
     294             : }
     295             : 
     296           0 : uno::Any ScVbaSheetObjectsBase::getItemByStringIndex( const OUString& rIndex ) throw (uno::RuntimeException)
     297             : {
     298           0 :     return mxContainer->getItemByStringIndex( rIndex );
     299             : }
     300             : 
     301             : 
     302             : // Graphic object containers supporting ooo.vba.excel.XGraphicObject
     303             : 
     304             : 
     305           0 : ScVbaGraphicObjectsBase::ScVbaGraphicObjectsBase( const ScVbaObjectContainerRef& rxContainer ) throw (uno::RuntimeException) :
     306           0 :     ScVbaGraphicObjects_BASE( rxContainer )
     307             : {
     308           0 : }
     309             : 
     310             : // XGraphicObjects
     311             : 
     312           0 : uno::Any SAL_CALL ScVbaGraphicObjectsBase::Add( const uno::Any& rLeft, const uno::Any& rTop, const uno::Any& rWidth, const uno::Any& rHeight ) throw (uno::RuntimeException, std::exception)
     313             : {
     314             :     /*  Extract double values from passed Anys (the lclPointsToHmm() helper
     315             :         function will throw a RuntimeException on any error), and convert from
     316             :         points to 1/100 mm. */
     317           0 :     awt::Point aPos( static_cast<sal_Int32>(lclPointsToHmm( rLeft )),  static_cast<sal_Int32>(lclPointsToHmm( rTop )) );
     318           0 :     awt::Size aSize( static_cast<sal_Int32>(lclPointsToHmm( rWidth )), static_cast<sal_Int32>(lclPointsToHmm( rHeight )) );
     319             :     // TODO: translate coordinates for RTL sheets
     320           0 :     if( (aPos.X < 0) || (aPos.Y < 0) || (aSize.Width <= 0) || (aSize.Height <= 0) )
     321           0 :         throw uno::RuntimeException();
     322             : 
     323             :     // create the UNO shape
     324           0 :     uno::Reference< drawing::XShape > xShape( mxContainer->createShape( aPos, aSize ), uno::UNO_SET_THROW );
     325           0 :     sal_Int32 nIndex = mxContainer->insertShape( xShape );
     326             : 
     327             :     // create and return the VBA object
     328           0 :     ::rtl::Reference< ScVbaSheetObjectBase > xVbaObject = mxContainer->createVbaObject( xShape );
     329           0 :     xVbaObject->setDefaultProperties( nIndex );
     330           0 :     return uno::Any( uno::Reference< excel::XSheetObject >( xVbaObject.get() ) );
     331             : }
     332             : 
     333             : 
     334             : // Drawing controls
     335             : 
     336             : 
     337           0 : class ScVbaControlContainer : public ScVbaObjectContainer
     338             : {
     339             : public:
     340             :     explicit ScVbaControlContainer(
     341             :         const uno::Reference< XHelperInterface >& rxParent,
     342             :         const uno::Reference< uno::XComponentContext >& rxContext,
     343             :         const uno::Reference< frame::XModel >& rxModel,
     344             :         const uno::Reference< sheet::XSpreadsheet >& rxSheet,
     345             :         const uno::Type& rVbaType,
     346             :         const OUString& rModelServiceName,
     347             :         sal_Int16 nComponentType ) throw (uno::RuntimeException);
     348             : 
     349             : protected:
     350             :     uno::Reference< container::XIndexContainer > createForm() throw (uno::RuntimeException);
     351             : 
     352             :     virtual bool implPickShape( const uno::Reference< drawing::XShape >& rxShape ) const SAL_OVERRIDE;
     353             :     virtual OUString implGetShapeServiceName() const SAL_OVERRIDE;
     354             :     virtual bool implCheckProperties( const uno::Reference< beans::XPropertySet >& rxModelProps ) const;
     355             :     virtual OUString implGetShapeName( const uno::Reference< drawing::XShape >& rxShape ) const throw (uno::RuntimeException) SAL_OVERRIDE;
     356             :     virtual void implOnShapeCreated( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException) SAL_OVERRIDE;
     357             : 
     358             : protected:
     359             :     uno::Reference< container::XIndexContainer > mxFormIC;
     360             :     OUString maModelServiceName;
     361             :     sal_Int16 mnComponentType;
     362             : };
     363             : 
     364           0 : ScVbaControlContainer::ScVbaControlContainer(
     365             :         const uno::Reference< XHelperInterface >& rxParent,
     366             :         const uno::Reference< uno::XComponentContext >& rxContext,
     367             :         const uno::Reference< frame::XModel >& rxModel,
     368             :         const uno::Reference< sheet::XSpreadsheet >& rxSheet,
     369             :         const uno::Type& rVbaType,
     370             :         const OUString& rModelServiceName,
     371             :         sal_Int16 nComponentType ) throw (uno::RuntimeException) :
     372             :     ScVbaObjectContainer( rxParent, rxContext, rxModel, rxSheet, rVbaType ),
     373             :     maModelServiceName( rModelServiceName ),
     374           0 :     mnComponentType( nComponentType )
     375             : {
     376           0 : }
     377             : 
     378           0 : uno::Reference< container::XIndexContainer > ScVbaControlContainer::createForm() throw (uno::RuntimeException)
     379             : {
     380           0 :     if( !mxFormIC.is() )
     381             :     {
     382           0 :         uno::Reference< form::XFormsSupplier > xFormsSupp( mxShapes, uno::UNO_QUERY_THROW );
     383           0 :         uno::Reference< container::XNameContainer > xFormsNC( xFormsSupp->getForms(), uno::UNO_SET_THROW );
     384           0 :         OUString aFormName = "Standard";
     385           0 :         if( xFormsNC->hasByName( aFormName ) )
     386             :         {
     387           0 :             mxFormIC.set( xFormsNC->getByName( aFormName ), uno::UNO_QUERY_THROW );
     388             :         }
     389             :         else
     390             :         {
     391           0 :             uno::Reference< form::XForm > xForm( mxFactory->createInstance( "com.sun.star.form.component.Form" ), uno::UNO_QUERY_THROW );
     392           0 :             xFormsNC->insertByName( aFormName, uno::Any( xForm ) );
     393           0 :             mxFormIC.set( xForm, uno::UNO_QUERY_THROW );
     394           0 :         }
     395             :     }
     396           0 :     return mxFormIC;
     397             : }
     398             : 
     399           0 : bool ScVbaControlContainer::implPickShape( const uno::Reference< drawing::XShape >& rxShape ) const
     400             : {
     401             :     try
     402             :     {
     403           0 :         uno::Reference< drawing::XControlShape > xControlShape( rxShape, uno::UNO_QUERY_THROW );
     404           0 :         uno::Reference< beans::XPropertySet > xModelProps( xControlShape->getControl(), uno::UNO_QUERY_THROW );
     405           0 :         sal_Int16 nClassId = -1;
     406           0 :         return lclGetProperty( nClassId, xModelProps, "ClassId" ) &&
     407           0 :             (nClassId == mnComponentType) && implCheckProperties( xModelProps );
     408             :     }
     409           0 :     catch( uno::Exception& )
     410             :     {
     411             :     }
     412           0 :     return false;
     413             : }
     414             : 
     415           0 : OUString ScVbaControlContainer::implGetShapeServiceName() const
     416             : {
     417           0 :     return OUString( "com.sun.star.drawing.ControlShape" );
     418             : }
     419             : 
     420           0 : bool ScVbaControlContainer::implCheckProperties( const uno::Reference< beans::XPropertySet >& /*rxModelProps*/ ) const
     421             : {
     422           0 :     return true;
     423             : }
     424             : 
     425           0 : OUString ScVbaControlContainer::implGetShapeName( const uno::Reference< drawing::XShape >& rxShape ) const throw (uno::RuntimeException)
     426             : {
     427           0 :     uno::Reference< drawing::XControlShape > xControlShape( rxShape, uno::UNO_QUERY_THROW );
     428           0 :     return uno::Reference< container::XNamed >( xControlShape->getControl(), uno::UNO_QUERY_THROW )->getName();
     429             : }
     430             : 
     431           0 : void ScVbaControlContainer::implOnShapeCreated( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException)
     432             : {
     433             :     // passed shape must be a control shape
     434           0 :     uno::Reference< drawing::XControlShape > xControlShape( rxShape, uno::UNO_QUERY_THROW );
     435             : 
     436             :     // create the UNO control model
     437           0 :     uno::Reference< form::XFormComponent > xFormComponent( mxFactory->createInstance( maModelServiceName ), uno::UNO_QUERY_THROW );
     438           0 :     uno::Reference< awt::XControlModel > xControlModel( xFormComponent, uno::UNO_QUERY_THROW );
     439             : 
     440             :     // insert the control model into the form and the shape
     441           0 :     createForm();
     442           0 :     mxFormIC->insertByIndex( mxFormIC->getCount(), uno::Any( xFormComponent ) );
     443           0 :     xControlShape->setControl( xControlModel );
     444           0 : }
     445             : 
     446             : 
     447             : // Push button
     448             : 
     449             : 
     450           0 : class ScVbaButtonContainer : public ScVbaControlContainer
     451             : {
     452             : public:
     453             :     explicit ScVbaButtonContainer(
     454             :         const uno::Reference< XHelperInterface >& rxParent,
     455             :         const uno::Reference< uno::XComponentContext >& rxContext,
     456             :         const uno::Reference< frame::XModel >& rxModel,
     457             :         const uno::Reference< sheet::XSpreadsheet >& rxSheet ) throw (uno::RuntimeException);
     458             : 
     459             : protected:
     460             :     virtual ScVbaSheetObjectBase* implCreateVbaObject( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException) SAL_OVERRIDE;
     461             :     virtual bool implCheckProperties( const uno::Reference< beans::XPropertySet >& rxModelProps ) const SAL_OVERRIDE;
     462             : };
     463             : 
     464           0 : ScVbaButtonContainer::ScVbaButtonContainer(
     465             :         const uno::Reference< XHelperInterface >& rxParent,
     466             :         const uno::Reference< uno::XComponentContext >& rxContext,
     467             :         const uno::Reference< frame::XModel >& rxModel,
     468             :         const uno::Reference< sheet::XSpreadsheet >& rxSheet ) throw (uno::RuntimeException) :
     469             :     ScVbaControlContainer(
     470             :         rxParent, rxContext, rxModel, rxSheet,
     471           0 :         cppu::UnoType<excel::XButton>::get(),
     472             :         "com.sun.star.form.component.CommandButton",
     473           0 :         form::FormComponentType::COMMANDBUTTON )
     474             : {
     475           0 : }
     476             : 
     477           0 : ScVbaSheetObjectBase* ScVbaButtonContainer::implCreateVbaObject( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException)
     478             : {
     479           0 :     uno::Reference< drawing::XControlShape > xControlShape( rxShape, uno::UNO_QUERY_THROW );
     480           0 :     return new ScVbaButton( mxParent, mxContext, mxModel, createForm(), xControlShape );
     481             : }
     482             : 
     483           0 : bool ScVbaButtonContainer::implCheckProperties( const uno::Reference< beans::XPropertySet >& rxModelProps ) const
     484             : {
     485             :     // do not insert toggle buttons into the 'Buttons' collection
     486           0 :     bool bToggle = false;
     487           0 :     return lclGetProperty( bToggle, rxModelProps, "Toggle" ) && !bToggle;
     488             : }
     489             : 
     490           0 : ScVbaButtons::ScVbaButtons(
     491             :         const uno::Reference< XHelperInterface >& rxParent,
     492             :         const uno::Reference< uno::XComponentContext >& rxContext,
     493             :         const uno::Reference< frame::XModel >& rxModel,
     494             :         const uno::Reference< sheet::XSpreadsheet >& rxSheet ) throw (uno::RuntimeException) :
     495           0 :     ScVbaGraphicObjectsBase( new ScVbaButtonContainer( rxParent, rxContext, rxModel, rxSheet ) )
     496             : {
     497           0 : }
     498             : 
     499           0 : VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaButtons, "ooo.vba.excel.Buttons" )
     500             : 
     501             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10