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