Update ooo320-m1
[ooovba.git] / chart2 / source / controller / chartapiwrapper / WrappedDataCaptionProperties.cxx
blobbd3bf5e277d2c0e8d77f02277f16e588cfeab452
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WrappedDataCaptionProperties.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "WrappedDataCaptionProperties.hxx"
35 #include "WrappedSeriesOrDiagramProperty.hxx"
36 #include "macros.hxx"
37 #include "FastPropertyIdRanges.hxx"
38 #include <com/sun/star/chart2/DataPointLabel.hpp>
39 #include <com/sun/star/chart/ChartDataCaption.hpp>
40 #include <com/sun/star/beans/PropertyAttribute.hpp>
42 using namespace ::com::sun::star;
43 using ::com::sun::star::uno::Any;
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::uno::Sequence;
46 using ::com::sun::star::beans::Property;
47 using ::rtl::OUString;
49 //.............................................................................
50 namespace chart
52 namespace wrapper
55 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
57 //-----------------------------------------------------------------------------
59 class WrappedDataCaptionProperty : public WrappedSeriesOrDiagramProperty< sal_Int32 >
61 public:
62 virtual sal_Int32 getValueFromSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet ) const;
63 virtual void setValueToSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet, sal_Int32 aNewValue ) const;
65 explicit WrappedDataCaptionProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact,
66 tSeriesOrDiagramPropertyType ePropertyType );
67 virtual ~WrappedDataCaptionProperty();
70 namespace
72 enum
74 //data caption properties
75 PROP_CHART_DATAPOINT_DATA_CAPTION = FAST_PROPERTY_ID_START_CHART_DATACAPTION_PROP
78 sal_Int32 lcl_LabelToCaption( const chart2::DataPointLabel& rLabel )
80 sal_Int32 nCaption=0;
82 if( rLabel.ShowNumber )
83 nCaption |= ::com::sun::star::chart::ChartDataCaption::VALUE;
84 if( rLabel.ShowNumberInPercent )
85 nCaption |= ::com::sun::star::chart::ChartDataCaption::PERCENT;
86 if( rLabel.ShowCategoryName )
87 nCaption |= ::com::sun::star::chart::ChartDataCaption::TEXT;
88 if( rLabel.ShowLegendSymbol )
89 nCaption |= ::com::sun::star::chart::ChartDataCaption::SYMBOL;
91 return nCaption;
94 chart2::DataPointLabel lcl_CaptionToLabel( sal_Int32 nCaption )
96 chart2::DataPointLabel aLabel(false,false,false,false);
98 if( nCaption & ::com::sun::star::chart::ChartDataCaption::VALUE )
99 aLabel.ShowNumber = true;
100 if( nCaption & ::com::sun::star::chart::ChartDataCaption::PERCENT )
101 aLabel.ShowNumberInPercent = true;
102 if( nCaption & ::com::sun::star::chart::ChartDataCaption::TEXT )
103 aLabel.ShowCategoryName = true;
104 if( nCaption & ::com::sun::star::chart::ChartDataCaption::SYMBOL )
105 aLabel.ShowLegendSymbol = true;
107 return aLabel;
110 void lcl_addWrappedProperties( std::vector< WrappedProperty* >& rList
111 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact
112 , tSeriesOrDiagramPropertyType ePropertyType )
114 //if !spChart2ModelContact.get() is then the created properties do belong to a single series or single datapoint
115 //otherwise they do belong to the whole diagram
117 rList.push_back( new WrappedDataCaptionProperty( spChart2ModelContact, ePropertyType ) );
120 }//anonymous namespace
122 //-----------------------------------------------------------------------------
123 //-----------------------------------------------------------------------------
124 //-----------------------------------------------------------------------------
125 //static
126 void WrappedDataCaptionProperties::addProperties( ::std::vector< Property > & rOutProperties )
128 rOutProperties.push_back(
129 Property( C2U( "DataCaption" ),
130 PROP_CHART_DATAPOINT_DATA_CAPTION,
131 ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
132 beans::PropertyAttribute::BOUND
133 | beans::PropertyAttribute::MAYBEDEFAULT ));
136 //-----------------------------------------------------------------------------
137 //-----------------------------------------------------------------------------
139 //static
140 void WrappedDataCaptionProperties::addWrappedPropertiesForSeries( std::vector< WrappedProperty* >& rList
141 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
143 lcl_addWrappedProperties( rList, spChart2ModelContact, DATA_SERIES );
146 //-----------------------------------------------------------------------------
147 //-----------------------------------------------------------------------------
149 //static
150 void WrappedDataCaptionProperties::addWrappedPropertiesForDiagram( std::vector< WrappedProperty* >& rList
151 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
153 lcl_addWrappedProperties( rList, spChart2ModelContact, DIAGRAM );
156 //-----------------------------------------------------------------------------
157 //-----------------------------------------------------------------------------
158 //-----------------------------------------------------------------------------
160 WrappedDataCaptionProperty::WrappedDataCaptionProperty(
161 ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact
162 , tSeriesOrDiagramPropertyType ePropertyType )
163 : WrappedSeriesOrDiagramProperty< sal_Int32 >( C2U("DataCaption")
164 , uno::makeAny( sal_Int32(0) ), spChart2ModelContact, ePropertyType )
167 WrappedDataCaptionProperty::~WrappedDataCaptionProperty()
171 sal_Int32 WrappedDataCaptionProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
173 sal_Int32 aRet = 0;
174 m_aDefaultValue >>= aRet;
175 chart2::DataPointLabel aLabel;
176 if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue(C2U("Label")) >>= aLabel ) )
177 aRet = lcl_LabelToCaption( aLabel );
178 return aRet;
181 void WrappedDataCaptionProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, sal_Int32 nCaption ) const
183 if(!xSeriesPropertySet.is())
184 return;
186 chart2::DataPointLabel aLabel = lcl_CaptionToLabel( nCaption );
187 xSeriesPropertySet->setPropertyValue( C2U("Label"), uno::makeAny( aLabel ) );
190 //-----------------------------------------------------------------------------
191 //-----------------------------------------------------------------------------
192 //-----------------------------------------------------------------------------
194 } //namespace wrapper
195 } //namespace chart
196 //.............................................................................