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 307 : void WrappedAxisAndGridExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
60 : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
61 : {
62 307 : rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 0, spChart2ModelContact ) );//x axis
63 307 : rList.push_back( new WrappedAxisAndGridExistenceProperty( true, false, 0, spChart2ModelContact ) );//x secondary axis
64 307 : rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 0, spChart2ModelContact ) );//x grid
65 307 : rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 0, spChart2ModelContact ) );//x help grid
66 :
67 307 : rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 1, spChart2ModelContact ) );//y axis
68 307 : rList.push_back( new WrappedAxisAndGridExistenceProperty( true, false, 1, spChart2ModelContact ) );//y secondary axis
69 307 : rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 1, spChart2ModelContact ) );//y grid
70 307 : rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 1, spChart2ModelContact ) );//y help grid
71 :
72 307 : rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 2, spChart2ModelContact ) );//z axis
73 307 : rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 2, spChart2ModelContact ) );//z grid
74 307 : rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 2, spChart2ModelContact ) );//z help grid
75 307 : }
76 :
77 3377 : 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 3377 : , m_nDimensionIndex( nDimensionIndex )
84 : {
85 3377 : switch( m_nDimensionIndex )
86 : {
87 : case 0:
88 : {
89 1228 : if( m_bAxis )
90 : {
91 614 : if( m_bMain )
92 307 : m_aOuterName = "HasXAxis";
93 : else
94 307 : m_aOuterName = "HasSecondaryXAxis";
95 : }
96 : else
97 : {
98 614 : if( m_bMain )
99 307 : m_aOuterName = "HasXAxisGrid";
100 : else
101 307 : m_aOuterName = "HasXAxisHelpGrid";
102 : }
103 : }
104 1228 : break;
105 : case 2:
106 : {
107 921 : if( m_bAxis )
108 : {
109 : OSL_ENSURE(m_bMain,"there is no secondary z axis at the old api");
110 307 : m_bMain = true;
111 307 : m_aOuterName = "HasZAxis";
112 : }
113 : else
114 : {
115 614 : if( m_bMain )
116 307 : m_aOuterName = "HasZAxisGrid";
117 : else
118 307 : m_aOuterName = "HasZAxisHelpGrid";
119 : }
120 : }
121 921 : break;
122 : default:
123 : {
124 1228 : if( m_bAxis )
125 : {
126 614 : if( m_bMain )
127 307 : m_aOuterName = "HasYAxis";
128 : else
129 307 : m_aOuterName = "HasSecondaryYAxis";
130 : }
131 : else
132 : {
133 614 : if( m_bMain )
134 307 : m_aOuterName = "HasYAxisGrid";
135 : else
136 307 : m_aOuterName = "HasYAxisHelpGrid";
137 : }
138 : }
139 1228 : break;
140 : }
141 3377 : }
142 :
143 6754 : WrappedAxisAndGridExistenceProperty::~WrappedAxisAndGridExistenceProperty()
144 : {
145 6754 : }
146 :
147 887 : 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 887 : bool bNewValue = false;
151 887 : if( ! (rOuterValue >>= bNewValue) )
152 0 : throw lang::IllegalArgumentException( "Has axis or grid properties require boolean values", 0, 0 );
153 :
154 887 : bool bOldValue = false;
155 887 : getPropertyValue( xInnerPropertySet ) >>= bOldValue;
156 :
157 887 : if( bOldValue == bNewValue )
158 1271 : return;
159 :
160 503 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
161 503 : if( bNewValue )
162 : {
163 245 : if( m_bAxis )
164 155 : AxisHelper::showAxis( m_nDimensionIndex, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext );
165 : else
166 90 : AxisHelper::showGrid( m_nDimensionIndex, 0, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext );
167 : }
168 : else
169 : {
170 258 : if( m_bAxis )
171 172 : AxisHelper::hideAxis( m_nDimensionIndex, m_bMain, xDiagram );
172 : else
173 86 : AxisHelper::hideGrid( m_nDimensionIndex, 0, m_bMain, xDiagram );
174 503 : }
175 : }
176 :
177 7579 : Any WrappedAxisAndGridExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /* xInnerPropertySet */ ) const
178 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
179 : {
180 7579 : Any aRet;
181 15158 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
182 7579 : if(m_bAxis)
183 : {
184 3393 : bool bShown = AxisHelper::isAxisShown( m_nDimensionIndex, m_bMain, xDiagram );
185 3393 : aRet <<= bShown;
186 : }
187 : else
188 : {
189 4186 : bool bShown = AxisHelper::isGridShown( m_nDimensionIndex, 0, m_bMain, xDiagram );
190 4186 : aRet <<= bShown;
191 : }
192 15158 : 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 307 : void WrappedAxisTitleExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
225 : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
226 : {
227 307 : rList.push_back( new WrappedAxisTitleExistenceProperty( 0, spChart2ModelContact ) );//x axis title
228 307 : rList.push_back( new WrappedAxisTitleExistenceProperty( 1, spChart2ModelContact ) );//y axis title
229 307 : rList.push_back( new WrappedAxisTitleExistenceProperty( 2, spChart2ModelContact ) );//z axis title
230 307 : rList.push_back( new WrappedAxisTitleExistenceProperty( 3, spChart2ModelContact ) );//secondary x axis title
231 307 : rList.push_back( new WrappedAxisTitleExistenceProperty( 4, spChart2ModelContact ) );//secondary y axis title
232 307 : }
233 :
234 1535 : WrappedAxisTitleExistenceProperty::WrappedAxisTitleExistenceProperty( sal_Int32 nTitleIndex
235 : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
236 : : WrappedProperty(OUString(),OUString())
237 : , m_spChart2ModelContact( spChart2ModelContact )
238 1535 : , m_eTitleType( TitleHelper::Y_AXIS_TITLE )
239 : {
240 1535 : switch( nTitleIndex )
241 : {
242 : case 0:
243 307 : m_aOuterName = "HasXAxisTitle";
244 307 : m_eTitleType = TitleHelper::X_AXIS_TITLE;
245 307 : break;
246 : case 2:
247 307 : m_aOuterName = "HasZAxisTitle";
248 307 : m_eTitleType = TitleHelper::Z_AXIS_TITLE;
249 307 : break;
250 : case 3:
251 307 : m_aOuterName = "HasSecondaryXAxisTitle";
252 307 : m_eTitleType = TitleHelper::SECONDARY_X_AXIS_TITLE;
253 307 : break;
254 : case 4:
255 307 : m_aOuterName = "HasSecondaryYAxisTitle";
256 307 : m_eTitleType = TitleHelper::SECONDARY_Y_AXIS_TITLE;
257 307 : break;
258 : default:
259 307 : m_aOuterName = "HasYAxisTitle";
260 307 : m_eTitleType = TitleHelper::Y_AXIS_TITLE;
261 307 : break;
262 : }
263 1535 : }
264 :
265 3070 : WrappedAxisTitleExistenceProperty::~WrappedAxisTitleExistenceProperty()
266 : {
267 3070 : }
268 :
269 14 : 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 14 : bool bNewValue = false;
273 14 : if( ! (rOuterValue >>= bNewValue) )
274 0 : throw lang::IllegalArgumentException( "Has axis or grid properties require boolean values", 0, 0 );
275 :
276 14 : bool bOldValue = false;
277 14 : getPropertyValue( xInnerPropertySet ) >>= bOldValue;
278 :
279 14 : if( bOldValue == bNewValue )
280 14 : return;
281 :
282 14 : if( bNewValue )
283 : {
284 14 : OUString aTitleText;
285 : TitleHelper::createTitle( m_eTitleType, aTitleText
286 14 : , m_spChart2ModelContact->getChartModel(), m_spChart2ModelContact->m_xContext );
287 : }
288 : else
289 : {
290 0 : TitleHelper::removeTitle( m_eTitleType, m_spChart2ModelContact->getChartModel() );
291 : }
292 : }
293 :
294 3315 : Any WrappedAxisTitleExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
295 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
296 : {
297 3315 : bool bHasTitle = false;
298 :
299 3315 : Reference< chart2::XTitle > xTitle( TitleHelper::getTitle( m_eTitleType, m_spChart2ModelContact->getChartModel() ) );
300 3315 : if( xTitle.is() && !TitleHelper::getCompleteString( xTitle ).isEmpty() )
301 209 : bHasTitle = true;
302 :
303 3315 : Any aRet;
304 3315 : aRet <<= bHasTitle;
305 3315 : 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 307 : void WrappedAxisLabelExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
340 : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
341 : {
342 307 : rList.push_back( new WrappedAxisLabelExistenceProperty( true, 0, spChart2ModelContact ) );//x axis
343 307 : rList.push_back( new WrappedAxisLabelExistenceProperty( true, 1, spChart2ModelContact ) );//y axis
344 307 : rList.push_back( new WrappedAxisLabelExistenceProperty( true, 2, spChart2ModelContact ) );//z axis
345 307 : rList.push_back( new WrappedAxisLabelExistenceProperty( false, 0, spChart2ModelContact ) );//secondary x axis
346 307 : rList.push_back( new WrappedAxisLabelExistenceProperty( false, 1, spChart2ModelContact ) );//secondary y axis
347 307 : }
348 :
349 1535 : 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 1535 : , m_nDimensionIndex( nDimensionIndex )
355 : {
356 1535 : switch( m_nDimensionIndex )
357 : {
358 : case 0:
359 614 : m_bMain ? m_aOuterName = "HasXAxisDescription" : m_aOuterName = "HasSecondaryXAxisDescription";
360 614 : break;
361 : case 2:
362 : OSL_ENSURE(m_bMain,"there is no description available for a secondary z axis");
363 307 : m_aOuterName = "HasZAxisDescription";
364 307 : break;
365 : default:
366 614 : m_bMain ? m_aOuterName = "HasYAxisDescription" : m_aOuterName = "HasSecondaryYAxisDescription";
367 614 : break;
368 : }
369 1535 : }
370 :
371 3070 : WrappedAxisLabelExistenceProperty::~WrappedAxisLabelExistenceProperty()
372 : {
373 3070 : }
374 :
375 432 : 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 432 : bool bNewValue = false;
379 432 : if( ! (rOuterValue >>= bNewValue) )
380 0 : throw lang::IllegalArgumentException( "Has axis or grid properties require boolean values", 0, 0 );
381 :
382 432 : bool bOldValue = false;
383 432 : getPropertyValue( xInnerPropertySet ) >>= bOldValue;
384 :
385 432 : if( bOldValue == bNewValue )
386 690 : return;
387 :
388 174 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
389 348 : Reference< beans::XPropertySet > xProp( AxisHelper::getAxis( m_nDimensionIndex, m_bMain, xDiagram ), uno::UNO_QUERY );
390 174 : 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 174 : if( xProp.is() )
398 348 : xProp->setPropertyValue( "DisplayLabels", rOuterValue );
399 : }
400 :
401 436 : Any WrappedAxisLabelExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
402 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
403 : {
404 436 : Any aRet;
405 872 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
406 872 : Reference< beans::XPropertySet > xProp( AxisHelper::getAxis( m_nDimensionIndex, m_bMain, xDiagram ), uno::UNO_QUERY );
407 436 : if( xProp.is() )
408 178 : aRet = xProp->getPropertyValue( "DisplayLabels" );
409 : else
410 258 : aRet <<= false;
411 872 : 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 : } //namespace chart
424 :
425 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|