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