1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "WrappedSplineProperties.hxx"
33 #include "FastPropertyIdRanges.hxx"
34 #include "DiagramHelper.hxx"
35 #include <com/sun/star/chart2/CurveStyle.hpp>
36 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 using namespace ::com::sun::star
;
39 using ::com::sun::star::uno::Any
;
40 using ::com::sun::star::uno::Reference
;
41 using ::com::sun::star::uno::Sequence
;
42 using ::com::sun::star::beans::Property
;
43 using ::rtl::OUString
;
45 //.............................................................................
51 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 //PROPERTYTYPE is the type of the outer property
57 template< typename PROPERTYTYPE
>
58 class WrappedSplineProperty
: public WrappedProperty
61 explicit WrappedSplineProperty( const ::rtl::OUString
& rOuterName
, const ::rtl::OUString
& rInnerName
62 , const ::com::sun::star::uno::Any
& rDefaulValue
63 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
64 : WrappedProperty(rOuterName
,OUString())
65 , m_spChart2ModelContact(spChart2ModelContact
)
66 , m_aOuterValue(rDefaulValue
)
67 , m_aDefaultValue(rDefaulValue
)
68 , m_aOwnInnerName(rInnerName
)
71 virtual ~WrappedSplineProperty() {};
73 bool detectInnerValue( PROPERTYTYPE
& rValue
, bool& rHasAmbiguousValue
) const
75 bool bHasDetectableInnerValue
= false;
76 rHasAmbiguousValue
= false;
77 Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::chart2::XChartType
> > aChartTypes(
78 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact
->getChart2Diagram() ) );
79 for( sal_Int32 nN
= aChartTypes
.getLength(); nN
--; )
83 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xChartTypePropertySet( aChartTypes
[nN
], ::com::sun::star::uno::UNO_QUERY
);
85 Any aSingleValue
= this->convertInnerToOuterValue( xChartTypePropertySet
->getPropertyValue(m_aOwnInnerName
) );
86 PROPERTYTYPE aCurValue
= PROPERTYTYPE();
87 aSingleValue
>>= aCurValue
;
88 if( !bHasDetectableInnerValue
)
92 if( rValue
!= aCurValue
)
94 rHasAmbiguousValue
= true;
100 bHasDetectableInnerValue
= true;
102 catch( uno::Exception
& ex
)
104 //spline properties are not supported by all charttypes
105 //in that cases this exception is ok
106 ex
.Context
.is();//to have debug information without compilation warnings
109 return bHasDetectableInnerValue
;
111 void setPropertyValue( const ::com::sun::star::uno::Any
& rOuterValue
, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& /*xInnerPropertySet*/ ) const
112 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
)
114 PROPERTYTYPE aNewValue
;
115 if( ! (rOuterValue
>>= aNewValue
) )
116 throw ::com::sun::star::lang::IllegalArgumentException( C2U("spline property requires different type"), 0, 0 );
118 m_aOuterValue
= rOuterValue
;
120 bool bHasAmbiguousValue
= false;
121 PROPERTYTYPE aOldValue
;
122 if( detectInnerValue( aOldValue
, bHasAmbiguousValue
) )
124 if( bHasAmbiguousValue
|| aNewValue
!= aOldValue
)
126 Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::chart2::XChartType
> > aChartTypes(
127 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact
->getChart2Diagram() ) );
128 for( sal_Int32 nN
= aChartTypes
.getLength(); nN
--; )
132 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xChartTypePropertySet( aChartTypes
[nN
], ::com::sun::star::uno::UNO_QUERY
);
133 if( xChartTypePropertySet
.is() )
135 xChartTypePropertySet
->setPropertyValue(m_aOwnInnerName
,this->convertOuterToInnerValue(uno::makeAny(aNewValue
)));
138 catch( uno::Exception
& ex
)
140 //spline properties are not supported by all charttypes
141 //in that cases this exception is ok
142 ex
.Context
.is();//to have debug information without compilation warnings
149 ::com::sun::star::uno::Any
getPropertyValue( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& /*xInnerPropertySet*/ ) const
150 throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
)
152 bool bHasAmbiguousValue
= false;
154 if( detectInnerValue( aValue
, bHasAmbiguousValue
) )
156 m_aOuterValue
<<= aValue
;
158 return m_aOuterValue
;
161 ::com::sun::star::uno::Any
getPropertyDefault( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyState
>& /*xInnerPropertyState*/ ) const
162 throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
)
164 return m_aDefaultValue
;
168 ::boost::shared_ptr
< Chart2ModelContact
> m_spChart2ModelContact
;
169 mutable ::com::sun::star::uno::Any m_aOuterValue
;
170 ::com::sun::star::uno::Any m_aDefaultValue
;
171 // this inner name is not set as inner name at the base class
172 const OUString m_aOwnInnerName
;
175 class WrappedSplineTypeProperty
: public WrappedSplineProperty
< sal_Int32
>
178 explicit WrappedSplineTypeProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
);
179 virtual ~WrappedSplineTypeProperty();
181 virtual ::com::sun::star::uno::Any
convertInnerToOuterValue( const ::com::sun::star::uno::Any
& rInnerValue
) const;
182 virtual ::com::sun::star::uno::Any
convertOuterToInnerValue( const ::com::sun::star::uno::Any
& rOuterValue
) const;
190 PROP_CHART_SPLINE_TYPE
= FAST_PROPERTY_ID_START_CHART_SPLINE_PROP
191 , PROP_CHART_SPLINE_ORDER
192 , PROP_CHART_SPLINE_RESOLUTION
195 }//anonymous namespace
197 //-----------------------------------------------------------------------------
198 //-----------------------------------------------------------------------------
199 //-----------------------------------------------------------------------------
201 void WrappedSplineProperties::addProperties( ::std::vector
< Property
> & rOutProperties
)
203 rOutProperties
.push_back(
204 Property( C2U( "SplineType" ),
205 PROP_CHART_SPLINE_TYPE
,
206 ::getCppuType( reinterpret_cast< sal_Int32
* >(0)),
207 beans::PropertyAttribute::BOUND
208 | beans::PropertyAttribute::MAYBEDEFAULT
209 | beans::PropertyAttribute::MAYBEVOID
));
210 rOutProperties
.push_back(
211 Property( C2U( "SplineOrder" ),
212 PROP_CHART_SPLINE_ORDER
,
213 ::getCppuType( reinterpret_cast< sal_Int32
* >(0)),
214 beans::PropertyAttribute::BOUND
215 | beans::PropertyAttribute::MAYBEDEFAULT
216 | beans::PropertyAttribute::MAYBEVOID
));
217 rOutProperties
.push_back(
218 Property( C2U( "SplineResolution" ),
219 PROP_CHART_SPLINE_RESOLUTION
,
220 ::getCppuType( reinterpret_cast< sal_Int32
* >(0)),
221 beans::PropertyAttribute::BOUND
222 | beans::PropertyAttribute::MAYBEDEFAULT
223 | beans::PropertyAttribute::MAYBEVOID
));
226 //-----------------------------------------------------------------------------
227 //-----------------------------------------------------------------------------
230 void WrappedSplineProperties::addWrappedProperties( std::vector
< WrappedProperty
* >& rList
231 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
233 rList
.push_back( new WrappedSplineTypeProperty( spChart2ModelContact
) );
234 rList
.push_back( new WrappedSplineProperty
<sal_Int32
>( C2U("SplineOrder"), C2U("SplineOrder"), uno::makeAny(sal_Int32(2)), spChart2ModelContact
) );
235 rList
.push_back( new WrappedSplineProperty
<sal_Int32
>( C2U("SplineResolution"), C2U("CurveResolution"), uno::makeAny(sal_Int32(20)), spChart2ModelContact
) );
238 //-----------------------------------------------------------------------------
239 //-----------------------------------------------------------------------------
240 //-----------------------------------------------------------------------------
243 WrappedSplineTypeProperty::WrappedSplineTypeProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
244 : WrappedSplineProperty
<sal_Int32
>( C2U("SplineType"), C2U("CurveStyle"), uno::makeAny(sal_Int32(0)), spChart2ModelContact
)
247 WrappedSplineTypeProperty::~WrappedSplineTypeProperty()
250 Any
WrappedSplineTypeProperty::convertInnerToOuterValue( const Any
& rInnerValue
) const
252 chart2::CurveStyle aInnerValue
= chart2::CurveStyle_LINES
;
253 rInnerValue
>>= aInnerValue
;
255 sal_Int32 nOuterValue
;
256 if( chart2::CurveStyle_CUBIC_SPLINES
== aInnerValue
)
258 else if( chart2::CurveStyle_B_SPLINES
== aInnerValue
)
263 return uno::makeAny(nOuterValue
);
265 Any
WrappedSplineTypeProperty::convertOuterToInnerValue( const Any
& rOuterValue
) const
267 sal_Int32 nOuterValue
=0;
268 rOuterValue
>>= nOuterValue
;
270 chart2::CurveStyle aInnerValue
;
273 aInnerValue
= chart2::CurveStyle_CUBIC_SPLINES
;
274 else if(2==nOuterValue
)
275 aInnerValue
= chart2::CurveStyle_B_SPLINES
;
277 aInnerValue
= chart2::CurveStyle_LINES
;
279 return uno::makeAny(aInnerValue
);
281 //-----------------------------------------------------------------------------
282 //-----------------------------------------------------------------------------
283 //-----------------------------------------------------------------------------
285 } //namespace wrapper
287 //.............................................................................