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 "WrappedAxisAndGridExistenceProperties.hxx"
21 : #include "AxisHelper.hxx"
22 : #include "ChartModelHelper.hxx"
23 : #include "TitleHelper.hxx"
24 : #include "macros.hxx"
25 :
26 : using namespace ::com::sun::star;
27 : using ::com::sun::star::uno::Any;
28 : using ::com::sun::star::uno::Reference;
29 : using ::com::sun::star::uno::Sequence;
30 :
31 : namespace chart
32 : {
33 : namespace wrapper
34 : {
35 :
36 : class WrappedAxisAndGridExistenceProperty : public WrappedProperty
37 : {
38 : public:
39 : WrappedAxisAndGridExistenceProperty( bool bAxis, bool bMain, sal_Int32 nDimensionIndex
40 : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
41 : virtual ~WrappedAxisAndGridExistenceProperty();
42 :
43 : virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
44 : 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;
45 :
46 : virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
47 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
48 :
49 : virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
50 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
51 :
52 : private: //member
53 : ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
54 : bool m_bAxis;
55 : bool m_bMain;
56 : sal_Int32 m_nDimensionIndex;
57 : };
58 :
59 580 : void WrappedAxisAndGridExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
60 : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
61 : {
62 580 : rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 0, spChart2ModelContact ) );//x axis
63 580 : rList.push_back( new WrappedAxisAndGridExistenceProperty( true, false, 0, spChart2ModelContact ) );//x secondary axis
64 580 : rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 0, spChart2ModelContact ) );//x grid
65 580 : rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 0, spChart2ModelContact ) );//x help grid
66 :
67 580 : rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 1, spChart2ModelContact ) );//y axis
68 580 : rList.push_back( new WrappedAxisAndGridExistenceProperty( true, false, 1, spChart2ModelContact ) );//y secondary axis
69 580 : rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 1, spChart2ModelContact ) );//y grid
70 580 : rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 1, spChart2ModelContact ) );//y help grid
71 :
72 580 : rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 2, spChart2ModelContact ) );//z axis
73 580 : rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 2, spChart2ModelContact ) );//z grid
74 580 : rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 2, spChart2ModelContact ) );//z help grid
75 580 : }
76 :
77 6380 : WrappedAxisAndGridExistenceProperty::WrappedAxisAndGridExistenceProperty( bool bAxis, bool bMain, sal_Int32 nDimensionIndex
78 : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
79 : : WrappedProperty(OUString(),OUString())
80 : , m_spChart2ModelContact( spChart2ModelContact )
81 : , m_bAxis( bAxis )
82 : , m_bMain( bMain )
83 6380 : , m_nDimensionIndex( nDimensionIndex )
84 : {
85 6380 : switch( m_nDimensionIndex )
86 : {
87 : case 0:
88 : {
89 2320 : if( m_bAxis )
90 : {
91 1160 : if( m_bMain )
92 580 : m_aOuterName = "HasXAxis";
93 : else
94 580 : m_aOuterName = "HasSecondaryXAxis";
95 : }
96 : else
97 : {
98 1160 : if( m_bMain )
99 580 : m_aOuterName = "HasXAxisGrid";
100 : else
101 580 : m_aOuterName = "HasXAxisHelpGrid";
102 : }
103 : }
104 2320 : break;
105 : case 2:
106 : {
107 1740 : if( m_bAxis )
108 : {
109 : OSL_ENSURE(m_bMain == true,"there is no secondary z axis at the old api");
110 580 : m_bMain = true;
111 580 : m_aOuterName = "HasZAxis";
112 : }
113 : else
114 : {
115 1160 : if( m_bMain )
116 580 : m_aOuterName = "HasZAxisGrid";
117 : else
118 580 : m_aOuterName = "HasZAxisHelpGrid";
119 : }
120 : }
121 1740 : break;
122 : default:
123 : {
124 2320 : if( m_bAxis )
125 : {
126 1160 : if( m_bMain )
127 580 : m_aOuterName = "HasYAxis";
128 : else
129 580 : m_aOuterName = "HasSecondaryYAxis";
130 : }
131 : else
132 : {
133 1160 : if( m_bMain )
134 580 : m_aOuterName = "HasYAxisGrid";
135 : else
136 580 : m_aOuterName = "HasYAxisHelpGrid";
137 : }
138 : }
139 2320 : break;
140 : }
141 6380 : }
142 :
143 12760 : WrappedAxisAndGridExistenceProperty::~WrappedAxisAndGridExistenceProperty()
144 : {
145 12760 : }
146 :
147 2550 : void WrappedAxisAndGridExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
148 : throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
149 : {
150 2550 : bool bNewValue = false;
151 2550 : if( ! (rOuterValue >>= bNewValue) )
152 0 : throw lang::IllegalArgumentException( "Has axis or grid properties require boolean values", 0, 0 );
153 :
154 2550 : bool bOldValue = false;
155 2550 : getPropertyValue( xInnerPropertySet ) >>= bOldValue;
156 :
157 2550 : if( bOldValue == bNewValue )
158 3710 : return;
159 :
160 1390 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
161 1390 : if( bNewValue )
162 : {
163 658 : if( m_bAxis )
164 400 : AxisHelper::showAxis( m_nDimensionIndex, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext );
165 : else
166 258 : AxisHelper::showGrid( m_nDimensionIndex, 0, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext );
167 : }
168 : else
169 : {
170 732 : if( m_bAxis )
171 488 : AxisHelper::hideAxis( m_nDimensionIndex, m_bMain, xDiagram );
172 : else
173 244 : AxisHelper::hideGrid( m_nDimensionIndex, 0, m_bMain, xDiagram );
174 1390 : }
175 : }
176 :
177 15610 : Any WrappedAxisAndGridExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /* xInnerPropertySet */ ) const
178 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
179 : {
180 15610 : Any aRet;
181 31220 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
182 15610 : if(m_bAxis)
183 : {
184 7400 : bool bShown = AxisHelper::isAxisShown( m_nDimensionIndex, m_bMain, xDiagram );
185 7400 : aRet <<= bShown;
186 : }
187 : else
188 : {
189 8210 : bool bShown = AxisHelper::isGridShown( m_nDimensionIndex, 0, m_bMain, xDiagram );
190 8210 : aRet <<= bShown;
191 : }
192 31220 : return aRet;
193 : }
194 :
195 0 : Any WrappedAxisAndGridExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
196 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
197 : {
198 0 : Any aRet;
199 0 : aRet <<= false;
200 0 : return aRet;
201 : }
202 :
203 : class WrappedAxisTitleExistenceProperty : public WrappedProperty
204 : {
205 : public:
206 : WrappedAxisTitleExistenceProperty( sal_Int32 nTitleIndex
207 : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
208 : virtual ~WrappedAxisTitleExistenceProperty();
209 :
210 : virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
211 : 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;
212 :
213 : virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
214 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
215 :
216 : virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
217 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
218 :
219 : private: //member
220 : ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
221 : TitleHelper::eTitleType m_eTitleType;
222 : };
223 :
224 580 : void WrappedAxisTitleExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
225 : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
226 : {
227 580 : rList.push_back( new WrappedAxisTitleExistenceProperty( 0, spChart2ModelContact ) );//x axis title
228 580 : rList.push_back( new WrappedAxisTitleExistenceProperty( 1, spChart2ModelContact ) );//y axis title
229 580 : rList.push_back( new WrappedAxisTitleExistenceProperty( 2, spChart2ModelContact ) );//z axis title
230 580 : rList.push_back( new WrappedAxisTitleExistenceProperty( 3, spChart2ModelContact ) );//secondary x axis title
231 580 : rList.push_back( new WrappedAxisTitleExistenceProperty( 4, spChart2ModelContact ) );//secondary y axis title
232 580 : }
233 :
234 2900 : WrappedAxisTitleExistenceProperty::WrappedAxisTitleExistenceProperty( sal_Int32 nTitleIndex
235 : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
236 : : WrappedProperty(OUString(),OUString())
237 : , m_spChart2ModelContact( spChart2ModelContact )
238 2900 : , m_eTitleType( TitleHelper::Y_AXIS_TITLE )
239 : {
240 2900 : switch( nTitleIndex )
241 : {
242 : case 0:
243 580 : m_aOuterName = "HasXAxisTitle";
244 580 : m_eTitleType = TitleHelper::X_AXIS_TITLE;
245 580 : break;
246 : case 2:
247 580 : m_aOuterName = "HasZAxisTitle";
248 580 : m_eTitleType = TitleHelper::Z_AXIS_TITLE;
249 580 : break;
250 : case 3:
251 580 : m_aOuterName = "HasSecondaryXAxisTitle";
252 580 : m_eTitleType = TitleHelper::SECONDARY_X_AXIS_TITLE;
253 580 : break;
254 : case 4:
255 580 : m_aOuterName = "HasSecondaryYAxisTitle";
256 580 : m_eTitleType = TitleHelper::SECONDARY_Y_AXIS_TITLE;
257 580 : break;
258 : default:
259 580 : m_aOuterName = "HasYAxisTitle";
260 580 : m_eTitleType = TitleHelper::Y_AXIS_TITLE;
261 580 : break;
262 : }
263 2900 : }
264 :
265 5800 : WrappedAxisTitleExistenceProperty::~WrappedAxisTitleExistenceProperty()
266 : {
267 5800 : }
268 :
269 58 : void WrappedAxisTitleExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
270 : throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
271 : {
272 58 : bool bNewValue = false;
273 58 : if( ! (rOuterValue >>= bNewValue) )
274 0 : throw lang::IllegalArgumentException( "Has axis or grid properties require boolean values", 0, 0 );
275 :
276 58 : bool bOldValue = false;
277 58 : getPropertyValue( xInnerPropertySet ) >>= bOldValue;
278 :
279 58 : if( bOldValue == bNewValue )
280 58 : return;
281 :
282 58 : if( bNewValue )
283 : {
284 58 : OUString aTitleText;
285 : TitleHelper::createTitle( m_eTitleType, aTitleText
286 58 : , m_spChart2ModelContact->getChartModel(), m_spChart2ModelContact->m_xContext );
287 : }
288 : else
289 : {
290 0 : TitleHelper::removeTitle( m_eTitleType, m_spChart2ModelContact->getChartModel() );
291 : }
292 : }
293 :
294 6328 : Any WrappedAxisTitleExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
295 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
296 : {
297 6328 : bool bHasTitle = false;
298 :
299 6328 : Reference< chart2::XTitle > xTitle( TitleHelper::getTitle( m_eTitleType, m_spChart2ModelContact->getChartModel() ) );
300 6328 : if( xTitle.is() && !TitleHelper::getCompleteString( xTitle ).isEmpty() )
301 402 : bHasTitle = true;
302 :
303 6328 : Any aRet;
304 6328 : aRet <<= bHasTitle;
305 6328 : return aRet;
306 :
307 : }
308 :
309 0 : Any WrappedAxisTitleExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
310 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
311 : {
312 0 : Any aRet;
313 0 : aRet <<= false;
314 0 : return aRet;
315 : }
316 :
317 : class WrappedAxisLabelExistenceProperty : public WrappedProperty
318 : {
319 : public:
320 : WrappedAxisLabelExistenceProperty( bool bMain, sal_Int32 nDimensionIndex
321 : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
322 : virtual ~WrappedAxisLabelExistenceProperty();
323 :
324 : virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
325 : 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;
326 :
327 : virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
328 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
329 :
330 : virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
331 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
332 :
333 : private: //member
334 : ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
335 : bool m_bMain;
336 : sal_Int32 m_nDimensionIndex;
337 : };
338 :
339 580 : void WrappedAxisLabelExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
340 : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
341 : {
342 580 : rList.push_back( new WrappedAxisLabelExistenceProperty( true, 0, spChart2ModelContact ) );//x axis
343 580 : rList.push_back( new WrappedAxisLabelExistenceProperty( true, 1, spChart2ModelContact ) );//y axis
344 580 : rList.push_back( new WrappedAxisLabelExistenceProperty( true, 2, spChart2ModelContact ) );//z axis
345 580 : rList.push_back( new WrappedAxisLabelExistenceProperty( false, 0, spChart2ModelContact ) );//secondary x axis
346 580 : rList.push_back( new WrappedAxisLabelExistenceProperty( false, 1, spChart2ModelContact ) );//secondary y axis
347 580 : }
348 :
349 2900 : WrappedAxisLabelExistenceProperty::WrappedAxisLabelExistenceProperty( bool bMain, sal_Int32 nDimensionIndex
350 : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
351 : : WrappedProperty(OUString(),OUString())
352 : , m_spChart2ModelContact( spChart2ModelContact )
353 : , m_bMain( bMain )
354 2900 : , m_nDimensionIndex( nDimensionIndex )
355 : {
356 2900 : switch( m_nDimensionIndex )
357 : {
358 : case 0:
359 1160 : m_bMain ? m_aOuterName = "HasXAxisDescription" : m_aOuterName = "HasSecondaryXAxisDescription";
360 1160 : break;
361 : case 2:
362 : OSL_ENSURE(m_bMain,"there is no description available for a secondary z axis");
363 580 : m_aOuterName = "HasZAxisDescription";
364 580 : break;
365 : default:
366 1160 : m_bMain ? m_aOuterName = "HasYAxisDescription" : m_aOuterName = "HasSecondaryYAxisDescription";
367 1160 : break;
368 : }
369 2900 : }
370 :
371 5800 : WrappedAxisLabelExistenceProperty::~WrappedAxisLabelExistenceProperty()
372 : {
373 5800 : }
374 :
375 1224 : void WrappedAxisLabelExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
376 : throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
377 : {
378 1224 : bool bNewValue = false;
379 1224 : if( ! (rOuterValue >>= bNewValue) )
380 0 : throw lang::IllegalArgumentException( "Has axis or grid properties require boolean values", 0, 0 );
381 :
382 1224 : bool bOldValue = false;
383 1224 : getPropertyValue( xInnerPropertySet ) >>= bOldValue;
384 :
385 1224 : if( bOldValue == bNewValue )
386 1956 : return;
387 :
388 492 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
389 984 : Reference< beans::XPropertySet > xProp( AxisHelper::getAxis( m_nDimensionIndex, m_bMain, xDiagram ), uno::UNO_QUERY );
390 492 : if( !xProp.is() && bNewValue )
391 : {
392 : //create axis if needed
393 0 : xProp.set( AxisHelper::createAxis( m_nDimensionIndex, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext ), uno::UNO_QUERY );
394 0 : if( xProp.is() )
395 0 : xProp->setPropertyValue( "Show", uno::makeAny( sal_False ) );
396 : }
397 492 : if( xProp.is() )
398 984 : xProp->setPropertyValue( "DisplayLabels", rOuterValue );
399 : }
400 :
401 1232 : Any WrappedAxisLabelExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
402 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
403 : {
404 1232 : Any aRet;
405 2464 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
406 2464 : Reference< beans::XPropertySet > xProp( AxisHelper::getAxis( m_nDimensionIndex, m_bMain, xDiagram ), uno::UNO_QUERY );
407 1232 : if( xProp.is() )
408 500 : aRet = xProp->getPropertyValue( "DisplayLabels" );
409 : else
410 732 : aRet <<= false;
411 2464 : return aRet;
412 : }
413 :
414 0 : Any WrappedAxisLabelExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
415 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
416 : {
417 0 : Any aRet;
418 0 : aRet <<= true;
419 0 : return aRet;
420 : }
421 :
422 : } //namespace wrapper
423 102 : } //namespace chart
424 :
425 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|