LibreOffice Module sd (master) 1
unopback.cxx
Go to the documentation of this file.
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#include <com/sun/star/drawing/BitmapMode.hpp>
21#include <vcl/svapp.hxx>
22#include <svl/itemset.hxx>
23#include <svx/svdpool.hxx>
25#include <svx/xflbstit.hxx>
26#include <svx/xflbmtit.hxx>
27#include <svx/svdobj.hxx>
28#include <svx/unoshape.hxx>
29#include <svx/unoshprp.hxx>
30
31#include "unopback.hxx"
32#include <drawdoc.hxx>
33#include <unokywds.hxx>
34
35using namespace ::com::sun::star;
36
38{
39 static const SfxItemPropertyMapEntry aPageBackgroundPropertyMap_Impl[] =
40 {
42 };
43
44 static SvxItemPropertySet aPageBackgroundPropertySet_Impl( aPageBackgroundPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
45 return &aPageBackgroundPropertySet_Impl;
46}
47
49 SdDrawDocument* pDoc /* = NULL */,
50 const SfxItemSet* pSet /* = NULL */)
52 mpDoc(pDoc)
53{
54 if( pDoc )
55 {
56 StartListening( *pDoc );
57 mpSet = std::make_unique<SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST>>( pDoc->GetPool() );
58
59 if( pSet )
60 mpSet->Put(*pSet);
61 }
62}
63
65{
67
68 if( mpDoc )
70}
71
73{
74 if (rHint.GetId() != SfxHintId::ThisIsAnSdrHint)
75 return;
76 const SdrHint* pSdrHint = static_cast<const SdrHint*>( &rHint );
77
78 // delete item set if document is dying because then the pool
79 // will also die
80 if( pSdrHint->GetKind() == SdrHintKind::ModelCleared )
81 {
82 mpSet.reset();
83 mpDoc = nullptr;
84 }
85}
86
88{
90
91 if( mpSet == nullptr )
92 {
93 StartListening( *pDoc );
94 mpDoc = pDoc;
95
96 mpSet = std::make_unique<SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST>>( *rSet.GetPool() );
97
99 {
100 for( const auto pProp : mpPropSet->getPropertyMap().getPropertyEntries() )
101 {
102 uno::Any* pAny = maUsrAnys.GetUsrAnyForID( *pProp );
103 if( pAny )
104 {
105 const OUString & aPropertyName = pProp->aName;
106 switch( pProp->nWID )
107 {
109 case XATTR_FILLGRADIENT :
110 {
111 if ( ( pAny->getValueType() == ::cppu::UnoType< css::awt::Gradient>::get() )
112 && ( pProp->nMemberId == MID_FILLGRADIENT ) )
113 {
114 setPropertyValue( aPropertyName, *pAny );
115 }
116 else if ( ( pAny->getValueType() == ::cppu::UnoType<OUString>::get() ) &&
117 ( pProp->nMemberId == MID_NAME ) )
118 {
119 setPropertyValue( aPropertyName, *pAny );
120 }
121 }
122 break;
123 case XATTR_FILLHATCH :
124 {
125 if ( ( pAny->getValueType() == ::cppu::UnoType< css::drawing::Hatch>::get() )
126 && ( pProp->nMemberId == MID_FILLHATCH ) )
127 {
128 setPropertyValue( aPropertyName, *pAny );
129 }
130 else if ( ( pAny->getValueType() == ::cppu::UnoType<OUString>::get() ) &&
131 ( pProp->nMemberId == MID_NAME ) )
132 {
133 setPropertyValue( aPropertyName, *pAny );
134 }
135 }
136 break;
137 case XATTR_FILLBITMAP :
138 {
139 if (pProp->nMemberId == MID_BITMAP &&
140 (pAny->getValueType() == cppu::UnoType<css::awt::XBitmap>::get() ||
141 pAny->getValueType() == cppu::UnoType<css::graphic::XGraphic>::get()))
142 {
143 setPropertyValue( aPropertyName, *pAny );
144 }
145 else if (pAny->getValueType() == ::cppu::UnoType<OUString>::get() && pProp->nMemberId == MID_NAME)
146 {
147 setPropertyValue( aPropertyName, *pAny );
148 }
149 }
150 break;
151
152 default:
153 setPropertyValue( aPropertyName, *pAny );
154 }
155 }
156 }
157 }
158 }
159
160 rSet.Put( *mpSet );
161}
162
163// XServiceInfo
165{
166 return "SdUnoPageBackground";
167}
168
169sal_Bool SAL_CALL SdUnoPageBackground::supportsService( const OUString& ServiceName )
170{
171 return cppu::supportsService( this, ServiceName );
172}
173
174uno::Sequence< OUString > SAL_CALL SdUnoPageBackground::getSupportedServiceNames()
175{
177}
178
179// XPropertySet
180uno::Reference< beans::XPropertySetInfo > SAL_CALL SdUnoPageBackground::getPropertySetInfo()
181{
183}
184
185void SAL_CALL SdUnoPageBackground::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
186{
187 SolarMutexGuard aGuard;
188
189 const SfxItemPropertyMapEntry* pEntry = getPropertyMapEntry( aPropertyName );
190
191 if( pEntry == nullptr )
192 {
193 throw beans::UnknownPropertyException( aPropertyName, static_cast<cppu::OWeakObject*>(this));
194 }
195
196 if( mpSet )
197 {
198 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
199 {
200 drawing::BitmapMode eMode;
201 if( aValue >>= eMode )
202 {
203 mpSet->Put( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
204 mpSet->Put( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
205 return;
206 }
207 throw lang::IllegalArgumentException();
208 }
209
210 SfxItemPool& rPool = *mpSet->GetPool();
211 SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
212 aSet.Put( *mpSet );
213
214 if( !aSet.Count() )
215 aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
216
217 if( pEntry->nMemberId == MID_NAME && ( pEntry->nWID == XATTR_FILLBITMAP || pEntry->nWID == XATTR_FILLGRADIENT || pEntry->nWID == XATTR_FILLHATCH || pEntry->nWID == XATTR_FILLFLOATTRANSPARENCE ) )
218 {
219 OUString aName;
220 if(!(aValue >>= aName ))
221 throw lang::IllegalArgumentException();
222
223 SvxShape::SetFillAttribute( pEntry->nWID, aName, aSet );
224 }
225 else
226 {
227 SvxItemPropertySet_setPropertyValue( pEntry, aValue, aSet );
228 }
229
230 mpSet->Put( aSet );
231 }
232 else
233 {
234 if(pEntry->nWID)
236 }
237}
238
239uno::Any SAL_CALL SdUnoPageBackground::getPropertyValue( const OUString& PropertyName )
240{
241 SolarMutexGuard aGuard;
242
243 uno::Any aAny;
244 const SfxItemPropertyMapEntry* pEntry = getPropertyMapEntry(PropertyName);
245
246 if( pEntry == nullptr )
247 {
248 throw beans::UnknownPropertyException( PropertyName, static_cast<cppu::OWeakObject*>(this));
249 }
250
251 if( mpSet )
252 {
253 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
254 {
256 const XFillBmpTileItem* pTileItem = mpSet->GetItem<XFillBmpTileItem>(XATTR_FILLBMP_TILE);
257
258 if( pStretchItem && pTileItem )
259 {
260 if( pTileItem->GetValue() )
261 aAny <<= drawing::BitmapMode_REPEAT;
262 else if( pStretchItem->GetValue() )
263 aAny <<= drawing::BitmapMode_STRETCH;
264 else
265 aAny <<= drawing::BitmapMode_NO_REPEAT;
266 }
267 }
268 else
269 {
270 SfxItemPool& rPool = *mpSet->GetPool();
271 SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
272 aSet.Put( *mpSet );
273
274 if( !aSet.Count() )
275 aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
276
277 // get value from ItemSet
278 aAny = SvxItemPropertySet_getPropertyValue( pEntry, aSet );
279 }
280 }
281 else
282 {
283 if(pEntry->nWID)
284 aAny = mpPropSet->getPropertyValue( pEntry, maUsrAnys );
285 }
286 return aAny;
287}
288
289void SAL_CALL SdUnoPageBackground::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) {}
290void SAL_CALL SdUnoPageBackground::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) {}
291void SAL_CALL SdUnoPageBackground::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) {}
292void SAL_CALL SdUnoPageBackground::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) {}
293
294// XPropertyState
295beans::PropertyState SAL_CALL SdUnoPageBackground::getPropertyState( const OUString& PropertyName )
296{
297 SolarMutexGuard aGuard;
298
299 const SfxItemPropertyMapEntry* pEntry = getPropertyMapEntry(PropertyName);
300
301 if( pEntry == nullptr )
302 throw beans::UnknownPropertyException( PropertyName, static_cast<cppu::OWeakObject*>(this));
303
304 if( mpSet )
305 {
306 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
307 {
308 if( mpSet->GetItemState( XATTR_FILLBMP_STRETCH, false ) == SfxItemState::SET ||
309 mpSet->GetItemState( XATTR_FILLBMP_TILE, false ) == SfxItemState::SET )
310 {
311 return beans::PropertyState_DIRECT_VALUE;
312 }
313 else
314 {
315 return beans::PropertyState_AMBIGUOUS_VALUE;
316 }
317 }
318
319 switch( mpSet->GetItemState( pEntry->nWID, false ) )
320 {
321 case SfxItemState::SET:
322 return beans::PropertyState_DIRECT_VALUE;
323 case SfxItemState::DEFAULT:
324 return beans::PropertyState_DEFAULT_VALUE;
325 default:
326// case SfxItemState::DONTCARE:
327// case SfxItemState::DISABLED:
328 return beans::PropertyState_AMBIGUOUS_VALUE;
329 }
330 }
331 else
332 {
333 if( nullptr == maUsrAnys.GetUsrAnyForID(*pEntry) )
334 return beans::PropertyState_DEFAULT_VALUE;
335 else
336 return beans::PropertyState_DIRECT_VALUE;
337 }
338}
339
340uno::Sequence< beans::PropertyState > SAL_CALL SdUnoPageBackground::getPropertyStates( const uno::Sequence< OUString >& aPropertyName )
341{
342 SolarMutexGuard aGuard;
343
344 sal_Int32 nCount = aPropertyName.getLength();
345
346 uno::Sequence< beans::PropertyState > aPropertyStateSequence( nCount );
347
348 std::transform(aPropertyName.begin(), aPropertyName.end(), aPropertyStateSequence.getArray(),
349 [this](const OUString& rName) -> beans::PropertyState { return getPropertyState(rName); });
350
351 return aPropertyStateSequence;
352}
353
354void SAL_CALL SdUnoPageBackground::setPropertyToDefault( const OUString& PropertyName )
355{
356 SolarMutexGuard aGuard;
357
358 const SfxItemPropertyMapEntry* pEntry = getPropertyMapEntry(PropertyName);
359
360 if( pEntry == nullptr )
361 throw beans::UnknownPropertyException( PropertyName, static_cast<cppu::OWeakObject*>(this));
362
363 if( mpSet )
364 {
365 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
366 {
367 mpSet->ClearItem( XATTR_FILLBMP_STRETCH );
368 mpSet->ClearItem( XATTR_FILLBMP_TILE );
369 }
370 else
371 {
372 mpSet->ClearItem( pEntry->nWID );
373 }
374 }
375}
376
377uno::Any SAL_CALL SdUnoPageBackground::getPropertyDefault( const OUString& aPropertyName )
378{
379 SolarMutexGuard aGuard;
380
381 const SfxItemPropertyMapEntry* pEntry = getPropertyMapEntry(aPropertyName);
382 if( pEntry == nullptr || mpSet == nullptr )
383 throw beans::UnknownPropertyException( aPropertyName, static_cast<cppu::OWeakObject*>(this));
384
385 uno::Any aAny;
386 if (pEntry->nWID == OWN_ATTR_FILLBMP_MODE)
387 {
388 aAny <<= drawing::BitmapMode_REPEAT;
389 }
390 else
391 {
392 SfxItemPool& rPool = *mpSet->GetPool();
393 SfxItemSet aSet(rPool, pEntry->nWID, pEntry->nWID);
394 aSet.Put(rPool.GetDefaultItem(pEntry->nWID));
395
396 aAny = SvxItemPropertySet_getPropertyValue(pEntry, aSet);
397 }
398 return aAny;
399}
400
402const SfxItemPropertyMapEntry* SdUnoPageBackground::getPropertyMapEntry( std::u16string_view rPropertyName ) const noexcept
403{
404 return mpPropSet->getPropertyMap().getByName(rPropertyName);
405}
406
407/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPRIVATE SfxItemPool & GetPool()
Definition: drawdoc.hxx:237
virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates(const css::uno::Sequence< OUString > &aPropertyName) override
Definition: unopback.cxx:340
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
Definition: unopback.cxx:290
virtual ~SdUnoPageBackground() noexcept override
Definition: unopback.cxx:64
SvxItemPropertySetUsrAnys maUsrAnys
Definition: unopback.hxx:50
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: unopback.cxx:185
SdUnoPageBackground(SdDrawDocument *pDoc=nullptr, const SfxItemSet *pSet=nullptr)
Definition: unopback.cxx:48
virtual css::beans::PropertyState SAL_CALL getPropertyState(const OUString &PropertyName) override
Definition: unopback.cxx:295
const SvxItemPropertySet * mpPropSet
Definition: unopback.hxx:49
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: unopback.cxx:289
SdrModel * mpDoc
Definition: unopback.hxx:52
virtual void SAL_CALL setPropertyToDefault(const OUString &PropertyName) override
Definition: unopback.cxx:354
const SfxItemPropertyMapEntry * getPropertyMapEntry(std::u16string_view rPropertyName) const noexcept
this is used because our property map is not sorted yet
Definition: unopback.cxx:402
std::unique_ptr< SfxItemSet > mpSet
Definition: unopback.hxx:51
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: unopback.cxx:291
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unopback.cxx:174
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: unopback.cxx:292
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: unopback.cxx:239
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: unopback.cxx:180
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unopback.cxx:169
void fillItemSet(SdDrawDocument *pDoc, SfxItemSet &rSet)
Definition: unopback.cxx:87
virtual css::uno::Any SAL_CALL getPropertyDefault(const OUString &aPropertyName) override
Definition: unopback.cxx:377
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: unopback.cxx:72
virtual OUString SAL_CALL getImplementationName() override
Definition: unopback.cxx:164
SdrHintKind GetKind() const
static SdrItemPool & GetGlobalDrawObjectItemPool()
SfxHintId GetId() const
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
const o3tl::sorted_vector< const SfxItemPropertyMapEntry *, SfxItemPropertyMapCompare > & getPropertyEntries() const
SfxItemPool * GetPool() const
sal_uInt16 Count() const
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
css::uno::Any * GetUsrAnyForID(SfxItemPropertyMapEntry const &entry) const
bool AreThereOwnUsrAnys() const
css::uno::Reference< css::beans::XPropertySetInfo > const & getPropertySetInfo() const
static void setPropertyValue(const SfxItemPropertyMapEntry *pMap, const css::uno::Any &rVal, SfxItemSet &rSet, bool bDontConvertNegativeValues)
const SfxItemPropertyMap & getPropertyMap() const
css::uno::Any getPropertyValue(const SfxItemPropertyMapEntry *pMap, SvxItemPropertySetUsrAnys &rAnys) const
static bool SetFillAttribute(sal_uInt16 nWID, const OUString &rName, SfxItemSet &rSet, SdrModel const *pModel)
int nCount
OUString aName
Mode eMode
#define MID_NAME
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
static SfxItemSet & rSet
unsigned char sal_Bool
constexpr OUStringLiteral sUNO_Service_PageBackground
Definition: unokywds.hxx:39
constexpr OUStringLiteral sUNO_Service_FillProperties
Definition: unokywds.hxx:37
#define OWN_ATTR_FILLBMP_MODE
#define MID_FILLHATCH
#define MID_FILLGRADIENT
#define MID_BITMAP
const SvxItemPropertySet * ImplGetPageBackgroundPropertySet()
Definition: unopback.cxx:37
void SVXCORE_DLLPUBLIC SvxItemPropertySet_setPropertyValue(const SfxItemPropertyMapEntry *pMap, const css::uno::Any &rVal, SfxItemSet &rSet)
css::uno::Any SVXCORE_DLLPUBLIC SvxItemPropertySet_getPropertyValue(const SfxItemPropertyMapEntry *pMap, const SfxItemSet &rSet)
#define FILL_PROPERTIES
constexpr TypedWhichId< XFillBmpStretchItem > XATTR_FILLBMP_STRETCH(XATTR_FILL_FIRST+16)
constexpr TypedWhichId< XFillHatchItem > XATTR_FILLHATCH(XATTR_FILL_FIRST+3)
constexpr TypedWhichId< XFillBmpTileItem > XATTR_FILLBMP_TILE(XATTR_FILL_FIRST+7)
constexpr TypedWhichId< XFillBitmapItem > XATTR_FILLBITMAP(XATTR_FILL_FIRST+4)
constexpr TypedWhichId< XFillFloatTransparenceItem > XATTR_FILLFLOATTRANSPARENCE(XATTR_FILL_FIRST+11)
constexpr TypedWhichId< XFillGradientItem > XATTR_FILLGRADIENT(XATTR_FILL_FIRST+2)