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