GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / uno / unoimap.cxx
blobd128c9f86752b5e395c9dad9f6849d8d53f41126
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 #ifndef SEQTYPE
46 #if defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)
47 #define SEQTYPE(x) (new ::com::sun::star::uno::Type( x ))
48 #else
49 #define SEQTYPE(x) &(x)
50 #endif
51 #endif
53 #define MAP_LEN(x) x, sizeof(x)-1
56 using namespace comphelper;
57 using namespace cppu;
58 using namespace com::sun::star;
59 using namespace com::sun::star::uno;
60 using namespace com::sun::star::lang;
61 using namespace com::sun::star::container;
62 using namespace com::sun::star::beans;
63 using namespace com::sun::star::document;
64 using namespace com::sun::star::drawing;
66 const sal_Int32 HANDLE_URL = 1;
67 const sal_Int32 HANDLE_DESCRIPTION = 2;
68 const sal_Int32 HANDLE_TARGET = 3;
69 const sal_Int32 HANDLE_NAME = 4;
70 const sal_Int32 HANDLE_ISACTIVE = 5;
71 const sal_Int32 HANDLE_POLYGON = 6;
72 const sal_Int32 HANDLE_CENTER = 7;
73 const sal_Int32 HANDLE_RADIUS = 8;
74 const sal_Int32 HANDLE_BOUNDARY = 9;
75 const sal_Int32 HANDLE_TITLE = 10;
77 class SvUnoImageMapObject : public OWeakAggObject,
78 public XEventsSupplier,
79 public XServiceInfo,
80 public PropertySetHelper,
81 public XTypeProvider,
82 public XUnoTunnel
84 public:
85 SvUnoImageMapObject( sal_uInt16 nType, const SvEventDescription* pSupportedMacroItems );
86 SvUnoImageMapObject( const IMapObject& rMapObject, const SvEventDescription* pSupportedMacroItems );
87 virtual ~SvUnoImageMapObject() throw();
89 UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMapObject )
91 IMapObject* createIMapObject() const;
93 SvMacroTableEventDescriptor* mpEvents;
95 // overiden helpers from PropertySetHelper
96 virtual void _setPropertyValues( const PropertyMapEntry** ppEntries, const Any* pValues ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException );
97 virtual void _getPropertyValues( const PropertyMapEntry** ppEntries, Any* pValue ) throw(UnknownPropertyException, WrappedTargetException );
99 // XInterface
100 virtual Any SAL_CALL queryAggregation( const Type & rType ) throw(RuntimeException);
101 virtual Any SAL_CALL queryInterface( const Type & rType ) throw(RuntimeException);
102 virtual void SAL_CALL acquire() throw();
103 virtual void SAL_CALL release() throw();
105 // XTypeProvider
106 virtual Sequence< Type > SAL_CALL getTypes( ) throw(RuntimeException);
107 virtual Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw(RuntimeException);
109 // XEventsSupplier
110 virtual Reference< ::com::sun::star::container::XNameReplace > SAL_CALL getEvents( ) throw(RuntimeException);
112 // XServiceInfo
113 virtual OUString SAL_CALL getImplementationName( ) throw( RuntimeException );
114 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( RuntimeException );
115 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw( RuntimeException );
117 private:
118 static PropertySetInfo* createPropertySetInfo( sal_uInt16 nType );
121 sal_uInt16 mnType;
123 OUString maURL;
124 OUString maAltText;
125 OUString maDesc;
126 OUString maTarget;
127 OUString maName;
128 sal_Bool mbIsActive;
129 awt::Rectangle maBoundary;
130 awt::Point maCenter;
131 sal_Int32 mnRadius;
132 PointSequence maPolygon;
135 UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMapObject );
137 PropertySetInfo* SvUnoImageMapObject::createPropertySetInfo( sal_uInt16 nType )
139 switch( nType )
141 case IMAP_OBJ_POLYGON:
143 static PropertyMapEntry aPolygonObj_Impl[] =
145 { MAP_LEN( "URL" ), HANDLE_URL, &::getCppuType((const OUString*)0), 0, 0 },
146 { MAP_LEN( "Title" ), HANDLE_TITLE, &::getCppuType((const OUString*)0), 0, 0 },
147 { MAP_LEN( "Description" ), HANDLE_DESCRIPTION, &::getCppuType((const OUString*)0), 0, 0 },
148 { MAP_LEN( "Target" ), HANDLE_TARGET, &::getCppuType((const OUString*)0), 0, 0 },
149 { MAP_LEN( "Name" ), HANDLE_NAME, &::getCppuType((const OUString*)0), 0, 0 },
150 { MAP_LEN( "IsActive" ), HANDLE_ISACTIVE, &::getBooleanCppuType(), 0, 0 },
151 { MAP_LEN( "Polygon" ), HANDLE_POLYGON, SEQTYPE(::getCppuType((const PointSequence*)0)), 0, 0 },
152 {0,0,0,0,0,0}
155 return new PropertySetInfo( aPolygonObj_Impl );
157 case IMAP_OBJ_CIRCLE:
159 static PropertyMapEntry aCircleObj_Impl[] =
161 { MAP_LEN( "URL" ), HANDLE_URL, &::getCppuType((const OUString*)0), 0, 0 },
162 { MAP_LEN( "Title" ), HANDLE_TITLE, &::getCppuType((const OUString*)0), 0, 0 },
163 { MAP_LEN( "Description" ), HANDLE_DESCRIPTION, &::getCppuType((const OUString*)0), 0, 0 },
164 { MAP_LEN( "Target" ), HANDLE_TARGET, &::getCppuType((const OUString*)0), 0, 0 },
165 { MAP_LEN( "Name" ), HANDLE_NAME, &::getCppuType((const OUString*)0), 0, 0 },
166 { MAP_LEN( "IsActive" ), HANDLE_ISACTIVE, &::getBooleanCppuType(), 0, 0 },
167 { MAP_LEN( "Center" ), HANDLE_CENTER, &::getCppuType((const awt::Point*)0), 0, 0 },
168 { MAP_LEN( "Radius" ), HANDLE_RADIUS, &::getCppuType((const sal_Int32*)0), 0, 0 },
169 {0,0,0,0,0,0}
172 return new PropertySetInfo( aCircleObj_Impl );
174 case IMAP_OBJ_RECTANGLE:
175 default:
177 static PropertyMapEntry aRectangleObj_Impl[] =
179 { MAP_LEN( "URL" ), HANDLE_URL, &::getCppuType((const OUString*)0), 0, 0 },
180 { MAP_LEN( "Title" ), HANDLE_TITLE, &::getCppuType((const OUString*)0), 0, 0 },
181 { MAP_LEN( "Description" ), HANDLE_DESCRIPTION, &::getCppuType((const OUString*)0), 0, 0 },
182 { MAP_LEN( "Target" ), HANDLE_TARGET, &::getCppuType((const OUString*)0), 0, 0 },
183 { MAP_LEN( "Name" ), HANDLE_NAME, &::getCppuType((const OUString*)0), 0, 0 },
184 { MAP_LEN( "IsActive" ), HANDLE_ISACTIVE, &::getBooleanCppuType(), 0, 0 },
185 { MAP_LEN( "Boundary" ), HANDLE_BOUNDARY, &::getCppuType((const awt::Rectangle*)0), 0, 0 },
186 {0,0,0,0,0,0}
189 return new PropertySetInfo( aRectangleObj_Impl );
194 SvUnoImageMapObject::SvUnoImageMapObject( sal_uInt16 nType, const SvEventDescription* pSupportedMacroItems )
195 : PropertySetHelper( createPropertySetInfo( nType ) ),
196 mnType( nType )
197 , mbIsActive( true )
198 , mnRadius( 0 )
200 mpEvents = new SvMacroTableEventDescriptor( pSupportedMacroItems );
201 mpEvents->acquire();
204 SvUnoImageMapObject::SvUnoImageMapObject( const IMapObject& rMapObject, const SvEventDescription* pSupportedMacroItems )
205 : PropertySetHelper( createPropertySetInfo( rMapObject.GetType() ) ),
206 mnType( rMapObject.GetType() )
207 , mbIsActive( true )
208 , mnRadius( 0 )
210 maURL = rMapObject.GetURL();
211 maAltText = rMapObject.GetAltText();
212 maDesc = rMapObject.GetDesc();
213 maTarget = rMapObject.GetTarget();
214 maName = rMapObject.GetName();
215 mbIsActive = rMapObject.IsActive();
217 switch( mnType )
219 case IMAP_OBJ_RECTANGLE:
221 const Rectangle aRect( ((IMapRectangleObject*)&rMapObject)->GetRectangle(sal_False) );
222 maBoundary.X = aRect.Left();
223 maBoundary.Y = aRect.Top();
224 maBoundary.Width = aRect.GetWidth();
225 maBoundary.Height = aRect.GetHeight();
227 break;
228 case IMAP_OBJ_CIRCLE:
230 mnRadius = (sal_Int32)((IMapCircleObject*)&rMapObject)->GetRadius(sal_False);
231 const Point aPoint( ((IMapCircleObject*)&rMapObject)->GetCenter(sal_False) );
233 maCenter.X = aPoint.X();
234 maCenter.Y = aPoint.Y();
236 break;
237 case IMAP_OBJ_POLYGON:
238 default:
240 const Polygon aPoly( ((IMapPolygonObject*)&rMapObject)->GetPolygon(sal_False) );
242 const sal_uInt16 nCount = aPoly.GetSize();
243 maPolygon.realloc( nCount );
244 awt::Point* pPoints = maPolygon.getArray();
246 for( sal_uInt16 nPoint = 0; nPoint < nCount; nPoint++ )
248 const Point& rPoint = aPoly.GetPoint( nPoint );
249 pPoints->X = rPoint.X();
250 pPoints->Y = rPoint.Y();
252 pPoints++;
257 mpEvents = new SvMacroTableEventDescriptor( rMapObject.GetMacroTable(), pSupportedMacroItems );
258 mpEvents->acquire();
261 SvUnoImageMapObject::~SvUnoImageMapObject() throw()
263 mpEvents->release();
266 IMapObject* SvUnoImageMapObject::createIMapObject() const
268 const OUString aURL( maURL );
269 const OUString aAltText( maAltText );
270 const OUString aDesc( maDesc );
271 const OUString aTarget( maTarget );
272 const OUString aName( maName );
274 IMapObject* pNewIMapObject;
276 switch( mnType )
278 case IMAP_OBJ_RECTANGLE:
280 const Rectangle aRect( maBoundary.X, maBoundary.Y, maBoundary.X + maBoundary.Width - 1, maBoundary.Y + maBoundary.Height - 1 );
281 pNewIMapObject = new IMapRectangleObject( aRect, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, sal_False );
283 break;
285 case IMAP_OBJ_CIRCLE:
287 const Point aCenter( maCenter.X, maCenter.Y );
288 pNewIMapObject = new IMapCircleObject( aCenter, mnRadius, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, sal_False );
290 break;
292 case IMAP_OBJ_POLYGON:
293 default:
295 const sal_uInt16 nCount = (sal_uInt16)maPolygon.getLength();
297 Polygon aPoly( nCount );
298 for( sal_uInt16 nPoint = 0; nPoint < nCount; nPoint++ )
300 Point aPoint( maPolygon[nPoint].X, maPolygon[nPoint].Y );
301 aPoly.SetPoint( aPoint, nPoint );
304 aPoly.Optimize( POLY_OPTIMIZE_CLOSE );
305 pNewIMapObject = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, sal_False );
307 break;
310 SvxMacroTableDtor aMacroTable;
311 mpEvents->copyMacrosIntoTable(aMacroTable);
312 pNewIMapObject->SetMacroTable( aMacroTable );
314 return pNewIMapObject;
317 // XInterface
319 Any SAL_CALL SvUnoImageMapObject::queryInterface( const Type & rType )
320 throw( RuntimeException )
322 return OWeakAggObject::queryInterface( rType );
325 Any SAL_CALL SvUnoImageMapObject::queryAggregation( const Type & rType )
326 throw(RuntimeException)
328 Any aAny;
330 if( rType == ::getCppuType((const Reference< XServiceInfo >*)0) )
331 aAny <<= Reference< XServiceInfo >(this);
332 else if( rType == ::getCppuType((const Reference< XTypeProvider >*)0) )
333 aAny <<= Reference< XTypeProvider >(this);
334 else if( rType == ::getCppuType((const Reference< XPropertySet >*)0) )
335 aAny <<= Reference< XPropertySet >(this);
336 else if( rType == ::getCppuType((const Reference< XEventsSupplier >*)0) )
337 aAny <<= Reference< XEventsSupplier >(this);
338 else if( rType == ::getCppuType((const Reference< XMultiPropertySet >*)0) )
339 aAny <<= Reference< XMultiPropertySet >(this);
340 else if( rType == ::getCppuType((const Reference< XUnoTunnel >*)0) )
341 aAny <<= Reference< XUnoTunnel >(this);
342 else
343 aAny <<= OWeakAggObject::queryAggregation( rType );
345 return aAny;
348 void SAL_CALL SvUnoImageMapObject::acquire() throw()
350 OWeakAggObject::acquire();
353 void SAL_CALL SvUnoImageMapObject::release() throw()
355 OWeakAggObject::release();
358 uno::Sequence< uno::Type > SAL_CALL SvUnoImageMapObject::getTypes()
359 throw (uno::RuntimeException)
361 uno::Sequence< uno::Type > aTypes( 7 );
362 uno::Type* pTypes = aTypes.getArray();
364 *pTypes++ = ::getCppuType((const uno::Reference< XAggregation>*)0);
365 *pTypes++ = ::getCppuType((const uno::Reference< XEventsSupplier>*)0);
366 *pTypes++ = ::getCppuType((const uno::Reference< XServiceInfo>*)0);
367 *pTypes++ = ::getCppuType((const uno::Reference< XPropertySet>*)0);
368 *pTypes++ = ::getCppuType((const uno::Reference< XMultiPropertySet>*)0);
369 *pTypes++ = ::getCppuType((const uno::Reference< XTypeProvider>*)0);
370 *pTypes++ = ::getCppuType((const uno::Reference< XUnoTunnel>*)0);
372 return aTypes;
375 namespace
377 class theSvUnoImageMapObjectImplementationId : public rtl::Static< UnoTunnelIdInit, theSvUnoImageMapObjectImplementationId > {};
380 uno::Sequence< sal_Int8 > SAL_CALL SvUnoImageMapObject::getImplementationId()
381 throw (uno::RuntimeException)
383 return theSvUnoImageMapObjectImplementationId::get().getSeq();
386 // XServiceInfo
387 sal_Bool SAL_CALL SvUnoImageMapObject::supportsService( const OUString& ServiceName ) throw(RuntimeException)
389 return cppu::supportsService(this, ServiceName);
392 Sequence< OUString > SAL_CALL SvUnoImageMapObject::getSupportedServiceNames()
393 throw(RuntimeException)
395 Sequence< OUString > aSNS( 2 );
396 aSNS.getArray()[0] = "com.sun.star.image.ImageMapObject";
397 switch( mnType )
399 case IMAP_OBJ_POLYGON:
400 default:
401 aSNS.getArray()[1] = "com.sun.star.image.ImageMapPolygonObject";
402 break;
403 case IMAP_OBJ_RECTANGLE:
404 aSNS.getArray()[1] = "com.sun.star.image.ImageMapRectangleObject";
405 break;
406 case IMAP_OBJ_CIRCLE:
407 aSNS.getArray()[1] = "com.sun.star.image.ImageMapCircleObject";
408 break;
410 return aSNS;
413 OUString SAL_CALL SvUnoImageMapObject::getImplementationName() throw(RuntimeException)
415 switch( mnType )
417 case IMAP_OBJ_POLYGON:
418 default:
419 return OUString("org.openoffice.comp.svt.ImageMapPolygonObject");
420 case IMAP_OBJ_CIRCLE:
421 return OUString("org.openoffice.comp.svt.ImageMapCircleObject");
422 case IMAP_OBJ_RECTANGLE:
423 return OUString("org.openoffice.comp.svt.ImageMapRectangleObject");
427 // overiden helpers from PropertySetHelper
428 void SvUnoImageMapObject::_setPropertyValues( const PropertyMapEntry** ppEntries, const Any* pValues )
429 throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException )
431 sal_Bool bOk = sal_False;
433 while( *ppEntries )
435 switch( (*ppEntries)->mnHandle )
437 case HANDLE_URL:
438 bOk = *pValues >>= maURL;
439 break;
440 case HANDLE_TITLE:
441 bOk = *pValues >>= maAltText;
442 break;
443 case HANDLE_DESCRIPTION:
444 bOk = *pValues >>= maDesc;
445 break;
446 case HANDLE_TARGET:
447 bOk = *pValues >>= maTarget;
448 break;
449 case HANDLE_NAME:
450 bOk = *pValues >>= maName;
451 break;
452 case HANDLE_ISACTIVE:
453 bOk = *pValues >>= mbIsActive;
454 break;
455 case HANDLE_BOUNDARY:
456 bOk = *pValues >>= maBoundary;
457 break;
458 case HANDLE_CENTER:
459 bOk = *pValues >>= maCenter;
460 break;
461 case HANDLE_RADIUS:
462 bOk = *pValues >>= mnRadius;
463 break;
464 case HANDLE_POLYGON:
465 bOk = *pValues >>= maPolygon;
466 break;
467 default:
468 OSL_FAIL( "SvUnoImageMapObject::_setPropertyValues: unexpected property handle" );
469 break;
472 if( !bOk )
473 throw IllegalArgumentException();
475 ppEntries++;
476 pValues++;
480 void SvUnoImageMapObject::_getPropertyValues( const PropertyMapEntry** ppEntries, Any* pValues )
481 throw(UnknownPropertyException, WrappedTargetException )
483 while( *ppEntries )
485 switch( (*ppEntries)->mnHandle )
487 case HANDLE_URL:
488 *pValues <<= maURL;
489 break;
490 case HANDLE_TITLE:
491 *pValues <<= maAltText;
492 break;
493 case HANDLE_DESCRIPTION:
494 *pValues <<= maDesc;
495 break;
496 case HANDLE_TARGET:
497 *pValues <<= maTarget;
498 break;
499 case HANDLE_NAME:
500 *pValues <<= maName;
501 break;
502 case HANDLE_ISACTIVE:
503 *pValues <<= mbIsActive;
504 break;
505 case HANDLE_BOUNDARY:
506 *pValues <<= maBoundary;
507 break;
508 case HANDLE_CENTER:
509 *pValues <<= maCenter;
510 break;
511 case HANDLE_RADIUS:
512 *pValues <<= mnRadius;
513 break;
514 case HANDLE_POLYGON:
515 *pValues <<= maPolygon;
516 break;
517 default:
518 OSL_FAIL( "SvUnoImageMapObject::_getPropertyValues: unexpected property handle" );
519 break;
522 ppEntries++;
523 pValues++;
528 Reference< XNameReplace > SAL_CALL SvUnoImageMapObject::getEvents()
529 throw( RuntimeException )
531 // try weak reference first
532 Reference< XNameReplace > xEvents( mpEvents );
533 return xEvents;
536 ///////////////////////////////////////////////////////////////////////
538 class SvUnoImageMap : public WeakImplHelper3< XIndexContainer, XServiceInfo, XUnoTunnel >
540 public:
541 SvUnoImageMap( const SvEventDescription* pSupportedMacroItems );
542 SvUnoImageMap( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems );
543 virtual ~SvUnoImageMap();
545 sal_Bool fillImageMap( ImageMap& rMap ) const;
546 SvUnoImageMapObject* getObject( const Any& aElement ) const throw( IllegalArgumentException );
548 UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMap )
550 // XIndexContainer
551 virtual void SAL_CALL insertByIndex( sal_Int32 Index, const Any& Element ) throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException );
552 virtual void SAL_CALL removeByIndex( sal_Int32 Index ) throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException );
554 // XIndexReplace
555 virtual void SAL_CALL replaceByIndex( sal_Int32 Index, const Any& Element ) throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException );
557 // XIndexAccess
558 virtual sal_Int32 SAL_CALL getCount( ) throw( RuntimeException );
559 virtual Any SAL_CALL getByIndex( sal_Int32 Index ) throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException );
561 // XElementAccess
562 virtual Type SAL_CALL getElementType( ) throw( RuntimeException );
563 virtual sal_Bool SAL_CALL hasElements( ) throw( RuntimeException );
565 // XSerivceInfo
566 virtual OUString SAL_CALL getImplementationName( ) throw( RuntimeException );
567 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( RuntimeException );
568 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw( RuntimeException );
570 private:
571 OUString maName;
573 std::list< SvUnoImageMapObject* > maObjectList;
576 UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMap );
578 SvUnoImageMap::SvUnoImageMap( const SvEventDescription* )
582 SvUnoImageMap::SvUnoImageMap( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems )
584 maName = rMap.GetName();
586 const sal_uInt16 nCount = rMap.GetIMapObjectCount();
587 for( sal_uInt16 nPos = 0; nPos < nCount; nPos++ )
589 IMapObject* pMapObject = rMap.GetIMapObject( nPos );
590 SvUnoImageMapObject* pUnoObj = new SvUnoImageMapObject( *pMapObject, pSupportedMacroItems );
591 pUnoObj->acquire();
592 maObjectList.push_back( pUnoObj );
596 SvUnoImageMap::~SvUnoImageMap()
598 std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
599 const std::list< SvUnoImageMapObject* >::iterator aEnd = maObjectList.end();
600 while( aIter != aEnd )
602 (*aIter++)->release();
606 SvUnoImageMapObject* SvUnoImageMap::getObject( const Any& aElement ) const
607 throw( IllegalArgumentException )
609 Reference< XInterface > xObject;
610 aElement >>= xObject;
612 SvUnoImageMapObject* pObject = SvUnoImageMapObject::getImplementation( xObject );
613 if( NULL == pObject )
614 throw IllegalArgumentException();
616 return pObject;
619 // XIndexContainer
620 void SAL_CALL SvUnoImageMap::insertByIndex( sal_Int32 Index, const Any& Element )
621 throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
623 SvUnoImageMapObject* pObject = getObject( Element );
624 const sal_Int32 nCount = maObjectList.size();
625 if( NULL == pObject || Index > nCount )
626 throw IndexOutOfBoundsException();
628 pObject->acquire();
630 if( Index == nCount )
631 maObjectList.push_back( pObject );
632 else
634 std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
635 for( sal_Int32 n = 0; n < Index; n++ )
636 ++aIter;
638 maObjectList.insert( aIter, pObject );
642 void SAL_CALL SvUnoImageMap::removeByIndex( sal_Int32 nIndex ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
644 const sal_Int32 nCount = maObjectList.size();
645 if( nIndex >= nCount )
646 throw IndexOutOfBoundsException();
648 if( nCount - 1 == nIndex )
650 maObjectList.back()->release();
651 maObjectList.pop_back();
653 else
655 std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
656 std::advance(aIter, nIndex);
658 (*aIter)->release();
659 maObjectList.erase( aIter );
663 // XIndexReplace
664 void SAL_CALL SvUnoImageMap::replaceByIndex( sal_Int32 Index, const Any& Element ) throw(IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
666 SvUnoImageMapObject* pObject = getObject( Element );
667 const sal_Int32 nCount = maObjectList.size();
668 if( NULL == pObject || Index >= nCount )
669 throw IndexOutOfBoundsException();
671 std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
672 for( sal_Int32 n = 0; n < Index; n++ )
673 ++aIter;
675 (*aIter)->release();
676 *aIter = pObject;
677 pObject->acquire();
680 // XIndexAccess
681 sal_Int32 SAL_CALL SvUnoImageMap::getCount( ) throw(RuntimeException)
683 return maObjectList.size();
686 Any SAL_CALL SvUnoImageMap::getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
688 const sal_Int32 nCount = maObjectList.size();
689 if( Index >= nCount )
690 throw IndexOutOfBoundsException();
692 std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
693 for( sal_Int32 n = 0; n < Index; n++ )
694 ++aIter;
696 Reference< XPropertySet > xObj( *aIter );
697 return makeAny( xObj );
700 // XElementAccess
701 Type SAL_CALL SvUnoImageMap::getElementType( ) throw(RuntimeException)
703 return ::getCppuType((const Reference< XPropertySet >*)0);
706 sal_Bool SAL_CALL SvUnoImageMap::hasElements( ) throw(RuntimeException)
708 return (!maObjectList.empty());
711 // XSerivceInfo
712 OUString SAL_CALL SvUnoImageMap::getImplementationName( )
713 throw(RuntimeException)
715 return OUString( "org.openoffice.comp.svt.SvUnoImageMap" );
718 sal_Bool SAL_CALL SvUnoImageMap::supportsService( const OUString& ServiceName )
719 throw(RuntimeException)
721 const Sequence< OUString > aSNL( getSupportedServiceNames() );
722 const OUString * pArray = aSNL.getConstArray();
724 const sal_Int32 nCount = aSNL.getLength();
725 for( sal_Int32 i = 0; i < nCount; i++ )
726 if( pArray[i] == ServiceName )
727 return sal_True;
729 return sal_False;
732 Sequence< OUString > SAL_CALL SvUnoImageMap::getSupportedServiceNames( )
733 throw(RuntimeException)
735 const OUString aSN( "com.sun.star.image.ImageMap" );
736 return Sequence< OUString >( &aSN, 1 );
739 sal_Bool SvUnoImageMap::fillImageMap( ImageMap& rMap ) const
741 rMap.ClearImageMap();
743 rMap.SetName( maName );
745 std::list< SvUnoImageMapObject* >::const_iterator aIter = maObjectList.begin();
746 const std::list< SvUnoImageMapObject* >::const_iterator aEnd = maObjectList.end();
747 while( aIter != aEnd )
749 IMapObject* pNewMapObject = (*aIter)->createIMapObject();
750 rMap.InsertIMapObject( *pNewMapObject );
751 delete pNewMapObject;
753 ++aIter;
756 return sal_True;
759 // -------------------------------------------------------------------
760 // factory helper methods
761 // -------------------------------------------------------------------
763 Reference< XInterface > SvUnoImageMapRectangleObject_createInstance( const SvEventDescription* pSupportedMacroItems )
765 return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_RECTANGLE, pSupportedMacroItems );
768 Reference< XInterface > SvUnoImageMapCircleObject_createInstance( const SvEventDescription* pSupportedMacroItems )
770 return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_CIRCLE, pSupportedMacroItems );
773 Reference< XInterface > SvUnoImageMapPolygonObject_createInstance( const SvEventDescription* pSupportedMacroItems )
775 return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_POLYGON, pSupportedMacroItems );
778 Reference< XInterface > SvUnoImageMap_createInstance( const SvEventDescription* pSupportedMacroItems )
780 return (XWeak*)new SvUnoImageMap( pSupportedMacroItems );
783 Reference< XInterface > SvUnoImageMap_createInstance( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems )
785 return (XWeak*)new SvUnoImageMap( rMap, pSupportedMacroItems );
788 sal_Bool SvUnoImageMap_fillImageMap( Reference< XInterface > xImageMap, ImageMap& rMap )
790 SvUnoImageMap* pUnoImageMap = SvUnoImageMap::getImplementation( xImageMap );
791 if( NULL == pUnoImageMap )
792 return sal_False;
794 return pUnoImageMap->fillImageMap( rMap );
797 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */