Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/canvas/source/tools/propertysethelper.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 <sal/config.h>
21
22
#include <string_view>
23
24
#include <propertysethelper.hxx>
25
#include <com/sun/star/beans/PropertyVetoException.hpp>
26
#include <com/sun/star/beans/UnknownPropertyException.hpp>
27
28
using namespace ::com::sun::star;
29
30
namespace canvas
31
{
32
    namespace
33
    {
34
        void throwUnknown( std::u16string_view aPropertyName )
35
0
        {
36
0
            throw beans::UnknownPropertyException(
37
0
                OUString::Concat("PropertySetHelper: property ") +
38
0
                aPropertyName + " not found."
39
0
                );
40
0
        }
41
42
        void throwVeto( std::u16string_view aPropertyName )
43
0
        {
44
0
            throw beans::PropertyVetoException(
45
0
                OUString::Concat("PropertySetHelper: property ") +
46
0
                aPropertyName + " access was vetoed." );
47
0
        }
48
49
        struct EntryComparator
50
        {
51
            bool operator()( const PropertySetHelper::MapType::MapEntry& rLHS,
52
                             const PropertySetHelper::MapType::MapEntry& rRHS )
53
0
            {
54
0
                return strcmp( rLHS.maKey,
55
0
                               rRHS.maKey ) < 0;
56
0
            }
57
        };
58
    }
59
60
    PropertySetHelper::PropertySetHelper()
61
0
    {
62
0
    }
63
64
    void PropertySetHelper::initProperties( InputMap&& rMap )
65
0
    {
66
0
        mpMap.reset();
67
0
        maMapEntries = std::move(rMap);
68
69
0
        std::sort( maMapEntries.begin(),
70
0
                   maMapEntries.end(),
71
0
                   EntryComparator() );
72
73
0
        if( !maMapEntries.empty() )
74
0
            mpMap.reset( new MapType(maMapEntries.data(),
75
0
                                     maMapEntries.size(),
76
0
                                     true) );
77
0
    }
78
79
    void PropertySetHelper::addProperties( const InputMap& rMap )
80
0
    {
81
0
        InputMap aMerged( maMapEntries );
82
0
        aMerged.insert( aMerged.end(),
83
0
                        rMap.begin(),
84
0
                        rMap.end() );
85
86
0
        initProperties( std::move(aMerged) );
87
0
    }
88
89
    bool PropertySetHelper::isPropertyName( const OUString& aPropertyName ) const
90
0
    {
91
0
        if (!mpMap)
92
0
            return false;
93
94
0
        Callbacks aDummy;
95
0
        return mpMap->lookup( aPropertyName,
96
0
                              aDummy );
97
0
    }
98
99
    uno::Reference< beans::XPropertySetInfo > PropertySetHelper::getPropertySetInfo() const
100
0
    {
101
        // we're a stealth property set
102
0
        return uno::Reference< beans::XPropertySetInfo >();
103
0
    }
104
105
    void PropertySetHelper::setPropertyValue( const OUString& aPropertyName,
106
                                              const uno::Any&        aValue )
107
0
    {
108
0
        Callbacks aCallbacks;
109
0
        if (!mpMap || !mpMap->lookup(aPropertyName, aCallbacks))
110
0
        {
111
0
            throwUnknown( aPropertyName );
112
0
        }
113
114
0
        if (!aCallbacks.setter)
115
0
            throwVeto( aPropertyName );
116
117
0
        aCallbacks.setter(aValue);
118
0
    }
119
120
    uno::Any PropertySetHelper::getPropertyValue( const OUString& aPropertyName ) const
121
0
    {
122
0
        Callbacks aCallbacks;
123
0
        if (!mpMap || !mpMap->lookup(aPropertyName, aCallbacks))
124
0
        {
125
0
            throwUnknown( aPropertyName );
126
0
        }
127
128
0
        if (aCallbacks.getter)
129
0
            return aCallbacks.getter();
130
131
        // TODO(Q1): subtlety, empty getter method silently returns
132
        // the empty any
133
0
        return uno::Any();
134
0
    }
135
136
    void PropertySetHelper::addPropertyChangeListener( const OUString&                                  aPropertyName,
137
                                                       const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
138
0
    {
139
        // check validity of property, but otherwise ignore the
140
        // request
141
0
        if( !isPropertyName( aPropertyName ) )
142
0
            throwUnknown( aPropertyName );
143
0
    }
144
145
    void PropertySetHelper::addVetoableChangeListener( const OUString&                                  aPropertyName,
146
                                                       const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/ )
147
0
    {
148
        // check validity of property, but otherwise ignore the
149
        // request
150
0
        if( !isPropertyName( aPropertyName ) )
151
0
            throwUnknown( aPropertyName );
152
0
    }
153
154
}
155
156
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */