xref: /aoo42x/main/chart2/source/model/main/Legend.cxx (revision cde9e8dc)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 #include "Legend.hxx"
27 #include "macros.hxx"
28 #include "LineProperties.hxx"
29 #include "FillProperties.hxx"
30 #include "CharacterProperties.hxx"
31 #include "UserDefinedProperties.hxx"
32 #include "LegendHelper.hxx"
33 #include "ContainerHelper.hxx"
34 #include "CloneHelper.hxx"
35 #include "PropertyHelper.hxx"
36 #include <com/sun/star/beans/PropertyAttribute.hpp>
37 #include <com/sun/star/awt/Size.hpp>
38 #include <com/sun/star/chart2/LegendPosition.hpp>
39 #include <com/sun/star/chart/ChartLegendExpansion.hpp>
40 #include <com/sun/star/chart2/RelativePosition.hpp>
41 #include <com/sun/star/chart2/RelativeSize.hpp>
42 
43 #include <algorithm>
44 
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::beans::PropertyAttribute;
47 
48 using ::rtl::OUString;
49 using ::com::sun::star::uno::Sequence;
50 using ::com::sun::star::uno::Reference;
51 using ::com::sun::star::uno::Any;
52 using ::com::sun::star::beans::Property;
53 
54 namespace
55 {
56 
57 static const OUString lcl_aServiceName(
58     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.Legend" ));
59 
60 enum
61 {
62     PROP_LEGEND_ANCHOR_POSITION,
63     PROP_LEGEND_EXPANSION,
64     PROP_LEGEND_SHOW,
65     PROP_LEGEND_REF_PAGE_SIZE,
66     PROP_LEGEND_REL_POS,
67     PROP_LEGEND_REL_SIZE
68 };
69 
lcl_AddPropertiesToVector(::std::vector<Property> & rOutProperties)70 void lcl_AddPropertiesToVector(
71     ::std::vector< Property > & rOutProperties )
72 {
73     rOutProperties.push_back(
74         Property( C2U( "AnchorPosition" ),
75                   PROP_LEGEND_ANCHOR_POSITION,
76                   ::getCppuType( reinterpret_cast< const chart2::LegendPosition * >(0)),
77                   beans::PropertyAttribute::BOUND
78                   | beans::PropertyAttribute::MAYBEDEFAULT ));
79 
80     rOutProperties.push_back(
81         Property( C2U( "Expansion" ),
82                   PROP_LEGEND_EXPANSION,
83                   ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartLegendExpansion * >(0)),
84                   beans::PropertyAttribute::BOUND
85                   | beans::PropertyAttribute::MAYBEDEFAULT ));
86 
87     rOutProperties.push_back(
88         Property( C2U( "Show" ),
89                   PROP_LEGEND_SHOW,
90                   ::getBooleanCppuType(),
91                   beans::PropertyAttribute::BOUND
92                   | beans::PropertyAttribute::MAYBEDEFAULT ));
93     rOutProperties.push_back(
94         Property( C2U( "ReferencePageSize" ),
95                   PROP_LEGEND_REF_PAGE_SIZE,
96                   ::getCppuType( reinterpret_cast< const awt::Size * >(0)),
97                   beans::PropertyAttribute::BOUND
98                   | beans::PropertyAttribute::MAYBEVOID ));
99 
100     rOutProperties.push_back(
101         Property( C2U( "RelativePosition" ),
102                   PROP_LEGEND_REL_POS,
103                   ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)),
104                   beans::PropertyAttribute::BOUND
105                   | beans::PropertyAttribute::MAYBEVOID ));
106 
107     rOutProperties.push_back(
108         Property( C2U( "RelativeSize" ),
109                   PROP_LEGEND_REL_SIZE,
110                   ::getCppuType( reinterpret_cast< const chart2::RelativeSize * >(0)),
111                   beans::PropertyAttribute::BOUND
112                   | beans::PropertyAttribute::MAYBEVOID ));
113 
114 }
115 
116 struct StaticLegendDefaults_Initializer
117 {
operator ()__anona626852e0111::StaticLegendDefaults_Initializer118     ::chart::tPropertyValueMap* operator()()
119     {
120         static ::chart::tPropertyValueMap aStaticDefaults;
121         lcl_AddDefaultsToMap( aStaticDefaults );
122         return &aStaticDefaults;
123     }
124 private:
lcl_AddDefaultsToMap__anona626852e0111::StaticLegendDefaults_Initializer125     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
126     {
127         ::chart::LineProperties::AddDefaultsToMap( rOutMap );
128         ::chart::FillProperties::AddDefaultsToMap( rOutMap );
129         ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
130 
131         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_ANCHOR_POSITION, chart2::LegendPosition_LINE_END );
132         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_EXPANSION, ::com::sun::star::chart::ChartLegendExpansion_HIGH );
133         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_SHOW, true );
134 
135         float fDefaultCharHeight = 10.0;
136         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight );
137         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight );
138         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight );
139     }
140 };
141 
142 struct StaticLegendDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticLegendDefaults_Initializer >
143 {
144 };
145 
146 struct StaticLegendInfoHelper_Initializer
147 {
operator ()__anona626852e0111::StaticLegendInfoHelper_Initializer148     ::cppu::OPropertyArrayHelper* operator()()
149     {
150         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
151         return &aPropHelper;
152     }
153 
154 private:
lcl_GetPropertySequence__anona626852e0111::StaticLegendInfoHelper_Initializer155     Sequence< Property > lcl_GetPropertySequence()
156     {
157         ::std::vector< ::com::sun::star::beans::Property > aProperties;
158         lcl_AddPropertiesToVector( aProperties );
159         ::chart::LineProperties::AddPropertiesToVector( aProperties );
160         ::chart::FillProperties::AddPropertiesToVector( aProperties );
161         ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
162         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
163 
164         ::std::sort( aProperties.begin(), aProperties.end(),
165                      ::chart::PropertyNameLess() );
166 
167         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
168     }
169 };
170 
171 struct StaticLegendInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticLegendInfoHelper_Initializer >
172 {
173 };
174 
175 struct StaticLegendInfo_Initializer
176 {
operator ()__anona626852e0111::StaticLegendInfo_Initializer177     uno::Reference< beans::XPropertySetInfo >* operator()()
178     {
179         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
180             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticLegendInfoHelper::get() ) );
181         return &xPropertySetInfo;
182     }
183 };
184 
185 struct StaticLegendInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticLegendInfo_Initializer >
186 {
187 };
188 
189 } // anonymous namespace
190 
191 namespace chart
192 {
193 
Legend(Reference<uno::XComponentContext> const &)194 Legend::Legend( Reference< uno::XComponentContext > const & /* xContext */ ) :
195         ::property::OPropertySet( m_aMutex ),
196         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
197 {
198 }
199 
Legend(const Legend & rOther)200 Legend::Legend( const Legend & rOther ) :
201         MutexContainer(),
202         impl::Legend_Base(),
203         ::property::OPropertySet( rOther, m_aMutex ),
204     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
205 {
206 }
207 
~Legend()208 Legend::~Legend()
209 {
210 }
211 
212 // ____ XCloneable ____
createClone()213 Reference< util::XCloneable > SAL_CALL Legend::createClone()
214     throw (uno::RuntimeException)
215 {
216     return Reference< util::XCloneable >( new Legend( *this ));
217 }
218 
219 // ____ XModifyBroadcaster ____
addModifyListener(const Reference<util::XModifyListener> & aListener)220 void SAL_CALL Legend::addModifyListener( const Reference< util::XModifyListener >& aListener )
221     throw (uno::RuntimeException)
222 {
223     try
224     {
225         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
226         xBroadcaster->addModifyListener( aListener );
227     }
228     catch( const uno::Exception & ex )
229     {
230         ASSERT_EXCEPTION( ex );
231     }
232 }
233 
removeModifyListener(const Reference<util::XModifyListener> & aListener)234 void SAL_CALL Legend::removeModifyListener( const Reference< util::XModifyListener >& aListener )
235     throw (uno::RuntimeException)
236 {
237     try
238     {
239         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
240         xBroadcaster->removeModifyListener( aListener );
241     }
242     catch( const uno::Exception & ex )
243     {
244         ASSERT_EXCEPTION( ex );
245     }
246 }
247 
248 // ____ XModifyListener ____
modified(const lang::EventObject & aEvent)249 void SAL_CALL Legend::modified( const lang::EventObject& aEvent )
250     throw (uno::RuntimeException)
251 {
252     m_xModifyEventForwarder->modified( aEvent );
253 }
254 
255 // ____ XEventListener (base of XModifyListener) ____
disposing(const lang::EventObject &)256 void SAL_CALL Legend::disposing( const lang::EventObject& /* Source */ )
257     throw (uno::RuntimeException)
258 {
259     // nothing
260 }
261 
262 // ____ OPropertySet ____
firePropertyChangeEvent()263 void Legend::firePropertyChangeEvent()
264 {
265     fireModifyEvent();
266 }
267 
fireModifyEvent()268 void Legend::fireModifyEvent()
269 {
270     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
271 }
272 
273 // ================================================================================
274 
getSupportedServiceNames_Static()275 Sequence< OUString > Legend::getSupportedServiceNames_Static()
276 {
277     const sal_Int32 nNumServices( 6 );
278     sal_Int32 nI = 0;
279     Sequence< OUString > aServices( nNumServices );
280     aServices[ nI++ ] = C2U( "com.sun.star.chart2.Legend" );
281     aServices[ nI++ ] = C2U( "com.sun.star.beans.PropertySet" );
282     aServices[ nI++ ] = C2U( "com.sun.star.drawing.FillProperties" );
283     aServices[ nI++ ] = C2U( "com.sun.star.drawing.LineProperties" );
284     aServices[ nI++ ] = C2U( "com.sun.star.style.CharacterProperties" );
285     aServices[ nI++ ] = C2U( "com.sun.star.layout.LayoutElement" );
286     OSL_ASSERT( nNumServices == nI );
287     return aServices;
288 }
289 
290 // ____ OPropertySet ____
GetDefaultValue(sal_Int32 nHandle) const291 Any Legend::GetDefaultValue( sal_Int32 nHandle ) const
292     throw(beans::UnknownPropertyException)
293 {
294     const tPropertyValueMap& rStaticDefaults = *StaticLegendDefaults::get();
295     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
296     if( aFound == rStaticDefaults.end() )
297         return uno::Any();
298     return (*aFound).second;
299 }
300 
getInfoHelper()301 ::cppu::IPropertyArrayHelper & SAL_CALL Legend::getInfoHelper()
302 {
303     return *StaticLegendInfoHelper::get();
304 }
305 
306 // ____ XPropertySet ____
getPropertySetInfo()307 Reference< beans::XPropertySetInfo > SAL_CALL Legend::getPropertySetInfo()
308     throw (uno::RuntimeException)
309 {
310     return *StaticLegendInfo::get();
311 }
312 
313 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
314 APPHELPER_XSERVICEINFO_IMPL( Legend, lcl_aServiceName );
315 
316 // needed by MSC compiler
317 using impl::Legend_Base;
318 
319 IMPLEMENT_FORWARD_XINTERFACE2( Legend, Legend_Base, ::property::OPropertySet )
320 IMPLEMENT_FORWARD_XTYPEPROVIDER2( Legend, Legend_Base, ::property::OPropertySet )
321 
322 } //  namespace chart
323