fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svtools / source / uno / unoimap.cxx
blobd08a734e26f389d8231e6efaefafdc033379c581
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 <list>
35 #include <osl/mutex.hxx>
36 #include <vcl/svapp.hxx>
37 #include <svtools/unoevent.hxx>
38 #include <svtools/unoimap.hxx>
39 #include <svtools/imap.hxx>
40 #include <svtools/imapcirc.hxx>
41 #include <svtools/imaprect.hxx>
42 #include <svtools/imappoly.hxx>
44 #ifndef SEQTYPE
45 #if defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)
46 #define SEQTYPE(x) (new ::com::sun::star::uno::Type( x ))
47 #else
48 #define SEQTYPE(x) &(x)
49 #endif
50 #endif
52 #define MAP_LEN(x) x, sizeof(x)-1
55 using namespace comphelper;
56 using namespace cppu;
57 using namespace com::sun::star;
58 using namespace com::sun::star::uno;
59 using namespace com::sun::star::lang;
60 using namespace com::sun::star::container;
61 using namespace com::sun::star::beans;
62 using namespace com::sun::star::document;
63 using namespace com::sun::star::drawing;
65 const sal_Int32 HANDLE_URL = 1;
66 const sal_Int32 HANDLE_DESCRIPTION = 2;
67 const sal_Int32 HANDLE_TARGET = 3;
68 const sal_Int32 HANDLE_NAME = 4;
69 const sal_Int32 HANDLE_ISACTIVE = 5;
70 const sal_Int32 HANDLE_POLYGON = 6;
71 const sal_Int32 HANDLE_CENTER = 7;
72 const sal_Int32 HANDLE_RADIUS = 8;
73 const sal_Int32 HANDLE_BOUNDARY = 9;
74 const sal_Int32 HANDLE_TITLE = 10;
76 class SvUnoImageMapObject : public OWeakAggObject,
77 public XEventsSupplier,
78 public XServiceInfo,
79 public PropertySetHelper,
80 public XTypeProvider,
81 public XUnoTunnel
83 public:
84 SvUnoImageMapObject( sal_uInt16 nType, const SvEventDescription* pSupportedMacroItems );
85 SvUnoImageMapObject( const IMapObject& rMapObject, const SvEventDescription* pSupportedMacroItems );
86 virtual ~SvUnoImageMapObject() throw();
88 UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMapObject )
90 IMapObject* createIMapObject() const;
92 SvMacroTableEventDescriptor* mpEvents;
94 // overiden helpers from PropertySetHelper
95 virtual void _setPropertyValues( const PropertyMapEntry** ppEntries, const Any* pValues ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException );
96 virtual void _getPropertyValues( const PropertyMapEntry** ppEntries, Any* pValue ) throw(UnknownPropertyException, WrappedTargetException );
98 // XInterface
99 virtual Any SAL_CALL queryAggregation( const Type & rType ) throw(RuntimeException);
100 virtual Any SAL_CALL queryInterface( const Type & rType ) throw(RuntimeException);
101 virtual void SAL_CALL acquire() throw();
102 virtual void SAL_CALL release() throw();
104 // XTypeProvider
105 virtual Sequence< Type > SAL_CALL getTypes( ) throw(RuntimeException);
106 virtual Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw(RuntimeException);
108 // XEventsSupplier
109 virtual Reference< ::com::sun::star::container::XNameReplace > SAL_CALL getEvents( ) throw(RuntimeException);
111 // XServiceInfo
112 virtual OUString SAL_CALL getImplementationName( ) throw( RuntimeException );
113 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( RuntimeException );
114 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw( RuntimeException );
116 private:
117 static PropertySetInfo* createPropertySetInfo( sal_uInt16 nType );
120 sal_uInt16 mnType;
122 OUString maURL;
123 OUString maAltText;
124 OUString maDesc;
125 OUString maTarget;
126 OUString maName;
127 sal_Bool mbIsActive;
128 awt::Rectangle maBoundary;
129 awt::Point maCenter;
130 sal_Int32 mnRadius;
131 PointSequence maPolygon;
134 UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMapObject );
136 PropertySetInfo* SvUnoImageMapObject::createPropertySetInfo( sal_uInt16 nType )
138 switch( nType )
140 case IMAP_OBJ_POLYGON:
142 static PropertyMapEntry aPolygonObj_Impl[] =
144 { MAP_LEN( "URL" ), HANDLE_URL, &::getCppuType((const OUString*)0), 0, 0 },
145 { MAP_LEN( "Title" ), HANDLE_TITLE, &::getCppuType((const OUString*)0), 0, 0 },
146 { MAP_LEN( "Description" ), HANDLE_DESCRIPTION, &::getCppuType((const OUString*)0), 0, 0 },
147 { MAP_LEN( "Target" ), HANDLE_TARGET, &::getCppuType((const OUString*)0), 0, 0 },
148 { MAP_LEN( "Name" ), HANDLE_NAME, &::getCppuType((const OUString*)0), 0, 0 },
149 { MAP_LEN( "IsActive" ), HANDLE_ISACTIVE, &::getBooleanCppuType(), 0, 0 },
150 { MAP_LEN( "Polygon" ), HANDLE_POLYGON, SEQTYPE(::getCppuType((const PointSequence*)0)), 0, 0 },
151 {0,0,0,0,0,0}
154 return new PropertySetInfo( aPolygonObj_Impl );
156 case IMAP_OBJ_CIRCLE:
158 static PropertyMapEntry aCircleObj_Impl[] =
160 { MAP_LEN( "URL" ), HANDLE_URL, &::getCppuType((const OUString*)0), 0, 0 },
161 { MAP_LEN( "Title" ), HANDLE_TITLE, &::getCppuType((const OUString*)0), 0, 0 },
162 { MAP_LEN( "Description" ), HANDLE_DESCRIPTION, &::getCppuType((const OUString*)0), 0, 0 },
163 { MAP_LEN( "Target" ), HANDLE_TARGET, &::getCppuType((const OUString*)0), 0, 0 },
164 { MAP_LEN( "Name" ), HANDLE_NAME, &::getCppuType((const OUString*)0), 0, 0 },
165 { MAP_LEN( "IsActive" ), HANDLE_ISACTIVE, &::getBooleanCppuType(), 0, 0 },
166 { MAP_LEN( "Center" ), HANDLE_CENTER, &::getCppuType((const awt::Point*)0), 0, 0 },
167 { MAP_LEN( "Radius" ), HANDLE_RADIUS, &::getCppuType((const sal_Int32*)0), 0, 0 },
168 {0,0,0,0,0,0}
171 return new PropertySetInfo( aCircleObj_Impl );
173 case IMAP_OBJ_RECTANGLE:
174 default:
176 static PropertyMapEntry aRectangleObj_Impl[] =
178 { MAP_LEN( "URL" ), HANDLE_URL, &::getCppuType((const OUString*)0), 0, 0 },
179 { MAP_LEN( "Title" ), HANDLE_TITLE, &::getCppuType((const OUString*)0), 0, 0 },
180 { MAP_LEN( "Description" ), HANDLE_DESCRIPTION, &::getCppuType((const OUString*)0), 0, 0 },
181 { MAP_LEN( "Target" ), HANDLE_TARGET, &::getCppuType((const OUString*)0), 0, 0 },
182 { MAP_LEN( "Name" ), HANDLE_NAME, &::getCppuType((const OUString*)0), 0, 0 },
183 { MAP_LEN( "IsActive" ), HANDLE_ISACTIVE, &::getBooleanCppuType(), 0, 0 },
184 { MAP_LEN( "Boundary" ), HANDLE_BOUNDARY, &::getCppuType((const awt::Rectangle*)0), 0, 0 },
185 {0,0,0,0,0,0}
188 return new PropertySetInfo( aRectangleObj_Impl );
193 SvUnoImageMapObject::SvUnoImageMapObject( sal_uInt16 nType, const SvEventDescription* pSupportedMacroItems )
194 : PropertySetHelper( createPropertySetInfo( nType ) ),
195 mnType( nType )
196 , mbIsActive( true )
197 , mnRadius( 0 )
199 mpEvents = new SvMacroTableEventDescriptor( pSupportedMacroItems );
200 mpEvents->acquire();
203 SvUnoImageMapObject::SvUnoImageMapObject( const IMapObject& rMapObject, const SvEventDescription* pSupportedMacroItems )
204 : PropertySetHelper( createPropertySetInfo( rMapObject.GetType() ) ),
205 mnType( rMapObject.GetType() )
206 , mbIsActive( true )
207 , mnRadius( 0 )
209 maURL = rMapObject.GetURL();
210 maAltText = rMapObject.GetAltText();
211 maDesc = rMapObject.GetDesc();
212 maTarget = rMapObject.GetTarget();
213 maName = rMapObject.GetName();
214 mbIsActive = rMapObject.IsActive();
216 switch( mnType )
218 case IMAP_OBJ_RECTANGLE:
220 const Rectangle aRect( ((IMapRectangleObject*)&rMapObject)->GetRectangle(sal_False) );
221 maBoundary.X = aRect.Left();
222 maBoundary.Y = aRect.Top();
223 maBoundary.Width = aRect.GetWidth();
224 maBoundary.Height = aRect.GetHeight();
226 break;
227 case IMAP_OBJ_CIRCLE:
229 mnRadius = (sal_Int32)((IMapCircleObject*)&rMapObject)->GetRadius(sal_False);
230 const Point aPoint( ((IMapCircleObject*)&rMapObject)->GetCenter(sal_False) );
232 maCenter.X = aPoint.X();
233 maCenter.Y = aPoint.Y();
235 break;
236 case IMAP_OBJ_POLYGON:
237 default:
239 const Polygon aPoly( ((IMapPolygonObject*)&rMapObject)->GetPolygon(sal_False) );
241 const sal_uInt16 nCount = aPoly.GetSize();
242 maPolygon.realloc( nCount );
243 awt::Point* pPoints = maPolygon.getArray();
245 for( sal_uInt16 nPoint = 0; nPoint < nCount; nPoint++ )
247 const Point& rPoint = aPoly.GetPoint( nPoint );
248 pPoints->X = rPoint.X();
249 pPoints->Y = rPoint.Y();
251 pPoints++;
256 mpEvents = new SvMacroTableEventDescriptor( rMapObject.GetMacroTable(), pSupportedMacroItems );
257 mpEvents->acquire();
260 SvUnoImageMapObject::~SvUnoImageMapObject() throw()
262 mpEvents->release();
265 IMapObject* SvUnoImageMapObject::createIMapObject() const
267 const String aURL( maURL );
268 const String aAltText( maAltText );
269 const String aDesc( maDesc );
270 const String aTarget( maTarget );
271 const String aName( maName );
273 IMapObject* pNewIMapObject;
275 switch( mnType )
277 case IMAP_OBJ_RECTANGLE:
279 const Rectangle aRect( maBoundary.X, maBoundary.Y, maBoundary.X + maBoundary.Width - 1, maBoundary.Y + maBoundary.Height - 1 );
280 pNewIMapObject = new IMapRectangleObject( aRect, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, sal_False );
282 break;
284 case IMAP_OBJ_CIRCLE:
286 const Point aCenter( maCenter.X, maCenter.Y );
287 pNewIMapObject = new IMapCircleObject( aCenter, mnRadius, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, sal_False );
289 break;
291 case IMAP_OBJ_POLYGON:
292 default:
294 const sal_uInt16 nCount = (sal_uInt16)maPolygon.getLength();
296 Polygon aPoly( nCount );
297 for( sal_uInt16 nPoint = 0; nPoint < nCount; nPoint++ )
299 Point aPoint( maPolygon[nPoint].X, maPolygon[nPoint].Y );
300 aPoly.SetPoint( aPoint, nPoint );
303 aPoly.Optimize( POLY_OPTIMIZE_CLOSE );
304 pNewIMapObject = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, sal_False );
306 break;
309 SvxMacroTableDtor aMacroTable;
310 mpEvents->copyMacrosIntoTable(aMacroTable);
311 pNewIMapObject->SetMacroTable( aMacroTable );
313 return pNewIMapObject;
316 // XInterface
318 Any SAL_CALL SvUnoImageMapObject::queryInterface( const Type & rType )
319 throw( RuntimeException )
321 return OWeakAggObject::queryInterface( rType );
324 Any SAL_CALL SvUnoImageMapObject::queryAggregation( const Type & rType )
325 throw(RuntimeException)
327 Any aAny;
329 if( rType == ::getCppuType((const Reference< XServiceInfo >*)0) )
330 aAny <<= Reference< XServiceInfo >(this);
331 else if( rType == ::getCppuType((const Reference< XTypeProvider >*)0) )
332 aAny <<= Reference< XTypeProvider >(this);
333 else if( rType == ::getCppuType((const Reference< XPropertySet >*)0) )
334 aAny <<= Reference< XPropertySet >(this);
335 else if( rType == ::getCppuType((const Reference< XEventsSupplier >*)0) )
336 aAny <<= Reference< XEventsSupplier >(this);
337 else if( rType == ::getCppuType((const Reference< XMultiPropertySet >*)0) )
338 aAny <<= Reference< XMultiPropertySet >(this);
339 else if( rType == ::getCppuType((const Reference< XUnoTunnel >*)0) )
340 aAny <<= Reference< XUnoTunnel >(this);
341 else
342 aAny <<= OWeakAggObject::queryAggregation( rType );
344 return aAny;
347 void SAL_CALL SvUnoImageMapObject::acquire() throw()
349 OWeakAggObject::acquire();
352 void SAL_CALL SvUnoImageMapObject::release() throw()
354 OWeakAggObject::release();
357 uno::Sequence< uno::Type > SAL_CALL SvUnoImageMapObject::getTypes()
358 throw (uno::RuntimeException)
360 uno::Sequence< uno::Type > aTypes( 7 );
361 uno::Type* pTypes = aTypes.getArray();
363 *pTypes++ = ::getCppuType((const uno::Reference< XAggregation>*)0);
364 *pTypes++ = ::getCppuType((const uno::Reference< XEventsSupplier>*)0);
365 *pTypes++ = ::getCppuType((const uno::Reference< XServiceInfo>*)0);
366 *pTypes++ = ::getCppuType((const uno::Reference< XPropertySet>*)0);
367 *pTypes++ = ::getCppuType((const uno::Reference< XMultiPropertySet>*)0);
368 *pTypes++ = ::getCppuType((const uno::Reference< XTypeProvider>*)0);
369 *pTypes++ = ::getCppuType((const uno::Reference< XUnoTunnel>*)0);
371 return aTypes;
374 namespace
376 class theSvUnoImageMapObjectImplementationId : public rtl::Static< UnoTunnelIdInit, theSvUnoImageMapObjectImplementationId > {};
379 uno::Sequence< sal_Int8 > SAL_CALL SvUnoImageMapObject::getImplementationId()
380 throw (uno::RuntimeException)
382 return theSvUnoImageMapObjectImplementationId::get().getSeq();
385 // XServiceInfo
387 sal_Bool SAL_CALL SvUnoImageMapObject::supportsService( const OUString& ServiceName ) throw(RuntimeException)
389 const Sequence< OUString > aSNL( getSupportedServiceNames() );
390 const OUString * pArray = aSNL.getConstArray();
392 const sal_Int32 nCount = aSNL.getLength();
393 for( sal_Int32 i = 0; i < nCount; i++ )
394 if( pArray[i] == ServiceName )
395 return sal_True;
397 return sal_False;
400 Sequence< OUString > SAL_CALL SvUnoImageMapObject::getSupportedServiceNames()
401 throw(RuntimeException)
403 Sequence< OUString > aSNS( 2 );
404 aSNS.getArray()[0] = OUString("com.sun.star.image.ImageMapObject" );
405 switch( mnType )
407 case IMAP_OBJ_POLYGON:
408 default:
409 aSNS.getArray()[1] = OUString("com.sun.star.image.ImageMapPolygonObject" );
410 break;
411 case IMAP_OBJ_RECTANGLE:
412 aSNS.getArray()[1] = OUString("com.sun.star.image.ImageMapRectangleObject" );
413 break;
414 case IMAP_OBJ_CIRCLE:
415 aSNS.getArray()[1] = OUString("com.sun.star.image.ImageMapCircleObject" );
416 break;
418 return aSNS;
421 OUString SAL_CALL SvUnoImageMapObject::getImplementationName() throw(RuntimeException)
423 switch( mnType )
425 case IMAP_OBJ_POLYGON:
426 default:
427 return OUString("org.openoffice.comp.svt.ImageMapPolygonObject");
428 case IMAP_OBJ_CIRCLE:
429 return OUString("org.openoffice.comp.svt.ImageMapCircleObject");
430 case IMAP_OBJ_RECTANGLE:
431 return OUString("org.openoffice.comp.svt.ImageMapRectangleObject");
435 // overiden helpers from PropertySetHelper
436 void SvUnoImageMapObject::_setPropertyValues( const PropertyMapEntry** ppEntries, const Any* pValues )
437 throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException )
439 sal_Bool bOk = sal_False;
441 while( *ppEntries )
443 switch( (*ppEntries)->mnHandle )
445 case HANDLE_URL:
446 bOk = *pValues >>= maURL;
447 break;
448 case HANDLE_TITLE:
449 bOk = *pValues >>= maAltText;
450 break;
451 case HANDLE_DESCRIPTION:
452 bOk = *pValues >>= maDesc;
453 break;
454 case HANDLE_TARGET:
455 bOk = *pValues >>= maTarget;
456 break;
457 case HANDLE_NAME:
458 bOk = *pValues >>= maName;
459 break;
460 case HANDLE_ISACTIVE:
461 bOk = *pValues >>= mbIsActive;
462 break;
463 case HANDLE_BOUNDARY:
464 bOk = *pValues >>= maBoundary;
465 break;
466 case HANDLE_CENTER:
467 bOk = *pValues >>= maCenter;
468 break;
469 case HANDLE_RADIUS:
470 bOk = *pValues >>= mnRadius;
471 break;
472 case HANDLE_POLYGON:
473 bOk = *pValues >>= maPolygon;
474 break;
475 default:
476 OSL_FAIL( "SvUnoImageMapObject::_setPropertyValues: unexpected property handle" );
477 break;
480 if( !bOk )
481 throw IllegalArgumentException();
483 ppEntries++;
484 pValues++;
488 void SvUnoImageMapObject::_getPropertyValues( const PropertyMapEntry** ppEntries, Any* pValues )
489 throw(UnknownPropertyException, WrappedTargetException )
491 while( *ppEntries )
493 switch( (*ppEntries)->mnHandle )
495 case HANDLE_URL:
496 *pValues <<= maURL;
497 break;
498 case HANDLE_TITLE:
499 *pValues <<= maAltText;
500 break;
501 case HANDLE_DESCRIPTION:
502 *pValues <<= maDesc;
503 break;
504 case HANDLE_TARGET:
505 *pValues <<= maTarget;
506 break;
507 case HANDLE_NAME:
508 *pValues <<= maName;
509 break;
510 case HANDLE_ISACTIVE:
511 *pValues <<= mbIsActive;
512 break;
513 case HANDLE_BOUNDARY:
514 *pValues <<= maBoundary;
515 break;
516 case HANDLE_CENTER:
517 *pValues <<= maCenter;
518 break;
519 case HANDLE_RADIUS:
520 *pValues <<= mnRadius;
521 break;
522 case HANDLE_POLYGON:
523 *pValues <<= maPolygon;
524 break;
525 default:
526 OSL_FAIL( "SvUnoImageMapObject::_getPropertyValues: unexpected property handle" );
527 break;
530 ppEntries++;
531 pValues++;
536 Reference< XNameReplace > SAL_CALL SvUnoImageMapObject::getEvents()
537 throw( RuntimeException )
539 // try weak reference first
540 Reference< XNameReplace > xEvents( mpEvents );
541 return xEvents;
544 ///////////////////////////////////////////////////////////////////////
546 class SvUnoImageMap : public WeakImplHelper3< XIndexContainer, XServiceInfo, XUnoTunnel >
548 public:
549 SvUnoImageMap( const SvEventDescription* pSupportedMacroItems );
550 SvUnoImageMap( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems );
551 virtual ~SvUnoImageMap();
553 sal_Bool fillImageMap( ImageMap& rMap ) const;
554 SvUnoImageMapObject* getObject( const Any& aElement ) const throw( IllegalArgumentException );
556 UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMap )
558 // XIndexContainer
559 virtual void SAL_CALL insertByIndex( sal_Int32 Index, const Any& Element ) throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException );
560 virtual void SAL_CALL removeByIndex( sal_Int32 Index ) throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException );
562 // XIndexReplace
563 virtual void SAL_CALL replaceByIndex( sal_Int32 Index, const Any& Element ) throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException );
565 // XIndexAccess
566 virtual sal_Int32 SAL_CALL getCount( ) throw( RuntimeException );
567 virtual Any SAL_CALL getByIndex( sal_Int32 Index ) throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException );
569 // XElementAccess
570 virtual Type SAL_CALL getElementType( ) throw( RuntimeException );
571 virtual sal_Bool SAL_CALL hasElements( ) throw( RuntimeException );
573 // XSerivceInfo
574 virtual OUString SAL_CALL getImplementationName( ) throw( RuntimeException );
575 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( RuntimeException );
576 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw( RuntimeException );
578 private:
579 OUString maName;
581 std::list< SvUnoImageMapObject* > maObjectList;
584 UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMap );
586 SvUnoImageMap::SvUnoImageMap( const SvEventDescription* )
590 SvUnoImageMap::SvUnoImageMap( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems )
592 maName = rMap.GetName();
594 const sal_uInt16 nCount = rMap.GetIMapObjectCount();
595 for( sal_uInt16 nPos = 0; nPos < nCount; nPos++ )
597 IMapObject* pMapObject = rMap.GetIMapObject( nPos );
598 SvUnoImageMapObject* pUnoObj = new SvUnoImageMapObject( *pMapObject, pSupportedMacroItems );
599 pUnoObj->acquire();
600 maObjectList.push_back( pUnoObj );
604 SvUnoImageMap::~SvUnoImageMap()
606 std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
607 const std::list< SvUnoImageMapObject* >::iterator aEnd = maObjectList.end();
608 while( aIter != aEnd )
610 (*aIter++)->release();
614 SvUnoImageMapObject* SvUnoImageMap::getObject( const Any& aElement ) const
615 throw( IllegalArgumentException )
617 Reference< XInterface > xObject;
618 aElement >>= xObject;
620 SvUnoImageMapObject* pObject = SvUnoImageMapObject::getImplementation( xObject );
621 if( NULL == pObject )
622 throw IllegalArgumentException();
624 return pObject;
627 // XIndexContainer
628 void SAL_CALL SvUnoImageMap::insertByIndex( sal_Int32 Index, const Any& Element )
629 throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
631 SvUnoImageMapObject* pObject = getObject( Element );
632 const sal_Int32 nCount = maObjectList.size();
633 if( NULL == pObject || Index > nCount )
634 throw IndexOutOfBoundsException();
636 pObject->acquire();
638 if( Index == nCount )
639 maObjectList.push_back( pObject );
640 else
642 std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
643 for( sal_Int32 n = 0; n < Index; n++ )
644 ++aIter;
646 maObjectList.insert( aIter, pObject );
650 void SAL_CALL SvUnoImageMap::removeByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
652 const sal_Int32 nCount = maObjectList.size();
653 if( Index >= nCount )
654 throw IndexOutOfBoundsException();
656 if( nCount - 1 == Index )
658 maObjectList.back()->release();
659 maObjectList.pop_back();
661 else
663 std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
664 for( sal_Int32 n = 0; n < Index; n++ )
665 ++aIter;
667 (*aIter)->release();
668 maObjectList.erase( aIter );
672 // XIndexReplace
673 void SAL_CALL SvUnoImageMap::replaceByIndex( sal_Int32 Index, const Any& Element ) throw(IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
675 SvUnoImageMapObject* pObject = getObject( Element );
676 const sal_Int32 nCount = maObjectList.size();
677 if( NULL == pObject || Index >= nCount )
678 throw IndexOutOfBoundsException();
680 std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
681 for( sal_Int32 n = 0; n < Index; n++ )
682 ++aIter;
684 (*aIter)->release();
685 *aIter = pObject;
686 pObject->acquire();
689 // XIndexAccess
690 sal_Int32 SAL_CALL SvUnoImageMap::getCount( ) throw(RuntimeException)
692 return maObjectList.size();
695 Any SAL_CALL SvUnoImageMap::getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
697 const sal_Int32 nCount = maObjectList.size();
698 if( Index >= nCount )
699 throw IndexOutOfBoundsException();
701 std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
702 for( sal_Int32 n = 0; n < Index; n++ )
703 ++aIter;
705 Reference< XPropertySet > xObj( *aIter );
706 return makeAny( xObj );
709 // XElementAccess
710 Type SAL_CALL SvUnoImageMap::getElementType( ) throw(RuntimeException)
712 return ::getCppuType((const Reference< XPropertySet >*)0);
715 sal_Bool SAL_CALL SvUnoImageMap::hasElements( ) throw(RuntimeException)
717 return (!maObjectList.empty());
720 // XSerivceInfo
721 OUString SAL_CALL SvUnoImageMap::getImplementationName( )
722 throw(RuntimeException)
724 return OUString( "org.openoffice.comp.svt.SvUnoImageMap" );
727 sal_Bool SAL_CALL SvUnoImageMap::supportsService( const OUString& ServiceName )
728 throw(RuntimeException)
730 const Sequence< OUString > aSNL( getSupportedServiceNames() );
731 const OUString * pArray = aSNL.getConstArray();
733 const sal_Int32 nCount = aSNL.getLength();
734 for( sal_Int32 i = 0; i < nCount; i++ )
735 if( pArray[i] == ServiceName )
736 return sal_True;
738 return sal_False;
741 Sequence< OUString > SAL_CALL SvUnoImageMap::getSupportedServiceNames( )
742 throw(RuntimeException)
744 const OUString aSN( "com.sun.star.image.ImageMap" );
745 return Sequence< OUString >( &aSN, 1 );
748 sal_Bool SvUnoImageMap::fillImageMap( ImageMap& rMap ) const
750 rMap.ClearImageMap();
752 rMap.SetName( maName );
754 std::list< SvUnoImageMapObject* >::const_iterator aIter = maObjectList.begin();
755 const std::list< SvUnoImageMapObject* >::const_iterator aEnd = maObjectList.end();
756 while( aIter != aEnd )
758 IMapObject* pNewMapObject = (*aIter)->createIMapObject();
759 rMap.InsertIMapObject( *pNewMapObject );
760 delete pNewMapObject;
762 ++aIter;
765 return sal_True;
768 // -------------------------------------------------------------------
769 // factory helper methods
770 // -------------------------------------------------------------------
772 Reference< XInterface > SvUnoImageMapRectangleObject_createInstance( const SvEventDescription* pSupportedMacroItems )
774 return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_RECTANGLE, pSupportedMacroItems );
777 Reference< XInterface > SvUnoImageMapCircleObject_createInstance( const SvEventDescription* pSupportedMacroItems )
779 return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_CIRCLE, pSupportedMacroItems );
782 Reference< XInterface > SvUnoImageMapPolygonObject_createInstance( const SvEventDescription* pSupportedMacroItems )
784 return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_POLYGON, pSupportedMacroItems );
787 Reference< XInterface > SvUnoImageMap_createInstance( const SvEventDescription* pSupportedMacroItems )
789 return (XWeak*)new SvUnoImageMap( pSupportedMacroItems );
792 Reference< XInterface > SvUnoImageMap_createInstance( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems )
794 return (XWeak*)new SvUnoImageMap( rMap, pSupportedMacroItems );
797 sal_Bool SvUnoImageMap_fillImageMap( Reference< XInterface > xImageMap, ImageMap& rMap )
799 SvUnoImageMap* pUnoImageMap = SvUnoImageMap::getImplementation( xImageMap );
800 if( NULL == pUnoImageMap )
801 return sal_False;
803 return pUnoImageMap->fillImageMap( rMap );
806 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */