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 : // overriden 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 : bool mbIsActive;
118 : awt::Rectangle maBoundary;
119 : awt::Point maCenter;
120 : sal_Int32 mnRadius;
121 : PointSequence maPolygon;
122 : };
123 :
124 4 : UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMapObject );
125 :
126 4 : PropertySetInfo * SvUnoImageMapObject::createPropertySetInfo( sal_uInt16 nType )
127 : {
128 4 : switch( nType )
129 : {
130 : case IMAP_OBJ_POLYGON:
131 : {
132 : static PropertyMapEntry const aPolygonObj_Impl[] =
133 : {
134 2 : { OUString("URL"), HANDLE_URL, cppu::UnoType<OUString>::get(), 0, 0 },
135 2 : { OUString("Title"), HANDLE_TITLE, cppu::UnoType<OUString>::get(), 0, 0 },
136 2 : { OUString("Description"), HANDLE_DESCRIPTION, cppu::UnoType<OUString>::get(), 0, 0 },
137 2 : { OUString("Target"), HANDLE_TARGET, cppu::UnoType<OUString>::get(), 0, 0 },
138 2 : { OUString("Name"), HANDLE_NAME, cppu::UnoType<OUString>::get(), 0, 0 },
139 2 : { OUString("IsActive"), HANDLE_ISACTIVE, cppu::UnoType<bool>::get(), 0, 0 },
140 2 : { OUString("Polygon"), HANDLE_POLYGON, cppu::UnoType<PointSequence>::get(), 0, 0 },
141 : { OUString(), 0, css::uno::Type(), 0, 0 }
142 18 : };
143 :
144 2 : return new PropertySetInfo( aPolygonObj_Impl );
145 : }
146 : case IMAP_OBJ_CIRCLE:
147 : {
148 : static PropertyMapEntry const aCircleObj_Impl[] =
149 : {
150 1 : { OUString("URL"), HANDLE_URL, cppu::UnoType<OUString>::get(), 0, 0 },
151 1 : { OUString("Title"), HANDLE_TITLE, cppu::UnoType<OUString>::get(), 0, 0 },
152 1 : { OUString("Description"), HANDLE_DESCRIPTION, cppu::UnoType<OUString>::get(), 0, 0 },
153 1 : { OUString("Target"), HANDLE_TARGET, cppu::UnoType<OUString>::get(), 0, 0 },
154 1 : { OUString("Name"), HANDLE_NAME, cppu::UnoType<OUString>::get(), 0, 0 },
155 1 : { OUString("IsActive"), HANDLE_ISACTIVE, cppu::UnoType<bool>::get(), 0, 0 },
156 1 : { OUString("Center"), HANDLE_CENTER, cppu::UnoType<awt::Point>::get(), 0, 0 },
157 1 : { OUString("Radius"), HANDLE_RADIUS, cppu::UnoType<sal_Int32>::get(), 0, 0 },
158 : { OUString(), 0, css::uno::Type(), 0, 0 }
159 10 : };
160 :
161 1 : return new PropertySetInfo( aCircleObj_Impl );
162 : }
163 : case IMAP_OBJ_RECTANGLE:
164 : default:
165 : {
166 : static PropertyMapEntry const aRectangleObj_Impl[] =
167 : {
168 1 : { OUString("URL"), HANDLE_URL, cppu::UnoType<OUString>::get(), 0, 0 },
169 1 : { OUString("Title"), HANDLE_TITLE, cppu::UnoType<OUString>::get(), 0, 0 },
170 1 : { OUString("Description"), HANDLE_DESCRIPTION, cppu::UnoType<OUString>::get(), 0, 0 },
171 1 : { OUString("Target"), HANDLE_TARGET, cppu::UnoType<OUString>::get(), 0, 0 },
172 1 : { OUString("Name"), HANDLE_NAME, cppu::UnoType<OUString>::get(), 0, 0 },
173 1 : { OUString("IsActive"), HANDLE_ISACTIVE, cppu::UnoType<bool>::get(), 0, 0 },
174 1 : { OUString("Boundary"), HANDLE_BOUNDARY, cppu::UnoType<awt::Rectangle>::get(), 0, 0 },
175 : { OUString(), 0, css::uno::Type(), 0, 0 }
176 9 : };
177 :
178 1 : return new PropertySetInfo( aRectangleObj_Impl );
179 : }
180 : }
181 : }
182 :
183 4 : SvUnoImageMapObject::SvUnoImageMapObject( sal_uInt16 nType, const SvEventDescription* pSupportedMacroItems )
184 : : PropertySetHelper( createPropertySetInfo( nType ) ),
185 : mnType( nType )
186 : , mbIsActive( true )
187 4 : , mnRadius( 0 )
188 : {
189 4 : mpEvents = new SvMacroTableEventDescriptor( pSupportedMacroItems );
190 4 : mpEvents->acquire();
191 4 : }
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( static_cast<const 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)static_cast<const IMapCircleObject*>(&rMapObject)->GetRadius(false);
220 0 : const Point aPoint( static_cast<const 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( static_cast<const 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 12 : SvUnoImageMapObject::~SvUnoImageMapObject() throw()
251 : {
252 4 : mpEvents->release();
253 8 : }
254 :
255 1 : IMapObject* SvUnoImageMapObject::createIMapObject() const
256 : {
257 1 : const OUString aURL( maURL );
258 2 : const OUString aAltText( maAltText );
259 2 : const OUString aDesc( maDesc );
260 2 : const OUString aTarget( maTarget );
261 2 : const OUString aName( maName );
262 :
263 : IMapObject* pNewIMapObject;
264 :
265 1 : 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 1 : const sal_uInt16 nCount = (sal_uInt16)maPolygon.getLength();
285 :
286 1 : Polygon aPoly( nCount );
287 97 : for( sal_uInt16 nPoint = 0; nPoint < nCount; nPoint++ )
288 : {
289 96 : Point aPoint( maPolygon[nPoint].X, maPolygon[nPoint].Y );
290 96 : aPoly.SetPoint( aPoint, nPoint );
291 : }
292 :
293 1 : aPoly.Optimize( PolyOptimizeFlags::CLOSE );
294 1 : pNewIMapObject = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false );
295 : }
296 1 : break;
297 : }
298 :
299 1 : SvxMacroTableDtor aMacroTable;
300 1 : mpEvents->copyMacrosIntoTable(aMacroTable);
301 1 : pNewIMapObject->SetMacroTable( aMacroTable );
302 :
303 2 : return pNewIMapObject;
304 : }
305 :
306 : // XInterface
307 :
308 6 : Any SAL_CALL SvUnoImageMapObject::queryInterface( const Type & rType )
309 : throw( RuntimeException, std::exception )
310 : {
311 6 : return OWeakAggObject::queryInterface( rType );
312 : }
313 :
314 6 : Any SAL_CALL SvUnoImageMapObject::queryAggregation( const Type & rType )
315 : throw(RuntimeException, std::exception)
316 : {
317 6 : Any aAny;
318 :
319 6 : if( rType == cppu::UnoType<XServiceInfo>::get())
320 0 : aAny <<= Reference< XServiceInfo >(this);
321 6 : else if( rType == cppu::UnoType<XTypeProvider>::get())
322 0 : aAny <<= Reference< XTypeProvider >(this);
323 6 : else if( rType == cppu::UnoType<XPropertySet>::get())
324 1 : aAny <<= Reference< XPropertySet >(this);
325 5 : else if( rType == cppu::UnoType<XEventsSupplier>::get())
326 0 : aAny <<= Reference< XEventsSupplier >(this);
327 5 : else if( rType == cppu::UnoType<XMultiPropertySet>::get())
328 0 : aAny <<= Reference< XMultiPropertySet >(this);
329 5 : else if( rType == cppu::UnoType<XUnoTunnel>::get())
330 1 : aAny <<= Reference< XUnoTunnel >(this);
331 : else
332 4 : aAny <<= OWeakAggObject::queryAggregation( rType );
333 :
334 6 : return aAny;
335 : }
336 :
337 32 : void SAL_CALL SvUnoImageMapObject::acquire() throw()
338 : {
339 32 : OWeakAggObject::acquire();
340 32 : }
341 :
342 32 : void SAL_CALL SvUnoImageMapObject::release() throw()
343 : {
344 32 : OWeakAggObject::release();
345 32 : }
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++ = cppu::UnoType<XAggregation>::get();
354 0 : *pTypes++ = cppu::UnoType<XEventsSupplier>::get();
355 0 : *pTypes++ = cppu::UnoType<XServiceInfo>::get();
356 0 : *pTypes++ = cppu::UnoType<XPropertySet>::get();
357 0 : *pTypes++ = cppu::UnoType<XMultiPropertySet>::get();
358 0 : *pTypes++ = cppu::UnoType<XTypeProvider>::get();
359 0 : *pTypes++ = cppu::UnoType<XUnoTunnel>::get();
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 : // overriden helpers from PropertySetHelper
412 7 : void SvUnoImageMapObject::_setPropertyValues( const PropertyMapEntry** ppEntries, const Any* pValues )
413 : throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException )
414 : {
415 7 : bool bOk = false;
416 :
417 21 : while( *ppEntries )
418 : {
419 7 : switch( (*ppEntries)->mnHandle )
420 : {
421 : case HANDLE_URL:
422 1 : bOk = *pValues >>= maURL;
423 1 : break;
424 : case HANDLE_TITLE:
425 1 : bOk = *pValues >>= maAltText;
426 1 : break;
427 : case HANDLE_DESCRIPTION:
428 1 : bOk = *pValues >>= maDesc;
429 1 : break;
430 : case HANDLE_TARGET:
431 1 : bOk = *pValues >>= maTarget;
432 1 : break;
433 : case HANDLE_NAME:
434 1 : bOk = *pValues >>= maName;
435 1 : break;
436 : case HANDLE_ISACTIVE:
437 1 : bOk = *pValues >>= mbIsActive;
438 1 : 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 1 : bOk = *pValues >>= maPolygon;
450 1 : break;
451 : default:
452 : OSL_FAIL( "SvUnoImageMapObject::_setPropertyValues: unexpected property handle" );
453 0 : break;
454 : }
455 :
456 7 : if( !bOk )
457 0 : throw IllegalArgumentException();
458 :
459 7 : ppEntries++;
460 7 : pValues++;
461 : }
462 7 : }
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 : explicit SvUnoImageMap( const SvEventDescription* pSupportedMacroItems );
526 : SvUnoImageMap( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems );
527 : virtual ~SvUnoImageMap();
528 :
529 : bool fillImageMap( ImageMap& rMap ) const;
530 : static SvUnoImageMapObject* getObject( const Any& aElement ) 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 4 : UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMap );
561 :
562 10 : SvUnoImageMap::SvUnoImageMap( const SvEventDescription* )
563 : {
564 10 : }
565 :
566 75 : SvUnoImageMap::SvUnoImageMap( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems )
567 : {
568 75 : maName = rMap.GetName();
569 :
570 75 : const std::size_t nCount = rMap.GetIMapObjectCount();
571 75 : for( std::size_t 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 75 : }
579 :
580 255 : SvUnoImageMap::~SvUnoImageMap()
581 : {
582 85 : std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
583 85 : const std::list< SvUnoImageMapObject* >::iterator aEnd = maObjectList.end();
584 171 : while( aIter != aEnd )
585 : {
586 1 : (*aIter++)->release();
587 : }
588 170 : }
589 :
590 1 : SvUnoImageMapObject* SvUnoImageMap::getObject( const Any& aElement )
591 : throw( IllegalArgumentException )
592 : {
593 1 : Reference< XInterface > xObject;
594 1 : aElement >>= xObject;
595 :
596 1 : SvUnoImageMapObject* pObject = SvUnoImageMapObject::getImplementation( xObject );
597 1 : if( NULL == pObject )
598 0 : throw IllegalArgumentException();
599 :
600 1 : return pObject;
601 : }
602 :
603 : // XIndexContainer
604 1 : void SAL_CALL SvUnoImageMap::insertByIndex( sal_Int32 Index, const Any& Element )
605 : throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
606 : {
607 1 : SvUnoImageMapObject* pObject = getObject( Element );
608 1 : const sal_Int32 nCount = maObjectList.size();
609 1 : if( NULL == pObject || Index > nCount )
610 0 : throw IndexOutOfBoundsException();
611 :
612 1 : pObject->acquire();
613 :
614 1 : if( Index == nCount )
615 1 : 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 1 : }
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 1 : sal_Int32 SAL_CALL SvUnoImageMap::getCount( ) throw(RuntimeException, std::exception)
666 : {
667 1 : 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 cppu::UnoType<XPropertySet>::get();
688 : }
689 :
690 84 : sal_Bool SAL_CALL SvUnoImageMap::hasElements( ) throw(RuntimeException, std::exception)
691 : {
692 84 : 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 1 : bool SvUnoImageMap::fillImageMap( ImageMap& rMap ) const
716 : {
717 1 : rMap.ClearImageMap();
718 :
719 1 : rMap.SetName( maName );
720 :
721 1 : std::list< SvUnoImageMapObject* >::const_iterator aIter = maObjectList.begin();
722 1 : const std::list< SvUnoImageMapObject* >::const_iterator aEnd = maObjectList.end();
723 3 : while( aIter != aEnd )
724 : {
725 1 : IMapObject* pNewMapObject = (*aIter)->createIMapObject();
726 1 : rMap.InsertIMapObject( *pNewMapObject );
727 1 : delete pNewMapObject;
728 :
729 1 : ++aIter;
730 : }
731 :
732 1 : return true;
733 : }
734 :
735 :
736 : // factory helper methods
737 :
738 :
739 1 : Reference< XInterface > SvUnoImageMapRectangleObject_createInstance( const SvEventDescription* pSupportedMacroItems )
740 : {
741 1 : return static_cast<XWeak*>(new SvUnoImageMapObject( IMAP_OBJ_RECTANGLE, pSupportedMacroItems ));
742 : }
743 :
744 1 : Reference< XInterface > SvUnoImageMapCircleObject_createInstance( const SvEventDescription* pSupportedMacroItems )
745 : {
746 1 : return static_cast<XWeak*>(new SvUnoImageMapObject( IMAP_OBJ_CIRCLE, pSupportedMacroItems ));
747 : }
748 :
749 2 : Reference< XInterface > SvUnoImageMapPolygonObject_createInstance( const SvEventDescription* pSupportedMacroItems )
750 : {
751 2 : return static_cast<XWeak*>(new SvUnoImageMapObject( IMAP_OBJ_POLYGON, pSupportedMacroItems ));
752 : }
753 :
754 10 : Reference< XInterface > SvUnoImageMap_createInstance( const SvEventDescription* pSupportedMacroItems )
755 : {
756 10 : return static_cast<XWeak*>(new SvUnoImageMap( pSupportedMacroItems ));
757 : }
758 :
759 75 : Reference< XInterface > SvUnoImageMap_createInstance( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems )
760 : {
761 75 : return static_cast<XWeak*>(new SvUnoImageMap( rMap, pSupportedMacroItems ));
762 : }
763 :
764 1 : bool SvUnoImageMap_fillImageMap( Reference< XInterface > xImageMap, ImageMap& rMap )
765 : {
766 1 : SvUnoImageMap* pUnoImageMap = SvUnoImageMap::getImplementation( xImageMap );
767 1 : if( NULL == pUnoImageMap )
768 0 : return false;
769 :
770 1 : return pUnoImageMap->fillImageMap( rMap );
771 : }
772 :
773 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|