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 "WrappedStockProperties.hxx" 32 #include "macros.hxx" 33 #include "FastPropertyIdRanges.hxx" 34 #include "DiagramHelper.hxx" 35 #include "ChartModelHelper.hxx" 36 #include "ControllerLockGuard.hxx" 37 #include <com/sun/star/chart2/XChartDocument.hpp> 38 #include <com/sun/star/beans/PropertyAttribute.hpp> 39 40 using namespace ::com::sun::star; 41 using ::com::sun::star::uno::Any; 42 using ::com::sun::star::uno::Reference; 43 using ::com::sun::star::uno::Sequence; 44 using ::com::sun::star::beans::Property; 45 using ::rtl::OUString; 46 47 //............................................................................. 48 namespace chart 49 { 50 namespace wrapper 51 { 52 53 54 //----------------------------------------------------------------------------- 55 //----------------------------------------------------------------------------- 56 //----------------------------------------------------------------------------- 57 58 class WrappedStockProperty : public WrappedProperty 59 { 60 public: 61 explicit WrappedStockProperty( const ::rtl::OUString& rOuterName 62 , const ::com::sun::star::uno::Any& rDefaulValue 63 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ); 64 virtual ~WrappedStockProperty(); 65 66 void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const 67 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); 68 69 ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const 70 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 71 72 virtual uno::Reference< chart2::XChartTypeTemplate > getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const = 0; 73 74 protected: 75 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact; 76 mutable ::com::sun::star::uno::Any m_aOuterValue; 77 ::com::sun::star::uno::Any m_aDefaultValue; 78 }; 79 80 WrappedStockProperty::WrappedStockProperty( const ::rtl::OUString& rOuterName 81 , const ::com::sun::star::uno::Any& rDefaulValue 82 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 83 : WrappedProperty(rOuterName,rtl::OUString()) 84 , m_spChart2ModelContact(spChart2ModelContact) 85 , m_aOuterValue() 86 , m_aDefaultValue(rDefaulValue) 87 { 88 } 89 WrappedStockProperty::~WrappedStockProperty() 90 { 91 } 92 93 void WrappedStockProperty::setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const 94 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) 95 { 96 sal_Bool bNewValue = false; 97 if( ! (rOuterValue >>= bNewValue) ) 98 throw lang::IllegalArgumentException( C2U("stock properties require type sal_Bool"), 0, 0 ); 99 100 m_aOuterValue = rOuterValue; 101 102 Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() ); 103 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() ); 104 sal_Int32 nDimension = ::chart::DiagramHelper::getDimension( xDiagram ); 105 if( xChartDoc.is() && xDiagram.is() && nDimension==2 ) 106 { 107 Reference< lang::XMultiServiceFactory > xFactory( xChartDoc->getChartTypeManager(), uno::UNO_QUERY ); 108 DiagramHelper::tTemplateWithServiceName aTemplateAndService = 109 DiagramHelper::getTemplateForDiagram( xDiagram, xFactory ); 110 111 uno::Reference< chart2::XChartTypeTemplate > xTemplate = 112 getNewTemplate( bNewValue, aTemplateAndService.second, xFactory ); 113 114 if(xTemplate.is()) 115 { 116 try 117 { 118 // /-- locked controllers 119 ControllerLockGuard aCtrlLockGuard( m_spChart2ModelContact->getChartModel() ); 120 xTemplate->changeDiagram( xDiagram ); 121 // \-- locked controllers 122 } 123 catch( uno::Exception & ex ) 124 { 125 ASSERT_EXCEPTION( ex ); 126 } 127 } 128 } 129 } 130 131 ::com::sun::star::uno::Any WrappedStockProperty::getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& /*xInnerPropertyState*/ ) const 132 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 133 { 134 return m_aDefaultValue; 135 } 136 137 //------------------------------------------------------------------------------------- 138 //------------------------------------------------------------------------------------- 139 //------------------------------------------------------------------------------------- 140 141 class WrappedVolumeProperty : public WrappedStockProperty 142 { 143 public: 144 explicit WrappedVolumeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ); 145 virtual ~WrappedVolumeProperty(); 146 147 ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const 148 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 149 150 uno::Reference< chart2::XChartTypeTemplate > getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const; 151 }; 152 153 WrappedVolumeProperty::WrappedVolumeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 154 : WrappedStockProperty( C2U("Volume"), uno::makeAny(sal_False) , spChart2ModelContact ) 155 { 156 } 157 WrappedVolumeProperty::~WrappedVolumeProperty() 158 { 159 } 160 161 ::com::sun::star::uno::Any WrappedVolumeProperty::getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const 162 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 163 { 164 Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() ); 165 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() ); 166 if( xDiagram.is() && xChartDoc.is() ) 167 { 168 ::std::vector< uno::Reference< chart2::XDataSeries > > aSeriesVector( 169 DiagramHelper::getDataSeriesFromDiagram( xDiagram ) ); 170 if( aSeriesVector.size() > 0 ) 171 { 172 Reference< lang::XMultiServiceFactory > xFact( xChartDoc->getChartTypeManager(), uno::UNO_QUERY ); 173 DiagramHelper::tTemplateWithServiceName aTemplateAndService = 174 DiagramHelper::getTemplateForDiagram( xDiagram, xFact ); 175 176 if( aTemplateAndService.second.equals( C2U( "com.sun.star.chart2.template.StockVolumeLowHighClose" ) ) 177 || aTemplateAndService.second.equals( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ) ) 178 m_aOuterValue <<= sal_Bool(sal_True); 179 else if( aTemplateAndService.second.getLength() || !m_aOuterValue.hasValue() ) 180 m_aOuterValue <<= sal_Bool(sal_False); 181 } 182 else if(!m_aOuterValue.hasValue()) 183 m_aOuterValue <<= sal_Bool(sal_False); 184 } 185 return m_aOuterValue; 186 } 187 188 uno::Reference< chart2::XChartTypeTemplate > WrappedVolumeProperty::getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const 189 { 190 uno::Reference< chart2::XChartTypeTemplate > xTemplate(0); 191 192 if(!xFactory.is()) 193 return xTemplate; 194 195 if( bNewValue ) //add volume 196 { 197 if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockLowHighClose" ) ) ) 198 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockVolumeLowHighClose" ) ), uno::UNO_QUERY ); 199 else if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockOpenLowHighClose" ) ) ) 200 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ), uno::UNO_QUERY ); 201 } 202 else //remove volume 203 { 204 if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockVolumeLowHighClose" ) ) ) 205 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockLowHighClose" ) ), uno::UNO_QUERY ); 206 else if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ) ) 207 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockOpenLowHighClose" ) ), uno::UNO_QUERY ); 208 } 209 return xTemplate; 210 } 211 212 //------------------------------------------------------------------------------------- 213 //------------------------------------------------------------------------------------- 214 215 216 class WrappedUpDownProperty : public WrappedStockProperty 217 { 218 public: 219 explicit WrappedUpDownProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ); 220 virtual ~WrappedUpDownProperty(); 221 222 ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const 223 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 224 225 uno::Reference< chart2::XChartTypeTemplate > getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const; 226 }; 227 WrappedUpDownProperty::WrappedUpDownProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 228 : WrappedStockProperty( C2U("UpDown"), uno::makeAny(sal_False) , spChart2ModelContact ) 229 { 230 } 231 WrappedUpDownProperty::~WrappedUpDownProperty() 232 { 233 } 234 ::com::sun::star::uno::Any WrappedUpDownProperty::getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const 235 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 236 { 237 Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() ); 238 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() ); 239 if( xDiagram.is() && xChartDoc.is() ) 240 { 241 ::std::vector< uno::Reference< chart2::XDataSeries > > aSeriesVector( 242 DiagramHelper::getDataSeriesFromDiagram( xDiagram ) ); 243 if( aSeriesVector.size() > 0 ) 244 { 245 Reference< lang::XMultiServiceFactory > xFact( xChartDoc->getChartTypeManager(), uno::UNO_QUERY ); 246 DiagramHelper::tTemplateWithServiceName aTemplateAndService = 247 DiagramHelper::getTemplateForDiagram( xDiagram, xFact ); 248 249 if( aTemplateAndService.second.equals( C2U( "com.sun.star.chart2.template.StockOpenLowHighClose" ) ) 250 || aTemplateAndService.second.equals( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ) ) 251 m_aOuterValue <<= sal_Bool(sal_True); 252 else if( aTemplateAndService.second.getLength() || !m_aOuterValue.hasValue() ) 253 m_aOuterValue <<= sal_Bool(sal_False); 254 } 255 else if(!m_aOuterValue.hasValue()) 256 m_aOuterValue <<= sal_Bool(sal_False); 257 } 258 return m_aOuterValue; 259 } 260 uno::Reference< chart2::XChartTypeTemplate > WrappedUpDownProperty::getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const 261 { 262 uno::Reference< chart2::XChartTypeTemplate > xTemplate(0); 263 if( bNewValue ) //add open series 264 { 265 if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockLowHighClose" ) ) ) 266 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockOpenLowHighClose" ) ), uno::UNO_QUERY ); 267 else if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockVolumeLowHighClose" ) ) ) 268 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ), uno::UNO_QUERY ); 269 } 270 else //remove open series 271 { 272 if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockOpenLowHighClose" ) ) ) 273 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockLowHighClose" ) ), uno::UNO_QUERY ); 274 else if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ) ) 275 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockVolumeLowHighClose" ) ), uno::UNO_QUERY ); 276 } 277 return xTemplate; 278 } 279 280 namespace 281 { 282 enum 283 { 284 //spline properties 285 PROP_CHART_STOCK_VOLUME = FAST_PROPERTY_ID_START_CHART_STOCK_PROP 286 , PROP_CHART_STOCK_UPDOWN 287 }; 288 289 }//anonymous namespace 290 291 //----------------------------------------------------------------------------- 292 //----------------------------------------------------------------------------- 293 //----------------------------------------------------------------------------- 294 void WrappedStockProperties::addProperties( ::std::vector< Property > & rOutProperties ) 295 { 296 rOutProperties.push_back( 297 Property( C2U( "Volume" ), 298 PROP_CHART_STOCK_VOLUME, 299 ::getCppuType( reinterpret_cast< sal_Bool * >(0)), 300 beans::PropertyAttribute::BOUND 301 | beans::PropertyAttribute::MAYBEDEFAULT 302 | beans::PropertyAttribute::MAYBEVOID )); 303 rOutProperties.push_back( 304 Property( C2U( "UpDown" ), 305 PROP_CHART_STOCK_UPDOWN, 306 ::getCppuType( reinterpret_cast< sal_Bool * >(0)), 307 beans::PropertyAttribute::BOUND 308 | beans::PropertyAttribute::MAYBEDEFAULT 309 | beans::PropertyAttribute::MAYBEVOID )); 310 } 311 312 //----------------------------------------------------------------------------- 313 //----------------------------------------------------------------------------- 314 315 void WrappedStockProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList 316 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 317 { 318 rList.push_back( new WrappedVolumeProperty( spChart2ModelContact ) ); 319 rList.push_back( new WrappedUpDownProperty( spChart2ModelContact ) ); 320 } 321 322 //----------------------------------------------------------------------------- 323 //----------------------------------------------------------------------------- 324 //----------------------------------------------------------------------------- 325 326 } //namespace wrapper 327 } //namespace chart 328 //............................................................................. 329