Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/unodraw/unopool.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/lang/XServiceInfo.hpp>
21
#include <com/sun/star/beans/PropertyState.hpp>
22
23
#include <comphelper/propertysetinfo.hxx>
24
#include <cppuhelper/supportsservice.hxx>
25
#include <editeng/unoipset.hxx>
26
#include <vcl/svapp.hxx>
27
#include <svx/unopool.hxx>
28
#include <svx/svdmodel.hxx>
29
#include <svx/svdpool.hxx>
30
#include <svx/unoshprp.hxx>
31
#include <svx/xflbstit.hxx>
32
#include <svx/xflbmtit.hxx>
33
#include <svx/svdetc.hxx>
34
#include <editeng/editeng.hxx>
35
#include <tools/debug.hxx>
36
37
#include <memory>
38
39
using namespace ::com::sun::star;
40
using namespace ::cppu;
41
42
SvxUnoDrawPool::SvxUnoDrawPool(SdrModel* pModel, rtl::Reference<comphelper::PropertySetInfo> const & xDefaults)
43
2.23k
: SvxUnoDrawPool_Base(), PropertySetHelper( xDefaults ), mpModel( pModel )
44
2.23k
{
45
2.23k
    init();
46
2.23k
}
SvxUnoDrawPool::SvxUnoDrawPool(SdrModel*, rtl::Reference<comphelper::PropertySetInfo> const&)
Line
Count
Source
43
2.23k
: SvxUnoDrawPool_Base(), PropertySetHelper( xDefaults ), mpModel( pModel )
44
2.23k
{
45
2.23k
    init();
46
2.23k
}
Unexecuted instantiation: SvxUnoDrawPool::SvxUnoDrawPool(SdrModel*, rtl::Reference<comphelper::PropertySetInfo> const&)
47
48
SvxUnoDrawPool::~SvxUnoDrawPool() noexcept
49
2.23k
{
50
2.23k
}
51
52
void SvxUnoDrawPool::init()
53
2.23k
{
54
2.23k
    mpDefaultsPool = new SdrItemPool();
55
2.23k
    rtl::Reference<SfxItemPool> pOutlPool = EditEngine::CreatePool();
56
2.23k
    mpDefaultsPool->SetSecondaryPool(pOutlPool.get());
57
58
2.23k
    SdrModel::SetTextDefaults( mpDefaultsPool.get(), SdrEngineDefaults::GetFontHeight() );
59
2.23k
    mpDefaultsPool->SetDefaultMetric(SdrEngineDefaults::GetMapUnit());
60
2.23k
}
61
62
SfxItemPool* SvxUnoDrawPool::getModelPool( bool bReadOnly ) noexcept
63
1.71k
{
64
1.71k
    if( mpModel )
65
1.71k
    {
66
1.71k
        return &mpModel->GetItemPool();
67
1.71k
    }
68
0
    else
69
0
    {
70
0
        if( bReadOnly )
71
0
            return mpDefaultsPool.get();
72
0
        else
73
0
            return nullptr;
74
0
    }
75
1.71k
}
76
77
void SvxUnoDrawPool::getAny( SfxItemPool const * pPool, const comphelper::PropertyMapEntry* pEntry, uno::Any& rValue )
78
1.66k
{
79
1.66k
    switch( pEntry->mnHandle )
80
1.66k
    {
81
0
    case OWN_ATTR_FILLBMP_MODE:
82
0
        {
83
0
            if (pPool->GetUserOrPoolDefaultItem(XATTR_FILLBMP_TILE).GetValue())
84
0
            {
85
0
                rValue <<= drawing::BitmapMode_REPEAT;
86
0
            }
87
0
            else if (pPool->GetUserOrPoolDefaultItem(XATTR_FILLBMP_STRETCH).GetValue())
88
0
            {
89
0
                rValue <<= drawing::BitmapMode_STRETCH;
90
0
            }
91
0
            else
92
0
            {
93
0
                rValue <<= drawing::BitmapMode_NO_REPEAT;
94
0
            }
95
0
            break;
96
0
        }
97
1.66k
    default:
98
1.66k
        {
99
1.66k
            const MapUnit eMapUnit = pPool->GetMetric(static_cast<sal_uInt16>(pEntry->mnHandle));
100
101
1.66k
            sal_uInt8 nMemberId = pEntry->mnMemberId;
102
1.66k
            if( eMapUnit == MapUnit::Map100thMM )
103
1.66k
                nMemberId &= (~CONVERT_TWIPS);
104
105
            // Assure, that ID is a Which-ID (it could be a Slot-ID.)
106
            // Thus, convert handle to Which-ID.
107
1.66k
            pPool->GetUserOrPoolDefaultItem( pPool->GetWhichIDFromSlotID( static_cast<sal_uInt16>(pEntry->mnHandle) ) ).QueryValue( rValue, nMemberId );
108
1.66k
        }
109
1.66k
    }
110
111
112
    // check for needed metric translation
113
1.66k
    const MapUnit eMapUnit = pPool->GetMetric(static_cast<sal_uInt16>(pEntry->mnHandle));
114
1.66k
    if(pEntry->mnMoreFlags & PropertyMoreFlags::METRIC_ITEM && eMapUnit != MapUnit::Map100thMM)
115
0
    {
116
0
        SvxUnoConvertToMM( eMapUnit, rValue );
117
0
    }
118
    // convert int32 to correct enum type if needed
119
1.66k
    else if ( pEntry->maType.getTypeClass() == uno::TypeClass_ENUM && rValue.getValueType() == ::cppu::UnoType<sal_Int32>::get() )
120
0
    {
121
0
        sal_Int32 nEnum;
122
0
        rValue >>= nEnum;
123
124
0
        rValue.setValue( &nEnum, pEntry->maType );
125
0
    }
126
1.66k
}
127
128
void SvxUnoDrawPool::putAny( SfxItemPool* pPool, const comphelper::PropertyMapEntry* pEntry, const uno::Any& rValue )
129
52.8k
{
130
52.8k
    uno::Any aValue( rValue );
131
132
52.8k
    const MapUnit eMapUnit = pPool->GetMetric(static_cast<sal_uInt16>(pEntry->mnHandle));
133
52.8k
    if(pEntry->mnMoreFlags & PropertyMoreFlags::METRIC_ITEM && eMapUnit != MapUnit::Map100thMM)
134
3.80k
    {
135
3.80k
        SvxUnoConvertFromMM( eMapUnit, aValue );
136
3.80k
    }
137
138
    // Assure, that ID is a Which-ID (it could be a Slot-ID.)
139
    // Thus, convert handle to Which-ID.
140
52.8k
    const sal_uInt16 nWhich = pPool->GetWhichIDFromSlotID( static_cast<sal_uInt16>(pEntry->mnHandle) );
141
52.8k
    switch( nWhich )
142
52.8k
    {
143
0
        case OWN_ATTR_FILLBMP_MODE:
144
0
            do
145
0
            {
146
0
                drawing::BitmapMode eMode;
147
0
                if(!(aValue >>= eMode) )
148
0
                {
149
0
                    sal_Int32 nMode = 0;
150
0
                    if(!(aValue >>= nMode))
151
0
                        throw lang::IllegalArgumentException();
152
153
0
                    eMode = static_cast<drawing::BitmapMode>(nMode);
154
0
                }
155
156
0
                pPool->SetUserDefaultItem( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
157
0
                pPool->SetUserDefaultItem( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
158
0
                return;
159
0
            }
160
0
            while(false);
161
162
52.8k
    default:
163
52.8k
        {
164
52.8k
            std::unique_ptr<SfxPoolItem> pNewItem( pPool->GetUserOrPoolDefaultItem( nWhich ).Clone() );
165
52.8k
            sal_uInt8 nMemberId = pEntry->mnMemberId;
166
52.8k
            if( pPool->GetMetric(nWhich) == MapUnit::Map100thMM )
167
0
                nMemberId &= (~CONVERT_TWIPS);
168
169
52.8k
            if( !pNewItem->PutValue( aValue, nMemberId ) )
170
243
                throw lang::IllegalArgumentException();
171
172
52.6k
            pPool->SetUserDefaultItem( *pNewItem );
173
52.6k
        }
174
52.8k
    }
175
52.8k
}
176
177
void SvxUnoDrawPool::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
178
6.71k
{
179
6.71k
    SolarMutexGuard aGuard;
180
181
6.71k
    SfxItemPool* pPool = getModelPool( false );
182
183
6.71k
    DBG_ASSERT( pPool, "I need a SfxItemPool!" );
184
6.71k
    if( nullptr == pPool )
185
0
        throw beans::UnknownPropertyException( u"no pool, no properties.."_ustr, getXWeak());
186
187
59.5k
    while( *ppEntries )
188
52.8k
        putAny( pPool, *ppEntries++, *pValues++ );
189
6.71k
}
190
191
void SvxUnoDrawPool::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValue )
192
1.66k
{
193
1.66k
    SolarMutexGuard aGuard;
194
195
1.66k
    SfxItemPool* pPool = getModelPool( true );
196
197
1.66k
    DBG_ASSERT( pPool, "I need a SfxItemPool!" );
198
1.66k
    if( nullptr == pPool )
199
0
        throw beans::UnknownPropertyException( u"no pool, no properties.."_ustr, getXWeak());
200
201
3.33k
    while( *ppEntries )
202
1.66k
        getAny( pPool, *ppEntries++, *pValue++ );
203
1.66k
}
204
205
void SvxUnoDrawPool::_getPropertyStates( const comphelper::PropertyMapEntry** ppEntries, beans::PropertyState* pStates )
206
49
{
207
49
    SolarMutexGuard aGuard;
208
209
49
    SfxItemPool* pPool = getModelPool( true );
210
211
49
    if( pPool && pPool != mpDefaultsPool.get() )
212
49
    {
213
8.67k
        while( *ppEntries )
214
8.62k
        {
215
            //Assure, that ID is a Which-ID (it could be a Slot-ID.)
216
            // Thus, convert handle to Which-ID.
217
8.62k
            const sal_uInt16 nWhich = pPool->GetWhichIDFromSlotID( static_cast<sal_uInt16>((*ppEntries)->mnHandle) );
218
219
8.62k
            switch( nWhich )
220
8.62k
            {
221
49
            case OWN_ATTR_FILLBMP_MODE:
222
49
                {
223
                    // use method <IsStaticDefaultItem(..)> instead of using
224
                    // probably incompatible item pool <mpDefaultPool>.
225
49
                    if ( IsStaticDefaultItem( &(pPool->GetUserOrPoolDefaultItem( XATTR_FILLBMP_STRETCH )) ) ||
226
0
                         IsStaticDefaultItem( &(pPool->GetUserOrPoolDefaultItem( XATTR_FILLBMP_TILE )) ) )
227
49
                    {
228
49
                        *pStates = beans::PropertyState_DEFAULT_VALUE;
229
49
                    }
230
0
                    else
231
0
                    {
232
0
                        *pStates = beans::PropertyState_DIRECT_VALUE;
233
0
                    }
234
49
                }
235
49
                break;
236
49
            case OWN_ATTR_TEXTCOLUMNS:
237
49
                if (IsStaticDefaultItem(&pPool->GetUserOrPoolDefaultItem(sal_uInt16(SDRATTR_TEXTCOLUMNS_NUMBER)))
238
49
                    && IsStaticDefaultItem(&pPool->GetUserOrPoolDefaultItem(sal_uInt16(SDRATTR_TEXTCOLUMNS_SPACING))))
239
49
                    *pStates = beans::PropertyState_DEFAULT_VALUE;
240
0
                else
241
0
                    *pStates = beans::PropertyState_DIRECT_VALUE;
242
49
                break;
243
8.52k
            default:
244
                //#i18732# - correction:
245
                // use method <IsStaticDefaultItem(..)> instead of using probably
246
                // incompatible item pool <mpDefaultPool>.
247
8.52k
                const SfxPoolItem& r1 = pPool->GetUserOrPoolDefaultItem( nWhich );
248
                //const SfxPoolItem& r2 = mpDefaultPool->GetUserOrPoolDefaultItem( nWhich );
249
250
8.52k
                if ( IsStaticDefaultItem( &r1 ) )
251
7.44k
                {
252
7.44k
                    *pStates = beans::PropertyState_DEFAULT_VALUE;
253
7.44k
                }
254
1.07k
                else
255
1.07k
                {
256
1.07k
                    *pStates = beans::PropertyState_DIRECT_VALUE;
257
1.07k
                }
258
8.62k
            }
259
260
8.62k
            pStates++;
261
8.62k
            ppEntries++;
262
8.62k
        }
263
49
    }
264
0
    else
265
0
    {
266
        // as long as we have no model, all properties are default
267
0
        while( *ppEntries++ )
268
0
            *pStates++ = beans::PropertyState_DEFAULT_VALUE;
269
0
        return;
270
0
    }
271
49
}
272
273
void SvxUnoDrawPool::_setPropertyToDefault( const comphelper::PropertyMapEntry* pEntry )
274
0
{
275
0
    SolarMutexGuard aGuard;
276
277
0
    SfxItemPool* pPool = getModelPool( true );
278
279
    // Assure, that ID is a Which-ID (it could be a Slot-ID.)
280
    // Thus, convert handle to Which-ID.
281
0
    const sal_uInt16 nWhich = pPool->GetWhichIDFromSlotID( static_cast<sal_uInt16>(pEntry->mnHandle) );
282
0
    if ( pPool && pPool != mpDefaultsPool.get() )
283
0
    {
284
        // use method <ResetUserDefaultItem(..)> instead of using probably incompatible item pool <mpDefaultsPool>.
285
0
        pPool->ResetUserDefaultItem( nWhich );
286
0
    }
287
0
}
288
289
uno::Any SvxUnoDrawPool::_getPropertyDefault( const comphelper::PropertyMapEntry* pEntry )
290
0
{
291
0
    SolarMutexGuard aGuard;
292
    //#i18732# - use method <GetUserDefaultItem(..)> instead of
293
    // using probably incompatible item pool <mpDefaultsPool>
294
0
    uno::Any aAny;
295
0
    SfxItemPool* pPool = getModelPool( true );
296
0
    const sal_uInt16 nWhich = pPool->GetWhichIDFromSlotID( static_cast<sal_uInt16>(pEntry->mnHandle) );
297
0
    const SfxPoolItem *pItem = pPool->GetUserDefaultItem ( nWhich );
298
0
    if (pItem)
299
0
    {
300
0
        pItem->QueryValue( aAny, pEntry->mnMemberId );
301
0
    }
302
303
0
    return aAny;
304
0
}
305
306
// XInterface
307
308
uno::Any SAL_CALL SvxUnoDrawPool::queryInterface( const uno::Type & rType )
309
6.79k
{
310
6.79k
    uno::Any aAny;
311
312
6.79k
    if( rType == cppu::UnoType<lang::XServiceInfo>::get())
313
0
        aAny <<= uno::Reference< lang::XServiceInfo >(this);
314
6.79k
    else if( rType == cppu::UnoType<lang::XTypeProvider>::get())
315
0
        aAny <<= uno::Reference< lang::XTypeProvider >(this);
316
6.79k
    else if( rType == cppu::UnoType<beans::XPropertySet>::get())
317
2.25k
        aAny <<= uno::Reference< beans::XPropertySet >(this);
318
4.54k
    else if( rType == cppu::UnoType<beans::XPropertyState>::get())
319
49
        aAny <<= uno::Reference< beans::XPropertyState >(this);
320
4.50k
    else if( rType == cppu::UnoType<beans::XMultiPropertySet>::get())
321
2.25k
        aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
322
2.25k
    else
323
2.25k
        aAny = OWeakObject::queryInterface( rType );
324
325
6.79k
    return aAny;
326
6.79k
}
327
328
uno::Sequence< uno::Type > SAL_CALL SvxUnoDrawPool::getTypes()
329
0
{
330
0
    static const uno::Sequence aTypes {
331
0
        cppu::UnoType<lang::XServiceInfo>::get(),
332
0
        cppu::UnoType<lang::XTypeProvider>::get(),
333
0
        cppu::UnoType<beans::XPropertySet>::get(),
334
0
        cppu::UnoType<beans::XPropertyState>::get(),
335
0
        cppu::UnoType<beans::XMultiPropertySet>::get() };
336
0
    return aTypes;
337
0
}
338
339
uno::Sequence< sal_Int8 > SAL_CALL SvxUnoDrawPool::getImplementationId()
340
0
{
341
0
    return css::uno::Sequence<sal_Int8>();
342
0
}
343
344
// XServiceInfo
345
sal_Bool SAL_CALL SvxUnoDrawPool::supportsService( const  OUString& ServiceName )
346
0
{
347
0
    return cppu::supportsService(this, ServiceName);
348
0
}
349
350
OUString SAL_CALL SvxUnoDrawPool::getImplementationName()
351
0
{
352
0
    return u"SvxUnoDrawPool"_ustr;
353
0
}
354
355
uno::Sequence< OUString > SAL_CALL SvxUnoDrawPool::getSupportedServiceNames(  )
356
0
{
357
0
    uno::Sequence<OUString> aSNS { u"com.sun.star.drawing.Defaults"_ustr };
358
0
    return aSNS;
359
0
}
360
361
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */