Coverage Report

Created: 2026-09-28 10:59

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