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/drawing/XShapeGrouper.hpp>
24 #include <com/sun/star/drawing/XDrawPage.hpp>
25 #include<com/sun/star/view/XSelectionSupplier.hpp>
26
27 #include <vbahelper/vbahelper.hxx>
28 #include <vbahelper/vbashaperange.hxx>
29 #include <vbahelper/vbashape.hxx>
30 using namespace ::ooo::vba;
31 using namespace ::com::sun::star;
32
33 class VbShapeRangeEnumHelper : public EnumerationHelper_BASE
34 {
35 uno::Reference< XCollection > m_xParent;
36 uno::Reference<container::XIndexAccess > m_xIndexAccess;
37 sal_Int32 nIndex;
38 public:
VbShapeRangeEnumHelper(const uno::Reference<XCollection> & xParent,const uno::Reference<container::XIndexAccess> & xIndexAccess)39 VbShapeRangeEnumHelper( const uno::Reference< XCollection >& xParent, const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xParent( xParent ), m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {}
hasMoreElements()40 virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException)
41 {
42 return ( nIndex < m_xIndexAccess->getCount() );
43 }
nextElement()44 virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
45 {
46 ScVbaShapeRange* pCollectionImpl = dynamic_cast< ScVbaShapeRange* >(m_xParent.get());
47 if ( pCollectionImpl && hasMoreElements() )
48 return pCollectionImpl->createCollectionObject( m_xIndexAccess->getByIndex( nIndex++ ) );
49 throw container::NoSuchElementException();
50 }
51
52 };
53
ScVbaShapeRange(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<container::XIndexAccess> & xShapes,const uno::Reference<drawing::XDrawPage> & xDrawPage,const uno::Reference<frame::XModel> & xModel)54 ScVbaShapeRange::ScVbaShapeRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xShapes, const uno::Reference< drawing::XDrawPage >& xDrawPage, const uno::Reference< frame::XModel >& xModel ) : ScVbaShapeRange_BASE( xParent, xContext, xShapes ), m_xDrawPage( xDrawPage ), m_nShapeGroupCount(0), m_xModel( xModel )
55 {
56 }
57
58 // Methods
59 void SAL_CALL
Select()60 ScVbaShapeRange::Select( ) throw (uno::RuntimeException)
61 {
62 uno::Reference< view::XSelectionSupplier > xSelectSupp( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
63 xSelectSupp->select( uno::makeAny( getShapes() ) );
64 }
65
66 uno::Reference< msforms::XShape > SAL_CALL
Group()67 ScVbaShapeRange::Group() throw (uno::RuntimeException)
68 {
69 uno::Reference< drawing::XShapeGrouper > xShapeGrouper( m_xDrawPage, uno::UNO_QUERY_THROW );
70 uno::Reference< drawing::XShapeGroup > xShapeGroup( xShapeGrouper->group( getShapes() ), uno::UNO_QUERY_THROW );
71 uno::Reference< drawing::XShape > xShape( xShapeGroup, uno::UNO_QUERY_THROW );
72 return uno::Reference< msforms::XShape >( new ScVbaShape( getParent(), mxContext, xShape, getShapes(), m_xModel, office::MsoShapeType::msoGroup ) );
73 }
74
75 uno::Reference< drawing::XShapes >
getShapes()76 ScVbaShapeRange::getShapes() throw (uno::RuntimeException)
77 {
78 if ( !m_xShapes.is() )
79 {
80 uno::Reference< lang::XMultiServiceFactory > xMSF( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
81 m_xShapes.set( xMSF->createInstance( rtl::OUString::createFromAscii( "com.sun.star.drawing.ShapeCollection" ) ), uno::UNO_QUERY_THROW );
82 sal_Int32 nLen = m_xIndexAccess->getCount();
83 for ( sal_Int32 index = 0; index < nLen; ++index )
84 m_xShapes->add( uno::Reference< drawing::XShape >( m_xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW ) );
85
86 }
87 return m_xShapes;
88 }
89
90
91 void SAL_CALL
IncrementRotation(double Increment)92 ScVbaShapeRange::IncrementRotation( double Increment ) throw (uno::RuntimeException)
93 {
94 sal_Int32 nLen = getCount();
95 for ( sal_Int32 index = 1; index <= nLen; ++index )
96 {
97 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
98 xShape->IncrementRotation( Increment );
99 }
100 }
101
102 void SAL_CALL
IncrementLeft(double Increment)103 ScVbaShapeRange::IncrementLeft( double Increment ) throw (uno::RuntimeException)
104 {
105 sal_Int32 nLen = getCount();
106 for ( sal_Int32 index = 1; index <= nLen; ++index )
107 {
108 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
109 xShape->IncrementLeft( Increment );
110 }
111 }
112
113 void SAL_CALL
IncrementTop(double Increment)114 ScVbaShapeRange::IncrementTop( double Increment ) throw (uno::RuntimeException)
115 {
116 sal_Int32 nLen = getCount();
117 for ( sal_Int32 index = 1; index <= nLen; ++index )
118 {
119 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
120 xShape->IncrementTop( Increment );
121 }
122 }
123
getHeight()124 double SAL_CALL ScVbaShapeRange::getHeight() throw (uno::RuntimeException)
125 {
126 sal_Int32 nLen = getCount();
127 for ( sal_Int32 index = 1; index <= nLen; ++index )
128 {
129 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
130 return xShape->getHeight( );
131 }
132 throw uno::RuntimeException();
133 }
134
setHeight(double _height)135 void SAL_CALL ScVbaShapeRange::setHeight( double _height ) throw (uno::RuntimeException)
136 {
137 sal_Int32 nLen = getCount();
138 for ( sal_Int32 index = 1; index <= nLen; ++index )
139 {
140 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
141 xShape->setHeight( _height );
142 }
143 }
144
getWidth()145 double SAL_CALL ScVbaShapeRange::getWidth() throw (uno::RuntimeException)
146 {
147 sal_Int32 nLen = getCount();
148 for ( sal_Int32 index = 1; index <= nLen; ++index )
149 {
150 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
151 return xShape->getWidth( );
152 }
153 throw uno::RuntimeException();
154 }
155
setWidth(double _width)156 void SAL_CALL ScVbaShapeRange::setWidth( double _width ) throw (uno::RuntimeException)
157 {
158 sal_Int32 nLen = getCount();
159 for ( sal_Int32 index = 1; index <= nLen; ++index )
160 {
161 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
162 xShape->setWidth( _width );
163 }
164 }
165
getLeft()166 double SAL_CALL ScVbaShapeRange::getLeft() throw (uno::RuntimeException)
167 {
168 sal_Int32 nLen = getCount();
169 for ( sal_Int32 index = 1; index <= nLen; ++index )
170 {
171 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
172 return xShape->getLeft();
173 }
174 throw uno::RuntimeException();
175 }
176
setLeft(double _left)177 void SAL_CALL ScVbaShapeRange::setLeft( double _left ) throw (uno::RuntimeException)
178 {
179 sal_Int32 nLen = getCount();
180 for ( sal_Int32 index = 1; index <= nLen; ++index )
181 {
182 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
183 xShape->setLeft( _left );
184 }
185 }
186
getTop()187 double SAL_CALL ScVbaShapeRange::getTop() throw (uno::RuntimeException)
188 {
189 sal_Int32 nLen = getCount();
190 for ( sal_Int32 index = 1; index <= nLen; ++index )
191 {
192 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
193 return xShape->getTop();
194 }
195 throw uno::RuntimeException();
196 }
197
setTop(double _top)198 void SAL_CALL ScVbaShapeRange::setTop( double _top ) throw (uno::RuntimeException)
199 {
200 sal_Int32 nLen = getCount();
201 for ( sal_Int32 index = 1; index <= nLen; ++index )
202 {
203 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
204 xShape->setTop( _top );
205 }
206 }
207
getLine()208 uno::Reference< ov::msforms::XLineFormat > SAL_CALL ScVbaShapeRange::getLine() throw (css::uno::RuntimeException)
209 {
210 sal_Int32 nLen = getCount();
211 for ( sal_Int32 index = 1; index <= nLen; ++index )
212 {
213 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
214 return xShape->getLine();
215 }
216 throw uno::RuntimeException();
217 }
218
getFill()219 uno::Reference< ov::msforms::XFillFormat > SAL_CALL ScVbaShapeRange::getFill() throw (css::uno::RuntimeException)
220 {
221 sal_Int32 nLen = getCount();
222 for ( sal_Int32 index = 1; index <= nLen; ++index )
223 {
224 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
225 return xShape->getFill();
226 }
227 throw uno::RuntimeException();
228 }
229
getLockAspectRatio()230 ::sal_Bool SAL_CALL ScVbaShapeRange::getLockAspectRatio() throw (uno::RuntimeException)
231 {
232 sal_Int32 nLen = getCount();
233 for ( sal_Int32 index = 1; index <= nLen; ++index )
234 {
235 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
236 return xShape->getLockAspectRatio();
237 }
238 throw uno::RuntimeException();
239 }
240
setLockAspectRatio(::sal_Bool _lockaspectratio)241 void SAL_CALL ScVbaShapeRange::setLockAspectRatio( ::sal_Bool _lockaspectratio ) throw (uno::RuntimeException)
242 {
243 sal_Int32 nLen = getCount();
244 for ( sal_Int32 index = 1; index <= nLen; ++index )
245 {
246 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
247 xShape->setLockAspectRatio( _lockaspectratio );
248 }
249 }
250
getLockAnchor()251 ::sal_Bool SAL_CALL ScVbaShapeRange::getLockAnchor() throw (uno::RuntimeException)
252 {
253 sal_Int32 nLen = getCount();
254 for ( sal_Int32 index = 1; index <= nLen; ++index )
255 {
256 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
257 return xShape->getLockAnchor();
258 }
259 throw uno::RuntimeException();
260 }
261
setLockAnchor(::sal_Bool _lockanchor)262 void SAL_CALL ScVbaShapeRange::setLockAnchor( ::sal_Bool _lockanchor ) throw (uno::RuntimeException)
263 {
264 sal_Int32 nLen = getCount();
265 for ( sal_Int32 index = 1; index <= nLen; ++index )
266 {
267 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
268 xShape->setLockAnchor( _lockanchor );
269 }
270 }
271
getRelativeHorizontalPosition()272 ::sal_Int32 SAL_CALL ScVbaShapeRange::getRelativeHorizontalPosition() throw (uno::RuntimeException)
273 {
274 sal_Int32 nLen = getCount();
275 for ( sal_Int32 index = 1; index <= nLen; ++index )
276 {
277 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
278 return xShape->getRelativeHorizontalPosition();
279 }
280 throw uno::RuntimeException();
281 }
282
setRelativeHorizontalPosition(::sal_Int32 _relativehorizontalposition)283 void SAL_CALL ScVbaShapeRange::setRelativeHorizontalPosition( ::sal_Int32 _relativehorizontalposition ) throw (uno::RuntimeException)
284 {
285 sal_Int32 nLen = getCount();
286 for ( sal_Int32 index = 1; index <= nLen; ++index )
287 {
288 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
289 xShape->setRelativeHorizontalPosition( _relativehorizontalposition );
290 }
291 }
292
getRelativeVerticalPosition()293 ::sal_Int32 SAL_CALL ScVbaShapeRange::getRelativeVerticalPosition() throw (uno::RuntimeException)
294 {
295 sal_Int32 nLen = getCount();
296 for ( sal_Int32 index = 1; index <= nLen; ++index )
297 {
298 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
299 return xShape->getRelativeVerticalPosition();
300 }
301 throw uno::RuntimeException();
302 }
303
setRelativeVerticalPosition(::sal_Int32 _relativeverticalposition)304 void SAL_CALL ScVbaShapeRange::setRelativeVerticalPosition( ::sal_Int32 _relativeverticalposition ) throw (uno::RuntimeException)
305 {
306 sal_Int32 nLen = getCount();
307 for ( sal_Int32 index = 1; index <= nLen; ++index )
308 {
309 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
310 xShape->setRelativeVerticalPosition( _relativeverticalposition );
311 }
312 }
313
TextFrame()314 uno::Any SAL_CALL ScVbaShapeRange::TextFrame( ) throw (css::uno::RuntimeException)
315 {
316 sal_Int32 nLen = getCount();
317 for ( sal_Int32 index = 1; index <= nLen; ++index )
318 {
319 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
320 return xShape->TextFrame();
321 }
322 throw uno::RuntimeException();
323 }
324
WrapFormat()325 uno::Any SAL_CALL ScVbaShapeRange::WrapFormat( ) throw (css::uno::RuntimeException)
326 {
327 sal_Int32 nLen = getCount();
328 for ( sal_Int32 index = 1; index <= nLen; ++index )
329 {
330 uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
331 return xShape->WrapFormat();
332 }
333 throw uno::RuntimeException();
334 }
335
336 uno::Type SAL_CALL
getElementType()337 ScVbaShapeRange::getElementType() throw (uno::RuntimeException)
338 {
339 return msforms::XShape::static_type(0);
340 }
341
342 uno::Reference< container::XEnumeration > SAL_CALL
createEnumeration()343 ScVbaShapeRange::createEnumeration() throw (uno::RuntimeException)
344 {
345 return new VbShapeRangeEnumHelper( this, m_xIndexAccess );
346 }
347
348 uno::Any
createCollectionObject(const css::uno::Any & aSource)349 ScVbaShapeRange:: createCollectionObject( const css::uno::Any& aSource )
350 {
351 uno::Reference< drawing::XShape > xShape( aSource, uno::UNO_QUERY_THROW );
352 // #TODO #FIXME Shape parent should always be the sheet the shapes belong
353 // to
354 uno::Reference< msforms::XShape > xVbShape( new ScVbaShape( uno::Reference< XHelperInterface >(), mxContext, xShape, getShapes(), m_xModel, ScVbaShape::getType( xShape ) ) );
355 return uno::makeAny( xVbShape );
356 }
357
358 rtl::OUString&
getServiceImplName()359 ScVbaShapeRange::getServiceImplName()
360 {
361 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaShapeRange") );
362 return sImplName;
363 }
364
365 uno::Sequence< rtl::OUString >
getServiceNames()366 ScVbaShapeRange::getServiceNames()
367 {
368 static uno::Sequence< rtl::OUString > aServiceNames;
369 if ( aServiceNames.getLength() == 0 )
370 {
371 aServiceNames.realloc( 1 );
372 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msform.ShapeRange" ) );
373 }
374 return aServiceNames;
375 }
376