19#include <ooo/vba/office/MsoZOrderCmd.hpp>
20#include <ooo/vba/office/MsoScaleFrom.hpp>
21#include <com/sun/star/container/XChild.hpp>
22#include <com/sun/star/container/XNamed.hpp>
23#include <com/sun/star/drawing/ConnectorType.hpp>
24#include <com/sun/star/drawing/XDrawPage.hpp>
25#include <com/sun/star/drawing/XShapes.hpp>
26#include <com/sun/star/view/XSelectionSupplier.hpp>
27#include <com/sun/star/lang/XServiceInfo.hpp>
28#include <com/sun/star/text/RelOrientation.hpp>
29#include <com/sun/star/uno/XComponentContext.hpp>
30#include <com/sun/star/frame/XModel.hpp>
31#include <ooo/vba/office/MsoShapeType.hpp>
32#include <ooo/vba/office/MsoAutoShapeType.hpp>
33#include <ooo/vba/word/WdRelativeHorizontalPosition.hpp>
34#include <ooo/vba/word/WdRelativeVerticalPosition.hpp>
52ScVbaShape::ScVbaShape(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< drawing::XShape > xShape, uno::Reference< drawing::XShapes > xShapes, uno::Reference< frame::XModel > xModel, sal_Int32 nType )
54 , m_aShapeHelper( xShape )
55 , m_xShape(
std::move( xShape ))
56 , m_xShapes(
std::move( xShapes ))
73 uno::Reference< drawing::XShapes > xShapes( rEventObject.Source, uno::UNO_QUERY );
74 uno::Reference< drawing::XShape > xShape( rEventObject.Source, uno::UNO_QUERY );
80 catch( uno::Exception& )
88 uno::Reference< lang::XComponent > xComponent(
m_xShape, uno::UNO_QUERY );
89 if ( xComponent.is() )
90 xComponent->addEventListener(
this );
92 xComponent.set(
m_xShapes, uno::UNO_QUERY );
93 if ( xComponent.is() )
94 xComponent->addEventListener(
this );
102 uno::Reference< lang::XComponent > xComponent(
m_xShape, uno::UNO_QUERY_THROW );
103 xComponent->removeEventListener(
this );
114 uno::Reference< lang::XComponent > xComponent(
m_xShapes, uno::UNO_QUERY_THROW );
115 xComponent->removeEventListener(
this );
124 uno::Reference< drawing::XShapeDescriptor > xShapeDescriptor( xShape, uno::UNO_QUERY_THROW );
125 sShapeType = xShapeDescriptor->getShapeType();
126 SAL_INFO(
"vbahelper",
"ScVbaShape::getType: " << sShapeType);
128 if( sShapeType ==
"com.sun.star.drawing.GroupShape" )
129 return office::MsoShapeType::msoGroup;
130 else if( sShapeType ==
"com.sun.star.drawing.GraphicObjectShape" )
131 return office::MsoShapeType::msoPicture;
132 else if( sShapeType ==
"com.sun.star.drawing.ControlShape" || sShapeType ==
"FrameShape" )
133 return office::MsoShapeType::msoOLEControlObject;
135 else if( sShapeType ==
"com.sun.star.drawing.OLE2Shape" )
136 return office::MsoShapeType::msoChart;
138 else if( sShapeType ==
"com.sun.star.drawing.ConnectorShape" )
140 drawing::ConnectorType connectorType;
141 uno::Reference< beans::XPropertySet > xPropertySet( xShape, uno::UNO_QUERY_THROW );
142 xPropertySet->getPropertyValue(
"EdgeKind" ) >>= connectorType;
143 if( connectorType == drawing::ConnectorType_CURVE )
144 return office::MsoShapeType::msoFreeform;
145 else if( connectorType == drawing::ConnectorType_LINE )
146 return office::MsoShapeType::msoLine;
148 return office::MsoShapeType::msoAutoShape;
150 else if( sShapeType ==
"com.sun.star.drawing.LineShape" )
151 return office::MsoShapeType::msoLine;
152 else if( sShapeType ==
"com.sun.star.drawing.CustomShape"
153 || sShapeType ==
"com.sun.star.drawing.RectangleShape"
154 || sShapeType ==
"com.sun.star.drawing.EllipseShape" )
155 return office::MsoShapeType::msoAutoShape;
156 else if( sShapeType ==
"com.sun.star.drawing.TextShape" )
157 return office::MsoShapeType::msoTextBox;
159 throw uno::RuntimeException(
"the shape type do not be supported: " + sShapeType );
167 uno::Reference< drawing::XShapeDescriptor > xShapeDescriptor( xShape, uno::UNO_QUERY_THROW );
168 sShapeType = xShapeDescriptor->getShapeType();
169 SAL_INFO(
"vbahelper",
"ScVbaShape::getAutoShapeType: " << sShapeType);
171 if( sShapeType ==
"com.sun.star.drawing.EllipseShape" )
172 return office::MsoAutoShapeType::msoShapeOval;
173 else if ( sShapeType ==
"com.sun.star.drawing.RectangleShape" )
174 return office::MsoAutoShapeType::msoShapeRectangle;
175 else if ( sShapeType ==
"com.sun.star.drawing.CustomShape" )
177 uno::Reference< beans::XPropertySet > aXPropSet( xShape, uno::UNO_QUERY );
178 uno::Any aGeoPropSet = aXPropSet->getPropertyValue(
"CustomShapeGeometry" );
179 uno::Sequence< beans::PropertyValue > aGeoPropSeq;
180 if ( aGeoPropSet >>= aGeoPropSeq )
182 for(
const auto& rProp : std::as_const(aGeoPropSeq) )
184 if( rProp.Name ==
"Type" )
187 if( rProp.Value >>=
sType )
189 if(
sType.endsWith(
"ellipse" ) )
190 return office::MsoAutoShapeType::msoShapeOval;
198 SAL_WARN(
"vbahelper",
"ScVbaShape::getAutoShapeType: unknown auto type" );
208 uno::Reference< container::XNamed > xNamed(
m_xShape, uno::UNO_QUERY_THROW );
209 sName = xNamed->getName();
216 uno::Reference< container::XNamed > xNamed(
m_xShape, uno::UNO_QUERY_THROW );
217 xNamed->setName( _name );
224 uno::Reference< beans::XPropertySet > xProps(
m_xShape, uno::UNO_QUERY_THROW );
225 xProps->getPropertyValue(
"Title") >>= sAltText;
232 uno::Reference< beans::XPropertySet > xProps(
m_xShape, uno::UNO_QUERY_THROW );
233 xProps->setPropertyValue(
"Title",
uno::Any( sAltText ) );
268 catch( uno::Exception& )
272 m_xPropertySet->getPropertyValue(
"HoriOrientPosition" ) >>= nLeft;
273 left = Millimeter::getInPoints( nLeft );
285 catch( uno::Exception& )
287 sal_Int32 nLeft = Millimeter::getInHundredthsOfOneMillimeter( _left );
300 catch( uno::Exception& )
303 m_xPropertySet->getPropertyValue(
"VertOrientPosition" ) >>= nTop;
304 top = Millimeter::getInPoints( nTop );
316 catch( uno::Exception& )
318 sal_Int32 nTop = Millimeter::getInHundredthsOfOneMillimeter( _top );
341 sal_Int32 nZOrderPosition = 0;
343 aZOrderPosition >>= nZOrderPosition;
344 return nZOrderPosition + 1;
356 double dRotation = 0;
357 sal_Int32 nRotation = 0;
359 dRotation =
static_cast< double >( nRotation /100 );
366 sal_Int32 nRotation =
static_cast < sal_Int32
> ( _rotation * 100 );
370uno::Reference< msforms::XLineFormat > SAL_CALL
377uno::Reference< msforms::XFillFormat > SAL_CALL
383uno::Reference< msforms::XPictureFormat > SAL_CALL
393 uno::Reference< lang::XServiceInfo > xServiceInfo(
m_xModel, uno::UNO_QUERY_THROW );
394 if( xServiceInfo->supportsService(
"com.sun.star.sheet.SpreadsheetDocument" ) )
397 uno::Reference< uno::XInterface > xTextFrame = xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
"ooo.vba.excel.TextFrame" , {
uno::Any(
getParent()),
uno::Any(
m_xShape) }, xContext );
414 sal_Int32 nOrderPosition;
416 aOrderPosition >>= nOrderPosition;
419 case office::MsoZOrderCmd::msoBringToFront:
422 case office::MsoZOrderCmd::msoSendToBack:
425 case office::MsoZOrderCmd::msoBringForward:
429 case office::MsoZOrderCmd::msoSendBackward:
430 if( nOrderPosition > 0 )
437 case office::MsoZOrderCmd::msoBringInFrontOfText:
438 case office::MsoZOrderCmd::msoSendBehindText:
439 throw uno::RuntimeException(
"This ZOrderCmd is not implemented, it is use with writer." );
441 throw uno::RuntimeException(
"Invalid Parameter." );
449 nCurrentRotation += Increment;
456 double nCurrentLeft =
getLeft();
457 nCurrentLeft += Increment;
464 double nCurrentTop =
getTop();
465 nCurrentTop += Increment;
473 double nNewHeight = nHeight * Factor;
474 if(
Scale == office::MsoScaleFrom::msoScaleFromTopLeft )
478 else if(
Scale == office::MsoScaleFrom::msoScaleFromBottomRight )
480 double nDeltaHeight = nNewHeight - nHeight;
481 double nNewTop =
getTop() - nDeltaHeight;
485 else if(
Scale == office::MsoScaleFrom::msoScaleFromMiddle )
487 double nDeltaHeight = (nNewHeight - nHeight) / 2;
488 double nNewTop =
getTop() - nDeltaHeight;
494 throw uno::RuntimeException(
"ScaleHeight.Scale wrong value is given." );
502 double nNewWidth = nWidth * Factor;
503 if(
Scale == office::MsoScaleFrom::msoScaleFromTopLeft )
507 else if(
Scale == office::MsoScaleFrom::msoScaleFromBottomRight )
509 double nDeltaWidth = nNewWidth - nWidth;
510 double nNewLeft =
getLeft() - nDeltaWidth;
514 else if(
Scale == office::MsoScaleFrom::msoScaleFromMiddle )
516 double nDeltaWidth = (nNewWidth - nWidth) / 2;
517 double nNewLeft =
getLeft() - nDeltaWidth;
523 throw uno::RuntimeException(
"ScaleHeight.Scale wrong value is given." );
530 uno::Reference< view::XSelectionSupplier > xSelectSupp(
m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
548 uno::Reference< container::XChild > xChild(
m_xShape, uno::UNO_QUERY_THROW );
550 uno::Reference< msforms::XShapeRange > xShapeRange(
new ScVbaShapeRange(
mxParent,
mxContext, xIndexAccess, uno::Reference< drawing::XDrawPage >( xChild->getParent(), uno::UNO_QUERY_THROW ),
m_xModel ) );
551 if (
index.hasValue() )
585 sal_Int32 nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionMargin;
586 sal_Int16
nType = text::RelOrientation::PAGE_LEFT;
591 case text::RelOrientation::FRAME:
593 nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionColumn;
596 case text::RelOrientation::PAGE_FRAME:
598 nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionPage;
601 case text::RelOrientation::CHAR:
603 nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionCharacter;
606 case text::RelOrientation::PAGE_PRINT_AREA:
608 nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionMargin;
613 throw uno::RuntimeException(
"Shape::RelativeHorizontalPosition: not implemented" );
616 return nRelativeHorizontalPosition;
622 sal_Int16
nType = text::RelOrientation::PAGE_FRAME;
623 switch( _relativehorizontalposition )
625 case word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionCharacter:
627 nType = text::RelOrientation::CHAR;
630 case word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionColumn:
632 nType = text::RelOrientation::PAGE_FRAME;
635 case word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionMargin:
637 nType = text::RelOrientation::PAGE_PRINT_AREA;
640 case word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionPage:
642 nType = text::RelOrientation::PAGE_FRAME;
656 sal_Int32 nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionMargin;
657 sal_Int16
nType = text::RelOrientation::PAGE_FRAME;
662 case text::RelOrientation::FRAME:
664 nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionParagraph;
667 case text::RelOrientation::PAGE_FRAME:
669 nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionPage;
672 case text::RelOrientation::TEXT_LINE:
674 nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionLine;
677 case text::RelOrientation::PAGE_PRINT_AREA:
679 nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionMargin;
684 throw uno::RuntimeException(
"Shape::RelativeVerticalPosition: not implemented" );
687 return nRelativeVerticalPosition;
693 sal_Int16
nType = text::RelOrientation::PAGE_FRAME;
694 switch( _relativeverticalposition )
696 case word::WdRelativeVerticalPosition::wdRelativeVerticalPositionLine:
698 nType = text::RelOrientation::TEXT_LINE;
701 case word::WdRelativeVerticalPosition::wdRelativeVerticalPositionParagraph:
703 nType = text::RelOrientation::FRAME;
706 case word::WdRelativeVerticalPosition::wdRelativeVerticalPositionMargin:
708 nType = text::RelOrientation::PAGE_PRINT_AREA;
711 case word::WdRelativeVerticalPosition::wdRelativeVerticalPositionPage:
713 nType = text::RelOrientation::PAGE_FRAME;
727 uno::Reference< lang::XServiceInfo > xServiceInfo(
m_xModel, uno::UNO_QUERY_THROW );
728 if( xServiceInfo->supportsService(
"com.sun.star.text.TextDocument" ))
731 uno::Reference< uno::XInterface > xWrapFormat = xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
"ooo.vba.word.WrapFormat" ,{
uno::Any(
getParent()),
uno::Any(
m_xShape) }, xContext );
734 throw uno::RuntimeException(
"Not implemented" );
743uno::Sequence< OUString >
748 "ooo.vba.msform.Shape"
css::uno::Reference< css::uno::XComponentContext > mxContext
css::uno::WeakReference< ov::XHelperInterface > mxParent
virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent() override
virtual void SAL_CALL Delete() override
virtual OUString SAL_CALL getAlternativeText() override
virtual void SAL_CALL setWidth(double _width) override
virtual void SAL_CALL setLockAnchor(sal_Bool _lockanchor) override
virtual sal_Bool SAL_CALL getVisible() override
virtual css::uno::Any SAL_CALL TextFrame() override
virtual void SAL_CALL ZOrder(sal_Int32 ZOrderCmd) override
virtual css::uno::Reference< ov::msforms::XLineFormat > SAL_CALL getLine() override
virtual double SAL_CALL getWidth() override
ov::ShapeHelper m_aShapeHelper
virtual sal_Int32 SAL_CALL getZOrderPosition() override
virtual void SAL_CALL setRelativeHorizontalPosition(::sal_Int32 _relativehorizontalposition) override
virtual void SAL_CALL setTop(double _top) override
virtual css::uno::Reference< ov::msforms::XPictureFormat > SAL_CALL getPictureFormat() override
virtual double SAL_CALL getRotation() override
virtual void SAL_CALL setVisible(sal_Bool _visible) override
css::uno::Reference< css::beans::XPropertySet > m_xPropertySet
virtual void SAL_CALL IncrementRotation(double Increment) override
virtual void SAL_CALL setLockAspectRatio(sal_Bool _lockaspectratio) override
virtual double SAL_CALL getLeft() override
virtual ::sal_Int32 SAL_CALL getRelativeVerticalPosition() override
virtual css::uno::Any SAL_CALL WrapFormat() override
virtual void SAL_CALL Select(const css::uno::Any &Replace) override
virtual sal_Bool SAL_CALL getLockAspectRatio() override
virtual double SAL_CALL getHeight() override
virtual OUString SAL_CALL getName() override
virtual void SAL_CALL ScaleWidth(double Factor, sal_Bool RelativeToOriginalSize, sal_Int32 Scale) override
virtual sal_Bool SAL_CALL getLockAnchor() override
css::uno::Reference< css::drawing::XShapes > m_xShapes
css::uno::Reference< css::frame::XModel > m_xModel
void removeShapesListener()
virtual double SAL_CALL getTop() override
virtual void SAL_CALL setRelativeVerticalPosition(::sal_Int32 _relativeverticalposition) override
virtual sal_Int32 SAL_CALL getType() override
virtual void SAL_CALL setRotation(double _rotation) override
static sal_Int32 getAutoShapeType(const css::uno::Reference< css::drawing::XShape > &rShape)
virtual void SAL_CALL IncrementLeft(double Increment) override
virtual void SAL_CALL setHeight(double _height) override
virtual void SAL_CALL ScaleHeight(double Factor, sal_Bool RelativeToOriginalSize, sal_Int32 Scale) override
virtual css::uno::Any SAL_CALL ShapeRange(const css::uno::Any &index) override
void removeShapeListener()
ScVbaShape(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, css::uno::Reference< css::drawing::XShape > xShape, css::uno::Reference< css::drawing::XShapes > xShapes, css::uno::Reference< css::frame::XModel > xModel, sal_Int32 nType)
virtual void SAL_CALL IncrementTop(double Increment) override
virtual ::sal_Int32 SAL_CALL getRelativeHorizontalPosition() override
css::uno::Reference< css::drawing::XShape > m_xShape
virtual ~ScVbaShape() override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual OUString getServiceImplName() override
virtual void SAL_CALL setName(const OUString &_name) override
virtual void SAL_CALL setAlternativeText(const OUString &_name) override
virtual void SAL_CALL disposing(const css::lang::EventObject &rEventObject) override
virtual void SAL_CALL setLeft(double _left) override
virtual css::uno::Reference< ov::msforms::XFillFormat > SAL_CALL getFill() override
std::vector< css::uno::Reference< OneIfc > > XNamedVec
void setWidth(double _fWidth)
void setTop(double _fTop)
void setHeight(double _fheight)
void setLeft(double _fLeft)
Reference< frame::XModel > m_xModel
Sequence< OUString > aServiceNames
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
Reference< XComponentContext > getProcessComponentContext()
#define ERRCODE_BASIC_BAD_ARGUMENT
Reference< XModel > xModel