24#include <rtl/math.hxx>
25#include <com/sun/star/beans/XPropertySet.hpp>
26#include <com/sun/star/container/XIndexContainer.hpp>
27#include <com/sun/star/container/XNamed.hpp>
28#include <com/sun/star/drawing/XControlShape.hpp>
29#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
30#include <com/sun/star/drawing/XShapes.hpp>
31#include <com/sun/star/form/FormComponentType.hpp>
32#include <com/sun/star/form/XForm.hpp>
33#include <com/sun/star/form/XFormComponent.hpp>
34#include <com/sun/star/form/XFormsSupplier.hpp>
35#include <com/sun/star/frame/XModel.hpp>
36#include <com/sun/star/lang/XMultiServiceFactory.hpp>
37#include <com/sun/star/sheet/XSpreadsheet.hpp>
46template<
typename Type >
47bool lclGetProperty(
Type& orValue,
const uno::Reference< beans::XPropertySet >& rxPropSet,
const OUString& rPropName )
51 return rxPropSet->getPropertyValue( rPropName ) >>= orValue;
53 catch( uno::Exception& )
63sal_Int32 lclPointsToHmm(
const uno::Any& rPoints )
65 return std::round(
o3tl::convert(::rtl::math::approxFloor(rPoints.get<
double>() / 0.75) * 0.75,
83 uno::Reference< XHelperInterface > xParent,
84 uno::Reference< uno::XComponentContext > xContext,
85 const uno::Reference< frame::XModel >& rxModel,
86 const uno::Reference< sheet::XSpreadsheet >& rxSheet,
106 uno::Reference< drawing::XShape >
createShape(
const awt::Point& rPos,
const awt::Size& rSize );
111 sal_Int32
insertShape(
const uno::Reference< drawing::XShape >& rxShape );
129 virtual sal_Int32 SAL_CALL
getCount()
override;
138 virtual bool implPickShape(
const uno::Reference< drawing::XShape >& rxShape )
const = 0;
151 virtual OUString
implGetShapeName(
const uno::Reference< drawing::XShape >& rxShape )
const;
166 typedef ::std::vector< uno::Reference< drawing::XShape > >
ShapeVector;
172 uno::Reference< XHelperInterface > xParent,
173 uno::Reference< uno::XComponentContext > xContext,
174 const uno::Reference< frame::XModel >& rxModel,
175 const uno::Reference< sheet::XSpreadsheet >& rxSheet,
181 maVbaType( rVbaType )
183 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupp( rxSheet, uno::UNO_QUERY_THROW );
184 mxShapes.set( xDrawPageSupp->getDrawPage(), uno::UNO_QUERY_THROW );
192 uno::Reference< drawing::XShape > xShape(
mxShapes->getByIndex(
nIndex ), uno::UNO_QUERY_THROW );
201 xShape->setPosition( rPos );
202 xShape->setSize( rSize );
215 const uno::Reference< drawing::XShape >& rxShape )
222 uno::Reference< drawing::XShape > xShape( rSource, uno::UNO_QUERY_THROW );
230 [&rIndex,
this](
const ShapeVector::value_type& rxShape) { return rIndex == implGetShapeName( rxShape ); });
233 throw uno::RuntimeException();
240 return static_cast< sal_Int32
>(
maShapes.size() );
247 throw lang::IndexOutOfBoundsException();
266 uno::Reference< beans::XPropertySet > xPropSet( rxShape, uno::UNO_QUERY_THROW );
267 return xPropSet->getPropertyValue(
"Name" ).get< OUString >();
294uno::Any ScVbaObjectEnumeration::createCollectionObject(
const uno::Any& rSource )
296 return mxContainer->createCollectionObject( rSource );
333 return mxContainer->createCollectionObject( rSource );
338 return mxContainer->getItemByStringIndex( rIndex );
355 awt::Point aPos( lclPointsToHmm( rLeft ), lclPointsToHmm( rTop ) );
356 awt::Size aSize( lclPointsToHmm( rWidth ), lclPointsToHmm( rHeight ) );
358 if( (aPos.X < 0) || (aPos.Y < 0) || (aSize.Width <= 0) || (aSize.Height <= 0) )
359 throw uno::RuntimeException();
362 uno::Reference< drawing::XShape > xShape(
mxContainer->createShape( aPos, aSize ), uno::UNO_SET_THROW );
367 xVbaObject->setDefaultProperties(
nIndex );
368 return uno::Any( uno::Reference< excel::XSheetObject >( xVbaObject ) );
379 explicit ScVbaControlContainer(
380 const uno::Reference< XHelperInterface >& rxParent,
381 const uno::Reference< uno::XComponentContext >& rxContext,
382 const uno::Reference< frame::XModel >& rxModel,
383 const uno::Reference< sheet::XSpreadsheet >& rxSheet,
385 OUString aModelServiceName,
390 uno::Reference< container::XIndexContainer >
const & createForm();
392 virtual bool implPickShape(
const uno::Reference< drawing::XShape >& rxShape )
const override;
394 virtual bool implCheckProperties(
const uno::Reference< beans::XPropertySet >& rxModelProps )
const;
395 virtual OUString
implGetShapeName(
const uno::Reference< drawing::XShape >& rxShape )
const override;
396 virtual void implOnShapeCreated(
const uno::Reference< drawing::XShape >& rxShape )
override;
399 uno::Reference< container::XIndexContainer > mxFormIC;
400 OUString maModelServiceName;
406ScVbaControlContainer::ScVbaControlContainer(
407 const uno::Reference< XHelperInterface >& rxParent,
408 const uno::Reference< uno::XComponentContext >& rxContext,
409 const uno::Reference< frame::XModel >& rxModel,
410 const uno::Reference< sheet::XSpreadsheet >& rxSheet,
412 OUString aModelServiceName,
415 maModelServiceName(
std::move( aModelServiceName )),
420uno::Reference< container::XIndexContainer >
const & ScVbaControlContainer::createForm()
424 uno::Reference< form::XFormsSupplier > xFormsSupp( mxShapes, uno::UNO_QUERY_THROW );
425 uno::Reference< container::XNameContainer > xFormsNC( xFormsSupp->getForms(), uno::UNO_SET_THROW );
426 OUString aFormName =
"Standard";
427 if( xFormsNC->hasByName( aFormName ) )
429 mxFormIC.set( xFormsNC->getByName( aFormName ), uno::UNO_QUERY_THROW );
433 uno::Reference< form::XForm > xForm(
mxFactory->createInstance(
"com.sun.star.form.component.Form" ), uno::UNO_QUERY_THROW );
434 xFormsNC->insertByName( aFormName,
uno::Any( xForm ) );
435 mxFormIC.set( xForm, uno::UNO_QUERY_THROW );
441bool ScVbaControlContainer::implPickShape(
const uno::Reference< drawing::XShape >& rxShape )
const
445 uno::Reference< drawing::XControlShape > xControlShape( rxShape, uno::UNO_QUERY_THROW );
446 uno::Reference< beans::XPropertySet > xModelProps( xControlShape->getControl(), uno::UNO_QUERY_THROW );
447 sal_Int16 nClassId = -1;
448 return lclGetProperty( nClassId, xModelProps,
"ClassId" ) &&
449 (nClassId ==
meType) && implCheckProperties( xModelProps );
451 catch( uno::Exception& )
457OUString ScVbaControlContainer::implGetShapeServiceName()
const
459 return "com.sun.star.drawing.ControlShape";
462bool ScVbaControlContainer::implCheckProperties(
const uno::Reference< beans::XPropertySet >& )
const
467OUString ScVbaControlContainer::implGetShapeName(
const uno::Reference< drawing::XShape >& rxShape )
const
469 uno::Reference< drawing::XControlShape > xControlShape( rxShape, uno::UNO_QUERY_THROW );
470 return uno::Reference< container::XNamed >( xControlShape->getControl(), uno::UNO_QUERY_THROW )->getName();
473void ScVbaControlContainer::implOnShapeCreated(
const uno::Reference< drawing::XShape >& rxShape )
476 uno::Reference< drawing::XControlShape > xControlShape( rxShape, uno::UNO_QUERY_THROW );
479 uno::Reference< form::XFormComponent > xFormComponent(
mxFactory->createInstance( maModelServiceName ), uno::UNO_QUERY_THROW );
480 uno::Reference< awt::XControlModel > xControlModel( xFormComponent, uno::UNO_QUERY_THROW );
484 mxFormIC->insertByIndex( mxFormIC->getCount(),
uno::Any( xFormComponent ) );
485 xControlShape->setControl( xControlModel );
492class ScVbaButtonContainer :
public ScVbaControlContainer
494 bool mbOptionButtons;
497 explicit ScVbaButtonContainer(
498 const uno::Reference< XHelperInterface >& rxParent,
499 const uno::Reference< uno::XComponentContext >& rxContext,
500 const uno::Reference< frame::XModel >& rxModel,
501 const uno::Reference< sheet::XSpreadsheet >& rxSheet,
502 bool bOptionButtons);
506 virtual bool implCheckProperties(
const uno::Reference< beans::XPropertySet >& rxModelProps )
const override;
511ScVbaButtonContainer::ScVbaButtonContainer(
512 const uno::Reference< XHelperInterface >& rxParent,
513 const uno::Reference< uno::XComponentContext >& rxContext,
514 const uno::Reference< frame::XModel >& rxModel,
515 const uno::Reference< sheet::XSpreadsheet >& rxSheet,
516 bool bOptionButtons ) :
517 ScVbaControlContainer(
518 rxParent, rxContext, rxModel, rxSheet,
519 cppu::UnoType<excel::XButton>::
get(),
521 OUString(
"com.sun.star.form.component.RadioButton" ) :
522 OUString(
"com.sun.star.form.component.CommandButton" ) ),
525 form::FormComponentType::COMMANDBUTTON) ),
526 mbOptionButtons(bOptionButtons)
532 uno::Reference< drawing::XControlShape > xControlShape( rxShape, uno::UNO_QUERY_THROW );
533 return new ScVbaButton( mxParent, mxContext, mxModel, createForm(), xControlShape );
536bool ScVbaButtonContainer::implCheckProperties(
const uno::Reference< beans::XPropertySet >& rxModelProps )
const
542 bool bToggle =
false;
543 return lclGetProperty( bToggle, rxModelProps,
"Toggle" ) && !bToggle;
547 const uno::Reference< XHelperInterface >& rxParent,
548 const uno::Reference< uno::XComponentContext >& rxContext,
549 const uno::Reference< frame::XModel >& rxModel,
550 const uno::Reference< sheet::XSpreadsheet >& rxSheet,
551 bool bOptionButtons) :
css::uno::Reference< css::frame::XModel2 > mxModel
unotools::WeakReference< AnimationNode > mxParent
Base class for collections containing a specific type of graphic object from a sheet.
ScVbaGraphicObjectsBase(const ScVbaObjectContainerRef &rxContainer)
virtual css::uno::Any SAL_CALL Add(const css::uno::Any &rLeft, const css::uno::Any &rTop, const css::uno::Any &rWidth, const css::uno::Any &rHeight) override
Container for a specific type of drawing object in a spreadsheet.
virtual rtl::Reference< ScVbaSheetObjectBase > implCreateVbaObject(const uno::Reference< drawing::XShape > &rxShape)=0
Derived classes create and return a new VBA implementation object for the passed shape.
virtual uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override
virtual uno::Type SAL_CALL getElementType() override
::std::vector< uno::Reference< drawing::XShape > > ShapeVector
const uno::Type maVbaType
uno::Any createCollectionObject(const uno::Any &rSource)
Creates and returns a new VBA implementation object for the passed shape in an Any.
uno::Reference< frame::XModel > mxModel
virtual sal_Bool SAL_CALL hasElements() override
ScVbaObjectContainer(uno::Reference< XHelperInterface > xParent, uno::Reference< uno::XComponentContext > xContext, const uno::Reference< frame::XModel > &rxModel, const uno::Reference< sheet::XSpreadsheet > &rxSheet, const uno::Type &rVbaType)
uno::Any getItemByStringIndex(const OUString &rIndex)
Returns the VBA implementation object with the specified name.
virtual OUString implGetShapeName(const uno::Reference< drawing::XShape > &rxShape) const
Returns the shape name via 'Name' property of the UNO shape.
uno::Reference< drawing::XShapes > mxShapes
uno::Reference< uno::XComponentContext > mxContext
virtual OUString implGetShapeServiceName() const =0
Derived classes return the service name of the UNO shape.
virtual sal_Int32 SAL_CALL getCount() override
const uno::Reference< XHelperInterface > & getParent() const
Returns the VBA helper interface of the VBA collection object.
const uno::Reference< uno::XComponentContext > & getContext() const
Returns the component context of the VBA collection object.
uno::Reference< lang::XMultiServiceFactory > mxFactory
const uno::Type & getVbaType() const
Returns the VBA type information of the objects in this container.
::rtl::Reference< ScVbaSheetObjectBase > createVbaObject(const uno::Reference< drawing::XShape > &rxShape)
Creates and returns a new VBA implementation object for the passed shape.
uno::Reference< drawing::XShape > createShape(const awt::Point &rPos, const awt::Size &rSize)
Creates and returns a new UNO shape.
sal_Int32 insertShape(const uno::Reference< drawing::XShape > &rxShape)
Inserts the passed shape into the draw page and into this container, and returns its index in the dra...
uno::Reference< XHelperInterface > mxParent
virtual bool implPickShape(const uno::Reference< drawing::XShape > &rxShape) const =0
Derived classes return true, if the passed shape is supported by the instance.
void collectShapes()
Collects all shapes supported by this instance and inserts them into the internal shape vector.
virtual void implOnShapeCreated(const uno::Reference< drawing::XShape > &rxShape)
Is called when a new UNO shape has been created but not yet inserted into the drawing page.
virtual ~ScVbaSheetObjectsBase() override
ScVbaObjectContainerRef mxContainer
virtual css::uno::Any getItemByStringIndex(const OUString &rIndex) override
void collectShapes()
Updates the collection by fetching all shapes from the draw page.
ScVbaSheetObjectsBase(const ScVbaObjectContainerRef &rxContainer)
virtual css::uno::Any createCollectionObject(const css::uno::Any &rSource) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual css::uno::Type SAL_CALL getElementType() override
virtual css::uno::Any createCollectionObject(const css::uno::Any &rSource)=0
css::uno::Type const & get()
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
uno::Reference< presentation::XTransitionFactory > mxFactory
#define VBAHELPER_IMPL_XHELPERINTERFACE(classname, servicename)
::cppu::ImplInheritanceHelper< ScVbaSheetObjectsBase, ov::excel::XGraphicObjects > ScVbaGraphicObjects_BASE