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_chart2.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                 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
77 {
78     sal_Int32 nNewValue = 0;
79     if( ! (rOuterValue >>= nNewValue) )
80         throw lang::IllegalArgumentException( C2U("GapWidth and Overlap property require value of type sal_Int32"), 0, 0 );
81 
82     m_aOuterValue = rOuterValue;
83 
84     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
85     if( !xDiagram.is() )
86         return;
87 
88     if( m_nDimensionIndex==1 )
89     {
90         Sequence< Reference< chart2::XChartType > > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
91         for( sal_Int32 nN = 0; nN < aChartTypeList.getLength(); nN++ )
92         {
93             try
94             {
95                 Reference< beans::XPropertySet > xProp( aChartTypeList[nN], uno::UNO_QUERY );
96                 if( xProp.is() )
97                 {
98                     Sequence< sal_Int32 > aBarPositionSequence;
99                     xProp->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
100 
101                     long nOldLength = aBarPositionSequence.getLength();
102                     if( nOldLength <= m_nAxisIndex  )
103                     {
104                         aBarPositionSequence.realloc( m_nAxisIndex+1 );
105                         for( sal_Int32 i=nOldLength; i<m_nAxisIndex; i++ )
106                         {
107                             aBarPositionSequence[i] = m_nDefaultValue;
108                         }
109                     }
110                     aBarPositionSequence[m_nAxisIndex] = nNewValue;
111 
112                     xProp->setPropertyValue( m_InnerSequencePropertyName, uno::makeAny( aBarPositionSequence ) );
113                 }
114             }
115             catch( uno::Exception& e )
116 	        {
117                 //the above properties are not supported by all charttypes (only by column and bar)
118                 //in that cases this exception is ok
119                 e.Context.is();//to have debug information without compilation warnings
120             }
121         }
122     }
123 }
124 
getPropertyValue(const Reference<beans::XPropertySet> &) const125 Any WrappedBarPositionProperty_Base::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
126                         throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
127 {
128     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
129     if( xDiagram.is() )
130     {
131         bool bInnerValueDetected = false;
132         sal_Int32 nInnerValue = m_nDefaultValue;
133 
134         if( m_nDimensionIndex==1 )
135         {
136             Sequence< Reference< chart2::XChartType > > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
137             for( sal_Int32 nN = 0; nN < aChartTypeList.getLength() && !bInnerValueDetected; nN++ )
138             {
139                 try
140                 {
141                     Reference< beans::XPropertySet > xProp( aChartTypeList[nN], uno::UNO_QUERY );
142                     if( xProp.is() )
143                     {
144                         Sequence< sal_Int32 > aBarPositionSequence;
145                         xProp->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
146                         if( m_nAxisIndex < aBarPositionSequence.getLength() )
147                         {
148                             nInnerValue = aBarPositionSequence[m_nAxisIndex];
149                             bInnerValueDetected = true;
150                         }
151                     }
152                 }
153                 catch( uno::Exception& e )
154 	            {
155                     //the above properties are not supported by all charttypes (only by column and bar)
156                     //in that cases this exception is ok
157                     e.Context.is();//to have debug information without compilation warnings
158                 }
159             }
160         }
161         if( bInnerValueDetected )
162         {
163             m_aOuterValue <<= nInnerValue;
164         }
165     }
166     return m_aOuterValue;
167 }
168 
169 //-----------------------------------------------------------------------------
170 //-----------------------------------------------------------------------------
171 //-----------------------------------------------------------------------------
172 
WrappedGapwidthProperty(::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)173 WrappedGapwidthProperty::WrappedGapwidthProperty(
174         ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
175     : WrappedBarPositionProperty_Base( C2U("GapWidth"), C2U("GapwidthSequence"), DEFAULT_GAPWIDTH, spChart2ModelContact )
176 {
177 }
~WrappedGapwidthProperty()178 WrappedGapwidthProperty::~WrappedGapwidthProperty()
179 {
180 }
181 
182 //-----------------------------------------------------------------------------
183 //-----------------------------------------------------------------------------
184 //-----------------------------------------------------------------------------
185 
WrappedBarOverlapProperty(::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)186 WrappedBarOverlapProperty::WrappedBarOverlapProperty(
187         ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
188     : WrappedBarPositionProperty_Base( C2U("Overlap"), C2U("OverlapSequence"), DEFAULT_OVERLAP, spChart2ModelContact )
189 {
190 }
~WrappedBarOverlapProperty()191 WrappedBarOverlapProperty::~WrappedBarOverlapProperty()
192 {
193 }
194 
195 } //  namespace wrapper
196 } //  namespace chart
197 //.............................................................................
198