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 31*cdf0e10cSrcweir #include "WrappedDataCaptionProperties.hxx" 32*cdf0e10cSrcweir #include "WrappedSeriesOrDiagramProperty.hxx" 33*cdf0e10cSrcweir #include "macros.hxx" 34*cdf0e10cSrcweir #include "FastPropertyIdRanges.hxx" 35*cdf0e10cSrcweir #include <com/sun/star/chart2/DataPointLabel.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/chart/ChartDataCaption.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir using namespace ::com::sun::star; 40*cdf0e10cSrcweir using ::com::sun::star::uno::Any; 41*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 42*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 43*cdf0e10cSrcweir using ::com::sun::star::beans::Property; 44*cdf0e10cSrcweir using ::rtl::OUString; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir //............................................................................. 47*cdf0e10cSrcweir namespace chart 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir namespace wrapper 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir //----------------------------------------------------------------------------- 53*cdf0e10cSrcweir //----------------------------------------------------------------------------- 54*cdf0e10cSrcweir //----------------------------------------------------------------------------- 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir class WrappedDataCaptionProperty : public WrappedSeriesOrDiagramProperty< sal_Int32 > 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir public: 59*cdf0e10cSrcweir virtual sal_Int32 getValueFromSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet ) const; 60*cdf0e10cSrcweir virtual void setValueToSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet, sal_Int32 aNewValue ) const; 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir explicit WrappedDataCaptionProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact, 63*cdf0e10cSrcweir tSeriesOrDiagramPropertyType ePropertyType ); 64*cdf0e10cSrcweir virtual ~WrappedDataCaptionProperty(); 65*cdf0e10cSrcweir }; 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir namespace 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir enum 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir //data caption properties 72*cdf0e10cSrcweir PROP_CHART_DATAPOINT_DATA_CAPTION = FAST_PROPERTY_ID_START_CHART_DATACAPTION_PROP 73*cdf0e10cSrcweir }; 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir sal_Int32 lcl_LabelToCaption( const chart2::DataPointLabel& rLabel ) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir sal_Int32 nCaption=0; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir if( rLabel.ShowNumber ) 80*cdf0e10cSrcweir nCaption |= ::com::sun::star::chart::ChartDataCaption::VALUE; 81*cdf0e10cSrcweir if( rLabel.ShowNumberInPercent ) 82*cdf0e10cSrcweir nCaption |= ::com::sun::star::chart::ChartDataCaption::PERCENT; 83*cdf0e10cSrcweir if( rLabel.ShowCategoryName ) 84*cdf0e10cSrcweir nCaption |= ::com::sun::star::chart::ChartDataCaption::TEXT; 85*cdf0e10cSrcweir if( rLabel.ShowLegendSymbol ) 86*cdf0e10cSrcweir nCaption |= ::com::sun::star::chart::ChartDataCaption::SYMBOL; 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir return nCaption; 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir chart2::DataPointLabel lcl_CaptionToLabel( sal_Int32 nCaption ) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir chart2::DataPointLabel aLabel(false,false,false,false); 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir if( nCaption & ::com::sun::star::chart::ChartDataCaption::VALUE ) 96*cdf0e10cSrcweir aLabel.ShowNumber = true; 97*cdf0e10cSrcweir if( nCaption & ::com::sun::star::chart::ChartDataCaption::PERCENT ) 98*cdf0e10cSrcweir aLabel.ShowNumberInPercent = true; 99*cdf0e10cSrcweir if( nCaption & ::com::sun::star::chart::ChartDataCaption::TEXT ) 100*cdf0e10cSrcweir aLabel.ShowCategoryName = true; 101*cdf0e10cSrcweir if( nCaption & ::com::sun::star::chart::ChartDataCaption::SYMBOL ) 102*cdf0e10cSrcweir aLabel.ShowLegendSymbol = true; 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir return aLabel; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir void lcl_addWrappedProperties( std::vector< WrappedProperty* >& rList 108*cdf0e10cSrcweir , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact 109*cdf0e10cSrcweir , tSeriesOrDiagramPropertyType ePropertyType ) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir //if !spChart2ModelContact.get() is then the created properties do belong to a single series or single datapoint 112*cdf0e10cSrcweir //otherwise they do belong to the whole diagram 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir rList.push_back( new WrappedDataCaptionProperty( spChart2ModelContact, ePropertyType ) ); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir }//anonymous namespace 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir //----------------------------------------------------------------------------- 120*cdf0e10cSrcweir //----------------------------------------------------------------------------- 121*cdf0e10cSrcweir //----------------------------------------------------------------------------- 122*cdf0e10cSrcweir void WrappedDataCaptionProperties::addProperties( ::std::vector< Property > & rOutProperties ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir rOutProperties.push_back( 125*cdf0e10cSrcweir Property( C2U( "DataCaption" ), 126*cdf0e10cSrcweir PROP_CHART_DATAPOINT_DATA_CAPTION, 127*cdf0e10cSrcweir ::getCppuType( reinterpret_cast< sal_Int32 * >(0)), 128*cdf0e10cSrcweir beans::PropertyAttribute::BOUND 129*cdf0e10cSrcweir | beans::PropertyAttribute::MAYBEDEFAULT )); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir //----------------------------------------------------------------------------- 133*cdf0e10cSrcweir //----------------------------------------------------------------------------- 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir void WrappedDataCaptionProperties::addWrappedPropertiesForSeries( std::vector< WrappedProperty* >& rList 136*cdf0e10cSrcweir , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir lcl_addWrappedProperties( rList, spChart2ModelContact, DATA_SERIES ); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir //----------------------------------------------------------------------------- 142*cdf0e10cSrcweir //----------------------------------------------------------------------------- 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir void WrappedDataCaptionProperties::addWrappedPropertiesForDiagram( std::vector< WrappedProperty* >& rList 145*cdf0e10cSrcweir , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir lcl_addWrappedProperties( rList, spChart2ModelContact, DIAGRAM ); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir //----------------------------------------------------------------------------- 151*cdf0e10cSrcweir //----------------------------------------------------------------------------- 152*cdf0e10cSrcweir //----------------------------------------------------------------------------- 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir WrappedDataCaptionProperty::WrappedDataCaptionProperty( 155*cdf0e10cSrcweir ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact 156*cdf0e10cSrcweir , tSeriesOrDiagramPropertyType ePropertyType ) 157*cdf0e10cSrcweir : WrappedSeriesOrDiagramProperty< sal_Int32 >( C2U("DataCaption") 158*cdf0e10cSrcweir , uno::makeAny( sal_Int32(0) ), spChart2ModelContact, ePropertyType ) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir WrappedDataCaptionProperty::~WrappedDataCaptionProperty() 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir sal_Int32 WrappedDataCaptionProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir sal_Int32 aRet = 0; 168*cdf0e10cSrcweir m_aDefaultValue >>= aRet; 169*cdf0e10cSrcweir chart2::DataPointLabel aLabel; 170*cdf0e10cSrcweir if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue(C2U("Label")) >>= aLabel ) ) 171*cdf0e10cSrcweir aRet = lcl_LabelToCaption( aLabel ); 172*cdf0e10cSrcweir return aRet; 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir void WrappedDataCaptionProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, sal_Int32 nCaption ) const 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir if(!xSeriesPropertySet.is()) 178*cdf0e10cSrcweir return; 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir chart2::DataPointLabel aLabel = lcl_CaptionToLabel( nCaption ); 181*cdf0e10cSrcweir xSeriesPropertySet->setPropertyValue( C2U("Label"), uno::makeAny( aLabel ) ); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir //----------------------------------------------------------------------------- 185*cdf0e10cSrcweir //----------------------------------------------------------------------------- 186*cdf0e10cSrcweir //----------------------------------------------------------------------------- 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir } //namespace wrapper 189*cdf0e10cSrcweir } //namespace chart 190*cdf0e10cSrcweir //............................................................................. 191