/src/libreoffice/svx/source/unodraw/XPropertyTable.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | |
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 | | #include <docmodel/uno/UnoGradientTools.hxx> |
41 | | |
42 | | using namespace com::sun::star; |
43 | | using namespace ::cppu; |
44 | | |
45 | | namespace { |
46 | | |
47 | | class SvxUnoXPropertyTable : public WeakImplHelper< container::XNameContainer, lang::XServiceInfo > |
48 | | { |
49 | | private: |
50 | | XPropertyList& mrList; |
51 | | sal_Int16 mnWhich; |
52 | | |
53 | 0 | tools::Long getCount() const { return mrList.Count(); } |
54 | | const XPropertyEntry* get(tools::Long index) const; |
55 | | public: |
56 | | SvxUnoXPropertyTable( sal_Int16 nWhich, XPropertyList& rList ) noexcept; |
57 | | |
58 | | /// @throws uno::RuntimeException |
59 | | virtual uno::Any getAny( const XPropertyEntry* pEntry ) const = 0; |
60 | | /// @throws uno::RuntimeException |
61 | | /// @throws lang::IllegalArgumentException |
62 | | virtual std::unique_ptr<XPropertyEntry> createEntry(const OUString& rName, const uno::Any& rAny) const = 0; |
63 | | |
64 | | // XServiceInfo |
65 | | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; |
66 | | |
67 | | // XNameContainer |
68 | | virtual void SAL_CALL insertByName( const OUString& aName, const uno::Any& aElement ) override; |
69 | | virtual void SAL_CALL removeByName( const OUString& Name ) override; |
70 | | |
71 | | // XNameReplace |
72 | | virtual void SAL_CALL replaceByName( const OUString& aName, const uno::Any& aElement ) override; |
73 | | |
74 | | // XNameAccess |
75 | | virtual uno::Any SAL_CALL getByName( const OUString& aName ) override; |
76 | | virtual uno::Sequence< OUString > SAL_CALL getElementNames( ) override; |
77 | | virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override; |
78 | | |
79 | | // XElementAccess |
80 | | virtual sal_Bool SAL_CALL hasElements( ) override; |
81 | | }; |
82 | | |
83 | | } |
84 | | |
85 | | SvxUnoXPropertyTable::SvxUnoXPropertyTable( sal_Int16 nWhich, XPropertyList& rList ) noexcept |
86 | 17.1k | : mrList( rList ), mnWhich( nWhich ) |
87 | 17.1k | { |
88 | 17.1k | } |
89 | | |
90 | | const XPropertyEntry* SvxUnoXPropertyTable::get(tools::Long index) const |
91 | 0 | { |
92 | 0 | return mrList.Get(index); |
93 | 0 | } |
94 | | |
95 | | // XServiceInfo |
96 | | sal_Bool SAL_CALL SvxUnoXPropertyTable::supportsService( const OUString& ServiceName ) |
97 | 0 | { |
98 | 0 | return cppu::supportsService(this, ServiceName); |
99 | 0 | } |
100 | | |
101 | | // XNameContainer |
102 | | void SAL_CALL SvxUnoXPropertyTable::insertByName( const OUString& aName, const uno::Any& aElement ) |
103 | 0 | { |
104 | 0 | SolarMutexGuard aGuard; |
105 | |
|
106 | 0 | if( hasByName( aName ) ) |
107 | 0 | throw container::ElementExistException(); |
108 | | |
109 | 0 | OUString aInternalName = SvxUnogetInternalNameForItem(mnWhich, aName); |
110 | |
|
111 | 0 | std::unique_ptr<XPropertyEntry> pNewEntry(createEntry(aInternalName, aElement)); |
112 | 0 | if (!pNewEntry) |
113 | 0 | throw lang::IllegalArgumentException(); |
114 | | |
115 | 0 | mrList.Insert(std::move(pNewEntry)); |
116 | 0 | } |
117 | | |
118 | | void SAL_CALL SvxUnoXPropertyTable::removeByName( const OUString& Name ) |
119 | 0 | { |
120 | 0 | SolarMutexGuard aGuard; |
121 | |
|
122 | 0 | OUString aInternalName = SvxUnogetInternalNameForItem(mnWhich, Name); |
123 | |
|
124 | 0 | const tools::Long nCount = getCount(); |
125 | 0 | tools::Long i; |
126 | 0 | for( i = 0; i < nCount; i++ ) |
127 | 0 | { |
128 | 0 | const XPropertyEntry* pEntry = get(i); |
129 | 0 | if (pEntry && aInternalName == pEntry->GetName()) |
130 | 0 | { |
131 | 0 | mrList.Remove(i); |
132 | 0 | return; |
133 | 0 | } |
134 | 0 | } |
135 | | |
136 | 0 | throw container::NoSuchElementException(); |
137 | 0 | } |
138 | | |
139 | | // XNameReplace |
140 | | void SAL_CALL SvxUnoXPropertyTable::replaceByName( const OUString& aName, const uno::Any& aElement ) |
141 | 0 | { |
142 | 0 | SolarMutexGuard aGuard; |
143 | |
|
144 | 0 | OUString aInternalName = SvxUnogetInternalNameForItem(mnWhich, aName); |
145 | |
|
146 | 0 | const tools::Long nCount = getCount(); |
147 | 0 | tools::Long i; |
148 | 0 | for( i = 0; i < nCount; i++ ) |
149 | 0 | { |
150 | 0 | const XPropertyEntry* pEntry = get(i); |
151 | 0 | if (pEntry && aInternalName == pEntry->GetName()) |
152 | 0 | { |
153 | 0 | std::unique_ptr<XPropertyEntry> pNewEntry(createEntry(aInternalName, aElement)); |
154 | 0 | if (!pNewEntry) |
155 | 0 | throw lang::IllegalArgumentException(); |
156 | | |
157 | 0 | mrList.Replace(std::move(pNewEntry), i); |
158 | 0 | return; |
159 | 0 | } |
160 | 0 | } |
161 | | |
162 | 0 | throw container::NoSuchElementException(); |
163 | 0 | } |
164 | | |
165 | | // XNameAccess |
166 | | uno::Any SAL_CALL SvxUnoXPropertyTable::getByName( const OUString& aName ) |
167 | 0 | { |
168 | 0 | SolarMutexGuard aGuard; |
169 | |
|
170 | 0 | OUString aInternalName = SvxUnogetInternalNameForItem(mnWhich, aName); |
171 | |
|
172 | 0 | const tools::Long nCount = getCount(); |
173 | 0 | tools::Long i; |
174 | 0 | for( i = 0; i < nCount; i++ ) |
175 | 0 | { |
176 | 0 | const XPropertyEntry* pEntry = get(i); |
177 | |
|
178 | 0 | if (pEntry && aInternalName == pEntry->GetName()) |
179 | 0 | return getAny( pEntry ); |
180 | 0 | } |
181 | | |
182 | 0 | throw container::NoSuchElementException(); |
183 | 0 | } |
184 | | |
185 | | uno::Sequence< OUString > SAL_CALL SvxUnoXPropertyTable::getElementNames() |
186 | 0 | { |
187 | 0 | SolarMutexGuard aGuard; |
188 | |
|
189 | 0 | const tools::Long nCount = getCount(); |
190 | 0 | uno::Sequence< OUString > aNames( nCount ); |
191 | 0 | OUString* pNames = aNames.getArray(); |
192 | 0 | tools::Long i; |
193 | 0 | for( i = 0; i < nCount; i++ ) |
194 | 0 | { |
195 | 0 | const XPropertyEntry* pEntry = get(i); |
196 | |
|
197 | 0 | if (pEntry) |
198 | 0 | *pNames++ = SvxUnogetApiNameForItem(mnWhich, pEntry->GetName()); |
199 | 0 | } |
200 | |
|
201 | 0 | return aNames; |
202 | 0 | } |
203 | | |
204 | | sal_Bool SAL_CALL SvxUnoXPropertyTable::hasByName( const OUString& aName ) |
205 | 0 | { |
206 | 0 | SolarMutexGuard aGuard; |
207 | |
|
208 | 0 | OUString aInternalName = SvxUnogetInternalNameForItem(mnWhich, aName); |
209 | |
|
210 | 0 | const tools::Long nCount = mrList.Count(); |
211 | 0 | tools::Long i; |
212 | 0 | for( i = 0; i < nCount; i++ ) |
213 | 0 | { |
214 | 0 | const XPropertyEntry* pEntry = get(i); |
215 | 0 | if (pEntry && aInternalName == pEntry->GetName()) |
216 | 0 | return true; |
217 | 0 | } |
218 | | |
219 | 0 | return false; |
220 | 0 | } |
221 | | |
222 | | // XElementAccess |
223 | | sal_Bool SAL_CALL SvxUnoXPropertyTable::hasElements( ) |
224 | 0 | { |
225 | 0 | SolarMutexGuard aGuard; |
226 | |
|
227 | 0 | return getCount() != 0; |
228 | 0 | } |
229 | | |
230 | | namespace { |
231 | | |
232 | | class SvxUnoXColorTable : public SvxUnoXPropertyTable |
233 | | { |
234 | | public: |
235 | 398 | explicit SvxUnoXColorTable( XPropertyList& rList ) noexcept : SvxUnoXPropertyTable( XATTR_LINECOLOR, rList ) {}; |
236 | | |
237 | | // SvxUnoXPropertyTable |
238 | | virtual uno::Any getAny( const XPropertyEntry* pEntry ) const noexcept override; |
239 | | virtual std::unique_ptr<XPropertyEntry> createEntry(const OUString& rName, const uno::Any& rAny) const override; |
240 | | |
241 | | // XElementAccess |
242 | | virtual uno::Type SAL_CALL getElementType() override; |
243 | | |
244 | | // XServiceInfo |
245 | | virtual OUString SAL_CALL getImplementationName( ) override; |
246 | | virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; |
247 | | }; |
248 | | |
249 | | } |
250 | | |
251 | | uno::Reference< container::XNameContainer > SvxUnoXColorTable_createInstance( XPropertyList& rList ) noexcept |
252 | 398 | { |
253 | 398 | return new SvxUnoXColorTable( rList ); |
254 | 398 | } |
255 | | |
256 | | // SvxUnoXPropertyTable |
257 | | uno::Any SvxUnoXColorTable::getAny( const XPropertyEntry* pEntry ) const noexcept |
258 | 0 | { |
259 | 0 | return uno::Any( static_cast<sal_Int32>(static_cast<const XColorEntry*>(pEntry)->GetColor()) ); |
260 | 0 | } |
261 | | |
262 | | std::unique_ptr<XPropertyEntry> SvxUnoXColorTable::createEntry(const OUString& rName, const uno::Any& rAny) const |
263 | 0 | { |
264 | 0 | Color aColor; |
265 | 0 | if( !(rAny >>= aColor) ) |
266 | 0 | return std::unique_ptr<XPropertyEntry>(); |
267 | | |
268 | 0 | return std::make_unique<XColorEntry>(aColor, rName); |
269 | 0 | } |
270 | | |
271 | | // XElementAccess |
272 | | uno::Type SAL_CALL SvxUnoXColorTable::getElementType() |
273 | 0 | { |
274 | 0 | return ::cppu::UnoType<sal_Int32>::get(); |
275 | 0 | } |
276 | | |
277 | | // XServiceInfo |
278 | | OUString SAL_CALL SvxUnoXColorTable::getImplementationName( ) |
279 | 0 | { |
280 | 0 | return u"SvxUnoXColorTable"_ustr; |
281 | 0 | } |
282 | | |
283 | | uno::Sequence< OUString > SAL_CALL SvxUnoXColorTable::getSupportedServiceNames( ) |
284 | 0 | { |
285 | 0 | return { u"com.sun.star.drawing.ColorTable"_ustr }; |
286 | 0 | } |
287 | | |
288 | | namespace { |
289 | | |
290 | | class SvxUnoXLineEndTable : public SvxUnoXPropertyTable |
291 | | { |
292 | | public: |
293 | 399 | explicit SvxUnoXLineEndTable( XPropertyList& rTable ) noexcept : SvxUnoXPropertyTable( XATTR_LINEEND, rTable ) {}; |
294 | | |
295 | | // SvxUnoXPropertyTable |
296 | | virtual uno::Any getAny( const XPropertyEntry* pEntry ) const noexcept override; |
297 | | virtual std::unique_ptr<XPropertyEntry> createEntry(const OUString& rName, const uno::Any& rAny) const override; |
298 | | |
299 | | // XElementAccess |
300 | | virtual uno::Type SAL_CALL getElementType() override; |
301 | | |
302 | | // XServiceInfo |
303 | | virtual OUString SAL_CALL getImplementationName( ) override; |
304 | | virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; |
305 | | }; |
306 | | |
307 | | } |
308 | | |
309 | | uno::Reference< container::XNameContainer > SvxUnoXLineEndTable_createInstance( XPropertyList& rTable ) noexcept |
310 | 399 | { |
311 | 399 | return new SvxUnoXLineEndTable( rTable ); |
312 | 399 | } |
313 | | |
314 | | // SvxUnoXPropertyTable |
315 | | uno::Any SvxUnoXLineEndTable::getAny( const XPropertyEntry* pEntry ) const noexcept |
316 | 0 | { |
317 | 0 | drawing::PolyPolygonBezierCoords aBezier; |
318 | 0 | basegfx::utils::B2DPolyPolygonToUnoPolyPolygonBezierCoords( static_cast<const XLineEndEntry*>(pEntry)->GetLineEnd(), |
319 | 0 | aBezier ); |
320 | 0 | return uno::Any(aBezier); |
321 | 0 | } |
322 | | |
323 | | std::unique_ptr<XPropertyEntry> SvxUnoXLineEndTable::createEntry(const OUString& rName, const uno::Any& rAny) const |
324 | 0 | { |
325 | 0 | auto pCoords = o3tl::tryAccess<drawing::PolyPolygonBezierCoords>(rAny); |
326 | 0 | if( !pCoords ) |
327 | 0 | return std::unique_ptr<XLineEndEntry>(); |
328 | | |
329 | 0 | basegfx::B2DPolyPolygon aPolyPolygon; |
330 | 0 | if( pCoords->Coordinates.getLength() > 0 ) |
331 | 0 | aPolyPolygon = basegfx::utils::UnoPolyPolygonBezierCoordsToB2DPolyPolygon( *pCoords ); |
332 | | |
333 | | // #86265# make sure polygon is closed |
334 | 0 | aPolyPolygon.setClosed(true); |
335 | |
|
336 | 0 | return std::make_unique<XLineEndEntry>(aPolyPolygon, rName); |
337 | 0 | } |
338 | | |
339 | | // XElementAccess |
340 | | uno::Type SAL_CALL SvxUnoXLineEndTable::getElementType() |
341 | 0 | { |
342 | 0 | return cppu::UnoType<drawing::PolyPolygonBezierCoords>::get(); |
343 | 0 | } |
344 | | |
345 | | // XServiceInfo |
346 | | OUString SAL_CALL SvxUnoXLineEndTable::getImplementationName( ) |
347 | 0 | { |
348 | 0 | return u"SvxUnoXLineEndTable"_ustr; |
349 | 0 | } |
350 | | |
351 | | uno::Sequence< OUString > SAL_CALL SvxUnoXLineEndTable::getSupportedServiceNames( ) |
352 | 0 | { |
353 | 0 | return { u"com.sun.star.drawing.LineEndTable"_ustr }; |
354 | 0 | } |
355 | | |
356 | | namespace { |
357 | | |
358 | | class SvxUnoXDashTable : public SvxUnoXPropertyTable |
359 | | { |
360 | | public: |
361 | 400 | explicit SvxUnoXDashTable( XPropertyList& rTable ) noexcept : SvxUnoXPropertyTable( XATTR_LINEDASH, rTable ) {}; |
362 | | |
363 | | // SvxUnoXPropertyTable |
364 | | virtual uno::Any getAny( const XPropertyEntry* pEntry ) const noexcept override; |
365 | | virtual std::unique_ptr<XPropertyEntry> createEntry(const OUString& rName, const uno::Any& rAny) const override; |
366 | | |
367 | | // XElementAccess |
368 | | virtual uno::Type SAL_CALL getElementType() override; |
369 | | |
370 | | // XServiceInfo |
371 | | virtual OUString SAL_CALL getImplementationName( ) override; |
372 | | virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; |
373 | | }; |
374 | | |
375 | | } |
376 | | |
377 | | uno::Reference< container::XNameContainer > SvxUnoXDashTable_createInstance( XPropertyList& rTable ) noexcept |
378 | 400 | { |
379 | 400 | return new SvxUnoXDashTable( rTable ); |
380 | 400 | } |
381 | | |
382 | | // SvxUnoXPropertyTable |
383 | | uno::Any SvxUnoXDashTable::getAny( const XPropertyEntry* pEntry ) const noexcept |
384 | 0 | { |
385 | 0 | const XDash& rXD = static_cast<const XDashEntry*>(pEntry)->GetDash(); |
386 | |
|
387 | 0 | drawing::LineDash aLineDash; |
388 | |
|
389 | 0 | aLineDash.Style = static_cast<css::drawing::DashStyle>(static_cast<sal_uInt16>(rXD.GetDashStyle())); |
390 | 0 | aLineDash.Dots = rXD.GetDots(); |
391 | 0 | aLineDash.DotLen = rXD.GetDotLen(); |
392 | 0 | aLineDash.Dashes = rXD.GetDashes(); |
393 | 0 | aLineDash.DashLen = rXD.GetDashLen(); |
394 | 0 | aLineDash.Distance = rXD.GetDistance(); |
395 | |
|
396 | 0 | return uno::Any(aLineDash); |
397 | 0 | } |
398 | | |
399 | | std::unique_ptr<XPropertyEntry> SvxUnoXDashTable::createEntry(const OUString& rName, const uno::Any& rAny) const |
400 | 0 | { |
401 | 0 | drawing::LineDash aLineDash; |
402 | 0 | if(!(rAny >>= aLineDash)) |
403 | 0 | return std::unique_ptr<XDashEntry>(); |
404 | | |
405 | 0 | XDash aXDash; |
406 | |
|
407 | 0 | aXDash.SetDashStyle(static_cast<css::drawing::DashStyle>(static_cast<sal_uInt16>(aLineDash.Style))); |
408 | 0 | aXDash.SetDots(aLineDash.Dots); |
409 | 0 | aXDash.SetDotLen(aLineDash.DotLen); |
410 | 0 | aXDash.SetDashes(aLineDash.Dashes); |
411 | 0 | aXDash.SetDashLen(aLineDash.DashLen); |
412 | 0 | aXDash.SetDistance(aLineDash.Distance); |
413 | |
|
414 | 0 | return std::make_unique<XDashEntry>(aXDash, rName); |
415 | 0 | } |
416 | | |
417 | | // XElementAccess |
418 | | uno::Type SAL_CALL SvxUnoXDashTable::getElementType() |
419 | 0 | { |
420 | 0 | return cppu::UnoType<drawing::LineDash>::get(); |
421 | 0 | } |
422 | | |
423 | | // XServiceInfo |
424 | | OUString SAL_CALL SvxUnoXDashTable::getImplementationName( ) |
425 | 0 | { |
426 | 0 | return u"SvxUnoXDashTable"_ustr; |
427 | 0 | } |
428 | | |
429 | | uno::Sequence< OUString > SAL_CALL SvxUnoXDashTable::getSupportedServiceNames( ) |
430 | 0 | { |
431 | 0 | return { u"com.sun.star.drawing.DashTable"_ustr }; |
432 | 0 | } |
433 | | |
434 | | namespace { |
435 | | |
436 | | class SvxUnoXHatchTable : public SvxUnoXPropertyTable |
437 | | { |
438 | | public: |
439 | 15.0k | explicit SvxUnoXHatchTable( XPropertyList& rTable ) noexcept : SvxUnoXPropertyTable( XATTR_FILLHATCH, rTable ) {}; |
440 | | |
441 | | // SvxUnoXPropertyTable |
442 | | virtual uno::Any getAny( const XPropertyEntry* pEntry ) const noexcept override; |
443 | | virtual std::unique_ptr<XPropertyEntry> createEntry(const OUString& rName, const uno::Any& rAny) const override; |
444 | | |
445 | | // XElementAccess |
446 | | virtual uno::Type SAL_CALL getElementType() override; |
447 | | |
448 | | // XServiceInfo |
449 | | virtual OUString SAL_CALL getImplementationName( ) override; |
450 | | virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; |
451 | | }; |
452 | | |
453 | | } |
454 | | |
455 | | uno::Reference< container::XNameContainer > SvxUnoXHatchTable_createInstance( XPropertyList& rTable ) noexcept |
456 | 15.0k | { |
457 | 15.0k | return new SvxUnoXHatchTable( rTable ); |
458 | 15.0k | } |
459 | | |
460 | | // SvxUnoXPropertyTable |
461 | | uno::Any SvxUnoXHatchTable::getAny( const XPropertyEntry* pEntry ) const noexcept |
462 | 0 | { |
463 | 0 | const XHatch& aHatch = static_cast<const XHatchEntry*>(pEntry)->GetHatch(); |
464 | |
|
465 | 0 | drawing::Hatch aUnoHatch; |
466 | |
|
467 | 0 | aUnoHatch.Style = aHatch.GetHatchStyle(); |
468 | 0 | aUnoHatch.Color = sal_Int32(aHatch.GetColor()); |
469 | 0 | aUnoHatch.Distance = aHatch.GetDistance(); |
470 | 0 | aUnoHatch.Angle = aHatch.GetAngle().get(); |
471 | |
|
472 | 0 | return uno::Any(aUnoHatch); |
473 | 0 | } |
474 | | |
475 | | std::unique_ptr<XPropertyEntry> SvxUnoXHatchTable::createEntry(const OUString& rName, const uno::Any& rAny) const |
476 | 0 | { |
477 | 0 | drawing::Hatch aUnoHatch; |
478 | 0 | if(!(rAny >>= aUnoHatch)) |
479 | 0 | return std::unique_ptr<XHatchEntry>(); |
480 | | |
481 | 0 | XHatch aXHatch; |
482 | 0 | aXHatch.SetHatchStyle( aUnoHatch.Style ); |
483 | 0 | aXHatch.SetColor( Color(ColorTransparency, aUnoHatch.Color) ); |
484 | 0 | aXHatch.SetDistance( aUnoHatch.Distance ); |
485 | 0 | aXHatch.SetAngle( Degree10(aUnoHatch.Angle) ); |
486 | |
|
487 | 0 | return std::make_unique<XHatchEntry>(aXHatch, rName); |
488 | 0 | } |
489 | | |
490 | | // XElementAccess |
491 | | uno::Type SAL_CALL SvxUnoXHatchTable::getElementType() |
492 | 0 | { |
493 | 0 | return cppu::UnoType<drawing::Hatch>::get(); |
494 | 0 | } |
495 | | |
496 | | // XServiceInfo |
497 | | OUString SAL_CALL SvxUnoXHatchTable::getImplementationName( ) |
498 | 0 | { |
499 | 0 | return u"SvxUnoXHatchTable"_ustr; |
500 | 0 | } |
501 | | |
502 | | uno::Sequence< OUString > SAL_CALL SvxUnoXHatchTable::getSupportedServiceNames( ) |
503 | 0 | { |
504 | 0 | return { u"com.sun.star.drawing.HatchTable"_ustr }; |
505 | 0 | } |
506 | | |
507 | | namespace { |
508 | | |
509 | | class SvxUnoXGradientTable : public SvxUnoXPropertyTable |
510 | | { |
511 | | public: |
512 | 440 | explicit SvxUnoXGradientTable( XPropertyList& rTable ) noexcept : SvxUnoXPropertyTable( XATTR_FILLGRADIENT, rTable ) {}; |
513 | | |
514 | | // SvxUnoXPropertyTable |
515 | | virtual uno::Any getAny( const XPropertyEntry* pEntry ) const noexcept override; |
516 | | virtual std::unique_ptr<XPropertyEntry> createEntry(const OUString& rName, const uno::Any& rAny) const override; |
517 | | |
518 | | // XElementAccess |
519 | | virtual uno::Type SAL_CALL getElementType() override; |
520 | | |
521 | | // XServiceInfo |
522 | | virtual OUString SAL_CALL getImplementationName( ) override; |
523 | | virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; |
524 | | }; |
525 | | |
526 | | } |
527 | | |
528 | | uno::Reference< container::XNameContainer > SvxUnoXGradientTable_createInstance( XPropertyList& rTable ) noexcept |
529 | 440 | { |
530 | 440 | return new SvxUnoXGradientTable( rTable ); |
531 | 440 | } |
532 | | |
533 | | // SvxUnoXPropertyTable |
534 | | uno::Any SvxUnoXGradientTable::getAny( const XPropertyEntry* pEntry ) const noexcept |
535 | 0 | { |
536 | 0 | const basegfx::BGradient& aBGradient = static_cast<const XGradientEntry*>(pEntry)->GetGradient(); |
537 | |
|
538 | 0 | awt::Gradient2 aGradient = model::gradient::createUnoGradient2(aBGradient); |
539 | 0 | assert(aGradient.ColorStops.get() && "cid#1524745 aGradient.ColorStops._pSequence won't be null here"); |
540 | |
|
541 | 0 | return uno::Any(aGradient); |
542 | 0 | } |
543 | | |
544 | | std::unique_ptr<XPropertyEntry> SvxUnoXGradientTable::createEntry(const OUString& rName, const uno::Any& rAny) const |
545 | 0 | { |
546 | 0 | if (!rAny.has<css::awt::Gradient>() || !rAny.has<css::awt::Gradient2>()) |
547 | 0 | return std::unique_ptr<XPropertyEntry>(); |
548 | | |
549 | 0 | const basegfx::BGradient aBGradient = model::gradient::getFromAny(rAny); |
550 | 0 | return std::make_unique<XGradientEntry>(aBGradient, rName); |
551 | 0 | } |
552 | | |
553 | | // XElementAccess |
554 | | uno::Type SAL_CALL SvxUnoXGradientTable::getElementType() |
555 | 0 | { |
556 | 0 | return cppu::UnoType<awt::Gradient>::get(); |
557 | 0 | } |
558 | | |
559 | | // XServiceInfo |
560 | | OUString SAL_CALL SvxUnoXGradientTable::getImplementationName( ) |
561 | 0 | { |
562 | 0 | return u"SvxUnoXGradientTable"_ustr; |
563 | 0 | } |
564 | | |
565 | | uno::Sequence< OUString > SAL_CALL SvxUnoXGradientTable::getSupportedServiceNames( ) |
566 | 0 | { |
567 | 0 | return { u"com.sun.star.drawing.GradientTable"_ustr }; |
568 | 0 | } |
569 | | |
570 | | namespace { |
571 | | |
572 | | class SvxUnoXBitmapTable : public SvxUnoXPropertyTable |
573 | | { |
574 | | public: |
575 | 410 | explicit SvxUnoXBitmapTable( XPropertyList& rTable ) noexcept : SvxUnoXPropertyTable( XATTR_FILLBITMAP, rTable ) {}; |
576 | | |
577 | | // SvxUnoXPropertyTable |
578 | | virtual uno::Any getAny( const XPropertyEntry* pEntry ) const override; |
579 | | virtual std::unique_ptr<XPropertyEntry> createEntry(const OUString& rName, const uno::Any& rAny) const override; |
580 | | |
581 | | // XElementAccess |
582 | | virtual uno::Type SAL_CALL getElementType() override; |
583 | | |
584 | | // XServiceInfo |
585 | | virtual OUString SAL_CALL getImplementationName( ) override; |
586 | | virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; |
587 | | }; |
588 | | |
589 | | } |
590 | | |
591 | | uno::Reference< container::XNameContainer > SvxUnoXBitmapTable_createInstance( XPropertyList& rTable ) noexcept |
592 | 410 | { |
593 | 410 | return new SvxUnoXBitmapTable( rTable ); |
594 | 410 | } |
595 | | |
596 | | // SvxUnoXPropertyTable |
597 | | uno::Any SvxUnoXBitmapTable::getAny( const XPropertyEntry* pEntry ) const |
598 | 0 | { |
599 | 0 | auto xBitmapEntry = static_cast<const XBitmapEntry*>(pEntry); |
600 | 0 | css::uno::Reference<css::awt::XBitmap> xBitmap(xBitmapEntry->GetGraphicObject().GetGraphic().GetXGraphic(), uno::UNO_QUERY); |
601 | 0 | return uno::Any(xBitmap); |
602 | 0 | } |
603 | | |
604 | | std::unique_ptr<XPropertyEntry> SvxUnoXBitmapTable::createEntry(const OUString& rName, const uno::Any& rAny) const |
605 | 0 | { |
606 | 0 | if (!rAny.has<uno::Reference<awt::XBitmap>>()) |
607 | 0 | return std::unique_ptr<XPropertyEntry>(); |
608 | | |
609 | 0 | auto xBitmap = rAny.get<uno::Reference<awt::XBitmap>>(); |
610 | 0 | if (!xBitmap.is()) |
611 | 0 | return nullptr; |
612 | | |
613 | 0 | uno::Reference<graphic::XGraphic> xGraphic(xBitmap, uno::UNO_QUERY); |
614 | 0 | if (!xGraphic.is()) |
615 | 0 | return nullptr; |
616 | | |
617 | 0 | Graphic aGraphic(xGraphic); |
618 | 0 | if (aGraphic.IsNone()) |
619 | 0 | return nullptr; |
620 | | |
621 | 0 | GraphicObject aGraphicObject(std::move(aGraphic)); |
622 | 0 | return std::make_unique<XBitmapEntry>(aGraphicObject, rName); |
623 | 0 | } |
624 | | |
625 | | // XElementAccess |
626 | | uno::Type SAL_CALL SvxUnoXBitmapTable::getElementType() |
627 | 0 | { |
628 | 0 | return ::cppu::UnoType<awt::XBitmap>::get(); |
629 | 0 | } |
630 | | |
631 | | // XServiceInfo |
632 | | OUString SAL_CALL SvxUnoXBitmapTable::getImplementationName( ) |
633 | 0 | { |
634 | 0 | return u"SvxUnoXBitmapTable"_ustr; |
635 | 0 | } |
636 | | |
637 | | uno::Sequence< OUString > SAL_CALL SvxUnoXBitmapTable::getSupportedServiceNames( ) |
638 | 0 | { |
639 | 0 | return { u"com.sun.star.drawing.BitmapTable"_ustr }; |
640 | 0 | } |
641 | | |
642 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |