1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 
31 #include "WrappedDataCaptionProperties.hxx"
32 #include "WrappedSeriesOrDiagramProperty.hxx"
33 #include "macros.hxx"
34 #include "FastPropertyIdRanges.hxx"
35 #include <com/sun/star/chart2/DataPointLabel.hpp>
36 #include <com/sun/star/chart/ChartDataCaption.hpp>
37 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 
39 using namespace ::com::sun::star;
40 using ::com::sun::star::uno::Any;
41 using ::com::sun::star::uno::Reference;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::beans::Property;
44 using ::rtl::OUString;
45 
46 //.............................................................................
47 namespace chart
48 {
49 namespace wrapper
50 {
51 
52 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
55 
56 class WrappedDataCaptionProperty : public WrappedSeriesOrDiagramProperty< sal_Int32 >
57 {
58 public:
59     virtual sal_Int32 getValueFromSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet ) const;
60     virtual void setValueToSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet, sal_Int32 aNewValue ) const;
61 
62     explicit WrappedDataCaptionProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact,
63                                          tSeriesOrDiagramPropertyType ePropertyType );
64     virtual ~WrappedDataCaptionProperty();
65 };
66 
67 namespace
68 {
69 enum
70 {
71     //data caption properties
72     PROP_CHART_DATAPOINT_DATA_CAPTION = FAST_PROPERTY_ID_START_CHART_DATACAPTION_PROP
73 };
74 
75 sal_Int32 lcl_LabelToCaption( const chart2::DataPointLabel& rLabel )
76 {
77     sal_Int32 nCaption=0;
78 
79     if( rLabel.ShowNumber )
80         nCaption |= ::com::sun::star::chart::ChartDataCaption::VALUE;
81     if( rLabel.ShowNumberInPercent )
82         nCaption |= ::com::sun::star::chart::ChartDataCaption::PERCENT;
83     if( rLabel.ShowCategoryName )
84         nCaption |= ::com::sun::star::chart::ChartDataCaption::TEXT;
85     if( rLabel.ShowLegendSymbol )
86         nCaption |= ::com::sun::star::chart::ChartDataCaption::SYMBOL;
87 
88     return nCaption;
89 }
90 
91 chart2::DataPointLabel lcl_CaptionToLabel( sal_Int32 nCaption )
92 {
93     chart2::DataPointLabel aLabel(false,false,false,false);
94 
95     if( nCaption & ::com::sun::star::chart::ChartDataCaption::VALUE )
96         aLabel.ShowNumber = true;
97     if( nCaption & ::com::sun::star::chart::ChartDataCaption::PERCENT )
98         aLabel.ShowNumberInPercent = true;
99     if( nCaption & ::com::sun::star::chart::ChartDataCaption::TEXT )
100         aLabel.ShowCategoryName = true;
101     if( nCaption & ::com::sun::star::chart::ChartDataCaption::SYMBOL )
102         aLabel.ShowLegendSymbol = true;
103 
104     return aLabel;
105 }
106 
107 void lcl_addWrappedProperties( std::vector< WrappedProperty* >& rList
108                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact
109                                     , tSeriesOrDiagramPropertyType ePropertyType )
110 {
111     //if !spChart2ModelContact.get() is then the created properties do belong to a single series or single datapoint
112     //otherwise they do belong to the whole diagram
113 
114     rList.push_back( new WrappedDataCaptionProperty( spChart2ModelContact, ePropertyType ) );
115 }
116 
117 }//anonymous namespace
118 
119 //-----------------------------------------------------------------------------
120 //-----------------------------------------------------------------------------
121 //-----------------------------------------------------------------------------
122 void WrappedDataCaptionProperties::addProperties( ::std::vector< Property > & rOutProperties )
123 {
124     rOutProperties.push_back(
125         Property( C2U( "DataCaption" ),
126                   PROP_CHART_DATAPOINT_DATA_CAPTION,
127                   ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
128                   beans::PropertyAttribute::BOUND
129                   | beans::PropertyAttribute::MAYBEDEFAULT ));
130 }
131 
132 //-----------------------------------------------------------------------------
133 //-----------------------------------------------------------------------------
134 
135 void WrappedDataCaptionProperties::addWrappedPropertiesForSeries( std::vector< WrappedProperty* >& rList
136                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
137 {
138     lcl_addWrappedProperties( rList, spChart2ModelContact, DATA_SERIES );
139 }
140 
141 //-----------------------------------------------------------------------------
142 //-----------------------------------------------------------------------------
143 
144 void WrappedDataCaptionProperties::addWrappedPropertiesForDiagram( std::vector< WrappedProperty* >& rList
145                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
146 {
147     lcl_addWrappedProperties( rList, spChart2ModelContact, DIAGRAM );
148 }
149 
150 //-----------------------------------------------------------------------------
151 //-----------------------------------------------------------------------------
152 //-----------------------------------------------------------------------------
153 
154 WrappedDataCaptionProperty::WrappedDataCaptionProperty(
155       ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact
156     , tSeriesOrDiagramPropertyType ePropertyType )
157         : WrappedSeriesOrDiagramProperty< sal_Int32 >( C2U("DataCaption")
158             , uno::makeAny( sal_Int32(0) ), spChart2ModelContact, ePropertyType )
159 {
160 }
161 WrappedDataCaptionProperty::~WrappedDataCaptionProperty()
162 {
163 }
164 
165 sal_Int32 WrappedDataCaptionProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
166 {
167     sal_Int32 aRet = 0;
168     m_aDefaultValue >>= aRet;
169     chart2::DataPointLabel aLabel;
170     if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue(C2U("Label")) >>= aLabel ) )
171         aRet = lcl_LabelToCaption( aLabel );
172     return aRet;
173 }
174 
175 void WrappedDataCaptionProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, sal_Int32 nCaption ) const
176 {
177     if(!xSeriesPropertySet.is())
178         return;
179 
180     chart2::DataPointLabel aLabel = lcl_CaptionToLabel( nCaption );
181     xSeriesPropertySet->setPropertyValue( C2U("Label"), uno::makeAny( aLabel ) );
182 }
183 
184 //-----------------------------------------------------------------------------
185 //-----------------------------------------------------------------------------
186 //-----------------------------------------------------------------------------
187 
188 } //namespace wrapper
189 } //namespace chart
190 //.............................................................................
191