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