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 <com/sun/star/container/XNamed.hpp>
24 #include <com/sun/star/view/XSelectionSupplier.hpp>
25 #include <com/sun/star/text/WrapTextMode.hpp>
26 #include <ooo/vba/msforms/XShapeRange.hpp>
27 #include <ooo/vba/office/MsoAutoShapeType.hpp>
28 #include <ooo/vba/office/MsoTextOrientation.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/text/XText.hpp>
31 #include <com/sun/star/text/XTextDocument.hpp>
32 #include <com/sun/star/text/XTextContent.hpp>
33 #include <com/sun/star/text/TextContentAnchorType.hpp>
34 #include <com/sun/star/text/HoriOrientation.hpp>
35 #include <com/sun/star/text/VertOrientation.hpp>
36 #include <com/sun/star/text/RelOrientation.hpp>
37 #include <com/sun/star/text/SizeType.hpp>
38 #include <com/sun/star/text/WritingMode.hpp>
39 #include <com/sun/star/drawing/LineStyle.hpp>
40
41 #include <vbahelper/vbahelper.hxx>
42 #include <vbahelper/vbashape.hxx>
43 #include <vbahelper/vbashapes.hxx>
44 #include <vbahelper/vbashaperange.hxx>
45
46 using namespace ::ooo::vba;
47 using namespace ::com::sun::star;
48
49 class VbShapeEnumHelper : public EnumerationHelper_BASE
50 {
51 uno::Reference<msforms::XShapes > m_xParent;
52 uno::Reference<container::XIndexAccess > m_xIndexAccess;
53 sal_Int32 nIndex;
54 public:
VbShapeEnumHelper(const uno::Reference<msforms::XShapes> & xParent,const uno::Reference<container::XIndexAccess> & xIndexAccess)55 VbShapeEnumHelper( const uno::Reference< msforms::XShapes >& xParent, const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xParent( xParent ), m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {}
hasMoreElements()56 virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException)
57 {
58 return ( nIndex < m_xIndexAccess->getCount() );
59 }
nextElement()60 virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
61 {
62 ScVbaShapes* pShapes = dynamic_cast< ScVbaShapes* >(m_xParent.get());
63 if ( pShapes && hasMoreElements() )
64 return pShapes->createCollectionObject( m_xIndexAccess->getByIndex( nIndex++ ) );
65 throw container::NoSuchElementException();
66 }
67
68 };
69
initBaseCollection()70 void ScVbaShapes::initBaseCollection()
71 {
72 if ( m_xNameAccess.is() ) // already has NameAccess
73 return;
74 // no NameAccess then use ShapeCollectionHelper
75 XNamedObjectCollectionHelper< drawing::XShape >::XNamedVec mShapes;
76 sal_Int32 nLen = m_xIndexAccess->getCount();
77 mShapes.reserve( nLen );
78 for ( sal_Int32 index=0; index<nLen; ++index )
79 mShapes.push_back( uno::Reference< drawing::XShape >( m_xIndexAccess->getByIndex( index ) , uno::UNO_QUERY ) );
80 uno::Reference< container::XIndexAccess > xShapes( new XNamedObjectCollectionHelper< drawing::XShape >( mShapes ) );
81 m_xIndexAccess.set( xShapes, uno::UNO_QUERY );
82 m_xNameAccess.set( xShapes, uno::UNO_QUERY );
83 }
84
ScVbaShapes(const css::uno::Reference<ov::XHelperInterface> & xParent,const css::uno::Reference<css::uno::XComponentContext> & xContext,const css::uno::Reference<css::container::XIndexAccess> xShapes,const uno::Reference<frame::XModel> & xModel)85 ScVbaShapes::ScVbaShapes( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess > xShapes, const uno::Reference< frame::XModel>& xModel ): ScVbaShapes_BASE( xParent, xContext, xShapes ), m_nNewShapeCount(0), m_xModel( xModel )
86 {
87 m_xShapes.set( xShapes, uno::UNO_QUERY_THROW );
88 m_xDrawPage.set( xShapes, uno::UNO_QUERY_THROW );
89 initBaseCollection();
90 }
91
92 uno::Reference< container::XEnumeration >
createEnumeration()93 ScVbaShapes::createEnumeration() throw (uno::RuntimeException)
94 {
95 return new VbShapeEnumHelper( this, m_xIndexAccess );
96 }
97
98 uno::Any
createCollectionObject(const css::uno::Any & aSource)99 ScVbaShapes::createCollectionObject( const css::uno::Any& aSource ) throw (uno::RuntimeException)
100 {
101 if( aSource.hasValue() )
102 {
103 uno::Reference< drawing::XShape > xShape( aSource, uno::UNO_QUERY_THROW );
104 return uno::makeAny( uno::Reference< msforms::XShape >( new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) ) ) );
105 }
106 return uno::Any();
107 }
108
109 uno::Type
getElementType()110 ScVbaShapes::getElementType() throw (uno::RuntimeException)
111 {
112 return ooo::vba::msforms::XShape::static_type(0);
113 }
114 rtl::OUString&
getServiceImplName()115 ScVbaShapes::getServiceImplName()
116 {
117 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaShapes") );
118 return sImplName;
119 }
120
121 uno::Sequence< rtl::OUString >
getServiceNames()122 ScVbaShapes::getServiceNames()
123 {
124 static uno::Sequence< rtl::OUString > aServiceNames;
125 if ( aServiceNames.getLength() == 0 )
126 {
127 aServiceNames.realloc( 1 );
128 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msform.Shapes" ) );
129 }
130 return aServiceNames;
131 }
132
133 css::uno::Reference< css::container::XIndexAccess >
getShapesByArrayIndices(const uno::Any & Index)134 ScVbaShapes::getShapesByArrayIndices( const uno::Any& Index ) throw (uno::RuntimeException)
135 {
136 if ( Index.getValueTypeClass() != uno::TypeClass_SEQUENCE )
137 throw uno::RuntimeException();
138
139 uno::Reference< script::XTypeConverter > xConverter = getTypeConverter(mxContext);
140 uno::Any aConverted;
141 aConverted = xConverter->convertTo( Index, getCppuType((uno::Sequence< uno::Any >*)0) );
142
143 uno::Sequence< uno::Any > sIndices;
144 aConverted >>= sIndices;
145 XNamedObjectCollectionHelper< drawing::XShape >::XNamedVec mShapes;
146 sal_Int32 nElems = sIndices.getLength();
147 for( sal_Int32 index = 0; index < nElems; ++index )
148 {
149 uno::Reference< drawing::XShape > xShape;
150 if ( sIndices[ index ].getValueTypeClass() == uno::TypeClass_STRING )
151 {
152 rtl::OUString sName;
153 sIndices[ index ] >>= sName;
154 xShape.set( m_xNameAccess->getByName( sName ), uno::UNO_QUERY );
155 }
156 else
157 {
158 sal_Int32 nIndex = 0;
159 sIndices[ index ] >>= nIndex;
160 // adjust for 1 based mso indexing
161 xShape.set( m_xIndexAccess->getByIndex( nIndex - 1 ), uno::UNO_QUERY );
162
163 }
164 // populate map with drawing::XShapes
165 if ( xShape.is() )
166 mShapes.push_back( xShape );
167 }
168 uno::Reference< container::XIndexAccess > xIndexAccess( new XNamedObjectCollectionHelper< drawing::XShape >( mShapes ) );
169 return xIndexAccess;
170 }
171
172 uno::Any SAL_CALL
Item(const uno::Any & Index,const uno::Any & Index2)173 ScVbaShapes::Item( const uno::Any& Index, const uno::Any& Index2 ) throw (uno::RuntimeException)
174 {
175 // I don't think we need to support Array of indices for shapes
176 /*
177 if ( Index.getValueTypeClass() == uno::TypeClass_SEQUENCE )
178 {
179 uno::Reference< container::XIndexAccess > xIndexAccess( getShapesByArrayIndices( Index ) );
180 // return new collection instance
181 uno::Reference< XCollection > xShapesCollection( new ScVbaShapes( this->getParent(), mxContext, xIndexAccess ) );
182 return uno::makeAny( xShapesCollection );
183 }
184 */
185 return ScVbaShapes_BASE::Item( Index, Index2 );
186 }
187
188 uno::Reference< msforms::XShapeRange > SAL_CALL
Range(const uno::Any & shapes)189 ScVbaShapes::Range( const uno::Any& shapes ) throw (css::uno::RuntimeException)
190 {
191 // shapes, can be an index or an array of indices
192 uno::Reference< container::XIndexAccess > xShapes;
193 if ( shapes.getValueTypeClass() == uno::TypeClass_SEQUENCE )
194 xShapes = getShapesByArrayIndices( shapes );
195 else
196 {
197 // wrap single index into a sequence
198 uno::Sequence< uno::Any > sIndices(1);
199 sIndices[ 0 ] = shapes;
200 uno::Any aIndex;
201 aIndex <<= sIndices;
202 xShapes = getShapesByArrayIndices( aIndex );
203 }
204 return new ScVbaShapeRange( getParent(), mxContext, xShapes, m_xDrawPage, m_xModel );
205 }
206
207 void SAL_CALL
SelectAll()208 ScVbaShapes::SelectAll() throw (uno::RuntimeException)
209 {
210 uno::Reference< view::XSelectionSupplier > xSelectSupp( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
211 try
212 {
213 xSelectSupp->select( uno::makeAny( m_xShapes ) );
214 }
215 // viewuno.cxx ScTabViewObj::select will throw IllegalArgumentException
216 // if one of the shapes is no 'markable' e.g. a button
217 // the method still works
218 catch( lang::IllegalArgumentException& )
219 {
220 }
221 }
222
223 uno::Reference< drawing::XShape >
createShape(rtl::OUString service)224 ScVbaShapes::createShape( rtl::OUString service ) throw (css::uno::RuntimeException)
225 {
226 uno::Reference< lang::XMultiServiceFactory > xMSF( m_xModel, uno::UNO_QUERY_THROW );
227 uno::Reference< drawing::XShape > xShape( xMSF->createInstance( service ), uno::UNO_QUERY_THROW );
228 return xShape;
229 }
230
231 uno::Any
AddRectangle(sal_Int32 startX,sal_Int32 startY,sal_Int32 nLineWidth,sal_Int32 nLineHeight,uno::Any aRange)232 ScVbaShapes::AddRectangle( sal_Int32 startX, sal_Int32 startY, sal_Int32 nLineWidth, sal_Int32 nLineHeight, uno::Any aRange ) throw (css::uno::RuntimeException)
233 {
234 rtl::OUString sCreateShapeName( rtl::OUString::createFromAscii( "com.sun.star.drawing.RectangleShape" ) );
235 sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( startX );
236 sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( startY );
237 sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter( nLineWidth );
238 sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( nLineHeight );
239
240 uno::Reference< drawing::XShape > xShape( createShape( sCreateShapeName ), uno::UNO_QUERY_THROW );
241 m_xShapes->add( xShape );
242
243 rtl::OUString sName = createName( rtl::OUString::createFromAscii( "Rectangle" ) );
244 setDefaultShapeProperties( xShape );
245 setShape_NameProperty( xShape, sName );
246
247 awt::Point aMovePositionIfRange(0, 0);
248 awt::Point position;
249 position.X = nXPos - aMovePositionIfRange.X;
250 position.Y = nYPos - aMovePositionIfRange.Y;
251 xShape->setPosition( position );
252
253 awt::Size size;
254 size.Height = nHeight;
255 size.Width = nWidth;
256 xShape->setSize( size );
257
258 ScVbaShape *pScVbaShape = new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) );
259 pScVbaShape->setRange( aRange );
260 return uno::makeAny( uno::Reference< msforms::XShape > ( pScVbaShape ) );
261 }
262
263 uno::Any
AddEllipse(sal_Int32 startX,sal_Int32 startY,sal_Int32 nLineWidth,sal_Int32 nLineHeight,uno::Any aRange)264 ScVbaShapes::AddEllipse( sal_Int32 startX, sal_Int32 startY, sal_Int32 nLineWidth, sal_Int32 nLineHeight, uno::Any aRange ) throw (css::uno::RuntimeException)
265 {
266 rtl::OUString sCreateShapeName( rtl::OUString::createFromAscii( "com.sun.star.drawing.EllipseShape" ) );
267 sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( startX );
268 sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( startY );
269 sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter( nLineWidth );
270 sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( nLineHeight );
271
272 uno::Reference< drawing::XShape > xShape( createShape( sCreateShapeName ), uno::UNO_QUERY_THROW );
273 m_xShapes->add( xShape );
274
275 awt::Point aMovePositionIfRange( 0, 0 );
276 //TODO helperapi using a writer document
277 /*
278 XDocument xDocument = (XDocument)getParent();
279 if (AnyConverter.isVoid(_aRange))
280 {
281 _aRange = xDocument.Range(new Integer(0), new Integer(1));
282 // Top&Left in Word is Top&Left of the paper and not the writeable area.
283 aMovePositionIfRange = calculateTopLeftMargin((HelperInterfaceAdaptor)xDocument);
284 }
285
286 setShape_AnchorTypeAndRangeProperty(xShape, _aRange);
287 */
288 rtl::OUString name = createName( rtl::OUString::createFromAscii( "Oval" ));
289 setDefaultShapeProperties(xShape);
290 setShape_NameProperty(xShape, name);
291
292 awt::Point position;
293 position.X = nXPos - aMovePositionIfRange.X;
294 position.Y = nYPos - aMovePositionIfRange.Y;
295 xShape->setPosition(position);
296
297 awt::Size size;
298 size.Height = nHeight;
299 size.Width = nWidth;
300 xShape->setSize(size);
301
302 ScVbaShape *pScVbaShape = new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) );
303 pScVbaShape->setRange( aRange );
304 return uno::makeAny( uno::Reference< msforms::XShape > ( pScVbaShape ) );
305 }
306
307 //helpeapi calc
308 uno::Any SAL_CALL
AddLine(sal_Int32 StartX,sal_Int32 StartY,sal_Int32 endX,sal_Int32 endY)309 ScVbaShapes::AddLine( sal_Int32 StartX, sal_Int32 StartY, sal_Int32 endX, sal_Int32 endY ) throw (uno::RuntimeException)
310 {
311 sal_Int32 nLineWidth = endX - StartX;
312 sal_Int32 nLineHeight = endY - StartY;
313
314 sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( nLineHeight );
315 sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter( nLineWidth );
316 sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( StartX );
317 sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( StartY );
318
319 uno::Reference< drawing::XShape > xShape( createShape( rtl::OUString::createFromAscii("com.sun.star.drawing.LineShape") ), uno::UNO_QUERY_THROW );
320 m_xShapes->add( xShape );
321
322 awt::Point aMovePositionIfRange( 0, 0 );
323
324 rtl::OUString name = createName( rtl::OUString::createFromAscii( "Line" ) );
325 setDefaultShapeProperties(xShape);
326 setShape_NameProperty(xShape, name);
327
328 awt::Point position;
329 position.X = nXPos - aMovePositionIfRange.X;
330 position.Y = nYPos - aMovePositionIfRange.Y;
331 xShape->setPosition(position);
332
333 awt::Size size;
334 size.Height = nHeight;
335 size.Width = nWidth;
336 xShape->setSize(size);
337
338 ScVbaShape *pScVbaShape = new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) );
339 return uno::makeAny( uno::Reference< msforms::XShape > ( pScVbaShape ) );
340 }
341
342 uno::Any SAL_CALL
AddShape(sal_Int32 _nType,sal_Int32 _nLeft,sal_Int32 _nTop,sal_Int32 _nWidth,sal_Int32 _nHeight)343 ScVbaShapes::AddShape( sal_Int32 _nType, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) throw (uno::RuntimeException)
344 {
345 uno::Any _aAnchor;
346 if (_nType == office::MsoAutoShapeType::msoShapeRectangle)
347 {
348 return AddRectangle(_nLeft, _nTop, _nWidth, _nHeight, _aAnchor);
349 }
350 else if (_nType == office::MsoAutoShapeType::msoShapeOval)
351 {
352 return AddEllipse(_nLeft, _nTop, _nWidth, _nHeight, _aAnchor);
353 }
354 return uno::Any();
355 }
356
357 uno::Any SAL_CALL
AddTextbox(sal_Int32 _nOrientation,sal_Int32 _nLeft,sal_Int32 _nTop,sal_Int32 _nWidth,sal_Int32 _nHeight)358 ScVbaShapes::AddTextbox( sal_Int32 _nOrientation, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) throw (uno::RuntimeException)
359 {
360 uno::Reference< lang::XServiceInfo > xServiceInfo( m_xModel, uno::UNO_QUERY_THROW );
361 if( xServiceInfo->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument" ) ) ) )
362 {
363 return AddTextboxInWriter( _nOrientation, _nLeft, _nTop, _nWidth, _nHeight );
364 }
365 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
366 }
367
368 uno::Any
AddTextboxInWriter(sal_Int32,sal_Int32 _nLeft,sal_Int32 _nTop,sal_Int32 _nWidth,sal_Int32 _nHeight)369 ScVbaShapes::AddTextboxInWriter( sal_Int32 /*_nOrientation*/, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) throw (uno::RuntimeException)
370 {
371 rtl::OUString sCreateShapeName( rtl::OUString::createFromAscii( "com.sun.star.drawing.TextShape" ) );
372 sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( _nLeft );
373 sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( _nTop );
374 sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter( _nWidth );
375 sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( _nHeight );
376
377 uno::Reference< drawing::XShape > xShape( createShape( sCreateShapeName ), uno::UNO_QUERY_THROW );
378 m_xShapes->add( xShape );
379
380 setDefaultShapeProperties(xShape);
381
382 rtl::OUString sName = createName( rtl::OUString::createFromAscii( "Text Box") );
383 setShape_NameProperty( xShape, sName );
384
385 awt::Size size;
386 size.Height = nHeight;
387 size.Width = nWidth;
388 xShape->setSize(size);
389
390 uno::Reference< beans::XPropertySet > xShapeProps( xShape, uno::UNO_QUERY_THROW );
391 xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "AnchorType" ), uno::makeAny( text::TextContentAnchorType_AT_PAGE ) );
392 xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "HoriOrientRelation" ), uno::makeAny( text::RelOrientation::PAGE_LEFT ) );
393 xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "HoriOrient" ), uno::makeAny( text::HoriOrientation::NONE ) );
394 xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "HoriOrientPosition" ), uno::makeAny( nXPos ) );
395
396 xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "VertOrientRelation" ), uno::makeAny( text::RelOrientation::PAGE_FRAME ) );
397 xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "VertOrient" ), uno::makeAny( text::VertOrientation::NONE ) );
398 xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "VertOrientPosition" ), uno::makeAny( nYPos ) );
399
400 // set to visible
401 drawing::LineStyle aLineStyle = drawing::LineStyle_SOLID;
402 xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "LineStyle" ), uno::makeAny( aLineStyle ) );
403 // set to font
404 sal_Int16 nLayerId = 1;
405 rtl::OUString sLayerName = rtl::OUString::createFromAscii("Heaven");
406 xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "LayerID" ), uno::makeAny( nLayerId ) );
407 xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "LayerName" ), uno::makeAny( sLayerName ) );
408
409
410 ScVbaShape *pScVbaShape = new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) );
411 return uno::makeAny( uno::Reference< msforms::XShape > ( pScVbaShape ) );
412 }
413
414 uno::Any
AddShape(const rtl::OUString & sService,const rtl::OUString & sName,sal_Int32 _nLeft,sal_Int32 _nTop,sal_Int32 _nWidth,sal_Int32 _nHeight)415 ScVbaShapes::AddShape( const rtl::OUString& sService, const rtl::OUString& sName, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) throw (uno::RuntimeException)
416 {
417 sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( _nLeft );
418 sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( _nTop );
419 sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter( _nWidth );
420 sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( _nHeight );
421
422 uno::Reference< drawing::XShape > xShape( createShape( sService ), uno::UNO_QUERY_THROW );
423 m_xShapes->add( xShape );
424
425 setDefaultShapeProperties(xShape);
426 setShape_NameProperty( xShape, sName );
427
428 awt::Point aMovePositionIfRange( 0, 0 );
429 awt::Point position;
430 position.X = nXPos - aMovePositionIfRange.X;
431 position.Y = nYPos - aMovePositionIfRange.Y;
432 xShape->setPosition(position);
433
434 awt::Size size;
435 size.Height = nHeight;
436 size.Width = nWidth;
437 xShape->setSize(size);
438
439 ScVbaShape *pScVbaShape = new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) );
440 return uno::makeAny( uno::Reference< msforms::XShape > ( pScVbaShape ) );
441 }
442 void
setDefaultShapeProperties(uno::Reference<drawing::XShape> xShape)443 ScVbaShapes::setDefaultShapeProperties( uno::Reference< drawing::XShape > xShape ) throw (uno::RuntimeException)
444 {
445 uno::Reference< beans::XPropertySet > xPropertySet( xShape, uno::UNO_QUERY_THROW );
446 xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "FillStyle" ), uno::makeAny( rtl::OUString::createFromAscii( "SOLID" ) ) );
447 xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "FillColor"), uno::makeAny( sal_Int32(0xFFFFFF) ) );
448 xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "TextWordWrap"), uno::makeAny( text::WrapTextMode_THROUGHT ) );
449 //not find in OOo2.3
450 //xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "Opaque"), uno::makeAny( sal_True ) );
451 }
452
453 void
setShape_NameProperty(uno::Reference<css::drawing::XShape> xShape,rtl::OUString sName)454 ScVbaShapes::setShape_NameProperty( uno::Reference< css::drawing::XShape > xShape, rtl::OUString sName )
455 {
456 uno::Reference< beans::XPropertySet > xPropertySet( xShape, uno::UNO_QUERY_THROW );
457 try
458 {
459 xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "Name" ), uno::makeAny( sName ) );
460 }
461 catch( script::BasicErrorException e )
462 {
463 }
464 }
465
466 rtl::OUString
createName(rtl::OUString sName)467 ScVbaShapes::createName( rtl::OUString sName )
468 {
469 sal_Int32 nActNumber = 1 + m_nNewShapeCount;
470 m_nNewShapeCount++;
471 sName += rtl::OUString::valueOf( nActNumber );
472 return sName;
473 }
474
475 #if 0
476 //TODO helperapi using a writer document
477 awt::Point
478 calculateTopLeftMargin( uno::Reference< XHelperInterface > xDocument )
479 {
480 awt::Point aPoint( 0, 0 );
481 uno::Reference< frame::XModel > xModel( xDocument, uno::UNO_QUERY_THROW );
482 return awt::Point();
483 }
484 #endif
485