bump product version to 4.1.6.2
[LibreOffice.git] / chart2 / source / model / main / Legend.cxx
blob21d9e5c4a2440035e9e1987eac6baa3311e49091
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 "macros.hxx"
22 #include "LinePropertiesHelper.hxx"
23 #include "FillProperties.hxx"
24 #include "CharacterProperties.hxx"
25 #include "UserDefinedProperties.hxx"
26 #include "LegendHelper.hxx"
27 #include "ContainerHelper.hxx"
28 #include "CloneHelper.hxx"
29 #include "PropertyHelper.hxx"
30 #include <com/sun/star/beans/PropertyAttribute.hpp>
31 #include <com/sun/star/awt/Size.hpp>
32 #include <com/sun/star/chart2/LegendPosition.hpp>
33 #include <com/sun/star/chart/ChartLegendExpansion.hpp>
34 #include <com/sun/star/chart2/RelativePosition.hpp>
35 #include <com/sun/star/chart2/RelativeSize.hpp>
37 #include <algorithm>
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 static const OUString lcl_aServiceName( "com.sun.star.comp.chart2.Legend" );
52 enum
54 PROP_LEGEND_ANCHOR_POSITION,
55 PROP_LEGEND_EXPANSION,
56 PROP_LEGEND_SHOW,
57 PROP_LEGEND_REF_PAGE_SIZE,
58 PROP_LEGEND_REL_POS,
59 PROP_LEGEND_REL_SIZE
62 void lcl_AddPropertiesToVector(
63 ::std::vector< Property > & rOutProperties )
65 rOutProperties.push_back(
66 Property( "AnchorPosition",
67 PROP_LEGEND_ANCHOR_POSITION,
68 ::getCppuType( reinterpret_cast< const chart2::LegendPosition * >(0)),
69 beans::PropertyAttribute::BOUND
70 | beans::PropertyAttribute::MAYBEDEFAULT ));
72 rOutProperties.push_back(
73 Property( "Expansion",
74 PROP_LEGEND_EXPANSION,
75 ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartLegendExpansion * >(0)),
76 beans::PropertyAttribute::BOUND
77 | beans::PropertyAttribute::MAYBEDEFAULT ));
79 rOutProperties.push_back(
80 Property( "Show",
81 PROP_LEGEND_SHOW,
82 ::getBooleanCppuType(),
83 beans::PropertyAttribute::BOUND
84 | beans::PropertyAttribute::MAYBEDEFAULT ));
85 rOutProperties.push_back(
86 Property( "ReferencePageSize",
87 PROP_LEGEND_REF_PAGE_SIZE,
88 ::getCppuType( reinterpret_cast< const awt::Size * >(0)),
89 beans::PropertyAttribute::BOUND
90 | beans::PropertyAttribute::MAYBEVOID ));
92 rOutProperties.push_back(
93 Property( "RelativePosition",
94 PROP_LEGEND_REL_POS,
95 ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)),
96 beans::PropertyAttribute::BOUND
97 | beans::PropertyAttribute::MAYBEVOID ));
99 rOutProperties.push_back(
100 Property( "RelativeSize",
101 PROP_LEGEND_REL_SIZE,
102 ::getCppuType( reinterpret_cast< const chart2::RelativeSize * >(0)),
103 beans::PropertyAttribute::BOUND
104 | beans::PropertyAttribute::MAYBEVOID ));
108 struct StaticLegendDefaults_Initializer
110 ::chart::tPropertyValueMap* operator()()
112 static ::chart::tPropertyValueMap aStaticDefaults;
113 lcl_AddDefaultsToMap( aStaticDefaults );
114 return &aStaticDefaults;
116 private:
117 void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
119 ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap );
120 ::chart::FillProperties::AddDefaultsToMap( rOutMap );
121 ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
123 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_ANCHOR_POSITION, chart2::LegendPosition_LINE_END );
124 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_EXPANSION, ::com::sun::star::chart::ChartLegendExpansion_HIGH );
125 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_SHOW, true );
127 float fDefaultCharHeight = 10.0;
128 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight );
129 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight );
130 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight );
134 struct StaticLegendDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticLegendDefaults_Initializer >
138 struct StaticLegendInfoHelper_Initializer
140 ::cppu::OPropertyArrayHelper* operator()()
142 static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
143 return &aPropHelper;
146 private:
147 Sequence< Property > lcl_GetPropertySequence()
149 ::std::vector< ::com::sun::star::beans::Property > aProperties;
150 lcl_AddPropertiesToVector( aProperties );
151 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
152 ::chart::FillProperties::AddPropertiesToVector( aProperties );
153 ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
154 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
156 ::std::sort( aProperties.begin(), aProperties.end(),
157 ::chart::PropertyNameLess() );
159 return ::chart::ContainerHelper::ContainerToSequence( aProperties );
163 struct StaticLegendInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticLegendInfoHelper_Initializer >
167 struct StaticLegendInfo_Initializer
169 uno::Reference< beans::XPropertySetInfo >* operator()()
171 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
172 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticLegendInfoHelper::get() ) );
173 return &xPropertySetInfo;
177 struct StaticLegendInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticLegendInfo_Initializer >
181 } // anonymous namespace
183 namespace chart
186 Legend::Legend( Reference< uno::XComponentContext > const & /* xContext */ ) :
187 ::property::OPropertySet( m_aMutex ),
188 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
192 Legend::Legend( const Legend & rOther ) :
193 MutexContainer(),
194 impl::Legend_Base(),
195 ::property::OPropertySet( rOther, m_aMutex ),
196 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
200 Legend::~Legend()
204 // ____ XCloneable ____
205 Reference< util::XCloneable > SAL_CALL Legend::createClone()
206 throw (uno::RuntimeException)
208 return Reference< util::XCloneable >( new Legend( *this ));
211 // ____ XModifyBroadcaster ____
212 void SAL_CALL Legend::addModifyListener( const Reference< util::XModifyListener >& aListener )
213 throw (uno::RuntimeException)
217 Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
218 xBroadcaster->addModifyListener( aListener );
220 catch( const uno::Exception & ex )
222 ASSERT_EXCEPTION( ex );
226 void SAL_CALL Legend::removeModifyListener( const Reference< util::XModifyListener >& aListener )
227 throw (uno::RuntimeException)
231 Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
232 xBroadcaster->removeModifyListener( aListener );
234 catch( const uno::Exception & ex )
236 ASSERT_EXCEPTION( ex );
240 // ____ XModifyListener ____
241 void SAL_CALL Legend::modified( const lang::EventObject& aEvent )
242 throw (uno::RuntimeException)
244 m_xModifyEventForwarder->modified( aEvent );
247 // ____ XEventListener (base of XModifyListener) ____
248 void SAL_CALL Legend::disposing( const lang::EventObject& /* Source */ )
249 throw (uno::RuntimeException)
251 // nothing
254 // ____ OPropertySet ____
255 void Legend::firePropertyChangeEvent()
257 fireModifyEvent();
260 void Legend::fireModifyEvent()
262 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
265 // ================================================================================
267 Sequence< OUString > Legend::getSupportedServiceNames_Static()
269 const sal_Int32 nNumServices( 6 );
270 sal_Int32 nI = 0;
271 Sequence< OUString > aServices( nNumServices );
272 aServices[ nI++ ] = "com.sun.star.chart2.Legend";
273 aServices[ nI++ ] = "com.sun.star.beans.PropertySet";
274 aServices[ nI++ ] = "com.sun.star.drawing.FillProperties";
275 aServices[ nI++ ] = "com.sun.star.drawing.LineProperties";
276 aServices[ nI++ ] = "com.sun.star.style.CharacterProperties";
277 aServices[ nI++ ] = "com.sun.star.layout.LayoutElement";
278 OSL_ASSERT( nNumServices == nI );
279 return aServices;
282 // ____ OPropertySet ____
283 Any Legend::GetDefaultValue( sal_Int32 nHandle ) const
284 throw(beans::UnknownPropertyException)
286 const tPropertyValueMap& rStaticDefaults = *StaticLegendDefaults::get();
287 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
288 if( aFound == rStaticDefaults.end() )
289 return uno::Any();
290 return (*aFound).second;
293 ::cppu::IPropertyArrayHelper & SAL_CALL Legend::getInfoHelper()
295 return *StaticLegendInfoHelper::get();
298 // ____ XPropertySet ____
299 Reference< beans::XPropertySetInfo > SAL_CALL Legend::getPropertySetInfo()
300 throw (uno::RuntimeException)
302 return *StaticLegendInfo::get();
305 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
306 APPHELPER_XSERVICEINFO_IMPL( Legend, lcl_aServiceName );
308 // needed by MSC compiler
309 using impl::Legend_Base;
311 IMPLEMENT_FORWARD_XINTERFACE2( Legend, Legend_Base, ::property::OPropertySet )
312 IMPLEMENT_FORWARD_XTYPEPROVIDER2( Legend, Legend_Base, ::property::OPropertySet )
314 } // namespace chart
316 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */