Line data Source code
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"
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>
36 : #include <cppuhelper/supportsservice.hxx>
37 :
38 : #include <algorithm>
39 :
40 : using namespace ::com::sun::star;
41 : using namespace ::com::sun::star::beans::PropertyAttribute;
42 :
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;
47 :
48 : namespace
49 : {
50 :
51 : static const char lcl_aServiceName[] = "com.sun.star.comp.chart2.Legend";
52 :
53 : enum
54 : {
55 : PROP_LEGEND_ANCHOR_POSITION,
56 : PROP_LEGEND_EXPANSION,
57 : PROP_LEGEND_SHOW,
58 : PROP_LEGEND_REF_PAGE_SIZE,
59 : PROP_LEGEND_REL_POS,
60 : PROP_LEGEND_REL_SIZE
61 : };
62 :
63 11 : void lcl_AddPropertiesToVector(
64 : ::std::vector< Property > & rOutProperties )
65 : {
66 : rOutProperties.push_back(
67 : Property( "AnchorPosition",
68 : PROP_LEGEND_ANCHOR_POSITION,
69 11 : cppu::UnoType<chart2::LegendPosition>::get(),
70 : beans::PropertyAttribute::BOUND
71 22 : | beans::PropertyAttribute::MAYBEDEFAULT ));
72 :
73 : rOutProperties.push_back(
74 : Property( "Expansion",
75 : PROP_LEGEND_EXPANSION,
76 11 : cppu::UnoType<com::sun::star::chart::ChartLegendExpansion>::get(),
77 : beans::PropertyAttribute::BOUND
78 22 : | beans::PropertyAttribute::MAYBEDEFAULT ));
79 :
80 : rOutProperties.push_back(
81 : Property( "Show",
82 : PROP_LEGEND_SHOW,
83 11 : cppu::UnoType<bool>::get(),
84 : beans::PropertyAttribute::BOUND
85 22 : | beans::PropertyAttribute::MAYBEDEFAULT ));
86 : rOutProperties.push_back(
87 : Property( "ReferencePageSize",
88 : PROP_LEGEND_REF_PAGE_SIZE,
89 11 : cppu::UnoType<awt::Size>::get(),
90 : beans::PropertyAttribute::BOUND
91 22 : | beans::PropertyAttribute::MAYBEVOID ));
92 :
93 : rOutProperties.push_back(
94 : Property( "RelativePosition",
95 : PROP_LEGEND_REL_POS,
96 11 : cppu::UnoType<chart2::RelativePosition>::get(),
97 : beans::PropertyAttribute::BOUND
98 22 : | beans::PropertyAttribute::MAYBEVOID ));
99 :
100 : rOutProperties.push_back(
101 : Property( "RelativeSize",
102 : PROP_LEGEND_REL_SIZE,
103 11 : cppu::UnoType<chart2::RelativeSize>::get(),
104 : beans::PropertyAttribute::BOUND
105 22 : | beans::PropertyAttribute::MAYBEVOID ));
106 :
107 11 : }
108 :
109 : struct StaticLegendDefaults_Initializer
110 : {
111 11 : ::chart::tPropertyValueMap* operator()()
112 : {
113 11 : static ::chart::tPropertyValueMap aStaticDefaults;
114 11 : lcl_AddDefaultsToMap( aStaticDefaults );
115 11 : return &aStaticDefaults;
116 : }
117 : private:
118 11 : static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
119 : {
120 11 : ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap );
121 11 : ::chart::FillProperties::AddDefaultsToMap( rOutMap );
122 11 : ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
123 :
124 11 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_ANCHOR_POSITION, chart2::LegendPosition_LINE_END );
125 11 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_EXPANSION, ::com::sun::star::chart::ChartLegendExpansion_HIGH );
126 11 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_SHOW, true );
127 :
128 11 : float fDefaultCharHeight = 10.0;
129 11 : ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight );
130 11 : ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight );
131 11 : ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight );
132 11 : }
133 : };
134 :
135 : struct StaticLegendDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticLegendDefaults_Initializer >
136 : {
137 : };
138 :
139 : struct StaticLegendInfoHelper_Initializer
140 : {
141 11 : ::cppu::OPropertyArrayHelper* operator()()
142 : {
143 11 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
144 11 : return &aPropHelper;
145 : }
146 :
147 : private:
148 11 : static Sequence< Property > lcl_GetPropertySequence()
149 : {
150 11 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
151 11 : lcl_AddPropertiesToVector( aProperties );
152 11 : ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
153 11 : ::chart::FillProperties::AddPropertiesToVector( aProperties );
154 11 : ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
155 11 : ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
156 :
157 : ::std::sort( aProperties.begin(), aProperties.end(),
158 11 : ::chart::PropertyNameLess() );
159 :
160 11 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
161 : }
162 : };
163 :
164 : struct StaticLegendInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticLegendInfoHelper_Initializer >
165 : {
166 : };
167 :
168 : struct StaticLegendInfo_Initializer
169 : {
170 8 : uno::Reference< beans::XPropertySetInfo >* operator()()
171 : {
172 : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
173 8 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticLegendInfoHelper::get() ) );
174 8 : return &xPropertySetInfo;
175 : }
176 : };
177 :
178 : struct StaticLegendInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticLegendInfo_Initializer >
179 : {
180 : };
181 :
182 : } // anonymous namespace
183 :
184 : namespace chart
185 : {
186 :
187 228 : Legend::Legend( Reference< uno::XComponentContext > const & /* xContext */ ) :
188 : ::property::OPropertySet( m_aMutex ),
189 228 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
190 : {
191 228 : }
192 :
193 0 : Legend::Legend( const Legend & rOther ) :
194 : MutexContainer(),
195 : impl::Legend_Base(),
196 : ::property::OPropertySet( rOther, m_aMutex ),
197 0 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
198 : {
199 0 : }
200 :
201 456 : Legend::~Legend()
202 : {
203 456 : }
204 :
205 : // ____ XCloneable ____
206 0 : Reference< util::XCloneable > SAL_CALL Legend::createClone()
207 : throw (uno::RuntimeException, std::exception)
208 : {
209 0 : return Reference< util::XCloneable >( new Legend( *this ));
210 : }
211 :
212 : // ____ XModifyBroadcaster ____
213 227 : void SAL_CALL Legend::addModifyListener( const Reference< util::XModifyListener >& aListener )
214 : throw (uno::RuntimeException, std::exception)
215 : {
216 : try
217 : {
218 227 : Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
219 227 : xBroadcaster->addModifyListener( aListener );
220 : }
221 0 : catch( const uno::Exception & ex )
222 : {
223 : ASSERT_EXCEPTION( ex );
224 : }
225 227 : }
226 :
227 227 : void SAL_CALL Legend::removeModifyListener( const Reference< util::XModifyListener >& aListener )
228 : throw (uno::RuntimeException, std::exception)
229 : {
230 : try
231 : {
232 227 : Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
233 227 : xBroadcaster->removeModifyListener( aListener );
234 : }
235 0 : catch( const uno::Exception & ex )
236 : {
237 : ASSERT_EXCEPTION( ex );
238 : }
239 227 : }
240 :
241 : // ____ XModifyListener ____
242 0 : void SAL_CALL Legend::modified( const lang::EventObject& aEvent )
243 : throw (uno::RuntimeException, std::exception)
244 : {
245 0 : m_xModifyEventForwarder->modified( aEvent );
246 0 : }
247 :
248 : // ____ XEventListener (base of XModifyListener) ____
249 0 : void SAL_CALL Legend::disposing( const lang::EventObject& /* Source */ )
250 : throw (uno::RuntimeException, std::exception)
251 : {
252 : // nothing
253 0 : }
254 :
255 : // ____ OPropertySet ____
256 1804 : void Legend::firePropertyChangeEvent()
257 : {
258 1804 : fireModifyEvent();
259 1804 : }
260 :
261 1804 : void Legend::fireModifyEvent()
262 : {
263 1804 : m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
264 1804 : }
265 :
266 1 : Sequence< OUString > Legend::getSupportedServiceNames_Static()
267 : {
268 1 : const sal_Int32 nNumServices( 6 );
269 1 : sal_Int32 nI = 0;
270 1 : Sequence< OUString > aServices( nNumServices );
271 1 : aServices[ nI++ ] = "com.sun.star.chart2.Legend";
272 1 : aServices[ nI++ ] = "com.sun.star.beans.PropertySet";
273 1 : aServices[ nI++ ] = "com.sun.star.drawing.FillProperties";
274 1 : aServices[ nI++ ] = "com.sun.star.drawing.LineProperties";
275 1 : aServices[ nI++ ] = "com.sun.star.style.CharacterProperties";
276 1 : aServices[ nI++ ] = "com.sun.star.layout.LayoutElement";
277 : OSL_ASSERT( nNumServices == nI );
278 1 : return aServices;
279 : }
280 :
281 : // ____ OPropertySet ____
282 194159 : Any Legend::GetDefaultValue( sal_Int32 nHandle ) const
283 : throw (beans::UnknownPropertyException, uno::RuntimeException)
284 : {
285 194159 : const tPropertyValueMap& rStaticDefaults = *StaticLegendDefaults::get();
286 194159 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
287 194159 : if( aFound == rStaticDefaults.end() )
288 16930 : return uno::Any();
289 177229 : return (*aFound).second;
290 : }
291 :
292 448331 : ::cppu::IPropertyArrayHelper & SAL_CALL Legend::getInfoHelper()
293 : {
294 448331 : return *StaticLegendInfoHelper::get();
295 : }
296 :
297 : // ____ XPropertySet ____
298 2837 : Reference< beans::XPropertySetInfo > SAL_CALL Legend::getPropertySetInfo()
299 : throw (uno::RuntimeException, std::exception)
300 : {
301 2837 : return *StaticLegendInfo::get();
302 : }
303 :
304 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
305 1 : OUString SAL_CALL Legend::getImplementationName()
306 : throw( css::uno::RuntimeException, std::exception )
307 : {
308 1 : return getImplementationName_Static();
309 : }
310 :
311 1 : OUString Legend::getImplementationName_Static()
312 : {
313 1 : return OUString(lcl_aServiceName);
314 : }
315 :
316 0 : sal_Bool SAL_CALL Legend::supportsService( const OUString& rServiceName )
317 : throw( css::uno::RuntimeException, std::exception )
318 : {
319 0 : return cppu::supportsService(this, rServiceName);
320 : }
321 :
322 1 : css::uno::Sequence< OUString > SAL_CALL Legend::getSupportedServiceNames()
323 : throw( css::uno::RuntimeException, std::exception )
324 : {
325 1 : return getSupportedServiceNames_Static();
326 : }
327 :
328 : // needed by MSC compiler
329 : using impl::Legend_Base;
330 :
331 541903 : IMPLEMENT_FORWARD_XINTERFACE2( Legend, Legend_Base, ::property::OPropertySet )
332 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( Legend, Legend_Base, ::property::OPropertySet )
333 :
334 : } // namespace chart
335 :
336 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
337 228 : com_sun_star_comp_chart2_Legend_get_implementation(css::uno::XComponentContext *context,
338 : css::uno::Sequence<css::uno::Any> const &)
339 : {
340 228 : return cppu::acquire(new ::chart::Legend(context));
341 : }
342 :
343 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|