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>
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>
45 #if defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)
46 #define SEQTYPE(x) (new ::com::sun::star::uno::Type( x ))
48 #define SEQTYPE(x) &(x)
52 #define MAP_LEN(x) x, sizeof(x)-1
55 using namespace comphelper
;
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
,
79 public PropertySetHelper
,
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
);
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();
105 virtual Sequence
< Type
> SAL_CALL
getTypes( ) throw(RuntimeException
);
106 virtual Sequence
< sal_Int8
> SAL_CALL
getImplementationId( ) throw(RuntimeException
);
109 virtual Reference
< ::com::sun::star::container::XNameReplace
> SAL_CALL
getEvents( ) throw(RuntimeException
);
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
);
117 static PropertySetInfo
* createPropertySetInfo( sal_uInt16 nType
);
128 awt::Rectangle maBoundary
;
131 PointSequence maPolygon
;
134 UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMapObject
);
136 PropertySetInfo
* SvUnoImageMapObject::createPropertySetInfo( sal_uInt16 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 },
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 },
171 return new PropertySetInfo( aCircleObj_Impl
);
173 case IMAP_OBJ_RECTANGLE
:
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 },
188 return new PropertySetInfo( aRectangleObj_Impl
);
193 SvUnoImageMapObject::SvUnoImageMapObject( sal_uInt16 nType
, const SvEventDescription
* pSupportedMacroItems
)
194 : PropertySetHelper( createPropertySetInfo( nType
) ),
199 mpEvents
= new SvMacroTableEventDescriptor( pSupportedMacroItems
);
203 SvUnoImageMapObject::SvUnoImageMapObject( const IMapObject
& rMapObject
, const SvEventDescription
* pSupportedMacroItems
)
204 : PropertySetHelper( createPropertySetInfo( rMapObject
.GetType() ) ),
205 mnType( rMapObject
.GetType() )
209 maURL
= rMapObject
.GetURL();
210 maAltText
= rMapObject
.GetAltText();
211 maDesc
= rMapObject
.GetDesc();
212 maTarget
= rMapObject
.GetTarget();
213 maName
= rMapObject
.GetName();
214 mbIsActive
= rMapObject
.IsActive();
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();
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();
236 case IMAP_OBJ_POLYGON
:
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();
256 mpEvents
= new SvMacroTableEventDescriptor( rMapObject
.GetMacroTable(), pSupportedMacroItems
);
260 SvUnoImageMapObject::~SvUnoImageMapObject() throw()
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
;
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
);
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
);
291 case IMAP_OBJ_POLYGON
:
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
);
309 SvxMacroTableDtor aMacroTable
;
310 mpEvents
->copyMacrosIntoTable(aMacroTable
);
311 pNewIMapObject
->SetMacroTable( aMacroTable
);
313 return pNewIMapObject
;
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
)
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);
342 aAny
<<= OWeakAggObject::queryAggregation( rType
);
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);
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();
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
)
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" );
407 case IMAP_OBJ_POLYGON
:
409 aSNS
.getArray()[1] = OUString("com.sun.star.image.ImageMapPolygonObject" );
411 case IMAP_OBJ_RECTANGLE
:
412 aSNS
.getArray()[1] = OUString("com.sun.star.image.ImageMapRectangleObject" );
414 case IMAP_OBJ_CIRCLE
:
415 aSNS
.getArray()[1] = OUString("com.sun.star.image.ImageMapCircleObject" );
421 OUString SAL_CALL
SvUnoImageMapObject::getImplementationName() throw(RuntimeException
)
425 case IMAP_OBJ_POLYGON
:
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
;
443 switch( (*ppEntries
)->mnHandle
)
446 bOk
= *pValues
>>= maURL
;
449 bOk
= *pValues
>>= maAltText
;
451 case HANDLE_DESCRIPTION
:
452 bOk
= *pValues
>>= maDesc
;
455 bOk
= *pValues
>>= maTarget
;
458 bOk
= *pValues
>>= maName
;
460 case HANDLE_ISACTIVE
:
461 bOk
= *pValues
>>= mbIsActive
;
463 case HANDLE_BOUNDARY
:
464 bOk
= *pValues
>>= maBoundary
;
467 bOk
= *pValues
>>= maCenter
;
470 bOk
= *pValues
>>= mnRadius
;
473 bOk
= *pValues
>>= maPolygon
;
476 OSL_FAIL( "SvUnoImageMapObject::_setPropertyValues: unexpected property handle" );
481 throw IllegalArgumentException();
488 void SvUnoImageMapObject::_getPropertyValues( const PropertyMapEntry
** ppEntries
, Any
* pValues
)
489 throw(UnknownPropertyException
, WrappedTargetException
)
493 switch( (*ppEntries
)->mnHandle
)
499 *pValues
<<= maAltText
;
501 case HANDLE_DESCRIPTION
:
505 *pValues
<<= maTarget
;
510 case HANDLE_ISACTIVE
:
511 *pValues
<<= mbIsActive
;
513 case HANDLE_BOUNDARY
:
514 *pValues
<<= maBoundary
;
517 *pValues
<<= maCenter
;
520 *pValues
<<= mnRadius
;
523 *pValues
<<= maPolygon
;
526 OSL_FAIL( "SvUnoImageMapObject::_getPropertyValues: unexpected property handle" );
536 Reference
< XNameReplace
> SAL_CALL
SvUnoImageMapObject::getEvents()
537 throw( RuntimeException
)
539 // try weak reference first
540 Reference
< XNameReplace
> xEvents( mpEvents
);
544 ///////////////////////////////////////////////////////////////////////
546 class SvUnoImageMap
: public WeakImplHelper3
< XIndexContainer
, XServiceInfo
, XUnoTunnel
>
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
)
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
);
563 virtual void SAL_CALL
replaceByIndex( sal_Int32 Index
, const Any
& Element
) throw( IllegalArgumentException
, IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
);
566 virtual sal_Int32 SAL_CALL
getCount( ) throw( RuntimeException
);
567 virtual Any SAL_CALL
getByIndex( sal_Int32 Index
) throw( IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
);
570 virtual Type SAL_CALL
getElementType( ) throw( RuntimeException
);
571 virtual sal_Bool SAL_CALL
hasElements( ) throw( RuntimeException
);
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
);
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
);
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();
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();
638 if( Index
== nCount
)
639 maObjectList
.push_back( pObject
);
642 std::list
< SvUnoImageMapObject
* >::iterator aIter
= maObjectList
.begin();
643 for( sal_Int32 n
= 0; n
< Index
; n
++ )
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();
663 std::list
< SvUnoImageMapObject
* >::iterator aIter
= maObjectList
.begin();
664 for( sal_Int32 n
= 0; n
< Index
; n
++ )
668 maObjectList
.erase( aIter
);
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
++ )
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
++ )
705 Reference
< XPropertySet
> xObj( *aIter
);
706 return makeAny( xObj
);
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());
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
)
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
;
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
)
803 return pUnoImageMap
->fillImageMap( rMap
);
806 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */