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 .
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 #include <tools/diagnose_ex.h>
38 namespace com::sun::star::uno
{ class XComponentContext
; }
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
;
53 PROP_LEGEND_ANCHOR_POSITION
,
54 PROP_LEGEND_EXPANSION
,
57 PROP_LEGEND_REF_PAGE_SIZE
,
62 void lcl_AddPropertiesToVector(
63 std::vector
< Property
> & rOutProperties
)
65 rOutProperties
.emplace_back( "AnchorPosition",
66 PROP_LEGEND_ANCHOR_POSITION
,
67 cppu::UnoType
<chart2::LegendPosition
>::get(),
68 beans::PropertyAttribute::BOUND
69 | beans::PropertyAttribute::MAYBEDEFAULT
);
71 rOutProperties
.emplace_back( "Expansion",
72 PROP_LEGEND_EXPANSION
,
73 cppu::UnoType
<css::chart::ChartLegendExpansion
>::get(),
74 beans::PropertyAttribute::BOUND
75 | beans::PropertyAttribute::MAYBEDEFAULT
);
77 rOutProperties
.emplace_back( "Show",
79 cppu::UnoType
<bool>::get(),
80 beans::PropertyAttribute::BOUND
81 | beans::PropertyAttribute::MAYBEDEFAULT
);
83 rOutProperties
.emplace_back( "Overlay",
85 cppu::UnoType
<bool>::get(),
86 beans::PropertyAttribute::BOUND
87 | beans::PropertyAttribute::MAYBEDEFAULT
);
89 rOutProperties
.emplace_back( "ReferencePageSize",
90 PROP_LEGEND_REF_PAGE_SIZE
,
91 cppu::UnoType
<awt::Size
>::get(),
92 beans::PropertyAttribute::BOUND
93 | beans::PropertyAttribute::MAYBEVOID
);
95 rOutProperties
.emplace_back( "RelativePosition",
97 cppu::UnoType
<chart2::RelativePosition
>::get(),
98 beans::PropertyAttribute::BOUND
99 | beans::PropertyAttribute::MAYBEVOID
);
101 rOutProperties
.emplace_back( "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
, css::chart::ChartLegendExpansion_HIGH
);
126 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_LEGEND_SHOW
, true );
127 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_LEGEND_OVERLAY
, false );
129 float fDefaultCharHeight
= 10.0;
130 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT
, fDefaultCharHeight
);
131 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT
, fDefaultCharHeight
);
132 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT
, fDefaultCharHeight
);
136 struct StaticLegendDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticLegendDefaults_Initializer
>
140 struct StaticLegendInfoHelper_Initializer
142 ::cppu::OPropertyArrayHelper
* operator()()
144 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
149 static Sequence
< Property
> lcl_GetPropertySequence()
151 std::vector
< css::beans::Property
> aProperties
;
152 lcl_AddPropertiesToVector( aProperties
);
153 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
154 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
155 ::chart::CharacterProperties::AddPropertiesToVector( aProperties
);
156 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
158 std::sort( aProperties
.begin(), aProperties
.end(),
159 ::chart::PropertyNameLess() );
161 return comphelper::containerToSequence( aProperties
);
165 struct StaticLegendInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticLegendInfoHelper_Initializer
>
169 struct StaticLegendInfo_Initializer
171 uno::Reference
< beans::XPropertySetInfo
>* operator()()
173 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
174 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticLegendInfoHelper::get() ) );
175 return &xPropertySetInfo
;
179 struct StaticLegendInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticLegendInfo_Initializer
>
183 } // anonymous namespace
189 ::property::OPropertySet( m_aMutex
),
190 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
194 Legend::Legend( const Legend
& rOther
) :
195 impl::Legend_Base(rOther
),
196 ::property::OPropertySet( rOther
, m_aMutex
),
197 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
205 // ____ XCloneable ____
206 Reference
< util::XCloneable
> SAL_CALL
Legend::createClone()
208 return Reference
< util::XCloneable
>( new Legend( *this ));
211 // ____ XModifyBroadcaster ____
212 void SAL_CALL
Legend::addModifyListener( const Reference
< util::XModifyListener
>& aListener
)
216 Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
217 xBroadcaster
->addModifyListener( aListener
);
219 catch( const uno::Exception
& )
221 DBG_UNHANDLED_EXCEPTION("chart2");
225 void SAL_CALL
Legend::removeModifyListener( const Reference
< util::XModifyListener
>& aListener
)
229 Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
230 xBroadcaster
->removeModifyListener( aListener
);
232 catch( const uno::Exception
& )
234 DBG_UNHANDLED_EXCEPTION("chart2");
238 // ____ XModifyListener ____
239 void SAL_CALL
Legend::modified( const lang::EventObject
& aEvent
)
241 m_xModifyEventForwarder
->modified( aEvent
);
244 // ____ XEventListener (base of XModifyListener) ____
245 void SAL_CALL
Legend::disposing( const lang::EventObject
& /* Source */ )
250 // ____ OPropertySet ____
251 void Legend::firePropertyChangeEvent()
253 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
256 // ____ OPropertySet ____
257 Any
Legend::GetDefaultValue( sal_Int32 nHandle
) const
259 const tPropertyValueMap
& rStaticDefaults
= *StaticLegendDefaults::get();
260 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
261 if( aFound
== rStaticDefaults
.end() )
263 return (*aFound
).second
;
266 ::cppu::IPropertyArrayHelper
& SAL_CALL
Legend::getInfoHelper()
268 return *StaticLegendInfoHelper::get();
271 // ____ XPropertySet ____
272 Reference
< beans::XPropertySetInfo
> SAL_CALL
Legend::getPropertySetInfo()
274 return *StaticLegendInfo::get();
277 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
278 OUString SAL_CALL
Legend::getImplementationName()
280 return "com.sun.star.comp.chart2.Legend";
283 sal_Bool SAL_CALL
Legend::supportsService( const OUString
& rServiceName
)
285 return cppu::supportsService(this, rServiceName
);
288 css::uno::Sequence
< OUString
> SAL_CALL
Legend::getSupportedServiceNames()
291 "com.sun.star.chart2.Legend",
292 "com.sun.star.beans.PropertySet",
293 "com.sun.star.drawing.FillProperties",
294 "com.sun.star.drawing.LineProperties",
295 "com.sun.star.style.CharacterProperties",
296 "com.sun.star.layout.LayoutElement"
300 // needed by MSC compiler
301 using impl::Legend_Base
;
303 IMPLEMENT_FORWARD_XINTERFACE2( Legend
, Legend_Base
, ::property::OPropertySet
)
304 IMPLEMENT_FORWARD_XTYPEPROVIDER2( Legend
, Legend_Base
, ::property::OPropertySet
)
308 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
309 com_sun_star_comp_chart2_Legend_get_implementation(css::uno::XComponentContext
*,
310 css::uno::Sequence
<css::uno::Any
> const &)
312 return cppu::acquire(new ::chart::Legend
);
315 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */