1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WrappedSplineProperties.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "WrappedSplineProperties.hxx"
36 #include "FastPropertyIdRanges.hxx"
37 #include "DiagramHelper.hxx"
38 #include <com/sun/star/chart2/CurveStyle.hpp>
39 #include <com/sun/star/beans/PropertyAttribute.hpp>
41 using namespace ::com::sun::star
;
42 using ::com::sun::star::uno::Any
;
43 using ::com::sun::star::uno::Reference
;
44 using ::com::sun::star::uno::Sequence
;
45 using ::com::sun::star::beans::Property
;
46 using ::rtl::OUString
;
48 //.............................................................................
54 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
58 //PROPERTYTYPE is the type of the outer property
60 template< typename PROPERTYTYPE
>
61 class WrappedSplineProperty
: public WrappedProperty
64 explicit WrappedSplineProperty( const ::rtl::OUString
& rOuterName
, const ::rtl::OUString
& rInnerName
65 , const ::com::sun::star::uno::Any
& rDefaulValue
66 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
67 : WrappedProperty(rOuterName
,OUString())
68 , m_spChart2ModelContact(spChart2ModelContact
)
69 , m_aOuterValue(rDefaulValue
)
70 , m_aDefaultValue(rDefaulValue
)
71 , m_aOwnInnerName(rInnerName
)
74 virtual ~WrappedSplineProperty() {};
76 bool detectInnerValue( PROPERTYTYPE
& rValue
, bool& rHasAmbiguousValue
) const
78 bool bHasDetectableInnerValue
= false;
79 rHasAmbiguousValue
= false;
80 Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::chart2::XChartType
> > aChartTypes(
81 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact
->getChart2Diagram() ) );
82 for( sal_Int32 nN
= aChartTypes
.getLength(); nN
--; )
86 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xChartTypePropertySet( aChartTypes
[nN
], ::com::sun::star::uno::UNO_QUERY
);
88 Any aSingleValue
= this->convertInnerToOuterValue( xChartTypePropertySet
->getPropertyValue(m_aOwnInnerName
) );
89 PROPERTYTYPE aCurValue
= PROPERTYTYPE();
90 aSingleValue
>>= aCurValue
;
91 if( !bHasDetectableInnerValue
)
95 if( rValue
!= aCurValue
)
97 rHasAmbiguousValue
= true;
103 bHasDetectableInnerValue
= true;
105 catch( uno::Exception
& ex
)
107 //spline properties are not supported by all charttypes
108 //in that cases this exception is ok
109 ex
.Context
.is();//to have debug information without compilation warnings
112 return bHasDetectableInnerValue
;
114 void setPropertyValue( const ::com::sun::star::uno::Any
& rOuterValue
, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& /*xInnerPropertySet*/ ) const
115 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
)
117 PROPERTYTYPE aNewValue
;
118 if( ! (rOuterValue
>>= aNewValue
) )
119 throw ::com::sun::star::lang::IllegalArgumentException( C2U("spline property requires different type"), 0, 0 );
121 m_aOuterValue
= rOuterValue
;
123 bool bHasAmbiguousValue
= false;
124 PROPERTYTYPE aOldValue
;
125 if( detectInnerValue( aOldValue
, bHasAmbiguousValue
) )
127 if( bHasAmbiguousValue
|| aNewValue
!= aOldValue
)
129 Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::chart2::XChartType
> > aChartTypes(
130 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact
->getChart2Diagram() ) );
131 for( sal_Int32 nN
= aChartTypes
.getLength(); nN
--; )
135 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xChartTypePropertySet( aChartTypes
[nN
], ::com::sun::star::uno::UNO_QUERY
);
136 if( xChartTypePropertySet
.is() )
138 xChartTypePropertySet
->setPropertyValue(m_aOwnInnerName
,this->convertOuterToInnerValue(uno::makeAny(aNewValue
)));
141 catch( uno::Exception
& ex
)
143 //spline properties are not supported by all charttypes
144 //in that cases this exception is ok
145 ex
.Context
.is();//to have debug information without compilation warnings
152 ::com::sun::star::uno::Any
getPropertyValue( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& /*xInnerPropertySet*/ ) const
153 throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
)
155 bool bHasAmbiguousValue
= false;
157 if( detectInnerValue( aValue
, bHasAmbiguousValue
) )
159 m_aOuterValue
<<= aValue
;
161 return m_aOuterValue
;
164 ::com::sun::star::uno::Any
getPropertyDefault( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyState
>& /*xInnerPropertyState*/ ) const
165 throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
)
167 return m_aDefaultValue
;
171 ::boost::shared_ptr
< Chart2ModelContact
> m_spChart2ModelContact
;
172 mutable ::com::sun::star::uno::Any m_aOuterValue
;
173 ::com::sun::star::uno::Any m_aDefaultValue
;
174 // this inner name is not set as inner name at the base class
175 const OUString m_aOwnInnerName
;
178 class WrappedSplineTypeProperty
: public WrappedSplineProperty
< sal_Int32
>
181 explicit WrappedSplineTypeProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
);
182 virtual ~WrappedSplineTypeProperty();
184 virtual ::com::sun::star::uno::Any
convertInnerToOuterValue( const ::com::sun::star::uno::Any
& rInnerValue
) const;
185 virtual ::com::sun::star::uno::Any
convertOuterToInnerValue( const ::com::sun::star::uno::Any
& rOuterValue
) const;
193 PROP_CHART_SPLINE_TYPE
= FAST_PROPERTY_ID_START_CHART_SPLINE_PROP
194 , PROP_CHART_SPLINE_ORDER
195 , PROP_CHART_SPLINE_RESOLUTION
198 }//anonymous namespace
200 //-----------------------------------------------------------------------------
201 //-----------------------------------------------------------------------------
202 //-----------------------------------------------------------------------------
204 void WrappedSplineProperties::addProperties( ::std::vector
< Property
> & rOutProperties
)
206 rOutProperties
.push_back(
207 Property( C2U( "SplineType" ),
208 PROP_CHART_SPLINE_TYPE
,
209 ::getCppuType( reinterpret_cast< sal_Int32
* >(0)),
210 beans::PropertyAttribute::BOUND
211 | beans::PropertyAttribute::MAYBEDEFAULT
212 | beans::PropertyAttribute::MAYBEVOID
));
213 rOutProperties
.push_back(
214 Property( C2U( "SplineOrder" ),
215 PROP_CHART_SPLINE_ORDER
,
216 ::getCppuType( reinterpret_cast< sal_Int32
* >(0)),
217 beans::PropertyAttribute::BOUND
218 | beans::PropertyAttribute::MAYBEDEFAULT
219 | beans::PropertyAttribute::MAYBEVOID
));
220 rOutProperties
.push_back(
221 Property( C2U( "SplineResolution" ),
222 PROP_CHART_SPLINE_RESOLUTION
,
223 ::getCppuType( reinterpret_cast< sal_Int32
* >(0)),
224 beans::PropertyAttribute::BOUND
225 | beans::PropertyAttribute::MAYBEDEFAULT
226 | beans::PropertyAttribute::MAYBEVOID
));
229 //-----------------------------------------------------------------------------
230 //-----------------------------------------------------------------------------
233 void WrappedSplineProperties::addWrappedProperties( std::vector
< WrappedProperty
* >& rList
234 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
236 rList
.push_back( new WrappedSplineTypeProperty( spChart2ModelContact
) );
237 rList
.push_back( new WrappedSplineProperty
<sal_Int32
>( C2U("SplineOrder"), C2U("SplineOrder"), uno::makeAny(sal_Int32(2)), spChart2ModelContact
) );
238 rList
.push_back( new WrappedSplineProperty
<sal_Int32
>( C2U("SplineResolution"), C2U("CurveResolution"), uno::makeAny(sal_Int32(20)), spChart2ModelContact
) );
241 //-----------------------------------------------------------------------------
242 //-----------------------------------------------------------------------------
243 //-----------------------------------------------------------------------------
246 WrappedSplineTypeProperty::WrappedSplineTypeProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
247 : WrappedSplineProperty
<sal_Int32
>( C2U("SplineType"), C2U("CurveStyle"), uno::makeAny(sal_Int32(0)), spChart2ModelContact
)
250 WrappedSplineTypeProperty::~WrappedSplineTypeProperty()
253 Any
WrappedSplineTypeProperty::convertInnerToOuterValue( const Any
& rInnerValue
) const
255 chart2::CurveStyle aInnerValue
= chart2::CurveStyle_LINES
;
256 rInnerValue
>>= aInnerValue
;
258 sal_Int32 nOuterValue
;
259 if( chart2::CurveStyle_CUBIC_SPLINES
== aInnerValue
)
261 else if( chart2::CurveStyle_B_SPLINES
== aInnerValue
)
266 return uno::makeAny(nOuterValue
);
268 Any
WrappedSplineTypeProperty::convertOuterToInnerValue( const Any
& rOuterValue
) const
270 sal_Int32 nOuterValue
=0;
271 rOuterValue
>>= nOuterValue
;
273 chart2::CurveStyle aInnerValue
;
276 aInnerValue
= chart2::CurveStyle_CUBIC_SPLINES
;
277 else if(2==nOuterValue
)
278 aInnerValue
= chart2::CurveStyle_B_SPLINES
;
280 aInnerValue
= chart2::CurveStyle_LINES
;
282 return uno::makeAny(aInnerValue
);
284 //-----------------------------------------------------------------------------
285 //-----------------------------------------------------------------------------
286 //-----------------------------------------------------------------------------
288 } //namespace wrapper
290 //.............................................................................