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