1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_chartcontroller.hxx" 26 27 #include "WrappedStockProperties.hxx" 28 #include "macros.hxx" 29 #include "FastPropertyIdRanges.hxx" 30 #include "DiagramHelper.hxx" 31 #include "ChartModelHelper.hxx" 32 #include "ControllerLockGuard.hxx" 33 #include <com/sun/star/chart2/XChartDocument.hpp> 34 #include <com/sun/star/beans/PropertyAttribute.hpp> 35 36 using namespace ::com::sun::star; 37 using ::com::sun::star::uno::Any; 38 using ::com::sun::star::uno::Reference; 39 using ::com::sun::star::uno::Sequence; 40 using ::com::sun::star::beans::Property; 41 using ::rtl::OUString; 42 43 //............................................................................. 44 namespace chart 45 { 46 namespace wrapper 47 { 48 49 50 //----------------------------------------------------------------------------- 51 //----------------------------------------------------------------------------- 52 //----------------------------------------------------------------------------- 53 54 class WrappedStockProperty : public WrappedProperty 55 { 56 public: 57 explicit WrappedStockProperty( const ::rtl::OUString& rOuterName 58 , const ::com::sun::star::uno::Any& rDefaulValue 59 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ); 60 virtual ~WrappedStockProperty(); 61 62 void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const; 63 64 ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const; 65 66 virtual uno::Reference< chart2::XChartTypeTemplate > getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const = 0; 67 68 protected: 69 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact; 70 mutable ::com::sun::star::uno::Any m_aOuterValue; 71 ::com::sun::star::uno::Any m_aDefaultValue; 72 }; 73 74 WrappedStockProperty::WrappedStockProperty( const ::rtl::OUString& rOuterName 75 , const ::com::sun::star::uno::Any& rDefaulValue 76 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 77 : WrappedProperty(rOuterName,rtl::OUString()) 78 , m_spChart2ModelContact(spChart2ModelContact) 79 , m_aOuterValue() 80 , m_aDefaultValue(rDefaulValue) 81 { 82 } 83 WrappedStockProperty::~WrappedStockProperty() 84 { 85 } 86 87 void WrappedStockProperty::setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const 88 { 89 sal_Bool bNewValue = false; 90 if( ! (rOuterValue >>= bNewValue) ) 91 throw lang::IllegalArgumentException( C2U("stock properties require type sal_Bool"), 0, 0 ); 92 93 m_aOuterValue = rOuterValue; 94 95 Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() ); 96 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() ); 97 sal_Int32 nDimension = ::chart::DiagramHelper::getDimension( xDiagram ); 98 if( xChartDoc.is() && xDiagram.is() && nDimension==2 ) 99 { 100 Reference< lang::XMultiServiceFactory > xFactory( xChartDoc->getChartTypeManager(), uno::UNO_QUERY ); 101 DiagramHelper::tTemplateWithServiceName aTemplateAndService = 102 DiagramHelper::getTemplateForDiagram( xDiagram, xFactory ); 103 104 uno::Reference< chart2::XChartTypeTemplate > xTemplate = 105 getNewTemplate( bNewValue, aTemplateAndService.second, xFactory ); 106 107 if(xTemplate.is()) 108 { 109 try 110 { 111 // /-- locked controllers 112 ControllerLockGuard aCtrlLockGuard( m_spChart2ModelContact->getChartModel() ); 113 xTemplate->changeDiagram( xDiagram ); 114 // \-- locked controllers 115 } 116 catch( uno::Exception & ex ) 117 { 118 ASSERT_EXCEPTION( ex ); 119 } 120 } 121 } 122 } 123 124 ::com::sun::star::uno::Any WrappedStockProperty::getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& /*xInnerPropertyState*/ ) const 125 { 126 return m_aDefaultValue; 127 } 128 129 //------------------------------------------------------------------------------------- 130 //------------------------------------------------------------------------------------- 131 //------------------------------------------------------------------------------------- 132 133 class WrappedVolumeProperty : public WrappedStockProperty 134 { 135 public: 136 explicit WrappedVolumeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ); 137 virtual ~WrappedVolumeProperty(); 138 139 ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const; 140 141 uno::Reference< chart2::XChartTypeTemplate > getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const; 142 }; 143 144 WrappedVolumeProperty::WrappedVolumeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 145 : WrappedStockProperty( C2U("Volume"), uno::makeAny(sal_False) , spChart2ModelContact ) 146 { 147 } 148 WrappedVolumeProperty::~WrappedVolumeProperty() 149 { 150 } 151 152 ::com::sun::star::uno::Any WrappedVolumeProperty::getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const 153 { 154 Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() ); 155 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() ); 156 if( xDiagram.is() && xChartDoc.is() ) 157 { 158 ::std::vector< uno::Reference< chart2::XDataSeries > > aSeriesVector( 159 DiagramHelper::getDataSeriesFromDiagram( xDiagram ) ); 160 if( aSeriesVector.size() > 0 ) 161 { 162 Reference< lang::XMultiServiceFactory > xFact( xChartDoc->getChartTypeManager(), uno::UNO_QUERY ); 163 DiagramHelper::tTemplateWithServiceName aTemplateAndService = 164 DiagramHelper::getTemplateForDiagram( xDiagram, xFact ); 165 166 if( aTemplateAndService.second.equals( C2U( "com.sun.star.chart2.template.StockVolumeLowHighClose" ) ) 167 || aTemplateAndService.second.equals( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ) ) 168 m_aOuterValue <<= sal_Bool(sal_True); 169 else if( !aTemplateAndService.second.isEmpty() || !m_aOuterValue.hasValue() ) 170 m_aOuterValue <<= sal_Bool(sal_False); 171 } 172 else if(!m_aOuterValue.hasValue()) 173 m_aOuterValue <<= sal_Bool(sal_False); 174 } 175 return m_aOuterValue; 176 } 177 178 uno::Reference< chart2::XChartTypeTemplate > WrappedVolumeProperty::getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const 179 { 180 uno::Reference< chart2::XChartTypeTemplate > xTemplate(0); 181 182 if(!xFactory.is()) 183 return xTemplate; 184 185 if( bNewValue ) //add volume 186 { 187 if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockLowHighClose" ) ) ) 188 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockVolumeLowHighClose" ) ), uno::UNO_QUERY ); 189 else if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockOpenLowHighClose" ) ) ) 190 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ), uno::UNO_QUERY ); 191 } 192 else //remove volume 193 { 194 if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockVolumeLowHighClose" ) ) ) 195 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockLowHighClose" ) ), uno::UNO_QUERY ); 196 else if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ) ) 197 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockOpenLowHighClose" ) ), uno::UNO_QUERY ); 198 } 199 return xTemplate; 200 } 201 202 //------------------------------------------------------------------------------------- 203 //------------------------------------------------------------------------------------- 204 205 206 class WrappedUpDownProperty : public WrappedStockProperty 207 { 208 public: 209 explicit WrappedUpDownProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ); 210 virtual ~WrappedUpDownProperty(); 211 212 ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const; 213 214 uno::Reference< chart2::XChartTypeTemplate > getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const; 215 }; 216 WrappedUpDownProperty::WrappedUpDownProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 217 : WrappedStockProperty( C2U("UpDown"), uno::makeAny(sal_False) , spChart2ModelContact ) 218 { 219 } 220 WrappedUpDownProperty::~WrappedUpDownProperty() 221 { 222 } 223 ::com::sun::star::uno::Any WrappedUpDownProperty::getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const 224 { 225 Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() ); 226 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() ); 227 if( xDiagram.is() && xChartDoc.is() ) 228 { 229 ::std::vector< uno::Reference< chart2::XDataSeries > > aSeriesVector( 230 DiagramHelper::getDataSeriesFromDiagram( xDiagram ) ); 231 if( aSeriesVector.size() > 0 ) 232 { 233 Reference< lang::XMultiServiceFactory > xFact( xChartDoc->getChartTypeManager(), uno::UNO_QUERY ); 234 DiagramHelper::tTemplateWithServiceName aTemplateAndService = 235 DiagramHelper::getTemplateForDiagram( xDiagram, xFact ); 236 237 if( aTemplateAndService.second.equals( C2U( "com.sun.star.chart2.template.StockOpenLowHighClose" ) ) 238 || aTemplateAndService.second.equals( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ) ) 239 m_aOuterValue <<= sal_Bool(sal_True); 240 else if( !aTemplateAndService.second.isEmpty() || !m_aOuterValue.hasValue() ) 241 m_aOuterValue <<= sal_Bool(sal_False); 242 } 243 else if(!m_aOuterValue.hasValue()) 244 m_aOuterValue <<= sal_Bool(sal_False); 245 } 246 return m_aOuterValue; 247 } 248 uno::Reference< chart2::XChartTypeTemplate > WrappedUpDownProperty::getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const 249 { 250 uno::Reference< chart2::XChartTypeTemplate > xTemplate(0); 251 if( bNewValue ) //add open series 252 { 253 if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockLowHighClose" ) ) ) 254 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockOpenLowHighClose" ) ), uno::UNO_QUERY ); 255 else if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockVolumeLowHighClose" ) ) ) 256 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ), uno::UNO_QUERY ); 257 } 258 else //remove open series 259 { 260 if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockOpenLowHighClose" ) ) ) 261 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockLowHighClose" ) ), uno::UNO_QUERY ); 262 else if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ) ) 263 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockVolumeLowHighClose" ) ), uno::UNO_QUERY ); 264 } 265 return xTemplate; 266 } 267 268 namespace 269 { 270 enum 271 { 272 //spline properties 273 PROP_CHART_STOCK_VOLUME = FAST_PROPERTY_ID_START_CHART_STOCK_PROP 274 , PROP_CHART_STOCK_UPDOWN 275 }; 276 277 }//anonymous namespace 278 279 //----------------------------------------------------------------------------- 280 //----------------------------------------------------------------------------- 281 //----------------------------------------------------------------------------- 282 void WrappedStockProperties::addProperties( ::std::vector< Property > & rOutProperties ) 283 { 284 rOutProperties.push_back( 285 Property( C2U( "Volume" ), 286 PROP_CHART_STOCK_VOLUME, 287 ::getCppuType( reinterpret_cast< sal_Bool * >(0)), 288 beans::PropertyAttribute::BOUND 289 | beans::PropertyAttribute::MAYBEDEFAULT 290 | beans::PropertyAttribute::MAYBEVOID )); 291 rOutProperties.push_back( 292 Property( C2U( "UpDown" ), 293 PROP_CHART_STOCK_UPDOWN, 294 ::getCppuType( reinterpret_cast< sal_Bool * >(0)), 295 beans::PropertyAttribute::BOUND 296 | beans::PropertyAttribute::MAYBEDEFAULT 297 | beans::PropertyAttribute::MAYBEVOID )); 298 } 299 300 //----------------------------------------------------------------------------- 301 //----------------------------------------------------------------------------- 302 303 void WrappedStockProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList 304 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 305 { 306 rList.push_back( new WrappedVolumeProperty( spChart2ModelContact ) ); 307 rList.push_back( new WrappedUpDownProperty( spChart2ModelContact ) ); 308 } 309 310 //----------------------------------------------------------------------------- 311 //----------------------------------------------------------------------------- 312 //----------------------------------------------------------------------------- 313 314 } //namespace wrapper 315 } //namespace chart 316 //............................................................................. 317