20#include <com/sun/star/view/XSelectionSupplier.hpp>
21#include <com/sun/star/text/WrapTextMode.hpp>
22#include <ooo/vba/msforms/XShapeRange.hpp>
23#include <ooo/vba/office/MsoAutoShapeType.hpp>
24#include <com/sun/star/awt/Point.hpp>
25#include <com/sun/star/awt/Size.hpp>
26#include <com/sun/star/beans/XPropertySet.hpp>
27#include <com/sun/star/frame/XModel.hpp>
28#include <com/sun/star/lang/XMultiServiceFactory.hpp>
29#include <com/sun/star/lang/XServiceInfo.hpp>
30#include <com/sun/star/script/BasicErrorException.hpp>
31#include <com/sun/star/script/XTypeConverter.hpp>
32#include <com/sun/star/text/TextContentAnchorType.hpp>
33#include <com/sun/star/text/HoriOrientation.hpp>
34#include <com/sun/star/text/VertOrientation.hpp>
35#include <com/sun/star/text/RelOrientation.hpp>
36#include <com/sun/star/drawing/LineStyle.hpp>
37#include <com/sun/star/drawing/XDrawPage.hpp>
38#include <com/sun/star/drawing/XShape.hpp>
39#include <com/sun/star/drawing/XShapes.hpp>
55 uno::Reference<msforms::XShapes > m_xParent;
56 uno::Reference<container::XIndexAccess > m_xIndexAccess;
59 VbShapeEnumHelper( uno::Reference< msforms::XShapes > xParent, uno::Reference< container::XIndexAccess > xIndexAccess ) : m_xParent(
std::move( xParent )), m_xIndexAccess(
std::move( xIndexAccess )),
nIndex( 0 ) {}
60 virtual sal_Bool SAL_CALL hasMoreElements( )
override
62 return ( nIndex < m_xIndexAccess->getCount() );
64 virtual uno::Any SAL_CALL nextElement( )
override
67 if ( pShapes && hasMoreElements() )
69 throw container::NoSuchElementException();
83 aShapes.reserve( nLen );
91ScVbaShapes::ScVbaShapes(
const css::uno::Reference< ov::XHelperInterface >& xParent,
const css::uno::Reference< css::uno::XComponentContext >& xContext,
const css::uno::Reference< css::container::XIndexAccess >& xShapes, uno::Reference< frame::XModel> xModel ):
ScVbaShapes_BASE( xParent, xContext, xShapes, true ), m_nNewShapeCount(0),
m_xModel(
std::move(
xModel ))
93 m_xShapes.set( xShapes, uno::UNO_QUERY_THROW );
98uno::Reference< container::XEnumeration >
107 if( aSource.hasValue() )
109 uno::Reference< drawing::XShape > xShape( aSource, uno::UNO_QUERY_THROW );
124 return "ScVbaShapes";
127uno::Sequence< OUString >
132 "ooo.vba.msform.Shapes"
137css::uno::Reference< css::container::XIndexAccess >
140 if (
Index.getValueTypeClass() != uno::TypeClass_SEQUENCE )
141 throw uno::RuntimeException();
146 uno::Sequence< uno::Any > sIndices;
147 aConverted >>= sIndices;
149 for(
const auto& rIndex : std::as_const(sIndices) )
151 uno::Reference< drawing::XShape > xShape;
152 if ( rIndex.getValueTypeClass() == uno::TypeClass_STRING )
168 aShapes.push_back( xShape );
174uno::Reference< msforms::XShapeRange > SAL_CALL
178 uno::Reference< container::XIndexAccess > xShapes;
179 if ( shapes.getValueTypeClass() == uno::TypeClass_SEQUENCE )
184 uno::Sequence< uno::Any > sIndices { shapes };
195 uno::Reference< view::XSelectionSupplier > xSelectSupp(
m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
203 catch(
const lang::IllegalArgumentException&)
208uno::Reference< drawing::XShape >
211 uno::Reference< lang::XMultiServiceFactory > xMSF(
m_xModel, uno::UNO_QUERY_THROW );
212 uno::Reference< drawing::XShape > xShape( xMSF->createInstance( service ), uno::UNO_QUERY_THROW );
219 sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( startX );
220 sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( startY );
221 sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter(
nLineWidth );
222 sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( nLineHeight );
224 uno::Reference< drawing::XShape > xShape(
createShape(
"com.sun.star.drawing.RectangleShape" ), uno::UNO_SET_THROW );
231 awt::Point aMovePositionIfRange(0, 0);
233 position.X = nXPos - aMovePositionIfRange.X;
234 position.Y = nYPos - aMovePositionIfRange.Y;
238 size.Height = nHeight;
240 xShape->setSize(
size );
243 return uno::Any( uno::Reference< msforms::XShape > ( pScVbaShape ) );
249 sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( startX );
250 sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( startY );
251 sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter(
nLineWidth );
252 sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( nLineHeight );
254 uno::Reference< drawing::XShape > xShape(
createShape(
"com.sun.star.drawing.EllipseShape" ), uno::UNO_SET_THROW );
257 awt::Point aMovePositionIfRange( 0, 0 );
275 position.X = nXPos - aMovePositionIfRange.X;
276 position.Y = nYPos - aMovePositionIfRange.Y;
280 size.Height = nHeight;
282 xShape->setSize(
size);
285 return uno::Any( uno::Reference< msforms::XShape > ( pScVbaShape ) );
293 sal_Int32 nLineHeight = endY - StartY;
295 sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( nLineHeight );
296 sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter(
nLineWidth );
297 sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( StartX );
298 sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( StartY );
300 uno::Reference< drawing::XShape > xShape(
createShape(
"com.sun.star.drawing.LineShape" ), uno::UNO_SET_THROW );
303 awt::Point aMovePositionIfRange( 0, 0 );
310 position.X = nXPos - aMovePositionIfRange.X;
311 position.Y = nYPos - aMovePositionIfRange.Y;
315 size.Height = nHeight;
317 xShape->setSize(
size);
320 return uno::Any( uno::Reference< msforms::XShape > ( pScVbaShape ) );
326 if (_nType == office::MsoAutoShapeType::msoShapeRectangle)
330 else if (_nType == office::MsoAutoShapeType::msoShapeOval)
332 return AddEllipse(_nLeft, _nTop, _nWidth, _nHeight);
340 uno::Reference< lang::XServiceInfo > xServiceInfo(
m_xModel, uno::UNO_QUERY_THROW );
341 if( xServiceInfo->supportsService(
"com.sun.star.text.TextDocument" ) )
345 throw uno::RuntimeException(
"Not implemented" );
351 sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( _nLeft );
352 sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( _nTop );
353 sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter( _nWidth );
354 sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( _nHeight );
356 uno::Reference< drawing::XShape > xShape(
createShape(
"com.sun.star.drawing.TextShape" ), uno::UNO_SET_THROW );
365 size.Height = nHeight;
367 xShape->setSize(
size);
369 uno::Reference< beans::XPropertySet > xShapeProps( xShape, uno::UNO_QUERY_THROW );
370 xShapeProps->setPropertyValue(
"AnchorType",
uno::Any( text::TextContentAnchorType_AT_PAGE ) );
371 xShapeProps->setPropertyValue(
"HoriOrientRelation",
uno::Any( text::RelOrientation::PAGE_LEFT ) );
372 xShapeProps->setPropertyValue(
"HoriOrient",
uno::Any( text::HoriOrientation::NONE ) );
373 xShapeProps->setPropertyValue(
"HoriOrientPosition",
uno::Any( nXPos ) );
375 xShapeProps->setPropertyValue(
"VertOrientRelation",
uno::Any( text::RelOrientation::PAGE_FRAME ) );
376 xShapeProps->setPropertyValue(
"VertOrient",
uno::Any( text::VertOrientation::NONE ) );
377 xShapeProps->setPropertyValue(
"VertOrientPosition",
uno::Any( nYPos ) );
380 xShapeProps->setPropertyValue(
"LineStyle",
uno::Any( drawing::LineStyle_SOLID ) );
382 xShapeProps->setPropertyValue(
"LayerID",
uno::Any( sal_Int16(1) ) );
383 xShapeProps->setPropertyValue(
"LayerName",
uno::Any( OUString(
"Heaven") ) );
387 return uno::Any( uno::Reference< msforms::XShape > ( pScVbaShape ) );
393 uno::Reference< beans::XPropertySet > xPropertySet( xShape, uno::UNO_QUERY_THROW );
394 xPropertySet->setPropertyValue(
"FillStyle",
uno::Any( OUString(
"SOLID") ) );
395 xPropertySet->setPropertyValue(
"FillColor",
uno::Any( sal_Int32(0xFFFFFF) ) );
396 xPropertySet->setPropertyValue(
"TextWordWrap",
uno::Any( text::WrapTextMode_THROUGH ) );
404 uno::Reference< beans::XPropertySet > xPropertySet( xShape, uno::UNO_QUERY_THROW );
409 catch(
const script::BasicErrorException&)
419 return sName + OUString::number( nActNumber );
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent() override
css::uno::Reference< css::container::XNameAccess > m_xNameAccess
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
virtual sal_Int32 SAL_CALL getType() override
static void setShape_NameProperty(const css::uno::Reference< css::drawing::XShape > &xShape, const OUString &sName)
css::uno::Reference< css::frame::XModel > m_xModel
css::uno::Any AddEllipse(sal_Int32 startX, sal_Int32 startY, sal_Int32 nLineWidth, sal_Int32 nLineHeight)
css::uno::Reference< css::container::XIndexAccess > getShapesByArrayIndices(const css::uno::Any &Index)
css::uno::Any AddTextboxInWriter(sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight)
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
virtual css::uno::Type SAL_CALL getElementType() override
css::uno::Reference< css::drawing::XShape > createShape(const OUString &service)
sal_Int32 m_nNewShapeCount
css::uno::Any AddRectangle(sal_Int32 startX, sal_Int32 startY, sal_Int32 nLineWidth, sal_Int32 nLineHeight)
virtual void SAL_CALL SelectAll() override
virtual css::uno::Any SAL_CALL AddShape(sal_Int32 _nType, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight) override
ScVbaShapes(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::container::XIndexAccess > &xShapes, css::uno::Reference< css::frame::XModel > xModel)
css::uno::Reference< css::drawing::XShapes > m_xShapes
void initBaseCollection()
virtual OUString getServiceImplName() override
virtual css::uno::Any SAL_CALL AddTextbox(sal_Int32 _nOrientation, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
static void setDefaultShapeProperties(const css::uno::Reference< css::drawing::XShape > &xShape)
virtual css::uno::Reference< ov::msforms::XShapeRange > SAL_CALL Range(const css::uno::Any &shapes) override
virtual css::uno::Sequence< OUString > getServiceNames() override
css::uno::Reference< css::drawing::XDrawPage > m_xDrawPage
OUString createName(std::u16string_view sName)
virtual css::uno::Any SAL_CALL AddLine(sal_Int32 StartX, sal_Int32 StartY, sal_Int32 endX, sal_Int32 endY) override
std::vector< css::uno::Reference< OneIfc > > XNamedVec
css::uno::Type const & get()
Reference< frame::XModel > m_xModel
std::deque< AttacherIndex_Impl > aIndex
Reference< XTypeConverter > xConverter
Sequence< OUString > aServiceNames
uno::Reference< script::XTypeConverter > const & getTypeConverter(const uno::Reference< uno::XComponentContext > &xContext)
Reference< XModel > xModel
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE