Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "WrappedSplineProperties.hxx"
22 : #include "macros.hxx"
23 : #include "FastPropertyIdRanges.hxx"
24 : #include "DiagramHelper.hxx"
25 : #include <com/sun/star/chart2/CurveStyle.hpp>
26 : #include <com/sun/star/beans/PropertyAttribute.hpp>
27 :
28 : using namespace ::com::sun::star;
29 : using ::com::sun::star::uno::Any;
30 : using ::com::sun::star::uno::Reference;
31 : using ::com::sun::star::uno::Sequence;
32 : using ::com::sun::star::beans::Property;
33 : using ::rtl::OUString;
34 :
35 : //.............................................................................
36 : namespace chart
37 : {
38 : namespace wrapper
39 : {
40 :
41 : //-----------------------------------------------------------------------------
42 : //PROPERTYTYPE is the type of the outer property
43 :
44 : template< typename PROPERTYTYPE >
45 : class WrappedSplineProperty : public WrappedProperty
46 : {
47 : public:
48 120 : explicit WrappedSplineProperty( const ::rtl::OUString& rOuterName, const ::rtl::OUString& rInnerName
49 : , const ::com::sun::star::uno::Any& rDefaulValue
50 : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
51 : : WrappedProperty(rOuterName,OUString())
52 : , m_spChart2ModelContact(spChart2ModelContact)
53 : , m_aOuterValue(rDefaulValue)
54 : , m_aDefaultValue(rDefaulValue)
55 120 : , m_aOwnInnerName(rInnerName)
56 : {
57 120 : }
58 200 : virtual ~WrappedSplineProperty() {};
59 :
60 0 : bool detectInnerValue( PROPERTYTYPE& rValue, bool& rHasAmbiguousValue ) const
61 : {
62 0 : bool bHasDetectableInnerValue = false;
63 0 : rHasAmbiguousValue = false;
64 : Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > > aChartTypes(
65 0 : ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
66 0 : for( sal_Int32 nN = aChartTypes.getLength(); nN--; )
67 : {
68 : try
69 : {
70 0 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xChartTypePropertySet( aChartTypes[nN], ::com::sun::star::uno::UNO_QUERY );
71 :
72 0 : Any aSingleValue = this->convertInnerToOuterValue( xChartTypePropertySet->getPropertyValue(m_aOwnInnerName) );
73 0 : PROPERTYTYPE aCurValue = PROPERTYTYPE();
74 0 : aSingleValue >>= aCurValue;
75 0 : if( !bHasDetectableInnerValue )
76 0 : rValue = aCurValue;
77 : else
78 : {
79 0 : if( rValue != aCurValue )
80 : {
81 0 : rHasAmbiguousValue = true;
82 : break;
83 : }
84 : else
85 0 : rValue = aCurValue;
86 : }
87 0 : bHasDetectableInnerValue = true;
88 : }
89 0 : catch( uno::Exception & ex )
90 : {
91 : //spline properties are not supported by all charttypes
92 : //in that cases this exception is ok
93 0 : ex.Context.is();//to have debug information without compilation warnings
94 : }
95 : }
96 0 : return bHasDetectableInnerValue;
97 : }
98 0 : void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const
99 : 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)
100 : {
101 : PROPERTYTYPE aNewValue;
102 0 : if( ! (rOuterValue >>= aNewValue) )
103 0 : throw ::com::sun::star::lang::IllegalArgumentException( "spline property requires different type", 0, 0 );
104 :
105 0 : m_aOuterValue = rOuterValue;
106 :
107 0 : bool bHasAmbiguousValue = false;
108 0 : PROPERTYTYPE aOldValue = PROPERTYTYPE();
109 0 : if( detectInnerValue( aOldValue, bHasAmbiguousValue ) )
110 : {
111 0 : if( bHasAmbiguousValue || aNewValue != aOldValue )
112 : {
113 : Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > > aChartTypes(
114 0 : ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
115 0 : for( sal_Int32 nN = aChartTypes.getLength(); nN--; )
116 : {
117 : try
118 : {
119 0 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xChartTypePropertySet( aChartTypes[nN], ::com::sun::star::uno::UNO_QUERY );
120 0 : if( xChartTypePropertySet.is() )
121 : {
122 0 : xChartTypePropertySet->setPropertyValue(m_aOwnInnerName,this->convertOuterToInnerValue(uno::makeAny(aNewValue)));
123 : }
124 : }
125 0 : catch( uno::Exception & ex )
126 : {
127 : //spline properties are not supported by all charttypes
128 : //in that cases this exception is ok
129 0 : ex.Context.is();//to have debug information without compilation warnings
130 : }
131 : }
132 : }
133 : }
134 0 : }
135 :
136 0 : ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const
137 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
138 : {
139 0 : bool bHasAmbiguousValue = false;
140 : PROPERTYTYPE aValue;
141 0 : if( detectInnerValue( aValue, bHasAmbiguousValue ) )
142 : {
143 0 : m_aOuterValue <<= aValue;
144 : }
145 0 : return m_aOuterValue;
146 : }
147 :
148 0 : ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& /*xInnerPropertyState*/ ) const
149 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
150 : {
151 0 : return m_aDefaultValue;
152 : }
153 :
154 : protected:
155 : ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
156 : mutable ::com::sun::star::uno::Any m_aOuterValue;
157 : ::com::sun::star::uno::Any m_aDefaultValue;
158 : // this inner name is not set as inner name at the base class
159 : const OUString m_aOwnInnerName;
160 : };
161 :
162 : class WrappedSplineTypeProperty : public WrappedSplineProperty< sal_Int32 >
163 : {
164 : public:
165 : explicit WrappedSplineTypeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
166 : virtual ~WrappedSplineTypeProperty();
167 :
168 : virtual ::com::sun::star::uno::Any convertInnerToOuterValue( const ::com::sun::star::uno::Any& rInnerValue ) const;
169 : virtual ::com::sun::star::uno::Any convertOuterToInnerValue( const ::com::sun::star::uno::Any& rOuterValue ) const;
170 : };
171 :
172 : namespace
173 : {
174 : enum
175 : {
176 : //spline properties
177 : PROP_CHART_SPLINE_TYPE = FAST_PROPERTY_ID_START_CHART_SPLINE_PROP
178 : , PROP_CHART_SPLINE_ORDER
179 : , PROP_CHART_SPLINE_RESOLUTION
180 : };
181 :
182 : }//anonymous namespace
183 :
184 : //-----------------------------------------------------------------------------
185 1 : void WrappedSplineProperties::addProperties( ::std::vector< Property > & rOutProperties )
186 : {
187 : rOutProperties.push_back(
188 : Property( "SplineType",
189 : PROP_CHART_SPLINE_TYPE,
190 1 : ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
191 : beans::PropertyAttribute::BOUND
192 : | beans::PropertyAttribute::MAYBEDEFAULT
193 2 : | beans::PropertyAttribute::MAYBEVOID ));
194 : rOutProperties.push_back(
195 : Property( "SplineOrder",
196 : PROP_CHART_SPLINE_ORDER,
197 1 : ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
198 : beans::PropertyAttribute::BOUND
199 : | beans::PropertyAttribute::MAYBEDEFAULT
200 2 : | beans::PropertyAttribute::MAYBEVOID ));
201 : rOutProperties.push_back(
202 : Property( "SplineResolution",
203 : PROP_CHART_SPLINE_RESOLUTION,
204 1 : ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
205 : beans::PropertyAttribute::BOUND
206 : | beans::PropertyAttribute::MAYBEDEFAULT
207 2 : | beans::PropertyAttribute::MAYBEVOID ));
208 1 : }
209 :
210 : //-----------------------------------------------------------------------------
211 40 : void WrappedSplineProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
212 : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
213 : {
214 40 : rList.push_back( new WrappedSplineTypeProperty( spChart2ModelContact ) );
215 40 : rList.push_back( new WrappedSplineProperty<sal_Int32>( "SplineOrder", "SplineOrder", uno::makeAny(sal_Int32(3)), spChart2ModelContact ) );
216 40 : rList.push_back( new WrappedSplineProperty<sal_Int32>( "SplineResolution", "CurveResolution", uno::makeAny(sal_Int32(20)), spChart2ModelContact ) );
217 40 : }
218 :
219 : //-----------------------------------------------------------------------------
220 :
221 40 : WrappedSplineTypeProperty::WrappedSplineTypeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
222 40 : : WrappedSplineProperty<sal_Int32>( "SplineType", "CurveStyle", uno::makeAny(sal_Int32(0)), spChart2ModelContact )
223 : {
224 40 : }
225 80 : WrappedSplineTypeProperty::~WrappedSplineTypeProperty()
226 : {
227 80 : }
228 0 : Any WrappedSplineTypeProperty::convertInnerToOuterValue( const Any& rInnerValue ) const
229 : {
230 0 : chart2::CurveStyle aInnerValue = chart2::CurveStyle_LINES;
231 0 : rInnerValue >>= aInnerValue;
232 :
233 : sal_Int32 nOuterValue;
234 0 : if( chart2::CurveStyle_CUBIC_SPLINES == aInnerValue )
235 0 : nOuterValue = 1;
236 0 : else if( chart2::CurveStyle_B_SPLINES == aInnerValue )
237 0 : nOuterValue = 2;
238 : else
239 0 : nOuterValue = 0;
240 :
241 0 : return uno::makeAny(nOuterValue);
242 : }
243 0 : Any WrappedSplineTypeProperty::convertOuterToInnerValue( const Any& rOuterValue ) const
244 : {
245 0 : sal_Int32 nOuterValue=0;
246 0 : rOuterValue >>= nOuterValue;
247 :
248 : chart2::CurveStyle aInnerValue;
249 :
250 0 : if(1==nOuterValue)
251 0 : aInnerValue = chart2::CurveStyle_CUBIC_SPLINES;
252 0 : else if(2==nOuterValue)
253 0 : aInnerValue = chart2::CurveStyle_B_SPLINES;
254 : else
255 0 : aInnerValue = chart2::CurveStyle_LINES;
256 :
257 0 : return uno::makeAny(aInnerValue);
258 : }
259 :
260 : } //namespace wrapper
261 : } //namespace chart
262 : //.............................................................................
263 :
264 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|