fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svtools / source / uno / unoimap.cxx
blobba7be37d202077e9251972e3f231ab5f85151511
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
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;
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;
66 class SvUnoImageMapObject : public OWeakAggObject,
67 public XEventsSupplier,
68 public XServiceInfo,
69 public PropertySetHelper,
70 public XTypeProvider,
71 public XUnoTunnel
73 public:
74 SvUnoImageMapObject( sal_uInt16 nType, const SvEventDescription* pSupportedMacroItems );
75 SvUnoImageMapObject( const IMapObject& rMapObject, const SvEventDescription* pSupportedMacroItems );
76 virtual ~SvUnoImageMapObject() throw();
78 UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMapObject )
80 IMapObject* createIMapObject() const;
82 SvMacroTableEventDescriptor* mpEvents;
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;
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;
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;
98 // XEventsSupplier
99 virtual Reference< ::com::sun::star::container::XNameReplace > SAL_CALL getEvents( ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
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;
106 private:
107 static PropertySetInfo* createPropertySetInfo( sal_uInt16 nType );
110 sal_uInt16 mnType;
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;
124 UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMapObject );
126 PropertySetInfo * SvUnoImageMapObject::createPropertySetInfo( sal_uInt16 nType )
128 switch( nType )
130 case IMAP_OBJ_POLYGON:
132 static PropertyMapEntry const aPolygonObj_Impl[] =
134 { OUString("URL"), HANDLE_URL, cppu::UnoType<OUString>::get(), 0, 0 },
135 { OUString("Title"), HANDLE_TITLE, cppu::UnoType<OUString>::get(), 0, 0 },
136 { OUString("Description"), HANDLE_DESCRIPTION, cppu::UnoType<OUString>::get(), 0, 0 },
137 { OUString("Target"), HANDLE_TARGET, cppu::UnoType<OUString>::get(), 0, 0 },
138 { OUString("Name"), HANDLE_NAME, cppu::UnoType<OUString>::get(), 0, 0 },
139 { OUString("IsActive"), HANDLE_ISACTIVE, cppu::UnoType<bool>::get(), 0, 0 },
140 { OUString("Polygon"), HANDLE_POLYGON, cppu::UnoType<PointSequence>::get(), 0, 0 },
141 { OUString(), 0, css::uno::Type(), 0, 0 }
144 return new PropertySetInfo( aPolygonObj_Impl );
146 case IMAP_OBJ_CIRCLE:
148 static PropertyMapEntry const aCircleObj_Impl[] =
150 { OUString("URL"), HANDLE_URL, cppu::UnoType<OUString>::get(), 0, 0 },
151 { OUString("Title"), HANDLE_TITLE, cppu::UnoType<OUString>::get(), 0, 0 },
152 { OUString("Description"), HANDLE_DESCRIPTION, cppu::UnoType<OUString>::get(), 0, 0 },
153 { OUString("Target"), HANDLE_TARGET, cppu::UnoType<OUString>::get(), 0, 0 },
154 { OUString("Name"), HANDLE_NAME, cppu::UnoType<OUString>::get(), 0, 0 },
155 { OUString("IsActive"), HANDLE_ISACTIVE, cppu::UnoType<bool>::get(), 0, 0 },
156 { OUString("Center"), HANDLE_CENTER, cppu::UnoType<awt::Point>::get(), 0, 0 },
157 { OUString("Radius"), HANDLE_RADIUS, cppu::UnoType<sal_Int32>::get(), 0, 0 },
158 { OUString(), 0, css::uno::Type(), 0, 0 }
161 return new PropertySetInfo( aCircleObj_Impl );
163 case IMAP_OBJ_RECTANGLE:
164 default:
166 static PropertyMapEntry const aRectangleObj_Impl[] =
168 { OUString("URL"), HANDLE_URL, cppu::UnoType<OUString>::get(), 0, 0 },
169 { OUString("Title"), HANDLE_TITLE, cppu::UnoType<OUString>::get(), 0, 0 },
170 { OUString("Description"), HANDLE_DESCRIPTION, cppu::UnoType<OUString>::get(), 0, 0 },
171 { OUString("Target"), HANDLE_TARGET, cppu::UnoType<OUString>::get(), 0, 0 },
172 { OUString("Name"), HANDLE_NAME, cppu::UnoType<OUString>::get(), 0, 0 },
173 { OUString("IsActive"), HANDLE_ISACTIVE, cppu::UnoType<bool>::get(), 0, 0 },
174 { OUString("Boundary"), HANDLE_BOUNDARY, cppu::UnoType<awt::Rectangle>::get(), 0, 0 },
175 { OUString(), 0, css::uno::Type(), 0, 0 }
178 return new PropertySetInfo( aRectangleObj_Impl );
183 SvUnoImageMapObject::SvUnoImageMapObject( sal_uInt16 nType, const SvEventDescription* pSupportedMacroItems )
184 : PropertySetHelper( createPropertySetInfo( nType ) ),
185 mnType( nType )
186 , mbIsActive( true )
187 , mnRadius( 0 )
189 mpEvents = new SvMacroTableEventDescriptor( pSupportedMacroItems );
190 mpEvents->acquire();
193 SvUnoImageMapObject::SvUnoImageMapObject( const IMapObject& rMapObject, const SvEventDescription* pSupportedMacroItems )
194 : PropertySetHelper( createPropertySetInfo( rMapObject.GetType() ) ),
195 mnType( rMapObject.GetType() )
196 , mbIsActive( true )
197 , mnRadius( 0 )
199 maURL = rMapObject.GetURL();
200 maAltText = rMapObject.GetAltText();
201 maDesc = rMapObject.GetDesc();
202 maTarget = rMapObject.GetTarget();
203 maName = rMapObject.GetName();
204 mbIsActive = rMapObject.IsActive();
206 switch( mnType )
208 case IMAP_OBJ_RECTANGLE:
210 const Rectangle aRect( static_cast<const IMapRectangleObject*>(&rMapObject)->GetRectangle(false) );
211 maBoundary.X = aRect.Left();
212 maBoundary.Y = aRect.Top();
213 maBoundary.Width = aRect.GetWidth();
214 maBoundary.Height = aRect.GetHeight();
216 break;
217 case IMAP_OBJ_CIRCLE:
219 mnRadius = (sal_Int32)static_cast<const IMapCircleObject*>(&rMapObject)->GetRadius(false);
220 const Point aPoint( static_cast<const IMapCircleObject*>(&rMapObject)->GetCenter(false) );
222 maCenter.X = aPoint.X();
223 maCenter.Y = aPoint.Y();
225 break;
226 case IMAP_OBJ_POLYGON:
227 default:
229 const Polygon aPoly( static_cast<const IMapPolygonObject*>(&rMapObject)->GetPolygon(false) );
231 const sal_uInt16 nCount = aPoly.GetSize();
232 maPolygon.realloc( nCount );
233 awt::Point* pPoints = maPolygon.getArray();
235 for( sal_uInt16 nPoint = 0; nPoint < nCount; nPoint++ )
237 const Point& rPoint = aPoly.GetPoint( nPoint );
238 pPoints->X = rPoint.X();
239 pPoints->Y = rPoint.Y();
241 pPoints++;
246 mpEvents = new SvMacroTableEventDescriptor( rMapObject.GetMacroTable(), pSupportedMacroItems );
247 mpEvents->acquire();
250 SvUnoImageMapObject::~SvUnoImageMapObject() throw()
252 mpEvents->release();
255 IMapObject* SvUnoImageMapObject::createIMapObject() const
257 const OUString aURL( maURL );
258 const OUString aAltText( maAltText );
259 const OUString aDesc( maDesc );
260 const OUString aTarget( maTarget );
261 const OUString aName( maName );
263 IMapObject* pNewIMapObject;
265 switch( mnType )
267 case IMAP_OBJ_RECTANGLE:
269 const Rectangle aRect( maBoundary.X, maBoundary.Y, maBoundary.X + maBoundary.Width - 1, maBoundary.Y + maBoundary.Height - 1 );
270 pNewIMapObject = new IMapRectangleObject( aRect, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false );
272 break;
274 case IMAP_OBJ_CIRCLE:
276 const Point aCenter( maCenter.X, maCenter.Y );
277 pNewIMapObject = new IMapCircleObject( aCenter, mnRadius, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false );
279 break;
281 case IMAP_OBJ_POLYGON:
282 default:
284 const sal_uInt16 nCount = (sal_uInt16)maPolygon.getLength();
286 Polygon aPoly( nCount );
287 for( sal_uInt16 nPoint = 0; nPoint < nCount; nPoint++ )
289 Point aPoint( maPolygon[nPoint].X, maPolygon[nPoint].Y );
290 aPoly.SetPoint( aPoint, nPoint );
293 aPoly.Optimize( PolyOptimizeFlags::CLOSE );
294 pNewIMapObject = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false );
296 break;
299 SvxMacroTableDtor aMacroTable;
300 mpEvents->copyMacrosIntoTable(aMacroTable);
301 pNewIMapObject->SetMacroTable( aMacroTable );
303 return pNewIMapObject;
306 // XInterface
308 Any SAL_CALL SvUnoImageMapObject::queryInterface( const Type & rType )
309 throw( RuntimeException, std::exception )
311 return OWeakAggObject::queryInterface( rType );
314 Any SAL_CALL SvUnoImageMapObject::queryAggregation( const Type & rType )
315 throw(RuntimeException, std::exception)
317 Any aAny;
319 if( rType == cppu::UnoType<XServiceInfo>::get())
320 aAny <<= Reference< XServiceInfo >(this);
321 else if( rType == cppu::UnoType<XTypeProvider>::get())
322 aAny <<= Reference< XTypeProvider >(this);
323 else if( rType == cppu::UnoType<XPropertySet>::get())
324 aAny <<= Reference< XPropertySet >(this);
325 else if( rType == cppu::UnoType<XEventsSupplier>::get())
326 aAny <<= Reference< XEventsSupplier >(this);
327 else if( rType == cppu::UnoType<XMultiPropertySet>::get())
328 aAny <<= Reference< XMultiPropertySet >(this);
329 else if( rType == cppu::UnoType<XUnoTunnel>::get())
330 aAny <<= Reference< XUnoTunnel >(this);
331 else
332 aAny <<= OWeakAggObject::queryAggregation( rType );
334 return aAny;
337 void SAL_CALL SvUnoImageMapObject::acquire() throw()
339 OWeakAggObject::acquire();
342 void SAL_CALL SvUnoImageMapObject::release() throw()
344 OWeakAggObject::release();
347 uno::Sequence< uno::Type > SAL_CALL SvUnoImageMapObject::getTypes()
348 throw (uno::RuntimeException, std::exception)
350 uno::Sequence< uno::Type > aTypes( 7 );
351 uno::Type* pTypes = aTypes.getArray();
353 *pTypes++ = cppu::UnoType<XAggregation>::get();
354 *pTypes++ = cppu::UnoType<XEventsSupplier>::get();
355 *pTypes++ = cppu::UnoType<XServiceInfo>::get();
356 *pTypes++ = cppu::UnoType<XPropertySet>::get();
357 *pTypes++ = cppu::UnoType<XMultiPropertySet>::get();
358 *pTypes++ = cppu::UnoType<XTypeProvider>::get();
359 *pTypes++ = cppu::UnoType<XUnoTunnel>::get();
361 return aTypes;
364 uno::Sequence< sal_Int8 > SAL_CALL SvUnoImageMapObject::getImplementationId()
365 throw (uno::RuntimeException, std::exception)
367 return css::uno::Sequence<sal_Int8>();
370 // XServiceInfo
371 sal_Bool SAL_CALL SvUnoImageMapObject::supportsService( const OUString& ServiceName ) throw(RuntimeException, std::exception)
373 return cppu::supportsService(this, ServiceName);
376 Sequence< OUString > SAL_CALL SvUnoImageMapObject::getSupportedServiceNames()
377 throw(RuntimeException, std::exception)
379 Sequence< OUString > aSNS( 2 );
380 aSNS.getArray()[0] = "com.sun.star.image.ImageMapObject";
381 switch( mnType )
383 case IMAP_OBJ_POLYGON:
384 default:
385 aSNS.getArray()[1] = "com.sun.star.image.ImageMapPolygonObject";
386 break;
387 case IMAP_OBJ_RECTANGLE:
388 aSNS.getArray()[1] = "com.sun.star.image.ImageMapRectangleObject";
389 break;
390 case IMAP_OBJ_CIRCLE:
391 aSNS.getArray()[1] = "com.sun.star.image.ImageMapCircleObject";
392 break;
394 return aSNS;
397 OUString SAL_CALL SvUnoImageMapObject::getImplementationName() throw(RuntimeException, std::exception)
399 switch( mnType )
401 case IMAP_OBJ_POLYGON:
402 default:
403 return OUString("org.openoffice.comp.svt.ImageMapPolygonObject");
404 case IMAP_OBJ_CIRCLE:
405 return OUString("org.openoffice.comp.svt.ImageMapCircleObject");
406 case IMAP_OBJ_RECTANGLE:
407 return OUString("org.openoffice.comp.svt.ImageMapRectangleObject");
411 // overriden helpers from PropertySetHelper
412 void SvUnoImageMapObject::_setPropertyValues( const PropertyMapEntry** ppEntries, const Any* pValues )
413 throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException )
415 bool bOk = false;
417 while( *ppEntries )
419 switch( (*ppEntries)->mnHandle )
421 case HANDLE_URL:
422 bOk = *pValues >>= maURL;
423 break;
424 case HANDLE_TITLE:
425 bOk = *pValues >>= maAltText;
426 break;
427 case HANDLE_DESCRIPTION:
428 bOk = *pValues >>= maDesc;
429 break;
430 case HANDLE_TARGET:
431 bOk = *pValues >>= maTarget;
432 break;
433 case HANDLE_NAME:
434 bOk = *pValues >>= maName;
435 break;
436 case HANDLE_ISACTIVE:
437 bOk = *pValues >>= mbIsActive;
438 break;
439 case HANDLE_BOUNDARY:
440 bOk = *pValues >>= maBoundary;
441 break;
442 case HANDLE_CENTER:
443 bOk = *pValues >>= maCenter;
444 break;
445 case HANDLE_RADIUS:
446 bOk = *pValues >>= mnRadius;
447 break;
448 case HANDLE_POLYGON:
449 bOk = *pValues >>= maPolygon;
450 break;
451 default:
452 OSL_FAIL( "SvUnoImageMapObject::_setPropertyValues: unexpected property handle" );
453 break;
456 if( !bOk )
457 throw IllegalArgumentException();
459 ppEntries++;
460 pValues++;
464 void SvUnoImageMapObject::_getPropertyValues( const PropertyMapEntry** ppEntries, Any* pValues )
465 throw(UnknownPropertyException, WrappedTargetException )
467 while( *ppEntries )
469 switch( (*ppEntries)->mnHandle )
471 case HANDLE_URL:
472 *pValues <<= maURL;
473 break;
474 case HANDLE_TITLE:
475 *pValues <<= maAltText;
476 break;
477 case HANDLE_DESCRIPTION:
478 *pValues <<= maDesc;
479 break;
480 case HANDLE_TARGET:
481 *pValues <<= maTarget;
482 break;
483 case HANDLE_NAME:
484 *pValues <<= maName;
485 break;
486 case HANDLE_ISACTIVE:
487 *pValues <<= mbIsActive;
488 break;
489 case HANDLE_BOUNDARY:
490 *pValues <<= maBoundary;
491 break;
492 case HANDLE_CENTER:
493 *pValues <<= maCenter;
494 break;
495 case HANDLE_RADIUS:
496 *pValues <<= mnRadius;
497 break;
498 case HANDLE_POLYGON:
499 *pValues <<= maPolygon;
500 break;
501 default:
502 OSL_FAIL( "SvUnoImageMapObject::_getPropertyValues: unexpected property handle" );
503 break;
506 ppEntries++;
507 pValues++;
512 Reference< XNameReplace > SAL_CALL SvUnoImageMapObject::getEvents()
513 throw( RuntimeException, std::exception )
515 // try weak reference first
516 Reference< XNameReplace > xEvents( mpEvents );
517 return xEvents;
522 class SvUnoImageMap : public WeakImplHelper3< XIndexContainer, XServiceInfo, XUnoTunnel >
524 public:
525 SvUnoImageMap( const SvEventDescription* pSupportedMacroItems );
526 SvUnoImageMap( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems );
527 virtual ~SvUnoImageMap();
529 bool fillImageMap( ImageMap& rMap ) const;
530 static SvUnoImageMapObject* getObject( const Any& aElement ) throw( IllegalArgumentException );
532 UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMap )
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;
538 // XIndexReplace
539 virtual void SAL_CALL replaceByIndex( sal_Int32 Index, const Any& Element ) throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception ) SAL_OVERRIDE;
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;
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;
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;
554 private:
555 OUString maName;
557 std::list< SvUnoImageMapObject* > maObjectList;
560 UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMap );
562 SvUnoImageMap::SvUnoImageMap( const SvEventDescription* )
566 SvUnoImageMap::SvUnoImageMap( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems )
568 maName = rMap.GetName();
570 const std::size_t nCount = rMap.GetIMapObjectCount();
571 for( std::size_t nPos = 0; nPos < nCount; nPos++ )
573 IMapObject* pMapObject = rMap.GetIMapObject( nPos );
574 SvUnoImageMapObject* pUnoObj = new SvUnoImageMapObject( *pMapObject, pSupportedMacroItems );
575 pUnoObj->acquire();
576 maObjectList.push_back( pUnoObj );
580 SvUnoImageMap::~SvUnoImageMap()
582 std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
583 const std::list< SvUnoImageMapObject* >::iterator aEnd = maObjectList.end();
584 while( aIter != aEnd )
586 (*aIter++)->release();
590 SvUnoImageMapObject* SvUnoImageMap::getObject( const Any& aElement )
591 throw( IllegalArgumentException )
593 Reference< XInterface > xObject;
594 aElement >>= xObject;
596 SvUnoImageMapObject* pObject = SvUnoImageMapObject::getImplementation( xObject );
597 if( NULL == pObject )
598 throw IllegalArgumentException();
600 return pObject;
603 // XIndexContainer
604 void SAL_CALL SvUnoImageMap::insertByIndex( sal_Int32 Index, const Any& Element )
605 throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
607 SvUnoImageMapObject* pObject = getObject( Element );
608 const sal_Int32 nCount = maObjectList.size();
609 if( NULL == pObject || Index > nCount )
610 throw IndexOutOfBoundsException();
612 pObject->acquire();
614 if( Index == nCount )
615 maObjectList.push_back( pObject );
616 else
618 std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
619 for( sal_Int32 n = 0; n < Index; n++ )
620 ++aIter;
622 maObjectList.insert( aIter, pObject );
626 void SAL_CALL SvUnoImageMap::removeByIndex( sal_Int32 nIndex ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception)
628 const sal_Int32 nCount = maObjectList.size();
629 if( nIndex >= nCount )
630 throw IndexOutOfBoundsException();
632 if( nCount - 1 == nIndex )
634 maObjectList.back()->release();
635 maObjectList.pop_back();
637 else
639 std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
640 std::advance(aIter, nIndex);
642 (*aIter)->release();
643 maObjectList.erase( aIter );
647 // XIndexReplace
648 void SAL_CALL SvUnoImageMap::replaceByIndex( sal_Int32 Index, const Any& Element ) throw(IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception)
650 SvUnoImageMapObject* pObject = getObject( Element );
651 const sal_Int32 nCount = maObjectList.size();
652 if( NULL == pObject || Index >= nCount )
653 throw IndexOutOfBoundsException();
655 std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
656 for( sal_Int32 n = 0; n < Index; n++ )
657 ++aIter;
659 (*aIter)->release();
660 *aIter = pObject;
661 pObject->acquire();
664 // XIndexAccess
665 sal_Int32 SAL_CALL SvUnoImageMap::getCount( ) throw(RuntimeException, std::exception)
667 return maObjectList.size();
670 Any SAL_CALL SvUnoImageMap::getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception)
672 const sal_Int32 nCount = maObjectList.size();
673 if( Index >= nCount )
674 throw IndexOutOfBoundsException();
676 std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
677 for( sal_Int32 n = 0; n < Index; n++ )
678 ++aIter;
680 Reference< XPropertySet > xObj( *aIter );
681 return makeAny( xObj );
684 // XElementAccess
685 Type SAL_CALL SvUnoImageMap::getElementType( ) throw(RuntimeException, std::exception)
687 return cppu::UnoType<XPropertySet>::get();
690 sal_Bool SAL_CALL SvUnoImageMap::hasElements( ) throw(RuntimeException, std::exception)
692 return (!maObjectList.empty());
695 // XSerivceInfo
696 OUString SAL_CALL SvUnoImageMap::getImplementationName( )
697 throw(RuntimeException, std::exception)
699 return OUString( "org.openoffice.comp.svt.SvUnoImageMap" );
702 sal_Bool SAL_CALL SvUnoImageMap::supportsService( const OUString& ServiceName )
703 throw(RuntimeException, std::exception)
705 return cppu::supportsService(this, ServiceName);
708 Sequence< OUString > SAL_CALL SvUnoImageMap::getSupportedServiceNames( )
709 throw(RuntimeException, std::exception)
711 const OUString aSN( "com.sun.star.image.ImageMap" );
712 return Sequence< OUString >( &aSN, 1 );
715 bool SvUnoImageMap::fillImageMap( ImageMap& rMap ) const
717 rMap.ClearImageMap();
719 rMap.SetName( maName );
721 std::list< SvUnoImageMapObject* >::const_iterator aIter = maObjectList.begin();
722 const std::list< SvUnoImageMapObject* >::const_iterator aEnd = maObjectList.end();
723 while( aIter != aEnd )
725 IMapObject* pNewMapObject = (*aIter)->createIMapObject();
726 rMap.InsertIMapObject( *pNewMapObject );
727 delete pNewMapObject;
729 ++aIter;
732 return true;
736 // factory helper methods
739 Reference< XInterface > SvUnoImageMapRectangleObject_createInstance( const SvEventDescription* pSupportedMacroItems )
741 return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_RECTANGLE, pSupportedMacroItems );
744 Reference< XInterface > SvUnoImageMapCircleObject_createInstance( const SvEventDescription* pSupportedMacroItems )
746 return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_CIRCLE, pSupportedMacroItems );
749 Reference< XInterface > SvUnoImageMapPolygonObject_createInstance( const SvEventDescription* pSupportedMacroItems )
751 return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_POLYGON, pSupportedMacroItems );
754 Reference< XInterface > SvUnoImageMap_createInstance( const SvEventDescription* pSupportedMacroItems )
756 return (XWeak*)new SvUnoImageMap( pSupportedMacroItems );
759 Reference< XInterface > SvUnoImageMap_createInstance( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems )
761 return (XWeak*)new SvUnoImageMap( rMap, pSupportedMacroItems );
764 bool SvUnoImageMap_fillImageMap( Reference< XInterface > xImageMap, ImageMap& rMap )
766 SvUnoImageMap* pUnoImageMap = SvUnoImageMap::getImplementation( xImageMap );
767 if( NULL == pUnoImageMap )
768 return false;
770 return pUnoImageMap->fillImageMap( rMap );
773 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */