Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/model/main/Legend.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 <Legend.hxx>
21
#include <LinePropertiesHelper.hxx>
22
#include <FillProperties.hxx>
23
#include <CharacterProperties.hxx>
24
#include <UserDefinedProperties.hxx>
25
#include <ModifyListenerHelper.hxx>
26
#include <PropertyHelper.hxx>
27
#include <com/sun/star/beans/PropertyAttribute.hpp>
28
#include <com/sun/star/awt/Size.hpp>
29
#include <com/sun/star/chart2/LegendPosition.hpp>
30
#include <com/sun/star/chart/ChartLegendExpansion.hpp>
31
#include <com/sun/star/chart2/RelativePosition.hpp>
32
#include <com/sun/star/chart2/RelativeSize.hpp>
33
#include <cppuhelper/supportsservice.hxx>
34
35
#include <algorithm>
36
37
namespace com::sun::star::uno { class XComponentContext; }
38
39
using namespace ::com::sun::star;
40
using namespace ::com::sun::star::beans::PropertyAttribute;
41
42
using ::com::sun::star::uno::Sequence;
43
using ::com::sun::star::uno::Reference;
44
using ::com::sun::star::uno::Any;
45
using ::com::sun::star::beans::Property;
46
47
namespace
48
{
49
50
enum
51
{
52
    PROP_LEGEND_ANCHOR_POSITION,
53
    PROP_LEGEND_EXPANSION,
54
    PROP_LEGEND_SHOW,
55
    PROP_LEGEND_OVERLAY,
56
    PROP_LEGEND_REF_PAGE_SIZE,
57
    PROP_LEGEND_REL_POS,
58
    PROP_LEGEND_REL_SIZE,
59
    PROP_LEGEND_HAS_EXPLICIT_SPPR
60
};
61
62
void lcl_AddPropertiesToVector(
63
    std::vector< Property > & rOutProperties )
64
0
{
65
0
    rOutProperties.emplace_back( "AnchorPosition",
66
0
                  PROP_LEGEND_ANCHOR_POSITION,
67
0
                  cppu::UnoType<chart2::LegendPosition>::get(),
68
0
                  beans::PropertyAttribute::BOUND
69
0
                  | beans::PropertyAttribute::MAYBEDEFAULT );
70
71
0
    rOutProperties.emplace_back( "Expansion",
72
0
                  PROP_LEGEND_EXPANSION,
73
0
                  cppu::UnoType<css::chart::ChartLegendExpansion>::get(),
74
0
                  beans::PropertyAttribute::BOUND
75
0
                  | beans::PropertyAttribute::MAYBEDEFAULT );
76
77
0
    rOutProperties.emplace_back( "Show",
78
0
                  PROP_LEGEND_SHOW,
79
0
                  cppu::UnoType<bool>::get(),
80
0
                  beans::PropertyAttribute::BOUND
81
0
                  | beans::PropertyAttribute::MAYBEDEFAULT );
82
83
0
    rOutProperties.emplace_back( "Overlay",
84
0
                  PROP_LEGEND_OVERLAY,
85
0
                  cppu::UnoType<bool>::get(),
86
0
                  beans::PropertyAttribute::BOUND
87
0
                  | beans::PropertyAttribute::MAYBEDEFAULT );
88
89
0
    rOutProperties.emplace_back( "ReferencePageSize",
90
0
                  PROP_LEGEND_REF_PAGE_SIZE,
91
0
                  cppu::UnoType<awt::Size>::get(),
92
0
                  beans::PropertyAttribute::BOUND
93
0
                  | beans::PropertyAttribute::MAYBEVOID );
94
95
0
    rOutProperties.emplace_back( "RelativePosition",
96
0
                  PROP_LEGEND_REL_POS,
97
0
                  cppu::UnoType<chart2::RelativePosition>::get(),
98
0
                  beans::PropertyAttribute::BOUND
99
0
                  | beans::PropertyAttribute::MAYBEVOID );
100
101
0
    rOutProperties.emplace_back( "RelativeSize",
102
0
                  PROP_LEGEND_REL_SIZE,
103
0
                  cppu::UnoType<chart2::RelativeSize>::get(),
104
0
                  beans::PropertyAttribute::BOUND
105
0
                  | beans::PropertyAttribute::MAYBEVOID );
106
107
0
    rOutProperties.emplace_back( "HasExplicitSpPr",
108
0
                  PROP_LEGEND_HAS_EXPLICIT_SPPR,
109
0
                  cppu::UnoType<bool>::get(),
110
0
                  beans::PropertyAttribute::BOUND
111
0
                  | beans::PropertyAttribute::MAYBEVOID );
112
0
}
113
114
} // namespace
115
116
namespace chart
117
{
118
const ::chart::tPropertyValueMap& StaticLegendDefaults()
119
0
{
120
0
    static ::chart::tPropertyValueMap aStaticDefaults = []()
121
0
        {
122
0
            ::chart::tPropertyValueMap aTmp;
123
0
            ::chart::LinePropertiesHelper::AddDefaultsToMap( aTmp );
124
0
            ::chart::FillProperties::AddDefaultsToMap( aTmp );
125
0
            ::chart::CharacterProperties::AddDefaultsToMap( aTmp );
126
127
0
            ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_LEGEND_ANCHOR_POSITION, chart2::LegendPosition_LINE_END );
128
0
            ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_LEGEND_EXPANSION, css::chart::ChartLegendExpansion_HIGH );
129
0
            ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_LEGEND_SHOW, true );
130
0
            ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_LEGEND_OVERLAY, false );
131
132
0
            float fDefaultCharHeight = 10.0;
