1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_chart2.hxx" 30 31 #include "WrappedSplineProperties.hxx" 32 #include "macros.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> 37 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; 44 45 //............................................................................. 46 namespace chart 47 { 48 namespace wrapper 49 { 50 51 //----------------------------------------------------------------------------- 52 //----------------------------------------------------------------------------- 53 //----------------------------------------------------------------------------- 54 55 //PROPERTYTYPE is the type of the outer property 56 57 template< typename PROPERTYTYPE > 58 class WrappedSplineProperty : public WrappedProperty 59 { 60 public: 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) 69 { 70 } 71 virtual ~WrappedSplineProperty() {}; 72 73 bool detectInnerValue( PROPERTYTYPE& rValue, bool& rHasAmbiguousValue ) const 74 { 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--; ) 80 { 81 try 82 { 83 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xChartTypePropertySet( aChartTypes[nN], ::com::sun::star::uno::UNO_QUERY ); 84 85 Any aSingleValue = this->convertInnerToOuterValue( xChartTypePropertySet->getPropertyValue(m_aOwnInnerName) ); 86 PROPERTYTYPE aCurValue = PROPERTYTYPE(); 87 aSingleValue >>= aCurValue; 88 if( !bHasDetectableInnerValue ) 89 rValue = aCurValue; 90 else 91 { 92 if( rValue != aCurValue ) 93 { 94 rHasAmbiguousValue = true; 95 break; 96 } 97 else 98 rValue = aCurValue; 99 } 100 bHasDetectableInnerValue = true; 101 } 102 catch( uno::Exception & ex ) 103 { 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 107 } 108 } 109 return bHasDetectableInnerValue; 110 } 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) 113 { 114 PROPERTYTYPE aNewValue; 115 if( ! (rOuterValue >>= aNewValue) ) 116 throw ::com::sun::star::lang::IllegalArgumentException( C2U("spline property requires different type"), 0, 0 ); 117 118 m_aOuterValue = rOuterValue; 119 120 bool bHasAmbiguousValue = false; 121 PROPERTYTYPE aOldValue; 122 if( detectInnerValue( aOldValue, bHasAmbiguousValue ) ) 123 { 124 if( bHasAmbiguousValue || aNewValue != aOldValue ) 125 { 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--; ) 129 { 130 try 131 { 132 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xChartTypePropertySet( aChartTypes[nN], ::com::sun::star::uno::UNO_QUERY ); 133 if( xChartTypePropertySet.is() ) 134 { 135 xChartTypePropertySet->setPropertyValue(m_aOwnInnerName,this->convertOuterToInnerValue(uno::makeAny(aNewValue))); 136 } 137 } 138 catch( uno::Exception & ex ) 139 { 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 143 } 144 } 145 } 146 } 147 } 148 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) 151 { 152 bool bHasAmbiguousValue = false; 153 PROPERTYTYPE aValue; 154 if( detectInnerValue( aValue, bHasAmbiguousValue ) ) 155 { 156 m_aOuterValue <<= aValue; 157 } 158 return m_aOuterValue; 159 } 160 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) 163 { 164 return m_aDefaultValue; 165 } 166 167 protected: 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; 173 }; 174 175 class WrappedSplineTypeProperty : public WrappedSplineProperty< sal_Int32 > 176 { 177 public: 178 explicit WrappedSplineTypeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ); 179 virtual ~WrappedSplineTypeProperty(); 180 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; 183 }; 184 185 namespace 186 { 187 enum 188 { 189 //spline properties 190 PROP_CHART_SPLINE_TYPE = FAST_PROPERTY_ID_START_CHART_SPLINE_PROP 191 , PROP_CHART_SPLINE_ORDER 192 , PROP_CHART_SPLINE_RESOLUTION 193 }; 194 195 }//anonymous namespace 196 197 //----------------------------------------------------------------------------- 198 //----------------------------------------------------------------------------- 199 //----------------------------------------------------------------------------- 200 void WrappedSplineProperties::addProperties( ::std::vector< Property > & rOutProperties ) 201 { 202 rOutProperties.push_back( 203 Property( C2U( "SplineType" ), 204 PROP_CHART_SPLINE_TYPE, 205 ::getCppuType( reinterpret_cast< sal_Int32 * >(0)), 206 beans::PropertyAttribute::BOUND 207 | beans::PropertyAttribute::MAYBEDEFAULT 208 | beans::PropertyAttribute::MAYBEVOID )); 209 rOutProperties.push_back( 210 Property( C2U( "SplineOrder" ), 211 PROP_CHART_SPLINE_ORDER, 212 ::getCppuType( reinterpret_cast< sal_Int32 * >(0)), 213 beans::PropertyAttribute::BOUND 214 | beans::PropertyAttribute::MAYBEDEFAULT 215 | beans::PropertyAttribute::MAYBEVOID )); 216 rOutProperties.push_back( 217 Property( C2U( "SplineResolution" ), 218 PROP_CHART_SPLINE_RESOLUTION, 219 ::getCppuType( reinterpret_cast< sal_Int32 * >(0)), 220 beans::PropertyAttribute::BOUND 221 | beans::PropertyAttribute::MAYBEDEFAULT 222 | beans::PropertyAttribute::MAYBEVOID )); 223 } 224 225 //----------------------------------------------------------------------------- 226 //----------------------------------------------------------------------------- 227 228 void WrappedSplineProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList 229 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 230 { 231 rList.push_back( new WrappedSplineTypeProperty( spChart2ModelContact ) ); 232 rList.push_back( new WrappedSplineProperty<sal_Int32>( C2U("SplineOrder"), C2U("SplineOrder"), uno::makeAny(sal_Int32(3)), spChart2ModelContact ) ); 233 rList.push_back( new WrappedSplineProperty<sal_Int32>( C2U("SplineResolution"), C2U("CurveResolution"), uno::makeAny(sal_Int32(20)), spChart2ModelContact ) ); 234 } 235 236 //----------------------------------------------------------------------------- 237 //----------------------------------------------------------------------------- 238 //----------------------------------------------------------------------------- 239 240 241 WrappedSplineTypeProperty::WrappedSplineTypeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 242 : WrappedSplineProperty<sal_Int32>( C2U("SplineType"), C2U("CurveStyle"), uno::makeAny(sal_Int32(0)), spChart2ModelContact ) 243 { 244 } 245 WrappedSplineTypeProperty::~WrappedSplineTypeProperty() 246 { 247 } 248 Any WrappedSplineTypeProperty::convertInnerToOuterValue( const Any& rInnerValue ) const 249 { 250 chart2::CurveStyle aInnerValue = chart2::CurveStyle_LINES; 251 rInnerValue >>= aInnerValue; 252 253 sal_Int32 nOuterValue; 254 if( chart2::CurveStyle_CUBIC_SPLINES == aInnerValue ) 255 nOuterValue = 1; 256 else if( chart2::CurveStyle_B_SPLINES == aInnerValue ) 257 nOuterValue = 2; 258 else 259 nOuterValue = 0; 260 261 return uno::makeAny(nOuterValue); 262 } 263 Any WrappedSplineTypeProperty::convertOuterToInnerValue( const Any& rOuterValue ) const 264 { 265 sal_Int32 nOuterValue=0; 266 rOuterValue >>= nOuterValue; 267 268 chart2::CurveStyle aInnerValue; 269 270 if(1==nOuterValue) 271 aInnerValue = chart2::CurveStyle_CUBIC_SPLINES; 272 else if(2==nOuterValue) 273 aInnerValue = chart2::CurveStyle_B_SPLINES; 274 else 275 aInnerValue = chart2::CurveStyle_LINES; 276 277 return uno::makeAny(aInnerValue); 278 } 279 //----------------------------------------------------------------------------- 280 //----------------------------------------------------------------------------- 281 //----------------------------------------------------------------------------- 282 283 } //namespace wrapper 284 } //namespace chart 285 //............................................................................. 286