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