xref: /AOO41X/main/vbahelper/source/vbahelper/vbashape.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #include<ooo/vba/office/MsoZOrderCmd.hpp>
28 #include<ooo/vba/office/MsoScaleFrom.hpp>
29 #include<com/sun/star/container/XNamed.hpp>
30 #include<com/sun/star/drawing/ConnectorType.hpp>
31 #include <com/sun/star/lang/XEventListener.hpp>
32 #include<com/sun/star/drawing/XDrawPagesSupplier.hpp>
33 #include<com/sun/star/drawing/XDrawPages.hpp>
34 #include<com/sun/star/view/XSelectionSupplier.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/text/TextContentAnchorType.hpp>
38 #include <ooo/vba/word/WdRelativeHorizontalPosition.hpp>
39 #include <ooo/vba/word/WdRelativeVerticalPosition.hpp>
40 
41 #include <comphelper/processfactory.hxx>
42 #include <vos/mutex.hxx>
43 #include <vcl/svapp.hxx>
44 #include <svx/unopage.hxx>
45 #include <svx/unoshape.hxx>
46 
47 #include <vbahelper/vbashape.hxx>
48 #include <vbahelper/vbatextframe.hxx>
49 #include "vbalineformat.hxx"
50 #include "vbafillformat.hxx"
51 #include "vbapictureformat.hxx"
52 #include <vbahelper/vbashaperange.hxx>
53 
54 using namespace ::ooo::vba;
55 using namespace ::com::sun::star;
56 using namespace ::vos;
57 
58 ScVbaShape::ScVbaShape( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape >& xShape, const uno::Reference< drawing::XShapes >& xShapes, const uno::Reference< frame::XModel >& xModel, sal_Int32 nType ) throw( lang::IllegalArgumentException ) : ScVbaShape_BASE( xParent, xContext ), m_xShape( xShape ), m_xShapes( xShapes ), m_nType( nType ), m_xModel( xModel )
59 {
60     m_xPropertySet.set( m_xShape, uno::UNO_QUERY_THROW );
61     m_pShapeHelper.reset( new ShapeHelper( m_xShape ) );
62     addListeners();
63 }
64 
65 ScVbaShape::ScVbaShape( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape >& xShape, const uno::Reference< frame::XModel >& xModel ) throw( lang::IllegalArgumentException ) : ScVbaShape_BASE( uno::Reference< XHelperInterface >(), xContext ), m_xShape( xShape ), m_xModel( xModel )
66 {
67     // add listener
68     addListeners();
69 }
70 
71 ScVbaShape::~ScVbaShape()
72 {
73     // dtor must never ever throw
74     /*try
75     {
76         removeShapeListener();
77         removeShapesListener();
78     }
79     catch( uno::Exception& )
80     {
81     }*/
82 }
83 
84 void SAL_CALL
85 ScVbaShape::disposing( const lang::EventObject& rEventObject ) throw( uno::RuntimeException )
86 {
87     try
88     {
89     uno::Reference< drawing::XShapes > xShapes( rEventObject.Source, uno::UNO_QUERY );
90     uno::Reference< drawing::XShape > xShape( rEventObject.Source, uno::UNO_QUERY );
91     if ( xShapes.is() )
92         removeShapesListener();
93     if ( xShape.is() )
94         removeShapeListener();
95     }
96     catch( uno::Exception& )
97     {
98     }
99 }
100 
101 
102 void ScVbaShape::addListeners()
103 {
104     uno::Reference< lang::XComponent > xComponent( m_xShape, uno::UNO_QUERY );
105     if ( xComponent.is() )
106     	xComponent->addEventListener( this );
107 
108     xComponent.set( m_xShapes, uno::UNO_QUERY );
109     if ( xComponent.is() )
110     	xComponent->addEventListener( this );
111 }
112 
113 void
114 ScVbaShape::removeShapeListener() throw( uno::RuntimeException )
115 {
116     if( m_xShape.is() )
117     {
118         uno::Reference< lang::XComponent > xComponent( m_xShape, uno::UNO_QUERY_THROW );
119         xComponent->removeEventListener( this );
120     }
121     m_xShape = NULL;
122     m_xPropertySet = NULL;
123 }
124 
125 void
126 ScVbaShape::removeShapesListener() throw( uno::RuntimeException )
127 {
128     if( m_xShapes.is() )
129     {
130         uno::Reference< lang::XComponent > xComponent( m_xShapes, uno::UNO_QUERY_THROW );
131         xComponent->removeEventListener( this );
132     }
133     m_xShapes = NULL;
134 }
135 
136 sal_Int32
137 ScVbaShape::getType( const css::uno::Reference< drawing::XShape > xShape ) throw (uno::RuntimeException)
138 {
139     rtl::OUString sShapeType;
140     uno::Reference< drawing::XShapeDescriptor > xShapeDescriptor( xShape, uno::UNO_QUERY_THROW );
141     sShapeType = xShapeDescriptor->getShapeType();
142     OSL_TRACE("ScVbaShape::getType: %s", rtl::OUStringToOString( sShapeType, RTL_TEXTENCODING_UTF8 ).getStr() );
143     // office::MsoShapeType::msoDiagram to "com.sun.star.drawing.GroupShape"
144     if( sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.GroupShape" ) ) )
145         return office::MsoShapeType::msoGroup;
146     else if( sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.GraphicObjectShape" ) ) )
147         return office::MsoShapeType::msoPicture;
148     else if( sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.ControlShape" ) ) ||
149             sShapeType.equals( rtl::OUString::createFromAscii( "FrameShape" ) ) )
150         return office::MsoShapeType::msoOLEControlObject;
151     // OOo don't support office::MsoShapeType::msoComment as a Shape.
152     else if( sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.OLE2Shape" ) ) )
153         return office::MsoShapeType::msoChart;
154     // Art characters office::MsoShapeType::msoTextEffect, in OOo corresponding to "com.sun.star.drawing.CustomShape"
155     else if( sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.ConnectorShape" ) ) )
156     {
157         enum drawing::ConnectorType connectorType;
158         uno::Reference< beans::XPropertySet > xPropertySet( xShape, uno::UNO_QUERY_THROW );
159         xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("EdgeKind")) >>= connectorType;
160         if( connectorType == drawing::ConnectorType_CURVE )
161             return office::MsoShapeType::msoFreeform;
162         else if( connectorType == drawing::ConnectorType_LINE )
163             return office::MsoShapeType::msoLine;
164         else
165             return office::MsoShapeType::msoAutoShape;
166     }
167     else if( sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.LineShape" ) ) )
168         return office::MsoShapeType::msoLine;
169     else if( sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.CustomShape" ) ) ||
170             sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.RectangleShape") ) )
171         return office::MsoShapeType::msoAutoShape;
172     else if( sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.TextShape" ) ) )
173         return office::MsoShapeType::msoTextBox;
174     else
175         throw uno::RuntimeException( rtl::OUString::createFromAscii( "the shape type do not be supported: " ) + sShapeType, uno::Reference< uno::XInterface >() );
176 }
177 
178 // Attributes
179 rtl::OUString SAL_CALL
180 ScVbaShape::getName() throw (uno::RuntimeException)
181 {
182     rtl::OUString sName;
183     uno::Reference< container::XNamed > xNamed( m_xShape, uno::UNO_QUERY_THROW );
184     sName = xNamed->getName();
185     return sName;
186 }
187 
188 void SAL_CALL
189 ScVbaShape::setName( const rtl::OUString& _name ) throw (uno::RuntimeException)
190 {
191     uno::Reference< container::XNamed > xNamed( m_xShape, uno::UNO_QUERY_THROW );
192     xNamed->setName( _name );
193 }
194 
195 double SAL_CALL
196 ScVbaShape::getHeight() throw (uno::RuntimeException)
197 {
198     return m_pShapeHelper->getHeight();
199 }
200 
201 void SAL_CALL
202 ScVbaShape::setHeight( double _height ) throw (uno::RuntimeException)
203 {
204     m_pShapeHelper->setHeight( _height );
205 }
206 
207 double SAL_CALL
208 ScVbaShape::getWidth() throw (uno::RuntimeException)
209 {
210     return m_pShapeHelper->getWidth();
211 }
212 
213 void SAL_CALL
214 ScVbaShape::setWidth( double _width ) throw (uno::RuntimeException)
215 {
216     m_pShapeHelper->setWidth( _width );
217 }
218 
219 double SAL_CALL
220 ScVbaShape::getLeft() throw (uno::RuntimeException)
221 {
222     return m_pShapeHelper->getLeft();
223 }
224 
225 void SAL_CALL
226 ScVbaShape::setLeft( double _left ) throw (uno::RuntimeException)
227 {
228     m_pShapeHelper->setLeft( _left );
229 }
230 
231 double SAL_CALL
232 ScVbaShape::getTop() throw (uno::RuntimeException)
233 {
234     return m_pShapeHelper->getTop();
235 }
236 
237 void SAL_CALL
238 ScVbaShape::setTop( double _top ) throw (uno::RuntimeException)
239 {
240     return m_pShapeHelper->setTop( _top );
241 }
242 
243 sal_Bool SAL_CALL
244 ScVbaShape::getVisible() throw (uno::RuntimeException)
245 {
246     //UNO Shapes are always visible
247     return sal_True;
248 }
249 
250 void SAL_CALL
251 ScVbaShape::setVisible( sal_Bool /*_visible*/ ) throw (uno::RuntimeException)
252 {
253     //UNO Shapes are always visible
254 }
255 
256 sal_Int32 SAL_CALL
257 ScVbaShape::getZOrderPosition() throw (uno::RuntimeException)
258 {
259     sal_Int32 nZOrderPosition = 0;
260     uno::Any aZOrderPosition =  m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii( "ZOrder" ) );
261     aZOrderPosition >>= nZOrderPosition;
262     return nZOrderPosition + 1;
263 }
264 
265 sal_Int32 SAL_CALL
266 ScVbaShape::getType() throw (uno::RuntimeException)
267 {
268     return m_nType;
269 }
270 
271 double SAL_CALL
272 ScVbaShape::getRotation() throw (uno::RuntimeException)
273 {
274     double dRotation = 0;
275     sal_Int32 nRotation = 0;
276     m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii( "RotateAngle" ) ) >>= nRotation;
277     dRotation = static_cast< double >( nRotation /100 );
278     return dRotation;
279 }
280 
281 void SAL_CALL
282 ScVbaShape::setRotation( double _rotation ) throw (uno::RuntimeException)
283 {
284     sal_Int32 nRotation = static_cast < sal_Int32 > ( _rotation * 100 );
285     m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "RotateAngle" ), uno::makeAny( nRotation ) );
286 }
287 
288 uno::Reference< msforms::XLineFormat > SAL_CALL
289 ScVbaShape::getLine() throw (uno::RuntimeException)
290 {
291     // TODO should ongly return line
292     return uno::Reference< msforms::XLineFormat >( new ScVbaLineFormat( this, mxContext, m_xShape ) );
293 }
294 
295 uno::Reference< msforms::XFillFormat > SAL_CALL
296 ScVbaShape::getFill() throw (uno::RuntimeException)
297 {
298     return uno::Reference< msforms::XFillFormat >( new ScVbaFillFormat( this, mxContext, m_xShape ) );
299 }
300 
301 uno::Reference<  msforms::XPictureFormat > SAL_CALL
302 ScVbaShape::getPictureFormat() throw (uno::RuntimeException)
303 {
304     return uno::Reference< msforms::XPictureFormat >( new ScVbaPictureFormat( this, mxContext, m_xShape ) );
305 }
306 
307 // Methods
308 uno::Any SAL_CALL
309 ScVbaShape::TextFrame() throw (uno::RuntimeException)
310 {
311     uno::Reference< lang::XServiceInfo > xServiceInfo( m_xModel, uno::UNO_QUERY_THROW );
312     if( xServiceInfo->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadsheetDocument" ) ) ) )
313     {
314         uno::Reference< lang::XMultiServiceFactory > xSF( comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
315         uno::Sequence< uno::Any > aArgs(2);
316         aArgs[0] = uno::makeAny( getParent() );
317         aArgs[1] <<= m_xShape;
318         uno::Reference< uno::XInterface > xTextFrame( xSF->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.TextFrame") ) , aArgs ) , uno::UNO_QUERY_THROW );
319         return uno::makeAny( xTextFrame );
320     }
321 
322     return uno::makeAny( uno::Reference< msforms::XTextFrame >( new VbaTextFrame( this, mxContext, m_xShape ) ) );
323 }
324 
325 void SAL_CALL
326 ScVbaShape::Delete() throw (uno::RuntimeException)
327 {
328     OGuard aGuard( Application::GetSolarMutex() );
329     m_xShapes->remove( m_xShape );
330 }
331 
332 void SAL_CALL
333 ScVbaShape::ZOrder( sal_Int32 ZOrderCmd ) throw (uno::RuntimeException)
334 {
335     sal_Int32 nOrderPositon;
336     uno::Any aOrderPostion = m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii( "ZOrder" ) );
337     aOrderPostion >>= nOrderPositon;
338     switch( ZOrderCmd )
339     {
340     case office::MsoZOrderCmd::msoBringToFront:
341         m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "ZOrder" ), uno::makeAny( SAL_MAX_INT32 ) );
342         break;
343     case office::MsoZOrderCmd::msoSendToBack:
344         m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "ZOrder" ), uno::makeAny( (sal_Int32)0 ) );
345         break;
346     case office::MsoZOrderCmd::msoBringForward:
347         nOrderPositon += 1;
348         m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "ZOrder" ), uno::makeAny( nOrderPositon ) );
349         break;
350     case office::MsoZOrderCmd::msoSendBackward:
351         if( nOrderPositon > 0 )
352         {
353             nOrderPositon -= 1;
354             m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "ZOrder" ), uno::makeAny( nOrderPositon ) );
355         }
356         break;
357     // below two commands use with Writer for text and image object.
358     case office::MsoZOrderCmd::msoBringInFrontOfText:
359     case office::MsoZOrderCmd::msoSendBehindText:
360         throw uno::RuntimeException( rtl::OUString::createFromAscii( "This ZOrderCmd is not implemented, it is use with writer." ), uno::Reference< uno::XInterface >() );
361     default:
362         throw uno::RuntimeException( rtl::OUString::createFromAscii( "Invalid Parameter." ), uno::Reference< uno::XInterface >() );
363     }
364 }
365 
366 void SAL_CALL
367 ScVbaShape::IncrementRotation( double Increment ) throw (uno::RuntimeException)
368 {
369     double nCurrentRotation = getRotation();
370     nCurrentRotation += Increment;
371     setRotation(nCurrentRotation);
372 }
373 
374 void SAL_CALL
375 ScVbaShape::IncrementLeft( double Increment ) throw (uno::RuntimeException)
376 {
377     double nCurrentLeft = getLeft();
378     nCurrentLeft += Increment;
379     setLeft(nCurrentLeft);
380 }
381 
382 void SAL_CALL
383 ScVbaShape::IncrementTop( double Increment ) throw (uno::RuntimeException)
384 {
385     double nCurrentTop = getTop();
386     nCurrentTop += Increment;
387     setTop(nCurrentTop);
388 }
389 
390 void SAL_CALL
391 ScVbaShape::ScaleHeight( double Factor, sal_Bool /*RelativeToOriginalSize*/, sal_Int32 Scale ) throw (uno::RuntimeException)
392 {
393     double nHeight = getHeight();
394     double nNewHeight = nHeight * Factor;
395     if( Scale == office::MsoScaleFrom::msoScaleFromTopLeft )
396     {
397         setHeight(nNewHeight);
398     }
399     else if( Scale == office::MsoScaleFrom::msoScaleFromBottomRight )
400     {
401         double nDeltaHeight = nNewHeight - nHeight;
402         double nNewTop = getTop() - nDeltaHeight;
403         setTop(nNewTop);
404         setHeight(nNewHeight);
405     }
406     else if( Scale == office::MsoScaleFrom::msoScaleFromMiddle )
407     {
408         double nDeltaHeight = (nNewHeight - nHeight) / 2;
409         double nNewTop = getTop() - nDeltaHeight;
410         setTop(nNewTop);
411         setHeight(nNewHeight);
412     }
413     else
414     {
415         throw uno::RuntimeException( rtl::OUString::createFromAscii( "ScaleHeight.Scale wrong value is given." ) , uno::Reference< uno::XInterface >() );
416     }
417 }
418 
419 void SAL_CALL
420 ScVbaShape::ScaleWidth( double Factor, sal_Bool /*RelativeToOriginalSize*/, sal_Int32 Scale ) throw (uno::RuntimeException)
421 {
422     double nWidth = getWidth();
423     double nNewWidth = nWidth * Factor;
424     if( Scale == office::MsoScaleFrom::msoScaleFromTopLeft )
425     {
426         setWidth(nNewWidth);
427     }
428     else if( Scale == office::MsoScaleFrom::msoScaleFromBottomRight )
429     {
430         double nDeltaWidth = nNewWidth - nWidth;
431         double nNewLeft = getLeft() - nDeltaWidth;
432         setLeft(nNewLeft);
433         setWidth(nNewWidth);
434     }
435     else if( Scale == office::MsoScaleFrom::msoScaleFromMiddle )
436     {
437         double nDeltaWidth = (nNewWidth - nWidth) / 2;
438         double nNewLeft = getLeft() - nDeltaWidth;
439         setLeft(nNewLeft);
440         setWidth(nNewWidth);
441     }
442     else
443     {
444         throw uno::RuntimeException( rtl::OUString::createFromAscii( "ScaleHeight.Scale wrong value is given." ) , uno::Reference< uno::XInterface >() );
445     }
446 }
447 
448 void SAL_CALL
449 ScVbaShape::Select( const uno::Any& /*Replace*/ ) throw ( uno::RuntimeException )
450 {
451     uno::Reference< view::XSelectionSupplier > xSelectSupp( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
452     xSelectSupp->select( uno::makeAny( m_xShape ) );
453 }
454 
455 // This method should not be part of Shape, what we reall need to do is...
456 // dynamically create the appropriate objects e.g. TextBox, Oval, Picture etc.
457 // ( e.g. the ones that really do have ShapeRange as an attribute )
458 uno::Any SAL_CALL
459 ScVbaShape::ShapeRange( const uno::Any& index ) throw ( uno::RuntimeException )
460 {
461 	// perhaps we should store a reference to the Shapes Collection
462 	// in this class
463 	// but anyway this method should not even be in this class
464 	// #TODO not sure what the parent of the Shapes collection should be
465 
466 	XNamedObjectCollectionHelper< drawing::XShape >::XNamedVec aVec;
467 	aVec.push_back( m_xShape );
468 	uno::Reference< container::XIndexAccess > xIndexAccess( new XNamedObjectCollectionHelper< drawing::XShape >( aVec ) );
469 	uno::Reference< container::XChild > xChild( m_xShape, uno::UNO_QUERY_THROW );
470 	// #FIXME for want of a better parent, setting this
471 	uno::Reference< msforms::XShapeRange > xShapeRange( new ScVbaShapeRange( mxParent, mxContext, xIndexAccess,  uno::Reference< drawing::XDrawPage >( xChild->getParent(), uno::UNO_QUERY_THROW ), m_xModel ) );
472 	if ( index.hasValue() )
473 		return xShapeRange->Item( index, uno::Any() );
474 	return uno::makeAny( xShapeRange );
475 }
476 
477 sal_Bool SAL_CALL
478 ScVbaShape::getLockAspectRatio() throw (uno::RuntimeException)
479 {
480     // FIXME:
481     return sal_False;
482 }
483 
484 void SAL_CALL
485 ScVbaShape::setLockAspectRatio( sal_Bool /*_lockaspectratio*/ ) throw (uno::RuntimeException)
486 {
487     // FIXME:
488 }
489 
490 sal_Bool SAL_CALL
491 ScVbaShape::getLockAnchor() throw (uno::RuntimeException)
492 {
493     // FIXME:
494     return sal_True;
495 }
496 
497 void SAL_CALL
498 ScVbaShape::setLockAnchor( sal_Bool /*_lockanchor*/ ) throw (uno::RuntimeException)
499 {
500     // FIXME:
501 }
502 
503 sal_Int32 SAL_CALL
504 ScVbaShape::getRelativeHorizontalPosition() throw (uno::RuntimeException)
505 {
506     sal_Int32 nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionMargin;
507     text::TextContentAnchorType eType = text::TextContentAnchorType_AT_PARAGRAPH;
508     m_xPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AnchorType") ) ) >>= eType;
509 
510     switch( eType )
511     {
512         case text::TextContentAnchorType_AT_PARAGRAPH:
513         {
514             nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionColumn;
515             break;
516         }
517         case text::TextContentAnchorType_AT_PAGE:
518         {
519             nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionPage;
520             break;
521         }
522         case text::TextContentAnchorType_AT_CHARACTER:
523         {
524             nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionCharacter;
525             break;
526         }
527         case text::TextContentAnchorType_AT_FRAME:
528         case text::TextContentAnchorType_AS_CHARACTER:
529         {
530             nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionMargin;
531             break;
532         }
533         default:
534         {
535             nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionMargin;
536         }
537     }
538     return nRelativeHorizontalPosition;
539 }
540 
541 void SAL_CALL
542 ScVbaShape::setRelativeHorizontalPosition( ::sal_Int32 _relativehorizontalposition ) throw (uno::RuntimeException)
543 {
544     text::TextContentAnchorType eType = text::TextContentAnchorType_AT_PARAGRAPH;
545     switch( _relativehorizontalposition )
546     {
547         case word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionCharacter:
548         {
549             eType = text::TextContentAnchorType_AT_CHARACTER;
550             break;
551         }
552         case word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionColumn:
553         case word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionMargin:
554         {
555             eType = text::TextContentAnchorType_AT_PARAGRAPH;
556             break;
557         }
558         case word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionPage:
559         {
560             eType = text::TextContentAnchorType_AT_PAGE;
561             break;
562         }
563         default:
564         {
565             DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
566         }
567     }
568     m_xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AnchorType") ), uno::makeAny( eType ) );
569 }
570 
571 sal_Int32 SAL_CALL
572 ScVbaShape::getRelativeVerticalPosition() throw (uno::RuntimeException)
573 {
574     sal_Int32 nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionMargin;
575     text::TextContentAnchorType eType = text::TextContentAnchorType_AT_PARAGRAPH;
576     m_xPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AnchorType") ) ) >>= eType;
577 
578     switch( eType )
579     {
580         case text::TextContentAnchorType_AT_PARAGRAPH:
581         {
582             nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionParagraph;
583             break;
584         }
585         case text::TextContentAnchorType_AT_PAGE:
586         {
587             nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionPage;
588             break;
589         }
590         case text::TextContentAnchorType_AT_CHARACTER:
591         {
592             nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionLine;
593             break;
594         }
595         case text::TextContentAnchorType_AT_FRAME:
596         case text::TextContentAnchorType_AS_CHARACTER:
597         {
598             nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionMargin;
599             break;
600         }
601         default:
602         {
603             nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionMargin;
604         }
605     }
606     return nRelativeVerticalPosition;
607 }
608 
609 void SAL_CALL
610 ScVbaShape::setRelativeVerticalPosition( ::sal_Int32 _relativeverticalposition ) throw (uno::RuntimeException)
611 {
612     text::TextContentAnchorType eType = text::TextContentAnchorType_AT_PARAGRAPH;
613     switch( _relativeverticalposition )
614     {
615         case word::WdRelativeVerticalPosition::wdRelativeVerticalPositionLine:
616         {
617             eType = text::TextContentAnchorType_AT_CHARACTER;
618             break;
619         }
620         case word::WdRelativeVerticalPosition::wdRelativeVerticalPositionParagraph:
621         case word::WdRelativeVerticalPosition::wdRelativeVerticalPositionMargin:
622         {
623             eType = text::TextContentAnchorType_AT_PARAGRAPH;
624             break;
625         }
626         case word::WdRelativeVerticalPosition::wdRelativeVerticalPositionPage:
627         {
628             eType = text::TextContentAnchorType_AT_PAGE;
629             break;
630         }
631         default:
632         {
633             DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
634         }
635     }
636     m_xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AnchorType") ), uno::makeAny( eType ) );
637 }
638 
639 uno::Any SAL_CALL
640 ScVbaShape::WrapFormat() throw (uno::RuntimeException)
641 {
642     uno::Reference< lang::XServiceInfo > xServiceInfo( m_xModel, uno::UNO_QUERY_THROW );
643     if( xServiceInfo->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument" ) ) ) )
644     {
645         uno::Reference< lang::XMultiServiceFactory > xSF( comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
646         uno::Sequence< uno::Any > aArgs(2);
647         aArgs[0] = uno::makeAny( getParent() );
648         aArgs[1] <<= m_xShape;
649         uno::Reference< uno::XInterface > xWrapFormat( xSF->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.WrapFormat") ) , aArgs ) , uno::UNO_QUERY_THROW );
650         return uno::makeAny( xWrapFormat );
651     }
652     throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
653 }
654 
655 
656 rtl::OUString&
657 ScVbaShape::getServiceImplName()
658 {
659 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaShape") );
660 	return sImplName;
661 }
662 
663 uno::Sequence< rtl::OUString >
664 ScVbaShape::getServiceNames()
665 {
666 	static uno::Sequence< rtl::OUString > aServiceNames;
667 	if ( aServiceNames.getLength() == 0 )
668 	{
669 		aServiceNames.realloc( 1 );
670 		aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msform.Shape" ) );
671 	}
672 	return aServiceNames;
673 }
674