merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / controller / chartapiwrapper / WrappedAxisAndGridExistenceProperties.cxx
blob51a7747799c4d3696dc0c93dc07e1c31fac99713
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WrappedAxisAndGridExistenceProperties.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "WrappedAxisAndGridExistenceProperties.hxx"
35 #include "AxisHelper.hxx"
36 #include "ChartModelHelper.hxx"
37 #include "TitleHelper.hxx"
38 #include "macros.hxx"
40 using namespace ::com::sun::star;
41 using ::com::sun::star::uno::Any;
42 using ::com::sun::star::uno::Reference;
43 using ::com::sun::star::uno::Sequence;
44 using ::rtl::OUString;
46 //.............................................................................
47 namespace chart
49 namespace wrapper
52 class WrappedAxisAndGridExistenceProperty : public WrappedProperty
54 public:
55 WrappedAxisAndGridExistenceProperty( bool bAxis, bool bMain, sal_Int32 nDimensionIndex
56 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
57 virtual ~WrappedAxisAndGridExistenceProperty();
59 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
60 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);
62 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
63 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
65 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
66 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
68 private: //member
69 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
70 bool m_bAxis;
71 bool m_bMain;
72 sal_Int32 m_nDimensionIndex;
75 //static
76 void WrappedAxisAndGridExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
77 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
79 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 0, spChart2ModelContact ) );//x axis
80 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, false, 0, spChart2ModelContact ) );//x secondary axis
81 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 0, spChart2ModelContact ) );//x grid
82 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 0, spChart2ModelContact ) );//x help grid
84 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 1, spChart2ModelContact ) );//y axis
85 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, false, 1, spChart2ModelContact ) );//y secondary axis
86 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 1, spChart2ModelContact ) );//y grid
87 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 1, spChart2ModelContact ) );//y help grid
89 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 2, spChart2ModelContact ) );//z axis
90 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 2, spChart2ModelContact ) );//z grid
91 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 2, spChart2ModelContact ) );//z help grid
94 WrappedAxisAndGridExistenceProperty::WrappedAxisAndGridExistenceProperty( bool bAxis, bool bMain, sal_Int32 nDimensionIndex
95 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
96 : WrappedProperty(OUString(),OUString())
97 , m_spChart2ModelContact( spChart2ModelContact )
98 , m_bAxis( bAxis )
99 , m_bMain( bMain )
100 , m_nDimensionIndex( nDimensionIndex )
102 switch( m_nDimensionIndex )
104 case 0:
106 if( m_bAxis )
108 if( m_bMain )
109 m_aOuterName = C2U( "HasXAxis" );
110 else
111 m_aOuterName = C2U( "HasSecondaryXAxis" );
113 else
115 if( m_bMain )
116 m_aOuterName = C2U( "HasXAxisGrid" );
117 else
118 m_aOuterName = C2U( "HasXAxisHelpGrid" );
121 break;
122 case 2:
124 if( m_bAxis )
126 OSL_ENSURE(m_bMain == true,"there is no secondary z axis at the old api");
127 m_bMain = true;
128 m_aOuterName = C2U( "HasZAxis" );
130 else
132 if( m_bMain )
133 m_aOuterName = C2U( "HasZAxisGrid" );
134 else
135 m_aOuterName = C2U( "HasZAxisHelpGrid" );
138 break;
139 default:
141 if( m_bAxis )
143 if( m_bMain )
144 m_aOuterName = C2U( "HasYAxis" );
145 else
146 m_aOuterName = C2U( "HasSecondaryYAxis" );
148 else
150 if( m_bMain )
151 m_aOuterName = C2U( "HasYAxisGrid" );
152 else
153 m_aOuterName = C2U( "HasYAxisHelpGrid" );
156 break;
160 WrappedAxisAndGridExistenceProperty::~WrappedAxisAndGridExistenceProperty()
164 void WrappedAxisAndGridExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
165 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
167 sal_Bool bNewValue = false;
168 if( ! (rOuterValue >>= bNewValue) )
169 throw lang::IllegalArgumentException( C2U("Has axis or grid properties require boolean values"), 0, 0 );
171 sal_Bool bOldValue = sal_False;
172 getPropertyValue( xInnerPropertySet ) >>= bOldValue;
174 if( bOldValue == bNewValue )
175 return;
177 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
178 if( bNewValue )
180 if( m_bAxis )
181 AxisHelper::showAxis( m_nDimensionIndex, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext );
182 else
183 AxisHelper::showGrid( m_nDimensionIndex, 0, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext );
185 else
187 if( m_bAxis )
188 AxisHelper::hideAxis( m_nDimensionIndex, m_bMain, xDiagram );
189 else
190 AxisHelper::hideGrid( m_nDimensionIndex, 0, m_bMain, xDiagram );
194 Any WrappedAxisAndGridExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /* xInnerPropertySet */ ) const
195 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
197 Any aRet;
198 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
199 if(m_bAxis)
201 sal_Bool bShown = AxisHelper::isAxisShown( m_nDimensionIndex, m_bMain, xDiagram );
202 aRet <<= bShown;
204 else
206 sal_Bool bShown = AxisHelper::isGridShown( m_nDimensionIndex, 0, m_bMain, xDiagram );
207 aRet <<= bShown;
209 return aRet;
212 Any WrappedAxisAndGridExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
213 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
215 Any aRet;
216 aRet <<= false;
217 return aRet;
220 //---------------------------------------------------------------------------------------------------------------
221 //---------------------------------------------------------------------------------------------------------------
222 //---------------------------------------------------------------------------------------------------------------
224 class WrappedAxisTitleExistenceProperty : public WrappedProperty
226 public:
227 WrappedAxisTitleExistenceProperty( sal_Int32 nTitleIndex
228 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
229 virtual ~WrappedAxisTitleExistenceProperty();
231 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
232 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);
234 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
235 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
237 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
238 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
240 private: //member
241 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
242 TitleHelper::eTitleType m_eTitleType;
245 //static
246 void WrappedAxisTitleExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
247 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
249 rList.push_back( new WrappedAxisTitleExistenceProperty( 0, spChart2ModelContact ) );//x axis title
250 rList.push_back( new WrappedAxisTitleExistenceProperty( 1, spChart2ModelContact ) );//y axis title
251 rList.push_back( new WrappedAxisTitleExistenceProperty( 2, spChart2ModelContact ) );//z axis title
252 rList.push_back( new WrappedAxisTitleExistenceProperty( 3, spChart2ModelContact ) );//secondary x axis title
253 rList.push_back( new WrappedAxisTitleExistenceProperty( 4, spChart2ModelContact ) );//secondary y axis title
256 WrappedAxisTitleExistenceProperty::WrappedAxisTitleExistenceProperty( sal_Int32 nTitleIndex
257 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
258 : WrappedProperty(OUString(),OUString())
259 , m_spChart2ModelContact( spChart2ModelContact )
260 , m_eTitleType( TitleHelper::Y_AXIS_TITLE )
262 switch( nTitleIndex )
264 case 0:
265 m_aOuterName = C2U( "HasXAxisTitle" );
266 m_eTitleType = TitleHelper::X_AXIS_TITLE;
267 break;
268 case 2:
269 m_aOuterName = C2U( "HasZAxisTitle" );
270 m_eTitleType = TitleHelper::Z_AXIS_TITLE;
271 break;
272 case 3:
273 m_aOuterName = C2U( "HasSecondaryXAxisTitle" );
274 m_eTitleType = TitleHelper::SECONDARY_X_AXIS_TITLE;
275 break;
276 case 4:
277 m_aOuterName = C2U( "HasSecondaryYAxisTitle" );
278 m_eTitleType = TitleHelper::SECONDARY_Y_AXIS_TITLE;
279 break;
280 default:
281 m_aOuterName = C2U( "HasYAxisTitle" );
282 m_eTitleType = TitleHelper::Y_AXIS_TITLE;
283 break;
287 WrappedAxisTitleExistenceProperty::~WrappedAxisTitleExistenceProperty()
291 void WrappedAxisTitleExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
292 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
294 sal_Bool bNewValue = false;
295 if( ! (rOuterValue >>= bNewValue) )
296 throw lang::IllegalArgumentException( C2U("Has axis or grid properties require boolean values"), 0, 0 );
298 sal_Bool bOldValue = sal_False;
299 getPropertyValue( xInnerPropertySet ) >>= bOldValue;
301 if( bOldValue == bNewValue )
302 return;
304 if( bNewValue )
306 rtl::OUString aTitleText;
307 TitleHelper::createTitle( m_eTitleType, aTitleText
308 , m_spChart2ModelContact->getChartModel(), m_spChart2ModelContact->m_xContext );
310 else
312 TitleHelper::removeTitle( m_eTitleType, m_spChart2ModelContact->getChartModel() );
316 Any WrappedAxisTitleExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
317 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
319 sal_Bool bHasTitle = sal_False;
321 Reference< chart2::XTitle > xTitle( TitleHelper::getTitle( m_eTitleType, m_spChart2ModelContact->getChartModel() ) );
322 if( xTitle.is() && (TitleHelper::getCompleteString( xTitle ).getLength() != 0) )
323 bHasTitle = sal_True;
325 Any aRet;
326 aRet <<= bHasTitle;
327 return aRet;
331 Any WrappedAxisTitleExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
332 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
334 Any aRet;
335 aRet <<= sal_Bool( sal_False );
336 return aRet;
339 //---------------------------------------------------------------------------------------------------------------
340 //---------------------------------------------------------------------------------------------------------------
341 //---------------------------------------------------------------------------------------------------------------
343 class WrappedAxisLabelExistenceProperty : public WrappedProperty
345 public:
346 WrappedAxisLabelExistenceProperty( bool bMain, sal_Int32 nDimensionIndex
347 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
348 virtual ~WrappedAxisLabelExistenceProperty();
350 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
351 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);
353 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
354 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
356 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
357 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
359 private: //member
360 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
361 bool m_bMain;
362 sal_Int32 m_nDimensionIndex;
365 //static
366 void WrappedAxisLabelExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
367 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
369 rList.push_back( new WrappedAxisLabelExistenceProperty( true, 0, spChart2ModelContact ) );//x axis
370 rList.push_back( new WrappedAxisLabelExistenceProperty( true, 1, spChart2ModelContact ) );//y axis
371 rList.push_back( new WrappedAxisLabelExistenceProperty( true, 2, spChart2ModelContact ) );//z axis
372 rList.push_back( new WrappedAxisLabelExistenceProperty( false, 0, spChart2ModelContact ) );//secondary x axis
373 rList.push_back( new WrappedAxisLabelExistenceProperty( false, 1, spChart2ModelContact ) );//secondary y axis
376 WrappedAxisLabelExistenceProperty::WrappedAxisLabelExistenceProperty( bool bMain, sal_Int32 nDimensionIndex
377 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
378 : WrappedProperty(OUString(),OUString())
379 , m_spChart2ModelContact( spChart2ModelContact )
380 , m_bMain( bMain )
381 , m_nDimensionIndex( nDimensionIndex )
383 switch( m_nDimensionIndex )
385 case 0:
386 m_aOuterName = m_bMain ? C2U( "HasXAxisDescription" ) : C2U( "HasSecondaryXAxisDescription" );
387 break;
388 case 2:
389 OSL_ENSURE(m_bMain,"there is no description available for a secondary z axis");
390 m_aOuterName = C2U( "HasZAxisDescription" );
391 break;
392 default:
393 m_aOuterName = m_bMain ? C2U( "HasYAxisDescription" ) : C2U( "HasSecondaryYAxisDescription" );
394 break;
398 WrappedAxisLabelExistenceProperty::~WrappedAxisLabelExistenceProperty()
402 void WrappedAxisLabelExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
403 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
405 sal_Bool bNewValue = false;
406 if( ! (rOuterValue >>= bNewValue) )
407 throw lang::IllegalArgumentException( C2U("Has axis or grid properties require boolean values"), 0, 0 );
409 sal_Bool bOldValue = sal_False;
410 getPropertyValue( xInnerPropertySet ) >>= bOldValue;
412 if( bOldValue == bNewValue )
413 return;
415 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
416 Reference< beans::XPropertySet > xProp( AxisHelper::getAxis( m_nDimensionIndex, m_bMain, xDiagram ), uno::UNO_QUERY );
417 if( !xProp.is() && bNewValue )
419 //create axis if needed
420 xProp.set( AxisHelper::createAxis( m_nDimensionIndex, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext ), uno::UNO_QUERY );
421 if( xProp.is() )
422 xProp->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_False ) );
424 if( xProp.is() )
425 xProp->setPropertyValue( C2U( "DisplayLabels" ), rOuterValue );
428 Any WrappedAxisLabelExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
429 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
431 Any aRet;
432 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
433 Reference< beans::XPropertySet > xProp( AxisHelper::getAxis( m_nDimensionIndex, m_bMain, xDiagram ), uno::UNO_QUERY );
434 if( xProp.is() )
435 aRet = xProp->getPropertyValue( C2U( "DisplayLabels" ));
436 else
437 aRet <<= sal_False;
438 return aRet;
441 Any WrappedAxisLabelExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
442 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
444 Any aRet;
445 aRet <<= sal_Bool( sal_True );
446 return aRet;
449 } //namespace wrapper
450 } //namespace chart
451 //.............................................................................