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