1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "WrappedGapwidthProperty.hxx"
22 #include "DiagramHelper.hxx"
24 using namespace ::com::sun::star
;
25 using ::com::sun::star::uno::Reference
;
26 using ::com::sun::star::uno::Sequence
;
27 using ::com::sun::star::uno::Any
;
34 const sal_Int32 DEFAULT_GAPWIDTH
= 100;
35 const sal_Int32 DEFAULT_OVERLAP
= 0;
37 WrappedBarPositionProperty_Base::WrappedBarPositionProperty_Base(
38 const OUString
& rOuterName
39 , const OUString
& rInnerSequencePropertyName
40 , sal_Int32 nDefaultValue
41 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
42 : WrappedDefaultProperty( rOuterName
, OUString(), uno::makeAny( nDefaultValue
) )
43 , m_nDimensionIndex(0)
45 , m_spChart2ModelContact( spChart2ModelContact
)
46 , m_nDefaultValue( nDefaultValue
)
47 , m_InnerSequencePropertyName( rInnerSequencePropertyName
)
51 void WrappedBarPositionProperty_Base::setDimensionAndAxisIndex( sal_Int32 nDimensionIndex
, sal_Int32 nAxisIndex
)
53 m_nDimensionIndex
= nDimensionIndex
;
54 m_nAxisIndex
= nAxisIndex
;
57 WrappedBarPositionProperty_Base::~WrappedBarPositionProperty_Base()
61 void WrappedBarPositionProperty_Base::setPropertyValue( const Any
& rOuterValue
, const Reference
< beans::XPropertySet
>& /*xInnerPropertySet*/ ) const
62 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
64 sal_Int32 nNewValue
= 0;
65 if( ! (rOuterValue
>>= nNewValue
) )
66 throw lang::IllegalArgumentException( "GapWidth and Overlap property require value of type sal_Int32", 0, 0 );
68 m_aOuterValue
= rOuterValue
;
70 Reference
< chart2::XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
74 if( m_nDimensionIndex
==1 )
76 Sequence
< Reference
< chart2::XChartType
> > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram
) );
77 for( sal_Int32 nN
= 0; nN
< aChartTypeList
.getLength(); nN
++ )
81 Reference
< beans::XPropertySet
> xProp( aChartTypeList
[nN
], uno::UNO_QUERY
);
84 Sequence
< sal_Int32
> aBarPositionSequence
;
85 xProp
->getPropertyValue( m_InnerSequencePropertyName
) >>= aBarPositionSequence
;
87 long nOldLength
= aBarPositionSequence
.getLength();
88 if( nOldLength
<= m_nAxisIndex
)
90 aBarPositionSequence
.realloc( m_nAxisIndex
+1 );
91 for( sal_Int32 i
=nOldLength
; i
<m_nAxisIndex
; i
++ )
93 aBarPositionSequence
[i
] = m_nDefaultValue
;
96 aBarPositionSequence
[m_nAxisIndex
] = nNewValue
;
98 xProp
->setPropertyValue( m_InnerSequencePropertyName
, uno::makeAny( aBarPositionSequence
) );
101 catch( uno::Exception
& e
)
103 //the above properties are not supported by all charttypes (only by column and bar)
104 //in that cases this exception is ok
105 e
.Context
.is();//to have debug information without compilation warnings
111 Any
WrappedBarPositionProperty_Base::getPropertyValue( const Reference
< beans::XPropertySet
>& /*xInnerPropertySet*/ ) const
112 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
114 Reference
< chart2::XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
117 bool bInnerValueDetected
= false;
118 sal_Int32 nInnerValue
= m_nDefaultValue
;
120 if( m_nDimensionIndex
==1 )
122 Sequence
< Reference
< chart2::XChartType
> > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram
) );
123 for( sal_Int32 nN
= 0; nN
< aChartTypeList
.getLength() && !bInnerValueDetected
; nN
++ )
127 Reference
< beans::XPropertySet
> xProp( aChartTypeList
[nN
], uno::UNO_QUERY
);
130 Sequence
< sal_Int32
> aBarPositionSequence
;
131 xProp
->getPropertyValue( m_InnerSequencePropertyName
) >>= aBarPositionSequence
;
132 if( m_nAxisIndex
< aBarPositionSequence
.getLength() )
134 nInnerValue
= aBarPositionSequence
[m_nAxisIndex
];
135 bInnerValueDetected
= true;
139 catch( uno::Exception
& e
)
141 //the above properties are not supported by all charttypes (only by column and bar)
142 //in that cases this exception is ok
143 e
.Context
.is();//to have debug information without compilation warnings
147 if( bInnerValueDetected
)
149 m_aOuterValue
<<= nInnerValue
;
152 return m_aOuterValue
;
155 WrappedGapwidthProperty::WrappedGapwidthProperty(
156 ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
157 : WrappedBarPositionProperty_Base( "GapWidth", "GapwidthSequence", DEFAULT_GAPWIDTH
, spChart2ModelContact
)
160 WrappedGapwidthProperty::~WrappedGapwidthProperty()
164 WrappedBarOverlapProperty::WrappedBarOverlapProperty(
165 ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
166 : WrappedBarPositionProperty_Base( "Overlap", "OverlapSequence", DEFAULT_OVERLAP
, spChart2ModelContact
)
169 WrappedBarOverlapProperty::~WrappedBarOverlapProperty()
173 } // namespace wrapper
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */