1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WrappedAxisAndGridExistenceProperties.cxx,v $
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"
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 //.............................................................................
52 class WrappedAxisAndGridExistenceProperty
: public WrappedProperty
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
);
69 ::boost::shared_ptr
< Chart2ModelContact
> m_spChart2ModelContact
;
72 sal_Int32 m_nDimensionIndex
;
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
)
100 , m_nDimensionIndex( nDimensionIndex
)
102 switch( m_nDimensionIndex
)
109 m_aOuterName
= C2U( "HasXAxis" );
111 m_aOuterName
= C2U( "HasSecondaryXAxis" );
116 m_aOuterName
= C2U( "HasXAxisGrid" );
118 m_aOuterName
= C2U( "HasXAxisHelpGrid" );
126 OSL_ENSURE(m_bMain
== true,"there is no secondary z axis at the old api");
128 m_aOuterName
= C2U( "HasZAxis" );
133 m_aOuterName
= C2U( "HasZAxisGrid" );
135 m_aOuterName
= C2U( "HasZAxisHelpGrid" );
144 m_aOuterName
= C2U( "HasYAxis" );
146 m_aOuterName
= C2U( "HasSecondaryYAxis" );
151 m_aOuterName
= C2U( "HasYAxisGrid" );
153 m_aOuterName
= C2U( "HasYAxisHelpGrid" );
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
)
177 Reference
< chart2::XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
181 AxisHelper::showAxis( m_nDimensionIndex
, m_bMain
, xDiagram
, m_spChart2ModelContact
->m_xContext
);
183 AxisHelper::showGrid( m_nDimensionIndex
, 0, m_bMain
, xDiagram
, m_spChart2ModelContact
->m_xContext
);
188 AxisHelper::hideAxis( m_nDimensionIndex
, m_bMain
, xDiagram
);
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
)
198 Reference
< chart2::XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
201 sal_Bool bShown
= AxisHelper::isAxisShown( m_nDimensionIndex
, m_bMain
, xDiagram
);
206 sal_Bool bShown
= AxisHelper::isGridShown( m_nDimensionIndex
, 0, m_bMain
, xDiagram
);
212 Any
WrappedAxisAndGridExistenceProperty::getPropertyDefault( const Reference
< beans::XPropertyState
>& /*xInnerPropertyState*/ ) const
213 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
220 //---------------------------------------------------------------------------------------------------------------
221 //---------------------------------------------------------------------------------------------------------------
222 //---------------------------------------------------------------------------------------------------------------
224 class WrappedAxisTitleExistenceProperty
: public WrappedProperty
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
);
241 ::boost::shared_ptr
< Chart2ModelContact
> m_spChart2ModelContact
;
242 TitleHelper::eTitleType m_eTitleType
;
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
)
265 m_aOuterName
= C2U( "HasXAxisTitle" );
266 m_eTitleType
= TitleHelper::X_AXIS_TITLE
;
269 m_aOuterName
= C2U( "HasZAxisTitle" );
270 m_eTitleType
= TitleHelper::Z_AXIS_TITLE
;
273 m_aOuterName
= C2U( "HasSecondaryXAxisTitle" );
274 m_eTitleType
= TitleHelper::SECONDARY_X_AXIS_TITLE
;
277 m_aOuterName
= C2U( "HasSecondaryYAxisTitle" );
278 m_eTitleType
= TitleHelper::SECONDARY_Y_AXIS_TITLE
;
281 m_aOuterName
= C2U( "HasYAxisTitle" );
282 m_eTitleType
= TitleHelper::Y_AXIS_TITLE
;
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
)
306 rtl::OUString aTitleText
;
307 TitleHelper::createTitle( m_eTitleType
, aTitleText
308 , m_spChart2ModelContact
->getChartModel(), m_spChart2ModelContact
->m_xContext
);
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
;
331 Any
WrappedAxisTitleExistenceProperty::getPropertyDefault( const Reference
< beans::XPropertyState
>& /*xInnerPropertyState*/ ) const
332 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
335 aRet
<<= sal_Bool( sal_False
);
339 //---------------------------------------------------------------------------------------------------------------
340 //---------------------------------------------------------------------------------------------------------------
341 //---------------------------------------------------------------------------------------------------------------
343 class WrappedAxisLabelExistenceProperty
: public WrappedProperty
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
);
360 ::boost::shared_ptr
< Chart2ModelContact
> m_spChart2ModelContact
;
362 sal_Int32 m_nDimensionIndex
;
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
)
381 , m_nDimensionIndex( nDimensionIndex
)
383 switch( m_nDimensionIndex
)
386 m_aOuterName
= m_bMain
? C2U( "HasXAxisDescription" ) : C2U( "HasSecondaryXAxisDescription" );
389 OSL_ENSURE(m_bMain
,"there is no description available for a secondary z axis");
390 m_aOuterName
= C2U( "HasZAxisDescription" );
393 m_aOuterName
= m_bMain
? C2U( "HasYAxisDescription" ) : C2U( "HasSecondaryYAxisDescription" );
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
)
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
);
422 xProp
->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_False
) );
425 xProp
->setPropertyValue( C2U( "DisplayLabels" ), rOuterValue
);
428 Any
WrappedAxisLabelExistenceProperty::getPropertyValue( const Reference
< beans::XPropertySet
>& /*xInnerPropertySet*/ ) const
429 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
432 Reference
< chart2::XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
433 Reference
< beans::XPropertySet
> xProp( AxisHelper::getAxis( m_nDimensionIndex
, m_bMain
, xDiagram
), uno::UNO_QUERY
);
435 aRet
= xProp
->getPropertyValue( C2U( "DisplayLabels" ));
441 Any
WrappedAxisLabelExistenceProperty::getPropertyDefault( const Reference
< beans::XPropertyState
>& /*xInnerPropertyState*/ ) const
442 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
445 aRet
<<= sal_Bool( sal_True
);
449 } //namespace wrapper
451 //.............................................................................