Update ooo320-m1
[ooovba.git] / chart2 / source / controller / chartapiwrapper / WrappedStockProperties.cxx
blob561634bf618513f9fc8229b78987c46b560c6020
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WrappedStockProperties.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "WrappedStockProperties.hxx"
35 #include "macros.hxx"
36 #include "FastPropertyIdRanges.hxx"
37 #include "DiagramHelper.hxx"
38 #include "ChartModelHelper.hxx"
39 #include "ControllerLockGuard.hxx"
40 #include <com/sun/star/chart2/XChartDocument.hpp>
41 #include <com/sun/star/beans/PropertyAttribute.hpp>
43 using namespace ::com::sun::star;
44 using ::com::sun::star::uno::Any;
45 using ::com::sun::star::uno::Reference;
46 using ::com::sun::star::uno::Sequence;
47 using ::com::sun::star::beans::Property;
48 using ::rtl::OUString;
50 //.............................................................................
51 namespace chart
53 namespace wrapper
57 //-----------------------------------------------------------------------------
58 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
61 class WrappedStockProperty : public WrappedProperty
63 public:
64 explicit WrappedStockProperty( const ::rtl::OUString& rOuterName
65 , const ::com::sun::star::uno::Any& rDefaulValue
66 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
67 virtual ~WrappedStockProperty();
69 void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
70 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);
72 ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
73 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
75 virtual uno::Reference< chart2::XChartTypeTemplate > getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const = 0;
77 protected:
78 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
79 mutable ::com::sun::star::uno::Any m_aOuterValue;
80 ::com::sun::star::uno::Any m_aDefaultValue;
83 WrappedStockProperty::WrappedStockProperty( const ::rtl::OUString& rOuterName
84 , const ::com::sun::star::uno::Any& rDefaulValue
85 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
86 : WrappedProperty(rOuterName,rtl::OUString())
87 , m_spChart2ModelContact(spChart2ModelContact)
88 , m_aOuterValue()
89 , m_aDefaultValue(rDefaulValue)
92 WrappedStockProperty::~WrappedStockProperty()
96 void WrappedStockProperty::setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const
97 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)
99 sal_Bool bNewValue = false;
100 if( ! (rOuterValue >>= bNewValue) )
101 throw lang::IllegalArgumentException( C2U("stock properties require type sal_Bool"), 0, 0 );
103 m_aOuterValue = rOuterValue;
105 Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
106 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
107 sal_Int32 nDimension = ::chart::DiagramHelper::getDimension( xDiagram );
108 if( xChartDoc.is() && xDiagram.is() && nDimension==2 )
110 Reference< lang::XMultiServiceFactory > xFactory( xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
111 DiagramHelper::tTemplateWithServiceName aTemplateAndService =
112 DiagramHelper::getTemplateForDiagram( xDiagram, xFactory );
114 uno::Reference< chart2::XChartTypeTemplate > xTemplate =
115 getNewTemplate( bNewValue, aTemplateAndService.second, xFactory );
117 if(xTemplate.is())
121 // /-- locked controllers
122 ControllerLockGuard aCtrlLockGuard( m_spChart2ModelContact->getChartModel() );
123 xTemplate->changeDiagram( xDiagram );
124 // \-- locked controllers
126 catch( uno::Exception & ex )
128 ASSERT_EXCEPTION( ex );
134 ::com::sun::star::uno::Any WrappedStockProperty::getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& /*xInnerPropertyState*/ ) const
135 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
137 return m_aDefaultValue;
140 //-------------------------------------------------------------------------------------
141 //-------------------------------------------------------------------------------------
142 //-------------------------------------------------------------------------------------
144 class WrappedVolumeProperty : public WrappedStockProperty
146 public:
147 explicit WrappedVolumeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
148 virtual ~WrappedVolumeProperty();
150 ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
151 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
153 uno::Reference< chart2::XChartTypeTemplate > getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const;
156 WrappedVolumeProperty::WrappedVolumeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
157 : WrappedStockProperty( C2U("Volume"), uno::makeAny(sal_False) , spChart2ModelContact )
160 WrappedVolumeProperty::~WrappedVolumeProperty()
164 ::com::sun::star::uno::Any WrappedVolumeProperty::getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const
165 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
167 Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
168 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
169 if( xDiagram.is() && xChartDoc.is() )
171 ::std::vector< uno::Reference< chart2::XDataSeries > > aSeriesVector(
172 DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
173 if( aSeriesVector.size() > 0 )
175 Reference< lang::XMultiServiceFactory > xFact( xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
176 DiagramHelper::tTemplateWithServiceName aTemplateAndService =
177 DiagramHelper::getTemplateForDiagram( xDiagram, xFact );
179 if( aTemplateAndService.second.equals( C2U( "com.sun.star.chart2.template.StockVolumeLowHighClose" ) )
180 || aTemplateAndService.second.equals( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ) )
181 m_aOuterValue <<= sal_Bool(sal_True);
182 else if( aTemplateAndService.second.getLength() || !m_aOuterValue.hasValue() )
183 m_aOuterValue <<= sal_Bool(sal_False);
185 else if(!m_aOuterValue.hasValue())
186 m_aOuterValue <<= sal_Bool(sal_False);
188 return m_aOuterValue;
191 uno::Reference< chart2::XChartTypeTemplate > WrappedVolumeProperty::getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const
193 uno::Reference< chart2::XChartTypeTemplate > xTemplate(0);
195 if(!xFactory.is())
196 return xTemplate;
198 if( bNewValue ) //add volume
200 if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockLowHighClose" ) ) )
201 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockVolumeLowHighClose" ) ), uno::UNO_QUERY );
202 else if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockOpenLowHighClose" ) ) )
203 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ), uno::UNO_QUERY );
205 else //remove volume
207 if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockVolumeLowHighClose" ) ) )
208 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockLowHighClose" ) ), uno::UNO_QUERY );
209 else if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ) )
210 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockOpenLowHighClose" ) ), uno::UNO_QUERY );
212 return xTemplate;
215 //-------------------------------------------------------------------------------------
216 //-------------------------------------------------------------------------------------
219 class WrappedUpDownProperty : public WrappedStockProperty
221 public:
222 explicit WrappedUpDownProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
223 virtual ~WrappedUpDownProperty();
225 ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
226 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
228 uno::Reference< chart2::XChartTypeTemplate > getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const;
230 WrappedUpDownProperty::WrappedUpDownProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
231 : WrappedStockProperty( C2U("UpDown"), uno::makeAny(sal_False) , spChart2ModelContact )
234 WrappedUpDownProperty::~WrappedUpDownProperty()
237 ::com::sun::star::uno::Any WrappedUpDownProperty::getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& /*xInnerPropertySet*/ ) const
238 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
240 Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
241 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
242 if( xDiagram.is() && xChartDoc.is() )
244 ::std::vector< uno::Reference< chart2::XDataSeries > > aSeriesVector(
245 DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
246 if( aSeriesVector.size() > 0 )
248 Reference< lang::XMultiServiceFactory > xFact( xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
249 DiagramHelper::tTemplateWithServiceName aTemplateAndService =
250 DiagramHelper::getTemplateForDiagram( xDiagram, xFact );
252 if( aTemplateAndService.second.equals( C2U( "com.sun.star.chart2.template.StockOpenLowHighClose" ) )
253 || aTemplateAndService.second.equals( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ) )
254 m_aOuterValue <<= sal_Bool(sal_True);
255 else if( aTemplateAndService.second.getLength() || !m_aOuterValue.hasValue() )
256 m_aOuterValue <<= sal_Bool(sal_False);
258 else if(!m_aOuterValue.hasValue())
259 m_aOuterValue <<= sal_Bool(sal_False);
261 return m_aOuterValue;
263 uno::Reference< chart2::XChartTypeTemplate > WrappedUpDownProperty::getNewTemplate( sal_Bool bNewValue, const rtl::OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const
265 uno::Reference< chart2::XChartTypeTemplate > xTemplate(0);
266 if( bNewValue ) //add open series
268 if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockLowHighClose" ) ) )
269 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockOpenLowHighClose" ) ), uno::UNO_QUERY );
270 else if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockVolumeLowHighClose" ) ) )
271 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ), uno::UNO_QUERY );
273 else //remove open series
275 if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockOpenLowHighClose" ) ) )
276 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockLowHighClose" ) ), uno::UNO_QUERY );
277 else if( rCurrentTemplate.equals( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ) ) )
278 xTemplate.set( xFactory->createInstance( C2U( "com.sun.star.chart2.template.StockVolumeLowHighClose" ) ), uno::UNO_QUERY );
280 return xTemplate;
283 namespace
285 enum
287 //spline properties
288 PROP_CHART_STOCK_VOLUME = FAST_PROPERTY_ID_START_CHART_STOCK_PROP
289 , PROP_CHART_STOCK_UPDOWN
292 }//anonymous namespace
294 //-----------------------------------------------------------------------------
295 //-----------------------------------------------------------------------------
296 //-----------------------------------------------------------------------------
297 //static
298 void WrappedStockProperties::addProperties( ::std::vector< Property > & rOutProperties )
300 rOutProperties.push_back(
301 Property( C2U( "Volume" ),
302 PROP_CHART_STOCK_VOLUME,
303 ::getCppuType( reinterpret_cast< sal_Bool * >(0)),
304 beans::PropertyAttribute::BOUND
305 | beans::PropertyAttribute::MAYBEDEFAULT
306 | beans::PropertyAttribute::MAYBEVOID ));
307 rOutProperties.push_back(
308 Property( C2U( "UpDown" ),
309 PROP_CHART_STOCK_UPDOWN,
310 ::getCppuType( reinterpret_cast< sal_Bool * >(0)),
311 beans::PropertyAttribute::BOUND
312 | beans::PropertyAttribute::MAYBEDEFAULT
313 | beans::PropertyAttribute::MAYBEVOID ));
316 //-----------------------------------------------------------------------------
317 //-----------------------------------------------------------------------------
319 //static
320 void WrappedStockProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
321 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
323 rList.push_back( new WrappedVolumeProperty( spChart2ModelContact ) );
324 rList.push_back( new WrappedUpDownProperty( spChart2ModelContact ) );
327 //-----------------------------------------------------------------------------
328 //-----------------------------------------------------------------------------
329 //-----------------------------------------------------------------------------
331 } //namespace wrapper
332 } //namespace chart
333 //.............................................................................