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