Line data Source code
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 :
20 : #include <com/sun/star/container/XNameContainer.hpp>
21 : #include <com/sun/star/container/XIndexContainer.hpp>
22 : #include <com/sun/star/lang/XServiceInfo.hpp>
23 : #include <com/sun/star/document/XEventsSupplier.hpp>
24 : #include <com/sun/star/lang/XUnoTunnel.hpp>
25 : #include <com/sun/star/beans/XPropertySet.hpp>
26 : #include <com/sun/star/awt/Rectangle.hpp>
27 : #include <com/sun/star/awt/Point.hpp>
28 : #include <com/sun/star/drawing/PointSequence.hpp>
29 : #include <comphelper/servicehelper.hxx>
30 : #include <comphelper/propertysethelper.hxx>
31 : #include <comphelper/propertysetinfo.hxx>
32 : #include <cppuhelper/weakagg.hxx>
33 : #include <cppuhelper/implbase3.hxx>
34 : #include <cppuhelper/supportsservice.hxx>
35 : #include <list>
36 : #include <osl/mutex.hxx>
37 : #include <vcl/svapp.hxx>
38 : #include <svtools/unoevent.hxx>
39 : #include <svtools/unoimap.hxx>
40 : #include <svtools/imap.hxx>
41 : #include <svtools/imapcirc.hxx>
42 : #include <svtools/imaprect.hxx>
43 : #include <svtools/imappoly.hxx>
44 :
45 : using namespace comphelper;
46 : using namespace cppu;
47 : using namespace com::sun::star;
48 : using namespace com::sun::star::uno;
49 : using namespace com::sun::star::lang;
50 : using namespace com::sun::star::container;
51 : using namespace com::sun::star::beans;
52 : using namespace com::sun::star::document;
53 : using namespace com::sun::star::drawing;
54 :
55 : const sal_Int32 HANDLE_URL = 1;
56 : const sal_Int32 HANDLE_DESCRIPTION = 2;
57 : const sal_Int32 HANDLE_TARGET = 3;
58 : const sal_Int32 HANDLE_NAME = 4;
59 : const sal_Int32 HANDLE_ISACTIVE = 5;
60 : const sal_Int32 HANDLE_POLYGON = 6;
61 : const sal_Int32 HANDLE_CENTER = 7;
62 : const sal_Int32 HANDLE_RADIUS = 8;
63 : const sal_Int32 HANDLE_BOUNDARY = 9;
64 : const sal_Int32 HANDLE_TITLE = 10;
65 :
66 : class SvUnoImageMapObject : public OWeakAggObject,
67 : public XEventsSupplier,
68 : public XServiceInfo,
69 : public PropertySetHelper,
70 : public XTypeProvider,
71 : public XUnoTunnel
72 : {
73 : public:
74 : SvUnoImageMapObject( sal_uInt16 nType, const SvEventDescription* pSupportedMacroItems );
75 : SvUnoImageMapObject( const IMapObject& rMapObject, const SvEventDescription* pSupportedMacroItems );
76 : virtual ~SvUnoImageMapObject() throw();
77 :
78 : UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMapObject )
79 :
80 : IMapObject* createIMapObject() const;
81 :
82 : SvMacroTableEventDescriptor* mpEvents;
83 :
84 : // overiden helpers from PropertySetHelper
85 : virtual void _setPropertyValues( const PropertyMapEntry** ppEntries, const Any* pValues ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException ) SAL_OVERRIDE;
86 : virtual void _getPropertyValues( const PropertyMapEntry** ppEntries, Any* pValue ) throw(UnknownPropertyException, WrappedTargetException ) SAL_OVERRIDE;
87 :
88 : // XInterface
89 : virtual Any SAL_CALL queryAggregation( const Type & rType ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
90 : virtual Any SAL_CALL queryInterface( const Type & rType ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
91 : virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
92 : virtual void SAL_CALL release() throw() SAL_OVERRIDE;
93 :
94 : // XTypeProvider
95 : virtual Sequence< Type > SAL_CALL getTypes( ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
96 : virtual Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
97 :
98 : // XEventsSupplier
99 : virtual Reference< ::com::sun::star::container::XNameReplace > SAL_CALL getEvents( ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
100 :
101 : // XServiceInfo
102 : virtual OUString SAL_CALL getImplementationName( ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
103 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
104 : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
105 :
106 : private:
107 : static PropertySetInfo* createPropertySetInfo( sal_uInt16 nType );
108 :
109 :
110 : sal_uInt16 mnType;
111 :
112 : OUString maURL;
113 : OUString maAltText;
114 : OUString maDesc;
115 : OUString maTarget;
116 : OUString maName;
117 : sal_Bool mbIsActive;
118 : awt::Rectangle maBoundary;
119 : awt::Point maCenter;
120 : sal_Int32 mnRadius;
121 : PointSequence maPolygon;
122 : };
123 :
124 0 : UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMapObject );
125 :
126 0 : PropertySetInfo * SvUnoImageMapObject::createPropertySetInfo( sal_uInt16 nType )
127 : {
128 0 : switch( nType )
129 : {
130 : case IMAP_OBJ_POLYGON:
131 : {
132 : static PropertyMapEntry const aPolygonObj_Impl[] =
133 : {
134 0 : { OUString("URL"), HANDLE_URL, ::getCppuType((const OUString*)0), 0, 0 },
135 0 : { OUString("Title"), HANDLE_TITLE, ::getCppuType((const OUString*)0), 0, 0 },
136 0 : { OUString("Description"), HANDLE_DESCRIPTION, ::getCppuType((const OUString*)0), 0, 0 },
137 0 : { OUString("Target"), HANDLE_TARGET, ::getCppuType((const OUString*)0), 0, 0 },
138 0 : { OUString("Name"), HANDLE_NAME, ::getCppuType((const OUString*)0), 0, 0 },
139 0 : { OUString("IsActive"), HANDLE_ISACTIVE, ::getBooleanCppuType(), 0, 0 },
140 0 : { OUString("Polygon"), HANDLE_POLYGON, ::getCppuType((const PointSequence*)0), 0, 0 },
141 : { OUString(), 0, css::uno::Type(), 0, 0 }
142 0 : };
143 :
144 0 : return new PropertySetInfo( aPolygonObj_Impl );
145 : }
146 : case IMAP_OBJ_CIRCLE:
147 : {
148 : static PropertyMapEntry const aCircleObj_Impl[] =
149 : {
150 0 : { OUString("URL"), HANDLE_URL, ::getCppuType((const OUString*)0), 0, 0 },
151 0 : { OUString("Title"), HANDLE_TITLE, ::getCppuType((const OUString*)0), 0, 0 },
152 0 : { OUString("Description"), HANDLE_DESCRIPTION, ::getCppuType((const OUString*)0), 0, 0 },
153 0 : { OUString("Target"), HANDLE_TARGET, ::getCppuType((const OUString*)0), 0, 0 },
154 0 : { OUString("Name"), HANDLE_NAME, ::getCppuType((const OUString*)0), 0, 0 },
155 0 : { OUString("IsActive"), HANDLE_ISACTIVE, ::getBooleanCppuType(), 0, 0 },
156 0 : { OUString("Center"), HANDLE_CENTER, ::getCppuType((const awt::Point*)0), 0, 0 },
157 0 : { OUString("Radius"), HANDLE_RADIUS, ::getCppuType((const sal_Int32*)0), 0, 0 },
158 : { OUString(), 0, css::uno::Type(), 0, 0 }
159 0 : };
160 :
161 0 : return new PropertySetInfo( aCircleObj_Impl );
162 : }
163 : case IMAP_OBJ_RECTANGLE:
164 : default:
165 : {
166 : static PropertyMapEntry const aRectangleObj_Impl[] =
167 : {
168 0 : { OUString("URL"), HANDLE_URL, ::getCppuType((const OUString*)0), 0, 0 },
169 0 : { OUString("Title"), HANDLE_TITLE, ::getCppuType((const OUString*)0), 0, 0 },
170 0 : { OUString("Description"), HANDLE_DESCRIPTION, ::getCppuType((const OUString*)0), 0, 0 },
171 0 : { OUString("Target"), HANDLE_TARGET, ::getCppuType((const OUString*)0), 0, 0 },
172 0 : { OUString("Name"), HANDLE_NAME, ::getCppuType((const OUString*)0), 0, 0 },
173 0 : { OUString("IsActive"), HANDLE_ISACTIVE, ::getBooleanCppuType(), 0, 0 },
174 0 : { OUString("Boundary"), HANDLE_BOUNDARY, ::getCppuType((const awt::Rectangle*)0), 0, 0 },
175 : { OUString(), 0, css::uno::Type(), 0, 0 }
176 0 : };
177 :
178 0 : return new PropertySetInfo( aRectangleObj_Impl );
179 : }
180 : }
181 : }
182 :
183 0 : SvUnoImageMapObject::SvUnoImageMapObject( sal_uInt16 nType, const SvEventDescription* pSupportedMacroItems )
184 : : PropertySetHelper( createPropertySetInfo( nType ) ),
185 : mnType( nType )
186 : , mbIsActive( true )
187 0 : , mnRadius( 0 )
188 : {
189 0 : mpEvents = new SvMacroTableEventDescriptor( pSupportedMacroItems );
190 0 : mpEvents->acquire();
191 0 : }
192 :
193 0 : SvUnoImageMapObject::SvUnoImageMapObject( const IMapObject& rMapObject, const SvEventDescription* pSupportedMacroItems )
194 0 : : PropertySetHelper( createPropertySetInfo( rMapObject.GetType() ) ),
195 0 : mnType( rMapObject.GetType() )
196 : , mbIsActive( true )
197 0 : , mnRadius( 0 )
198 : {
199 0 : maURL = rMapObject.GetURL();
200 0 : maAltText = rMapObject.GetAltText();
201 0 : maDesc = rMapObject.GetDesc();
202 0 : maTarget = rMapObject.GetTarget();
203 0 : maName = rMapObject.GetName();
204 0 : mbIsActive = rMapObject.IsActive();
205 :
206 0 : switch( mnType )
207 : {
208 : case IMAP_OBJ_RECTANGLE:
209 : {
210 0 : const Rectangle aRect( ((IMapRectangleObject*)&rMapObject)->GetRectangle(false) );
211 0 : maBoundary.X = aRect.Left();
212 0 : maBoundary.Y = aRect.Top();
213 0 : maBoundary.Width = aRect.GetWidth();
214 0 : maBoundary.Height = aRect.GetHeight();
215 : }
216 0 : break;
217 : case IMAP_OBJ_CIRCLE:
218 : {
219 0 : mnRadius = (sal_Int32)((IMapCircleObject*)&rMapObject)->GetRadius(false);
220 0 : const Point aPoint( ((IMapCircleObject*)&rMapObject)->GetCenter(false) );
221 :
222 0 : maCenter.X = aPoint.X();
223 0 : maCenter.Y = aPoint.Y();
224 : }
225 0 : break;
226 : case IMAP_OBJ_POLYGON:
227 : default:
228 : {
229 0 : const Polygon aPoly( ((IMapPolygonObject*)&rMapObject)->GetPolygon(false) );
230 :
231 0 : const sal_uInt16 nCount = aPoly.GetSize();
232 0 : maPolygon.realloc( nCount );
233 0 : awt::Point* pPoints = maPolygon.getArray();
234 :
235 0 : for( sal_uInt16 nPoint = 0; nPoint < nCount; nPoint++ )
236 : {
237 0 : const Point& rPoint = aPoly.GetPoint( nPoint );
238 0 : pPoints->X = rPoint.X();
239 0 : pPoints->Y = rPoint.Y();
240 :
241 0 : pPoints++;
242 0 : }
243 : }
244 : }
245 :
246 0 : mpEvents = new SvMacroTableEventDescriptor( rMapObject.GetMacroTable(), pSupportedMacroItems );
247 0 : mpEvents->acquire();
248 0 : }
249 :
250 0 : SvUnoImageMapObject::~SvUnoImageMapObject() throw()
251 : {
252 0 : mpEvents->release();
253 0 : }
254 :
255 0 : IMapObject* SvUnoImageMapObject::createIMapObject() const
256 : {
257 0 : const OUString aURL( maURL );
258 0 : const OUString aAltText( maAltText );
259 0 : const OUString aDesc( maDesc );
260 0 : const OUString aTarget( maTarget );
261 0 : const OUString aName( maName );
262 :
263 : IMapObject* pNewIMapObject;
264 :
265 0 : switch( mnType )
266 : {
267 : case IMAP_OBJ_RECTANGLE:
268 : {
269 0 : const Rectangle aRect( maBoundary.X, maBoundary.Y, maBoundary.X + maBoundary.Width - 1, maBoundary.Y + maBoundary.Height - 1 );
270 0 : pNewIMapObject = new IMapRectangleObject( aRect, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false );
271 : }
272 0 : break;
273 :
274 : case IMAP_OBJ_CIRCLE:
275 : {
276 0 : const Point aCenter( maCenter.X, maCenter.Y );
277 0 : pNewIMapObject = new IMapCircleObject( aCenter, mnRadius, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false );
278 : }
279 0 : break;
280 :
281 : case IMAP_OBJ_POLYGON:
282 : default:
283 : {
284 0 : const sal_uInt16 nCount = (sal_uInt16)maPolygon.getLength();
285 :
286 0 : Polygon aPoly( nCount );
287 0 : for( sal_uInt16 nPoint = 0; nPoint < nCount; nPoint++ )
288 : {
289 0 : Point aPoint( maPolygon[nPoint].X, maPolygon[nPoint].Y );
290 0 : aPoly.SetPoint( aPoint, nPoint );
291 : }
292 :
293 0 : aPoly.Optimize( POLY_OPTIMIZE_CLOSE );
294 0 : pNewIMapObject = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false );
295 : }
296 0 : break;
297 : }
298 :
299 0 : SvxMacroTableDtor aMacroTable;
300 0 : mpEvents->copyMacrosIntoTable(aMacroTable);
301 0 : pNewIMapObject->SetMacroTable( aMacroTable );
302 :
303 0 : return pNewIMapObject;
304 : }
305 :
306 : // XInterface
307 :
308 0 : Any SAL_CALL SvUnoImageMapObject::queryInterface( const Type & rType )
309 : throw( RuntimeException, std::exception )
310 : {
311 0 : return OWeakAggObject::queryInterface( rType );
312 : }
313 :
314 0 : Any SAL_CALL SvUnoImageMapObject::queryAggregation( const Type & rType )
315 : throw(RuntimeException, std::exception)
316 : {
317 0 : Any aAny;
318 :
319 0 : if( rType == ::getCppuType((const Reference< XServiceInfo >*)0) )
320 0 : aAny <<= Reference< XServiceInfo >(this);
321 0 : else if( rType == ::getCppuType((const Reference< XTypeProvider >*)0) )
322 0 : aAny <<= Reference< XTypeProvider >(this);
323 0 : else if( rType == ::getCppuType((const Reference< XPropertySet >*)0) )
324 0 : aAny <<= Reference< XPropertySet >(this);
325 0 : else if( rType == ::getCppuType((const Reference< XEventsSupplier >*)0) )
326 0 : aAny <<= Reference< XEventsSupplier >(this);
327 0 : else if( rType == ::getCppuType((const Reference< XMultiPropertySet >*)0) )
328 0 : aAny <<= Reference< XMultiPropertySet >(this);
329 0 : else if( rType == ::getCppuType((const Reference< XUnoTunnel >*)0) )
330 0 : aAny <<= Reference< XUnoTunnel >(this);
331 : else
332 0 : aAny <<= OWeakAggObject::queryAggregation( rType );
333 :
334 0 : return aAny;
335 : }
336 :
337 0 : void SAL_CALL SvUnoImageMapObject::acquire() throw()
338 : {
339 0 : OWeakAggObject::acquire();
340 0 : }
341 :
342 0 : void SAL_CALL SvUnoImageMapObject::release() throw()
343 : {
344 0 : OWeakAggObject::release();
345 0 : }
346 :
347 0 : uno::Sequence< uno::Type > SAL_CALL SvUnoImageMapObject::getTypes()
348 : throw (uno::RuntimeException, std::exception)
349 : {
350 0 : uno::Sequence< uno::Type > aTypes( 7 );
351 0 : uno::Type* pTypes = aTypes.getArray();
352 :
353 0 : *pTypes++ = ::getCppuType((const uno::Reference< XAggregation>*)0);
354 0 : *pTypes++ = ::getCppuType((const uno::Reference< XEventsSupplier>*)0);
355 0 : *pTypes++ = ::getCppuType((const uno::Reference< XServiceInfo>*)0);
356 0 : *pTypes++ = ::getCppuType((const uno::Reference< XPropertySet>*)0);
357 0 : *pTypes++ = ::getCppuType((const uno::Reference< XMultiPropertySet>*)0);
358 0 : *pTypes++ = ::getCppuType((const uno::Reference< XTypeProvider>*)0);
359 0 : *pTypes++ = ::getCppuType((const uno::Reference< XUnoTunnel>*)0);
360 :
361 0 : return aTypes;
362 : }
363 :
364 0 : uno::Sequence< sal_Int8 > SAL_CALL SvUnoImageMapObject::getImplementationId()
365 : throw (uno::RuntimeException, std::exception)
366 : {
367 0 : return css::uno::Sequence<sal_Int8>();
368 : }
369 :
370 : // XServiceInfo
371 0 : sal_Bool SAL_CALL SvUnoImageMapObject::supportsService( const OUString& ServiceName ) throw(RuntimeException, std::exception)
372 : {
373 0 : return cppu::supportsService(this, ServiceName);
374 : }
375 :
376 0 : Sequence< OUString > SAL_CALL SvUnoImageMapObject::getSupportedServiceNames()
377 : throw(RuntimeException, std::exception)
378 : {
379 0 : Sequence< OUString > aSNS( 2 );
380 0 : aSNS.getArray()[0] = "com.sun.star.image.ImageMapObject";
381 0 : switch( mnType )
382 : {
383 : case IMAP_OBJ_POLYGON:
384 : default:
385 0 : aSNS.getArray()[1] = "com.sun.star.image.ImageMapPolygonObject";
386 0 : break;
387 : case IMAP_OBJ_RECTANGLE:
388 0 : aSNS.getArray()[1] = "com.sun.star.image.ImageMapRectangleObject";
389 0 : break;
390 : case IMAP_OBJ_CIRCLE:
391 0 : aSNS.getArray()[1] = "com.sun.star.image.ImageMapCircleObject";
392 0 : break;
393 : }
394 0 : return aSNS;
395 : }
396 :
397 0 : OUString SAL_CALL SvUnoImageMapObject::getImplementationName() throw(RuntimeException, std::exception)
398 : {
399 0 : switch( mnType )
400 : {
401 : case IMAP_OBJ_POLYGON:
402 : default:
403 0 : return OUString("org.openoffice.comp.svt.ImageMapPolygonObject");
404 : case IMAP_OBJ_CIRCLE:
405 0 : return OUString("org.openoffice.comp.svt.ImageMapCircleObject");
406 : case IMAP_OBJ_RECTANGLE:
407 0 : return OUString("org.openoffice.comp.svt.ImageMapRectangleObject");
408 : }
409 : }
410 :
411 : // overiden helpers from PropertySetHelper
412 0 : void SvUnoImageMapObject::_setPropertyValues( const PropertyMapEntry** ppEntries, const Any* pValues )
413 : throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException )
414 : {
415 0 : sal_Bool bOk = sal_False;
416 :
417 0 : while( *ppEntries )
418 : {
419 0 : switch( (*ppEntries)->mnHandle )
420 : {
421 : case HANDLE_URL:
422 0 : bOk = *pValues >>= maURL;
423 0 : break;
424 : case HANDLE_TITLE:
425 0 : bOk = *pValues >>= maAltText;
426 0 : break;
427 : case HANDLE_DESCRIPTION:
428 0 : bOk = *pValues >>= maDesc;
429 0 : break;
430 : case HANDLE_TARGET:
431 0 : bOk = *pValues >>= maTarget;
432 0 : break;
433 : case HANDLE_NAME:
434 0 : bOk = *pValues >>= maName;
435 0 : break;
436 : case HANDLE_ISACTIVE:
437 0 : bOk = *pValues >>= mbIsActive;
438 0 : break;
439 : case HANDLE_BOUNDARY:
440 0 : bOk = *pValues >>= maBoundary;
441 0 : break;
442 : case HANDLE_CENTER:
443 0 : bOk = *pValues >>= maCenter;
444 0 : break;
445 : case HANDLE_RADIUS:
446 0 : bOk = *pValues >>= mnRadius;
447 0 : break;
448 : case HANDLE_POLYGON:
449 0 : bOk = *pValues >>= maPolygon;
450 0 : break;
451 : default:
452 : OSL_FAIL( "SvUnoImageMapObject::_setPropertyValues: unexpected property handle" );
453 0 : break;
454 : }
455 :
456 0 : if( !bOk )
457 0 : throw IllegalArgumentException();
458 :
459 0 : ppEntries++;
460 0 : pValues++;
461 : }
462 0 : }
463 :
464 0 : void SvUnoImageMapObject::_getPropertyValues( const PropertyMapEntry** ppEntries, Any* pValues )
465 : throw(UnknownPropertyException, WrappedTargetException )
466 : {
467 0 : while( *ppEntries )
468 : {
469 0 : switch( (*ppEntries)->mnHandle )
470 : {
471 : case HANDLE_URL:
472 0 : *pValues <<= maURL;
473 0 : break;
474 : case HANDLE_TITLE:
475 0 : *pValues <<= maAltText;
476 0 : break;
477 : case HANDLE_DESCRIPTION:
478 0 : *pValues <<= maDesc;
479 0 : break;
480 : case HANDLE_TARGET:
481 0 : *pValues <<= maTarget;
482 0 : break;
483 : case HANDLE_NAME:
484 0 : *pValues <<= maName;
485 0 : break;
486 : case HANDLE_ISACTIVE:
487 0 : *pValues <<= mbIsActive;
488 0 : break;
489 : case HANDLE_BOUNDARY:
490 0 : *pValues <<= maBoundary;
491 0 : break;
492 : case HANDLE_CENTER:
493 0 : *pValues <<= maCenter;
494 0 : break;
495 : case HANDLE_RADIUS:
496 0 : *pValues <<= mnRadius;
497 0 : break;
498 : case HANDLE_POLYGON:
499 0 : *pValues <<= maPolygon;
500 0 : break;
501 : default:
502 : OSL_FAIL( "SvUnoImageMapObject::_getPropertyValues: unexpected property handle" );
503 0 : break;
504 : }
505 :
506 0 : ppEntries++;
507 0 : pValues++;
508 : }
509 0 : }
510 :
511 :
512 0 : Reference< XNameReplace > SAL_CALL SvUnoImageMapObject::getEvents()
513 : throw( RuntimeException, std::exception )
514 : {
515 : // try weak reference first
516 0 : Reference< XNameReplace > xEvents( mpEvents );
517 0 : return xEvents;
518 : }
519 :
520 :
521 :
522 : class SvUnoImageMap : public WeakImplHelper3< XIndexContainer, XServiceInfo, XUnoTunnel >
523 : {
524 : public:
525 : SvUnoImageMap( const SvEventDescription* pSupportedMacroItems );
526 : SvUnoImageMap( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems );
527 : virtual ~SvUnoImageMap();
528 :
529 : sal_Bool fillImageMap( ImageMap& rMap ) const;
530 : SvUnoImageMapObject* getObject( const Any& aElement ) const throw( IllegalArgumentException );
531 :
532 : UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMap )
533 :
534 : // XIndexContainer
535 : virtual void SAL_CALL insertByIndex( sal_Int32 Index, const Any& Element ) throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception ) SAL_OVERRIDE;
536 : virtual void SAL_CALL removeByIndex( sal_Int32 Index ) throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception ) SAL_OVERRIDE;
537 :
538 : // XIndexReplace
539 : virtual void SAL_CALL replaceByIndex( sal_Int32 Index, const Any& Element ) throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception ) SAL_OVERRIDE;
540 :
541 : // XIndexAccess
542 : virtual sal_Int32 SAL_CALL getCount( ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
543 : virtual Any SAL_CALL getByIndex( sal_Int32 Index ) throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception ) SAL_OVERRIDE;
544 :
545 : // XElementAccess
546 : virtual Type SAL_CALL getElementType( ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
547 : virtual sal_Bool SAL_CALL hasElements( ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
548 :
549 : // XSerivceInfo
550 : virtual OUString SAL_CALL getImplementationName( ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
551 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
552 : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
553 :
554 : private:
555 : OUString maName;
556 :
557 : std::list< SvUnoImageMapObject* > maObjectList;
558 : };
559 :
560 0 : UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMap );
561 :
562 0 : SvUnoImageMap::SvUnoImageMap( const SvEventDescription* )
563 : {
564 0 : }
565 :
566 0 : SvUnoImageMap::SvUnoImageMap( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems )
567 : {
568 0 : maName = rMap.GetName();
569 :
570 0 : const sal_uInt16 nCount = rMap.GetIMapObjectCount();
571 0 : for( sal_uInt16 nPos = 0; nPos < nCount; nPos++ )
572 : {
573 0 : IMapObject* pMapObject = rMap.GetIMapObject( nPos );
574 0 : SvUnoImageMapObject* pUnoObj = new SvUnoImageMapObject( *pMapObject, pSupportedMacroItems );
575 0 : pUnoObj->acquire();
576 0 : maObjectList.push_back( pUnoObj );
577 : }
578 0 : }
579 :
580 0 : SvUnoImageMap::~SvUnoImageMap()
581 : {
582 0 : std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
583 0 : const std::list< SvUnoImageMapObject* >::iterator aEnd = maObjectList.end();
584 0 : while( aIter != aEnd )
585 : {
586 0 : (*aIter++)->release();
587 : }
588 0 : }
589 :
590 0 : SvUnoImageMapObject* SvUnoImageMap::getObject( const Any& aElement ) const
591 : throw( IllegalArgumentException )
592 : {
593 0 : Reference< XInterface > xObject;
594 0 : aElement >>= xObject;
595 :
596 0 : SvUnoImageMapObject* pObject = SvUnoImageMapObject::getImplementation( xObject );
597 0 : if( NULL == pObject )
598 0 : throw IllegalArgumentException();
599 :
600 0 : return pObject;
601 : }
602 :
603 : // XIndexContainer
604 0 : void SAL_CALL SvUnoImageMap::insertByIndex( sal_Int32 Index, const Any& Element )
605 : throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
606 : {
607 0 : SvUnoImageMapObject* pObject = getObject( Element );
608 0 : const sal_Int32 nCount = maObjectList.size();
609 0 : if( NULL == pObject || Index > nCount )
610 0 : throw IndexOutOfBoundsException();
611 :
612 0 : pObject->acquire();
613 :
614 0 : if( Index == nCount )
615 0 : maObjectList.push_back( pObject );
616 : else
617 : {
618 0 : std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
619 0 : for( sal_Int32 n = 0; n < Index; n++ )
620 0 : ++aIter;
621 :
622 0 : maObjectList.insert( aIter, pObject );
623 : }
624 0 : }
625 :
626 0 : void SAL_CALL SvUnoImageMap::removeByIndex( sal_Int32 nIndex ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception)
627 : {
628 0 : const sal_Int32 nCount = maObjectList.size();
629 0 : if( nIndex >= nCount )
630 0 : throw IndexOutOfBoundsException();
631 :
632 0 : if( nCount - 1 == nIndex )
633 : {
634 0 : maObjectList.back()->release();
635 0 : maObjectList.pop_back();
636 : }
637 : else
638 : {
639 0 : std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
640 0 : std::advance(aIter, nIndex);
641 :
642 0 : (*aIter)->release();
643 0 : maObjectList.erase( aIter );
644 : }
645 0 : }
646 :
647 : // XIndexReplace
648 0 : void SAL_CALL SvUnoImageMap::replaceByIndex( sal_Int32 Index, const Any& Element ) throw(IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception)
649 : {
650 0 : SvUnoImageMapObject* pObject = getObject( Element );
651 0 : const sal_Int32 nCount = maObjectList.size();
652 0 : if( NULL == pObject || Index >= nCount )
653 0 : throw IndexOutOfBoundsException();
654 :
655 0 : std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
656 0 : for( sal_Int32 n = 0; n < Index; n++ )
657 0 : ++aIter;
658 :
659 0 : (*aIter)->release();
660 0 : *aIter = pObject;
661 0 : pObject->acquire();
662 0 : }
663 :
664 : // XIndexAccess
665 0 : sal_Int32 SAL_CALL SvUnoImageMap::getCount( ) throw(RuntimeException, std::exception)
666 : {
667 0 : return maObjectList.size();
668 : }
669 :
670 0 : Any SAL_CALL SvUnoImageMap::getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception)
671 : {
672 0 : const sal_Int32 nCount = maObjectList.size();
673 0 : if( Index >= nCount )
674 0 : throw IndexOutOfBoundsException();
675 :
676 0 : std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
677 0 : for( sal_Int32 n = 0; n < Index; n++ )
678 0 : ++aIter;
679 :
680 0 : Reference< XPropertySet > xObj( *aIter );
681 0 : return makeAny( xObj );
682 : }
683 :
684 : // XElementAccess
685 0 : Type SAL_CALL SvUnoImageMap::getElementType( ) throw(RuntimeException, std::exception)
686 : {
687 0 : return ::getCppuType((const Reference< XPropertySet >*)0);
688 : }
689 :
690 0 : sal_Bool SAL_CALL SvUnoImageMap::hasElements( ) throw(RuntimeException, std::exception)
691 : {
692 0 : return (!maObjectList.empty());
693 : }
694 :
695 : // XSerivceInfo
696 0 : OUString SAL_CALL SvUnoImageMap::getImplementationName( )
697 : throw(RuntimeException, std::exception)
698 : {
699 0 : return OUString( "org.openoffice.comp.svt.SvUnoImageMap" );
700 : }
701 :
702 0 : sal_Bool SAL_CALL SvUnoImageMap::supportsService( const OUString& ServiceName )
703 : throw(RuntimeException, std::exception)
704 : {
705 0 : return cppu::supportsService(this, ServiceName);
706 : }
707 :
708 0 : Sequence< OUString > SAL_CALL SvUnoImageMap::getSupportedServiceNames( )
709 : throw(RuntimeException, std::exception)
710 : {
711 0 : const OUString aSN( "com.sun.star.image.ImageMap" );
712 0 : return Sequence< OUString >( &aSN, 1 );
713 : }
714 :
715 0 : sal_Bool SvUnoImageMap::fillImageMap( ImageMap& rMap ) const
716 : {
717 0 : rMap.ClearImageMap();
718 :
719 0 : rMap.SetName( maName );
720 :
721 0 : std::list< SvUnoImageMapObject* >::const_iterator aIter = maObjectList.begin();
722 0 : const std::list< SvUnoImageMapObject* >::const_iterator aEnd = maObjectList.end();
723 0 : while( aIter != aEnd )
724 : {
725 0 : IMapObject* pNewMapObject = (*aIter)->createIMapObject();
726 0 : rMap.InsertIMapObject( *pNewMapObject );
727 0 : delete pNewMapObject;
728 :
729 0 : ++aIter;
730 : }
731 :
732 0 : return sal_True;
733 : }
734 :
735 :
736 : // factory helper methods
737 :
738 :
739 0 : Reference< XInterface > SvUnoImageMapRectangleObject_createInstance( const SvEventDescription* pSupportedMacroItems )
740 : {
741 0 : return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_RECTANGLE, pSupportedMacroItems );
742 : }
743 :
744 0 : Reference< XInterface > SvUnoImageMapCircleObject_createInstance( const SvEventDescription* pSupportedMacroItems )
745 : {
746 0 : return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_CIRCLE, pSupportedMacroItems );
747 : }
748 :
749 0 : Reference< XInterface > SvUnoImageMapPolygonObject_createInstance( const SvEventDescription* pSupportedMacroItems )
750 : {
751 0 : return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_POLYGON, pSupportedMacroItems );
752 : }
753 :
754 0 : Reference< XInterface > SvUnoImageMap_createInstance( const SvEventDescription* pSupportedMacroItems )
755 : {
756 0 : return (XWeak*)new SvUnoImageMap( pSupportedMacroItems );
757 : }
758 :
759 0 : Reference< XInterface > SvUnoImageMap_createInstance( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems )
760 : {
761 0 : return (XWeak*)new SvUnoImageMap( rMap, pSupportedMacroItems );
762 : }
763 :
764 0 : bool SvUnoImageMap_fillImageMap( Reference< XInterface > xImageMap, ImageMap& rMap )
765 : {
766 0 : SvUnoImageMap* pUnoImageMap = SvUnoImageMap::getImplementation( xImageMap );
767 0 : if( NULL == pUnoImageMap )
768 0 : return false;
769 :
770 0 : return pUnoImageMap->fillImageMap( rMap );
771 : }
772 :
773 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|