Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "WrappedStockProperties.hxx"
21 : #include "macros.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>
28 :
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;
34 :
35 : namespace chart
36 : {
37 : namespace wrapper
38 : {
39 :
40 : class WrappedStockProperty : public WrappedProperty
41 : {
42 : public:
43 : explicit WrappedStockProperty( const OUString& rOuterName
44 : , const ::com::sun::star::uno::Any& rDefaulValue
45 : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
46 : virtual ~WrappedStockProperty();
47 :
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;
50 :
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;
53 :
54 : virtual uno::Reference< chart2::XChartTypeTemplate > getNewTemplate( bool bNewValue, const OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const = 0;
55 :
56 : protected:
57 : ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
58 : mutable ::com::sun::star::uno::Any m_aOuterValue;
59 : ::com::sun::star::uno::Any m_aDefaultValue;
60 : };
61 :
62 614 : 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)
67 : , m_aOuterValue()
68 614 : , m_aDefaultValue(rDefaulValue)
69 : {
70 614 : }
71 614 : WrappedStockProperty::~WrappedStockProperty()
72 : {
73 614 : }
74 :
75 7 : 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)
77 : {
78 7 : bool bNewValue = false;
79 7 : if( ! (rOuterValue >>= bNewValue) )
80 0 : throw lang::IllegalArgumentException( "stock properties require type sal_Bool", 0, 0 );
81 :
82 7 : m_aOuterValue = rOuterValue;
83 :
84 7 : Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
85 14 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
86 7 : sal_Int32 nDimension = ::chart::DiagramHelper::getDimension( xDiagram );
87 7 : if( xChartDoc.is() && xDiagram.is() && nDimension==2 )
88 : {
89 7 : Reference< lang::XMultiServiceFactory > xFactory( xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
90 : DiagramHelper::tTemplateWithServiceName aTemplateAndService =
91 14 : DiagramHelper::getTemplateForDiagram( xDiagram, xFactory );
92 :
93 : uno::Reference< chart2::XChartTypeTemplate > xTemplate =
94 14 : getNewTemplate( bNewValue, aTemplateAndService.second, xFactory );
95 :
96 7 : if(xTemplate.is())
97 : {
98 : try
99 : {
100 : // locked controllers
101 1 : ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getChartModel() );
102 1 : xTemplate->changeDiagram( xDiagram );
103 : }
104 0 : catch( const uno::Exception & ex )
105 : {
106 : ASSERT_EXCEPTION( ex );
107 : }
108 7 : }
109 7 : }
110 7 : }
111 :
112 1072 : ::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)
114 : {
115 1072 : return m_aDefaultValue;
116 : }
117 :
118 : class WrappedVolumeProperty : public WrappedStockProperty
119 : {
120 : public:
121 : explicit WrappedVolumeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
122 : virtual ~WrappedVolumeProperty();
123 :
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;
126 :
127 : uno::Reference< chart2::XChartTypeTemplate > getNewTemplate( bool bNewValue, const OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const SAL_OVERRIDE;
128 : };
129 :
130 307 : WrappedVolumeProperty::WrappedVolumeProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
131 307 : : WrappedStockProperty( "Volume", uno::makeAny(sal_False) , spChart2ModelContact )
132 : {
133 307 : }
134 614 : WrappedVolumeProperty::~WrappedVolumeProperty()
135 : {
136 614 : }
137 :
138 636 : ::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)
140 : {
141 636 : Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
142 1272 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
143 636 : if( xDiagram.is() && xChartDoc.is() )
144 : {
145 : ::std::vector< uno::Reference< chart2::XDataSeries > > aSeriesVector(
146 634 : DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
147 634 : if( aSeriesVector.size() > 0 )
148 : {
149 548 : Reference< lang::XMultiServiceFactory > xFact( xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
150 : DiagramHelper::tTemplateWithServiceName aTemplateAndService =
151 1096 : DiagramHelper::getTemplateForDiagram( xDiagram, xFact );
152 :
153 1096 : if( aTemplateAndService.second == "com.sun.star.chart2.template.StockVolumeLowHighClose"
154 548 : || aTemplateAndService.second == "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" )
155 24 : m_aOuterValue <<= true;
156 524 : else if( !aTemplateAndService.second.isEmpty() || !m_aOuterValue.hasValue() )
157 1072 : m_aOuterValue <<= false;
158 : }
159 86 : else if(!m_aOuterValue.hasValue())
160 83 : m_aOuterValue <<= false;
161 : }
162 1272 : return m_aOuterValue;
163 : }
164 :
165 3 : uno::Reference< chart2::XChartTypeTemplate > WrappedVolumeProperty::getNewTemplate( bool bNewValue, const OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const
166 : {
167 3 : uno::Reference< chart2::XChartTypeTemplate > xTemplate(0);
168 :
169 3 : if(!xFactory.is())
170 0 : return xTemplate;
171 :
172 3 : if( bNewValue ) //add volume
173 : {
174 0 : if( rCurrentTemplate == "com.sun.star.chart2.template.StockLowHighClose" )
175 0 : xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockVolumeLowHighClose" ), uno::UNO_QUERY );
176 0 : else if( rCurrentTemplate == "com.sun.star.chart2.template.StockOpenLowHighClose" )
177 0 : xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ), uno::UNO_QUERY );
178 : }
179 : else //remove volume
180 : {
181 3 : if( rCurrentTemplate == "com.sun.star.chart2.template.StockVolumeLowHighClose" )
182 0 : xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockLowHighClose" ), uno::UNO_QUERY );
183 3 : else if( rCurrentTemplate == "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" )
184 0 : xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockOpenLowHighClose" ), uno::UNO_QUERY );
185 : }
186 3 : return xTemplate;
187 : }
188 :
189 : class WrappedUpDownProperty : public WrappedStockProperty
190 : {
191 : public:
192 : explicit WrappedUpDownProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
193 : virtual ~WrappedUpDownProperty();
194 :
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;
197 :
198 : uno::Reference< chart2::XChartTypeTemplate > getNewTemplate( bool bNewValue, const OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const SAL_OVERRIDE;
199 : };
200 307 : WrappedUpDownProperty::WrappedUpDownProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
201 307 : : WrappedStockProperty( "UpDown", uno::makeAny(sal_False) , spChart2ModelContact )
202 : {
203 307 : }
204 614 : WrappedUpDownProperty::~WrappedUpDownProperty()
205 : {
206 614 : }
207 550 : ::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)
209 : {
210 550 : Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
211 1100 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
212 550 : if( xDiagram.is() && xChartDoc.is() )
213 : {
214 : ::std::vector< uno::Reference< chart2::XDataSeries > > aSeriesVector(
215 548 : DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
216 548 : if( aSeriesVector.size() > 0 )
217 : {
218 548 : Reference< lang::XMultiServiceFactory > xFact( xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
219 : DiagramHelper::tTemplateWithServiceName aTemplateAndService =
220 1096 : DiagramHelper::getTemplateForDiagram( xDiagram, xFact );
221 :
222 1096 : if( aTemplateAndService.second == "com.sun.star.chart2.template.StockOpenLowHighClose"
223 548 : || aTemplateAndService.second == "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" )
224 24 : m_aOuterValue <<= true;
225 524 : else if( !aTemplateAndService.second.isEmpty() || !m_aOuterValue.hasValue() )
226 1072 : m_aOuterValue <<= false;
227 : }
228 0 : else if(!m_aOuterValue.hasValue())
229 0 : m_aOuterValue <<= false;
230 : }
231 1100 : return m_aOuterValue;
232 : }
233 4 : uno::Reference< chart2::XChartTypeTemplate > WrappedUpDownProperty::getNewTemplate( bool bNewValue, const OUString& rCurrentTemplate, const Reference< lang::XMultiServiceFactory >& xFactory ) const
234 : {
235 4 : uno::Reference< chart2::XChartTypeTemplate > xTemplate(0);
236 4 : if( bNewValue ) //add open series
237 : {
238 1 : if( rCurrentTemplate == "com.sun.star.chart2.template.StockLowHighClose" )
239 1 : xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockOpenLowHighClose" ), uno::UNO_QUERY );
240 0 : else if( rCurrentTemplate == "com.sun.star.chart2.template.StockVolumeLowHighClose" )
241 0 : xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ), uno::UNO_QUERY );
242 : }
243 : else //remove open series
244 : {
245 3 : if( rCurrentTemplate == "com.sun.star.chart2.template.StockOpenLowHighClose" )
246 0 : xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockLowHighClose" ), uno::UNO_QUERY );
247 3 : else if( rCurrentTemplate == "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" )
248 0 : xTemplate.set( xFactory->createInstance( "com.sun.star.chart2.template.StockVolumeLowHighClose" ), uno::UNO_QUERY );
249 : }
250 4 : return xTemplate;
251 : }
252 :
253 : namespace
254 : {
255 : enum
256 : {
257 : //spline properties
258 : PROP_CHART_STOCK_VOLUME = FAST_PROPERTY_ID_START_CHART_STOCK_PROP
259 : , PROP_CHART_STOCK_UPDOWN
260 : };
261 :
262 : }//anonymous namespace
263 :
264 14 : void WrappedStockProperties::addProperties( ::std::vector< Property > & rOutProperties )
265 : {
266 : rOutProperties.push_back(
267 : Property( "Volume",
268 : PROP_CHART_STOCK_VOLUME,
269 14 : cppu::UnoType<sal_Bool>::get(),
270 : beans::PropertyAttribute::BOUND
271 : | beans::PropertyAttribute::MAYBEDEFAULT
272 28 : | beans::PropertyAttribute::MAYBEVOID ));
273 : rOutProperties.push_back(
274 : Property( "UpDown",
275 : PROP_CHART_STOCK_UPDOWN,
276 14 : cppu::UnoType<sal_Bool>::get(),
277 : beans::PropertyAttribute::BOUND
278 : | beans::PropertyAttribute::MAYBEDEFAULT
279 28 : | beans::PropertyAttribute::MAYBEVOID ));
280 14 : }
281 :
282 307 : void WrappedStockProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
283 : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
284 : {
285 307 : rList.push_back( new WrappedVolumeProperty( spChart2ModelContact ) );
286 307 : rList.push_back( new WrappedUpDownProperty( spChart2ModelContact ) );
287 307 : }
288 :
289 : } //namespace wrapper
290 : } //namespace chart
291 :
292 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|