1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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>
46 #if defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)
47 #define SEQTYPE(x) (new ::com::sun::star::uno::Type( x ))
49 #define SEQTYPE(x) &(x)
53 #define MAP_LEN(x) x, sizeof(x)-1
56 using namespace comphelper
;
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
,
80 public PropertySetHelper
,
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
);
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();
106 virtual Sequence
< Type
> SAL_CALL
getTypes( ) throw(RuntimeException
);
107 virtual Sequence
< sal_Int8
> SAL_CALL
getImplementationId( ) throw(RuntimeException
);
110 virtual Reference
< ::com::sun::star::container::XNameReplace
> SAL_CALL
getEvents( ) throw(RuntimeException
);
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
);
118 static PropertySetInfo
* createPropertySetInfo( sal_uInt16 nType
);
129 awt::Rectangle maBoundary
;
132 PointSequence maPolygon
;
135 UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMapObject
);
137 PropertySetInfo
* SvUnoImageMapObject::createPropertySetInfo( sal_uInt16 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 },
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 },
172 return new PropertySetInfo( aCircleObj_Impl
);
174 case IMAP_OBJ_RECTANGLE
:
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 },
189 return new PropertySetInfo( aRectangleObj_Impl
);
194 SvUnoImageMapObject::SvUnoImageMapObject( sal_uInt16 nType
, const SvEventDescription
* pSupportedMacroItems
)
195 : PropertySetHelper( createPropertySetInfo( nType
) ),
200 mpEvents
= new SvMacroTableEventDescriptor( pSupportedMacroItems
);
204 SvUnoImageMapObject::SvUnoImageMapObject( const IMapObject
& rMapObject
, const SvEventDescription
* pSupportedMacroItems
)
205 : PropertySetHelper( createPropertySetInfo( rMapObject
.GetType() ) ),
206 mnType( rMapObject
.GetType() )
210 maURL
= rMapObject
.GetURL();
211 maAltText
= rMapObject
.GetAltText();
212 maDesc
= rMapObject
.GetDesc();
213 maTarget
= rMapObject
.GetTarget();
214 maName
= rMapObject
.GetName();
215 mbIsActive
= rMapObject
.IsActive();
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();
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();
237 case IMAP_OBJ_POLYGON
:
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();
257 mpEvents
= new SvMacroTableEventDescriptor( rMapObject
.GetMacroTable(), pSupportedMacroItems
);
261 SvUnoImageMapObject::~SvUnoImageMapObject() throw()
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
;
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
);
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
);
292 case IMAP_OBJ_POLYGON
:
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
);
310 SvxMacroTableDtor aMacroTable
;
311 mpEvents
->copyMacrosIntoTable(aMacroTable
);
312 pNewIMapObject
->SetMacroTable( aMacroTable
);
314 return pNewIMapObject
;
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
)
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);
343 aAny
<<= OWeakAggObject::queryAggregation( rType
);
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);
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();
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";
399 case IMAP_OBJ_POLYGON
:
401 aSNS
.getArray()[1] = "com.sun.star.image.ImageMapPolygonObject";
403 case IMAP_OBJ_RECTANGLE
:
404 aSNS
.getArray()[1] = "com.sun.star.image.ImageMapRectangleObject";
406 case IMAP_OBJ_CIRCLE
:
407 aSNS
.getArray()[1] = "com.sun.star.image.ImageMapCircleObject";
413 OUString SAL_CALL
SvUnoImageMapObject::getImplementationName() throw(RuntimeException
)
417 case IMAP_OBJ_POLYGON
:
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
;
435 switch( (*ppEntries
)->mnHandle
)
438 bOk
= *pValues
>>= maURL
;
441 bOk
= *pValues
>>= maAltText
;
443 case HANDLE_DESCRIPTION
:
444 bOk
= *pValues
>>= maDesc
;
447 bOk
= *pValues
>>= maTarget
;
450 bOk
= *pValues
>>= maName
;
452 case HANDLE_ISACTIVE
:
453 bOk
= *pValues
>>= mbIsActive
;
455 case HANDLE_BOUNDARY
:
456 bOk
= *pValues
>>= maBoundary
;
459 bOk
= *pValues
>>= maCenter
;
462 bOk
= *pValues
>>= mnRadius
;
465 bOk
= *pValues
>>= maPolygon
;
468 OSL_FAIL( "SvUnoImageMapObject::_setPropertyValues: unexpected property handle" );
473 throw IllegalArgumentException();
480 void SvUnoImageMapObject::_getPropertyValues( const PropertyMapEntry
** ppEntries
, Any
* pValues
)
481 throw(UnknownPropertyException
, WrappedTargetException
)
485 switch( (*ppEntries
)->mnHandle
)
491 *pValues
<<= maAltText
;
493 case HANDLE_DESCRIPTION
:
497 *pValues
<<= maTarget
;
502 case HANDLE_ISACTIVE
:
503 *pValues
<<= mbIsActive
;
505 case HANDLE_BOUNDARY
:
506 *pValues
<<= maBoundary
;
509 *pValues
<<= maCenter
;
512 *pValues
<<= mnRadius
;
515 *pValues
<<= maPolygon
;
518 OSL_FAIL( "SvUnoImageMapObject::_getPropertyValues: unexpected property handle" );
528 Reference
< XNameReplace
> SAL_CALL
SvUnoImageMapObject::getEvents()
529 throw( RuntimeException
)
531 // try weak reference first
532 Reference
< XNameReplace
> xEvents( mpEvents
);
536 ///////////////////////////////////////////////////////////////////////
538 class SvUnoImageMap
: public WeakImplHelper3
< XIndexContainer
, XServiceInfo
, XUnoTunnel
>
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
)
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
);
555 virtual void SAL_CALL
replaceByIndex( sal_Int32 Index
, const Any
& Element
) throw( IllegalArgumentException
, IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
);
558 virtual sal_Int32 SAL_CALL
getCount( ) throw( RuntimeException
);
559 virtual Any SAL_CALL
getByIndex( sal_Int32 Index
) throw( IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
);
562 virtual Type SAL_CALL
getElementType( ) throw( RuntimeException
);
563 virtual sal_Bool SAL_CALL
hasElements( ) throw( RuntimeException
);
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
);
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
);
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();
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();
630 if( Index
== nCount
)
631 maObjectList
.push_back( pObject
);
634 std::list
< SvUnoImageMapObject
* >::iterator aIter
= maObjectList
.begin();
635 for( sal_Int32 n
= 0; n
< Index
; n
++ )
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();
655 std::list
< SvUnoImageMapObject
* >::iterator aIter
= maObjectList
.begin();
656 std::advance(aIter
, nIndex
);
659 maObjectList
.erase( aIter
);
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
++ )
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
++ )
696 Reference
< XPropertySet
> xObj( *aIter
);
697 return makeAny( xObj
);
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());
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
)
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
;
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
)
794 return pUnoImageMap
->fillImageMap( rMap
);
797 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */