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>
45 using namespace comphelper
;
47 using namespace com::sun::star
;
48 using namespace com::sun::star::uno
;
49 using namespace com::sun::star::lang
;
50 using namespace com::sun::star::container
;
51 using namespace com::sun::star::beans
;
52 using namespace com::sun::star::document
;
53 using namespace com::sun::star::drawing
;
55 const sal_Int32 HANDLE_URL
= 1;
56 const sal_Int32 HANDLE_DESCRIPTION
= 2;
57 const sal_Int32 HANDLE_TARGET
= 3;
58 const sal_Int32 HANDLE_NAME
= 4;
59 const sal_Int32 HANDLE_ISACTIVE
= 5;
60 const sal_Int32 HANDLE_POLYGON
= 6;
61 const sal_Int32 HANDLE_CENTER
= 7;
62 const sal_Int32 HANDLE_RADIUS
= 8;
63 const sal_Int32 HANDLE_BOUNDARY
= 9;
64 const sal_Int32 HANDLE_TITLE
= 10;
66 class SvUnoImageMapObject
: public OWeakAggObject
,
67 public XEventsSupplier
,
69 public PropertySetHelper
,
74 SvUnoImageMapObject( sal_uInt16 nType
, const SvEventDescription
* pSupportedMacroItems
);
75 SvUnoImageMapObject( const IMapObject
& rMapObject
, const SvEventDescription
* pSupportedMacroItems
);
76 virtual ~SvUnoImageMapObject() throw();
78 UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMapObject
)
80 IMapObject
* createIMapObject() const;
82 SvMacroTableEventDescriptor
* mpEvents
;
84 // overriden helpers from PropertySetHelper
85 virtual void _setPropertyValues( const PropertyMapEntry
** ppEntries
, const Any
* pValues
) throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
) SAL_OVERRIDE
;
86 virtual void _getPropertyValues( const PropertyMapEntry
** ppEntries
, Any
* pValue
) throw(UnknownPropertyException
, WrappedTargetException
) SAL_OVERRIDE
;
89 virtual Any SAL_CALL
queryAggregation( const Type
& rType
) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
90 virtual Any SAL_CALL
queryInterface( const Type
& rType
) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
91 virtual void SAL_CALL
acquire() throw() SAL_OVERRIDE
;
92 virtual void SAL_CALL
release() throw() SAL_OVERRIDE
;
95 virtual Sequence
< Type
> SAL_CALL
getTypes( ) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
96 virtual Sequence
< sal_Int8
> SAL_CALL
getImplementationId( ) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
99 virtual Reference
< ::com::sun::star::container::XNameReplace
> SAL_CALL
getEvents( ) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
102 virtual OUString SAL_CALL
getImplementationName( ) throw( RuntimeException
, std::exception
) SAL_OVERRIDE
;
103 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw( RuntimeException
, std::exception
) SAL_OVERRIDE
;
104 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw( RuntimeException
, std::exception
) SAL_OVERRIDE
;
107 static PropertySetInfo
* createPropertySetInfo( sal_uInt16 nType
);
118 awt::Rectangle maBoundary
;
121 PointSequence maPolygon
;
124 UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMapObject
);
126 PropertySetInfo
* SvUnoImageMapObject::createPropertySetInfo( sal_uInt16 nType
)
130 case IMAP_OBJ_POLYGON
:
132 static PropertyMapEntry
const aPolygonObj_Impl
[] =
134 { OUString("URL"), HANDLE_URL
, cppu::UnoType
<OUString
>::get(), 0, 0 },
135 { OUString("Title"), HANDLE_TITLE
, cppu::UnoType
<OUString
>::get(), 0, 0 },
136 { OUString("Description"), HANDLE_DESCRIPTION
, cppu::UnoType
<OUString
>::get(), 0, 0 },
137 { OUString("Target"), HANDLE_TARGET
, cppu::UnoType
<OUString
>::get(), 0, 0 },
138 { OUString("Name"), HANDLE_NAME
, cppu::UnoType
<OUString
>::get(), 0, 0 },
139 { OUString("IsActive"), HANDLE_ISACTIVE
, cppu::UnoType
<bool>::get(), 0, 0 },
140 { OUString("Polygon"), HANDLE_POLYGON
, cppu::UnoType
<PointSequence
>::get(), 0, 0 },
141 { OUString(), 0, css::uno::Type(), 0, 0 }
144 return new PropertySetInfo( aPolygonObj_Impl
);
146 case IMAP_OBJ_CIRCLE
:
148 static PropertyMapEntry
const aCircleObj_Impl
[] =
150 { OUString("URL"), HANDLE_URL
, cppu::UnoType
<OUString
>::get(), 0, 0 },
151 { OUString("Title"), HANDLE_TITLE
, cppu::UnoType
<OUString
>::get(), 0, 0 },
152 { OUString("Description"), HANDLE_DESCRIPTION
, cppu::UnoType
<OUString
>::get(), 0, 0 },
153 { OUString("Target"), HANDLE_TARGET
, cppu::UnoType
<OUString
>::get(), 0, 0 },
154 { OUString("Name"), HANDLE_NAME
, cppu::UnoType
<OUString
>::get(), 0, 0 },
155 { OUString("IsActive"), HANDLE_ISACTIVE
, cppu::UnoType
<bool>::get(), 0, 0 },
156 { OUString("Center"), HANDLE_CENTER
, cppu::UnoType
<awt::Point
>::get(), 0, 0 },
157 { OUString("Radius"), HANDLE_RADIUS
, cppu::UnoType
<sal_Int32
>::get(), 0, 0 },
158 { OUString(), 0, css::uno::Type(), 0, 0 }
161 return new PropertySetInfo( aCircleObj_Impl
);
163 case IMAP_OBJ_RECTANGLE
:
166 static PropertyMapEntry
const aRectangleObj_Impl
[] =
168 { OUString("URL"), HANDLE_URL
, cppu::UnoType
<OUString
>::get(), 0, 0 },
169 { OUString("Title"), HANDLE_TITLE
, cppu::UnoType
<OUString
>::get(), 0, 0 },
170 { OUString("Description"), HANDLE_DESCRIPTION
, cppu::UnoType
<OUString
>::get(), 0, 0 },
171 { OUString("Target"), HANDLE_TARGET
, cppu::UnoType
<OUString
>::get(), 0, 0 },
172 { OUString("Name"), HANDLE_NAME
, cppu::UnoType
<OUString
>::get(), 0, 0 },
173 { OUString("IsActive"), HANDLE_ISACTIVE
, cppu::UnoType
<bool>::get(), 0, 0 },
174 { OUString("Boundary"), HANDLE_BOUNDARY
, cppu::UnoType
<awt::Rectangle
>::get(), 0, 0 },
175 { OUString(), 0, css::uno::Type(), 0, 0 }
178 return new PropertySetInfo( aRectangleObj_Impl
);
183 SvUnoImageMapObject::SvUnoImageMapObject( sal_uInt16 nType
, const SvEventDescription
* pSupportedMacroItems
)
184 : PropertySetHelper( createPropertySetInfo( nType
) ),
189 mpEvents
= new SvMacroTableEventDescriptor( pSupportedMacroItems
);
193 SvUnoImageMapObject::SvUnoImageMapObject( const IMapObject
& rMapObject
, const SvEventDescription
* pSupportedMacroItems
)
194 : PropertySetHelper( createPropertySetInfo( rMapObject
.GetType() ) ),
195 mnType( rMapObject
.GetType() )
199 maURL
= rMapObject
.GetURL();
200 maAltText
= rMapObject
.GetAltText();
201 maDesc
= rMapObject
.GetDesc();
202 maTarget
= rMapObject
.GetTarget();
203 maName
= rMapObject
.GetName();
204 mbIsActive
= rMapObject
.IsActive();
208 case IMAP_OBJ_RECTANGLE
:
210 const Rectangle
aRect( static_cast<const IMapRectangleObject
*>(&rMapObject
)->GetRectangle(false) );
211 maBoundary
.X
= aRect
.Left();
212 maBoundary
.Y
= aRect
.Top();
213 maBoundary
.Width
= aRect
.GetWidth();
214 maBoundary
.Height
= aRect
.GetHeight();
217 case IMAP_OBJ_CIRCLE
:
219 mnRadius
= (sal_Int32
)static_cast<const IMapCircleObject
*>(&rMapObject
)->GetRadius(false);
220 const Point
aPoint( static_cast<const IMapCircleObject
*>(&rMapObject
)->GetCenter(false) );
222 maCenter
.X
= aPoint
.X();
223 maCenter
.Y
= aPoint
.Y();
226 case IMAP_OBJ_POLYGON
:
229 const Polygon
aPoly( static_cast<const IMapPolygonObject
*>(&rMapObject
)->GetPolygon(false) );
231 const sal_uInt16 nCount
= aPoly
.GetSize();
232 maPolygon
.realloc( nCount
);
233 awt::Point
* pPoints
= maPolygon
.getArray();
235 for( sal_uInt16 nPoint
= 0; nPoint
< nCount
; nPoint
++ )
237 const Point
& rPoint
= aPoly
.GetPoint( nPoint
);
238 pPoints
->X
= rPoint
.X();
239 pPoints
->Y
= rPoint
.Y();
246 mpEvents
= new SvMacroTableEventDescriptor( rMapObject
.GetMacroTable(), pSupportedMacroItems
);
250 SvUnoImageMapObject::~SvUnoImageMapObject() throw()
255 IMapObject
* SvUnoImageMapObject::createIMapObject() const
257 const OUString
aURL( maURL
);
258 const OUString
aAltText( maAltText
);
259 const OUString
aDesc( maDesc
);
260 const OUString
aTarget( maTarget
);
261 const OUString
aName( maName
);
263 IMapObject
* pNewIMapObject
;
267 case IMAP_OBJ_RECTANGLE
:
269 const Rectangle
aRect( maBoundary
.X
, maBoundary
.Y
, maBoundary
.X
+ maBoundary
.Width
- 1, maBoundary
.Y
+ maBoundary
.Height
- 1 );
270 pNewIMapObject
= new IMapRectangleObject( aRect
, aURL
, aAltText
, aDesc
, aTarget
, aName
, mbIsActive
, false );
274 case IMAP_OBJ_CIRCLE
:
276 const Point
aCenter( maCenter
.X
, maCenter
.Y
);
277 pNewIMapObject
= new IMapCircleObject( aCenter
, mnRadius
, aURL
, aAltText
, aDesc
, aTarget
, aName
, mbIsActive
, false );
281 case IMAP_OBJ_POLYGON
:
284 const sal_uInt16 nCount
= (sal_uInt16
)maPolygon
.getLength();
286 Polygon
aPoly( nCount
);
287 for( sal_uInt16 nPoint
= 0; nPoint
< nCount
; nPoint
++ )
289 Point
aPoint( maPolygon
[nPoint
].X
, maPolygon
[nPoint
].Y
);
290 aPoly
.SetPoint( aPoint
, nPoint
);
293 aPoly
.Optimize( PolyOptimizeFlags::CLOSE
);
294 pNewIMapObject
= new IMapPolygonObject( aPoly
, aURL
, aAltText
, aDesc
, aTarget
, aName
, mbIsActive
, false );
299 SvxMacroTableDtor aMacroTable
;
300 mpEvents
->copyMacrosIntoTable(aMacroTable
);
301 pNewIMapObject
->SetMacroTable( aMacroTable
);
303 return pNewIMapObject
;
308 Any SAL_CALL
SvUnoImageMapObject::queryInterface( const Type
& rType
)
309 throw( RuntimeException
, std::exception
)
311 return OWeakAggObject::queryInterface( rType
);
314 Any SAL_CALL
SvUnoImageMapObject::queryAggregation( const Type
& rType
)
315 throw(RuntimeException
, std::exception
)
319 if( rType
== cppu::UnoType
<XServiceInfo
>::get())
320 aAny
<<= Reference
< XServiceInfo
>(this);
321 else if( rType
== cppu::UnoType
<XTypeProvider
>::get())
322 aAny
<<= Reference
< XTypeProvider
>(this);
323 else if( rType
== cppu::UnoType
<XPropertySet
>::get())
324 aAny
<<= Reference
< XPropertySet
>(this);
325 else if( rType
== cppu::UnoType
<XEventsSupplier
>::get())
326 aAny
<<= Reference
< XEventsSupplier
>(this);
327 else if( rType
== cppu::UnoType
<XMultiPropertySet
>::get())
328 aAny
<<= Reference
< XMultiPropertySet
>(this);
329 else if( rType
== cppu::UnoType
<XUnoTunnel
>::get())
330 aAny
<<= Reference
< XUnoTunnel
>(this);
332 aAny
<<= OWeakAggObject::queryAggregation( rType
);
337 void SAL_CALL
SvUnoImageMapObject::acquire() throw()
339 OWeakAggObject::acquire();
342 void SAL_CALL
SvUnoImageMapObject::release() throw()
344 OWeakAggObject::release();
347 uno::Sequence
< uno::Type
> SAL_CALL
SvUnoImageMapObject::getTypes()
348 throw (uno::RuntimeException
, std::exception
)
350 uno::Sequence
< uno::Type
> aTypes( 7 );
351 uno::Type
* pTypes
= aTypes
.getArray();
353 *pTypes
++ = cppu::UnoType
<XAggregation
>::get();
354 *pTypes
++ = cppu::UnoType
<XEventsSupplier
>::get();
355 *pTypes
++ = cppu::UnoType
<XServiceInfo
>::get();
356 *pTypes
++ = cppu::UnoType
<XPropertySet
>::get();
357 *pTypes
++ = cppu::UnoType
<XMultiPropertySet
>::get();
358 *pTypes
++ = cppu::UnoType
<XTypeProvider
>::get();
359 *pTypes
++ = cppu::UnoType
<XUnoTunnel
>::get();
364 uno::Sequence
< sal_Int8
> SAL_CALL
SvUnoImageMapObject::getImplementationId()
365 throw (uno::RuntimeException
, std::exception
)
367 return css::uno::Sequence
<sal_Int8
>();
371 sal_Bool SAL_CALL
SvUnoImageMapObject::supportsService( const OUString
& ServiceName
) throw(RuntimeException
, std::exception
)
373 return cppu::supportsService(this, ServiceName
);
376 Sequence
< OUString
> SAL_CALL
SvUnoImageMapObject::getSupportedServiceNames()
377 throw(RuntimeException
, std::exception
)
379 Sequence
< OUString
> aSNS( 2 );
380 aSNS
.getArray()[0] = "com.sun.star.image.ImageMapObject";
383 case IMAP_OBJ_POLYGON
:
385 aSNS
.getArray()[1] = "com.sun.star.image.ImageMapPolygonObject";
387 case IMAP_OBJ_RECTANGLE
:
388 aSNS
.getArray()[1] = "com.sun.star.image.ImageMapRectangleObject";
390 case IMAP_OBJ_CIRCLE
:
391 aSNS
.getArray()[1] = "com.sun.star.image.ImageMapCircleObject";
397 OUString SAL_CALL
SvUnoImageMapObject::getImplementationName() throw(RuntimeException
, std::exception
)
401 case IMAP_OBJ_POLYGON
:
403 return OUString("org.openoffice.comp.svt.ImageMapPolygonObject");
404 case IMAP_OBJ_CIRCLE
:
405 return OUString("org.openoffice.comp.svt.ImageMapCircleObject");
406 case IMAP_OBJ_RECTANGLE
:
407 return OUString("org.openoffice.comp.svt.ImageMapRectangleObject");
411 // overriden helpers from PropertySetHelper
412 void SvUnoImageMapObject::_setPropertyValues( const PropertyMapEntry
** ppEntries
, const Any
* pValues
)
413 throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
)
419 switch( (*ppEntries
)->mnHandle
)
422 bOk
= *pValues
>>= maURL
;
425 bOk
= *pValues
>>= maAltText
;
427 case HANDLE_DESCRIPTION
:
428 bOk
= *pValues
>>= maDesc
;
431 bOk
= *pValues
>>= maTarget
;
434 bOk
= *pValues
>>= maName
;
436 case HANDLE_ISACTIVE
:
437 bOk
= *pValues
>>= mbIsActive
;
439 case HANDLE_BOUNDARY
:
440 bOk
= *pValues
>>= maBoundary
;
443 bOk
= *pValues
>>= maCenter
;
446 bOk
= *pValues
>>= mnRadius
;
449 bOk
= *pValues
>>= maPolygon
;
452 OSL_FAIL( "SvUnoImageMapObject::_setPropertyValues: unexpected property handle" );
457 throw IllegalArgumentException();
464 void SvUnoImageMapObject::_getPropertyValues( const PropertyMapEntry
** ppEntries
, Any
* pValues
)
465 throw(UnknownPropertyException
, WrappedTargetException
)
469 switch( (*ppEntries
)->mnHandle
)
475 *pValues
<<= maAltText
;
477 case HANDLE_DESCRIPTION
:
481 *pValues
<<= maTarget
;
486 case HANDLE_ISACTIVE
:
487 *pValues
<<= mbIsActive
;
489 case HANDLE_BOUNDARY
:
490 *pValues
<<= maBoundary
;
493 *pValues
<<= maCenter
;
496 *pValues
<<= mnRadius
;
499 *pValues
<<= maPolygon
;
502 OSL_FAIL( "SvUnoImageMapObject::_getPropertyValues: unexpected property handle" );
512 Reference
< XNameReplace
> SAL_CALL
SvUnoImageMapObject::getEvents()
513 throw( RuntimeException
, std::exception
)
515 // try weak reference first
516 Reference
< XNameReplace
> xEvents( mpEvents
);
522 class SvUnoImageMap
: public WeakImplHelper3
< XIndexContainer
, XServiceInfo
, XUnoTunnel
>
525 SvUnoImageMap( const SvEventDescription
* pSupportedMacroItems
);
526 SvUnoImageMap( const ImageMap
& rMap
, const SvEventDescription
* pSupportedMacroItems
);
527 virtual ~SvUnoImageMap();
529 bool fillImageMap( ImageMap
& rMap
) const;
530 static SvUnoImageMapObject
* getObject( const Any
& aElement
) throw( IllegalArgumentException
);
532 UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMap
)
535 virtual void SAL_CALL
insertByIndex( sal_Int32 Index
, const Any
& Element
) throw( IllegalArgumentException
, IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
536 virtual void SAL_CALL
removeByIndex( sal_Int32 Index
) throw( IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
539 virtual void SAL_CALL
replaceByIndex( sal_Int32 Index
, const Any
& Element
) throw( IllegalArgumentException
, IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
542 virtual sal_Int32 SAL_CALL
getCount( ) throw( RuntimeException
, std::exception
) SAL_OVERRIDE
;
543 virtual Any SAL_CALL
getByIndex( sal_Int32 Index
) throw( IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
546 virtual Type SAL_CALL
getElementType( ) throw( RuntimeException
, std::exception
) SAL_OVERRIDE
;
547 virtual sal_Bool SAL_CALL
hasElements( ) throw( RuntimeException
, std::exception
) SAL_OVERRIDE
;
550 virtual OUString SAL_CALL
getImplementationName( ) throw( RuntimeException
, std::exception
) SAL_OVERRIDE
;
551 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw( RuntimeException
, std::exception
) SAL_OVERRIDE
;
552 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw( RuntimeException
, std::exception
) SAL_OVERRIDE
;
557 std::list
< SvUnoImageMapObject
* > maObjectList
;
560 UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMap
);
562 SvUnoImageMap::SvUnoImageMap( const SvEventDescription
* )
566 SvUnoImageMap::SvUnoImageMap( const ImageMap
& rMap
, const SvEventDescription
* pSupportedMacroItems
)
568 maName
= rMap
.GetName();
570 const std::size_t nCount
= rMap
.GetIMapObjectCount();
571 for( std::size_t nPos
= 0; nPos
< nCount
; nPos
++ )
573 IMapObject
* pMapObject
= rMap
.GetIMapObject( nPos
);
574 SvUnoImageMapObject
* pUnoObj
= new SvUnoImageMapObject( *pMapObject
, pSupportedMacroItems
);
576 maObjectList
.push_back( pUnoObj
);
580 SvUnoImageMap::~SvUnoImageMap()
582 std::list
< SvUnoImageMapObject
* >::iterator aIter
= maObjectList
.begin();
583 const std::list
< SvUnoImageMapObject
* >::iterator aEnd
= maObjectList
.end();
584 while( aIter
!= aEnd
)
586 (*aIter
++)->release();
590 SvUnoImageMapObject
* SvUnoImageMap::getObject( const Any
& aElement
)
591 throw( IllegalArgumentException
)
593 Reference
< XInterface
> xObject
;
594 aElement
>>= xObject
;
596 SvUnoImageMapObject
* pObject
= SvUnoImageMapObject::getImplementation( xObject
);
597 if( NULL
== pObject
)
598 throw IllegalArgumentException();
604 void SAL_CALL
SvUnoImageMap::insertByIndex( sal_Int32 Index
, const Any
& Element
)
605 throw( IllegalArgumentException
, IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
, std::exception
)
607 SvUnoImageMapObject
* pObject
= getObject( Element
);
608 const sal_Int32 nCount
= maObjectList
.size();
609 if( NULL
== pObject
|| Index
> nCount
)
610 throw IndexOutOfBoundsException();
614 if( Index
== nCount
)
615 maObjectList
.push_back( pObject
);
618 std::list
< SvUnoImageMapObject
* >::iterator aIter
= maObjectList
.begin();
619 for( sal_Int32 n
= 0; n
< Index
; n
++ )
622 maObjectList
.insert( aIter
, pObject
);
626 void SAL_CALL
SvUnoImageMap::removeByIndex( sal_Int32 nIndex
) throw(IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
, std::exception
)
628 const sal_Int32 nCount
= maObjectList
.size();
629 if( nIndex
>= nCount
)
630 throw IndexOutOfBoundsException();
632 if( nCount
- 1 == nIndex
)
634 maObjectList
.back()->release();
635 maObjectList
.pop_back();
639 std::list
< SvUnoImageMapObject
* >::iterator aIter
= maObjectList
.begin();
640 std::advance(aIter
, nIndex
);
643 maObjectList
.erase( aIter
);
648 void SAL_CALL
SvUnoImageMap::replaceByIndex( sal_Int32 Index
, const Any
& Element
) throw(IllegalArgumentException
, IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
, std::exception
)
650 SvUnoImageMapObject
* pObject
= getObject( Element
);
651 const sal_Int32 nCount
= maObjectList
.size();
652 if( NULL
== pObject
|| Index
>= nCount
)
653 throw IndexOutOfBoundsException();
655 std::list
< SvUnoImageMapObject
* >::iterator aIter
= maObjectList
.begin();
656 for( sal_Int32 n
= 0; n
< Index
; n
++ )
665 sal_Int32 SAL_CALL
SvUnoImageMap::getCount( ) throw(RuntimeException
, std::exception
)
667 return maObjectList
.size();
670 Any SAL_CALL
SvUnoImageMap::getByIndex( sal_Int32 Index
) throw(IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
, std::exception
)
672 const sal_Int32 nCount
= maObjectList
.size();
673 if( Index
>= nCount
)
674 throw IndexOutOfBoundsException();
676 std::list
< SvUnoImageMapObject
* >::iterator aIter
= maObjectList
.begin();
677 for( sal_Int32 n
= 0; n
< Index
; n
++ )
680 Reference
< XPropertySet
> xObj( *aIter
);
681 return makeAny( xObj
);
685 Type SAL_CALL
SvUnoImageMap::getElementType( ) throw(RuntimeException
, std::exception
)
687 return cppu::UnoType
<XPropertySet
>::get();
690 sal_Bool SAL_CALL
SvUnoImageMap::hasElements( ) throw(RuntimeException
, std::exception
)
692 return (!maObjectList
.empty());
696 OUString SAL_CALL
SvUnoImageMap::getImplementationName( )
697 throw(RuntimeException
, std::exception
)
699 return OUString( "org.openoffice.comp.svt.SvUnoImageMap" );
702 sal_Bool SAL_CALL
SvUnoImageMap::supportsService( const OUString
& ServiceName
)
703 throw(RuntimeException
, std::exception
)
705 return cppu::supportsService(this, ServiceName
);
708 Sequence
< OUString
> SAL_CALL
SvUnoImageMap::getSupportedServiceNames( )
709 throw(RuntimeException
, std::exception
)
711 const OUString
aSN( "com.sun.star.image.ImageMap" );
712 return Sequence
< OUString
>( &aSN
, 1 );
715 bool SvUnoImageMap::fillImageMap( ImageMap
& rMap
) const
717 rMap
.ClearImageMap();
719 rMap
.SetName( maName
);
721 std::list
< SvUnoImageMapObject
* >::const_iterator aIter
= maObjectList
.begin();
722 const std::list
< SvUnoImageMapObject
* >::const_iterator aEnd
= maObjectList
.end();
723 while( aIter
!= aEnd
)
725 IMapObject
* pNewMapObject
= (*aIter
)->createIMapObject();
726 rMap
.InsertIMapObject( *pNewMapObject
);
727 delete pNewMapObject
;
736 // factory helper methods
739 Reference
< XInterface
> SvUnoImageMapRectangleObject_createInstance( const SvEventDescription
* pSupportedMacroItems
)
741 return (XWeak
*)new SvUnoImageMapObject( IMAP_OBJ_RECTANGLE
, pSupportedMacroItems
);
744 Reference
< XInterface
> SvUnoImageMapCircleObject_createInstance( const SvEventDescription
* pSupportedMacroItems
)
746 return (XWeak
*)new SvUnoImageMapObject( IMAP_OBJ_CIRCLE
, pSupportedMacroItems
);
749 Reference
< XInterface
> SvUnoImageMapPolygonObject_createInstance( const SvEventDescription
* pSupportedMacroItems
)
751 return (XWeak
*)new SvUnoImageMapObject( IMAP_OBJ_POLYGON
, pSupportedMacroItems
);
754 Reference
< XInterface
> SvUnoImageMap_createInstance( const SvEventDescription
* pSupportedMacroItems
)
756 return (XWeak
*)new SvUnoImageMap( pSupportedMacroItems
);
759 Reference
< XInterface
> SvUnoImageMap_createInstance( const ImageMap
& rMap
, const SvEventDescription
* pSupportedMacroItems
)
761 return (XWeak
*)new SvUnoImageMap( rMap
, pSupportedMacroItems
);
764 bool SvUnoImageMap_fillImageMap( Reference
< XInterface
> xImageMap
, ImageMap
& rMap
)
766 SvUnoImageMap
* pUnoImageMap
= SvUnoImageMap::getImplementation( xImageMap
);
767 if( NULL
== pUnoImageMap
)
770 return pUnoImageMap
->fillImageMap( rMap
);
773 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */