merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / controller / chartapiwrapper / WrappedGapwidthProperty.cxx
blob060406b86a23c1d220355f3de97f8dc1db86ad0b
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: WrappedGapwidthProperty.cxx,v $
10 * $Revision: 1.5 $
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 "WrappedGapwidthProperty.hxx"
35 #include "macros.hxx"
36 #include "DiagramHelper.hxx"
38 using namespace ::com::sun::star;
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::uno::Sequence;
41 using ::com::sun::star::uno::Any;
42 using ::rtl::OUString;
45 //.............................................................................
46 namespace chart
48 namespace wrapper
51 const sal_Int32 DEFAULT_GAPWIDTH = 100;
52 const sal_Int32 DEFAULT_OVERLAP = 0;
54 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
58 WrappedBarPositionProperty_Base::WrappedBarPositionProperty_Base(
59 const ::rtl::OUString& rOuterName
60 , const ::rtl::OUString& rInnerSequencePropertyName
61 , sal_Int32 nDefaultValue
62 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
63 : WrappedDefaultProperty( rOuterName, rtl::OUString(), uno::makeAny( nDefaultValue ) )
64 , m_nDimensionIndex(0)
65 , m_nAxisIndex(0)
66 , m_spChart2ModelContact( spChart2ModelContact )
67 , m_nDefaultValue( nDefaultValue )
68 , m_InnerSequencePropertyName( rInnerSequencePropertyName )
72 void WrappedBarPositionProperty_Base::setDimensionAndAxisIndex( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
74 m_nDimensionIndex = nDimensionIndex;
75 m_nAxisIndex = nAxisIndex;
78 WrappedBarPositionProperty_Base::~WrappedBarPositionProperty_Base()
82 void WrappedBarPositionProperty_Base::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
83 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
85 sal_Int32 nNewValue = 0;
86 if( ! (rOuterValue >>= nNewValue) )
87 throw lang::IllegalArgumentException( C2U("GapWidth and Overlap property require value of type sal_Int32"), 0, 0 );
89 m_aOuterValue = rOuterValue;
91 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
92 if( !xDiagram.is() )
93 return;
95 if( m_nDimensionIndex==1 )
97 Sequence< Reference< chart2::XChartType > > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
98 for( sal_Int32 nN = 0; nN < aChartTypeList.getLength(); nN++ )
102 Reference< beans::XPropertySet > xProp( aChartTypeList[nN], uno::UNO_QUERY );
103 if( xProp.is() )
105 Sequence< sal_Int32 > aBarPositionSequence;
106 xProp->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
108 long nOldLength = aBarPositionSequence.getLength();
109 if( nOldLength <= m_nAxisIndex )
111 aBarPositionSequence.realloc( m_nAxisIndex+1 );
112 for( sal_Int32 i=nOldLength; i<m_nAxisIndex; i++ )
114 aBarPositionSequence[i] = m_nDefaultValue;
117 aBarPositionSequence[m_nAxisIndex] = nNewValue;
119 xProp->setPropertyValue( m_InnerSequencePropertyName, uno::makeAny( aBarPositionSequence ) );
122 catch( uno::Exception& e )
124 //the above properties are not supported by all charttypes (only by column and bar)
125 //in that cases this exception is ok
126 e.Context.is();//to have debug information without compilation warnings
132 Any WrappedBarPositionProperty_Base::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
133 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
135 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
136 if( xDiagram.is() )
138 bool bInnerValueDetected = false;
139 sal_Int32 nInnerValue = m_nDefaultValue;
141 if( m_nDimensionIndex==1 )
143 Sequence< Reference< chart2::XChartType > > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
144 for( sal_Int32 nN = 0; nN < aChartTypeList.getLength() && !bInnerValueDetected; nN++ )
148 Reference< beans::XPropertySet > xProp( aChartTypeList[nN], uno::UNO_QUERY );
149 if( xProp.is() )
151 Sequence< sal_Int32 > aBarPositionSequence;
152 xProp->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
153 if( m_nAxisIndex < aBarPositionSequence.getLength() )
155 nInnerValue = aBarPositionSequence[m_nAxisIndex];
156 bInnerValueDetected = true;
160 catch( uno::Exception& e )
162 //the above properties are not supported by all charttypes (only by column and bar)
163 //in that cases this exception is ok
164 e.Context.is();//to have debug information without compilation warnings
168 if( bInnerValueDetected )
170 m_aOuterValue <<= nInnerValue;
173 return m_aOuterValue;
176 //-----------------------------------------------------------------------------
177 //-----------------------------------------------------------------------------
178 //-----------------------------------------------------------------------------
180 WrappedGapwidthProperty::WrappedGapwidthProperty(
181 ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
182 : WrappedBarPositionProperty_Base( C2U("GapWidth"), C2U("GapwidthSequence"), DEFAULT_GAPWIDTH, spChart2ModelContact )
185 WrappedGapwidthProperty::~WrappedGapwidthProperty()
189 //-----------------------------------------------------------------------------
190 //-----------------------------------------------------------------------------
191 //-----------------------------------------------------------------------------
193 WrappedBarOverlapProperty::WrappedBarOverlapProperty(
194 ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
195 : WrappedBarPositionProperty_Base( C2U("Overlap"), C2U("OverlapSequence"), DEFAULT_OVERLAP, spChart2ModelContact )
198 WrappedBarOverlapProperty::~WrappedBarOverlapProperty()
202 } // namespace wrapper
203 } // namespace chart
204 //.............................................................................