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

Generated by: LCOV version 1.11