1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chartcontroller.hxx"
26
27 #include "WrappedGapwidthProperty.hxx"
28 #include "macros.hxx"
29 #include "DiagramHelper.hxx"
30
31 using namespace ::com::sun::star;
32 using ::com::sun::star::uno::Reference;
33 using ::com::sun::star::uno::Sequence;
34 using ::com::sun::star::uno::Any;
35 using ::rtl::OUString;
36
37
38 //.............................................................................
39 namespace chart
40 {
41 namespace wrapper
42 {
43
44 const sal_Int32 DEFAULT_GAPWIDTH = 100;
45 const sal_Int32 DEFAULT_OVERLAP = 0;
46
47 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
50
WrappedBarPositionProperty_Base(const::rtl::OUString & rOuterName,const::rtl::OUString & rInnerSequencePropertyName,sal_Int32 nDefaultValue,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)51 WrappedBarPositionProperty_Base::WrappedBarPositionProperty_Base(
52 const ::rtl::OUString& rOuterName
53 , const ::rtl::OUString& rInnerSequencePropertyName
54 , sal_Int32 nDefaultValue
55 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
56 : WrappedDefaultProperty( rOuterName, rtl::OUString(), uno::makeAny( nDefaultValue ) )
57 , m_nDimensionIndex(0)
58 , m_nAxisIndex(0)
59 , m_spChart2ModelContact( spChart2ModelContact )
60 , m_nDefaultValue( nDefaultValue )
61 , m_InnerSequencePropertyName( rInnerSequencePropertyName )
62 {
63 }
64
setDimensionAndAxisIndex(sal_Int32 nDimensionIndex,sal_Int32 nAxisIndex)65 void WrappedBarPositionProperty_Base::setDimensionAndAxisIndex( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
66 {
67 m_nDimensionIndex = nDimensionIndex;
68 m_nAxisIndex = nAxisIndex;
69 }
70
~WrappedBarPositionProperty_Base()71 WrappedBarPositionProperty_Base::~WrappedBarPositionProperty_Base()
72 {
73 }
74
setPropertyValue(const Any & rOuterValue,const Reference<beans::XPropertySet> &) const75 void WrappedBarPositionProperty_Base::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
76 {
77 sal_Int32 nNewValue = 0;
78 if( ! (rOuterValue >>= nNewValue) )
79 throw lang::IllegalArgumentException( C2U("GapWidth and Overlap property require value of type sal_Int32"), 0, 0 );
80
81 m_aOuterValue = rOuterValue;
82
83 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
84 if( !xDiagram.is() )
85 return;
86
87 if( m_nDimensionIndex==1 )
88 {
89 Sequence< Reference< chart2::XChartType > > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
90 for( sal_Int32 nN = 0; nN < aChartTypeList.getLength(); nN++ )
91 {
92 try
93 {
94 Reference< beans::XPropertySet > xProp( aChartTypeList[nN], uno::UNO_QUERY );
95 if( xProp.is() )
96 {
97 Sequence< sal_Int32 > aBarPositionSequence;
98 xProp->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
99
100 long nOldLength = aBarPositionSequence.getLength();
101 if( nOldLength <= m_nAxisIndex )
102 {
103 aBarPositionSequence.realloc( m_nAxisIndex+1 );
104 for( sal_Int32 i=nOldLength; i<m_nAxisIndex; i++ )
105 {
106 aBarPositionSequence[i] = m_nDefaultValue;
107 }
108 }
109 aBarPositionSequence[m_nAxisIndex] = nNewValue;
110
111 xProp->setPropertyValue( m_InnerSequencePropertyName, uno::makeAny( aBarPositionSequence ) );
112 }
113 }
114 catch( uno::Exception& e )
115 {
116 //the above properties are not supported by all charttypes (only by column and bar)
117 //in that cases this exception is ok
118 e.Context.is();//to have debug information without compilation warnings
119 }
120 }
121 }
122 }
123
getPropertyValue(const Reference<beans::XPropertySet> &) const124 Any WrappedBarPositionProperty_Base::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
125 {
126 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
127 if( xDiagram.is() )
128 {
129 bool bInnerValueDetected = false;
130 sal_Int32 nInnerValue = m_nDefaultValue;
131
132 if( m_nDimensionIndex==1 )
133 {
134 Sequence< Reference< chart2::XChartType > > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
135 for( sal_Int32 nN = 0; nN < aChartTypeList.getLength() && !bInnerValueDetected; nN++ )
136 {
137 try
138 {
139 Reference< beans::XPropertySet > xProp( aChartTypeList[nN], uno::UNO_QUERY );
140 if( xProp.is() )
141 {
142 Sequence< sal_Int32 > aBarPositionSequence;
143 xProp->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
144 if( m_nAxisIndex < aBarPositionSequence.getLength() )
145 {
146 nInnerValue = aBarPositionSequence[m_nAxisIndex];
147 bInnerValueDetected = true;
148 }
149 }
150 }
151 catch( uno::Exception& e )
152 {
153 //the above properties are not supported by all charttypes (only by column and bar)
154 //in that cases this exception is ok
155 e.Context.is();//to have debug information without compilation warnings
156 }
157 }
158 }
159 if( bInnerValueDetected )
160 {
161 m_aOuterValue <<= nInnerValue;
162 }
163 }
164 return m_aOuterValue;
165 }
166
167 //-----------------------------------------------------------------------------
168 //-----------------------------------------------------------------------------
169 //-----------------------------------------------------------------------------
170
WrappedGapwidthProperty(::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)171 WrappedGapwidthProperty::WrappedGapwidthProperty(
172 ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
173 : WrappedBarPositionProperty_Base( C2U("GapWidth"), C2U("GapwidthSequence"), DEFAULT_GAPWIDTH, spChart2ModelContact )
174 {
175 }
~WrappedGapwidthProperty()176 WrappedGapwidthProperty::~WrappedGapwidthProperty()
177 {
178 }
179
180 //-----------------------------------------------------------------------------
181 //-----------------------------------------------------------------------------
182 //-----------------------------------------------------------------------------
183
WrappedBarOverlapProperty(::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)184 WrappedBarOverlapProperty::WrappedBarOverlapProperty(
185 ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
186 : WrappedBarPositionProperty_Base( C2U("Overlap"), C2U("OverlapSequence"), DEFAULT_OVERLAP, spChart2ModelContact )
187 {
188 }
~WrappedBarOverlapProperty()189 WrappedBarOverlapProperty::~WrappedBarOverlapProperty()
190 {
191 }
192
193 } // namespace wrapper
194 } // namespace chart
195 //.............................................................................
196