Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/comphelper/source/property/propstate.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 <comphelper/propstate.hxx>
21
#include <cppuhelper/queryinterface.hxx>
22
#include <comphelper/sequence.hxx>
23
24
namespace comphelper
25
{
26
27
28
    using ::com::sun::star::uno::Type;
29
    using ::com::sun::star::uno::Sequence;
30
    using ::com::sun::star::lang::XTypeProvider;
31
    using ::com::sun::star::uno::Any;
32
    using ::com::sun::star::uno::cpp_queryInterface;
33
    using ::com::sun::star::uno::cpp_release;
34
    using ::com::sun::star::beans::PropertyState_DEFAULT_VALUE;
35
    using ::com::sun::star::beans::PropertyState_DIRECT_VALUE;
36
37
38
    // OPropertyStateHelper
39
40
41
    css::uno::Any SAL_CALL OPropertyStateHelper::queryInterface(const  css::uno::Type& _rType)
42
0
    {
43
0
        css::uno::Any aReturn = OPropertySetHelper2::queryInterface(_rType);
44
        // our own ifaces
45
0
        if ( !aReturn.hasValue() )
46
0
            aReturn = ::cppu::queryInterface(_rType, static_cast< css::beans::XPropertyState*>(this));
47
48
0
        return aReturn;
49
0
    }
50
51
52
    css::uno::Sequence<css::uno::Type> OPropertyStateHelper::getTypes()
53
0
    {
54
0
        return {
55
0
            cppu::UnoType<css::beans::XPropertySet>::get(),
56
0
            cppu::UnoType<css::beans::XMultiPropertySet>::get(),
57
0
            cppu::UnoType<css::beans::XFastPropertySet>::get(),
58
0
            cppu::UnoType<css::beans::XPropertySetOption>::get(),
59
0
            cppu::UnoType<css::beans::XPropertyState>::get()};
60
0
    }
61
62
    OPropertyStateHelper::OPropertyStateHelper(
63
        ::cppu::OBroadcastHelper& rBHlp,
64
        ::cppu::IEventNotificationHook *i_pFireEvents)
65
10.9k
        :   ::cppu::OPropertySetHelper2(rBHlp, i_pFireEvents) { }
66
67
10.9k
    OPropertyStateHelper::~OPropertyStateHelper() {}
68
69
70
    void OPropertyStateHelper::firePropertyChange(sal_Int32 nHandle, const  css::uno::Any& aNewValue, const  css::uno::Any& aOldValue)
71
0
    {
72
0
        fire(&nHandle, &aNewValue, &aOldValue, 1, false);
73
0
    }
74
75
    // XPropertyState
76
77
    css::beans::PropertyState SAL_CALL OPropertyStateHelper::getPropertyState(const OUString& _rsName)
78
0
    {
79
0
        cppu::IPropertyArrayHelper& rPH = getInfoHelper();
80
0
        sal_Int32 nHandle = rPH.getHandleByName(_rsName);
81
82
0
        if (nHandle == -1)
83
0
            throw  css::beans::UnknownPropertyException(_rsName);
84
85
0
        return getPropertyStateByHandle(nHandle);
86
0
    }
87
88
89
    void SAL_CALL OPropertyStateHelper::setPropertyToDefault(const OUString& _rsName)
90
0
    {
91
0
        cppu::IPropertyArrayHelper& rPH = getInfoHelper();
92
0
        sal_Int32 nHandle = rPH.getHandleByName(_rsName);
93
94
0
        if (nHandle == -1)
95
0
            throw css::beans::UnknownPropertyException(_rsName);
96
97
0
        setPropertyToDefaultByHandle(nHandle);
98
0
    }
99
100
101
    css::uno::Any SAL_CALL OPropertyStateHelper::getPropertyDefault(const OUString& _rsName)
102
0
    {
103
0
        cppu::IPropertyArrayHelper& rPH = getInfoHelper();
104
0
        sal_Int32 nHandle = rPH.getHandleByName(_rsName);
105
106
0
        if (nHandle == -1)
107
0
            throw css::beans::UnknownPropertyException(_rsName);
108
109
0
        return getPropertyDefaultByHandle(nHandle);
110
0
    }
111
112
113
    css::uno::Sequence< css::beans::PropertyState> SAL_CALL OPropertyStateHelper::getPropertyStates(const  css::uno::Sequence< OUString >& _rPropertyNames)
114
0
    {
115
0
        sal_Int32 nLen = _rPropertyNames.getLength();
116
0
        css::uno::Sequence< css::beans::PropertyState> aRet(nLen);
117
0
        css::beans::PropertyState* pValues = aRet.getArray();
118
119
0
        cppu::IPropertyArrayHelper& rHelper = getInfoHelper();
120
121
0
        css::uno::Sequence< css::beans::Property> aProps = rHelper.getProperties();
122
0
        auto it = aProps.begin();
123
0
        const auto end = aProps.end();
124
125
0
        osl::MutexGuard aGuard(rBHelper.rMutex);
126
        // Assumption is that both _rPropertyNames and aProps are sorted
127
0
        for (auto& propName : _rPropertyNames)
128
0
        {
129
            // get the values only for valid properties
130
0
            it = std::find_if(it, end, [&propName](auto& prop) { return prop.Name == propName; });
131
0
            if (it == end)
132
0
                break;
133
0
            *pValues++ = getPropertyStateByHandle(it->Handle);
134
0
        }
135
136
0
        return aRet;
137
0
    }
138
139
140
    css::beans::PropertyState OPropertyStateHelper::getPropertyStateByHandle( sal_Int32 _nHandle )
141
0
    {
142
        // simply compare the current and the default value
143
0
        Any aCurrentValue = getPropertyDefaultByHandle( _nHandle );
144
0
        Any aDefaultValue;
145
0
        getFastPropertyValue( aDefaultValue, _nHandle );
146
147
0
        bool bEqual = uno_type_equalData(
148
0
                const_cast< void* >( aCurrentValue.getValue() ), aCurrentValue.getValueType().getTypeLibType(),
149
0
                const_cast< void* >( aDefaultValue.getValue() ), aDefaultValue.getValueType().getTypeLibType(),
150
0
                reinterpret_cast< uno_QueryInterfaceFunc >(cpp_queryInterface),
151
0
                reinterpret_cast< uno_ReleaseFunc >(cpp_release)
152
0
            );
153
0
        return bEqual ? PropertyState_DEFAULT_VALUE : PropertyState_DIRECT_VALUE;
154
0
    }
155
156
157
    void OPropertyStateHelper::setPropertyToDefaultByHandle( sal_Int32 _nHandle )
158
0
    {
159
0
        setFastPropertyValue( _nHandle, getPropertyDefaultByHandle( _nHandle ) );
160
0
    }
161
162
163
    css::uno::Any OPropertyStateHelper::getPropertyDefaultByHandle( sal_Int32 ) const
164
0
    {
165
0
        return css::uno::Any();
166
0
    }
167
168
169
    // OStatefulPropertySet
170
171
172
    OStatefulPropertySet::OStatefulPropertySet()
173
0
        :OPropertyStateHelper( GetBroadcastHelper() )
174
0
    {
175
0
    }
176
177
178
    OStatefulPropertySet::~OStatefulPropertySet()
179
0
    {
180
0
    }
181
182
183
    Sequence< Type > SAL_CALL OStatefulPropertySet::getTypes()
184
0
    {
185
0
        return concatSequences(
186
0
            Sequence {
187
0
                cppu::UnoType<XWeak>::get(),
188
0
                cppu::UnoType<XTypeProvider>::get() },
189
0
            OPropertyStateHelper::getTypes()
190
0
        );
191
0
    }
192
193
    Sequence< sal_Int8 > SAL_CALL OStatefulPropertySet::getImplementationId()
194
0
    {
195
0
        return css::uno::Sequence<sal_Int8>();
196
0
    }
197
198
199
    Any SAL_CALL OStatefulPropertySet::queryInterface( const Type& _rType )
200
0
    {
201
0
        Any aReturn = OWeakObject::queryInterface( _rType );
202
0
        if ( !aReturn.hasValue() )
203
0
            aReturn = ::cppu::queryInterface( _rType, static_cast< XTypeProvider* >( this ) );
204
0
        if ( !aReturn.hasValue() )
205
0
            aReturn = OPropertyStateHelper::queryInterface( _rType );
206
0
        return aReturn;
207
0
    }
208
209
210
    void SAL_CALL OStatefulPropertySet::acquire() noexcept
211
0
    {
212
0
        ::cppu::OWeakObject::acquire();
213
0
    }
214
215
216
    void SAL_CALL OStatefulPropertySet::release() noexcept
217
0
    {
218
0
        ::cppu::OWeakObject::release();
219
0
    }
220
221
222
}
223
224
225
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */