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