1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unoimap.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include <com/sun/star/container/XNameContainer.hpp>
34 #include <com/sun/star/container/XIndexContainer.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/document/XEventsSupplier.hpp>
37 #include <com/sun/star/lang/XUnoTunnel.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/awt/Rectangle.hpp>
40 #include <com/sun/star/awt/Point.hpp>
41 #include <com/sun/star/drawing/PointSequence.hpp>
43 #ifndef _COMPHELPER_SERVICEHELPER_HXX_
44 #include <comphelper/servicehelper.hxx>
46 #include <comphelper/propertysethelper.hxx>
47 #include <comphelper/propertysetinfo.hxx>
48 #include <cppuhelper/weakagg.hxx>
50 #include <cppuhelper/implbase3.hxx>
54 #include <vos/mutex.hxx>
55 #include <vcl/svapp.hxx>
57 #include "unoevent.hxx"
58 #include "unoimap.hxx"
59 #include <svtools/imap.hxx>
60 #include <svtools/imapcirc.hxx>
61 #include <svtools/imaprect.hxx>
62 #include <svtools/imappoly.hxx>
65 #if defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)
66 #define SEQTYPE(x) (new ::com::sun::star::uno::Type( x ))
68 #define SEQTYPE(x) &(x)
72 #define MAP_LEN(x) x, sizeof(x)-1
75 using namespace comphelper
;
77 using namespace com::sun::star
;
78 using namespace com::sun::star::uno
;
79 using namespace com::sun::star::lang
;
80 using namespace com::sun::star::container
;
81 using namespace com::sun::star::beans
;
82 using namespace com::sun::star::document
;
83 using namespace com::sun::star::drawing
;
85 const sal_Int32 HANDLE_URL
= 1;
86 const sal_Int32 HANDLE_DESCRIPTION
= 2;
87 const sal_Int32 HANDLE_TARGET
= 3;
88 const sal_Int32 HANDLE_NAME
= 4;
89 const sal_Int32 HANDLE_ISACTIVE
= 5;
90 const sal_Int32 HANDLE_POLYGON
= 6;
91 const sal_Int32 HANDLE_CENTER
= 7;
92 const sal_Int32 HANDLE_RADIUS
= 8;
93 const sal_Int32 HANDLE_BOUNDARY
= 9;
94 const sal_Int32 HANDLE_TITLE
= 10;
96 class SvUnoImageMapObject
: public OWeakAggObject
,
97 public XEventsSupplier
,
99 public PropertySetHelper
,
100 public XTypeProvider
,
104 SvUnoImageMapObject( UINT16 nType
, const SvEventDescription
* pSupportedMacroItems
);
105 SvUnoImageMapObject( const IMapObject
& rMapObject
, const SvEventDescription
* pSupportedMacroItems
);
106 virtual ~SvUnoImageMapObject() throw();
108 UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMapObject
)
110 IMapObject
* createIMapObject() const;
112 SvMacroTableEventDescriptor
* mpEvents
;
114 // overiden helpers from PropertySetHelper
115 virtual void _setPropertyValues( const PropertyMapEntry
** ppEntries
, const Any
* pValues
) throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
);
116 virtual void _getPropertyValues( const PropertyMapEntry
** ppEntries
, Any
* pValue
) throw(UnknownPropertyException
, WrappedTargetException
);
119 virtual Any SAL_CALL
queryAggregation( const Type
& rType
) throw(RuntimeException
);
120 virtual Any SAL_CALL
queryInterface( const Type
& rType
) throw(RuntimeException
);
121 virtual void SAL_CALL
acquire() throw();
122 virtual void SAL_CALL
release() throw();
125 virtual Sequence
< Type
> SAL_CALL
getTypes( ) throw(RuntimeException
);
126 virtual Sequence
< sal_Int8
> SAL_CALL
getImplementationId( ) throw(RuntimeException
);
129 virtual Reference
< ::com::sun::star::container::XNameReplace
> SAL_CALL
getEvents( ) throw(RuntimeException
);
132 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw( RuntimeException
);
133 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
) throw( RuntimeException
);
134 virtual Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw( RuntimeException
);
137 static PropertySetInfo
* createPropertySetInfo( UINT16 nType
);
142 ::rtl::OUString maURL
;
143 ::rtl::OUString maAltText
;
144 ::rtl::OUString maDesc
;
145 ::rtl::OUString maTarget
;
146 ::rtl::OUString maName
;
148 awt::Rectangle maBoundary
;
151 PointSequence maPolygon
;
154 UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMapObject
);
156 PropertySetInfo
* SvUnoImageMapObject::createPropertySetInfo( UINT16 nType
)
160 case IMAP_OBJ_POLYGON
:
162 static PropertyMapEntry aPolygonObj_Impl
[] =
164 { MAP_LEN( "URL" ), HANDLE_URL
, &::getCppuType((const ::rtl::OUString
*)0), 0, 0 },
165 { MAP_LEN( "Title" ), HANDLE_TITLE
, &::getCppuType((const ::rtl::OUString
*)0), 0, 0 },
166 { MAP_LEN( "Description" ), HANDLE_DESCRIPTION
, &::getCppuType((const ::rtl::OUString
*)0), 0, 0 },
167 { MAP_LEN( "Target" ), HANDLE_TARGET
, &::getCppuType((const ::rtl::OUString
*)0), 0, 0 },
168 { MAP_LEN( "Name" ), HANDLE_NAME
, &::getCppuType((const ::rtl::OUString
*)0), 0, 0 },
169 { MAP_LEN( "IsActive" ), HANDLE_ISACTIVE
, &::getBooleanCppuType(), 0, 0 },
170 { MAP_LEN( "Polygon" ), HANDLE_POLYGON
, SEQTYPE(::getCppuType((const PointSequence
*)0)), 0, 0 },
174 return new PropertySetInfo( aPolygonObj_Impl
);
176 case IMAP_OBJ_CIRCLE
:
178 static PropertyMapEntry aCircleObj_Impl
[] =
180 { MAP_LEN( "URL" ), HANDLE_URL
, &::getCppuType((const ::rtl::OUString
*)0), 0, 0 },
181 { MAP_LEN( "Title" ), HANDLE_TITLE
, &::getCppuType((const ::rtl::OUString
*)0), 0, 0 },
182 { MAP_LEN( "Description" ), HANDLE_DESCRIPTION
, &::getCppuType((const ::rtl::OUString
*)0), 0, 0 },
183 { MAP_LEN( "Target" ), HANDLE_TARGET
, &::getCppuType((const ::rtl::OUString
*)0), 0, 0 },
184 { MAP_LEN( "Name" ), HANDLE_NAME
, &::getCppuType((const ::rtl::OUString
*)0), 0, 0 },
185 { MAP_LEN( "IsActive" ), HANDLE_ISACTIVE
, &::getBooleanCppuType(), 0, 0 },
186 { MAP_LEN( "Center" ), HANDLE_CENTER
, &::getCppuType((const awt::Point
*)0), 0, 0 },
187 { MAP_LEN( "Radius" ), HANDLE_RADIUS
, &::getCppuType((const sal_Int32
*)0), 0, 0 },
191 return new PropertySetInfo( aCircleObj_Impl
);
193 case IMAP_OBJ_RECTANGLE
:
196 static PropertyMapEntry aRectangleObj_Impl
[] =
198 { MAP_LEN( "URL" ), HANDLE_URL
, &::getCppuType((const ::rtl::OUString
*)0), 0, 0 },
199 { MAP_LEN( "Title" ), HANDLE_TITLE
, &::getCppuType((const ::rtl::OUString
*)0), 0, 0 },
200 { MAP_LEN( "Description" ), HANDLE_DESCRIPTION
, &::getCppuType((const ::rtl::OUString
*)0), 0, 0 },
201 { MAP_LEN( "Target" ), HANDLE_TARGET
, &::getCppuType((const ::rtl::OUString
*)0), 0, 0 },
202 { MAP_LEN( "Name" ), HANDLE_NAME
, &::getCppuType((const ::rtl::OUString
*)0), 0, 0 },
203 { MAP_LEN( "IsActive" ), HANDLE_ISACTIVE
, &::getBooleanCppuType(), 0, 0 },
204 { MAP_LEN( "Boundary" ), HANDLE_BOUNDARY
, &::getCppuType((const awt::Rectangle
*)0), 0, 0 },
208 return new PropertySetInfo( aRectangleObj_Impl
);
213 SvUnoImageMapObject::SvUnoImageMapObject( UINT16 nType
, const SvEventDescription
* pSupportedMacroItems
)
214 : PropertySetHelper( createPropertySetInfo( nType
) ),
217 mpEvents
= new SvMacroTableEventDescriptor( pSupportedMacroItems
);
221 SvUnoImageMapObject::SvUnoImageMapObject( const IMapObject
& rMapObject
, const SvEventDescription
* pSupportedMacroItems
)
222 : PropertySetHelper( createPropertySetInfo( rMapObject
.GetType() ) ),
223 mnType( rMapObject
.GetType() )
225 maURL
= rMapObject
.GetURL();
226 maAltText
= rMapObject
.GetAltText();
227 maDesc
= rMapObject
.GetDesc();
228 maTarget
= rMapObject
.GetTarget();
229 maName
= rMapObject
.GetName();
230 mbIsActive
= rMapObject
.IsActive();
234 case IMAP_OBJ_RECTANGLE
:
236 const Rectangle
aRect( ((IMapRectangleObject
*)&rMapObject
)->GetRectangle(sal_False
) );
237 maBoundary
.X
= aRect
.Left();
238 maBoundary
.Y
= aRect
.Top();
239 maBoundary
.Width
= aRect
.GetWidth();
240 maBoundary
.Height
= aRect
.GetHeight();
243 case IMAP_OBJ_CIRCLE
:
245 mnRadius
= (sal_Int32
)((IMapCircleObject
*)&rMapObject
)->GetRadius(sal_False
);
246 const Point
aPoint( ((IMapCircleObject
*)&rMapObject
)->GetCenter(sal_False
) );
248 maCenter
.X
= aPoint
.X();
249 maCenter
.Y
= aPoint
.Y();
252 case IMAP_OBJ_POLYGON
:
255 const Polygon
aPoly( ((IMapPolygonObject
*)&rMapObject
)->GetPolygon(sal_False
) );
257 const USHORT nCount
= aPoly
.GetSize();
258 maPolygon
.realloc( nCount
);
259 awt::Point
* pPoints
= maPolygon
.getArray();
261 for( USHORT nPoint
= 0; nPoint
< nCount
; nPoint
++ )
263 const Point
& rPoint
= aPoly
.GetPoint( nPoint
);
264 pPoints
->X
= rPoint
.X();
265 pPoints
->Y
= rPoint
.Y();
272 mpEvents
= new SvMacroTableEventDescriptor( rMapObject
.GetMacroTable(), pSupportedMacroItems
);
276 SvUnoImageMapObject::~SvUnoImageMapObject() throw()
281 IMapObject
* SvUnoImageMapObject::createIMapObject() const
283 const String
aURL( maURL
);
284 const String
aAltText( maAltText
);
285 const String
aDesc( maDesc
);
286 const String
aTarget( maTarget
);
287 const String
aName( maName
);
289 IMapObject
* pNewIMapObject
;
293 case IMAP_OBJ_RECTANGLE
:
295 const Rectangle
aRect( maBoundary
.X
, maBoundary
.Y
, maBoundary
.X
+ maBoundary
.Width
- 1, maBoundary
.Y
+ maBoundary
.Height
- 1 );
296 pNewIMapObject
= new IMapRectangleObject( aRect
, aURL
, aAltText
, aDesc
, aTarget
, aName
, mbIsActive
, sal_False
);
300 case IMAP_OBJ_CIRCLE
:
302 const Point
aCenter( maCenter
.X
, maCenter
.Y
);
303 pNewIMapObject
= new IMapCircleObject( aCenter
, mnRadius
, aURL
, aAltText
, aDesc
, aTarget
, aName
, mbIsActive
, sal_False
);
307 case IMAP_OBJ_POLYGON
:
310 const sal_uInt16 nCount
= (sal_uInt16
)maPolygon
.getLength();
312 Polygon
aPoly( nCount
);
313 for( sal_uInt16 nPoint
= 0; nPoint
< nCount
; nPoint
++ )
315 Point
aPoint( maPolygon
[nPoint
].X
, maPolygon
[nPoint
].Y
);
316 aPoly
.SetPoint( aPoint
, nPoint
);
319 aPoly
.Optimize( POLY_OPTIMIZE_CLOSE
);
320 pNewIMapObject
= new IMapPolygonObject( aPoly
, aURL
, aAltText
, aDesc
, aTarget
, aName
, mbIsActive
, sal_False
);
325 SvxMacroTableDtor aMacroTable
;
326 mpEvents
->copyMacrosIntoTable(aMacroTable
);
327 pNewIMapObject
->SetMacroTable( aMacroTable
);
329 return pNewIMapObject
;
334 Any SAL_CALL
SvUnoImageMapObject::queryInterface( const Type
& rType
)
335 throw( RuntimeException
)
337 return OWeakAggObject::queryInterface( rType
);
340 Any SAL_CALL
SvUnoImageMapObject::queryAggregation( const Type
& rType
)
341 throw(RuntimeException
)
345 if( rType
== ::getCppuType((const Reference
< XServiceInfo
>*)0) )
346 aAny
<<= Reference
< XServiceInfo
>(this);
347 else if( rType
== ::getCppuType((const Reference
< XTypeProvider
>*)0) )
348 aAny
<<= Reference
< XTypeProvider
>(this);
349 else if( rType
== ::getCppuType((const Reference
< XPropertySet
>*)0) )
350 aAny
<<= Reference
< XPropertySet
>(this);
351 else if( rType
== ::getCppuType((const Reference
< XEventsSupplier
>*)0) )
352 aAny
<<= Reference
< XEventsSupplier
>(this);
353 else if( rType
== ::getCppuType((const Reference
< XMultiPropertySet
>*)0) )
354 aAny
<<= Reference
< XMultiPropertySet
>(this);
355 else if( rType
== ::getCppuType((const Reference
< XUnoTunnel
>*)0) )
356 aAny
<<= Reference
< XUnoTunnel
>(this);
358 aAny
<<= OWeakAggObject::queryAggregation( rType
);
363 void SAL_CALL
SvUnoImageMapObject::acquire() throw()
365 OWeakAggObject::acquire();
368 void SAL_CALL
SvUnoImageMapObject::release() throw()
370 OWeakAggObject::release();
373 uno::Sequence
< uno::Type
> SAL_CALL
SvUnoImageMapObject::getTypes()
374 throw (uno::RuntimeException
)
376 uno::Sequence
< uno::Type
> aTypes( 7 );
377 uno::Type
* pTypes
= aTypes
.getArray();
379 *pTypes
++ = ::getCppuType((const uno::Reference
< XAggregation
>*)0);
380 *pTypes
++ = ::getCppuType((const uno::Reference
< XEventsSupplier
>*)0);
381 *pTypes
++ = ::getCppuType((const uno::Reference
< XServiceInfo
>*)0);
382 *pTypes
++ = ::getCppuType((const uno::Reference
< XPropertySet
>*)0);
383 *pTypes
++ = ::getCppuType((const uno::Reference
< XMultiPropertySet
>*)0);
384 *pTypes
++ = ::getCppuType((const uno::Reference
< XTypeProvider
>*)0);
385 *pTypes
++ = ::getCppuType((const uno::Reference
< XUnoTunnel
>*)0);
390 uno::Sequence
< sal_Int8
> SAL_CALL
SvUnoImageMapObject::getImplementationId()
391 throw (uno::RuntimeException
)
393 vos::OGuard
aGuard( Application::GetSolarMutex() );
395 static uno::Sequence
< sal_Int8
> aId
;
396 if( aId
.getLength() == 0 )
399 rtl_createUuid( (sal_uInt8
*)aId
.getArray(), 0, sal_True
);
406 sal_Bool SAL_CALL
SvUnoImageMapObject::supportsService( const ::rtl::OUString
& ServiceName
) throw(RuntimeException
)
408 const Sequence
< ::rtl::OUString
> aSNL( getSupportedServiceNames() );
409 const ::rtl::OUString
* pArray
= aSNL
.getConstArray();
411 const sal_Int32 nCount
= aSNL
.getLength();
412 for( sal_Int32 i
= 0; i
< nCount
; i
++ )
413 if( pArray
[i
] == ServiceName
)
419 Sequence
< ::rtl::OUString
> SAL_CALL
SvUnoImageMapObject::getSupportedServiceNames()
420 throw(RuntimeException
)
422 Sequence
< ::rtl::OUString
> aSNS( 2 );
423 aSNS
.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.image.ImageMapObject" ));
426 case IMAP_OBJ_POLYGON
:
428 aSNS
.getArray()[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.image.ImageMapPolygonObject" ));
430 case IMAP_OBJ_RECTANGLE
:
431 aSNS
.getArray()[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.image.ImageMapRectangleObject" ));
433 case IMAP_OBJ_CIRCLE
:
434 aSNS
.getArray()[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.image.ImageMapCircleObject" ));
440 ::rtl::OUString SAL_CALL
SvUnoImageMapObject::getImplementationName() throw(RuntimeException
)
444 case IMAP_OBJ_POLYGON
:
446 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.svt.ImageMapPolygonObject") );
447 case IMAP_OBJ_CIRCLE
:
448 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.svt.ImageMapCircleObject") );
449 case IMAP_OBJ_RECTANGLE
:
450 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.svt.ImageMapRectangleObject") );
454 // overiden helpers from PropertySetHelper
455 void SvUnoImageMapObject::_setPropertyValues( const PropertyMapEntry
** ppEntries
, const Any
* pValues
)
456 throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
)
458 sal_Bool bOk
= sal_False
;
462 switch( (*ppEntries
)->mnHandle
)
465 bOk
= *pValues
>>= maURL
;
468 bOk
= *pValues
>>= maAltText
;
470 case HANDLE_DESCRIPTION
:
471 bOk
= *pValues
>>= maDesc
;
474 bOk
= *pValues
>>= maTarget
;
477 bOk
= *pValues
>>= maName
;
479 case HANDLE_ISACTIVE
:
480 bOk
= *pValues
>>= mbIsActive
;
482 case HANDLE_BOUNDARY
:
483 bOk
= *pValues
>>= maBoundary
;
486 bOk
= *pValues
>>= maCenter
;
489 bOk
= *pValues
>>= mnRadius
;
492 bOk
= *pValues
>>= maPolygon
;
495 DBG_ERROR( "SvUnoImageMapObject::_setPropertyValues: unexpected property handle" );
500 throw IllegalArgumentException();
507 void SvUnoImageMapObject::_getPropertyValues( const PropertyMapEntry
** ppEntries
, Any
* pValues
)
508 throw(UnknownPropertyException
, WrappedTargetException
)
512 switch( (*ppEntries
)->mnHandle
)
518 *pValues
<<= maAltText
;
520 case HANDLE_DESCRIPTION
:
524 *pValues
<<= maTarget
;
529 case HANDLE_ISACTIVE
:
530 *pValues
<<= mbIsActive
;
532 case HANDLE_BOUNDARY
:
533 *pValues
<<= maBoundary
;
536 *pValues
<<= maCenter
;
539 *pValues
<<= mnRadius
;
542 *pValues
<<= maPolygon
;
545 DBG_ERROR( "SvUnoImageMapObject::_getPropertyValues: unexpected property handle" );
555 Reference
< XNameReplace
> SAL_CALL
SvUnoImageMapObject::getEvents()
556 throw( RuntimeException
)
558 // try weak reference first
559 Reference
< XNameReplace
> xEvents( mpEvents
);
563 ///////////////////////////////////////////////////////////////////////
565 class SvUnoImageMap
: public WeakImplHelper3
< XIndexContainer
, XServiceInfo
, XUnoTunnel
>
568 SvUnoImageMap( const SvEventDescription
* pSupportedMacroItems
);
569 SvUnoImageMap( const ImageMap
& rMap
, const SvEventDescription
* pSupportedMacroItems
);
570 virtual ~SvUnoImageMap();
572 sal_Bool
fillImageMap( ImageMap
& rMap
) const;
573 SvUnoImageMapObject
* getObject( const Any
& aElement
) const throw( IllegalArgumentException
);
575 UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMap
)
578 virtual void SAL_CALL
insertByIndex( sal_Int32 Index
, const Any
& Element
) throw( IllegalArgumentException
, IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
);
579 virtual void SAL_CALL
removeByIndex( sal_Int32 Index
) throw( IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
);
582 virtual void SAL_CALL
replaceByIndex( sal_Int32 Index
, const Any
& Element
) throw( IllegalArgumentException
, IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
);
585 virtual sal_Int32 SAL_CALL
getCount( ) throw( RuntimeException
);
586 virtual Any SAL_CALL
getByIndex( sal_Int32 Index
) throw( IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
);
589 virtual Type SAL_CALL
getElementType( ) throw( RuntimeException
);
590 virtual sal_Bool SAL_CALL
hasElements( ) throw( RuntimeException
);
593 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw( RuntimeException
);
594 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
) throw( RuntimeException
);
595 virtual Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw( RuntimeException
);
598 ::rtl::OUString maName
;
600 std::list
< SvUnoImageMapObject
* > maObjectList
;
603 UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMap
);
605 SvUnoImageMap::SvUnoImageMap( const SvEventDescription
* )
609 SvUnoImageMap::SvUnoImageMap( const ImageMap
& rMap
, const SvEventDescription
* pSupportedMacroItems
)
611 maName
= rMap
.GetName();
613 const UINT16 nCount
= rMap
.GetIMapObjectCount();
614 for( UINT16 nPos
= 0; nPos
< nCount
; nPos
++ )
616 IMapObject
* pMapObject
= rMap
.GetIMapObject( nPos
);
617 SvUnoImageMapObject
* pUnoObj
= new SvUnoImageMapObject( *pMapObject
, pSupportedMacroItems
);
619 maObjectList
.push_back( pUnoObj
);
623 SvUnoImageMap::~SvUnoImageMap()
625 std::list
< SvUnoImageMapObject
* >::iterator aIter
= maObjectList
.begin();
626 const std::list
< SvUnoImageMapObject
* >::iterator aEnd
= maObjectList
.end();
627 while( aIter
!= aEnd
)
629 (*aIter
++)->release();
633 SvUnoImageMapObject
* SvUnoImageMap::getObject( const Any
& aElement
) const
634 throw( IllegalArgumentException
)
636 Reference
< XInterface
> xObject
;
637 aElement
>>= xObject
;
639 SvUnoImageMapObject
* pObject
= SvUnoImageMapObject::getImplementation( xObject
);
640 if( NULL
== pObject
)
641 throw IllegalArgumentException();
647 void SAL_CALL
SvUnoImageMap::insertByIndex( sal_Int32 Index
, const Any
& Element
)
648 throw( IllegalArgumentException
, IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
)
650 SvUnoImageMapObject
* pObject
= getObject( Element
);
651 const sal_Int32 nCount
= maObjectList
.size();
652 if( NULL
== pObject
|| Index
> nCount
)
653 throw IndexOutOfBoundsException();
657 if( Index
== nCount
)
658 maObjectList
.push_back( pObject
);
661 std::list
< SvUnoImageMapObject
* >::iterator aIter
= maObjectList
.begin();
662 for( sal_Int32 n
= 0; n
< Index
; n
++ )
665 maObjectList
.insert( aIter
, pObject
);
669 void SAL_CALL
SvUnoImageMap::removeByIndex( sal_Int32 Index
) throw(IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
)
671 const sal_Int32 nCount
= maObjectList
.size();
672 if( Index
>= nCount
)
673 throw IndexOutOfBoundsException();
675 if( nCount
- 1 == Index
)
677 maObjectList
.back()->release();
678 maObjectList
.pop_back();
682 std::list
< SvUnoImageMapObject
* >::iterator aIter
= maObjectList
.begin();
683 for( sal_Int32 n
= 0; n
< Index
; n
++ )
687 maObjectList
.erase( aIter
);
692 void SAL_CALL
SvUnoImageMap::replaceByIndex( sal_Int32 Index
, const Any
& Element
) throw(IllegalArgumentException
, IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
)
694 SvUnoImageMapObject
* pObject
= getObject( Element
);
695 const sal_Int32 nCount
= maObjectList
.size();
696 if( NULL
== pObject
|| Index
>= nCount
)
697 throw IndexOutOfBoundsException();
699 std::list
< SvUnoImageMapObject
* >::iterator aIter
= maObjectList
.begin();
700 for( sal_Int32 n
= 0; n
< Index
; n
++ )
709 sal_Int32 SAL_CALL
SvUnoImageMap::getCount( ) throw(RuntimeException
)
711 return maObjectList
.size();
714 Any SAL_CALL
SvUnoImageMap::getByIndex( sal_Int32 Index
) throw(IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
)
716 const sal_Int32 nCount
= maObjectList
.size();
717 if( Index
>= nCount
)
718 throw IndexOutOfBoundsException();
720 std::list
< SvUnoImageMapObject
* >::iterator aIter
= maObjectList
.begin();
721 for( sal_Int32 n
= 0; n
< Index
; n
++ )
724 Reference
< XPropertySet
> xObj( *aIter
);
725 return makeAny( xObj
);
729 Type SAL_CALL
SvUnoImageMap::getElementType( ) throw(RuntimeException
)
731 return ::getCppuType((const Reference
< XPropertySet
>*)0);
734 sal_Bool SAL_CALL
SvUnoImageMap::hasElements( ) throw(RuntimeException
)
736 return maObjectList
.size() != 0;
740 ::rtl::OUString SAL_CALL
SvUnoImageMap::getImplementationName( )
741 throw(RuntimeException
)
743 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.comp.svt.SvUnoImageMap" ) );
746 sal_Bool SAL_CALL
SvUnoImageMap::supportsService( const ::rtl::OUString
& ServiceName
)
747 throw(RuntimeException
)
749 const Sequence
< ::rtl::OUString
> aSNL( getSupportedServiceNames() );
750 const ::rtl::OUString
* pArray
= aSNL
.getConstArray();
752 const sal_Int32 nCount
= aSNL
.getLength();
753 for( sal_Int32 i
= 0; i
< nCount
; i
++ )
754 if( pArray
[i
] == ServiceName
)
760 Sequence
< ::rtl::OUString
> SAL_CALL
SvUnoImageMap::getSupportedServiceNames( )
761 throw(RuntimeException
)
763 const ::rtl::OUString
aSN( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.image.ImageMap" ) );
764 return Sequence
< ::rtl::OUString
>( &aSN
, 1 );
767 sal_Bool
SvUnoImageMap::fillImageMap( ImageMap
& rMap
) const
769 rMap
.ClearImageMap();
771 rMap
.SetName( maName
);
773 std::list
< SvUnoImageMapObject
* >::const_iterator aIter
= maObjectList
.begin();
774 const std::list
< SvUnoImageMapObject
* >::const_iterator aEnd
= maObjectList
.end();
775 while( aIter
!= aEnd
)
777 IMapObject
* pNewMapObject
= (*aIter
)->createIMapObject();
778 rMap
.InsertIMapObject( *pNewMapObject
);
779 delete pNewMapObject
;
787 // -------------------------------------------------------------------
788 // factory helper methods
789 // -------------------------------------------------------------------
791 Reference
< XInterface
> SvUnoImageMapRectangleObject_createInstance( const SvEventDescription
* pSupportedMacroItems
)
793 return (XWeak
*)new SvUnoImageMapObject( IMAP_OBJ_RECTANGLE
, pSupportedMacroItems
);
796 Reference
< XInterface
> SvUnoImageMapCircleObject_createInstance( const SvEventDescription
* pSupportedMacroItems
)
798 return (XWeak
*)new SvUnoImageMapObject( IMAP_OBJ_CIRCLE
, pSupportedMacroItems
);
801 Reference
< XInterface
> SvUnoImageMapPolygonObject_createInstance( const SvEventDescription
* pSupportedMacroItems
)
803 return (XWeak
*)new SvUnoImageMapObject( IMAP_OBJ_POLYGON
, pSupportedMacroItems
);
806 Reference
< XInterface
> SvUnoImageMap_createInstance( const SvEventDescription
* pSupportedMacroItems
)
808 return (XWeak
*)new SvUnoImageMap( pSupportedMacroItems
);
811 Reference
< XInterface
> SvUnoImageMap_createInstance( const ImageMap
& rMap
, const SvEventDescription
* pSupportedMacroItems
)
813 return (XWeak
*)new SvUnoImageMap( rMap
, pSupportedMacroItems
);
816 sal_Bool
SvUnoImageMap_fillImageMap( Reference
< XInterface
> xImageMap
, ImageMap
& rMap
)
818 SvUnoImageMap
* pUnoImageMap
= SvUnoImageMap::getImplementation( xImageMap
);
819 if( NULL
== pUnoImageMap
)
822 return pUnoImageMap
->fillImageMap( rMap
);