LibreOffice Module vbahelper (master) 1
vbashaperange.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#include <com/sun/star/drawing/ShapeCollection.hpp>
20#include <com/sun/star/drawing/XShapeGrouper.hpp>
21#include <com/sun/star/drawing/XDrawPage.hpp>
22#include <com/sun/star/frame/XModel.hpp>
23#include <com/sun/star/view/XSelectionSupplier.hpp>
24#include <ooo/vba/office/MsoShapeType.hpp>
25
26#include <utility>
29using namespace ::ooo::vba;
30using namespace ::com::sun::star;
31
32namespace {
33
34class VbShapeRangeEnumHelper : public EnumerationHelper_BASE
35{
36 uno::Reference< XCollection > m_xParent;
37 uno::Reference<container::XIndexAccess > m_xIndexAccess;
38 sal_Int32 nIndex;
39public:
40 VbShapeRangeEnumHelper( uno::Reference< XCollection > xParent, uno::Reference< container::XIndexAccess > xIndexAccess ) : m_xParent(std::move( xParent )), m_xIndexAccess(std::move( xIndexAccess )), nIndex( 0 ) {}
41 virtual sal_Bool SAL_CALL hasMoreElements( ) override
42 {
43 return ( nIndex < m_xIndexAccess->getCount() );
44 }
45 virtual uno::Any SAL_CALL nextElement( ) override
46 {
47 ScVbaShapeRange* pCollectionImpl = dynamic_cast< ScVbaShapeRange* >(m_xParent.get());
48 if ( pCollectionImpl && hasMoreElements() )
49 return pCollectionImpl->createCollectionObject( m_xIndexAccess->getByIndex( nIndex++ ) );
50 throw container::NoSuchElementException();
51 }
52
53};
54
55}
56
57ScVbaShapeRange::ScVbaShapeRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xShapes, uno::Reference< drawing::XDrawPage > xDrawPage, uno::Reference< frame::XModel > xModel ) : ScVbaShapeRange_BASE( xParent, xContext, xShapes ), m_xDrawPage(std::move( xDrawPage )), m_xModel(std::move( xModel ))
58{
59}
60
61// Methods
62void SAL_CALL
64{
65 uno::Reference< view::XSelectionSupplier > xSelectSupp( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
66 xSelectSupp->select( uno::Any( getShapes() ) );
67}
68
69uno::Reference< msforms::XShape > SAL_CALL
71{
72 uno::Reference< drawing::XShapeGrouper > xShapeGrouper( m_xDrawPage, uno::UNO_QUERY_THROW );
73 uno::Reference< drawing::XShapeGroup > xShapeGroup( xShapeGrouper->group( getShapes() ), uno::UNO_SET_THROW );
74 uno::Reference< drawing::XShape > xShape( xShapeGroup, uno::UNO_QUERY_THROW );
75 return uno::Reference< msforms::XShape >( new ScVbaShape( getParent(), mxContext, xShape, getShapes(), m_xModel, office::MsoShapeType::msoGroup ) );
76}
77
78uno::Reference< drawing::XShapes > const &
80{
81 if ( !m_xShapes.is() )
82 {
83 m_xShapes.set( drawing::ShapeCollection::create(mxContext) );
84 sal_Int32 nLen = m_xIndexAccess->getCount();
85 for ( sal_Int32 index = 0; index < nLen; ++index )
86 m_xShapes->add( uno::Reference< drawing::XShape >( m_xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW ) );
87
88 }
89 return m_xShapes;
90}
91
92
93void SAL_CALL
95{
96 sal_Int32 nLen = getCount();
97 for ( sal_Int32 index = 1; index <= nLen; ++index )
98 {
99 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
100 xShape->IncrementRotation( Increment );
101 }
102}
103
104void SAL_CALL
106{
107 sal_Int32 nLen = getCount();
108 for ( sal_Int32 index = 1; index <= nLen; ++index )
109 {
110 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
111 xShape->IncrementLeft( Increment );
112 }
113}
114
115void SAL_CALL
117{
118 sal_Int32 nLen = getCount();
119 for ( sal_Int32 index = 1; index <= nLen; ++index )
120 {
121 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
122 xShape->IncrementTop( Increment );
123 }
124}
125
126OUString SAL_CALL ScVbaShapeRange::getName()
127{
128 sal_Int32 nLen = getCount();
129 sal_Int32 index = 1;
130 if (index <= nLen)
131 {
132 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
133 return xShape->getName( );
134 }
135 throw uno::RuntimeException();
136}
137
138void SAL_CALL ScVbaShapeRange::setName( const OUString& _name )
139{
140 sal_Int32 nLen = getCount();
141 for ( sal_Int32 index = 1; index <= nLen; ++index )
142 {
143 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
144 xShape->setName( _name );
145 }
146}
147
149{
150 sal_Int32 nLen = getCount();
151 sal_Int32 index = 1;
152 if (index <= nLen)
153 {
154 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
155 return xShape->getHeight( );
156 }
157 throw uno::RuntimeException();
158}
159
160void SAL_CALL ScVbaShapeRange::setHeight( double _height )
161{
162 sal_Int32 nLen = getCount();
163 for ( sal_Int32 index = 1; index <= nLen; ++index )
164 {
165 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
166 xShape->setHeight( _height );
167 }
168}
169
171{
172 sal_Int32 nLen = getCount();
173 sal_Int32 index = 1;
174 if (index <= nLen)
175 {
176 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
177 return xShape->getWidth( );
178 }
179 throw uno::RuntimeException();
180}
181
182void SAL_CALL ScVbaShapeRange::setWidth( double _width )
183{
184 sal_Int32 nLen = getCount();
185 for ( sal_Int32 index = 1; index <= nLen; ++index )
186 {
187 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
188 xShape->setWidth( _width );
189 }
190}
191
193{
194 sal_Int32 nLen = getCount();
195 sal_Int32 index = 1;
196 if (index <= nLen)
197 {
198 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
199 return xShape->getLeft();
200 }
201 throw uno::RuntimeException();
202}
203
204void SAL_CALL ScVbaShapeRange::setLeft( double _left )
205{
206 sal_Int32 nLen = getCount();
207 for ( sal_Int32 index = 1; index <= nLen; ++index )
208 {
209 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
210 xShape->setLeft( _left );
211 }
212}
213
214double SAL_CALL ScVbaShapeRange::getTop()
215{
216 sal_Int32 nLen = getCount();
217 sal_Int32 index = 1;
218 if (index <= nLen)
219 {
220 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
221 return xShape->getTop();
222 }
223 throw uno::RuntimeException();
224}
225
226void SAL_CALL ScVbaShapeRange::setTop( double _top )
227{
228 sal_Int32 nLen = getCount();
229 for ( sal_Int32 index = 1; index <= nLen; ++index )
230 {
231 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
232 xShape->setTop( _top );
233 }
234}
235
236uno::Reference< ov::msforms::XLineFormat > SAL_CALL ScVbaShapeRange::getLine()
237{
238 sal_Int32 nLen = getCount();
239 sal_Int32 index = 1;
240 if (index <= nLen)
241 {
242 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
243 return xShape->getLine();
244 }
245 throw uno::RuntimeException();
246}
247
248uno::Reference< ov::msforms::XFillFormat > SAL_CALL ScVbaShapeRange::getFill()
249{
250 sal_Int32 nLen = getCount();
251 sal_Int32 index = 1;
252 if (index <= nLen)
253 {
254 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
255 return xShape->getFill();
256 }
257 throw uno::RuntimeException();
258}
259
261{
262 sal_Int32 nLen = getCount();
263 sal_Int32 index = 1;
264 if (index <= nLen)
265 {
266 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
267 return xShape->getLockAspectRatio();
268 }
269 throw uno::RuntimeException();
270}
271
272void SAL_CALL ScVbaShapeRange::setLockAspectRatio( sal_Bool _lockaspectratio )
273{
274 sal_Int32 nLen = getCount();
275 for ( sal_Int32 index = 1; index <= nLen; ++index )
276 {
277 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
278 xShape->setLockAspectRatio( _lockaspectratio );
279 }
280}
281
283{
284 sal_Int32 nLen = getCount();
285 sal_Int32 index = 1;
286 if (index <= nLen)
287 {
288 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
289 return xShape->getLockAnchor();
290 }
291 throw uno::RuntimeException();
292}
293
294void SAL_CALL ScVbaShapeRange::setLockAnchor( sal_Bool _lockanchor )
295{
296 sal_Int32 nLen = getCount();
297 for ( sal_Int32 index = 1; index <= nLen; ++index )
298 {
299 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
300 xShape->setLockAnchor( _lockanchor );
301 }
302}
303
305{
306 sal_Int32 nLen = getCount();
307 sal_Int32 index = 1;
308 if (index <= nLen)
309 {
310 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
311 return xShape->getRelativeHorizontalPosition();
312 }
313 throw uno::RuntimeException();
314}
315
316void SAL_CALL ScVbaShapeRange::setRelativeHorizontalPosition( ::sal_Int32 _relativehorizontalposition )
317{
318 sal_Int32 nLen = getCount();
319 for ( sal_Int32 index = 1; index <= nLen; ++index )
320 {
321 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
322 xShape->setRelativeHorizontalPosition( _relativehorizontalposition );
323 }
324}
325
327{
328 sal_Int32 nLen = getCount();
329 sal_Int32 index = 1;
330 if (index <= nLen)
331 {
332 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
333 return xShape->getRelativeVerticalPosition();
334 }
335 throw uno::RuntimeException();
336}
337
338void SAL_CALL ScVbaShapeRange::setRelativeVerticalPosition( ::sal_Int32 _relativeverticalposition )
339{
340 sal_Int32 nLen = getCount();
341 for ( sal_Int32 index = 1; index <= nLen; ++index )
342 {
343 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
344 xShape->setRelativeVerticalPosition( _relativeverticalposition );
345 }
346}
347
349{
350 sal_Int32 nLen = getCount();
351 sal_Int32 index = 1;
352 if (index <= nLen)
353 {
354 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
355 return xShape->TextFrame();
356 }
357 throw uno::RuntimeException();
358}
359
361{
362 sal_Int32 nLen = getCount();
363 sal_Int32 index = 1;
364 if (index <= nLen)
365 {
366 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
367 return xShape->WrapFormat();
368 }
369 throw uno::RuntimeException();
370}
371
372void SAL_CALL ScVbaShapeRange::ZOrder( sal_Int32 ZOrderCmd )
373{
374 sal_Int32 nLen = getCount();
375 for ( sal_Int32 index = 1; index <= nLen; ++index )
376 {
377 uno::Reference< msforms::XShape > xShape( Item( uno::Any( index ), uno::Any() ), uno::UNO_QUERY_THROW );
378 xShape->ZOrder( ZOrderCmd );
379 }
380}
381
382uno::Type SAL_CALL
384{
386}
387
388uno::Reference< container::XEnumeration > SAL_CALL
390{
391 return new VbShapeRangeEnumHelper( this, m_xIndexAccess );
392}
393
395ScVbaShapeRange:: createCollectionObject( const css::uno::Any& aSource )
396{
397 uno::Reference< drawing::XShape > xShape( aSource, uno::UNO_QUERY_THROW );
398 // #TODO #FIXME Shape parent should always be the sheet the shapes belong
399 // to
400 uno::Reference< msforms::XShape > xVbShape( new ScVbaShape( uno::Reference< XHelperInterface >(), mxContext, xShape, getShapes(), m_xModel, ScVbaShape::getType( xShape ) ) );
401 return uno::Any( xVbShape );
402}
403
404OUString
406{
407 return "ScVbaShapeRange";
408}
409
410uno::Sequence< OUString >
412{
413 static uno::Sequence< OUString > const aServiceNames
414 {
415 "ooo.vba.msform.ShapeRange"
416 };
417 return aServiceNames;
418}
419
420/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent() override
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &Index1, const css::uno::Any &) override
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
virtual ::sal_Int32 SAL_CALL getCount() override
virtual void SAL_CALL IncrementLeft(double Increment) override
virtual void SAL_CALL setRelativeVerticalPosition(::sal_Int32 _relativeverticalposition) override
virtual void SAL_CALL setLeft(double _left) override
virtual void SAL_CALL setWidth(double _width) override
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
virtual void SAL_CALL setLockAspectRatio(sal_Bool _lockaspectratio) override
virtual void SAL_CALL IncrementTop(double Increment) override
css::uno::Reference< css::frame::XModel > m_xModel
virtual void SAL_CALL setRelativeHorizontalPosition(::sal_Int32 _relativehorizontalposition) override
virtual css::uno::Type SAL_CALL getElementType() override
virtual css::uno::Any SAL_CALL WrapFormat() override
virtual OUString SAL_CALL getName() override
virtual double SAL_CALL getHeight() override
virtual OUString getServiceImplName() override
virtual ::sal_Int32 SAL_CALL getRelativeVerticalPosition() override
virtual void SAL_CALL setTop(double _top) override
virtual css::uno::Reference< ov::msforms::XLineFormat > SAL_CALL getLine() override
virtual double SAL_CALL getTop() override
virtual css::uno::Any SAL_CALL TextFrame() override
virtual void SAL_CALL setName(const OUString &_name) override
virtual css::uno::Reference< ov::msforms::XFillFormat > SAL_CALL getFill() override
virtual sal_Bool SAL_CALL getLockAnchor() override
virtual void SAL_CALL setLockAnchor(sal_Bool _lockanchor) override
css::uno::Reference< css::drawing::XDrawPage > m_xDrawPage
virtual double SAL_CALL getWidth() override
virtual void SAL_CALL ZOrder(sal_Int32 ZOrderCmd) override
css::uno::Reference< css::drawing::XShapes > const & getShapes()
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual void SAL_CALL IncrementRotation(double Increment) override
virtual void SAL_CALL setHeight(double _height) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
ScVbaShapeRange(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::container::XIndexAccess > &xShapes, css::uno::Reference< css::drawing::XDrawPage > xDrawShape, css::uno::Reference< css::frame::XModel > xModel)
virtual void SAL_CALL Select() override
virtual double SAL_CALL getLeft() override
virtual sal_Bool SAL_CALL getLockAspectRatio() override
virtual ::sal_Int32 SAL_CALL getRelativeHorizontalPosition() override
css::uno::Reference< css::drawing::XShapes > m_xShapes
virtual css::uno::Reference< ::ooo::vba::msforms::XShape > SAL_CALL Group() override
virtual sal_Int32 SAL_CALL getType() override
Definition: vbashape.cxx:348
css::uno::Type const & get()
Reference< frame::XModel > m_xModel
Sequence< OUString > aServiceNames
sal_Int32 nIndex
index
Reference< XModel > xModel
unsigned char sal_Bool
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE