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