1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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>
36 #include <cppuhelper/supportsservice.hxx>
40 using namespace ::com::sun::star
;
41 using namespace ::com::sun::star::beans::PropertyAttribute
;
43 using ::com::sun::star::uno::Sequence
;
44 using ::com::sun::star::uno::Reference
;
45 using ::com::sun::star::uno::Any
;
46 using ::com::sun::star::beans::Property
;
51 static const char lcl_aServiceName
[] = "com.sun.star.comp.chart2.Legend";
55 PROP_LEGEND_ANCHOR_POSITION
,
56 PROP_LEGEND_EXPANSION
,
58 PROP_LEGEND_REF_PAGE_SIZE
,
63 void lcl_AddPropertiesToVector(
64 ::std::vector
< Property
> & rOutProperties
)
66 rOutProperties
.push_back(
67 Property( "AnchorPosition",
68 PROP_LEGEND_ANCHOR_POSITION
,
69 cppu::UnoType
<chart2::LegendPosition
>::get(),
70 beans::PropertyAttribute::BOUND
71 | beans::PropertyAttribute::MAYBEDEFAULT
));
73 rOutProperties
.push_back(
74 Property( "Expansion",
75 PROP_LEGEND_EXPANSION
,
76 cppu::UnoType
<com::sun::star::chart::ChartLegendExpansion
>::get(),
77 beans::PropertyAttribute::BOUND
78 | beans::PropertyAttribute::MAYBEDEFAULT
));
80 rOutProperties
.push_back(
83 cppu::UnoType
<bool>::get(),
84 beans::PropertyAttribute::BOUND
85 | beans::PropertyAttribute::MAYBEDEFAULT
));
86 rOutProperties
.push_back(
87 Property( "ReferencePageSize",
88 PROP_LEGEND_REF_PAGE_SIZE
,
89 cppu::UnoType
<awt::Size
>::get(),
90 beans::PropertyAttribute::BOUND
91 | beans::PropertyAttribute::MAYBEVOID
));
93 rOutProperties
.push_back(
94 Property( "RelativePosition",
96 cppu::UnoType
<chart2::RelativePosition
>::get(),
97 beans::PropertyAttribute::BOUND
98 | beans::PropertyAttribute::MAYBEVOID
));
100 rOutProperties
.push_back(
101 Property( "RelativeSize",
102 PROP_LEGEND_REL_SIZE
,
103 cppu::UnoType
<chart2::RelativeSize
>::get(),
104 beans::PropertyAttribute::BOUND
105 | beans::PropertyAttribute::MAYBEVOID
));
109 struct StaticLegendDefaults_Initializer
111 ::chart::tPropertyValueMap
* operator()()
113 static ::chart::tPropertyValueMap aStaticDefaults
;
114 lcl_AddDefaultsToMap( aStaticDefaults
);
115 return &aStaticDefaults
;
118 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap
& rOutMap
)
120 ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap
);
121 ::chart::FillProperties::AddDefaultsToMap( rOutMap
);
122 ::chart::CharacterProperties::AddDefaultsToMap( rOutMap
);
124 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_LEGEND_ANCHOR_POSITION
, chart2::LegendPosition_LINE_END
);
125 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_LEGEND_EXPANSION
, ::com::sun::star::chart::ChartLegendExpansion_HIGH
);
126 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_LEGEND_SHOW
, true );
128 float fDefaultCharHeight
= 10.0;
129 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT
, fDefaultCharHeight
);
130 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT
, fDefaultCharHeight
);
131 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT
, fDefaultCharHeight
);
135 struct StaticLegendDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticLegendDefaults_Initializer
>
139 struct StaticLegendInfoHelper_Initializer
141 ::cppu::OPropertyArrayHelper
* operator()()
143 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
148 static Sequence
< Property
> lcl_GetPropertySequence()
150 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
151 lcl_AddPropertiesToVector( aProperties
);
152 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
153 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
154 ::chart::CharacterProperties::AddPropertiesToVector( aProperties
);
155 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
157 ::std::sort( aProperties
.begin(), aProperties
.end(),
158 ::chart::PropertyNameLess() );
160 return ::chart::ContainerHelper::ContainerToSequence( aProperties
);
164 struct StaticLegendInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticLegendInfoHelper_Initializer
>
168 struct StaticLegendInfo_Initializer
170 uno::Reference
< beans::XPropertySetInfo
>* operator()()
172 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
173 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticLegendInfoHelper::get() ) );
174 return &xPropertySetInfo
;
178 struct StaticLegendInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticLegendInfo_Initializer
>
182 } // anonymous namespace
187 Legend::Legend( Reference
< uno::XComponentContext
> const & /* xContext */ ) :
188 ::property::OPropertySet( m_aMutex
),
189 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
193 Legend::Legend( const Legend
& rOther
) :
196 ::property::OPropertySet( rOther
, m_aMutex
),
197 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
205 // ____ XCloneable ____
206 Reference
< util::XCloneable
> SAL_CALL
Legend::createClone()
207 throw (uno::RuntimeException
, std::exception
)
209 return Reference
< util::XCloneable
>( new Legend( *this ));
212 // ____ XModifyBroadcaster ____
213 void SAL_CALL
Legend::addModifyListener( const Reference
< util::XModifyListener
>& aListener
)
214 throw (uno::RuntimeException
, std::exception
)
218 Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
219 xBroadcaster
->addModifyListener( aListener
);
221 catch( const uno::Exception
& ex
)
223 ASSERT_EXCEPTION( ex
);
227 void SAL_CALL
Legend::removeModifyListener( const Reference
< util::XModifyListener
>& aListener
)
228 throw (uno::RuntimeException
, std::exception
)
232 Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
233 xBroadcaster
->removeModifyListener( aListener
);
235 catch( const uno::Exception
& ex
)
237 ASSERT_EXCEPTION( ex
);
241 // ____ XModifyListener ____
242 void SAL_CALL
Legend::modified( const lang::EventObject
& aEvent
)
243 throw (uno::RuntimeException
, std::exception
)
245 m_xModifyEventForwarder
->modified( aEvent
);
248 // ____ XEventListener (base of XModifyListener) ____
249 void SAL_CALL
Legend::disposing( const lang::EventObject
& /* Source */ )
250 throw (uno::RuntimeException
, std::exception
)
255 // ____ OPropertySet ____
256 void Legend::firePropertyChangeEvent()
261 void Legend::fireModifyEvent()
263 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
266 Sequence
< OUString
> Legend::getSupportedServiceNames_Static()
268 const sal_Int32
nNumServices( 6 );
270 Sequence
< OUString
> aServices( nNumServices
);
271 aServices
[ nI
++ ] = "com.sun.star.chart2.Legend";
272 aServices
[ nI
++ ] = "com.sun.star.beans.PropertySet";
273 aServices
[ nI
++ ] = "com.sun.star.drawing.FillProperties";
274 aServices
[ nI
++ ] = "com.sun.star.drawing.LineProperties";
275 aServices
[ nI
++ ] = "com.sun.star.style.CharacterProperties";
276 aServices
[ nI
++ ] = "com.sun.star.layout.LayoutElement";
277 OSL_ASSERT( nNumServices
== nI
);
281 // ____ OPropertySet ____
282 Any
Legend::GetDefaultValue( sal_Int32 nHandle
) const
283 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
285 const tPropertyValueMap
& rStaticDefaults
= *StaticLegendDefaults::get();
286 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
287 if( aFound
== rStaticDefaults
.end() )
289 return (*aFound
).second
;
292 ::cppu::IPropertyArrayHelper
& SAL_CALL
Legend::getInfoHelper()
294 return *StaticLegendInfoHelper::get();
297 // ____ XPropertySet ____
298 Reference
< beans::XPropertySetInfo
> SAL_CALL
Legend::getPropertySetInfo()
299 throw (uno::RuntimeException
, std::exception
)
301 return *StaticLegendInfo::get();
304 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
305 OUString SAL_CALL
Legend::getImplementationName()
306 throw( css::uno::RuntimeException
, std::exception
)
308 return getImplementationName_Static();
311 OUString
Legend::getImplementationName_Static()
313 return OUString(lcl_aServiceName
);
316 sal_Bool SAL_CALL
Legend::supportsService( const OUString
& rServiceName
)
317 throw( css::uno::RuntimeException
, std::exception
)
319 return cppu::supportsService(this, rServiceName
);
322 css::uno::Sequence
< OUString
> SAL_CALL
Legend::getSupportedServiceNames()
323 throw( css::uno::RuntimeException
, std::exception
)
325 return getSupportedServiceNames_Static();
328 // needed by MSC compiler
329 using impl::Legend_Base
;
331 IMPLEMENT_FORWARD_XINTERFACE2( Legend
, Legend_Base
, ::property::OPropertySet
)
332 IMPLEMENT_FORWARD_XTYPEPROVIDER2( Legend
, Legend_Base
, ::property::OPropertySet
)
336 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
337 com_sun_star_comp_chart2_Legend_get_implementation(css::uno::XComponentContext
*context
,
338 css::uno::Sequence
<css::uno::Any
> const &)
340 return cppu::acquire(new ::chart::Legend(context
));
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */