1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 
27 #include "WrappedDataCaptionProperties.hxx"
28 #include "WrappedSeriesOrDiagramProperty.hxx"
29 #include "macros.hxx"
30 #include "FastPropertyIdRanges.hxx"
31 #include <com/sun/star/chart2/DataPointLabel.hpp>
32 #include <com/sun/star/chart/ChartDataCaption.hpp>
33 #include <com/sun/star/beans/PropertyAttribute.hpp>
34 
35 using namespace ::com::sun::star;
36 using ::com::sun::star::uno::Any;
37 using ::com::sun::star::uno::Reference;
38 using ::com::sun::star::uno::Sequence;
39 using ::com::sun::star::beans::Property;
40 using ::rtl::OUString;
41 
42 //.............................................................................
43 namespace chart
44 {
45 namespace wrapper
46 {
47 
48 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
51 
52 class WrappedDataCaptionProperty : public WrappedSeriesOrDiagramProperty< sal_Int32 >
53 {
54 public:
55     virtual sal_Int32 getValueFromSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet ) const;
56     virtual void setValueToSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet, sal_Int32 aNewValue ) const;
57 
58     explicit WrappedDataCaptionProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact,
59                                          tSeriesOrDiagramPropertyType ePropertyType );
60     virtual ~WrappedDataCaptionProperty();
61 };
62 
63 namespace
64 {
65 enum
66 {
67     //data caption properties
68     PROP_CHART_DATAPOINT_DATA_CAPTION = FAST_PROPERTY_ID_START_CHART_DATACAPTION_PROP
69 };
70 
lcl_LabelToCaption(const chart2::DataPointLabel & rLabel)71 sal_Int32 lcl_LabelToCaption( const chart2::DataPointLabel& rLabel )
72 {
73     sal_Int32 nCaption=0;
74 
75     if( rLabel.ShowNumber )
76         nCaption |= ::com::sun::star::chart::ChartDataCaption::VALUE;
77     if( rLabel.ShowNumberInPercent )
78         nCaption |= ::com::sun::star::chart::ChartDataCaption::PERCENT;
79     if( rLabel.ShowCategoryName )
80         nCaption |= ::com::sun::star::chart::ChartDataCaption::TEXT;
81     if( rLabel.ShowLegendSymbol )
82         nCaption |= ::com::sun::star::chart::ChartDataCaption::SYMBOL;
83 
84     return nCaption;
85 }
86 
lcl_CaptionToLabel(sal_Int32 nCaption)87 chart2::DataPointLabel lcl_CaptionToLabel( sal_Int32 nCaption )
88 {
89     chart2::DataPointLabel aLabel(false,false,false,false);
90 
91     if( nCaption & ::com::sun::star::chart::ChartDataCaption::VALUE )
92         aLabel.ShowNumber = true;
93     if( nCaption & ::com::sun::star::chart::ChartDataCaption::PERCENT )
94         aLabel.ShowNumberInPercent = true;
95     if( nCaption & ::com::sun::star::chart::ChartDataCaption::TEXT )
96         aLabel.ShowCategoryName = true;
97     if( nCaption & ::com::sun::star::chart::ChartDataCaption::SYMBOL )
98         aLabel.ShowLegendSymbol = true;
99 
100     return aLabel;
101 }
102 
lcl_addWrappedProperties(std::vector<WrappedProperty * > & rList,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact,tSeriesOrDiagramPropertyType ePropertyType)103 void lcl_addWrappedProperties( std::vector< WrappedProperty* >& rList
104                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact
105                                     , tSeriesOrDiagramPropertyType ePropertyType )
106 {
107     //if !spChart2ModelContact.get() is then the created properties do belong to a single series or single datapoint
108     //otherwise they do belong to the whole diagram
109 
110     rList.push_back( new WrappedDataCaptionProperty( spChart2ModelContact, ePropertyType ) );
111 }
112 
113 }//anonymous namespace
114 
115 //-----------------------------------------------------------------------------
116 //-----------------------------------------------------------------------------
117 //-----------------------------------------------------------------------------
addProperties(::std::vector<Property> & rOutProperties)118 void WrappedDataCaptionProperties::addProperties( ::std::vector< Property > & rOutProperties )
119 {
120     rOutProperties.push_back(
121         Property( C2U( "DataCaption" ),
122                   PROP_CHART_DATAPOINT_DATA_CAPTION,
123                   ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
124                   beans::PropertyAttribute::BOUND
125                   | beans::PropertyAttribute::MAYBEDEFAULT ));
126 }
127 
128 //-----------------------------------------------------------------------------
129 //-----------------------------------------------------------------------------
130 
addWrappedPropertiesForSeries(std::vector<WrappedProperty * > & rList,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)131 void WrappedDataCaptionProperties::addWrappedPropertiesForSeries( std::vector< WrappedProperty* >& rList
132                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
133 {
134     lcl_addWrappedProperties( rList, spChart2ModelContact, DATA_SERIES );
135 }
136 
137 //-----------------------------------------------------------------------------
138 //-----------------------------------------------------------------------------
139 
addWrappedPropertiesForDiagram(std::vector<WrappedProperty * > & rList,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)140 void WrappedDataCaptionProperties::addWrappedPropertiesForDiagram( std::vector< WrappedProperty* >& rList
141                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
142 {
143     lcl_addWrappedProperties( rList, spChart2ModelContact, DIAGRAM );
144 }
145 
146 //-----------------------------------------------------------------------------
147 //-----------------------------------------------------------------------------
148 //-----------------------------------------------------------------------------
149 
WrappedDataCaptionProperty(::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact,tSeriesOrDiagramPropertyType ePropertyType)150 WrappedDataCaptionProperty::WrappedDataCaptionProperty(
151       ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact
152     , tSeriesOrDiagramPropertyType ePropertyType )
153         : WrappedSeriesOrDiagramProperty< sal_Int32 >( C2U("DataCaption")
154             , uno::makeAny( sal_Int32(0) ), spChart2ModelContact, ePropertyType )
155 {
156 }
~WrappedDataCaptionProperty()157 WrappedDataCaptionProperty::~WrappedDataCaptionProperty()
158 {
159 }
160 
getValueFromSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet) const161 sal_Int32 WrappedDataCaptionProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
162 {
163     sal_Int32 aRet = 0;
164     m_aDefaultValue >>= aRet;
165     chart2::DataPointLabel aLabel;
166     if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue(C2U("Label")) >>= aLabel ) )
167         aRet = lcl_LabelToCaption( aLabel );
168     return aRet;
169 }
170 
setValueToSeries(const Reference<beans::XPropertySet> & xSeriesPropertySet,sal_Int32 nCaption) const171 void WrappedDataCaptionProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, sal_Int32 nCaption ) const
172 {
173     if(!xSeriesPropertySet.is())
174         return;
175 
176     chart2::DataPointLabel aLabel = lcl_CaptionToLabel( nCaption );
177     xSeriesPropertySet->setPropertyValue( C2U("Label"), uno::makeAny( aLabel ) );
178 }
179 
180 //-----------------------------------------------------------------------------
181 //-----------------------------------------------------------------------------
182 //-----------------------------------------------------------------------------
183 
184 } //namespace wrapper
185 } //namespace chart
186 //.............................................................................
187