1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "WrappedStockProperties.hxx"
22 #include "FastPropertyIdRanges.hxx"
23 #include "DiagramHelper.hxx"
24 #include "ChartModelHelper.hxx"
25 #include "ControllerLockGuard.hxx"
26 #include <com/sun/star/chart2/XChartDocument.hpp>
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 using namespace ::com::sun::star
;
30 using ::com::sun::star::uno::Any
;
31 using ::com::sun::star::uno::Reference
;
32 using ::com::sun::star::uno::Sequence
;
33 using ::com::sun::star::beans::Property
;
40 class WrappedStockProperty
: public WrappedProperty
43 explicit WrappedStockProperty( const OUString
& rOuterName
44 , const ::com::sun::star::uno::Any
& rDefaulValue
45 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
);
46 virtual ~WrappedStockProperty();
48 void setPropertyValue( const ::com::sun::star::uno::Any
& rOuterValue
, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xInnerPropertySet
) const
49 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
) SAL_OVERRIDE
;
51 ::com::sun::star::uno::Any
getPropertyDefault( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyState
>& xInnerPropertyState
) const
52 throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
54 virtual uno::Reference
< chart2::XChartTypeTemplate
> getNewTemplate( bool bNewValue
, const OUString
& rCurrentTemplate
, const Reference
< lang::XMultiServiceFactory
>& xFactory
) const = 0;
57 ::boost::shared_ptr
< Chart2ModelContact
> m_spChart2ModelContact
;
58 mutable ::com::sun::star::uno::Any m_aOuterValue
;
59 ::com::sun::star::uno::Any m_aDefaultValue
;
62 WrappedStockProperty::WrappedStockProperty( const OUString
& rOuterName
63 , const ::com::sun::star::uno::Any
& rDefaulValue
64 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
65 : WrappedProperty(rOuterName
,OUString())
66 , m_spChart2ModelContact(spChart2ModelContact
)
68 , m_aDefaultValue(rDefaulValue
)
71 WrappedStockProperty::~WrappedStockProperty()
75 void WrappedStockProperty::setPropertyValue( const ::com::sun::star::uno::Any
& rOuterValue
, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& /*xInnerPropertySet*/ ) const
76 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
)
78 bool bNewValue
= false;
79 if( ! (rOuterValue
>>= bNewValue
) )
80 throw lang::IllegalArgumentException( "stock properties require type sal_Bool", 0, 0 );
82 m_aOuterValue
= rOuterValue
;
84 Reference
< chart2::XChartDocument
> xChartDoc( m_spChart2ModelContact
->getChart2Document() );
85 Reference
< chart2::XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
86 sal_Int32 nDimension
= ::chart::DiagramHelper::getDimension( xDiagram
);
87 if( xChartDoc
.is() && xDiagram
.is() && nDimension
==2 )
89 Reference
< lang::XMultiServiceFactory
> xFactory( xChartDoc
->getChartTypeManager(), uno::UNO_QUERY
);
90 DiagramHelper::tTemplateWithServiceName aTemplateAndService
=
91 DiagramHelper::getTemplateForDiagram( xDiagram
, xFactory
);
93 uno::Reference
< chart2::XChartTypeTemplate
> xTemplate
=
94 getNewTemplate( bNewValue
, aTemplateAndService
.second
, xFactory
);
100 // locked controllers
101 ControllerLockGuardUNO
aCtrlLockGuard( m_spChart2ModelContact
->getChartModel() );
102 xTemplate
->changeDiagram( xDiagram
);
104 catch( const uno::Exception
& ex
)
106 ASSERT_EXCEPTION( ex
);
112 ::com::sun::star::uno::Any
WrappedStockProperty::getPropertyDefault( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyState
>& /*xInnerPropertyState*/ ) const
113 throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
)
115 return m_aDefaultValue
;
118 class WrappedVolumeProperty
: public WrappedStockProperty
121 explicit WrappedVolumeProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
);
122 virtual ~WrappedVolumeProperty();
124 ::com::sun::star::uno::Any
getPropertyValue( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xInnerPropertySet
) const
125 throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
127 uno::Reference
< chart2::XChartTypeTemplate
> getNewTemplate( bool bNewValue
, const OUString
& rCurrentTemplate
, const Reference
< lang::XMultiServiceFactory
>& xFactory
) const SAL_OVERRIDE
;
130 WrappedVolumeProperty::WrappedVolumeProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
131 : WrappedStockProperty( "Volume", uno::makeAny(sal_False
) , spChart2ModelContact
)
134 WrappedVolumeProperty::~WrappedVolumeProperty()
138 ::com::sun::star::uno::Any
WrappedVolumeProperty::getPropertyValue( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& /*xInnerPropertySet*/ ) const
139 throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
)
141 Reference
< chart2::XChartDocument
> xChartDoc( m_spChart2ModelContact
->getChart2Document() );
142 Reference
< chart2::XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
143 if( xDiagram
.is() && xChartDoc
.is() )
145 ::std::vector
< uno::Reference
< chart2::XDataSeries
> > aSeriesVector(
146 DiagramHelper::getDataSeriesFromDiagram( xDiagram
) );
147 if( aSeriesVector
.size() > 0 )
149 Reference
< lang::XMultiServiceFactory
> xFact( xChartDoc
->getChartTypeManager(), uno::UNO_QUERY
);
150 DiagramHelper::tTemplateWithServiceName aTemplateAndService
=
151 DiagramHelper::getTemplateForDiagram( xDiagram
, xFact
);
153 if( aTemplateAndService
.second
== "com.sun.star.chart2.template.StockVolumeLowHighClose"
154 || aTemplateAndService
.second
== "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" )
155 m_aOuterValue
<<= true;
156 else if( !aTemplateAndService
.second
.isEmpty() || !m_aOuterValue
.hasValue() )
157 m_aOuterValue
<<= false;
159 else if(!m_aOuterValue
.hasValue())
160 m_aOuterValue
<<= false;
162 return m_aOuterValue
;
165 uno::Reference
< chart2::XChartTypeTemplate
> WrappedVolumeProperty::getNewTemplate( bool bNewValue
, const OUString
& rCurrentTemplate
, const Reference
< lang::XMultiServiceFactory
>& xFactory
) const
167 uno::Reference
< chart2::XChartTypeTemplate
> xTemplate(0);
172 if( bNewValue
) //add volume
174 if( rCurrentTemplate
== "com.sun.star.chart2.template.StockLowHighClose" )
175 xTemplate
.set( xFactory
->createInstance( "com.sun.star.chart2.template.StockVolumeLowHighClose" ), uno::UNO_QUERY
);
176 else if( rCurrentTemplate
== "com.sun.star.chart2.template.StockOpenLowHighClose" )
177 xTemplate
.set( xFactory
->createInstance( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ), uno::UNO_QUERY
);
181 if( rCurrentTemplate
== "com.sun.star.chart2.template.StockVolumeLowHighClose" )
182 xTemplate
.set( xFactory
->createInstance( "com.sun.star.chart2.template.StockLowHighClose" ), uno::UNO_QUERY
);
183 else if( rCurrentTemplate
== "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" )
184 xTemplate
.set( xFactory
->createInstance( "com.sun.star.chart2.template.StockOpenLowHighClose" ), uno::UNO_QUERY
);
189 class WrappedUpDownProperty
: public WrappedStockProperty
192 explicit WrappedUpDownProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
);
193 virtual ~WrappedUpDownProperty();
195 ::com::sun::star::uno::Any
getPropertyValue( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xInnerPropertySet
) const
196 throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
198 uno::Reference
< chart2::XChartTypeTemplate
> getNewTemplate( bool bNewValue
, const OUString
& rCurrentTemplate
, const Reference
< lang::XMultiServiceFactory
>& xFactory
) const SAL_OVERRIDE
;
200 WrappedUpDownProperty::WrappedUpDownProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
201 : WrappedStockProperty( "UpDown", uno::makeAny(sal_False
) , spChart2ModelContact
)
204 WrappedUpDownProperty::~WrappedUpDownProperty()
207 ::com::sun::star::uno::Any
WrappedUpDownProperty::getPropertyValue( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& /*xInnerPropertySet*/ ) const
208 throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
)
210 Reference
< chart2::XChartDocument
> xChartDoc( m_spChart2ModelContact
->getChart2Document() );
211 Reference
< chart2::XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
212 if( xDiagram
.is() && xChartDoc
.is() )
214 ::std::vector
< uno::Reference
< chart2::XDataSeries
> > aSeriesVector(
215 DiagramHelper::getDataSeriesFromDiagram( xDiagram
) );
216 if( aSeriesVector
.size() > 0 )
218 Reference
< lang::XMultiServiceFactory
> xFact( xChartDoc
->getChartTypeManager(), uno::UNO_QUERY
);
219 DiagramHelper::tTemplateWithServiceName aTemplateAndService
=
220 DiagramHelper::getTemplateForDiagram( xDiagram
, xFact
);
222 if( aTemplateAndService
.second
== "com.sun.star.chart2.template.StockOpenLowHighClose"
223 || aTemplateAndService
.second
== "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" )
224 m_aOuterValue
<<= true;
225 else if( !aTemplateAndService
.second
.isEmpty() || !m_aOuterValue
.hasValue() )
226 m_aOuterValue
<<= false;
228 else if(!m_aOuterValue
.hasValue())
229 m_aOuterValue
<<= false;
231 return m_aOuterValue
;
233 uno::Reference
< chart2::XChartTypeTemplate
> WrappedUpDownProperty::getNewTemplate( bool bNewValue
, const OUString
& rCurrentTemplate
, const Reference
< lang::XMultiServiceFactory
>& xFactory
) const
235 uno::Reference
< chart2::XChartTypeTemplate
> xTemplate(0);
236 if( bNewValue
) //add open series
238 if( rCurrentTemplate
== "com.sun.star.chart2.template.StockLowHighClose" )
239 xTemplate
.set( xFactory
->createInstance( "com.sun.star.chart2.template.StockOpenLowHighClose" ), uno::UNO_QUERY
);
240 else if( rCurrentTemplate
== "com.sun.star.chart2.template.StockVolumeLowHighClose" )
241 xTemplate
.set( xFactory
->createInstance( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ), uno::UNO_QUERY
);
243 else //remove open series
245 if( rCurrentTemplate
== "com.sun.star.chart2.template.StockOpenLowHighClose" )
246 xTemplate
.set( xFactory
->createInstance( "com.sun.star.chart2.template.StockLowHighClose" ), uno::UNO_QUERY
);
247 else if( rCurrentTemplate
== "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" )
248 xTemplate
.set( xFactory
->createInstance( "com.sun.star.chart2.template.StockVolumeLowHighClose" ), uno::UNO_QUERY
);
258 PROP_CHART_STOCK_VOLUME
= FAST_PROPERTY_ID_START_CHART_STOCK_PROP
259 , PROP_CHART_STOCK_UPDOWN
262 }//anonymous namespace
264 void WrappedStockProperties::addProperties( ::std::vector
< Property
> & rOutProperties
)
266 rOutProperties
.push_back(
268 PROP_CHART_STOCK_VOLUME
,
269 cppu::UnoType
<sal_Bool
>::get(),
270 beans::PropertyAttribute::BOUND
271 | beans::PropertyAttribute::MAYBEDEFAULT
272 | beans::PropertyAttribute::MAYBEVOID
));
273 rOutProperties
.push_back(
275 PROP_CHART_STOCK_UPDOWN
,
276 cppu::UnoType
<sal_Bool
>::get(),
277 beans::PropertyAttribute::BOUND
278 | beans::PropertyAttribute::MAYBEDEFAULT
279 | beans::PropertyAttribute::MAYBEVOID
));
282 void WrappedStockProperties::addWrappedProperties( std::vector
< WrappedProperty
* >& rList
283 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
285 rList
.push_back( new WrappedVolumeProperty( spChart2ModelContact
) );
286 rList
.push_back( new WrappedUpDownProperty( spChart2ModelContact
) );
289 } //namespace wrapper
292 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */