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