/src/libreoffice/svtools/source/uno/unoimap.cxx
Line | Count | Source |
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/XIndexContainer.hpp> |
21 | | #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
22 | | #include <com/sun/star/lang/XServiceInfo.hpp> |
23 | | #include <com/sun/star/document/XEventsSupplier.hpp> |
24 | | #include <com/sun/star/beans/XPropertySet.hpp> |
25 | | #include <com/sun/star/awt/Rectangle.hpp> |
26 | | #include <com/sun/star/awt/Point.hpp> |
27 | | #include <com/sun/star/drawing/PointSequence.hpp> |
28 | | #include <comphelper/servicehelper.hxx> |
29 | | #include <comphelper/propertysethelper.hxx> |
30 | | #include <comphelper/propertysetinfo.hxx> |
31 | | #include <cppuhelper/implbase.hxx> |
32 | | #include <cppuhelper/supportsservice.hxx> |
33 | | #include <algorithm> |
34 | | #include <osl/diagnose.h> |
35 | | #include <rtl/ref.hxx> |
36 | | #include <svtools/unoevent.hxx> |
37 | | #include <svtools/unoimap.hxx> |
38 | | #include <vcl/imap.hxx> |
39 | | #include <vcl/imapcirc.hxx> |
40 | | #include <vcl/imaprect.hxx> |
41 | | #include <vcl/imappoly.hxx> |
42 | | |
43 | | using namespace comphelper; |
44 | | using namespace cppu; |
45 | | using namespace com::sun::star; |
46 | | using namespace css::uno; |
47 | | using namespace css::lang; |
48 | | using namespace css::container; |
49 | | using namespace css::beans; |
50 | | using namespace css::document; |
51 | | using namespace css::drawing; |
52 | | |
53 | | const sal_Int32 HANDLE_URL = 1; |
54 | | const sal_Int32 HANDLE_DESCRIPTION = 2; |
55 | | const sal_Int32 HANDLE_TARGET = 3; |
56 | | const sal_Int32 HANDLE_NAME = 4; |
57 | | const sal_Int32 HANDLE_ISACTIVE = 5; |
58 | | const sal_Int32 HANDLE_POLYGON = 6; |
59 | | const sal_Int32 HANDLE_CENTER = 7; |
60 | | const sal_Int32 HANDLE_RADIUS = 8; |
61 | | const sal_Int32 HANDLE_BOUNDARY = 9; |
62 | | const sal_Int32 HANDLE_TITLE = 10; |
63 | | |
64 | | namespace { |
65 | | |
66 | | class SvUnoImageMapObject : public OWeakObject, |
67 | | public XEventsSupplier, |
68 | | public XServiceInfo, |
69 | | public PropertySetHelper, |
70 | | public XTypeProvider |
71 | | { |
72 | | public: |
73 | | SvUnoImageMapObject( IMapObjectType nType, const SvEventDescription* pSupportedMacroItems ); |
74 | | SvUnoImageMapObject( const IMapObject& rMapObject, const SvEventDescription* pSupportedMacroItems ); |
75 | | |
76 | | std::unique_ptr<IMapObject> createIMapObject() const; |
77 | | |
78 | | rtl::Reference<SvMacroTableEventDescriptor> mxEvents; |
79 | | |
80 | | // overridden helpers from PropertySetHelper |
81 | | virtual void _setPropertyValues( const PropertyMapEntry** ppEntries, const Any* pValues ) override; |
82 | | virtual void _getPropertyValues( const PropertyMapEntry** ppEntries, Any* pValue ) override; |
83 | | |
84 | | // XInterface |
85 | | virtual Any SAL_CALL queryInterface( const Type & rType ) override; |
86 | | virtual void SAL_CALL acquire() noexcept override; |
87 | | virtual void SAL_CALL release() noexcept override; |
88 | | |
89 | | // XTypeProvider |
90 | | virtual Sequence< Type > SAL_CALL getTypes( ) override; |
91 | | virtual Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override; |
92 | | |
93 | | // XEventsSupplier |
94 | | virtual Reference< css::container::XNameReplace > SAL_CALL getEvents( ) override; |
95 | | |
96 | | // XServiceInfo |
97 | | virtual OUString SAL_CALL getImplementationName( ) override; |
98 | | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; |
99 | | virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; |
100 | | |
101 | | private: |
102 | | static rtl::Reference<PropertySetInfo> createPropertySetInfo( IMapObjectType nType ); |
103 | | |
104 | | |
105 | | IMapObjectType mnType; |
106 | | |
107 | | OUString maURL; |
108 | | OUString maAltText; |
109 | | OUString maDesc; |
110 | | OUString maTarget; |
111 | | OUString maName; |
112 | | bool mbIsActive; |
113 | | awt::Rectangle maBoundary; |
114 | | awt::Point maCenter; |
115 | | sal_Int32 mnRadius; |
116 | | PointSequence maPolygon; |
117 | | }; |
118 | | |
119 | | } |
120 | | |
121 | | rtl::Reference<PropertySetInfo> SvUnoImageMapObject::createPropertySetInfo( IMapObjectType nType ) |
122 | 0 | { |
123 | 0 | switch( nType ) |
124 | 0 | { |
125 | 0 | case IMapObjectType::Polygon: |
126 | 0 | { |
127 | 0 | static PropertyMapEntry const aPolygonObj_Impl[] = |
128 | 0 | { |
129 | 0 | { u"URL"_ustr, HANDLE_URL, cppu::UnoType<OUString>::get(), 0, 0 }, |
130 | 0 | { u"Title"_ustr, HANDLE_TITLE, cppu::UnoType<OUString>::get(), 0, 0 }, |
131 | 0 | { u"Description"_ustr, HANDLE_DESCRIPTION, cppu::UnoType<OUString>::get(), 0, 0 }, |
132 | 0 | { u"Target"_ustr, HANDLE_TARGET, cppu::UnoType<OUString>::get(), 0, 0 }, |
133 | 0 | { u"Name"_ustr, HANDLE_NAME, cppu::UnoType<OUString>::get(), 0, 0 }, |
134 | 0 | { u"IsActive"_ustr, HANDLE_ISACTIVE, cppu::UnoType<bool>::get(), 0, 0 }, |
135 | 0 | { u"Polygon"_ustr, HANDLE_POLYGON, cppu::UnoType<PointSequence>::get(), 0, 0 }, |
136 | 0 | }; |
137 | |
|
138 | 0 | return rtl::Reference<PropertySetInfo>(new PropertySetInfo( aPolygonObj_Impl )); |
139 | 0 | } |
140 | 0 | case IMapObjectType::Circle: |
141 | 0 | { |
142 | 0 | static PropertyMapEntry const aCircleObj_Impl[] = |
143 | 0 | { |
144 | 0 | { u"URL"_ustr, HANDLE_URL, cppu::UnoType<OUString>::get(), 0, 0 }, |
145 | 0 | { u"Title"_ustr, HANDLE_TITLE, cppu::UnoType<OUString>::get(), 0, 0 }, |
146 | 0 | { u"Description"_ustr, HANDLE_DESCRIPTION, cppu::UnoType<OUString>::get(), 0, 0 }, |
147 | 0 | { u"Target"_ustr, HANDLE_TARGET, cppu::UnoType<OUString>::get(), 0, 0 }, |
148 | 0 | { u"Name"_ustr, HANDLE_NAME, cppu::UnoType<OUString>::get(), 0, 0 }, |
149 | 0 | { u"IsActive"_ustr, HANDLE_ISACTIVE, cppu::UnoType<bool>::get(), 0, 0 }, |
150 | 0 | { u"Center"_ustr, HANDLE_CENTER, cppu::UnoType<awt::Point>::get(), 0, 0 }, |
151 | 0 | { u"Radius"_ustr, HANDLE_RADIUS, cppu::UnoType<sal_Int32>::get(), 0, 0 }, |
152 | 0 | }; |
153 | |
|
154 | 0 | return rtl::Reference<PropertySetInfo>(new PropertySetInfo( aCircleObj_Impl )); |
155 | 0 | } |
156 | 0 | case IMapObjectType::Rectangle: |
157 | 0 | default: |
158 | 0 | { |
159 | 0 | static PropertyMapEntry const aRectangleObj_Impl[] = |
160 | 0 | { |
161 | 0 | { u"URL"_ustr, HANDLE_URL, cppu::UnoType<OUString>::get(), 0, 0 }, |
162 | 0 | { u"Title"_ustr, HANDLE_TITLE, cppu::UnoType<OUString>::get(), 0, 0 }, |
163 | 0 | { u"Description"_ustr, HANDLE_DESCRIPTION, cppu::UnoType<OUString>::get(), 0, 0 }, |
164 | 0 | { u"Target"_ustr, HANDLE_TARGET, cppu::UnoType<OUString>::get(), 0, 0 }, |
165 | 0 | { u"Name"_ustr, HANDLE_NAME, cppu::UnoType<OUString>::get(), 0, 0 }, |
166 | 0 | { u"IsActive"_ustr, HANDLE_ISACTIVE, cppu::UnoType<bool>::get(), 0, 0 }, |
167 | 0 | { u"Boundary"_ustr, HANDLE_BOUNDARY, cppu::UnoType<awt::Rectangle>::get(), 0, 0 }, |
168 | 0 | }; |
169 | |
|
170 | 0 | return rtl::Reference<PropertySetInfo>(new PropertySetInfo( aRectangleObj_Impl )); |
171 | 0 | } |
172 | 0 | } |
173 | 0 | } |
174 | | |
175 | | SvUnoImageMapObject::SvUnoImageMapObject( IMapObjectType nType, const SvEventDescription* pSupportedMacroItems ) |
176 | 0 | : PropertySetHelper( createPropertySetInfo( nType ) ), |
177 | 0 | mnType( nType ) |
178 | 0 | , mbIsActive( true ) |
179 | 0 | , mnRadius( 0 ) |
180 | 0 | { |
181 | 0 | mxEvents = new SvMacroTableEventDescriptor( pSupportedMacroItems ); |
182 | 0 | } |
183 | | |
184 | | SvUnoImageMapObject::SvUnoImageMapObject( const IMapObject& rMapObject, const SvEventDescription* pSupportedMacroItems ) |
185 | 0 | : PropertySetHelper( createPropertySetInfo( rMapObject.GetType() ) ), |
186 | 0 | mnType( rMapObject.GetType() ) |
187 | 0 | , mbIsActive( true ) |
188 | 0 | , mnRadius( 0 ) |
189 | 0 | { |
190 | 0 | maURL = rMapObject.GetURL(); |
191 | 0 | maAltText = rMapObject.GetAltText(); |
192 | 0 | maDesc = rMapObject.GetDesc(); |
193 | 0 | maTarget = rMapObject.GetTarget(); |
194 | 0 | maName = rMapObject.GetName(); |
195 | 0 | mbIsActive = rMapObject.IsActive(); |
196 | |
|
197 | 0 | switch( mnType ) |
198 | 0 | { |
199 | 0 | case IMapObjectType::Rectangle: |
200 | 0 | { |
201 | 0 | const tools::Rectangle aRect( static_cast<const IMapRectangleObject*>(&rMapObject)->GetRectangle(false) ); |
202 | 0 | maBoundary.X = aRect.Left(); |
203 | 0 | maBoundary.Y = aRect.Top(); |
204 | 0 | maBoundary.Width = aRect.GetWidth(); |
205 | 0 | maBoundary.Height = aRect.GetHeight(); |
206 | 0 | } |
207 | 0 | break; |
208 | 0 | case IMapObjectType::Circle: |
209 | 0 | { |
210 | 0 | mnRadius = static_cast<const IMapCircleObject*>(&rMapObject)->GetRadius(false); |
211 | 0 | const Point aPoint( static_cast<const IMapCircleObject*>(&rMapObject)->GetCenter(false) ); |
212 | |
|
213 | 0 | maCenter.X = aPoint.X(); |
214 | 0 | maCenter.Y = aPoint.Y(); |
215 | 0 | } |
216 | 0 | break; |
217 | 0 | case IMapObjectType::Polygon: |
218 | 0 | default: |
219 | 0 | { |
220 | 0 | const tools::Polygon aPoly( static_cast<const IMapPolygonObject*>(&rMapObject)->GetPolygon(false) ); |
221 | |
|
222 | 0 | const sal_uInt16 nCount = aPoly.GetSize(); |
223 | 0 | maPolygon.realloc( nCount ); |
224 | 0 | awt::Point* pPoints = maPolygon.getArray(); |
225 | |
|
226 | 0 | for( sal_uInt16 nPoint = 0; nPoint < nCount; nPoint++ ) |
227 | 0 | { |
228 | 0 | const Point& rPoint = aPoly.GetPoint( nPoint ); |
229 | 0 | pPoints->X = rPoint.X(); |
230 | 0 | pPoints->Y = rPoint.Y(); |
231 | |
|
232 | 0 | pPoints++; |
233 | 0 | } |
234 | 0 | } |
235 | 0 | } |
236 | | |
237 | 0 | mxEvents = new SvMacroTableEventDescriptor( rMapObject.GetMacroTable(), pSupportedMacroItems ); |
238 | 0 | } |
239 | | |
240 | | std::unique_ptr<IMapObject> SvUnoImageMapObject::createIMapObject() const |
241 | 0 | { |
242 | 0 | const OUString aURL( maURL ); |
243 | 0 | const OUString aAltText( maAltText ); |
244 | 0 | const OUString aDesc( maDesc ); |
245 | 0 | const OUString aTarget( maTarget ); |
246 | 0 | const OUString aName( maName ); |
247 | |
|
248 | 0 | std::unique_ptr<IMapObject> pNewIMapObject; |
249 | |
|
250 | 0 | switch( mnType ) |
251 | 0 | { |
252 | 0 | case IMapObjectType::Rectangle: |
253 | 0 | { |
254 | 0 | const tools::Rectangle aRect( maBoundary.X, maBoundary.Y, maBoundary.X + maBoundary.Width - 1, maBoundary.Y + maBoundary.Height - 1 ); |
255 | 0 | pNewIMapObject.reset(new IMapRectangleObject( aRect, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false )); |
256 | 0 | } |
257 | 0 | break; |
258 | | |
259 | 0 | case IMapObjectType::Circle: |
260 | 0 | { |
261 | 0 | const Point aCenter( maCenter.X, maCenter.Y ); |
262 | 0 | pNewIMapObject.reset(new IMapCircleObject( aCenter, mnRadius, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false )); |
263 | 0 | } |
264 | 0 | break; |
265 | | |
266 | 0 | case IMapObjectType::Polygon: |
267 | 0 | default: |
268 | 0 | { |
269 | 0 | const sal_uInt16 nCount = static_cast<sal_uInt16>(maPolygon.getLength()); |
270 | |
|
271 | 0 | tools::Polygon aPoly( nCount ); |
272 | 0 | for( sal_uInt16 nPoint = 0; nPoint < nCount; nPoint++ ) |
273 | 0 | { |
274 | 0 | Point aPoint( maPolygon[nPoint].X, maPolygon[nPoint].Y ); |
275 | 0 | aPoly.SetPoint( aPoint, nPoint ); |
276 | 0 | } |
277 | |
|
278 | 0 | aPoly.Optimize( PolyOptimizeFlags::CLOSE ); |
279 | 0 | pNewIMapObject.reset(new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false )); |
280 | 0 | } |
281 | 0 | break; |
282 | 0 | } |
283 | | |
284 | 0 | SvxMacroTableDtor aMacroTable; |
285 | 0 | mxEvents->copyMacrosIntoTable(aMacroTable); |
286 | 0 | pNewIMapObject->SetMacroTable( aMacroTable ); |
287 | |
|
288 | 0 | return pNewIMapObject; |
289 | 0 | } |
290 | | |
291 | | // XInterface |
292 | | |
293 | | Any SAL_CALL SvUnoImageMapObject::queryInterface( const Type & rType ) |
294 | 0 | { |
295 | 0 | Any aAny; |
296 | |
|
297 | 0 | if( rType == cppu::UnoType<XServiceInfo>::get()) |
298 | 0 | aAny <<= Reference< XServiceInfo >(this); |
299 | 0 | else if( rType == cppu::UnoType<XTypeProvider>::get()) |
300 | 0 | aAny <<= Reference< XTypeProvider >(this); |
301 | 0 | else if( rType == cppu::UnoType<XPropertySet>::get()) |
302 | 0 | aAny <<= Reference< XPropertySet >(this); |
303 | 0 | else if( rType == cppu::UnoType<XEventsSupplier>::get()) |
304 | 0 | aAny <<= Reference< XEventsSupplier >(this); |
305 | 0 | else if( rType == cppu::UnoType<XMultiPropertySet>::get()) |
306 | 0 | aAny <<= Reference< XMultiPropertySet >(this); |
307 | 0 | else |
308 | 0 | aAny = OWeakObject::queryInterface( rType ); |
309 | |
|
310 | 0 | return aAny; |
311 | 0 | } |
312 | | |
313 | | void SAL_CALL SvUnoImageMapObject::acquire() noexcept |
314 | 0 | { |
315 | 0 | OWeakObject::acquire(); |
316 | 0 | } |
317 | | |
318 | | void SAL_CALL SvUnoImageMapObject::release() noexcept |
319 | 0 | { |
320 | 0 | OWeakObject::release(); |
321 | 0 | } |
322 | | |
323 | | uno::Sequence< uno::Type > SAL_CALL SvUnoImageMapObject::getTypes() |
324 | 0 | { |
325 | 0 | static const uno::Sequence< uno::Type > aTypes { |
326 | 0 | cppu::UnoType<XEventsSupplier>::get(), |
327 | 0 | cppu::UnoType<XServiceInfo>::get(), |
328 | 0 | cppu::UnoType<XPropertySet>::get(), |
329 | 0 | cppu::UnoType<XMultiPropertySet>::get(), |
330 | 0 | cppu::UnoType<XTypeProvider>::get() }; |
331 | 0 | return aTypes; |
332 | 0 | } |
333 | | |
334 | | uno::Sequence< sal_Int8 > SAL_CALL SvUnoImageMapObject::getImplementationId() |
335 | 0 | { |
336 | 0 | return css::uno::Sequence<sal_Int8>(); |
337 | 0 | } |
338 | | |
339 | | // XServiceInfo |
340 | | sal_Bool SAL_CALL SvUnoImageMapObject::supportsService( const OUString& ServiceName ) |
341 | 0 | { |
342 | 0 | return cppu::supportsService(this, ServiceName); |
343 | 0 | } |
344 | | |
345 | | Sequence< OUString > SAL_CALL SvUnoImageMapObject::getSupportedServiceNames() |
346 | 0 | { |
347 | 0 | Sequence< OUString > aSNS( 2 ); |
348 | 0 | aSNS.getArray()[0] = "com.sun.star.image.ImageMapObject"; |
349 | 0 | switch( mnType ) |
350 | 0 | { |
351 | 0 | case IMapObjectType::Polygon: |
352 | 0 | default: |
353 | 0 | aSNS.getArray()[1] = "com.sun.star.image.ImageMapPolygonObject"; |
354 | 0 | break; |
355 | 0 | case IMapObjectType::Rectangle: |
356 | 0 | aSNS.getArray()[1] = "com.sun.star.image.ImageMapRectangleObject"; |
357 | 0 | break; |
358 | 0 | case IMapObjectType::Circle: |
359 | 0 | aSNS.getArray()[1] = "com.sun.star.image.ImageMapCircleObject"; |
360 | 0 | break; |
361 | 0 | } |
362 | 0 | return aSNS; |
363 | 0 | } |
364 | | |
365 | | OUString SAL_CALL SvUnoImageMapObject::getImplementationName() |
366 | 0 | { |
367 | 0 | switch( mnType ) |
368 | 0 | { |
369 | 0 | case IMapObjectType::Polygon: |
370 | 0 | default: |
371 | 0 | return u"org.openoffice.comp.svt.ImageMapPolygonObject"_ustr; |
372 | 0 | case IMapObjectType::Circle: |
373 | 0 | return u"org.openoffice.comp.svt.ImageMapCircleObject"_ustr; |
374 | 0 | case IMapObjectType::Rectangle: |
375 | 0 | return u"org.openoffice.comp.svt.ImageMapRectangleObject"_ustr; |
376 | 0 | } |
377 | 0 | } |
378 | | |
379 | | // overridden helpers from PropertySetHelper |
380 | | void SvUnoImageMapObject::_setPropertyValues( const PropertyMapEntry** ppEntries, const Any* pValues ) |
381 | 0 | { |
382 | 0 | bool bOk = false; |
383 | |
|
384 | 0 | while( *ppEntries ) |
385 | 0 | { |
386 | 0 | switch( (*ppEntries)->mnHandle ) |
387 | 0 | { |
388 | 0 | case HANDLE_URL: |
389 | 0 | bOk = *pValues >>= maURL; |
390 | 0 | break; |
391 | 0 | case HANDLE_TITLE: |
392 | 0 | bOk = *pValues >>= maAltText; |
393 | 0 | break; |
394 | 0 | case HANDLE_DESCRIPTION: |
395 | 0 | bOk = *pValues >>= maDesc; |
396 | 0 | break; |
397 | 0 | case HANDLE_TARGET: |
398 | 0 | bOk = *pValues >>= maTarget; |
399 | 0 | break; |
400 | 0 | case HANDLE_NAME: |
401 | 0 | bOk = *pValues >>= maName; |
402 | 0 | break; |
403 | 0 | case HANDLE_ISACTIVE: |
404 | 0 | bOk = *pValues >>= mbIsActive; |
405 | 0 | break; |
406 | 0 | case HANDLE_BOUNDARY: |
407 | 0 | bOk = *pValues >>= maBoundary; |
408 | 0 | break; |
409 | 0 | case HANDLE_CENTER: |
410 | 0 | bOk = *pValues >>= maCenter; |
411 | 0 | break; |
412 | 0 | case HANDLE_RADIUS: |
413 | 0 | bOk = *pValues >>= mnRadius; |
414 | 0 | break; |
415 | 0 | case HANDLE_POLYGON: |
416 | 0 | bOk = *pValues >>= maPolygon; |
417 | 0 | break; |
418 | 0 | default: |
419 | 0 | OSL_FAIL( "SvUnoImageMapObject::_setPropertyValues: unexpected property handle" ); |
420 | 0 | break; |
421 | 0 | } |
422 | | |
423 | 0 | if( !bOk ) |
424 | 0 | throw IllegalArgumentException(); |
425 | | |
426 | 0 | ppEntries++; |
427 | 0 | pValues++; |
428 | 0 | } |
429 | 0 | } |
430 | | |
431 | | void SvUnoImageMapObject::_getPropertyValues( const PropertyMapEntry** ppEntries, Any* pValues ) |
432 | 0 | { |
433 | 0 | while( *ppEntries ) |
434 | 0 | { |
435 | 0 | switch( (*ppEntries)->mnHandle ) |
436 | 0 | { |
437 | 0 | case HANDLE_URL: |
438 | 0 | *pValues <<= maURL; |
439 | 0 | break; |
440 | 0 | case HANDLE_TITLE: |
441 | 0 | *pValues <<= maAltText; |
442 | 0 | break; |
443 | 0 | case HANDLE_DESCRIPTION: |
444 | 0 | *pValues <<= maDesc; |
445 | 0 | break; |
446 | 0 | case HANDLE_TARGET: |
447 | 0 | *pValues <<= maTarget; |
448 | 0 | break; |
449 | 0 | case HANDLE_NAME: |
450 | 0 | *pValues <<= maName; |
451 | 0 | break; |
452 | 0 | case HANDLE_ISACTIVE: |
453 | 0 | *pValues <<= mbIsActive; |
454 | 0 | break; |
455 | 0 | case HANDLE_BOUNDARY: |
456 | 0 | *pValues <<= maBoundary; |
457 | 0 | break; |
458 | 0 | case HANDLE_CENTER: |
459 | 0 | *pValues <<= maCenter; |
460 | 0 | break; |
461 | 0 | case HANDLE_RADIUS: |
462 | 0 | *pValues <<= mnRadius; |
463 | 0 | break; |
464 | 0 | case HANDLE_POLYGON: |
465 | 0 | *pValues <<= maPolygon; |
466 | 0 | break; |
467 | 0 | default: |
468 | 0 | OSL_FAIL( "SvUnoImageMapObject::_getPropertyValues: unexpected property handle" ); |
469 | 0 | break; |
470 | 0 | } |
471 | | |
472 | 0 | ppEntries++; |
473 | 0 | pValues++; |
474 | 0 | } |
475 | 0 | } |
476 | | |
477 | | |
478 | | Reference< XNameReplace > SAL_CALL SvUnoImageMapObject::getEvents() |
479 | 0 | { |
480 | 0 | return mxEvents; |
481 | 0 | } |
482 | | |
483 | | namespace { |
484 | | |
485 | | class SvUnoImageMap : public WeakImplHelper< XIndexContainer, XServiceInfo > |
486 | | { |
487 | | public: |
488 | | explicit SvUnoImageMap(); |
489 | | SvUnoImageMap( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems ); |
490 | | |
491 | | void fillImageMap( ImageMap& rMap ) const; |
492 | | /// @throws IllegalArgumentException |
493 | | static SvUnoImageMapObject* getObject( const Any& aElement ); |
494 | | |
495 | | // XIndexContainer |
496 | | virtual void SAL_CALL insertByIndex( sal_Int32 Index, const Any& Element ) override; |
497 | | virtual void SAL_CALL removeByIndex( sal_Int32 Index ) override; |
498 | | |
499 | | // XIndexReplace |
500 | | virtual void SAL_CALL replaceByIndex( sal_Int32 Index, const Any& Element ) override; |
501 | | |
502 | | // XIndexAccess |
503 | | virtual sal_Int32 SAL_CALL getCount( ) override; |
504 | | virtual Any SAL_CALL getByIndex( sal_Int32 Index ) override; |
505 | | |
506 | | // XElementAccess |
507 | | virtual Type SAL_CALL getElementType( ) override; |
508 | | virtual sal_Bool SAL_CALL hasElements( ) override; |
509 | | |
510 | | // XServiceInfo |
511 | | virtual OUString SAL_CALL getImplementationName( ) override; |
512 | | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; |
513 | | virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; |
514 | | |
515 | | private: |
516 | | OUString maName; |
517 | | |
518 | | std::vector< rtl::Reference<SvUnoImageMapObject> > maObjectList; |
519 | | }; |
520 | | |
521 | | } |
522 | | |
523 | | SvUnoImageMap::SvUnoImageMap() |
524 | 174 | { |
525 | 174 | } |
526 | | |
527 | | SvUnoImageMap::SvUnoImageMap( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems ) |
528 | 0 | { |
529 | 0 | maName = rMap.GetName(); |
530 | |
|
531 | 0 | const std::size_t nCount = rMap.GetIMapObjectCount(); |
532 | 0 | for( std::size_t nPos = 0; nPos < nCount; nPos++ ) |
533 | 0 | { |
534 | 0 | IMapObject* pMapObject = rMap.GetIMapObject( nPos ); |
535 | 0 | rtl::Reference<SvUnoImageMapObject> xUnoObj = new SvUnoImageMapObject( *pMapObject, pSupportedMacroItems ); |
536 | 0 | maObjectList.push_back( xUnoObj ); |
537 | 0 | } |
538 | 0 | } |
539 | | |
540 | | SvUnoImageMapObject* SvUnoImageMap::getObject( const Any& aElement ) |
541 | 0 | { |
542 | 0 | Reference< XInterface > xObject; |
543 | 0 | aElement >>= xObject; |
544 | |
|
545 | 0 | SvUnoImageMapObject* pObject = dynamic_cast<SvUnoImageMapObject*>( xObject.get() ); |
546 | 0 | if( nullptr == pObject ) |
547 | 0 | throw IllegalArgumentException(); |
548 | | |
549 | 0 | return pObject; |
550 | 0 | } |
551 | | |
552 | | // XIndexContainer |
553 | | void SAL_CALL SvUnoImageMap::insertByIndex( sal_Int32 nIndex, const Any& Element ) |
554 | 0 | { |
555 | 0 | SvUnoImageMapObject* pObject = getObject( Element ); |
556 | 0 | const sal_Int32 nCount = maObjectList.size(); |
557 | 0 | if( nullptr == pObject || nIndex > nCount ) |
558 | 0 | throw IndexOutOfBoundsException(); |
559 | | |
560 | 0 | if( nIndex == nCount ) |
561 | 0 | maObjectList.emplace_back(pObject ); |
562 | 0 | else |
563 | 0 | { |
564 | 0 | auto aIter = maObjectList.begin(); |
565 | 0 | std::advance(aIter, nIndex); |
566 | 0 | maObjectList.insert( aIter, pObject ); |
567 | 0 | } |
568 | 0 | } |
569 | | |
570 | | void SAL_CALL SvUnoImageMap::removeByIndex( sal_Int32 nIndex ) |
571 | 0 | { |
572 | 0 | const sal_Int32 nCount = maObjectList.size(); |
573 | 0 | if( nIndex >= nCount ) |
574 | 0 | throw IndexOutOfBoundsException(); |
575 | | |
576 | 0 | if( nCount - 1 == nIndex ) |
577 | 0 | { |
578 | 0 | maObjectList.pop_back(); |
579 | 0 | } |
580 | 0 | else |
581 | 0 | { |
582 | 0 | auto aIter = maObjectList.begin(); |
583 | 0 | std::advance(aIter, nIndex); |
584 | 0 | maObjectList.erase( aIter ); |
585 | 0 | } |
586 | 0 | } |
587 | | |
588 | | // XIndexReplace |
589 | | void SAL_CALL SvUnoImageMap::replaceByIndex( sal_Int32 nIndex, const Any& Element ) |
590 | 0 | { |
591 | 0 | SvUnoImageMapObject* pObject = getObject( Element ); |
592 | 0 | const sal_Int32 nCount = maObjectList.size(); |
593 | 0 | if( nullptr == pObject || nIndex >= nCount ) |
594 | 0 | throw IndexOutOfBoundsException(); |
595 | | |
596 | 0 | auto aIter = maObjectList.begin(); |
597 | 0 | std::advance(aIter, nIndex); |
598 | 0 | *aIter = pObject; |
599 | 0 | } |
600 | | |
601 | | // XIndexAccess |
602 | | sal_Int32 SAL_CALL SvUnoImageMap::getCount( ) |
603 | 0 | { |
604 | 0 | return maObjectList.size(); |
605 | 0 | } |
606 | | |
607 | | Any SAL_CALL SvUnoImageMap::getByIndex( sal_Int32 nIndex ) |
608 | 0 | { |
609 | 0 | const sal_Int32 nCount = maObjectList.size(); |
610 | 0 | if( nIndex >= nCount ) |
611 | 0 | throw IndexOutOfBoundsException(); |
612 | | |
613 | 0 | auto aIter = maObjectList.begin(); |
614 | 0 | std::advance(aIter, nIndex); |
615 | |
|
616 | 0 | return Any( Reference< XPropertySet >( *aIter ) ); |
617 | 0 | } |
618 | | |
619 | | // XElementAccess |
620 | | Type SAL_CALL SvUnoImageMap::getElementType( ) |
621 | 0 | { |
622 | 0 | return cppu::UnoType<XPropertySet>::get(); |
623 | 0 | } |
624 | | |
625 | | sal_Bool SAL_CALL SvUnoImageMap::hasElements( ) |
626 | 174 | { |
627 | 174 | return (!maObjectList.empty()); |
628 | 174 | } |
629 | | |
630 | | // XServiceInfo |
631 | | OUString SAL_CALL SvUnoImageMap::getImplementationName( ) |
632 | 0 | { |
633 | 0 | return u"org.openoffice.comp.svt.SvUnoImageMap"_ustr; |
634 | 0 | } |
635 | | |
636 | | sal_Bool SAL_CALL SvUnoImageMap::supportsService( const OUString& ServiceName ) |
637 | 0 | { |
638 | 0 | return cppu::supportsService(this, ServiceName); |
639 | 0 | } |
640 | | |
641 | | Sequence< OUString > SAL_CALL SvUnoImageMap::getSupportedServiceNames( ) |
642 | 0 | { |
643 | 0 | return { u"com.sun.star.image.ImageMap"_ustr }; |
644 | 0 | } |
645 | | |
646 | | void SvUnoImageMap::fillImageMap( ImageMap& rMap ) const |
647 | 0 | { |
648 | 0 | rMap.ClearImageMap(); |
649 | |
|
650 | 0 | rMap.SetName( maName ); |
651 | |
|
652 | 0 | for (auto const& elem : maObjectList) |
653 | 0 | { |
654 | 0 | std::unique_ptr<IMapObject> pNewMapObject = elem->createIMapObject(); |
655 | 0 | rMap.InsertIMapObject( std::move(pNewMapObject) ); |
656 | 0 | } |
657 | 0 | } |
658 | | |
659 | | |
660 | | // factory helper methods |
661 | | |
662 | | |
663 | | Reference< XInterface > SvUnoImageMapRectangleObject_createInstance( const SvEventDescription* pSupportedMacroItems ) |
664 | 0 | { |
665 | 0 | return getXWeak(new SvUnoImageMapObject( IMapObjectType::Rectangle, pSupportedMacroItems )); |
666 | 0 | } |
667 | | |
668 | | Reference< XInterface > SvUnoImageMapCircleObject_createInstance( const SvEventDescription* pSupportedMacroItems ) |
669 | 0 | { |
670 | 0 | return getXWeak(new SvUnoImageMapObject( IMapObjectType::Circle, pSupportedMacroItems )); |
671 | 0 | } |
672 | | |
673 | | Reference< XInterface > SvUnoImageMapPolygonObject_createInstance( const SvEventDescription* pSupportedMacroItems ) |
674 | 0 | { |
675 | 0 | return getXWeak(new SvUnoImageMapObject( IMapObjectType::Polygon, pSupportedMacroItems )); |
676 | 0 | } |
677 | | |
678 | | Reference< XInterface > SvUnoImageMap_createInstance() |
679 | 174 | { |
680 | 174 | return getXWeak(new SvUnoImageMap); |
681 | 174 | } |
682 | | |
683 | | Reference< XInterface > SvUnoImageMap_createInstance( const ImageMap& rMap, const SvEventDescription* pSupportedMacroItems ) |
684 | 0 | { |
685 | 0 | return getXWeak(new SvUnoImageMap( rMap, pSupportedMacroItems )); |
686 | 0 | } |
687 | | |
688 | | bool SvUnoImageMap_fillImageMap( const Reference< XInterface >& xImageMap, ImageMap& rMap ) |
689 | 0 | { |
690 | 0 | SvUnoImageMap* pUnoImageMap = dynamic_cast<SvUnoImageMap*>( xImageMap.get() ); |
691 | 0 | if( nullptr == pUnoImageMap ) |
692 | 0 | return false; |
693 | | |
694 | 0 | pUnoImageMap->fillImageMap( rMap ); |
695 | 0 | return true; |
696 | 0 | } |
697 | | |
698 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |