1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "WrappedStockProperties.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>
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
;
47 //.............................................................................
54 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
58 class WrappedStockProperty
: public WrappedProperty
61 explicit WrappedStockProperty( const ::rtl::OUString
& rOuterName
62 , const ::com::sun::star::uno::Any
& rDefaulValue
63 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
);
64 virtual ~WrappedStockProperty();
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
);
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
);
72 virtual uno::Reference
< chart2::XChartTypeTemplate
> getNewTemplate( sal_Bool bNewValue
, const rtl::OUString
& rCurrentTemplate
, const Reference
< lang::XMultiServiceFactory
>& xFactory
) const = 0;
75 ::boost::shared_ptr
< Chart2ModelContact
> m_spChart2ModelContact
;
76 mutable ::com::sun::star::uno::Any m_aOuterValue
;
77 ::com::sun::star::uno::Any m_aDefaultValue
;
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
)
86 , m_aDefaultValue(rDefaulValue
)
89 WrappedStockProperty::~WrappedStockProperty()
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
)
96 sal_Bool bNewValue
= false;
97 if( ! (rOuterValue
>>= bNewValue
) )
98 throw lang::IllegalArgumentException( C2U("stock properties require type sal_Bool"), 0, 0 );
100 m_aOuterValue
= rOuterValue
;
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 )
107 Reference
< lang::XMultiServiceFactory
> xFactory( xChartDoc
->getChartTypeManager(), uno::UNO_QUERY
);
108 DiagramHelper::tTemplateWithServiceName aTemplateAndService
=
109 DiagramHelper::getTemplateForDiagram( xDiagram
, xFactory
);
111 uno::Reference
< chart2::XChartTypeTemplate
> xTemplate
=
112 getNewTemplate( bNewValue
, aTemplateAndService
.second
, xFactory
);
118 // /-- locked controllers
119 ControllerLockGuard
aCtrlLockGuard( m_spChart2ModelContact
->getChartModel() );
120 xTemplate
->changeDiagram( xDiagram
);
121 // \-- locked controllers
123 catch( uno::Exception
& ex
)
125 ASSERT_EXCEPTION( ex
);
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
)
134 return m_aDefaultValue
;
137 //-------------------------------------------------------------------------------------
138 //-------------------------------------------------------------------------------------
139 //-------------------------------------------------------------------------------------
141 class WrappedVolumeProperty
: public WrappedStockProperty
144 explicit WrappedVolumeProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
);
145 virtual ~WrappedVolumeProperty();
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
);
150 uno::Reference
< chart2::XChartTypeTemplate
> getNewTemplate( sal_Bool bNewValue
, const rtl::OUString
& rCurrentTemplate
, const Reference
< lang::XMultiServiceFactory
>& xFactory
) const;
153 WrappedVolumeProperty::WrappedVolumeProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
154 : WrappedStockProperty( C2U("Volume"), uno::makeAny(sal_False
) , spChart2ModelContact
)
157 WrappedVolumeProperty::~WrappedVolumeProperty()
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
)
164 Reference
< chart2::XChartDocument
> xChartDoc( m_spChart2ModelContact
->getChart2Document() );
165 Reference
< chart2::XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
166 if( xDiagram
.is() && xChartDoc
.is() )
168 ::std::vector
< uno::Reference
< chart2::XDataSeries
> > aSeriesVector(
169 DiagramHelper::getDataSeriesFromDiagram( xDiagram
) );
170 if( aSeriesVector
.size() > 0 )
172 Reference
< lang::XMultiServiceFactory
> xFact( xChartDoc
->getChartTypeManager(), uno::UNO_QUERY
);
173 DiagramHelper::tTemplateWithServiceName aTemplateAndService
=
174 DiagramHelper::getTemplateForDiagram( xDiagram
, xFact
);
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
);
182 else if(!m_aOuterValue
.hasValue())
183 m_aOuterValue
<<= sal_Bool(sal_False
);
185 return m_aOuterValue
;
188 uno::Reference
< chart2::XChartTypeTemplate
> WrappedVolumeProperty::getNewTemplate( sal_Bool bNewValue
, const rtl::OUString
& rCurrentTemplate
, const Reference
< lang::XMultiServiceFactory
>& xFactory
) const
190 uno::Reference
< chart2::XChartTypeTemplate
> xTemplate(0);
195 if( bNewValue
) //add volume
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
);
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
);
212 //-------------------------------------------------------------------------------------
213 //-------------------------------------------------------------------------------------
216 class WrappedUpDownProperty
: public WrappedStockProperty
219 explicit WrappedUpDownProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
);
220 virtual ~WrappedUpDownProperty();
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
);
225 uno::Reference
< chart2::XChartTypeTemplate
> getNewTemplate( sal_Bool bNewValue
, const rtl::OUString
& rCurrentTemplate
, const Reference
< lang::XMultiServiceFactory
>& xFactory
) const;
227 WrappedUpDownProperty::WrappedUpDownProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
228 : WrappedStockProperty( C2U("UpDown"), uno::makeAny(sal_False
) , spChart2ModelContact
)
231 WrappedUpDownProperty::~WrappedUpDownProperty()
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
)
237 Reference
< chart2::XChartDocument
> xChartDoc( m_spChart2ModelContact
->getChart2Document() );
238 Reference
< chart2::XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
239 if( xDiagram
.is() && xChartDoc
.is() )
241 ::std::vector
< uno::Reference
< chart2::XDataSeries
> > aSeriesVector(
242 DiagramHelper::getDataSeriesFromDiagram( xDiagram
) );
243 if( aSeriesVector
.size() > 0 )
245 Reference
< lang::XMultiServiceFactory
> xFact( xChartDoc
->getChartTypeManager(), uno::UNO_QUERY
);
246 DiagramHelper::tTemplateWithServiceName aTemplateAndService
=
247 DiagramHelper::getTemplateForDiagram( xDiagram
, xFact
);
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
);
255 else if(!m_aOuterValue
.hasValue())
256 m_aOuterValue
<<= sal_Bool(sal_False
);
258 return m_aOuterValue
;
260 uno::Reference
< chart2::XChartTypeTemplate
> WrappedUpDownProperty::getNewTemplate( sal_Bool bNewValue
, const rtl::OUString
& rCurrentTemplate
, const Reference
< lang::XMultiServiceFactory
>& xFactory
) const
262 uno::Reference
< chart2::XChartTypeTemplate
> xTemplate(0);
263 if( bNewValue
) //add open series
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
);
270 else //remove open series
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
);
285 PROP_CHART_STOCK_VOLUME
= FAST_PROPERTY_ID_START_CHART_STOCK_PROP
286 , PROP_CHART_STOCK_UPDOWN
289 }//anonymous namespace
291 //-----------------------------------------------------------------------------
292 //-----------------------------------------------------------------------------
293 //-----------------------------------------------------------------------------
295 void WrappedStockProperties::addProperties( ::std::vector
< Property
> & rOutProperties
)
297 rOutProperties
.push_back(
298 Property( C2U( "Volume" ),
299 PROP_CHART_STOCK_VOLUME
,
300 ::getCppuType( reinterpret_cast< sal_Bool
* >(0)),
301 beans::PropertyAttribute::BOUND
302 | beans::PropertyAttribute::MAYBEDEFAULT
303 | beans::PropertyAttribute::MAYBEVOID
));
304 rOutProperties
.push_back(
305 Property( C2U( "UpDown" ),
306 PROP_CHART_STOCK_UPDOWN
,
307 ::getCppuType( reinterpret_cast< sal_Bool
* >(0)),
308 beans::PropertyAttribute::BOUND
309 | beans::PropertyAttribute::MAYBEDEFAULT
310 | beans::PropertyAttribute::MAYBEVOID
));
313 //-----------------------------------------------------------------------------
314 //-----------------------------------------------------------------------------
317 void WrappedStockProperties::addWrappedProperties( std::vector
< WrappedProperty
* >& rList
318 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
320 rList
.push_back( new WrappedVolumeProperty( spChart2ModelContact
) );
321 rList
.push_back( new WrappedUpDownProperty( spChart2ModelContact
) );
324 //-----------------------------------------------------------------------------
325 //-----------------------------------------------------------------------------
326 //-----------------------------------------------------------------------------
328 } //namespace wrapper
330 //.............................................................................