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 "WrappedScaleProperty.hxx"
28cdf0e10cSrcweir #include "macros.hxx"
29cdf0e10cSrcweir #include "CommonConverters.hxx"
30cdf0e10cSrcweir #include "AxisHelper.hxx"
31cdf0e10cSrcweir #include <com/sun/star/chart2/XAxis.hpp>
32cdf0e10cSrcweir #include <com/sun/star/chart/ChartAxisType.hpp>
33cdf0e10cSrcweir #include <chartview/ExplicitScaleValues.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace ::com::sun::star;
36cdf0e10cSrcweir using ::com::sun::star::uno::Any;
37cdf0e10cSrcweir using namespace ::com::sun::star::chart2;
38cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
39cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
40cdf0e10cSrcweir using ::rtl::OUString;
41cdf0e10cSrcweir using ::com::sun::star::chart::TimeIncrement;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir //.............................................................................
44cdf0e10cSrcweir namespace chart
45cdf0e10cSrcweir {
46cdf0e10cSrcweir namespace wrapper
47cdf0e10cSrcweir {
48cdf0e10cSrcweir 
WrappedScaleProperty(tScaleProperty eScaleProperty,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)49cdf0e10cSrcweir WrappedScaleProperty::WrappedScaleProperty( tScaleProperty eScaleProperty
50cdf0e10cSrcweir                 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
51cdf0e10cSrcweir             : WrappedProperty(OUString(),OUString())
52cdf0e10cSrcweir             , m_spChart2ModelContact( spChart2ModelContact )
53cdf0e10cSrcweir             , m_eScaleProperty( eScaleProperty )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir     switch( m_eScaleProperty )
56cdf0e10cSrcweir     {
57cdf0e10cSrcweir         case SCALE_PROP_MAX:
58cdf0e10cSrcweir             m_aOuterName = C2U("Max");
59cdf0e10cSrcweir             break;
60cdf0e10cSrcweir         case SCALE_PROP_MIN:
61cdf0e10cSrcweir             m_aOuterName = C2U("Min");
62cdf0e10cSrcweir             break;
63cdf0e10cSrcweir         case SCALE_PROP_ORIGIN:
64cdf0e10cSrcweir             m_aOuterName = C2U("Origin");
65cdf0e10cSrcweir             break;
66cdf0e10cSrcweir         case SCALE_PROP_STEPMAIN:
67cdf0e10cSrcweir             m_aOuterName = C2U("StepMain");
68cdf0e10cSrcweir             break;
69cdf0e10cSrcweir         case SCALE_PROP_STEPHELP:
70cdf0e10cSrcweir             m_aOuterName = C2U("StepHelp");
71cdf0e10cSrcweir             break;
72cdf0e10cSrcweir         case SCALE_PROP_STEPHELP_COUNT:
73cdf0e10cSrcweir             m_aOuterName = C2U("StepHelpCount");
74cdf0e10cSrcweir             break;
75cdf0e10cSrcweir         case SCALE_PROP_AUTO_MAX:
76cdf0e10cSrcweir             m_aOuterName = C2U("AutoMax");
77cdf0e10cSrcweir             break;
78cdf0e10cSrcweir         case SCALE_PROP_AUTO_MIN:
79cdf0e10cSrcweir             m_aOuterName = C2U("AutoMin");
80cdf0e10cSrcweir             break;
81cdf0e10cSrcweir         case SCALE_PROP_AUTO_ORIGIN:
82cdf0e10cSrcweir             m_aOuterName = C2U("AutoOrigin");
83cdf0e10cSrcweir             break;
84cdf0e10cSrcweir         case SCALE_PROP_AUTO_STEPMAIN:
85cdf0e10cSrcweir             m_aOuterName = C2U("AutoStepMain");
86cdf0e10cSrcweir             break;
87cdf0e10cSrcweir         case SCALE_PROP_AUTO_STEPHELP:
88cdf0e10cSrcweir             m_aOuterName = C2U("AutoStepHelp");
89cdf0e10cSrcweir             break;
90cdf0e10cSrcweir         case SCALE_PROP_AXIS_TYPE:
91cdf0e10cSrcweir             m_aOuterName = C2U("AxisType");
92cdf0e10cSrcweir             break;
93cdf0e10cSrcweir         case SCALE_PROP_DATE_INCREMENT:
94cdf0e10cSrcweir             m_aOuterName = C2U("TimeIncrement");
95cdf0e10cSrcweir             break;
96cdf0e10cSrcweir         case SCALE_PROP_EXPLICIT_DATE_INCREMENT:
97cdf0e10cSrcweir             m_aOuterName = C2U("ExplicitTimeIncrement");
98cdf0e10cSrcweir             break;
99cdf0e10cSrcweir         case SCALE_PROP_LOGARITHMIC:
100cdf0e10cSrcweir             m_aOuterName = C2U("Logarithmic");
101cdf0e10cSrcweir             break;
102cdf0e10cSrcweir         case SCALE_PROP_REVERSEDIRECTION:
103cdf0e10cSrcweir             m_aOuterName = C2U("ReverseDirection");
104cdf0e10cSrcweir             break;
105cdf0e10cSrcweir         default:
106cdf0e10cSrcweir             OSL_ENSURE(false,"unknown scale property");
107cdf0e10cSrcweir             break;
108cdf0e10cSrcweir     }
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
~WrappedScaleProperty()111cdf0e10cSrcweir WrappedScaleProperty::~WrappedScaleProperty()
112cdf0e10cSrcweir {
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
addWrappedProperties(std::vector<WrappedProperty * > & rList,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)115cdf0e10cSrcweir void WrappedScaleProperty::addWrappedProperties( std::vector< WrappedProperty* >& rList
116cdf0e10cSrcweir             , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     rList.push_back( new WrappedScaleProperty( SCALE_PROP_MAX, spChart2ModelContact ) );
119cdf0e10cSrcweir     rList.push_back( new WrappedScaleProperty( SCALE_PROP_MIN, spChart2ModelContact ) );
120cdf0e10cSrcweir     rList.push_back( new WrappedScaleProperty( SCALE_PROP_ORIGIN, spChart2ModelContact ) );
121cdf0e10cSrcweir     rList.push_back( new WrappedScaleProperty( SCALE_PROP_STEPMAIN, spChart2ModelContact ) );
122cdf0e10cSrcweir     rList.push_back( new WrappedScaleProperty( SCALE_PROP_STEPHELP, spChart2ModelContact ) );
123cdf0e10cSrcweir     rList.push_back( new WrappedScaleProperty( SCALE_PROP_STEPHELP_COUNT, spChart2ModelContact ) );
124cdf0e10cSrcweir     rList.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_MAX, spChart2ModelContact ) );
125cdf0e10cSrcweir     rList.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_MIN, spChart2ModelContact ) );
126cdf0e10cSrcweir     rList.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_ORIGIN, spChart2ModelContact ) );
127cdf0e10cSrcweir     rList.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_STEPMAIN, spChart2ModelContact ) );
128cdf0e10cSrcweir     rList.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_STEPHELP, spChart2ModelContact ) );
129cdf0e10cSrcweir     rList.push_back( new WrappedScaleProperty( SCALE_PROP_AXIS_TYPE, spChart2ModelContact ) );
130cdf0e10cSrcweir     rList.push_back( new WrappedScaleProperty( SCALE_PROP_DATE_INCREMENT, spChart2ModelContact ) );
131cdf0e10cSrcweir     rList.push_back( new WrappedScaleProperty( SCALE_PROP_EXPLICIT_DATE_INCREMENT, spChart2ModelContact ) );
132cdf0e10cSrcweir     rList.push_back( new WrappedScaleProperty( SCALE_PROP_LOGARITHMIC, spChart2ModelContact ) );
133cdf0e10cSrcweir     rList.push_back( new WrappedScaleProperty( SCALE_PROP_REVERSEDIRECTION, spChart2ModelContact ) );
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
setPropertyValue(const Any & rOuterValue,const Reference<beans::XPropertySet> & xInnerPropertySet) const136cdf0e10cSrcweir void WrappedScaleProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
137cdf0e10cSrcweir                 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir     setPropertyValue( m_eScaleProperty, rOuterValue, xInnerPropertySet );
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
getPropertyValue(const Reference<beans::XPropertySet> & xInnerPropertySet) const142cdf0e10cSrcweir Any WrappedScaleProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
143cdf0e10cSrcweir                         throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir     return getPropertyValue( m_eScaleProperty, xInnerPropertySet );
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
setPropertyValue(tScaleProperty eScaleProperty,const Any & rOuterValue,const Reference<beans::XPropertySet> & xInnerPropertySet) const148cdf0e10cSrcweir void WrappedScaleProperty::setPropertyValue( tScaleProperty eScaleProperty, const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
149cdf0e10cSrcweir                 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
150cdf0e10cSrcweir {
151cdf0e10cSrcweir     m_aOuterValue = rOuterValue;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     Reference< chart2::XAxis > xAxis( xInnerPropertySet, uno::UNO_QUERY );
154cdf0e10cSrcweir     OSL_ENSURE(xAxis.is(),"need an XAxis");
155cdf0e10cSrcweir     if(!xAxis.is())
156cdf0e10cSrcweir         return;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     bool bSetScaleData     = false;
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     chart2::ScaleData aScaleData( xAxis->getScaleData() );
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     sal_Bool bBool = false;
163cdf0e10cSrcweir     switch( eScaleProperty )
164cdf0e10cSrcweir     {
165cdf0e10cSrcweir         case SCALE_PROP_MAX:
166cdf0e10cSrcweir         {
167cdf0e10cSrcweir             aScaleData.Maximum = rOuterValue;
168cdf0e10cSrcweir             bSetScaleData = true;
169cdf0e10cSrcweir             break;
170cdf0e10cSrcweir         }
171cdf0e10cSrcweir         case SCALE_PROP_MIN:
172cdf0e10cSrcweir         {
173cdf0e10cSrcweir             aScaleData.Minimum = rOuterValue;
174cdf0e10cSrcweir             bSetScaleData = true;
175cdf0e10cSrcweir             break;
176cdf0e10cSrcweir         }
177cdf0e10cSrcweir         case SCALE_PROP_STEPMAIN:
178cdf0e10cSrcweir         {
179cdf0e10cSrcweir             aScaleData.IncrementData.Distance = rOuterValue;
180cdf0e10cSrcweir             bSetScaleData = true;
181cdf0e10cSrcweir             break;
182cdf0e10cSrcweir         }
183cdf0e10cSrcweir         case SCALE_PROP_STEPHELP:
184cdf0e10cSrcweir         {
185cdf0e10cSrcweir             Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
186cdf0e10cSrcweir             if( rSubIncrements.getLength() == 0 )
187cdf0e10cSrcweir                 rSubIncrements.realloc( 1 );
188cdf0e10cSrcweir 
189cdf0e10cSrcweir             double fStepMain = 0, fStepHelp = 0;
190cdf0e10cSrcweir             if( (rOuterValue >>= fStepHelp) )
191cdf0e10cSrcweir             {
192cdf0e10cSrcweir                 if( AxisHelper::isLogarithmic(aScaleData.Scaling) )
193cdf0e10cSrcweir                 {
194cdf0e10cSrcweir                     sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepHelp);
195cdf0e10cSrcweir                     rSubIncrements[ 0 ].IntervalCount <<= nIntervalCount;
196cdf0e10cSrcweir                 }
197cdf0e10cSrcweir                 else if( (fStepHelp != 0.0) &&
198cdf0e10cSrcweir                     (aScaleData.IncrementData.Distance >>= fStepMain) )
199cdf0e10cSrcweir                 {
200cdf0e10cSrcweir                     // approximate interval count
201cdf0e10cSrcweir                     sal_Int32 nIntervalCount = static_cast< sal_Int32 >(fStepMain / fStepHelp);
202cdf0e10cSrcweir                     rSubIncrements[ 0 ].IntervalCount <<= nIntervalCount;
203cdf0e10cSrcweir                 }
204cdf0e10cSrcweir             }
205cdf0e10cSrcweir             bSetScaleData = true;
206cdf0e10cSrcweir             break;
207cdf0e10cSrcweir         }
208cdf0e10cSrcweir         case SCALE_PROP_STEPHELP_COUNT:
209cdf0e10cSrcweir         {
210cdf0e10cSrcweir             Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
211cdf0e10cSrcweir             if( rSubIncrements.getLength() == 0 )
212cdf0e10cSrcweir                 rSubIncrements.realloc( 1 );
213cdf0e10cSrcweir             sal_Int32 nIntervalCount=0;
214cdf0e10cSrcweir             if( rOuterValue>>=nIntervalCount )
215cdf0e10cSrcweir                 rSubIncrements[ 0 ].IntervalCount <<= nIntervalCount;
216cdf0e10cSrcweir             else
217cdf0e10cSrcweir                 rSubIncrements[ 0 ].IntervalCount  = Any();
218cdf0e10cSrcweir             bSetScaleData = true;
219cdf0e10cSrcweir             break;
220cdf0e10cSrcweir         }
221cdf0e10cSrcweir         case SCALE_PROP_AUTO_MAX:
222cdf0e10cSrcweir         {
223cdf0e10cSrcweir             if( (rOuterValue >>= bBool) && bBool )
224cdf0e10cSrcweir                 aScaleData.Maximum = Any();
225cdf0e10cSrcweir             else
226cdf0e10cSrcweir                 aScaleData.Maximum = getPropertyValue( SCALE_PROP_MAX, xInnerPropertySet );
227cdf0e10cSrcweir             bSetScaleData = true;
228cdf0e10cSrcweir             break;
229cdf0e10cSrcweir         }
230cdf0e10cSrcweir         case SCALE_PROP_AUTO_MIN:
231cdf0e10cSrcweir         {
232cdf0e10cSrcweir             if( (rOuterValue >>= bBool) && bBool )
233cdf0e10cSrcweir                 aScaleData.Minimum = Any();
234cdf0e10cSrcweir             else
235cdf0e10cSrcweir                 aScaleData.Minimum = getPropertyValue( SCALE_PROP_MIN, xInnerPropertySet );
236cdf0e10cSrcweir             bSetScaleData = true;
237cdf0e10cSrcweir             break;
238cdf0e10cSrcweir         }
239cdf0e10cSrcweir         case SCALE_PROP_AUTO_STEPMAIN:
240cdf0e10cSrcweir         {
241cdf0e10cSrcweir             if( (rOuterValue >>= bBool) && bBool )
242cdf0e10cSrcweir                 aScaleData.IncrementData.Distance = Any();
243cdf0e10cSrcweir             else
244cdf0e10cSrcweir                 aScaleData.IncrementData.Distance = getPropertyValue( SCALE_PROP_STEPMAIN, xInnerPropertySet );
245cdf0e10cSrcweir             bSetScaleData = true;
246cdf0e10cSrcweir             break;
247cdf0e10cSrcweir         }
248cdf0e10cSrcweir         case SCALE_PROP_AUTO_STEPHELP:
249cdf0e10cSrcweir         {
250cdf0e10cSrcweir             Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
251cdf0e10cSrcweir             if( rSubIncrements.getLength() == 0 )
252cdf0e10cSrcweir                 rSubIncrements.realloc( 1 );
253cdf0e10cSrcweir 
254cdf0e10cSrcweir             if( (rOuterValue >>= bBool) && bBool )
255cdf0e10cSrcweir                 rSubIncrements[ 0 ].IntervalCount = Any();
256cdf0e10cSrcweir             else
257cdf0e10cSrcweir                 rSubIncrements[ 0 ].IntervalCount = getPropertyValue( SCALE_PROP_STEPHELP_COUNT, xInnerPropertySet );
258cdf0e10cSrcweir             bSetScaleData = true;
259cdf0e10cSrcweir             break;
260cdf0e10cSrcweir         }
261cdf0e10cSrcweir         case SCALE_PROP_ORIGIN:
262cdf0e10cSrcweir         {
263cdf0e10cSrcweir             aScaleData.Origin = rOuterValue;
264cdf0e10cSrcweir             bSetScaleData = true;
265cdf0e10cSrcweir             break;
266cdf0e10cSrcweir         }
267cdf0e10cSrcweir         case SCALE_PROP_AUTO_ORIGIN:
268cdf0e10cSrcweir         {
269cdf0e10cSrcweir             if( (rOuterValue >>= bBool) && bBool )
270cdf0e10cSrcweir                 aScaleData.Origin = Any();
271cdf0e10cSrcweir             else
272cdf0e10cSrcweir                 aScaleData.Origin = getPropertyValue( SCALE_PROP_ORIGIN, xInnerPropertySet );
273cdf0e10cSrcweir             bSetScaleData = true;
274cdf0e10cSrcweir             break;
275cdf0e10cSrcweir         }
276cdf0e10cSrcweir         case SCALE_PROP_AXIS_TYPE:
277cdf0e10cSrcweir         {
278cdf0e10cSrcweir             sal_Int32 nType = 0;
279cdf0e10cSrcweir             if( (rOuterValue >>= nType) )
280cdf0e10cSrcweir             {
281cdf0e10cSrcweir                 if( ::com::sun::star::chart::ChartAxisType::AUTOMATIC == nType )
282cdf0e10cSrcweir                 {
283cdf0e10cSrcweir                     aScaleData.AutoDateAxis = true;
284cdf0e10cSrcweir                     if( aScaleData.AxisType == AxisType::DATE )
285cdf0e10cSrcweir                         aScaleData.AxisType = AxisType::CATEGORY;
286cdf0e10cSrcweir                 }
287cdf0e10cSrcweir                 else if( ::com::sun::star::chart::ChartAxisType::CATEGORY == nType )
288cdf0e10cSrcweir                 {
289cdf0e10cSrcweir                     aScaleData.AutoDateAxis = false;
290cdf0e10cSrcweir                     if( aScaleData.AxisType == AxisType::DATE )
291cdf0e10cSrcweir                         aScaleData.AxisType = AxisType::CATEGORY;
292cdf0e10cSrcweir                 }
293cdf0e10cSrcweir                 else if( ::com::sun::star::chart::ChartAxisType::DATE == nType )
294cdf0e10cSrcweir                 {
295cdf0e10cSrcweir                     if( aScaleData.AxisType == AxisType::CATEGORY )
296cdf0e10cSrcweir                         aScaleData.AxisType = AxisType::DATE;
297cdf0e10cSrcweir                 }
298cdf0e10cSrcweir                 bSetScaleData = true;
299cdf0e10cSrcweir             }
300cdf0e10cSrcweir             break;
301cdf0e10cSrcweir         }
302cdf0e10cSrcweir         case SCALE_PROP_DATE_INCREMENT:
303cdf0e10cSrcweir         {
304cdf0e10cSrcweir             TimeIncrement aTimeIncrement;
305cdf0e10cSrcweir             rOuterValue >>= aTimeIncrement;
306cdf0e10cSrcweir             aScaleData.TimeIncrement = aTimeIncrement;
307cdf0e10cSrcweir             bSetScaleData = true;
308cdf0e10cSrcweir             break;
309cdf0e10cSrcweir         }
310cdf0e10cSrcweir         case SCALE_PROP_EXPLICIT_DATE_INCREMENT:
311cdf0e10cSrcweir             //read only property
312cdf0e10cSrcweir             break;
313cdf0e10cSrcweir         case SCALE_PROP_LOGARITHMIC:
314cdf0e10cSrcweir         {
315cdf0e10cSrcweir             if( rOuterValue >>= bBool )
316cdf0e10cSrcweir             {
317cdf0e10cSrcweir                 bool bWasLogarithm = AxisHelper::isLogarithmic( aScaleData.Scaling );
318cdf0e10cSrcweir 
319cdf0e10cSrcweir                 // safe comparison between sal_Bool and bool
320cdf0e10cSrcweir                 if( (!bBool) != (!bWasLogarithm) )
321cdf0e10cSrcweir                 {
322cdf0e10cSrcweir                     if( bBool )
323cdf0e10cSrcweir                         aScaleData.Scaling = AxisHelper::createLogarithmicScaling( 10.0 );
324cdf0e10cSrcweir                     else
325cdf0e10cSrcweir                         aScaleData.Scaling = 0;
326cdf0e10cSrcweir                     bSetScaleData = true;
327cdf0e10cSrcweir                 }
328cdf0e10cSrcweir             }
329cdf0e10cSrcweir             break;
330cdf0e10cSrcweir         }
331cdf0e10cSrcweir         case SCALE_PROP_REVERSEDIRECTION:
332cdf0e10cSrcweir         {
333cdf0e10cSrcweir             if( rOuterValue >>= bBool )
334cdf0e10cSrcweir             {
335cdf0e10cSrcweir                 bool bWasReverse = ( AxisOrientation_REVERSE == aScaleData.Orientation );
336cdf0e10cSrcweir                 if( (!bBool) != (!bWasReverse) ) // safe comparison between sal_Bool and bool
337cdf0e10cSrcweir                 {
338cdf0e10cSrcweir                     aScaleData.Orientation = bBool ? AxisOrientation_REVERSE : AxisOrientation_MATHEMATICAL;
339cdf0e10cSrcweir                     bSetScaleData = true;
340cdf0e10cSrcweir                 }
341cdf0e10cSrcweir             }
342cdf0e10cSrcweir             break;
343cdf0e10cSrcweir         }
344cdf0e10cSrcweir         default:
345cdf0e10cSrcweir         {
346cdf0e10cSrcweir             OSL_ENSURE(false,"unknown scale property");
347cdf0e10cSrcweir             break;
348cdf0e10cSrcweir         }
349cdf0e10cSrcweir     }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir     if( bSetScaleData )
352cdf0e10cSrcweir         xAxis->setScaleData( aScaleData );
353cdf0e10cSrcweir }
354cdf0e10cSrcweir 
getPropertyValue(tScaleProperty eScaleProperty,const Reference<beans::XPropertySet> & xInnerPropertySet) const355cdf0e10cSrcweir Any WrappedScaleProperty::getPropertyValue( tScaleProperty eScaleProperty, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
356cdf0e10cSrcweir                         throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
357cdf0e10cSrcweir {
358cdf0e10cSrcweir     Any aRet( m_aOuterValue );
359cdf0e10cSrcweir 
360cdf0e10cSrcweir     Reference< chart2::XAxis > xAxis( xInnerPropertySet, uno::UNO_QUERY );
361cdf0e10cSrcweir     OSL_ENSURE(xAxis.is(),"need an XAxis");
362cdf0e10cSrcweir     if(!xAxis.is())
363cdf0e10cSrcweir         return aRet;
364cdf0e10cSrcweir 
365cdf0e10cSrcweir     chart2::ScaleData aScaleData( xAxis->getScaleData() );
366cdf0e10cSrcweir 
367cdf0e10cSrcweir     ExplicitScaleData aExplicitScale;
368cdf0e10cSrcweir     ExplicitIncrementData aExplicitIncrement;
369cdf0e10cSrcweir 
370cdf0e10cSrcweir     switch( eScaleProperty )
371cdf0e10cSrcweir     {
372cdf0e10cSrcweir         case SCALE_PROP_MAX:
373cdf0e10cSrcweir         {
374cdf0e10cSrcweir             aRet = aScaleData.Maximum;
375cdf0e10cSrcweir             if( !aRet.hasValue() )
376cdf0e10cSrcweir             {
377cdf0e10cSrcweir                 m_spChart2ModelContact->getExplicitValuesForAxis(
378cdf0e10cSrcweir                     xAxis, aExplicitScale, aExplicitIncrement );
379cdf0e10cSrcweir                 aRet <<= aExplicitScale.Maximum;
380cdf0e10cSrcweir             }
381cdf0e10cSrcweir             break;
382cdf0e10cSrcweir         }
383cdf0e10cSrcweir         case SCALE_PROP_MIN:
384cdf0e10cSrcweir         {
385cdf0e10cSrcweir             aRet = aScaleData.Minimum;
386cdf0e10cSrcweir             if( !aRet.hasValue() )
387cdf0e10cSrcweir             {
388cdf0e10cSrcweir                 m_spChart2ModelContact->getExplicitValuesForAxis(
389cdf0e10cSrcweir                     xAxis, aExplicitScale, aExplicitIncrement );
390cdf0e10cSrcweir                 aRet <<= aExplicitScale.Minimum;
391cdf0e10cSrcweir             }
392cdf0e10cSrcweir             break;
393cdf0e10cSrcweir         }
394cdf0e10cSrcweir 
395cdf0e10cSrcweir         case SCALE_PROP_STEPMAIN:
396cdf0e10cSrcweir         {
397cdf0e10cSrcweir             aRet = aScaleData.IncrementData.Distance;
398cdf0e10cSrcweir             if( !aRet.hasValue() )
399cdf0e10cSrcweir             {
400cdf0e10cSrcweir                 m_spChart2ModelContact->getExplicitValuesForAxis(
401cdf0e10cSrcweir                     xAxis, aExplicitScale, aExplicitIncrement );
402cdf0e10cSrcweir                 aRet <<= aExplicitIncrement.Distance;
403cdf0e10cSrcweir             }
404cdf0e10cSrcweir             break;
405cdf0e10cSrcweir         }
406cdf0e10cSrcweir         case SCALE_PROP_STEPHELP:
407cdf0e10cSrcweir         {
408cdf0e10cSrcweir             // todo: evaluate PostEquidistant
409cdf0e10cSrcweir             bool bNeedToCalculateExplicitValues = true;
410cdf0e10cSrcweir 
411cdf0e10cSrcweir             bool bLogarithmic( AxisHelper::isLogarithmic(aScaleData.Scaling) );
412cdf0e10cSrcweir             Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
413cdf0e10cSrcweir             if( bLogarithmic )
414cdf0e10cSrcweir             {
415cdf0e10cSrcweir                 if( rSubIncrements.getLength() > 0 )
416cdf0e10cSrcweir                 {
417cdf0e10cSrcweir                     sal_Int32 nIntervalCount = 0;
418cdf0e10cSrcweir                     rSubIncrements[ 0 ].IntervalCount >>= nIntervalCount;
419cdf0e10cSrcweir                     aRet = uno::makeAny( double(nIntervalCount) );
420cdf0e10cSrcweir                     bNeedToCalculateExplicitValues = false;
421cdf0e10cSrcweir                 }
422cdf0e10cSrcweir             }
423cdf0e10cSrcweir             else if( aScaleData.IncrementData.Distance.hasValue() )
424cdf0e10cSrcweir             {
425cdf0e10cSrcweir                 if( rSubIncrements.getLength() > 0 )
426cdf0e10cSrcweir                 {
427cdf0e10cSrcweir                     double fStepMain = 0;
428cdf0e10cSrcweir                     sal_Int32 nIntervalCount = 0;
429cdf0e10cSrcweir                     if( (aScaleData.IncrementData.Distance >>= fStepMain) &&
430cdf0e10cSrcweir                         (rSubIncrements[ 0 ].IntervalCount >>= nIntervalCount) &&
431cdf0e10cSrcweir                         nIntervalCount > 0 )
432cdf0e10cSrcweir                     {
433cdf0e10cSrcweir                         aRet <<= ( fStepMain / static_cast< double >( nIntervalCount ) );
434cdf0e10cSrcweir                         bNeedToCalculateExplicitValues = false;
435cdf0e10cSrcweir                     }
436cdf0e10cSrcweir                 }
437cdf0e10cSrcweir                 else
438cdf0e10cSrcweir                 {
439cdf0e10cSrcweir                     aRet = aScaleData.IncrementData.Distance;
440cdf0e10cSrcweir                     bNeedToCalculateExplicitValues = false;
441cdf0e10cSrcweir                 }
442cdf0e10cSrcweir             }
443cdf0e10cSrcweir 
444cdf0e10cSrcweir             if( bNeedToCalculateExplicitValues )
445cdf0e10cSrcweir             {
446cdf0e10cSrcweir                 m_spChart2ModelContact->getExplicitValuesForAxis(
447cdf0e10cSrcweir                     xAxis, aExplicitScale, aExplicitIncrement );
448cdf0e10cSrcweir 
449cdf0e10cSrcweir                 if( !aExplicitIncrement.SubIncrements.empty() &&
450cdf0e10cSrcweir                      aExplicitIncrement.SubIncrements[ 0 ].IntervalCount > 0 )
451cdf0e10cSrcweir                 {
452cdf0e10cSrcweir                     if( bLogarithmic )
453cdf0e10cSrcweir                     {
454cdf0e10cSrcweir                         if( rSubIncrements.getLength() > 0 )
455cdf0e10cSrcweir                         {
456cdf0e10cSrcweir                             sal_Int32 nIntervalCount = aExplicitIncrement.SubIncrements[ 0 ].IntervalCount;
457cdf0e10cSrcweir                             aRet = uno::makeAny( double(nIntervalCount) );
458cdf0e10cSrcweir                         }
459cdf0e10cSrcweir                     }
460cdf0e10cSrcweir                     else
461cdf0e10cSrcweir                         aRet <<= ( aExplicitIncrement.Distance /
462cdf0e10cSrcweir                                 static_cast< double >(
463cdf0e10cSrcweir                                     aExplicitIncrement.SubIncrements[ 0 ].IntervalCount ));
464cdf0e10cSrcweir                 }
465cdf0e10cSrcweir                 else
466cdf0e10cSrcweir                 {
467cdf0e10cSrcweir                     if( bLogarithmic )
468cdf0e10cSrcweir                         aRet <<= 5.0;
469cdf0e10cSrcweir                     else
470cdf0e10cSrcweir                         aRet <<= aExplicitIncrement.Distance;
471cdf0e10cSrcweir                 }
472cdf0e10cSrcweir             }
473cdf0e10cSrcweir             break;
474cdf0e10cSrcweir         }
475cdf0e10cSrcweir         case SCALE_PROP_STEPHELP_COUNT:
476cdf0e10cSrcweir         {
477cdf0e10cSrcweir             sal_Int32 nIntervalCount = 0;
478cdf0e10cSrcweir             bool bNeedToCalculateExplicitValues = true;
479cdf0e10cSrcweir             Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
480cdf0e10cSrcweir             if( rSubIncrements.getLength() > 0 )
481cdf0e10cSrcweir             {
482cdf0e10cSrcweir                 if( (rSubIncrements[ 0 ].IntervalCount >>= nIntervalCount) && (nIntervalCount > 0) )
483cdf0e10cSrcweir                     bNeedToCalculateExplicitValues = false;
484cdf0e10cSrcweir             }
485cdf0e10cSrcweir             if( bNeedToCalculateExplicitValues )
486cdf0e10cSrcweir             {
487cdf0e10cSrcweir                 m_spChart2ModelContact->getExplicitValuesForAxis( xAxis, aExplicitScale, aExplicitIncrement );
488cdf0e10cSrcweir                 if( !aExplicitIncrement.SubIncrements.empty() )
489cdf0e10cSrcweir                     nIntervalCount = aExplicitIncrement.SubIncrements[ 0 ].IntervalCount;
490cdf0e10cSrcweir             }
491cdf0e10cSrcweir             aRet = uno::makeAny( nIntervalCount );
492cdf0e10cSrcweir             break;
493cdf0e10cSrcweir         }
494cdf0e10cSrcweir         case SCALE_PROP_AUTO_MAX:
495cdf0e10cSrcweir         {
496cdf0e10cSrcweir             aRet <<= (sal_Bool)( !aScaleData.Maximum.hasValue() );
497cdf0e10cSrcweir             break;
498cdf0e10cSrcweir         }
499cdf0e10cSrcweir         case SCALE_PROP_AUTO_MIN:
500cdf0e10cSrcweir         {
501cdf0e10cSrcweir             aRet <<= (sal_Bool)( !aScaleData.Minimum.hasValue() );
502cdf0e10cSrcweir             break;
503cdf0e10cSrcweir         }
504cdf0e10cSrcweir         case SCALE_PROP_AUTO_STEPMAIN:
505cdf0e10cSrcweir         {
506cdf0e10cSrcweir             aRet <<= (sal_Bool)( !aScaleData.IncrementData.Distance.hasValue() );
507cdf0e10cSrcweir             break;
508cdf0e10cSrcweir         }
509cdf0e10cSrcweir         case SCALE_PROP_AUTO_STEPHELP:
510cdf0e10cSrcweir         {
511cdf0e10cSrcweir             Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
512cdf0e10cSrcweir             if( rSubIncrements.getLength() > 0 )
513cdf0e10cSrcweir                 aRet <<= (sal_Bool)( !rSubIncrements[ 0 ].IntervalCount.hasValue() );
514cdf0e10cSrcweir             else
515cdf0e10cSrcweir                 aRet <<= sal_True;
516cdf0e10cSrcweir             break;
517cdf0e10cSrcweir         }
518cdf0e10cSrcweir         case SCALE_PROP_ORIGIN:
519cdf0e10cSrcweir         {
520cdf0e10cSrcweir             aRet = aScaleData.Origin;
521cdf0e10cSrcweir             if( !aRet.hasValue() )
522cdf0e10cSrcweir             {
523cdf0e10cSrcweir                 m_spChart2ModelContact->getExplicitValuesForAxis(
524cdf0e10cSrcweir                     xAxis, aExplicitScale, aExplicitIncrement );
525cdf0e10cSrcweir                 aRet <<= aExplicitScale.Origin;
526cdf0e10cSrcweir             }
527cdf0e10cSrcweir             break;
528cdf0e10cSrcweir         }
529cdf0e10cSrcweir         case SCALE_PROP_AUTO_ORIGIN:
530cdf0e10cSrcweir         {
531cdf0e10cSrcweir             aRet <<= !hasDoubleValue(aScaleData.Origin);
532cdf0e10cSrcweir             break;
533cdf0e10cSrcweir         }
534cdf0e10cSrcweir         case SCALE_PROP_AXIS_TYPE:
535cdf0e10cSrcweir         {
536cdf0e10cSrcweir             sal_Int32 nType = ::com::sun::star::chart::ChartAxisType::AUTOMATIC;
537cdf0e10cSrcweir             if( aScaleData.AxisType == AxisType::DATE )
538cdf0e10cSrcweir             {
539cdf0e10cSrcweir                 nType = ::com::sun::star::chart::ChartAxisType::DATE;
540cdf0e10cSrcweir             }
541cdf0e10cSrcweir             else if( aScaleData.AxisType == AxisType::CATEGORY )
542cdf0e10cSrcweir             {
543cdf0e10cSrcweir                 if( !aScaleData.AutoDateAxis )
544cdf0e10cSrcweir                     nType = ::com::sun::star::chart::ChartAxisType::CATEGORY;
545cdf0e10cSrcweir             }
546cdf0e10cSrcweir             aRet = uno::makeAny( nType );
547cdf0e10cSrcweir             break;
548cdf0e10cSrcweir         }
549cdf0e10cSrcweir         case SCALE_PROP_DATE_INCREMENT:
550cdf0e10cSrcweir         {
551cdf0e10cSrcweir             if( aScaleData.AxisType == AxisType::DATE || aScaleData.AutoDateAxis )
552cdf0e10cSrcweir                 aRet = uno::makeAny( aScaleData.TimeIncrement );
553cdf0e10cSrcweir             break;
554cdf0e10cSrcweir         }
555cdf0e10cSrcweir         case SCALE_PROP_EXPLICIT_DATE_INCREMENT:
556cdf0e10cSrcweir         {
557cdf0e10cSrcweir             if( aScaleData.AxisType == AxisType::DATE || aScaleData.AutoDateAxis )
558cdf0e10cSrcweir             {
559cdf0e10cSrcweir                 m_spChart2ModelContact->getExplicitValuesForAxis( xAxis, aExplicitScale, aExplicitIncrement );
560cdf0e10cSrcweir                 if( aExplicitScale.AxisType == AxisType::DATE )
561cdf0e10cSrcweir                 {
562cdf0e10cSrcweir                     TimeIncrement aTimeIncrement;
563cdf0e10cSrcweir                     aTimeIncrement.MajorTimeInterval = uno::makeAny( aExplicitIncrement.MajorTimeInterval );
564cdf0e10cSrcweir                     aTimeIncrement.MinorTimeInterval = uno::makeAny( aExplicitIncrement.MinorTimeInterval );
565cdf0e10cSrcweir                     aTimeIncrement.TimeResolution = uno::makeAny( aExplicitScale.TimeResolution );
566cdf0e10cSrcweir                     aRet = uno::makeAny(aTimeIncrement);
567cdf0e10cSrcweir                 }
568cdf0e10cSrcweir             }
569cdf0e10cSrcweir 
570cdf0e10cSrcweir             if( aScaleData.AxisType == AxisType::DATE || aScaleData.AutoDateAxis )
571cdf0e10cSrcweir                 aRet = uno::makeAny( aScaleData.TimeIncrement );
572cdf0e10cSrcweir             break;
573cdf0e10cSrcweir         }
574cdf0e10cSrcweir         case SCALE_PROP_LOGARITHMIC:
575cdf0e10cSrcweir         {
576cdf0e10cSrcweir             aRet <<= static_cast< sal_Bool >( AxisHelper::isLogarithmic(aScaleData.Scaling) );
577cdf0e10cSrcweir             break;
578cdf0e10cSrcweir         }
579cdf0e10cSrcweir         case SCALE_PROP_REVERSEDIRECTION:
580cdf0e10cSrcweir         {
581cdf0e10cSrcweir             aRet <<= static_cast< sal_Bool >( AxisOrientation_REVERSE == aScaleData.Orientation );
582cdf0e10cSrcweir             break;
583cdf0e10cSrcweir         }
584cdf0e10cSrcweir         default:
585cdf0e10cSrcweir         {
586cdf0e10cSrcweir             OSL_ENSURE(false,"unknown scale property");
587cdf0e10cSrcweir             break;
588cdf0e10cSrcweir         }
589cdf0e10cSrcweir     }
590cdf0e10cSrcweir 
591cdf0e10cSrcweir     return aRet;
592cdf0e10cSrcweir }
593cdf0e10cSrcweir 
594cdf0e10cSrcweir } //  namespace wrapper
595cdf0e10cSrcweir } //  namespace chart
596cdf0e10cSrcweir //.............................................................................
597