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