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 :
21 : #include "svx/XPropertyTable.hxx"
22 : #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
23 : #include <com/sun/star/drawing/LineDash.hpp>
24 : #include <com/sun/star/awt/Gradient.hpp>
25 : #include <com/sun/star/drawing/Hatch.hpp>
26 : #include <com/sun/star/lang/XServiceInfo.hpp>
27 : #include <com/sun/star/container/XNameContainer.hpp>
28 : #include <osl/mutex.hxx>
29 : #include <vcl/svapp.hxx>
30 :
31 : #include <cppuhelper/implbase2.hxx>
32 : #include <cppuhelper/supportsservice.hxx>
33 : #include <svx/xdef.hxx>
34 :
35 : #include "svx/unoapi.hxx"
36 : #include <editeng/unoprnms.hxx>
37 : #include <basegfx/polygon/b2dpolygon.hxx>
38 : #include <basegfx/tools/unotools.hxx>
39 :
40 : using namespace com::sun::star;
41 : using namespace ::cppu;
42 :
43 : class SvxUnoXPropertyTable : public WeakImplHelper2< container::XNameContainer, lang::XServiceInfo >
44 : {
45 : private:
46 : XPropertyList* mpList;
47 : sal_Int16 mnWhich;
48 :
49 109 : long getCount() const { return mpList ? mpList->Count() : 0; }
50 : XPropertyEntry* get( long index ) const;
51 : public:
52 : SvxUnoXPropertyTable( sal_Int16 nWhich, XPropertyList* pList ) throw();
53 :
54 : virtual ~SvxUnoXPropertyTable() throw();
55 :
56 : virtual uno::Any getAny( const XPropertyEntry* pEntry ) const throw(uno::RuntimeException) = 0;
57 : virtual XPropertyEntry* getEntry( const OUString& rName, const uno::Any& rAny ) const throw(uno::RuntimeException, lang::IllegalArgumentException) = 0;
58 :
59 : // XServiceInfo
60 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( uno::RuntimeException, std::exception) SAL_OVERRIDE;
61 :
62 : // XNameContainer
63 : virtual void SAL_CALL insertByName( const OUString& aName, const uno::Any& aElement ) throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
64 : virtual void SAL_CALL removeByName( const OUString& Name ) throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
65 :
66 : // XNameReplace
67 : virtual void SAL_CALL replaceByName( const OUString& aName, const uno::Any& aElement ) throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
68 :
69 : // XNameAccess
70 : virtual uno::Any SAL_CALL getByName( const OUString& aName ) throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
71 : virtual uno::Sequence< OUString > SAL_CALL getElementNames( ) throw( uno::RuntimeException, std::exception) SAL_OVERRIDE;
72 : virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw( uno::RuntimeException, std::exception) SAL_OVERRIDE;
73 :
74 : // XElementAccess
75 : virtual sal_Bool SAL_CALL hasElements( ) throw( uno::RuntimeException, std::exception) SAL_OVERRIDE;
76 : };
77 :
78 580 : SvxUnoXPropertyTable::SvxUnoXPropertyTable( sal_Int16 nWhich, XPropertyList* pList ) throw()
79 580 : : mpList( pList ), mnWhich( nWhich )
80 : {
81 580 : }
82 :
83 580 : SvxUnoXPropertyTable::~SvxUnoXPropertyTable() throw()
84 : {
85 580 : }
86 :
87 1706368 : XPropertyEntry* SvxUnoXPropertyTable::get( long index ) const
88 : {
89 1706368 : if( mpList )
90 1706368 : return mpList->Get(index);
91 : else
92 0 : return NULL;
93 : }
94 :
95 : // XServiceInfo
96 0 : sal_Bool SAL_CALL SvxUnoXPropertyTable::supportsService( const OUString& ServiceName )
97 : throw( uno::RuntimeException, std::exception)
98 : {
99 0 : return cppu::supportsService(this, ServiceName);
100 : }
101 :
102 : // XNameContainer
103 11561 : void SAL_CALL SvxUnoXPropertyTable::insertByName( const OUString& aName, const uno::Any& aElement )
104 : throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
105 : {
106 11561 : SolarMutexGuard aGuard;
107 :
108 11561 : if( NULL == mpList )
109 0 : throw lang::IllegalArgumentException();
110 :
111 11561 : if( hasByName( aName ) )
112 0 : throw container::ElementExistException();
113 :
114 23122 : OUString aInternalName = SvxUnogetInternalNameForItem(mnWhich, aName);
115 :
116 11561 : XPropertyEntry* pNewEntry = getEntry( aInternalName, aElement );
117 11561 : if( NULL == pNewEntry )
118 0 : throw lang::IllegalArgumentException();
119 :
120 11561 : if( mpList )
121 23122 : mpList->Insert( pNewEntry );
122 11561 : }
123 :
124 0 : void SAL_CALL SvxUnoXPropertyTable::removeByName( const OUString& Name )
125 : throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
126 : {
127 0 : SolarMutexGuard aGuard;
128 :
129 0 : OUString aInternalName = SvxUnogetInternalNameForItem(mnWhich, Name);
130 :
131 0 : const long nCount = getCount();
132 : long i;
133 : XPropertyEntry* pEntry;
134 0 : for( i = 0; i < nCount; i++ )
135 : {
136 0 : pEntry = get( i );
137 0 : if (pEntry && aInternalName.equals(pEntry->GetName()))
138 : {
139 0 : if( mpList )
140 0 : delete mpList->Remove( i );
141 0 : return;
142 : }
143 : }
144 :
145 0 : throw container::NoSuchElementException();
146 : }
147 :
148 : // XNameReplace
149 109 : void SAL_CALL SvxUnoXPropertyTable::replaceByName( const OUString& aName, const uno::Any& aElement )
150 : throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
151 : {
152 109 : SolarMutexGuard aGuard;
153 :
154 218 : OUString aInternalName = SvxUnogetInternalNameForItem(mnWhich, aName);
155 :
156 109 : const long nCount = getCount();
157 : long i;
158 : XPropertyEntry* pEntry;
159 218 : for( i = 0; i < nCount; i++ )
160 : {
161 218 : pEntry = get( i );
162 218 : if (pEntry && aInternalName.equals(pEntry->GetName()))
163 : {
164 109 : XPropertyEntry* pNewEntry = getEntry( aInternalName, aElement );
165 109 : if( NULL == pNewEntry )
166 0 : throw lang::IllegalArgumentException();
167 :
168 109 : if( mpList )
169 109 : delete mpList->Replace( pNewEntry, i );
170 218 : return;
171 : }
172 : }
173 :
174 109 : throw container::NoSuchElementException();
175 : }
176 :
177 : // XNameAccess
178 0 : uno::Any SAL_CALL SvxUnoXPropertyTable::getByName( const OUString& aName )
179 : throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
180 : {
181 0 : SolarMutexGuard aGuard;
182 :
183 0 : OUString aInternalName = SvxUnogetInternalNameForItem(mnWhich, aName);
184 :
185 0 : const long nCount = getCount();
186 : long i;
187 : XPropertyEntry* pEntry;
188 0 : for( i = 0; i < nCount; i++ )
189 : {
190 0 : pEntry = get( i );
191 :
192 0 : if (pEntry && aInternalName.equals(pEntry->GetName()))
193 0 : return getAny( pEntry );
194 : }
195 :
196 0 : throw container::NoSuchElementException();
197 : }
198 :
199 0 : uno::Sequence< OUString > SAL_CALL SvxUnoXPropertyTable::getElementNames()
200 : throw( uno::RuntimeException, std::exception)
201 : {
202 0 : SolarMutexGuard aGuard;
203 :
204 0 : const long nCount = getCount();
205 0 : uno::Sequence< OUString > aNames( nCount );
206 0 : OUString* pNames = aNames.getArray();
207 : long i;
208 : XPropertyEntry* pEntry;
209 0 : for( i = 0; i < nCount; i++ )
210 : {
211 0 : pEntry = get( i );
212 :
213 0 : if (pEntry)
214 0 : *pNames++ = SvxUnogetApiNameForItem(mnWhich, pEntry->GetName());
215 : }
216 :
217 0 : return aNames;
218 : }
219 :
220 23231 : sal_Bool SAL_CALL SvxUnoXPropertyTable::hasByName( const OUString& aName )
221 : throw( uno::RuntimeException, std::exception)
222 : {
223 23231 : SolarMutexGuard aGuard;
224 :
225 46462 : OUString aInternalName = SvxUnogetInternalNameForItem(mnWhich, aName);
226 :
227 23231 : const long nCount = mpList?mpList->Count():0;
228 : long i;
229 : XPropertyEntry* pEntry;
230 1729272 : for( i = 0; i < nCount; i++ )
231 : {
232 1706150 : pEntry = get( i );
233 1706150 : if (pEntry && aInternalName.equals(pEntry->GetName()))
234 109 : return sal_True;
235 : }
236 :
237 46353 : return sal_False;
238 : }
239 :
240 : // XElementAccess
241 0 : sal_Bool SAL_CALL SvxUnoXPropertyTable::hasElements( )
242 : throw( uno::RuntimeException, std::exception)
243 : {
244 0 : SolarMutexGuard aGuard;
245 :
246 0 : return getCount() != 0;
247 : }
248 :
249 :
250 :
251 186 : class SvxUnoXColorTable : public SvxUnoXPropertyTable
252 : {
253 : public:
254 93 : SvxUnoXColorTable( XPropertyList* pList ) throw() : SvxUnoXPropertyTable( XATTR_LINECOLOR, pList ) {};
255 :
256 : // SvxUnoXPropertyTable
257 : virtual uno::Any getAny( const XPropertyEntry* pEntry ) const throw() SAL_OVERRIDE;
258 : virtual XPropertyEntry* getEntry( const OUString& rName, const uno::Any& rAny ) const throw() SAL_OVERRIDE;
259 :
260 : // XElementAccess
261 : virtual uno::Type SAL_CALL getElementType() throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
262 :
263 : // XServiceInfo
264 : virtual OUString SAL_CALL getImplementationName( ) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
265 : virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw( uno::RuntimeException, std::exception) SAL_OVERRIDE;
266 : };
267 :
268 93 : uno::Reference< uno::XInterface > SAL_CALL SvxUnoXColorTable_createInstance( XPropertyList* pList ) throw()
269 : {
270 93 : return (OWeakObject*) new SvxUnoXColorTable( pList );
271 : }
272 :
273 : // SvxUnoXPropertyTable
274 0 : uno::Any SvxUnoXColorTable::getAny( const XPropertyEntry* pEntry ) const throw()
275 : {
276 0 : uno::Any aAny;
277 0 : aAny <<= (sal_Int32)static_cast<const XColorEntry*>(pEntry)->GetColor().GetColor();
278 0 : return aAny;
279 : }
280 :
281 10187 : XPropertyEntry* SvxUnoXColorTable::getEntry( const OUString& rName, const uno::Any& rAny ) const throw()
282 : {
283 10187 : sal_Int32 nColor = 0;
284 10187 : if( !(rAny >>= nColor) )
285 0 : return NULL;
286 :
287 10187 : const Color aColor( (ColorData)nColor );
288 10187 : return new XColorEntry( aColor, rName );
289 : }
290 :
291 : // XElementAccess
292 61 : uno::Type SAL_CALL SvxUnoXColorTable::getElementType()
293 : throw( uno::RuntimeException, std::exception )
294 : {
295 61 : return ::cppu::UnoType<sal_Int32>::get();
296 : }
297 :
298 : // XServiceInfo
299 0 : OUString SAL_CALL SvxUnoXColorTable::getImplementationName( ) throw( uno::RuntimeException, std::exception )
300 : {
301 0 : return OUString( "SvxUnoXColorTable" );
302 : }
303 :
304 0 : uno::Sequence< OUString > SAL_CALL SvxUnoXColorTable::getSupportedServiceNames( ) throw( uno::RuntimeException, std::exception)
305 : {
306 0 : const OUString aServiceName( "com.sun.star.drawing.ColorTable" );
307 0 : uno::Sequence< OUString > aServices( &aServiceName, 1 );
308 0 : return aServices;
309 : }
310 :
311 :
312 :
313 72 : class SvxUnoXLineEndTable : public SvxUnoXPropertyTable
314 : {
315 : public:
316 36 : SvxUnoXLineEndTable( XPropertyList* pTable ) throw() : SvxUnoXPropertyTable( XATTR_LINEEND, pTable ) {};
317 :
318 : // SvxUnoXPropertyTable
319 : virtual uno::Any getAny( const XPropertyEntry* pEntry ) const throw() SAL_OVERRIDE;
320 : virtual XPropertyEntry* getEntry( const OUString& rName, const uno::Any& rAny ) const throw(lang::IllegalArgumentException) SAL_OVERRIDE;
321 :
322 : // XElementAccess
323 : virtual uno::Type SAL_CALL getElementType() throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
324 :
325 : // XServiceInfo
326 : virtual OUString SAL_CALL getImplementationName( ) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
327 : virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw( uno::RuntimeException, std::exception) SAL_OVERRIDE;
328 : };
329 :
330 36 : uno::Reference< uno::XInterface > SAL_CALL SvxUnoXLineEndTable_createInstance( XPropertyList* pTable ) throw()
331 : {
332 36 : return (OWeakObject*)new SvxUnoXLineEndTable( pTable );
333 : }
334 :
335 : // SvxUnoXPropertyTable
336 0 : uno::Any SvxUnoXLineEndTable::getAny( const XPropertyEntry* pEntry ) const throw()
337 : {
338 :
339 0 : uno::Any aAny;
340 0 : drawing::PolyPolygonBezierCoords aBezier;
341 0 : basegfx::unotools::b2DPolyPolygonToPolyPolygonBezier( static_cast<const XLineEndEntry*>(pEntry)->GetLineEnd(),
342 0 : aBezier );
343 0 : aAny <<= aBezier;
344 0 : return aAny;
345 : }
346 :
347 80 : XPropertyEntry* SvxUnoXLineEndTable::getEntry( const OUString& rName, const uno::Any& rAny ) const throw(lang::IllegalArgumentException)
348 : {
349 :
350 80 : if( !rAny.getValue() || rAny.getValueType() != cppu::UnoType<drawing::PolyPolygonBezierCoords>::get())
351 0 : return NULL;
352 :
353 80 : basegfx::B2DPolyPolygon aPolyPolygon;
354 80 : drawing::PolyPolygonBezierCoords* pCoords = (drawing::PolyPolygonBezierCoords*)rAny.getValue();
355 80 : if( pCoords->Coordinates.getLength() > 0 )
356 80 : aPolyPolygon = basegfx::unotools::polyPolygonBezierToB2DPolyPolygon( *pCoords );
357 :
358 : // #86265# make sure polygon is closed
359 80 : aPolyPolygon.setClosed(true);
360 :
361 80 : return new XLineEndEntry( aPolyPolygon, rName );
362 : }
363 :
364 : // XElementAccess
365 4 : uno::Type SAL_CALL SvxUnoXLineEndTable::getElementType()
366 : throw( uno::RuntimeException, std::exception )
367 : {
368 4 : return cppu::UnoType<drawing::PolyPolygonBezierCoords>::get();
369 : }
370 :
371 : // XServiceInfo
372 0 : OUString SAL_CALL SvxUnoXLineEndTable::getImplementationName( ) throw( uno::RuntimeException, std::exception )
373 : {
374 0 : return OUString( "SvxUnoXLineEndTable" );
375 : }
376 :
377 0 : uno::Sequence< OUString > SAL_CALL SvxUnoXLineEndTable::getSupportedServiceNames( ) throw( uno::RuntimeException, std::exception)
378 : {
379 0 : const OUString aServiceName( "com.sun.star.drawing.LineEndTable" );
380 0 : uno::Sequence< OUString > aServices( &aServiceName, 1 );
381 0 : return aServices;
382 : }
383 :
384 :
385 :
386 462 : class SvxUnoXDashTable : public SvxUnoXPropertyTable
387 : {
388 : public:
389 231 : SvxUnoXDashTable( XPropertyList* pTable ) throw() : SvxUnoXPropertyTable( XATTR_LINEDASH, pTable ) {};
390 :
391 : // SvxUnoXPropertyTable
392 : virtual uno::Any getAny( const XPropertyEntry* pEntry ) const throw() SAL_OVERRIDE;
393 : virtual XPropertyEntry* getEntry( const OUString& rName, const uno::Any& rAny ) const throw() SAL_OVERRIDE;
394 :
395 : // XElementAccess
396 : virtual uno::Type SAL_CALL getElementType() throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
397 :
398 : // XServiceInfo
399 : virtual OUString SAL_CALL getImplementationName( ) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
400 : virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw( uno::RuntimeException, std::exception) SAL_OVERRIDE;
401 : };
402 :
403 231 : uno::Reference< uno::XInterface > SAL_CALL SvxUnoXDashTable_createInstance( XPropertyList* pTable ) throw()
404 : {
405 231 : return (OWeakObject*)new SvxUnoXDashTable( pTable );
406 : }
407 :
408 : // SvxUnoXPropertyTable
409 0 : uno::Any SvxUnoXDashTable::getAny( const XPropertyEntry* pEntry ) const throw()
410 : {
411 0 : const XDash& rXD = static_cast<const XDashEntry*>(pEntry)->GetDash();
412 :
413 0 : drawing::LineDash aLineDash;
414 :
415 0 : aLineDash.Style = (::com::sun::star::drawing::DashStyle)((sal_uInt16)rXD.GetDashStyle());
416 0 : aLineDash.Dots = rXD.GetDots();
417 0 : aLineDash.DotLen = rXD.GetDotLen();
418 0 : aLineDash.Dashes = rXD.GetDashes();
419 0 : aLineDash.DashLen = rXD.GetDashLen();
420 0 : aLineDash.Distance = rXD.GetDistance();
421 :
422 0 : uno::Any aAny;
423 0 : aAny <<= aLineDash;
424 0 : return aAny;
425 : }
426 :
427 1199 : XPropertyEntry* SvxUnoXDashTable::getEntry( const OUString& rName, const uno::Any& rAny ) const throw()
428 : {
429 1199 : drawing::LineDash aLineDash;
430 1199 : if(!(rAny >>= aLineDash))
431 0 : return NULL;
432 :
433 1199 : XDash aXDash;
434 :
435 1199 : aXDash.SetDashStyle((XDashStyle)((sal_uInt16)(aLineDash.Style)));
436 1199 : aXDash.SetDots(aLineDash.Dots);
437 1199 : aXDash.SetDotLen(aLineDash.DotLen);
438 1199 : aXDash.SetDashes(aLineDash.Dashes);
439 1199 : aXDash.SetDashLen(aLineDash.DashLen);
440 1199 : aXDash.SetDistance(aLineDash.Distance);
441 :
442 1199 : return new XDashEntry( aXDash, rName );
443 : }
444 :
445 : // XElementAccess
446 109 : uno::Type SAL_CALL SvxUnoXDashTable::getElementType()
447 : throw( uno::RuntimeException, std::exception )
448 : {
449 109 : return cppu::UnoType<drawing::LineDash>::get();
450 : }
451 :
452 : // XServiceInfo
453 0 : OUString SAL_CALL SvxUnoXDashTable::getImplementationName( ) throw( uno::RuntimeException, std::exception )
454 : {
455 0 : return OUString( "SvxUnoXDashTable" );
456 : }
457 :
458 0 : uno::Sequence< OUString > SAL_CALL SvxUnoXDashTable::getSupportedServiceNames( ) throw( uno::RuntimeException, std::exception)
459 : {
460 0 : const OUString aServiceName( "com.sun.star.drawing.DashTable" );
461 0 : uno::Sequence< OUString > aServices( &aServiceName, 1 );
462 0 : return aServices;
463 : }
464 :
465 :
466 :
467 128 : class SvxUnoXHatchTable : public SvxUnoXPropertyTable
468 : {
469 : public:
470 64 : SvxUnoXHatchTable( XPropertyList* pTable ) throw() : SvxUnoXPropertyTable( XATTR_FILLHATCH, pTable ) {};
471 :
472 : // SvxUnoXPropertyTable
473 : virtual uno::Any getAny( const XPropertyEntry* pEntry ) const throw() SAL_OVERRIDE;
474 : virtual XPropertyEntry* getEntry( const OUString& rName, const uno::Any& rAny ) const throw() SAL_OVERRIDE;
475 :
476 : // XElementAccess
477 : virtual uno::Type SAL_CALL getElementType() throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
478 :
479 : // XServiceInfo
480 : virtual OUString SAL_CALL getImplementationName( ) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
481 : virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw( uno::RuntimeException, std::exception) SAL_OVERRIDE;
482 : };
483 :
484 64 : uno::Reference< uno::XInterface > SAL_CALL SvxUnoXHatchTable_createInstance( XPropertyList* pTable ) throw()
485 : {
486 64 : return (OWeakObject*)new SvxUnoXHatchTable( pTable );
487 : }
488 :
489 : // SvxUnoXPropertyTable
490 0 : uno::Any SvxUnoXHatchTable::getAny( const XPropertyEntry* pEntry ) const throw()
491 : {
492 0 : const XHatch& aHatch = static_cast<const XHatchEntry*>(pEntry)->GetHatch();
493 :
494 0 : drawing::Hatch aUnoHatch;
495 :
496 0 : aUnoHatch.Style = (drawing::HatchStyle)aHatch.GetHatchStyle();
497 0 : aUnoHatch.Color = aHatch.GetColor().GetColor();
498 0 : aUnoHatch.Distance = aHatch.GetDistance();
499 0 : aUnoHatch.Angle = aHatch.GetAngle();
500 :
501 0 : uno::Any aAny;
502 0 : aAny <<= aUnoHatch;
503 0 : return aAny;
504 : }
505 :
506 40 : XPropertyEntry* SvxUnoXHatchTable::getEntry( const OUString& rName, const uno::Any& rAny ) const throw()
507 : {
508 40 : drawing::Hatch aUnoHatch;
509 40 : if(!(rAny >>= aUnoHatch))
510 0 : return NULL;
511 :
512 40 : XHatch aXHatch;
513 40 : aXHatch.SetHatchStyle( (XHatchStyle)aUnoHatch.Style );
514 40 : aXHatch.SetColor( aUnoHatch.Color );
515 40 : aXHatch.SetDistance( aUnoHatch.Distance );
516 40 : aXHatch.SetAngle( aUnoHatch.Angle );
517 :
518 40 : return new XHatchEntry( aXHatch, rName );
519 : }
520 :
521 : // XElementAccess
522 4 : uno::Type SAL_CALL SvxUnoXHatchTable::getElementType()
523 : throw( uno::RuntimeException, std::exception )
524 : {
525 4 : return cppu::UnoType<drawing::Hatch>::get();
526 : }
527 :
528 : // XServiceInfo
529 0 : OUString SAL_CALL SvxUnoXHatchTable::getImplementationName( ) throw( uno::RuntimeException, std::exception )
530 : {
531 0 : return OUString( "SvxUnoXHatchTable" );
532 : }
533 :
534 0 : uno::Sequence< OUString > SAL_CALL SvxUnoXHatchTable::getSupportedServiceNames( ) throw( uno::RuntimeException, std::exception)
535 : {
536 0 : const OUString aServiceName( "com.sun.star.drawing.HatchTable" );
537 0 : uno::Sequence< OUString > aServices( &aServiceName, 1 );
538 0 : return aServices;
539 : }
540 :
541 :
542 :
543 232 : class SvxUnoXGradientTable : public SvxUnoXPropertyTable
544 : {
545 : public:
546 116 : SvxUnoXGradientTable( XPropertyList* pTable ) throw() : SvxUnoXPropertyTable( XATTR_FILLGRADIENT, pTable ) {};
547 :
548 : // SvxUnoXPropertyTable
549 : virtual uno::Any getAny( const XPropertyEntry* pEntry ) const throw() SAL_OVERRIDE;
550 : virtual XPropertyEntry* getEntry( const OUString& rName, const uno::Any& rAny ) const throw() SAL_OVERRIDE;
551 :
552 : // XElementAccess
553 : virtual uno::Type SAL_CALL getElementType() throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
554 :
555 : // XServiceInfo
556 : virtual OUString SAL_CALL getImplementationName( ) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
557 : virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw( uno::RuntimeException, std::exception) SAL_OVERRIDE;
558 : };
559 :
560 116 : uno::Reference< uno::XInterface > SAL_CALL SvxUnoXGradientTable_createInstance( XPropertyList* pTable ) throw()
561 : {
562 116 : return (OWeakObject*)new SvxUnoXGradientTable( pTable );
563 : }
564 :
565 : // SvxUnoXPropertyTable
566 0 : uno::Any SvxUnoXGradientTable::getAny( const XPropertyEntry* pEntry ) const throw()
567 : {
568 0 : const XGradient& aXGradient = static_cast<const XGradientEntry*>(pEntry)->GetGradient();
569 0 : awt::Gradient aGradient;
570 :
571 0 : aGradient.Style = (awt::GradientStyle) aXGradient.GetGradientStyle();
572 0 : aGradient.StartColor = (sal_Int32)aXGradient.GetStartColor().GetColor();
573 0 : aGradient.EndColor = (sal_Int32)aXGradient.GetEndColor().GetColor();
574 0 : aGradient.Angle = (short)aXGradient.GetAngle();
575 0 : aGradient.Border = aXGradient.GetBorder();
576 0 : aGradient.XOffset = aXGradient.GetXOffset();
577 0 : aGradient.YOffset = aXGradient.GetYOffset();
578 0 : aGradient.StartIntensity = aXGradient.GetStartIntens();
579 0 : aGradient.EndIntensity = aXGradient.GetEndIntens();
580 0 : aGradient.StepCount = aXGradient.GetSteps();
581 :
582 0 : uno::Any aAny;
583 0 : aAny <<= aGradient;
584 0 : return aAny;
585 : }
586 :
587 80 : XPropertyEntry* SvxUnoXGradientTable::getEntry( const OUString& rName, const uno::Any& rAny ) const throw()
588 : {
589 80 : awt::Gradient aGradient;
590 80 : if(!(rAny >>= aGradient))
591 0 : return NULL;
592 :
593 80 : XGradient aXGradient;
594 :
595 80 : aXGradient.SetGradientStyle( (XGradientStyle) aGradient.Style );
596 80 : aXGradient.SetStartColor( aGradient.StartColor );
597 80 : aXGradient.SetEndColor( aGradient.EndColor );
598 80 : aXGradient.SetAngle( aGradient.Angle );
599 80 : aXGradient.SetBorder( aGradient.Border );
600 80 : aXGradient.SetXOffset( aGradient.XOffset );
601 80 : aXGradient.SetYOffset( aGradient.YOffset );
602 80 : aXGradient.SetStartIntens( aGradient.StartIntensity );
603 80 : aXGradient.SetEndIntens( aGradient.EndIntensity );
604 80 : aXGradient.SetSteps( aGradient.StepCount );
605 :
606 80 : return new XGradientEntry( aXGradient, rName );
607 : }
608 :
609 : // XElementAccess
610 4 : uno::Type SAL_CALL SvxUnoXGradientTable::getElementType()
611 : throw( uno::RuntimeException, std::exception )
612 : {
613 4 : return cppu::UnoType<awt::Gradient>::get();
614 : }
615 :
616 : // XServiceInfo
617 0 : OUString SAL_CALL SvxUnoXGradientTable::getImplementationName( ) throw( uno::RuntimeException, std::exception )
618 : {
619 0 : return OUString( "SvxUnoXGradientTable" );
620 : }
621 :
622 0 : uno::Sequence< OUString > SAL_CALL SvxUnoXGradientTable::getSupportedServiceNames( ) throw( uno::RuntimeException, std::exception)
623 : {
624 0 : const OUString aServiceName( "com.sun.star.drawing.GradientTable" );
625 0 : uno::Sequence< OUString > aServices( &aServiceName, 1 );
626 0 : return aServices;
627 : }
628 :
629 :
630 :
631 80 : class SvxUnoXBitmapTable : public SvxUnoXPropertyTable
632 : {
633 : public:
634 40 : SvxUnoXBitmapTable( XPropertyList* pTable ) throw() : SvxUnoXPropertyTable( XATTR_FILLBITMAP, pTable ) {};
635 :
636 : // SvxUnoXPropertyTable
637 : virtual uno::Any getAny( const XPropertyEntry* pEntry ) const throw(uno::RuntimeException) SAL_OVERRIDE;
638 : virtual XPropertyEntry* getEntry( const OUString& rName, const uno::Any& rAny ) const throw(uno::RuntimeException) SAL_OVERRIDE;
639 :
640 : // XElementAccess
641 : virtual uno::Type SAL_CALL getElementType() throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
642 :
643 : // XServiceInfo
644 : virtual OUString SAL_CALL getImplementationName( ) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
645 : virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw( uno::RuntimeException, std::exception) SAL_OVERRIDE;
646 : };
647 :
648 40 : uno::Reference< uno::XInterface > SAL_CALL SvxUnoXBitmapTable_createInstance( XPropertyList* pTable ) throw()
649 : {
650 40 : return (OWeakObject*)new SvxUnoXBitmapTable( pTable );
651 : }
652 :
653 : // SvxUnoXPropertyTable
654 0 : uno::Any SvxUnoXBitmapTable::getAny( const XPropertyEntry* pEntry ) const throw(uno::RuntimeException)
655 : {
656 0 : OUString aURL( UNO_NAME_GRAPHOBJ_URLPREFIX);
657 0 : const GraphicObject& rGraphicObject(static_cast<const XBitmapEntry*>(pEntry)->GetGraphicObject());
658 0 : aURL += OStringToOUString(rGraphicObject.GetUniqueID(), RTL_TEXTENCODING_ASCII_US);
659 :
660 0 : uno::Any aAny;
661 0 : aAny <<= aURL;
662 0 : return aAny;
663 : }
664 :
665 84 : XPropertyEntry* SvxUnoXBitmapTable::getEntry( const OUString& rName, const uno::Any& rAny ) const throw(uno::RuntimeException)
666 : {
667 84 : OUString aURL;
668 84 : if(!(rAny >>= aURL))
669 0 : return NULL;
670 :
671 168 : const GraphicObject aGrafObj(GraphicObject::CreateGraphicObjectFromURL(aURL));
672 :
673 168 : return new XBitmapEntry(aGrafObj, rName);
674 : }
675 :
676 : // XElementAccess
677 4 : uno::Type SAL_CALL SvxUnoXBitmapTable::getElementType()
678 : throw( uno::RuntimeException, std::exception )
679 : {
680 4 : return ::cppu::UnoType<OUString>::get();
681 : }
682 :
683 : // XServiceInfo
684 0 : OUString SAL_CALL SvxUnoXBitmapTable::getImplementationName( ) throw( uno::RuntimeException, std::exception )
685 : {
686 0 : return OUString( "SvxUnoXBitmapTable" );
687 : }
688 :
689 0 : uno::Sequence< OUString > SAL_CALL SvxUnoXBitmapTable::getSupportedServiceNames( ) throw( uno::RuntimeException, std::exception)
690 : {
691 0 : const OUString aServiceName( "com.sun.star.drawing.BitmapTable" );
692 0 : uno::Sequence< OUString > aServices( &aServiceName, 1 );
693 0 : return aServices;
694 651 : }
695 :
696 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|