Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "WrappedGapwidthProperty.hxx"
21 : #include "macros.hxx"
22 : #include "DiagramHelper.hxx"
23 :
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;
28 :
29 : namespace chart
30 : {
31 : namespace wrapper
32 : {
33 :
34 : const sal_Int32 DEFAULT_GAPWIDTH = 100;
35 : const sal_Int32 DEFAULT_OVERLAP = 0;
36 :
37 2076 : 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)
44 : , m_nAxisIndex(0)
45 : , m_spChart2ModelContact( spChart2ModelContact )
46 : , m_nDefaultValue( nDefaultValue )
47 2076 : , m_InnerSequencePropertyName( rInnerSequencePropertyName )
48 : {
49 2076 : }
50 :
51 2076 : void WrappedBarPositionProperty_Base::setDimensionAndAxisIndex( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
52 : {
53 2076 : m_nDimensionIndex = nDimensionIndex;
54 2076 : m_nAxisIndex = nAxisIndex;
55 2076 : }
56 :
57 2076 : WrappedBarPositionProperty_Base::~WrappedBarPositionProperty_Base()
58 : {
59 2076 : }
60 :
61 140 : 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)
63 : {
64 140 : sal_Int32 nNewValue = 0;
65 140 : if( ! (rOuterValue >>= nNewValue) )
66 0 : throw lang::IllegalArgumentException( "GapWidth and Overlap property require value of type sal_Int32", 0, 0 );
67 :
68 140 : m_aOuterValue = rOuterValue;
69 :
70 140 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
71 140 : if( !xDiagram.is() )
72 140 : return;
73 :
74 140 : if( m_nDimensionIndex==1 )
75 : {
76 140 : Sequence< Reference< chart2::XChartType > > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
77 280 : for( sal_Int32 nN = 0; nN < aChartTypeList.getLength(); nN++ )
78 : {
79 : try
80 : {
81 140 : Reference< beans::XPropertySet > xProp( aChartTypeList[nN], uno::UNO_QUERY );
82 140 : if( xProp.is() )
83 : {
84 140 : Sequence< sal_Int32 > aBarPositionSequence;
85 140 : xProp->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
86 :
87 136 : long nOldLength = aBarPositionSequence.getLength();
88 136 : if( nOldLength <= m_nAxisIndex )
89 : {
90 0 : aBarPositionSequence.realloc( m_nAxisIndex+1 );
91 0 : for( sal_Int32 i=nOldLength; i<m_nAxisIndex; i++ )
92 : {
93 0 : aBarPositionSequence[i] = m_nDefaultValue;
94 : }
95 : }
96 136 : aBarPositionSequence[m_nAxisIndex] = nNewValue;
97 :
98 136 : xProp->setPropertyValue( m_InnerSequencePropertyName, uno::makeAny( aBarPositionSequence ) );
99 140 : }
100 : }
101 8 : catch( uno::Exception& e )
102 : {
103 : //the above properties are not supported by all charttypes (only by column and bar)
104 : //in that cases this exception is ok
105 4 : e.Context.is();//to have debug information without compilation warnings
106 : }
107 140 : }
108 140 : }
109 : }
110 :
111 10196 : Any WrappedBarPositionProperty_Base::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
112 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
113 : {
114 10196 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
115 10196 : if( xDiagram.is() )
116 : {
117 10196 : bool bInnerValueDetected = false;
118 10196 : sal_Int32 nInnerValue = m_nDefaultValue;
119 :
120 10196 : if( m_nDimensionIndex==1 )
121 : {
122 3940 : Sequence< Reference< chart2::XChartType > > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
123 7880 : for( sal_Int32 nN = 0; nN < aChartTypeList.getLength() && !bInnerValueDetected; nN++ )
124 : {
125 : try
126 : {
127 3940 : Reference< beans::XPropertySet > xProp( aChartTypeList[nN], uno::UNO_QUERY );
128 3940 : if( xProp.is() )
129 : {
130 3940 : Sequence< sal_Int32 > aBarPositionSequence;
131 3940 : xProp->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
132 2180 : if( m_nAxisIndex < aBarPositionSequence.getLength() )
133 : {
134 2180 : nInnerValue = aBarPositionSequence[m_nAxisIndex];
135 2180 : bInnerValueDetected = true;
136 3940 : }
137 3940 : }
138 : }
139 3520 : catch( uno::Exception& e )
140 : {
141 : //the above properties are not supported by all charttypes (only by column and bar)
142 : //in that cases this exception is ok
143 1760 : e.Context.is();//to have debug information without compilation warnings
144 : }
145 3940 : }
146 : }
147 10196 : if( bInnerValueDetected )
148 : {
149 2180 : m_aOuterValue <<= nInnerValue;
150 : }
151 : }
152 10196 : return m_aOuterValue;
153 : }
154 :
155 1038 : WrappedGapwidthProperty::WrappedGapwidthProperty(
156 : ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
157 1038 : : WrappedBarPositionProperty_Base( "GapWidth", "GapwidthSequence", DEFAULT_GAPWIDTH, spChart2ModelContact )
158 : {
159 1038 : }
160 2076 : WrappedGapwidthProperty::~WrappedGapwidthProperty()
161 : {
162 2076 : }
163 :
164 1038 : WrappedBarOverlapProperty::WrappedBarOverlapProperty(
165 : ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
166 1038 : : WrappedBarPositionProperty_Base( "Overlap", "OverlapSequence", DEFAULT_OVERLAP, spChart2ModelContact )
167 : {
168 1038 : }
169 2076 : WrappedBarOverlapProperty::~WrappedBarOverlapProperty()
170 : {
171 2076 : }
172 :
173 : } // namespace wrapper
174 102 : } // namespace chart
175 :
176 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|