xref: /AOO41X/main/svtools/source/uno/unoimap.cxx (revision 5900e8ec128faec89519683efce668ccd8cc6084)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26 #include <com/sun/star/container/XNameContainer.hpp>
27 #include <com/sun/star/container/XIndexContainer.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/document/XEventsSupplier.hpp>
30 #include <com/sun/star/lang/XUnoTunnel.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/awt/Rectangle.hpp>
33 #include <com/sun/star/awt/Point.hpp>
34 #include <com/sun/star/drawing/PointSequence.hpp>
35 #include <comphelper/servicehelper.hxx>
36 #include <comphelper/propertysethelper.hxx>
37 #include <comphelper/propertysetinfo.hxx>
38 #include <cppuhelper/weakagg.hxx>
39 #include <cppuhelper/implbase3.hxx>
40 #include <list>
41 #include <rtl/uuid.h>
42 #include <vos/mutex.hxx>
43 #include <vcl/svapp.hxx>
44 #include <svtools/unoevent.hxx>
45 #include <svtools/unoimap.hxx>
46 #include <svtools/imap.hxx>
47 #include <svtools/imapcirc.hxx>
48 #include <svtools/imaprect.hxx>
49 #include <svtools/imappoly.hxx>
50 
51 #ifndef SEQTYPE
52  #if defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)
53   #define SEQTYPE(x) (new ::com::sun::star::uno::Type( x ))
54  #else
55   #define SEQTYPE(x) &(x)
56  #endif
57 #endif
58 
59 #define MAP_LEN(x) x, sizeof(x)-1
60 
61 
62 using namespace comphelper;
63 using namespace cppu;
64 using namespace com::sun::star;
65 using namespace com::sun::star::uno;
66 using namespace com::sun::star::lang;
67 using namespace com::sun::star::container;
68 using namespace com::sun::star::beans;
69 using namespace com::sun::star::document;
70 using namespace com::sun::star::drawing;
71 
72 const sal_Int32 HANDLE_URL = 1;
73 const sal_Int32 HANDLE_DESCRIPTION = 2;
74 const sal_Int32 HANDLE_TARGET = 3;
75 const sal_Int32 HANDLE_NAME = 4;
76 const sal_Int32 HANDLE_ISACTIVE = 5;
77 const sal_Int32 HANDLE_POLYGON = 6;
78 const sal_Int32 HANDLE_CENTER = 7;
79 const sal_Int32 HANDLE_RADIUS = 8;
80 const sal_Int32 HANDLE_BOUNDARY = 9;
81 const sal_Int32 HANDLE_TITLE = 10;
82 
83 class SvUnoImageMapObject : public OWeakAggObject,
84                             public XEventsSupplier,
85                             public XServiceInfo,
86                             public PropertySetHelper,
87                             public XTypeProvider,
88                             public XUnoTunnel
89 {
90 public:
91     SvUnoImageMapObject( sal_uInt16 nType, const SvEventDescription* pSupportedMacroItems );
92     SvUnoImageMapObject( const IMapObject& rMapObject, const SvEventDescription* pSupportedMacroItems );
93     virtual ~SvUnoImageMapObject() throw();
94 
95     UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMapObject )
96 
97     IMapObject* createIMapObject() const;
98 
99     SvMacroTableEventDescriptor* mpEvents;
100 
101     // overiden helpers from PropertySetHelper
102     virtual void _setPropertyValues( const PropertyMapEntry** ppEntries, const Any* pValues ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException );
103     virtual void _getPropertyValues( const PropertyMapEntry** ppEntries, Any* pValue ) throw(UnknownPropertyException, WrappedTargetException );
104 
105     // XInterface
106     virtual Any SAL_CALL queryAggregation( const Type & rType ) throw(RuntimeException);
107     virtual Any SAL_CALL queryInterface( const Type & rType ) throw(RuntimeException);
108     virtual void SAL_CALL acquire() throw();
109     virtual void SAL_CALL release() throw();
110 
111     // XTypeProvider
112     virtual Sequence< Type > SAL_CALL getTypes(  ) throw(RuntimeException);
113     virtual Sequence< sal_Int8 > SAL_CALL getImplementationId(  ) throw(RuntimeException);
114 
115     // XEventsSupplier
116     virtual Reference< ::com::sun::star::container::XNameReplace > SAL_CALL getEvents(  ) throw(RuntimeException);
117 
118     // XServiceInfo
119     virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw( RuntimeException );
120     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( RuntimeException );
121     virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw( RuntimeException );
122 
123 private:
124     static PropertySetInfo* createPropertySetInfo( sal_uInt16 nType );
125 
126 
127     sal_uInt16 mnType;
128 
129     ::rtl::OUString maURL;
130     ::rtl::OUString maAltText;
131     ::rtl::OUString maDesc;
132     ::rtl::OUString maTarget;
133     ::rtl::OUString maName;
134     sal_Bool mbIsActive;
135     awt::Rectangle maBoundary;
136     awt::Point maCenter;
137     sal_Int32 mnRadius;
138     PointSequence maPolygon;
139 };
140 
141 UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMapObject );
142 
createPropertySetInfo(sal_uInt16 nType)143 PropertySetInfo* SvUnoImageMapObject::createPropertySetInfo( sal_uInt16 nType )
144 {
145     switch( nType )
146     {
147     case IMAP_OBJ_POLYGON:
148         {
149             static PropertyMapEntry aPolygonObj_Impl[] =
150             {
151                 { MAP_LEN( "URL" ),         HANDLE_URL,         &::getCppuType((const ::rtl::OUString*)0),     0, 0 },
152                 { MAP_LEN( "Title" ),       HANDLE_TITLE,       &::getCppuType((const ::rtl::OUString*)0),     0, 0 },
153                 { MAP_LEN( "Description" ), HANDLE_DESCRIPTION, &::getCppuType((const ::rtl::OUString*)0),     0, 0 },
154                 { MAP_LEN( "Target" ),      HANDLE_TARGET,      &::getCppuType((const ::rtl::OUString*)0),     0, 0 },
155                 { MAP_LEN( "Name" ),        HANDLE_NAME,        &::getCppuType((const ::rtl::OUString*)0),     0, 0 },
156                 { MAP_LEN( "IsActive" ),    HANDLE_ISACTIVE,    &::getBooleanCppuType(),                0, 0 },
157                 { MAP_LEN( "Polygon" ),     HANDLE_POLYGON,     SEQTYPE(::getCppuType((const PointSequence*)0)),    0, 0 },
158                 {0,0,0,0,0,0}
159             };
160 
161             return new PropertySetInfo( aPolygonObj_Impl );
162         }
163     case IMAP_OBJ_CIRCLE:
164         {
165             static PropertyMapEntry aCircleObj_Impl[] =
166             {
167                 { MAP_LEN( "URL" ),         HANDLE_URL,         &::getCppuType((const ::rtl::OUString*)0),     0, 0 },
168                 { MAP_LEN( "Title" ),       HANDLE_TITLE,       &::getCppuType((const ::rtl::OUString*)0),     0, 0 },
169                 { MAP_LEN( "Description" ), HANDLE_DESCRIPTION, &::getCppuType((const ::rtl::OUString*)0),     0, 0 },
170                 { MAP_LEN( "Target" ),      HANDLE_TARGET,      &::getCppuType((const ::rtl::OUString*)0),     0, 0 },
171                 { MAP_LEN( "Name" ),            HANDLE_NAME,        &::getCppuType((const ::rtl::OUString*)0),     0, 0 },
172                 { MAP_LEN( "IsActive" ),        HANDLE_ISACTIVE,    &::getBooleanCppuType(),                0, 0 },
173                 { MAP_LEN( "Center" ),      HANDLE_CENTER,      &::getCppuType((const awt::Point*)0),   0, 0 },
174                 { MAP_LEN( "Radius" ),      HANDLE_RADIUS,      &::getCppuType((const sal_Int32*)0),    0, 0 },
175                 {0,0,0,0,0,0}
176             };
177 
178             return new PropertySetInfo( aCircleObj_Impl );
179         }
180     case IMAP_OBJ_RECTANGLE:
181     default:
182         {
183             static PropertyMapEntry aRectangleObj_Impl[] =
184             {
185                 { MAP_LEN( "URL" ),         HANDLE_URL,         &::getCppuType((const ::rtl::OUString*)0), 0, 0 },
186                 { MAP_LEN( "Title" ),       HANDLE_TITLE,       &::getCppuType((const ::rtl::OUString*)0),     0, 0 },
187                 { MAP_LEN( "Description" ), HANDLE_DESCRIPTION, &::getCppuType((const ::rtl::OUString*)0), 0, 0 },
188                 { MAP_LEN( "Target" ),      HANDLE_TARGET,      &::getCppuType((const ::rtl::OUString*)0), 0, 0 },
189                 { MAP_LEN( "Name" ),        HANDLE_NAME,        &::getCppuType((const ::rtl::OUString*)0), 0, 0 },
190                 { MAP_LEN( "IsActive" ),    HANDLE_ISACTIVE,    &::getBooleanCppuType(),            0, 0 },
191                 { MAP_LEN( "Boundary" ),    HANDLE_BOUNDARY,    &::getCppuType((const awt::Rectangle*)0),   0, 0 },
192                 {0,0,0,0,0,0}
193             };
194 
195             return new PropertySetInfo( aRectangleObj_Impl );
196         }
197     }
198 }
199 
SvUnoImageMapObject(sal_uInt16 nType,const SvEventDescription * pSupportedMacroItems)200 SvUnoImageMapObject::SvUnoImageMapObject( sal_uInt16 nType, const SvEventDescription* pSupportedMacroItems )
201 :   PropertySetHelper( createPropertySetInfo( nType ) ),
202     mnType( nType )
203 ,   mbIsActive( true )
204 ,   mnRadius( 0 )
205 {
206     mpEvents = new SvMacroTableEventDescriptor( pSupportedMacroItems );
207     mpEvents->acquire();
208 }
209 
SvUnoImageMapObject(const IMapObject & rMapObject,const SvEventDescription * pSupportedMacroItems)210 SvUnoImageMapObject::SvUnoImageMapObject( const IMapObject& rMapObject, const SvEventDescription* pSupportedMacroItems )
211 :   PropertySetHelper( createPropertySetInfo( rMapObject.GetType() ) ),
212     mnType( rMapObject.GetType() )
213 ,   mbIsActive( true )
214 ,   mnRadius( 0 )
215 {
216     maURL = rMapObject.GetURL();
217     maAltText = rMapObject.GetAltText();
218     maDesc = rMapObject.GetDesc();
219     maTarget = rMapObject.GetTarget();
220     maName = rMapObject.GetName();
221     mbIsActive = rMapObject.IsActive();
222 
223     switch( mnType )
224     {
225     case IMAP_OBJ_RECTANGLE:
226         {
227             const Rectangle aRect( ((IMapRectangleObject*)&rMapObject)->GetRectangle(sal_False) );
228             maBoundary.X = aRect.Left();
229             maBoundary.Y = aRect.Top();
230             maBoundary.Width = aRect.GetWidth();
231             maBoundary.Height = aRect.GetHeight();
232         }
233         break;
234     case IMAP_OBJ_CIRCLE:
235         {
236             mnRadius = (sal_Int32)((IMapCircleObject*)&rMapObject)->GetRadius(sal_False);
237             const Point aPoint( ((IMapCircleObject*)&rMapObject)->GetCenter(sal_False) );
238 
239             maCenter.X = aPoint.X();
240             maCenter.Y = aPoint.Y();
241         }
242         break;
243     case IMAP_OBJ_POLYGON:
244     default:
245         {
246             const Polygon aPoly( ((IMapPolygonObject*)&rMapObject)->GetPolygon(sal_False) );
247 
248             const sal_uInt16 nCount = aPoly.GetSize();
249             maPolygon.realloc( nCount );
250             awt::Point* pPoints = maPolygon.getArray();
251 
252             for( sal_uInt16 nPoint = 0; nPoint < nCount; nPoint++ )
253             {
254                 const Point& rPoint = aPoly.GetPoint( nPoint );
255                 pPoints->X = rPoint.X();
256                 pPoints->Y = rPoint.Y();
257 
258                 pPoints++;
259             }
260         }
261     }
262 
263     mpEvents = new SvMacroTableEventDescriptor( rMapObject.GetMacroTable(), pSupportedMacroItems );
264     mpEvents->acquire();
265 }
266 
~SvUnoImageMapObject()267 SvUnoImageMapObject::~SvUnoImageMapObject() throw()
268 {
269     mpEvents->release();
270 }
271 
createIMapObject() const272 IMapObject* SvUnoImageMapObject::createIMapObject() const
273 {
274     const String aURL( maURL );
275     const String aAltText( maAltText );
276     const String aDesc( maDesc );
277     const String aTarget( maTarget );
278     const String aName( maName );
279 
280     IMapObject* pNewIMapObject;
281 
282     switch( mnType )
283     {
284     case IMAP_OBJ_RECTANGLE:
285         {
286             const Rectangle aRect( maBoundary.X, maBoundary.Y, maBoundary.X + maBoundary.Width - 1, maBoundary.Y + maBoundary.Height - 1 );
287             pNewIMapObject = new IMapRectangleObject( aRect, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, sal_False );
288         }
289         break;
290 
291     case IMAP_OBJ_CIRCLE:
292         {
293             const Point aCenter( maCenter.X, maCenter.Y );
294             pNewIMapObject = new IMapCircleObject( aCenter, mnRadius, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, sal_False );
295         }
296         break;
297 
298     case IMAP_OBJ_POLYGON:
299     default:
300         {
301             const sal_uInt16 nCount = (sal_uInt16)maPolygon.getLength();
302 
303             Polygon aPoly( nCount );
304             for( sal_uInt16 nPoint = 0; nPoint < nCount; nPoint++ )
305             {
306                 Point aPoint( maPolygon[nPoint].X, maPolygon[nPoint].Y );
307                 aPoly.SetPoint( aPoint, nPoint );
308             }
309 
310             aPoly.Optimize( POLY_OPTIMIZE_CLOSE );
311             pNewIMapObject = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, sal_False );
312         }
313         break;
314     }
315 
316     SvxMacroTableDtor aMacroTable;
317     mpEvents->copyMacrosIntoTable(aMacroTable);
318     pNewIMapObject->SetMacroTable( aMacroTable );
319 
320     return pNewIMapObject;
321 }
322 
323 // XInterface
324 
queryInterface(const Type & rType)325 Any SAL_CALL SvUnoImageMapObject::queryInterface( const Type & rType )
326     throw( RuntimeException )
327 {
328     return OWeakAggObject::queryInterface( rType );
329 }
330 
queryAggregation(const Type & rType)331 Any SAL_CALL SvUnoImageMapObject::queryAggregation( const Type & rType )
332     throw(RuntimeException)
333 {
334     Any aAny;
335 
336     if( rType == ::getCppuType((const Reference< XServiceInfo >*)0) )
337         aAny <<= Reference< XServiceInfo >(this);
338     else if( rType == ::getCppuType((const Reference< XTypeProvider >*)0) )
339         aAny <<= Reference< XTypeProvider >(this);
340     else if( rType == ::getCppuType((const Reference< XPropertySet >*)0) )
341         aAny <<= Reference< XPropertySet >(this);
342     else if( rType == ::getCppuType((const Reference< XEventsSupplier >*)0) )
343         aAny <<= Reference< XEventsSupplier >(this);
344     else if( rType == ::getCppuType((const Reference< XMultiPropertySet >*)0) )
345         aAny <<= Reference< XMultiPropertySet >(this);
346     else if( rType == ::getCppuType((const Reference< XUnoTunnel >*)0) )
347         aAny <<= Reference< XUnoTunnel >(this);
348     else
349         aAny <<= OWeakAggObject::queryAggregation( rType );
350 
351     return aAny;
352 }
353 
acquire()354 void SAL_CALL SvUnoImageMapObject::acquire() throw()
355 {
356     OWeakAggObject::acquire();
357 }
358 
release()359 void SAL_CALL SvUnoImageMapObject::release() throw()
360 {
361     OWeakAggObject::release();
362 }
363 
getTypes()364 uno::Sequence< uno::Type > SAL_CALL SvUnoImageMapObject::getTypes()
365     throw (uno::RuntimeException)
366 {
367     uno::Sequence< uno::Type > aTypes( 7 );
368     uno::Type* pTypes = aTypes.getArray();
369 
370     *pTypes++ = ::getCppuType((const uno::Reference< XAggregation>*)0);
371     *pTypes++ = ::getCppuType((const uno::Reference< XEventsSupplier>*)0);
372     *pTypes++ = ::getCppuType((const uno::Reference< XServiceInfo>*)0);
373     *pTypes++ = ::getCppuType((const uno::Reference< XPropertySet>*)0);
374     *pTypes++ = ::getCppuType((const uno::Reference< XMultiPropertySet>*)0);
375     *pTypes++ = ::getCppuType((const uno::Reference< XTypeProvider>*)0);
376     *pTypes++ = ::getCppuType((const uno::Reference< XUnoTunnel>*)0);
377 
378     return aTypes;
379 }
380 
getImplementationId()381 uno::Sequence< sal_Int8 > SAL_CALL SvUnoImageMapObject::getImplementationId()
382     throw (uno::RuntimeException)
383 {
384     vos::OGuard aGuard( Application::GetSolarMutex() );
385 
386     static uno::Sequence< sal_Int8 > aId;
387     if( aId.getLength() == 0 )
388     {
389         aId.realloc( 16 );
390         rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
391     }
392     return aId;
393 }
394 
395 // XServiceInfo
396 
supportsService(const::rtl::OUString & ServiceName)397 sal_Bool SAL_CALL SvUnoImageMapObject::supportsService( const  ::rtl::OUString& ServiceName ) throw(RuntimeException)
398 {
399     const Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() );
400     const ::rtl::OUString * pArray = aSNL.getConstArray();
401 
402     const sal_Int32 nCount = aSNL.getLength();
403     for( sal_Int32 i = 0; i < nCount; i++ )
404         if( pArray[i] == ServiceName )
405             return sal_True;
406 
407     return sal_False;
408 }
409 
getSupportedServiceNames()410 Sequence< ::rtl::OUString > SAL_CALL SvUnoImageMapObject::getSupportedServiceNames()
411     throw(RuntimeException)
412 {
413     Sequence< ::rtl::OUString > aSNS( 2 );
414     aSNS.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.image.ImageMapObject" ));
415     switch( mnType )
416     {
417     case IMAP_OBJ_POLYGON:
418     default:
419         aSNS.getArray()[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.image.ImageMapPolygonObject" ));
420         break;
421     case IMAP_OBJ_RECTANGLE:
422         aSNS.getArray()[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.image.ImageMapRectangleObject" ));
423         break;
424     case IMAP_OBJ_CIRCLE:
425         aSNS.getArray()[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.image.ImageMapCircleObject" ));
426         break;
427     }
428     return aSNS;
429 }
430 
getImplementationName()431 ::rtl::OUString SAL_CALL SvUnoImageMapObject::getImplementationName() throw(RuntimeException)
432 {
433     switch( mnType )
434     {
435     case IMAP_OBJ_POLYGON:
436     default:
437         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.svt.ImageMapPolygonObject") );
438     case IMAP_OBJ_CIRCLE:
439         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.svt.ImageMapCircleObject") );
440     case IMAP_OBJ_RECTANGLE:
441         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.svt.ImageMapRectangleObject") );
442     }
443 }
444 
445 // overiden helpers from PropertySetHelper
_setPropertyValues(const PropertyMapEntry ** ppEntries,const Any * pValues)446 void SvUnoImageMapObject::_setPropertyValues( const PropertyMapEntry** ppEntries, const Any* pValues )
447     throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException )
448 {
449     sal_Bool bOk = sal_False;
450 
451     while( *ppEntries )
452     {
453         switch( (*ppEntries)->mnHandle )
454         {
455         case HANDLE_URL:
456             bOk = *pValues >>= maURL;
457             break;
458         case HANDLE_TITLE:
459             bOk = *pValues >>= maAltText;
460             break;
461         case HANDLE_DESCRIPTION:
462             bOk = *pValues >>= maDesc;
463             break;
464         case HANDLE_TARGET:
465             bOk = *pValues >>= maTarget;
466             break;
467         case HANDLE_NAME:
468             bOk = *pValues >>= maName;
469             break;
470         case HANDLE_ISACTIVE:
471             bOk = *pValues >>= mbIsActive;
472             break;
473         case HANDLE_BOUNDARY:
474             bOk = *pValues >>= maBoundary;
475             break;
476         case HANDLE_CENTER:
477             bOk = *pValues >>= maCenter;
478             break;
479         case HANDLE_RADIUS:
480             bOk = *pValues >>= mnRadius;
481             break;
482         case HANDLE_POLYGON:
483             bOk = *pValues >>= maPolygon;
484             break;
485         default:
486             DBG_ERROR( "SvUnoImageMapObject::_setPropertyValues: unexpected property handle" );
487             break;
488         }
489 
490         if( !bOk )
491             throw IllegalArgumentException();
492 
493         ppEntries++;
494         pValues++;
495     }
496 }
497 
_getPropertyValues(const PropertyMapEntry ** ppEntries,Any * pValues)498 void SvUnoImageMapObject::_getPropertyValues( const PropertyMapEntry** ppEntries, Any* pValues )
499     throw(UnknownPropertyException, WrappedTargetException )
500 {
501     while( *ppEntries )
502     {
503         switch( (*ppEntries)->mnHandle )
504         {
505         case HANDLE_URL:
506             *pValues <<= maURL;
507             break;
508         case HANDLE_TITLE:
509             *pValues <<= maAltText;
510             break;
511         case HANDLE_DESCRIPTION:
512             *pValues <<= maDesc;
513             break;
514         case HANDLE_TARGET:
515             *pValues <<= maTarget;
516             break;
517         case HANDLE_NAME:
518             *pValues <<= maName;
519             break;
520         case HANDLE_ISACTIVE:
521             *pValues <<= mbIsActive;
522             break;
523         case HANDLE_BOUNDARY:
524             *pValues <<= maBoundary;
525             break;
526         case HANDLE_CENTER:
527             *pValues <<= maCenter;
528             break;
529         case HANDLE_RADIUS:
530             *pValues <<= mnRadius;
531             break;
532         case HANDLE_POLYGON:
533             *pValues <<= maPolygon;
534             break;
535         default:
536             DBG_ERROR( "SvUnoImageMapObject::_getPropertyValues: unexpected property handle" );
537             break;
538         }
539 
540         ppEntries++;
541         pValues++;
542     }
543 }
544 
545 
getEvents()546 Reference< XNameReplace > SAL_CALL SvUnoImageMapObject::getEvents()
547     throw( RuntimeException )
548 {
549     // try weak reference first
550     Reference< XNameReplace > xEvents( mpEvents );
551     return xEvents;
552 }
553 
554 ///////////////////////////////////////////////////////////////////////
555 
556 class SvUnoImageMap : public WeakImplHelper3< XIndexContainer, XServiceInfo, XUnoTunnel >
557 {
558 public:
559     SvUnoImageMap( const SvEventDescription* pSupportedMacroItems );
560     SvUnoImageMap( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems );
561     virtual ~SvUnoImageMap();
562 
563     sal_Bool fillImageMap( ImageMap& rMap ) const;
564     SvUnoImageMapObject* getObject( const Any& aElement ) const throw( IllegalArgumentException );
565 
566     UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMap )
567 
568     // XIndexContainer
569     virtual void SAL_CALL insertByIndex( sal_Int32 Index, const Any& Element ) throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException );
570     virtual void SAL_CALL removeByIndex( sal_Int32 Index ) throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException );
571 
572     // XIndexReplace
573     virtual void SAL_CALL replaceByIndex( sal_Int32 Index, const Any& Element ) throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException );
574 
575     // XIndexAccess
576     virtual sal_Int32 SAL_CALL getCount(  ) throw( RuntimeException );
577     virtual Any SAL_CALL getByIndex( sal_Int32 Index ) throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException );
578 
579     // XElementAccess
580     virtual Type SAL_CALL getElementType(  ) throw( RuntimeException );
581     virtual sal_Bool SAL_CALL hasElements(  ) throw( RuntimeException );
582 
583     // XSerivceInfo
584     virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw( RuntimeException );
585     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( RuntimeException );
586     virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw( RuntimeException );
587 
588 private:
589     ::rtl::OUString maName;
590 
591     std::list< SvUnoImageMapObject* > maObjectList;
592 };
593 
594 UNO3_GETIMPLEMENTATION_IMPL( SvUnoImageMap );
595 
SvUnoImageMap(const SvEventDescription *)596 SvUnoImageMap::SvUnoImageMap( const SvEventDescription* )
597 {
598 }
599 
SvUnoImageMap(const ImageMap & rMap,const SvEventDescription * pSupportedMacroItems)600 SvUnoImageMap::SvUnoImageMap( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems )
601 {
602     maName = rMap.GetName();
603 
604     const sal_uInt16 nCount = rMap.GetIMapObjectCount();
605     for( sal_uInt16 nPos = 0; nPos < nCount; nPos++ )
606     {
607         IMapObject* pMapObject = rMap.GetIMapObject( nPos );
608         SvUnoImageMapObject* pUnoObj = new SvUnoImageMapObject( *pMapObject, pSupportedMacroItems );
609         pUnoObj->acquire();
610         maObjectList.push_back( pUnoObj );
611     }
612 }
613 
~SvUnoImageMap()614 SvUnoImageMap::~SvUnoImageMap()
615 {
616     std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
617     const std::list< SvUnoImageMapObject* >::iterator aEnd = maObjectList.end();
618     while( aIter != aEnd )
619     {
620         (*aIter++)->release();
621     }
622 }
623 
getObject(const Any & aElement) const624 SvUnoImageMapObject* SvUnoImageMap::getObject( const Any& aElement ) const
625     throw( IllegalArgumentException )
626 {
627     Reference< XInterface > xObject;
628     aElement >>= xObject;
629 
630     SvUnoImageMapObject* pObject = SvUnoImageMapObject::getImplementation( xObject );
631     if( NULL == pObject )
632         throw IllegalArgumentException();
633 
634     return pObject;
635 }
636 
637 // XIndexContainer
insertByIndex(sal_Int32 Index,const Any & Element)638 void SAL_CALL SvUnoImageMap::insertByIndex( sal_Int32 Index, const Any& Element )
639     throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
640 {
641     SvUnoImageMapObject* pObject = getObject( Element );
642     const sal_Int32 nCount = maObjectList.size();
643     if( NULL == pObject || Index > nCount )
644         throw IndexOutOfBoundsException();
645 
646     pObject->acquire();
647 
648     if( Index == nCount )
649         maObjectList.push_back( pObject );
650     else
651     {
652         std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
653         for( sal_Int32 n = 0; n < Index; n++ )
654             aIter++;
655 
656         maObjectList.insert( aIter, pObject );
657     }
658 }
659 
removeByIndex(sal_Int32 Index)660 void SAL_CALL SvUnoImageMap::removeByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
661 {
662     const sal_Int32 nCount = maObjectList.size();
663     if( Index >= nCount )
664         throw IndexOutOfBoundsException();
665 
666     if( nCount - 1 == Index )
667     {
668         maObjectList.back()->release();
669         maObjectList.pop_back();
670     }
671     else
672     {
673         std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
674         for( sal_Int32 n = 0; n < Index; n++ )
675             aIter++;
676 
677         (*aIter)->release();
678         maObjectList.erase( aIter );
679     }
680 }
681 
682 // XIndexReplace
replaceByIndex(sal_Int32 Index,const Any & Element)683 void SAL_CALL SvUnoImageMap::replaceByIndex( sal_Int32 Index, const Any& Element ) throw(IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
684 {
685     SvUnoImageMapObject* pObject = getObject( Element );
686     const sal_Int32 nCount = maObjectList.size();
687     if( NULL == pObject || Index >= nCount )
688         throw IndexOutOfBoundsException();
689 
690     std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
691     for( sal_Int32 n = 0; n < Index; n++ )
692         aIter++;
693 
694     (*aIter)->release();
695     *aIter = pObject;
696     pObject->acquire();
697 }
698 
699 // XIndexAccess
getCount()700 sal_Int32 SAL_CALL SvUnoImageMap::getCount(  ) throw(RuntimeException)
701 {
702     return maObjectList.size();
703 }
704 
getByIndex(sal_Int32 Index)705 Any SAL_CALL SvUnoImageMap::getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
706 {
707     const sal_Int32 nCount = maObjectList.size();
708     if( Index >= nCount )
709         throw IndexOutOfBoundsException();
710 
711     std::list< SvUnoImageMapObject* >::iterator aIter = maObjectList.begin();
712     for( sal_Int32 n = 0; n < Index; n++ )
713         aIter++;
714 
715     Reference< XPropertySet > xObj( *aIter );
716     return makeAny( xObj );
717 }
718 
719 // XElementAccess
getElementType()720 Type SAL_CALL SvUnoImageMap::getElementType(  ) throw(RuntimeException)
721 {
722     return ::getCppuType((const Reference< XPropertySet >*)0);
723 }
724 
hasElements()725 sal_Bool SAL_CALL SvUnoImageMap::hasElements(  ) throw(RuntimeException)
726 {
727     return maObjectList.size() != 0;
728 }
729 
730 // XSerivceInfo
getImplementationName()731 ::rtl::OUString SAL_CALL SvUnoImageMap::getImplementationName(  )
732     throw(RuntimeException)
733 {
734     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.comp.svt.SvUnoImageMap" ) );
735 }
736 
supportsService(const::rtl::OUString & ServiceName)737 sal_Bool SAL_CALL SvUnoImageMap::supportsService( const ::rtl::OUString& ServiceName )
738     throw(RuntimeException)
739 {
740     const Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() );
741     const ::rtl::OUString * pArray = aSNL.getConstArray();
742 
743     const sal_Int32 nCount = aSNL.getLength();
744     for( sal_Int32 i = 0; i < nCount; i++ )
745         if( pArray[i] == ServiceName )
746             return sal_True;
747 
748     return sal_False;
749 }
750 
getSupportedServiceNames()751 Sequence< ::rtl::OUString > SAL_CALL SvUnoImageMap::getSupportedServiceNames(  )
752     throw(RuntimeException)
753 {
754     const ::rtl::OUString aSN( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.image.ImageMap" ) );
755     return Sequence< ::rtl::OUString >( &aSN, 1 );
756 }
757 
fillImageMap(ImageMap & rMap) const758 sal_Bool SvUnoImageMap::fillImageMap( ImageMap& rMap ) const
759 {
760     rMap.ClearImageMap();
761 
762     rMap.SetName( maName );
763 
764     std::list< SvUnoImageMapObject* >::const_iterator aIter = maObjectList.begin();
765     const std::list< SvUnoImageMapObject* >::const_iterator aEnd = maObjectList.end();
766     while( aIter != aEnd )
767     {
768         IMapObject* pNewMapObject = (*aIter)->createIMapObject();
769         rMap.InsertIMapObject( *pNewMapObject );
770         delete pNewMapObject;
771 
772         aIter++;
773     }
774 
775     return sal_True;
776 }
777 
778 // -------------------------------------------------------------------
779 // factory helper methods
780 // -------------------------------------------------------------------
781 
SvUnoImageMapRectangleObject_createInstance(const SvEventDescription * pSupportedMacroItems)782 Reference< XInterface > SvUnoImageMapRectangleObject_createInstance( const SvEventDescription* pSupportedMacroItems )
783 {
784     return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_RECTANGLE, pSupportedMacroItems );
785 }
786 
SvUnoImageMapCircleObject_createInstance(const SvEventDescription * pSupportedMacroItems)787 Reference< XInterface > SvUnoImageMapCircleObject_createInstance( const SvEventDescription* pSupportedMacroItems )
788 {
789     return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_CIRCLE, pSupportedMacroItems );
790 }
791 
SvUnoImageMapPolygonObject_createInstance(const SvEventDescription * pSupportedMacroItems)792 Reference< XInterface > SvUnoImageMapPolygonObject_createInstance( const SvEventDescription* pSupportedMacroItems )
793 {
794     return (XWeak*)new SvUnoImageMapObject( IMAP_OBJ_POLYGON, pSupportedMacroItems );
795 }
796 
SvUnoImageMap_createInstance(const SvEventDescription * pSupportedMacroItems)797 Reference< XInterface > SvUnoImageMap_createInstance( const SvEventDescription* pSupportedMacroItems )
798 {
799     return (XWeak*)new SvUnoImageMap( pSupportedMacroItems );
800 }
801 
SvUnoImageMap_createInstance(const ImageMap & rMap,const SvEventDescription * pSupportedMacroItems)802 Reference< XInterface > SvUnoImageMap_createInstance( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems )
803 {
804     return (XWeak*)new SvUnoImageMap( rMap, pSupportedMacroItems );
805 }
806 
SvUnoImageMap_fillImageMap(Reference<XInterface> xImageMap,ImageMap & rMap)807 sal_Bool SvUnoImageMap_fillImageMap( Reference< XInterface > xImageMap, ImageMap& rMap )
808 {
809     SvUnoImageMap* pUnoImageMap = SvUnoImageMap::getImplementation( xImageMap );
810     if( NULL == pUnoImageMap )
811         return sal_False;
812 
813     return pUnoImageMap->fillImageMap( rMap );
814 }
815