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_chartcontroller.hxx"
26
27 #include "WrappedSplineProperties.hxx"
28 #include "macros.hxx"
29 #include "FastPropertyIdRanges.hxx"
30 #include "DiagramHelper.hxx"
31 #include <com/sun/star/chart2/CurveStyle.hpp>
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
33
34 using namespace ::com::sun::star;
35 using ::com::sun::star::uno::Any;
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::uno::Sequence;
38 using ::com::sun::star::beans::Property;
39 using ::rtl::OUString;
40
41 //.............................................................................
42 namespace chart
43 {
44 namespace wrapper
45 {
46
47 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
50
51 //PROPERTYTYPE is the type of the outer property
52
53 template< typename PROPERTYTYPE >
54 class WrappedSplineProperty : public WrappedProperty
55 {
56 public:
WrappedSplineProperty(const::rtl::OUString & rOuterName,const::rtl::OUString & rInnerName,const::com::sun::star::uno::Any & rDefaulValue,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)57 explicit WrappedSplineProperty( const ::rtl::OUString& rOuterName, const ::rtl::OUString& rInnerName
58 , const ::com::sun::star::uno::Any& rDefaulValue
59 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
60 : WrappedProperty(rOuterName,OUString())
61 , m_spChart2ModelContact(spChart2ModelContact)
62 , m_aOuterValue(rDefaulValue)
63 , m_aDefaultValue(rDefaulValue)
64 , m_aOwnInnerName(rInnerName)
65 {
66 }
~WrappedSplineProperty()67 virtual ~WrappedSplineProperty() {};
68
detectInnerValue(PROPERTYTYPE & rValue,bool & rHasAmbiguousValue) const69 bool detectInnerValue( PROPERTYTYPE& rValue, bool& rHasAmbiguousValue ) const
70 {
71 bool bHasDetectableInnerValue = false;
72 rHasAmbiguousValue = false;
73 Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > > aChartTypes(
74 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
75 for( sal_Int32 nN = aChartTypes.getLength(); nN--; )
76 {
77 try
78 {
79 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xChartTypePropertySet( aChartTypes[nN], ::com::sun::star::uno::UNO_QUERY );
80
81 Any aSingleValue = this->convertInnerToOuterValue( xChartTypePropertySet->getPropertyValue(m_aOwnInnerName) );
82 PROPERTYTYPE aCurValue = PROPERTYTYPE();
83 aSingleValue >>= aCurValue;
84 if( !bHasDetectableInnerValue )
85 rValue = aCurValue;
86 else
87 {
88 if( rValue != aCurValue )
89 {
90 rHasAmbiguousValue = true;
91 break;
92 }
93 else
94 rValue = aCurValue;
95 }
96 bHasDetectableInnerValue = true;
97 }
98 catch( uno::Exception & ex )
99 {
100 //spline properties are not supported by all charttypes
101 //in that cases this exception is ok
102 ex.Context.is();//to have debug information without compilation warnings
103 }
104 }
105 return bHasDetectableInnerValue;
106 }
setPropertyValue(const::com::sun::star::uno::Any & rOuterValue,const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertySet> &) const107 void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const
108 {
109 PROPERTYTYPE aNewValue;
110 if( ! (rOuterValue >>= aNewValue) )
111 throw ::com::sun::star::lang::IllegalArgumentException( C2U("spline property requires different type"), 0, 0 );
112
113 m_aOuterValue = rOuterValue;
114
115 bool bHasAmbiguousValue = false;
116 PROPERTYTYPE aOldValue;
117 if( detectInnerValue( aOldValue, bHasAmbiguousValue ) )
118 {
119 if( bHasAmbiguousValue || aNewValue != aOldValue )
120 {
121 Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > > aChartTypes(
122 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
123 for( sal_Int32 nN = aChartTypes.getLength(); nN--; )
124 {
125 try
126 {
127 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xChartTypePropertySet( aChartTypes[nN], ::com::sun::star::uno::UNO_QUERY );
128 if( xChartTypePropertySet.is() )
129 {
130 xChartTypePropertySet->setPropertyValue(m_aOwnInnerName,this->convertOuterToInnerValue(uno::makeAny(aNewValue)));
131 }
132 }
133 catch( uno::Exception & ex )
134 {
135 //spline properties are not supported by all charttypes
136 //in that cases this exception is ok
137 ex.Context.is();//to have debug information without compilation warnings
138 }
139 }
140 }
141 }
142 }
143
getPropertyValue(const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertySet> &) const144 ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const
145 {
146 bool bHasAmbiguousValue = false;
147 PROPERTYTYPE aValue;
148 if( detectInnerValue( aValue, bHasAmbiguousValue ) )
149 {
150 m_aOuterValue <<= aValue;
151 }
152 return m_aOuterValue;
153 }
154
getPropertyDefault(const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertyState> &) const155 ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& /*xInnerPropertyState*/ ) const
156 {
157 return m_aDefaultValue;
158 }
159
160 protected:
161 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
162 mutable ::com::sun::star::uno::Any m_aOuterValue;
163 ::com::sun::star::uno::Any m_aDefaultValue;
164 // this inner name is not set as inner name at the base class
165 const OUString m_aOwnInnerName;
166 };
167
168 class WrappedSplineTypeProperty : public WrappedSplineProperty< sal_Int32 >
169 {
170 public:
171 explicit WrappedSplineTypeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
172 virtual ~WrappedSplineTypeProperty();
173
174 virtual ::com::sun::star::uno::Any convertInnerToOuterValue( const ::com::sun::star::uno::Any& rInnerValue ) const;
175 virtual ::com::sun::star::uno::Any convertOuterToInnerValue( const ::com::sun::star::uno::Any& rOuterValue ) const;
176 };
177
178 namespace
179 {
180 enum
181 {
182 //spline properties
183 PROP_CHART_SPLINE_TYPE = FAST_PROPERTY_ID_START_CHART_SPLINE_PROP
184 , PROP_CHART_SPLINE_ORDER
185 , PROP_CHART_SPLINE_RESOLUTION
186 };
187
188 }//anonymous namespace
189
190 //-----------------------------------------------------------------------------
191 //-----------------------------------------------------------------------------
192 //-----------------------------------------------------------------------------
addProperties(::std::vector<Property> & rOutProperties)193 void WrappedSplineProperties::addProperties( ::std::vector< Property > & rOutProperties )
194 {
195 rOutProperties.push_back(
196 Property( C2U( "SplineType" ),
197 PROP_CHART_SPLINE_TYPE,
198 ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
199 beans::PropertyAttribute::BOUND
200 | beans::PropertyAttribute::MAYBEDEFAULT
201 | beans::PropertyAttribute::MAYBEVOID ));
202 rOutProperties.push_back(
203 Property( C2U( "SplineOrder" ),
204 PROP_CHART_SPLINE_ORDER,
205 ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
206 beans::PropertyAttribute::BOUND
207 | beans::PropertyAttribute::MAYBEDEFAULT
208 | beans::PropertyAttribute::MAYBEVOID ));
209 rOutProperties.push_back(
210 Property( C2U( "SplineResolution" ),
211 PROP_CHART_SPLINE_RESOLUTION,
212 ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
213 beans::PropertyAttribute::BOUND
214 | beans::PropertyAttribute::MAYBEDEFAULT
215 | beans::PropertyAttribute::MAYBEVOID ));
216 }
217
218 //-----------------------------------------------------------------------------
219 //-----------------------------------------------------------------------------
220
addWrappedProperties(std::vector<WrappedProperty * > & rList,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)221 void WrappedSplineProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
222 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
223 {
224 rList.push_back( new WrappedSplineTypeProperty( spChart2ModelContact ) );
225 rList.push_back( new WrappedSplineProperty<sal_Int32>( C2U("SplineOrder"), C2U("SplineOrder"), uno::makeAny(sal_Int32(3)), spChart2ModelContact ) );
226 rList.push_back( new WrappedSplineProperty<sal_Int32>( C2U("SplineResolution"), C2U("CurveResolution"), uno::makeAny(sal_Int32(20)), spChart2ModelContact ) );
227 }
228
229 //-----------------------------------------------------------------------------
230 //-----------------------------------------------------------------------------
231 //-----------------------------------------------------------------------------
232
233
WrappedSplineTypeProperty(::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)234 WrappedSplineTypeProperty::WrappedSplineTypeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
235 : WrappedSplineProperty<sal_Int32>( C2U("SplineType"), C2U("CurveStyle"), uno::makeAny(sal_Int32(0)), spChart2ModelContact )
236 {
237 }
~WrappedSplineTypeProperty()238 WrappedSplineTypeProperty::~WrappedSplineTypeProperty()
239 {
240 }
convertInnerToOuterValue(const Any & rInnerValue) const241 Any WrappedSplineTypeProperty::convertInnerToOuterValue( const Any& rInnerValue ) const
242 {
243 chart2::CurveStyle aInnerValue = chart2::CurveStyle_LINES;
244 rInnerValue >>= aInnerValue;
245
246 sal_Int32 nOuterValue;
247 if( chart2::CurveStyle_CUBIC_SPLINES == aInnerValue )
248 nOuterValue = 1;
249 else if( chart2::CurveStyle_B_SPLINES == aInnerValue )
250 nOuterValue = 2;
251 else
252 nOuterValue = 0;
253
254 return uno::makeAny(nOuterValue);
255 }
convertOuterToInnerValue(const Any & rOuterValue) const256 Any WrappedSplineTypeProperty::convertOuterToInnerValue( const Any& rOuterValue ) const
257 {
258 sal_Int32 nOuterValue=0;
259 rOuterValue >>= nOuterValue;
260
261 chart2::CurveStyle aInnerValue;
262
263 if(1==nOuterValue)
264 aInnerValue = chart2::CurveStyle_CUBIC_SPLINES;
265 else if(2==nOuterValue)
266 aInnerValue = chart2::CurveStyle_B_SPLINES;
267 else
268 aInnerValue = chart2::CurveStyle_LINES;
269
270 return uno::makeAny(aInnerValue);
271 }
272 //-----------------------------------------------------------------------------
273 //-----------------------------------------------------------------------------
274 //-----------------------------------------------------------------------------
275
276 } //namespace wrapper
277 } //namespace chart
278 //.............................................................................
279