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 0 : 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 0 : , m_InnerSequencePropertyName( rInnerSequencePropertyName )
48 : {
49 0 : }
50 :
51 0 : void WrappedBarPositionProperty_Base::setDimensionAndAxisIndex( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
52 : {
53 0 : m_nDimensionIndex = nDimensionIndex;
54 0 : m_nAxisIndex = nAxisIndex;
55 0 : }
56 :
57 0 : WrappedBarPositionProperty_Base::~WrappedBarPositionProperty_Base()
58 : {
59 0 : }
60 :
61 0 : 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 0 : sal_Int32 nNewValue = 0;
65 0 : if( ! (rOuterValue >>= nNewValue) )
66 0 : throw lang::IllegalArgumentException( "GapWidth and Overlap property require value of type sal_Int32", 0, 0 );
67 :
68 0 : m_aOuterValue = rOuterValue;
69 :
70 0 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
71 0 : if( !xDiagram.is() )
72 0 : return;
73 :
74 0 : if( m_nDimensionIndex==1 )
75 : {
76 0 : Sequence< Reference< chart2::XChartType > > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
77 0 : for( sal_Int32 nN = 0; nN < aChartTypeList.getLength(); nN++ )
78 : {
79 : try
80 : {
81 0 : Reference< beans::XPropertySet > xProp( aChartTypeList[nN], uno::UNO_QUERY );
82 0 : if( xProp.is() )
83 : {
84 0 : Sequence< sal_Int32 > aBarPositionSequence;
85 0 : xProp->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
86 :
87 0 : long nOldLength = aBarPositionSequence.getLength();
88 0 : 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 0 : aBarPositionSequence[m_nAxisIndex] = nNewValue;
97 :
98 0 : xProp->setPropertyValue( m_InnerSequencePropertyName, uno::makeAny( aBarPositionSequence ) );
99 0 : }
100 : }
101 0 : 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 0 : e.Context.is();//to have debug information without compilation warnings
106 : }
107 0 : }
108 0 : }
109 : }
110 :
111 0 : Any WrappedBarPositionProperty_Base::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
112 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
113 : {
114 0 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
115 0 : if( xDiagram.is() )
116 : {
117 0 : bool bInnerValueDetected = false;
118 0 : sal_Int32 nInnerValue = m_nDefaultValue;
119 :
120 0 : if( m_nDimensionIndex==1 )
121 : {
122 0 : Sequence< Reference< chart2::XChartType > > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
123 0 : for( sal_Int32 nN = 0; nN < aChartTypeList.getLength() && !bInnerValueDetected; nN++ )
124 : {
125 : try
126 : {
127 0 : Reference< beans::XPropertySet > xProp( aChartTypeList[nN], uno::UNO_QUERY );
128 0 : if( xProp.is() )
129 : {
130 0 : Sequence< sal_Int32 > aBarPositionSequence;
131 0 : xProp->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
132 0 : if( m_nAxisIndex < aBarPositionSequence.getLength() )
133 : {
134 0 : nInnerValue = aBarPositionSequence[m_nAxisIndex];
135 0 : bInnerValueDetected = true;
136 0 : }
137 0 : }
138 : }
139 0 : 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 0 : e.Context.is();//to have debug information without compilation warnings
144 : }
145 0 : }
146 : }
147 0 : if( bInnerValueDetected )
148 : {
149 0 : m_aOuterValue <<= nInnerValue;
150 : }
151 : }
152 0 : return m_aOuterValue;
153 : }
154 :
155 0 : WrappedGapwidthProperty::WrappedGapwidthProperty(
156 : ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
157 0 : : WrappedBarPositionProperty_Base( "GapWidth", "GapwidthSequence", DEFAULT_GAPWIDTH, spChart2ModelContact )
158 : {
159 0 : }
160 0 : WrappedGapwidthProperty::~WrappedGapwidthProperty()
161 : {
162 0 : }
163 :
164 0 : WrappedBarOverlapProperty::WrappedBarOverlapProperty(
165 : ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
166 0 : : WrappedBarPositionProperty_Base( "Overlap", "OverlapSequence", DEFAULT_OVERLAP, spChart2ModelContact )
167 : {
168 0 : }
169 0 : WrappedBarOverlapProperty::~WrappedBarOverlapProperty()
170 : {
171 0 : }
172 :
173 : } // namespace wrapper
174 : } // namespace chart
175 :
176 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|