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