xref: /AOO41X/main/chart2/source/controller/chartapiwrapper/WrappedSplineProperties.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_chart2.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "WrappedSplineProperties.hxx"
32*cdf0e10cSrcweir #include "macros.hxx"
33*cdf0e10cSrcweir #include "FastPropertyIdRanges.hxx"
34*cdf0e10cSrcweir #include "DiagramHelper.hxx"
35*cdf0e10cSrcweir #include <com/sun/star/chart2/CurveStyle.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir using namespace ::com::sun::star;
39*cdf0e10cSrcweir using ::com::sun::star::uno::Any;
40*cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
41*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
42*cdf0e10cSrcweir using ::com::sun::star::beans::Property;
43*cdf0e10cSrcweir using ::rtl::OUString;
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir //.............................................................................
46*cdf0e10cSrcweir namespace chart
47*cdf0e10cSrcweir {
48*cdf0e10cSrcweir namespace wrapper
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir //-----------------------------------------------------------------------------
52*cdf0e10cSrcweir //-----------------------------------------------------------------------------
53*cdf0e10cSrcweir //-----------------------------------------------------------------------------
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir //PROPERTYTYPE is the type of the outer property
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir template< typename PROPERTYTYPE >
58*cdf0e10cSrcweir class WrappedSplineProperty : public WrappedProperty
59*cdf0e10cSrcweir {
60*cdf0e10cSrcweir public:
61*cdf0e10cSrcweir     explicit WrappedSplineProperty( const ::rtl::OUString& rOuterName, const ::rtl::OUString& rInnerName
62*cdf0e10cSrcweir         , const ::com::sun::star::uno::Any& rDefaulValue
63*cdf0e10cSrcweir         , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
64*cdf0e10cSrcweir             : WrappedProperty(rOuterName,OUString())
65*cdf0e10cSrcweir             , m_spChart2ModelContact(spChart2ModelContact)
66*cdf0e10cSrcweir             , m_aOuterValue(rDefaulValue)
67*cdf0e10cSrcweir             , m_aDefaultValue(rDefaulValue)
68*cdf0e10cSrcweir             , m_aOwnInnerName(rInnerName)
69*cdf0e10cSrcweir     {
70*cdf0e10cSrcweir     }
71*cdf0e10cSrcweir     virtual ~WrappedSplineProperty() {};
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir     bool detectInnerValue( PROPERTYTYPE& rValue, bool& rHasAmbiguousValue ) const
74*cdf0e10cSrcweir     {
75*cdf0e10cSrcweir         bool bHasDetectableInnerValue = false;
76*cdf0e10cSrcweir         rHasAmbiguousValue = false;
77*cdf0e10cSrcweir         Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > > aChartTypes(
78*cdf0e10cSrcweir             ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
79*cdf0e10cSrcweir         for( sal_Int32 nN = aChartTypes.getLength(); nN--; )
80*cdf0e10cSrcweir         {
81*cdf0e10cSrcweir             try
82*cdf0e10cSrcweir             {
83*cdf0e10cSrcweir                 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xChartTypePropertySet( aChartTypes[nN], ::com::sun::star::uno::UNO_QUERY );
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir                 Any aSingleValue = this->convertInnerToOuterValue( xChartTypePropertySet->getPropertyValue(m_aOwnInnerName) );
86*cdf0e10cSrcweir                 PROPERTYTYPE aCurValue = PROPERTYTYPE();
87*cdf0e10cSrcweir                 aSingleValue >>= aCurValue;
88*cdf0e10cSrcweir                 if( !bHasDetectableInnerValue )
89*cdf0e10cSrcweir                     rValue = aCurValue;
90*cdf0e10cSrcweir                 else
91*cdf0e10cSrcweir                 {
92*cdf0e10cSrcweir                     if( rValue != aCurValue )
93*cdf0e10cSrcweir                     {
94*cdf0e10cSrcweir                         rHasAmbiguousValue = true;
95*cdf0e10cSrcweir                         break;
96*cdf0e10cSrcweir                     }
97*cdf0e10cSrcweir                     else
98*cdf0e10cSrcweir                         rValue = aCurValue;
99*cdf0e10cSrcweir                 }
100*cdf0e10cSrcweir                 bHasDetectableInnerValue = true;
101*cdf0e10cSrcweir             }
102*cdf0e10cSrcweir             catch( uno::Exception & ex )
103*cdf0e10cSrcweir             {
104*cdf0e10cSrcweir                 //spline properties are not supported by all charttypes
105*cdf0e10cSrcweir                 //in that cases this exception is ok
106*cdf0e10cSrcweir                 ex.Context.is();//to have debug information without compilation warnings
107*cdf0e10cSrcweir             }
108*cdf0e10cSrcweir         }
109*cdf0e10cSrcweir         return bHasDetectableInnerValue;
110*cdf0e10cSrcweir     }
111*cdf0e10cSrcweir     void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const
112*cdf0e10cSrcweir                     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)
113*cdf0e10cSrcweir     {
114*cdf0e10cSrcweir         PROPERTYTYPE aNewValue;
115*cdf0e10cSrcweir         if( ! (rOuterValue >>= aNewValue) )
116*cdf0e10cSrcweir             throw ::com::sun::star::lang::IllegalArgumentException( C2U("spline property requires different type"), 0, 0 );
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir         m_aOuterValue = rOuterValue;
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir         bool bHasAmbiguousValue = false;
121*cdf0e10cSrcweir         PROPERTYTYPE aOldValue;
122*cdf0e10cSrcweir         if( detectInnerValue( aOldValue, bHasAmbiguousValue ) )
123*cdf0e10cSrcweir         {
124*cdf0e10cSrcweir             if( bHasAmbiguousValue || aNewValue != aOldValue )
125*cdf0e10cSrcweir             {
126*cdf0e10cSrcweir                 Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > > aChartTypes(
127*cdf0e10cSrcweir                     ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
128*cdf0e10cSrcweir                 for( sal_Int32 nN = aChartTypes.getLength(); nN--; )
129*cdf0e10cSrcweir                 {
130*cdf0e10cSrcweir                     try
131*cdf0e10cSrcweir                     {
132*cdf0e10cSrcweir                         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xChartTypePropertySet( aChartTypes[nN], ::com::sun::star::uno::UNO_QUERY );
133*cdf0e10cSrcweir                         if( xChartTypePropertySet.is() )
134*cdf0e10cSrcweir                         {
135*cdf0e10cSrcweir                             xChartTypePropertySet->setPropertyValue(m_aOwnInnerName,this->convertOuterToInnerValue(uno::makeAny(aNewValue)));
136*cdf0e10cSrcweir                         }
137*cdf0e10cSrcweir                     }
138*cdf0e10cSrcweir                     catch( uno::Exception & ex )
139*cdf0e10cSrcweir                     {
140*cdf0e10cSrcweir                         //spline properties are not supported by all charttypes
141*cdf0e10cSrcweir                         //in that cases this exception is ok
142*cdf0e10cSrcweir                         ex.Context.is();//to have debug information without compilation warnings
143*cdf0e10cSrcweir                     }
144*cdf0e10cSrcweir                 }
145*cdf0e10cSrcweir             }
146*cdf0e10cSrcweir         }
147*cdf0e10cSrcweir     }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir     ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const
150*cdf0e10cSrcweir                             throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
151*cdf0e10cSrcweir     {
152*cdf0e10cSrcweir         bool bHasAmbiguousValue = false;
153*cdf0e10cSrcweir         PROPERTYTYPE aValue;
154*cdf0e10cSrcweir         if( detectInnerValue( aValue, bHasAmbiguousValue ) )
155*cdf0e10cSrcweir         {
156*cdf0e10cSrcweir             m_aOuterValue <<= aValue;
157*cdf0e10cSrcweir         }
158*cdf0e10cSrcweir         return m_aOuterValue;
159*cdf0e10cSrcweir     }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir     ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& /*xInnerPropertyState*/ ) const
162*cdf0e10cSrcweir                             throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
163*cdf0e10cSrcweir     {
164*cdf0e10cSrcweir         return m_aDefaultValue;
165*cdf0e10cSrcweir     }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir protected:
168*cdf0e10cSrcweir     ::boost::shared_ptr< Chart2ModelContact >   m_spChart2ModelContact;
169*cdf0e10cSrcweir     mutable ::com::sun::star::uno::Any     m_aOuterValue;
170*cdf0e10cSrcweir     ::com::sun::star::uno::Any             m_aDefaultValue;
171*cdf0e10cSrcweir     // this inner name is not set as inner name at the base class
172*cdf0e10cSrcweir     const OUString m_aOwnInnerName;
173*cdf0e10cSrcweir };
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir class WrappedSplineTypeProperty : public WrappedSplineProperty< sal_Int32 >
176*cdf0e10cSrcweir {
177*cdf0e10cSrcweir public:
178*cdf0e10cSrcweir     explicit WrappedSplineTypeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
179*cdf0e10cSrcweir     virtual ~WrappedSplineTypeProperty();
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir     virtual ::com::sun::star::uno::Any convertInnerToOuterValue( const ::com::sun::star::uno::Any& rInnerValue ) const;
182*cdf0e10cSrcweir     virtual ::com::sun::star::uno::Any convertOuterToInnerValue( const ::com::sun::star::uno::Any& rOuterValue ) const;
183*cdf0e10cSrcweir };
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir namespace
186*cdf0e10cSrcweir {
187*cdf0e10cSrcweir enum
188*cdf0e10cSrcweir {
189*cdf0e10cSrcweir     //spline properties
190*cdf0e10cSrcweir       PROP_CHART_SPLINE_TYPE = FAST_PROPERTY_ID_START_CHART_SPLINE_PROP
191*cdf0e10cSrcweir     , PROP_CHART_SPLINE_ORDER
192*cdf0e10cSrcweir     , PROP_CHART_SPLINE_RESOLUTION
193*cdf0e10cSrcweir };
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir }//anonymous namespace
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir //-----------------------------------------------------------------------------
198*cdf0e10cSrcweir //-----------------------------------------------------------------------------
199*cdf0e10cSrcweir //-----------------------------------------------------------------------------
200*cdf0e10cSrcweir void WrappedSplineProperties::addProperties( ::std::vector< Property > & rOutProperties )
201*cdf0e10cSrcweir {
202*cdf0e10cSrcweir     rOutProperties.push_back(
203*cdf0e10cSrcweir         Property( C2U( "SplineType" ),
204*cdf0e10cSrcweir                   PROP_CHART_SPLINE_TYPE,
205*cdf0e10cSrcweir                   ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
206*cdf0e10cSrcweir                   beans::PropertyAttribute::BOUND
207*cdf0e10cSrcweir                   | beans::PropertyAttribute::MAYBEDEFAULT
208*cdf0e10cSrcweir                   | beans::PropertyAttribute::MAYBEVOID ));
209*cdf0e10cSrcweir     rOutProperties.push_back(
210*cdf0e10cSrcweir         Property( C2U( "SplineOrder" ),
211*cdf0e10cSrcweir                   PROP_CHART_SPLINE_ORDER,
212*cdf0e10cSrcweir                   ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
213*cdf0e10cSrcweir                   beans::PropertyAttribute::BOUND
214*cdf0e10cSrcweir                   | beans::PropertyAttribute::MAYBEDEFAULT
215*cdf0e10cSrcweir                   | beans::PropertyAttribute::MAYBEVOID ));
216*cdf0e10cSrcweir     rOutProperties.push_back(
217*cdf0e10cSrcweir         Property( C2U( "SplineResolution" ),
218*cdf0e10cSrcweir                   PROP_CHART_SPLINE_RESOLUTION,
219*cdf0e10cSrcweir                   ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
220*cdf0e10cSrcweir                   beans::PropertyAttribute::BOUND
221*cdf0e10cSrcweir                   | beans::PropertyAttribute::MAYBEDEFAULT
222*cdf0e10cSrcweir                   | beans::PropertyAttribute::MAYBEVOID ));
223*cdf0e10cSrcweir }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir //-----------------------------------------------------------------------------
226*cdf0e10cSrcweir //-----------------------------------------------------------------------------
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir void WrappedSplineProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
229*cdf0e10cSrcweir                                     , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir     rList.push_back( new WrappedSplineTypeProperty( spChart2ModelContact ) );
232*cdf0e10cSrcweir     rList.push_back( new WrappedSplineProperty<sal_Int32>( C2U("SplineOrder"),      C2U("SplineOrder"), uno::makeAny(sal_Int32(3)), spChart2ModelContact ) );
233*cdf0e10cSrcweir     rList.push_back( new WrappedSplineProperty<sal_Int32>( C2U("SplineResolution"), C2U("CurveResolution"), uno::makeAny(sal_Int32(20)), spChart2ModelContact ) );
234*cdf0e10cSrcweir }
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir //-----------------------------------------------------------------------------
237*cdf0e10cSrcweir //-----------------------------------------------------------------------------
238*cdf0e10cSrcweir //-----------------------------------------------------------------------------
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir WrappedSplineTypeProperty::WrappedSplineTypeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
242*cdf0e10cSrcweir     : WrappedSplineProperty<sal_Int32>( C2U("SplineType"), C2U("CurveStyle"), uno::makeAny(sal_Int32(0)), spChart2ModelContact )
243*cdf0e10cSrcweir {
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir WrappedSplineTypeProperty::~WrappedSplineTypeProperty()
246*cdf0e10cSrcweir {
247*cdf0e10cSrcweir }
248*cdf0e10cSrcweir Any WrappedSplineTypeProperty::convertInnerToOuterValue( const Any& rInnerValue ) const
249*cdf0e10cSrcweir {
250*cdf0e10cSrcweir     chart2::CurveStyle aInnerValue = chart2::CurveStyle_LINES;
251*cdf0e10cSrcweir     rInnerValue >>= aInnerValue;
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir     sal_Int32 nOuterValue;
254*cdf0e10cSrcweir     if( chart2::CurveStyle_CUBIC_SPLINES == aInnerValue )
255*cdf0e10cSrcweir         nOuterValue = 1;
256*cdf0e10cSrcweir     else if( chart2::CurveStyle_B_SPLINES == aInnerValue )
257*cdf0e10cSrcweir         nOuterValue = 2;
258*cdf0e10cSrcweir     else
259*cdf0e10cSrcweir         nOuterValue = 0;
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir     return uno::makeAny(nOuterValue);
262*cdf0e10cSrcweir }
263*cdf0e10cSrcweir Any WrappedSplineTypeProperty::convertOuterToInnerValue( const Any& rOuterValue ) const
264*cdf0e10cSrcweir {
265*cdf0e10cSrcweir     sal_Int32 nOuterValue=0;
266*cdf0e10cSrcweir     rOuterValue >>= nOuterValue;
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir     chart2::CurveStyle aInnerValue;
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir     if(1==nOuterValue)
271*cdf0e10cSrcweir         aInnerValue = chart2::CurveStyle_CUBIC_SPLINES;
272*cdf0e10cSrcweir     else if(2==nOuterValue)
273*cdf0e10cSrcweir         aInnerValue = chart2::CurveStyle_B_SPLINES;
274*cdf0e10cSrcweir     else
275*cdf0e10cSrcweir         aInnerValue = chart2::CurveStyle_LINES;
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir     return uno::makeAny(aInnerValue);
278*cdf0e10cSrcweir }
279*cdf0e10cSrcweir //-----------------------------------------------------------------------------
280*cdf0e10cSrcweir //-----------------------------------------------------------------------------
281*cdf0e10cSrcweir //-----------------------------------------------------------------------------
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir } //namespace wrapper
284*cdf0e10cSrcweir } //namespace chart
285*cdf0e10cSrcweir //.............................................................................
286