tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / model / main / Legend.cxx
blob5f6ee67ccaa0efb2f4b3b914bb5a133b261f483c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
35 #include <algorithm>
37 namespace com::sun::star::uno { class XComponentContext; }
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::beans::PropertyAttribute;
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;
47 namespace
50 enum
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
61 void lcl_AddPropertiesToVector(
62 std::vector< Property > & rOutProperties )
64 rOutProperties.emplace_back( "AnchorPosition",
65 PROP_LEGEND_ANCHOR_POSITION,
66 cppu::UnoType<chart2::LegendPosition>::get(),
67 beans::PropertyAttribute::BOUND
68 | beans::PropertyAttribute::MAYBEDEFAULT );
70 rOutProperties.emplace_back( "Expansion",
71 PROP_LEGEND_EXPANSION,
72 cppu::UnoType<css::chart::ChartLegendExpansion>::get(),
73 beans::PropertyAttribute::BOUND
74 | beans::PropertyAttribute::MAYBEDEFAULT );
76 rOutProperties.emplace_back( "Show",
77 PROP_LEGEND_SHOW,
78 cppu::UnoType<bool>::get(),
79 beans::PropertyAttribute::BOUND
80 | beans::PropertyAttribute::MAYBEDEFAULT );
82 rOutProperties.emplace_back( "Overlay",
83 PROP_LEGEND_OVERLAY,
84 cppu::UnoType<bool>::get(),
85 beans::PropertyAttribute::BOUND
86 | beans::PropertyAttribute::MAYBEDEFAULT );
88 rOutProperties.emplace_back( "ReferencePageSize",
89 PROP_LEGEND_REF_PAGE_SIZE,
90 cppu::UnoType<awt::Size>::get(),
91 beans::PropertyAttribute::BOUND
92 | beans::PropertyAttribute::MAYBEVOID );
94 rOutProperties.emplace_back( "RelativePosition",
95 PROP_LEGEND_REL_POS,
96 cppu::UnoType<chart2::RelativePosition>::get(),
97 beans::PropertyAttribute::BOUND
98 | beans::PropertyAttribute::MAYBEVOID );
100 rOutProperties.emplace_back( "RelativeSize",
101 PROP_LEGEND_REL_SIZE,
102 cppu::UnoType<chart2::RelativeSize>::get(),
103 beans::PropertyAttribute::BOUND
104 | beans::PropertyAttribute::MAYBEVOID );
108 } // namespace
110 namespace chart
112 const ::chart::tPropertyValueMap& StaticLegendDefaults()
114 static ::chart::tPropertyValueMap aStaticDefaults = []()
116 ::chart::tPropertyValueMap aTmp;
117 ::chart::LinePropertiesHelper::AddDefaultsToMap( aTmp );
118 ::chart::FillProperties::AddDefaultsToMap( aTmp );
119 ::chart::CharacterProperties::AddDefaultsToMap( aTmp );
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 );
126 float fDefaultCharHeight = 10.0;
127 ::chart::PropertyHelper::setPropertyValue( aTmp, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight );
128 ::chart::PropertyHelper::setPropertyValue( aTmp, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight );
129 ::chart::PropertyHelper::setPropertyValue( aTmp, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight );
130 return aTmp;
131 }();
132 return aStaticDefaults;
134 } // namespace chart
136 namespace
138 ::cppu::OPropertyArrayHelper& StaticLegendInfoHelper()
140 static ::cppu::OPropertyArrayHelper aPropHelper = []()
142 std::vector< css::beans::Property > aProperties;
143 lcl_AddPropertiesToVector( aProperties );
144 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
145 ::chart::FillProperties::AddPropertiesToVector( aProperties );
146 ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
147 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
149 std::sort( aProperties.begin(), aProperties.end(),
150 ::chart::PropertyNameLess() );
152 return comphelper::containerToSequence( aProperties );
153 }();
154 return aPropHelper;
157 } // anonymous namespace
159 namespace chart
162 Legend::Legend() :
163 m_xModifyEventForwarder( new ModifyEventForwarder() )
167 Legend::Legend( const Legend & rOther ) :
168 impl::Legend_Base(rOther),
169 ::property::OPropertySet( rOther ),
170 m_xModifyEventForwarder( new ModifyEventForwarder() )
174 Legend::~Legend()
178 // ____ XCloneable ____
179 Reference< util::XCloneable > SAL_CALL Legend::createClone()
181 return Reference< util::XCloneable >( new Legend( *this ));
184 // ____ XModifyBroadcaster ____
185 void SAL_CALL Legend::addModifyListener( const Reference< util::XModifyListener >& aListener )
187 m_xModifyEventForwarder->addModifyListener( aListener );
190 void SAL_CALL Legend::removeModifyListener( const Reference< util::XModifyListener >& aListener )
192 m_xModifyEventForwarder->removeModifyListener( aListener );
195 // ____ XModifyListener ____
196 void SAL_CALL Legend::modified( const lang::EventObject& aEvent )
198 m_xModifyEventForwarder->modified( aEvent );
201 // ____ XEventListener (base of XModifyListener) ____
202 void SAL_CALL Legend::disposing( const lang::EventObject& /* Source */ )
204 // nothing
207 // ____ OPropertySet ____
208 void Legend::firePropertyChangeEvent()
210 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
213 // ____ OPropertySet ____
214 void Legend::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
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;
224 ::cppu::IPropertyArrayHelper & SAL_CALL Legend::getInfoHelper()
226 return StaticLegendInfoHelper();
229 // ____ XPropertySet ____
230 Reference< beans::XPropertySetInfo > SAL_CALL Legend::getPropertySetInfo()
232 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
233 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticLegendInfoHelper() ) );
234 return xPropertySetInfo;
237 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
238 OUString SAL_CALL Legend::getImplementationName()
240 return u"com.sun.star.comp.chart2.Legend"_ustr;
243 sal_Bool SAL_CALL Legend::supportsService( const OUString& rServiceName )
245 return cppu::supportsService(this, rServiceName);
248 css::uno::Sequence< OUString > SAL_CALL Legend::getSupportedServiceNames()
250 return {
251 u"com.sun.star.chart2.Legend"_ustr,
252 u"com.sun.star.beans.PropertySet"_ustr,
253 u"com.sun.star.drawing.FillProperties"_ustr,
254 u"com.sun.star.drawing.LineProperties"_ustr,
255 u"com.sun.star.style.CharacterProperties"_ustr,
256 u"com.sun.star.layout.LayoutElement"_ustr
260 // needed by MSC compiler
261 using impl::Legend_Base;
263 IMPLEMENT_FORWARD_XINTERFACE2( Legend, Legend_Base, ::property::OPropertySet )
264 IMPLEMENT_FORWARD_XTYPEPROVIDER2( Legend, Legend_Base, ::property::OPropertySet )
266 } // namespace chart
268 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
269 com_sun_star_comp_chart2_Legend_get_implementation(css::uno::XComponentContext *,
270 css::uno::Sequence<css::uno::Any> const &)
272 return cppu::acquire(new ::chart::Legend);
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */