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