LibreOffice Module chart2 (master) 1
Legend.cxx
Go to the documentation of this file.
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>
22#include <FillProperties.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>
34
35#include <algorithm>
36
37namespace com::sun::star::uno { class XComponentContext; }
38
39using namespace ::com::sun::star;
40using namespace ::com::sun::star::beans::PropertyAttribute;
41
42using ::com::sun::star::uno::Sequence;
43using ::com::sun::star::uno::Reference;
44using ::com::sun::star::uno::Any;
45using ::com::sun::star::beans::Property;
46
47namespace
48{
49
50enum
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};
60
61void lcl_AddPropertiesToVector(
62 std::vector< Property > & rOutProperties )
63{
64 rOutProperties.emplace_back( "AnchorPosition",
65 PROP_LEGEND_ANCHOR_POSITION,
67 beans::PropertyAttribute::BOUND
68 | beans::PropertyAttribute::MAYBEDEFAULT );
69
70 rOutProperties.emplace_back( "Expansion",
71 PROP_LEGEND_EXPANSION,
73 beans::PropertyAttribute::BOUND
74 | beans::PropertyAttribute::MAYBEDEFAULT );
75
76 rOutProperties.emplace_back( "Show",
77 PROP_LEGEND_SHOW,
79 beans::PropertyAttribute::BOUND
80 | beans::PropertyAttribute::MAYBEDEFAULT );
81
82 rOutProperties.emplace_back( "Overlay",
83 PROP_LEGEND_OVERLAY,
85 beans::PropertyAttribute::BOUND
86 | beans::PropertyAttribute::MAYBEDEFAULT );
87
88 rOutProperties.emplace_back( "ReferencePageSize",
89 PROP_LEGEND_REF_PAGE_SIZE,
91 beans::PropertyAttribute::BOUND
92 | beans::PropertyAttribute::MAYBEVOID );
93
94 rOutProperties.emplace_back( "RelativePosition",
95 PROP_LEGEND_REL_POS,
97 beans::PropertyAttribute::BOUND
98 | beans::PropertyAttribute::MAYBEVOID );
99
100 rOutProperties.emplace_back( "RelativeSize",
101 PROP_LEGEND_REL_SIZE,
103 beans::PropertyAttribute::BOUND
104 | beans::PropertyAttribute::MAYBEVOID );
105
106}
107
108} // namespace
109
110namespace chart
111{
113{
114 static ::chart::tPropertyValueMap aStaticDefaults = []()
115 {
120
121 ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_LEGEND_ANCHOR_POSITION, chart2::LegendPosition_LINE_END );
122 ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_LEGEND_EXPANSION, css::chart::ChartLegendExpansion_HIGH );
123 ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_LEGEND_SHOW, true );
124 ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_LEGEND_OVERLAY, false );
125
126 float fDefaultCharHeight = 10.0;
130 return aTmp;
131 }();
132 return aStaticDefaults;
133};
134} // namespace chart
135
136namespace
137{
138::cppu::OPropertyArrayHelper& StaticLegendInfoHelper()
139{
140 static ::cppu::OPropertyArrayHelper aPropHelper = []()
141 {
142 std::vector< css::beans::Property > aProperties;
143 lcl_AddPropertiesToVector( aProperties );
148
149 std::sort( aProperties.begin(), aProperties.end(),
151
152 return comphelper::containerToSequence( aProperties );
153 }();
154 return aPropHelper;
155};
156
157} // anonymous namespace
158
159namespace chart
160{
161
163 m_xModifyEventForwarder( new ModifyEventForwarder() )
164{
165}
166
167Legend::Legend( const Legend & rOther ) :
168 impl::Legend_Base(rOther),
169 ::property::OPropertySet( rOther ),
170 m_xModifyEventForwarder( new ModifyEventForwarder() )
171{
172}
173
175{
176}
177
178// ____ XCloneable ____
180{
181 return Reference< util::XCloneable >( new Legend( *this ));
182}
183
184// ____ XModifyBroadcaster ____
186{
187 m_xModifyEventForwarder->addModifyListener( aListener );
188}
189
191{
192 m_xModifyEventForwarder->removeModifyListener( aListener );
193}
194
195// ____ XModifyListener ____
196void SAL_CALL Legend::modified( const lang::EventObject& aEvent )
197{
198 m_xModifyEventForwarder->modified( aEvent );
199}
200
201// ____ XEventListener (base of XModifyListener) ____
202void SAL_CALL Legend::disposing( const lang::EventObject& /* Source */ )
203{
204 // nothing
205}
206
207// ____ OPropertySet ____
209{
210 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
211}
212
213// ____ OPropertySet ____
214void Legend::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
215{
216 const tPropertyValueMap& rStaticDefaults = StaticLegendDefaults();
217 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
218 if( aFound == rStaticDefaults.end() )
219 rAny.clear();
220 else
221 rAny = (*aFound).second;
222}
223
225{
226 return StaticLegendInfoHelper();
227}
228
229// ____ XPropertySet ____
231{
232 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
233 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticLegendInfoHelper() ) );
234 return xPropertySetInfo;
235}
236
237// implement XServiceInfo methods basing upon getSupportedServiceNames_Static
239{
240 return "com.sun.star.comp.chart2.Legend";
241}
242
243sal_Bool SAL_CALL Legend::supportsService( const OUString& rServiceName )
244{
245 return cppu::supportsService(this, rServiceName);
246}
247
248css::uno::Sequence< OUString > SAL_CALL Legend::getSupportedServiceNames()
249{
250 return {
251 "com.sun.star.chart2.Legend",
252 "com.sun.star.beans.PropertySet",
253 "com.sun.star.drawing.FillProperties",
254 "com.sun.star.drawing.LineProperties",
255 "com.sun.star.style.CharacterProperties",
256 "com.sun.star.layout.LayoutElement"
257 };
258}
259
260// needed by MSC compiler
262
265
266} // namespace chart
267
268extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
270 css::uno::Sequence<css::uno::Any> const &)
271{
272 return cppu::acquire(new ::chart::Legend);
273}
274
275/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart2_Legend_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Definition: Legend.cxx:269
PropertiesInfo aProperties
AnyEventRef aEvent
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: Legend.cxx:185
virtual void firePropertyChangeEvent() override
implement this method in derived classes to get called when properties change.
Definition: Legend.cxx:208
virtual void SAL_CALL modified(const css::lang::EventObject &aEvent) override
Definition: Legend.cxx:196
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
Definition: Legend.cxx:179
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: Legend.cxx:243
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: Legend.cxx:230
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: Legend.cxx:190
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
The InfoHelper table contains all property names and types of this object.
Definition: Legend.cxx:224
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: Legend.cxx:248
rtl::Reference< ModifyEventForwarder > m_xModifyEventForwarder
Definition: Legend.hxx:99
virtual void GetDefaultValue(sal_Int32 nHandle, css::uno::Any &rAny) const override
implement this method to provide default values for all properties supporting defaults.
Definition: Legend.cxx:214
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo declarations.
Definition: Legend.cxx:238
virtual ~Legend() override
Definition: Legend.cxx:174
This helper class serves as forwarder of modify events.
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
void SAL_CALL disposing()
OOO_DLLPUBLIC_CHARTTOOLS void AddDefaultsToMap(::chart::tPropertyValueMap &rOutMap)
OOO_DLLPUBLIC_CHARTTOOLS void AddPropertiesToVector(std::vector< css::beans::Property > &rOutProperties)
void setPropertyValueDefault(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Calls setPropertyValue() but asserts that the given property hasn't been set before.
void setPropertyValue(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Set a property to a certain value in the given map.
::cppu::WeakImplHelper< css::chart2::XLegend, css::lang::XServiceInfo, css::util::XCloneable, css::util::XModifyBroadcaster, css::util::XModifyListener > Legend_Base
Definition: Legend.hxx:42
std::unordered_map< tPropertyValueMapKey, css::uno::Any > tPropertyValueMap
OOO_DLLPUBLIC_CHARTTOOLSconst ::chart::tPropertyValueMap & StaticLegendDefaults()
Definition: Legend.cxx:112
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
sal_Int32 nHandle
unsigned char sal_Bool