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