Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "vbasheetobjects.hxx"
30 : : #include <vector>
31 : : #include <rtl/math.hxx>
32 : : #include <com/sun/star/beans/XPropertySet.hpp>
33 : : #include <com/sun/star/container/XIndexContainer.hpp>
34 : : #include <com/sun/star/container/XNamed.hpp>
35 : : #include <com/sun/star/drawing/XControlShape.hpp>
36 : : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
37 : : #include <com/sun/star/drawing/XShapes.hpp>
38 : : #include <com/sun/star/form/FormComponentType.hpp>
39 : : #include <com/sun/star/form/XForm.hpp>
40 : : #include <com/sun/star/form/XFormComponent.hpp>
41 : : #include <com/sun/star/form/XFormsSupplier.hpp>
42 : : #include <oox/helper/helper.hxx>
43 : : #include "vbasheetobject.hxx"
44 : :
45 : : using ::rtl::OUString;
46 : : using namespace ::com::sun::star;
47 : : using namespace ::ooo::vba;
48 : :
49 : : // ============================================================================
50 : :
51 : : namespace {
52 : :
53 : : template< typename Type >
54 : 0 : inline bool lclGetProperty( Type& orValue, const uno::Reference< beans::XPropertySet >& rxPropSet, const OUString& rPropName )
55 : : {
56 : : try
57 : : {
58 [ # # ][ # # ]: 0 : return rxPropSet->getPropertyValue( rPropName ) >>= orValue;
[ # # ][ # # ]
[ # # ][ # # ]
59 : : }
60 : 0 : catch( uno::Exception& )
61 : : {
62 : : }
63 : 0 : return false;
64 : : }
65 : :
66 : : /** Rounds the passed value to a multiple of 0.75 and converts it to 1/100 mm. */
67 : 0 : inline double lclPointsToHmm( const uno::Any& rPoints ) throw (uno::RuntimeException)
68 : : {
69 : 0 : return PointsToHmm( ::rtl::math::approxFloor( rPoints.get< double >() / 0.75 ) * 0.75 );
70 : : }
71 : :
72 : : } // namespace
73 : :
74 : : // ============================================================================
75 : : // Base implementations
76 : : // ============================================================================
77 : :
78 : : /** Container for a specific type of drawing object in a spreadsheet.
79 : :
80 : : Derived classes provide all required functionality specific to the type of
81 : : shapes covered by the container.
82 : : */
83 [ # # ]: 0 : class ScVbaObjectContainer : public ::cppu::WeakImplHelper1< container::XIndexAccess >
84 : : {
85 : : public:
86 : : explicit ScVbaObjectContainer(
87 : : const uno::Reference< XHelperInterface >& rxParent,
88 : : const uno::Reference< uno::XComponentContext >& rxContext,
89 : : const uno::Reference< frame::XModel >& rxModel,
90 : : const uno::Reference< sheet::XSpreadsheet >& rxSheet,
91 : : const uno::Type& rVbaType ) throw (uno::RuntimeException);
92 : :
93 : : /** Returns the VBA helper interface of the VBA collection object. */
94 : 0 : inline const uno::Reference< XHelperInterface >& getParent() const { return mxParent; }
95 : : /** Returns the component context of the VBA collection object. */
96 : 0 : inline const uno::Reference< uno::XComponentContext >& getContext() const { return mxContext; }
97 : : /** Returns the VBA type information of the objects in this container. */
98 : 0 : inline const uno::Type& getVbaType() const { return maVbaType; }
99 : :
100 : : /** Collects all shapes supported by this instance and inserts them into
101 : : the internal shape vector. */
102 : : void collectShapes() throw (uno::RuntimeException);
103 : : /** Creates and returns a new UNO shape. */
104 : : uno::Reference< drawing::XShape > createShape( const awt::Point& rPos, const awt::Size& rSize ) throw (uno::RuntimeException);
105 : : /** Inserts the passed shape into the draw page and into this container, and returns its index in the draw page. */
106 : : sal_Int32 insertShape( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException);
107 : : /** Creates and returns a new VBA implementation object for the passed shape. */
108 : : ::rtl::Reference< ScVbaSheetObjectBase > createVbaObject( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException);
109 : : /** Creates and returns a new VBA implementation object for the passed shape in an Any. */
110 : : uno::Any createCollectionObject( const uno::Any& rSource ) throw (uno::RuntimeException);
111 : : /** Returns the VBA implementation object with the specified name. */
112 : : uno::Any getItemByStringIndex( const OUString& rIndex ) throw (uno::RuntimeException);
113 : :
114 : : // XIndexAccess
115 : : virtual sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException);
116 : : virtual uno::Any SAL_CALL getByIndex( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException);
117 : :
118 : : // XElementAccess
119 : : virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException);
120 : : virtual sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException);
121 : :
122 : : protected:
123 : : /** Derived classes return true, if the passed shape is supported by the instance. */
124 : : virtual bool implPickShape( const uno::Reference< drawing::XShape >& rxShape ) const = 0;
125 : : /** Derived classes create and return a new VBA implementation object for the passed shape. */
126 : : virtual ScVbaSheetObjectBase* implCreateVbaObject( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException) = 0;
127 : : /** Derived classes return the service name of the UNO shape. */
128 : : virtual OUString implGetShapeServiceName() const = 0;
129 : :
130 : : /** Returns the shape name via 'Name' property of the UNO shape. May be overwritten. */
131 : : virtual OUString implGetShapeName( const uno::Reference< drawing::XShape >& rxShape ) const throw (uno::RuntimeException);
132 : : /** Is called when a new UNO shape has been created but not yet inserted into the drawing page. */
133 : : virtual void implOnShapeCreated( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException);
134 : :
135 : : protected:
136 : : uno::Reference< XHelperInterface > mxParent;
137 : : uno::Reference< uno::XComponentContext > mxContext;
138 : : uno::Reference< frame::XModel > mxModel;
139 : : uno::Reference< lang::XMultiServiceFactory > mxFactory;
140 : : uno::Reference< drawing::XShapes > mxShapes;
141 : :
142 : : private:
143 : : typedef ::std::vector< uno::Reference< drawing::XShape > > ShapeVector;
144 : : const uno::Type maVbaType;
145 : : ShapeVector maShapes;
146 : : };
147 : :
148 : : // ----------------------------------------------------------------------------
149 : :
150 : 0 : ScVbaObjectContainer::ScVbaObjectContainer(
151 : : const uno::Reference< XHelperInterface >& rxParent,
152 : : const uno::Reference< uno::XComponentContext >& rxContext,
153 : : const uno::Reference< frame::XModel >& rxModel,
154 : : const uno::Reference< sheet::XSpreadsheet >& rxSheet,
155 : : const uno::Type& rVbaType ) throw (uno::RuntimeException) :
156 : : mxParent( rxParent ),
157 : : mxContext( rxContext ),
158 : : mxModel( rxModel, uno::UNO_SET_THROW ),
159 : : mxFactory( rxModel, uno::UNO_QUERY_THROW ),
160 [ # # ][ # # ]: 0 : maVbaType( rVbaType )
[ # # ]
161 : : {
162 [ # # ]: 0 : uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupp( rxSheet, uno::UNO_QUERY_THROW );
163 [ # # ][ # # ]: 0 : mxShapes.set( xDrawPageSupp->getDrawPage(), uno::UNO_QUERY_THROW );
[ # # ]
164 : 0 : }
165 : :
166 : 0 : void ScVbaObjectContainer::collectShapes() throw (uno::RuntimeException)
167 : : {
168 : 0 : maShapes.clear();
169 [ # # ]: 0 : for( sal_Int32 nIndex = 0, nCount = mxShapes->getCount(); nIndex < nCount; ++nIndex )
170 : : {
171 [ # # ][ # # ]: 0 : uno::Reference< drawing::XShape > xShape( mxShapes->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
[ # # ]
172 [ # # ][ # # ]: 0 : if( implPickShape( xShape ) )
173 [ # # ]: 0 : maShapes.push_back( xShape );
174 : 0 : }
175 : 0 : }
176 : :
177 : 0 : uno::Reference< drawing::XShape > ScVbaObjectContainer::createShape( const awt::Point& rPos, const awt::Size& rSize ) throw (uno::RuntimeException)
178 : : {
179 [ # # ][ # # ]: 0 : uno::Reference< drawing::XShape > xShape( mxFactory->createInstance( implGetShapeServiceName() ), uno::UNO_QUERY_THROW );
180 [ # # ][ # # ]: 0 : xShape->setPosition( rPos );
181 [ # # ][ # # ]: 0 : xShape->setSize( rSize );
182 [ # # ]: 0 : implOnShapeCreated( xShape );
183 : 0 : return xShape;
184 : : }
185 : :
186 : 0 : sal_Int32 ScVbaObjectContainer::insertShape( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException)
187 : : {
188 : 0 : mxShapes->add( rxShape );
189 : 0 : maShapes.push_back( rxShape );
190 : 0 : return mxShapes->getCount() - 1;
191 : : }
192 : :
193 : 0 : ::rtl::Reference< ScVbaSheetObjectBase > ScVbaObjectContainer::createVbaObject(
194 : : const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException)
195 : : {
196 : 0 : return implCreateVbaObject( rxShape );
197 : : }
198 : :
199 : 0 : uno::Any ScVbaObjectContainer::createCollectionObject( const uno::Any& rSource ) throw (uno::RuntimeException)
200 : : {
201 [ # # ]: 0 : uno::Reference< drawing::XShape > xShape( rSource, uno::UNO_QUERY_THROW );
202 [ # # ][ # # ]: 0 : uno::Reference< excel::XSheetObject > xSheetObject( implCreateVbaObject( xShape ) );
[ # # ]
203 [ # # ]: 0 : return uno::Any( xSheetObject );
204 : : }
205 : :
206 : 0 : uno::Any ScVbaObjectContainer::getItemByStringIndex( const OUString& rIndex ) throw (uno::RuntimeException)
207 : : {
208 [ # # ][ # # ]: 0 : for( ShapeVector::iterator aIt = maShapes.begin(), aEnd = maShapes.end(); aIt != aEnd; ++aIt )
209 [ # # ][ # # ]: 0 : if( rIndex == implGetShapeName( *aIt ) )
210 [ # # ][ # # ]: 0 : return createCollectionObject( uno::Any( *aIt ) );
211 [ # # ]: 0 : throw uno::RuntimeException();
212 : : }
213 : :
214 : : // XIndexAccess
215 : :
216 : 0 : sal_Int32 SAL_CALL ScVbaObjectContainer::getCount() throw (uno::RuntimeException)
217 : : {
218 : 0 : return static_cast< sal_Int32 >( maShapes.size() );
219 : : }
220 : :
221 : 0 : uno::Any SAL_CALL ScVbaObjectContainer::getByIndex( sal_Int32 nIndex )
222 : : throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
223 : : {
224 [ # # ][ # # ]: 0 : if( (0 <= nIndex) && (nIndex < getCount()) )
[ # # ]
225 : 0 : return uno::Any( maShapes[ static_cast< size_t >( nIndex ) ] );
226 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
227 : : }
228 : :
229 : : // XElementAccess
230 : :
231 : 0 : uno::Type SAL_CALL ScVbaObjectContainer::getElementType() throw (uno::RuntimeException)
232 : : {
233 : 0 : return drawing::XShape::static_type( 0 );
234 : : }
235 : :
236 : 0 : sal_Bool SAL_CALL ScVbaObjectContainer::hasElements() throw (uno::RuntimeException)
237 : : {
238 : 0 : return !maShapes.empty();
239 : : }
240 : :
241 : : // private
242 : :
243 : 0 : OUString ScVbaObjectContainer::implGetShapeName( const uno::Reference< drawing::XShape >& rxShape ) const throw (uno::RuntimeException)
244 : : {
245 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xPropSet( rxShape, uno::UNO_QUERY_THROW );
246 [ # # ][ # # ]: 0 : return xPropSet->getPropertyValue( CREATE_OUSTRING( "Name" ) ).get< OUString >();
[ # # ][ # # ]
247 : : }
248 : :
249 : 0 : void ScVbaObjectContainer::implOnShapeCreated( const uno::Reference< drawing::XShape >& /*rxShape*/ ) throw (uno::RuntimeException)
250 : : {
251 : 0 : }
252 : :
253 : : // ============================================================================
254 : :
255 [ # # ]: 0 : class ScVbaObjectEnumeration : public SimpleEnumerationBase
256 : : {
257 : : public:
258 : : explicit ScVbaObjectEnumeration( const ScVbaObjectContainerRef& rxContainer );
259 : : virtual uno::Any createCollectionObject( const uno::Any& rSource );
260 : :
261 : : private:
262 : : ScVbaObjectContainerRef mxContainer;
263 : : };
264 : :
265 : : // ----------------------------------------------------------------------------
266 : :
267 : 0 : ScVbaObjectEnumeration::ScVbaObjectEnumeration( const ScVbaObjectContainerRef& rxContainer ) :
268 : 0 : SimpleEnumerationBase( rxContainer->getParent(), rxContainer->getContext(), rxContainer.get() ),
269 [ # # ][ # # ]: 0 : mxContainer( rxContainer )
270 : : {
271 : 0 : }
272 : :
273 : 0 : uno::Any ScVbaObjectEnumeration::createCollectionObject( const uno::Any& rSource )
274 : : {
275 : 0 : return mxContainer->createCollectionObject( rSource );
276 : : }
277 : :
278 : : // ============================================================================
279 : :
280 : 0 : ScVbaSheetObjectsBase::ScVbaSheetObjectsBase( const ScVbaObjectContainerRef& rxContainer ) throw (css::uno::RuntimeException) :
281 : 0 : ScVbaSheetObjects_BASE( rxContainer->getParent(), rxContainer->getContext(), rxContainer.get() ),
282 [ # # ][ # # ]: 0 : mxContainer( rxContainer )
283 : : {
284 [ # # ]: 0 : mxContainer->collectShapes();
285 : 0 : }
286 : :
287 : 0 : ScVbaSheetObjectsBase::~ScVbaSheetObjectsBase()
288 : : {
289 [ # # ]: 0 : }
290 : :
291 : 0 : void ScVbaSheetObjectsBase::collectShapes() throw (uno::RuntimeException)
292 : : {
293 : 0 : mxContainer->collectShapes();
294 : 0 : }
295 : :
296 : : // XEnumerationAccess
297 : :
298 : 0 : uno::Reference< container::XEnumeration > SAL_CALL ScVbaSheetObjectsBase::createEnumeration() throw (uno::RuntimeException)
299 : : {
300 [ # # ][ # # ]: 0 : return new ScVbaObjectEnumeration( mxContainer );
301 : : }
302 : :
303 : : // XElementAccess
304 : :
305 : 0 : uno::Type SAL_CALL ScVbaSheetObjectsBase::getElementType() throw (uno::RuntimeException)
306 : : {
307 : 0 : return mxContainer->getVbaType();
308 : : }
309 : :
310 : : // ScVbaCollectionBase
311 : :
312 : 0 : uno::Any ScVbaSheetObjectsBase::createCollectionObject( const uno::Any& rSource )
313 : : {
314 : 0 : return mxContainer->createCollectionObject( rSource );
315 : : }
316 : :
317 : 0 : uno::Any ScVbaSheetObjectsBase::getItemByStringIndex( const OUString& rIndex ) throw (uno::RuntimeException)
318 : : {
319 : 0 : return mxContainer->getItemByStringIndex( rIndex );
320 : : }
321 : :
322 : : // ============================================================================
323 : : // Graphic object containers supporting ooo.vba.excel.XGraphicObject
324 : : // ============================================================================
325 : :
326 : 0 : ScVbaGraphicObjectsBase::ScVbaGraphicObjectsBase( const ScVbaObjectContainerRef& rxContainer ) throw (uno::RuntimeException) :
327 : 0 : ScVbaGraphicObjects_BASE( rxContainer )
328 : : {
329 : 0 : }
330 : :
331 : : // XGraphicObjects
332 : :
333 : 0 : uno::Any SAL_CALL ScVbaGraphicObjectsBase::Add( const uno::Any& rLeft, const uno::Any& rTop, const uno::Any& rWidth, const uno::Any& rHeight ) throw (uno::RuntimeException)
334 : : {
335 : : /* Extract double values from passed Anys (the lclPointsToHmm() helper
336 : : function will throw a RuntimeException on any error), and convert from
337 : : points to 1/100 mm. */
338 [ # # ][ # # ]: 0 : awt::Point aPos( static_cast<sal_Int32>(lclPointsToHmm( rLeft )), static_cast<sal_Int32>(lclPointsToHmm( rTop )) );
339 [ # # ][ # # ]: 0 : awt::Size aSize( static_cast<sal_Int32>(lclPointsToHmm( rWidth )), static_cast<sal_Int32>(lclPointsToHmm( rHeight )) );
340 : : // TODO: translate coordinates for RTL sheets
341 [ # # ][ # # ]: 0 : if( (aPos.X < 0) || (aPos.Y < 0) || (aSize.Width <= 0) || (aSize.Height <= 0) )
[ # # ][ # # ]
342 [ # # ]: 0 : throw uno::RuntimeException();
343 : :
344 : : // create the UNO shape
345 [ # # ][ # # ]: 0 : uno::Reference< drawing::XShape > xShape( mxContainer->createShape( aPos, aSize ), uno::UNO_SET_THROW );
346 [ # # ]: 0 : sal_Int32 nIndex = mxContainer->insertShape( xShape );
347 : :
348 : : // create and return the VBA object
349 [ # # ]: 0 : ::rtl::Reference< ScVbaSheetObjectBase > xVbaObject = mxContainer->createVbaObject( xShape );
350 [ # # ]: 0 : xVbaObject->setDefaultProperties( nIndex );
351 [ # # ][ # # ]: 0 : return uno::Any( uno::Reference< excel::XSheetObject >( xVbaObject.get() ) );
[ # # ]
352 : : }
353 : :
354 : : // ============================================================================
355 : : // Drawing controls
356 : : // ============================================================================
357 : :
358 [ # # ]: 0 : class ScVbaControlContainer : public ScVbaObjectContainer
359 : : {
360 : : public:
361 : : explicit ScVbaControlContainer(
362 : : const uno::Reference< XHelperInterface >& rxParent,
363 : : const uno::Reference< uno::XComponentContext >& rxContext,
364 : : const uno::Reference< frame::XModel >& rxModel,
365 : : const uno::Reference< sheet::XSpreadsheet >& rxSheet,
366 : : const uno::Type& rVbaType,
367 : : const OUString& rModelServiceName,
368 : : sal_Int16 nComponentType ) throw (uno::RuntimeException);
369 : :
370 : : protected:
371 : : uno::Reference< container::XIndexContainer > createForm() throw (uno::RuntimeException);
372 : :
373 : : virtual bool implPickShape( const uno::Reference< drawing::XShape >& rxShape ) const;
374 : : virtual OUString implGetShapeServiceName() const;
375 : : virtual bool implCheckProperties( const uno::Reference< beans::XPropertySet >& rxModelProps ) const;
376 : : virtual OUString implGetShapeName( const uno::Reference< drawing::XShape >& rxShape ) const throw (uno::RuntimeException);
377 : : virtual void implOnShapeCreated( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException);
378 : :
379 : : protected:
380 : : uno::Reference< container::XIndexContainer > mxFormIC;
381 : : OUString maModelServiceName;
382 : : sal_Int16 mnComponentType;
383 : : };
384 : :
385 : : // ----------------------------------------------------------------------------
386 : :
387 : 0 : ScVbaControlContainer::ScVbaControlContainer(
388 : : const uno::Reference< XHelperInterface >& rxParent,
389 : : const uno::Reference< uno::XComponentContext >& rxContext,
390 : : const uno::Reference< frame::XModel >& rxModel,
391 : : const uno::Reference< sheet::XSpreadsheet >& rxSheet,
392 : : const uno::Type& rVbaType,
393 : : const OUString& rModelServiceName,
394 : : sal_Int16 nComponentType ) throw (uno::RuntimeException) :
395 : : ScVbaObjectContainer( rxParent, rxContext, rxModel, rxSheet, rVbaType ),
396 : : maModelServiceName( rModelServiceName ),
397 : 0 : mnComponentType( nComponentType )
398 : : {
399 : 0 : }
400 : :
401 : 0 : uno::Reference< container::XIndexContainer > ScVbaControlContainer::createForm() throw (uno::RuntimeException)
402 : : {
403 [ # # ]: 0 : if( !mxFormIC.is() )
404 : : {
405 [ # # ]: 0 : uno::Reference< form::XFormsSupplier > xFormsSupp( mxShapes, uno::UNO_QUERY_THROW );
406 [ # # ][ # # ]: 0 : uno::Reference< container::XNameContainer > xFormsNC( xFormsSupp->getForms(), uno::UNO_SET_THROW );
[ # # ]
407 [ # # ]: 0 : OUString aFormName = CREATE_OUSTRING( "Standard" );
408 [ # # ][ # # ]: 0 : if( xFormsNC->hasByName( aFormName ) )
[ # # ]
409 : : {
410 [ # # ][ # # ]: 0 : mxFormIC.set( xFormsNC->getByName( aFormName ), uno::UNO_QUERY_THROW );
[ # # ]
411 : : }
412 : : else
413 : : {
414 [ # # ][ # # ]: 0 : uno::Reference< form::XForm > xForm( mxFactory->createInstance( CREATE_OUSTRING( "com.sun.star.form.component.Form" ) ), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
415 [ # # ][ # # ]: 0 : xFormsNC->insertByName( aFormName, uno::Any( xForm ) );
[ # # ]
416 [ # # ]: 0 : mxFormIC.set( xForm, uno::UNO_QUERY_THROW );
417 : 0 : }
418 : : }
419 : 0 : return mxFormIC;
420 : : }
421 : :
422 : 0 : bool ScVbaControlContainer::implPickShape( const uno::Reference< drawing::XShape >& rxShape ) const
423 : : {
424 : : try
425 : : {
426 [ # # ]: 0 : uno::Reference< drawing::XControlShape > xControlShape( rxShape, uno::UNO_QUERY_THROW );
427 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xModelProps( xControlShape->getControl(), uno::UNO_QUERY_THROW );
[ # # ]
428 : 0 : sal_Int16 nClassId = -1;
429 [ # # ][ # # ]: 0 : return lclGetProperty( nClassId, xModelProps, CREATE_OUSTRING( "ClassId" ) ) &&
[ # # ][ # # ]
430 [ # # ][ # # ]: 0 : (nClassId == mnComponentType) && implCheckProperties( xModelProps );
[ # # ][ # # ]
[ # # ]
431 : : }
432 : 0 : catch( uno::Exception& )
433 : : {
434 : : }
435 : 0 : return false;
436 : : }
437 : :
438 : 0 : OUString ScVbaControlContainer::implGetShapeServiceName() const
439 : : {
440 : 0 : return CREATE_OUSTRING( "com.sun.star.drawing.ControlShape" );
441 : : }
442 : :
443 : 0 : bool ScVbaControlContainer::implCheckProperties( const uno::Reference< beans::XPropertySet >& /*rxModelProps*/ ) const
444 : : {
445 : 0 : return true;
446 : : }
447 : :
448 : 0 : OUString ScVbaControlContainer::implGetShapeName( const uno::Reference< drawing::XShape >& rxShape ) const throw (uno::RuntimeException)
449 : : {
450 [ # # ]: 0 : uno::Reference< drawing::XControlShape > xControlShape( rxShape, uno::UNO_QUERY_THROW );
451 [ # # ][ # # ]: 0 : return uno::Reference< container::XNamed >( xControlShape->getControl(), uno::UNO_QUERY_THROW )->getName();
[ # # ][ # # ]
[ # # ]
452 : : }
453 : :
454 : 0 : void ScVbaControlContainer::implOnShapeCreated( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException)
455 : : {
456 : : // passed shape must be a control shape
457 [ # # ]: 0 : uno::Reference< drawing::XControlShape > xControlShape( rxShape, uno::UNO_QUERY_THROW );
458 : :
459 : : // create the UNO control model
460 [ # # ][ # # ]: 0 : uno::Reference< form::XFormComponent > xFormComponent( mxFactory->createInstance( maModelServiceName ), uno::UNO_QUERY_THROW );
[ # # ]
461 [ # # ]: 0 : uno::Reference< awt::XControlModel > xControlModel( xFormComponent, uno::UNO_QUERY_THROW );
462 : :
463 : : // insert the control model into the form and the shape
464 [ # # ]: 0 : createForm();
465 [ # # ][ # # ]: 0 : mxFormIC->insertByIndex( mxFormIC->getCount(), uno::Any( xFormComponent ) );
[ # # ][ # # ]
[ # # ]
466 [ # # ][ # # ]: 0 : xControlShape->setControl( xControlModel );
467 : 0 : }
468 : :
469 : : // ============================================================================
470 : : // Push button
471 : : // ============================================================================
472 : :
473 [ # # ]: 0 : class ScVbaButtonContainer : public ScVbaControlContainer
474 : : {
475 : : public:
476 : : explicit ScVbaButtonContainer(
477 : : const uno::Reference< XHelperInterface >& rxParent,
478 : : const uno::Reference< uno::XComponentContext >& rxContext,
479 : : const uno::Reference< frame::XModel >& rxModel,
480 : : const uno::Reference< sheet::XSpreadsheet >& rxSheet ) throw (uno::RuntimeException);
481 : :
482 : : protected:
483 : : virtual ScVbaSheetObjectBase* implCreateVbaObject( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException);
484 : : virtual bool implCheckProperties( const uno::Reference< beans::XPropertySet >& rxModelProps ) const;
485 : : };
486 : :
487 : : // ----------------------------------------------------------------------------
488 : :
489 : 0 : ScVbaButtonContainer::ScVbaButtonContainer(
490 : : const uno::Reference< XHelperInterface >& rxParent,
491 : : const uno::Reference< uno::XComponentContext >& rxContext,
492 : : const uno::Reference< frame::XModel >& rxModel,
493 : : const uno::Reference< sheet::XSpreadsheet >& rxSheet ) throw (uno::RuntimeException) :
494 : : ScVbaControlContainer(
495 : : rxParent, rxContext, rxModel, rxSheet,
496 [ # # ]: 0 : excel::XButton::static_type( 0 ),
497 : : CREATE_OUSTRING( "com.sun.star.form.component.CommandButton" ),
498 [ # # ]: 0 : form::FormComponentType::COMMANDBUTTON )
499 : : {
500 : 0 : }
501 : :
502 : 0 : ScVbaSheetObjectBase* ScVbaButtonContainer::implCreateVbaObject( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException)
503 : : {
504 [ # # ]: 0 : uno::Reference< drawing::XControlShape > xControlShape( rxShape, uno::UNO_QUERY_THROW );
505 [ # # ][ # # ]: 0 : return new ScVbaButton( mxParent, mxContext, mxModel, createForm(), xControlShape );
506 : : }
507 : :
508 : 0 : bool ScVbaButtonContainer::implCheckProperties( const uno::Reference< beans::XPropertySet >& rxModelProps ) const
509 : : {
510 : : // do not insert toggle buttons into the 'Buttons' collection
511 : 0 : bool bToggle = false;
512 [ # # ][ # # ]: 0 : return lclGetProperty( bToggle, rxModelProps, CREATE_OUSTRING( "Toggle" ) ) && !bToggle;
[ # # ][ # # ]
[ # # ][ # # ]
513 : : }
514 : :
515 : : // ============================================================================
516 : :
517 : 0 : ScVbaButtons::ScVbaButtons(
518 : : const uno::Reference< XHelperInterface >& rxParent,
519 : : const uno::Reference< uno::XComponentContext >& rxContext,
520 : : const uno::Reference< frame::XModel >& rxModel,
521 : : const uno::Reference< sheet::XSpreadsheet >& rxSheet ) throw (uno::RuntimeException) :
522 [ # # ][ # # ]: 0 : ScVbaGraphicObjectsBase( new ScVbaButtonContainer( rxParent, rxContext, rxModel, rxSheet ) )
523 : : {
524 : 0 : }
525 : :
526 [ # # ][ # # ]: 0 : VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaButtons, "ooo.vba.excel.Buttons" )
[ # # ][ # # ]
[ # # ][ # # ]
527 : :
528 : : // ============================================================================
529 : :
530 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|