133
0
            ::chart::PropertyHelper::setPropertyValue( aTmp, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight );
134
0
            ::chart::PropertyHelper::setPropertyValue( aTmp, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight );
135
0
            ::chart::PropertyHelper::setPropertyValue( aTmp, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight );
136
0
            return aTmp;
137
0
        }();
138
0
    return aStaticDefaults;
139
0
}
140
} // namespace chart
141
142
namespace
143
{
144
::cppu::OPropertyArrayHelper& StaticLegendInfoHelper()
145
0
{
146
0
    static ::cppu::OPropertyArrayHelper aPropHelper = []()
147
0
        {
148
0
            std::vector< css::beans::Property > aProperties;
149
0
            lcl_AddPropertiesToVector( aProperties );
150
0
            ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
151
0
            ::chart::FillProperties::AddPropertiesToVector( aProperties );
152
0
            ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
153
0
            ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
154
155
0
            std::sort( aProperties.begin(), aProperties.end(),
156
0
                         ::chart::PropertyNameLess() );
157
158
0
            return comphelper::containerToSequence( aProperties );
159
0
        }();
160
0
    return aPropHelper;
161
0
}
162
163
} // anonymous namespace
164
165
namespace chart
166
{
167
168
Legend::Legend() :
169
0
        m_xModifyEventForwarder( new ModifyEventForwarder() )
170
0
{
171
0
}
172
173
Legend::Legend( const Legend & rOther ) :
174
0
        impl::Legend_Base(rOther),
175
0
        ::property::OPropertySet( rOther ),
176
0
    m_xModifyEventForwarder( new ModifyEventForwarder() )
177
0
{
178
0
}
179
180
Legend::~Legend()
181
0
{
182
0
}
183
184
// ____ XCloneable ____
185
Reference< util::XCloneable > SAL_CALL Legend::createClone()
186
0
{
187
0
    return Reference< util::XCloneable >( new Legend( *this ));
188
0
}
189
190
// ____ XModifyBroadcaster ____
191
void SAL_CALL Legend::addModifyListener( const Reference< util::XModifyListener >& aListener )
192
0
{
193
0
    m_xModifyEventForwarder->addModifyListener( aListener );
194
0
}
195
196
void SAL_CALL Legend::removeModifyListener( const Reference< util::XModifyListener >& aListener )
197
0
{
198
0
    m_xModifyEventForwarder->removeModifyListener( aListener );
199
0
}
200
201
// ____ XModifyListener ____
202
void SAL_CALL Legend::modified( const lang::EventObject& aEvent )
203
0
{
204
0
    m_xModifyEventForwarder->modified( aEvent );
205
0
}
206
207
// ____ XEventListener (base of XModifyListener) ____
208
void SAL_CALL Legend::disposing( const lang::EventObject& /* Source */ )
209
0
{
210
    // nothing
211
0
}
212
213
// ____ OPropertySet ____
214
void Legend::firePropertyChangeEvent()
215
0
{
216
0
    m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
217
0
}
218
219
// ____ OPropertySet ____
220
void Legend::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
221
0
{
222
0
    const tPropertyValueMap& rStaticDefaults = StaticLegendDefaults();
223
0
    tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
224
0
    if( aFound == rStaticDefaults.end() )
225
0
        rAny.clear();
226
0
    else
227
0
        rAny = (*aFound).second;
228
0
}
229
230
::cppu::IPropertyArrayHelper & SAL_CALL Legend::getInfoHelper()
231
0
{
232
0
    return StaticLegendInfoHelper();
233
0
}
234
235
// ____ XPropertySet ____
236
Reference< beans::XPropertySetInfo > SAL_CALL Legend::getPropertySetInfo()
237
0
{
238
0
    static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
239
0
        ::cppu::OPropertySetHelper::createPropertySetInfo(StaticLegendInfoHelper() ) );
240
0
    return xPropertySetInfo;
241
0
}
242
243
// implement XServiceInfo methods basing upon getSupportedServiceNames_Static
244
OUString SAL_CALL Legend::getImplementationName()
245
0
{
246
0
    return u"com.sun.star.comp.chart2.Legend"_ustr;
247
0
}
248
249
sal_Bool SAL_CALL Legend::supportsService( const OUString& rServiceName )
250
0
{
251
0
    return cppu::supportsService(this, rServiceName);
252
0
}
253
254
css::uno::Sequence< OUString > SAL_CALL Legend::getSupportedServiceNames()
255
0
{
256
0
    return {
257
0
        u"com.sun.star.chart2.Legend"_ustr,
258
0
        u"com.sun.star.beans.PropertySet"_ustr,
259
0
        u"com.sun.star.drawing.FillProperties"_ustr,
260
0
        u"com.sun.star.drawing.LineProperties"_ustr,
261
0
        u"com.sun.star.style.CharacterProperties"_ustr,
262
0
        u"com.sun.star.layout.LayoutElement"_ustr
263
0
    };
264
0
}
265
266
// needed by MSC compiler
267
using impl::Legend_Base;
268
269
IMPLEMENT_FORWARD_XINTERFACE2( Legend, Legend_Base, ::property::OPropertySet )
270
IMPLEMENT_FORWARD_XTYPEPROVIDER2( Legend, Legend_Base, ::property::OPropertySet )
271
272
} //  namespace chart
273
274
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
275
com_sun_star_comp_chart2_Legend_get_implementation(css::uno::XComponentContext *,
276
        css::uno::Sequence<css::uno::Any> const &)
277
0
{
278
0
    return cppu::acquire(new ::chart::Legend);
279
0
}
280
281
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */