update dev300-m58
[ooovba.git] / sc / source / ui / vba / vbaaxis.cxx
blob8eb0933a43a78811844965a91997c81905450782
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbaaxis.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "vbaaxis.hxx"
32 #include <ooo/vba/excel/XlAxisCrosses.hpp>
33 #include <ooo/vba/excel/XlAxisType.hpp>
34 #include <ooo/vba/excel/XlScaleType.hpp>
35 #include "vbaaxistitle.hxx"
36 #include "vbachart.hxx"
37 using namespace ::com::sun::star;
38 using namespace ::ooo::vba;
39 using namespace ::ooo::vba::excel::XlAxisCrosses;
40 using namespace ::ooo::vba::excel::XlAxisType;
41 using namespace ::ooo::vba::excel::XlScaleType;
43 const rtl::OUString ORIGIN( RTL_CONSTASCII_USTRINGPARAM("Origin") );
44 const rtl::OUString AUTOORIGIN( RTL_CONSTASCII_USTRINGPARAM("AutoOrigin") );
45 const rtl::OUString VBA_MIN( RTL_CONSTASCII_USTRINGPARAM("Max") );
46 const rtl::OUString VBA_MAX( RTL_CONSTASCII_USTRINGPARAM("Min") );
47 ScVbaChart*
48 ScVbaAxis::getChartPtr() throw( uno::RuntimeException )
50 ScVbaChart* pChart = static_cast< ScVbaChart* >( moChartParent.get() );
51 if ( !pChart )
52 throw uno::RuntimeException( rtl::OUString::createFromAscii("Can't access parent chart impl"), uno::Reference< uno::XInterface >() );
53 return pChart;
56 sal_Bool
57 ScVbaAxis::isValueAxis() throw( script::BasicErrorException )
59 if ( getType() == xlCategory )
61 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
63 return sal_True;
66 ScVbaAxis::ScVbaAxis( const uno::Reference< XHelperInterface >& xParent,const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< beans::XPropertySet >& _xPropertySet, sal_Int32 _nType, sal_Int32 _nGroup ) : ScVbaAxis_BASE( xParent, xContext ), mxPropertySet( _xPropertySet ), mnType( _nType ), mnGroup( _nGroup ), bCrossesAreCustomized( sal_False )
68 oShapeHelper.reset( new ShapeHelper( uno::Reference< drawing::XShape >( mxPropertySet, uno::UNO_QUERY ) ) );
69 moChartParent.set( xParent, uno::UNO_QUERY_THROW );
70 setType(_nType);
71 setCrosses(xlAxisCrossesAutomatic);
74 void SAL_CALL
75 ScVbaAxis::Delete( ) throw (script::BasicErrorException, uno::RuntimeException)
77 uno::Reference< lang::XComponent > xComponent( mxPropertySet, uno::UNO_QUERY_THROW );
78 xComponent->dispose();
81 uno::Reference< ::ooo::vba::excel::XAxisTitle > SAL_CALL
82 ScVbaAxis::getAxisTitle( ) throw (script::BasicErrorException, uno::RuntimeException)
84 uno::Reference< excel::XAxisTitle > xAxisTitle;
85 try
87 ScVbaChart* pChart = getChartPtr();
89 if (getHasTitle() )
91 int nType = getType();
92 switch(nType)
94 case xlCategory:
95 xAxisTitle = new ScVbaAxisTitle(this, mxContext, pChart->xAxisXSupplier->getXAxisTitle());
96 break;
97 case xlSeriesAxis:
98 xAxisTitle = new ScVbaAxisTitle(this, mxContext, pChart->xAxisZSupplier->getZAxisTitle());
99 break;
100 default: // xlValue:
101 xAxisTitle = new ScVbaAxisTitle(this, mxContext, pChart->xAxisYSupplier->getYAxisTitle());
102 break;
106 catch (uno::Exception& e)
108 DebugHelper::exception(e);
110 return xAxisTitle;
114 void SAL_CALL
115 ScVbaAxis::setDisplayUnit( ::sal_Int32 /*DisplayUnit*/ ) throw (script::BasicErrorException, uno::RuntimeException)
117 DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
120 ::sal_Int32 SAL_CALL
121 ScVbaAxis::getDisplayUnit( ) throw (script::BasicErrorException, uno::RuntimeException)
123 DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
124 return -1;
127 void SAL_CALL
128 ScVbaAxis::setCrosses( ::sal_Int32 _nCrosses ) throw (script::BasicErrorException, uno::RuntimeException)
132 double fNum = 0.0;
133 switch (_nCrosses)
135 case xlAxisCrossesAutomatic: //Microsoft Excel sets the axis crossing point.
136 mxPropertySet->setPropertyValue(AUTOORIGIN, uno::makeAny( sal_True ) );
137 bCrossesAreCustomized = sal_False;
138 return;
139 case xlAxisCrossesMinimum: // The axis crosses at the minimum value.
140 mxPropertySet->getPropertyValue(VBA_MIN) >>= fNum;
141 setCrossesAt( fNum );
142 bCrossesAreCustomized = sal_False;
143 break;
144 case xlAxisCrossesMaximum: // The axis crosses at the maximum value.
145 mxPropertySet->getPropertyValue(VBA_MAX) >>= fNum;
146 setCrossesAt(fNum);
147 bCrossesAreCustomized = sal_False;
148 break;
149 default: //xlAxisCrossesCustom
150 bCrossesAreCustomized = sal_True;
151 break;
153 mxPropertySet->setPropertyValue(AUTOORIGIN, uno::makeAny(sal_False) );
155 catch (uno::Exception& )
157 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
160 ::sal_Int32 SAL_CALL
161 ScVbaAxis::getCrosses( ) throw (script::BasicErrorException, uno::RuntimeException)
163 sal_Int32 nCrosses = xlAxisCrossesCustom;
166 sal_Bool bisAutoOrigin = sal_False;
167 mxPropertySet->getPropertyValue(AUTOORIGIN) >>= bisAutoOrigin;
168 if (bisAutoOrigin)
169 nCrosses = xlAxisCrossesAutomatic;
170 else
172 if (bCrossesAreCustomized)
173 nCrosses = xlAxisCrossesCustom;
174 else
176 double forigin = 0.0;
177 mxPropertySet->getPropertyValue(ORIGIN) >>= forigin;
178 //obsolete double fmax = AnyConverter.toDouble(mxPropertySet.getPropertyValue("Max"));
179 double fmin = 0.0;
180 mxPropertySet->getPropertyValue(VBA_MIN) >>= fmin;
181 if (forigin == fmin)
182 nCrosses = xlAxisCrossesMinimum;
183 else
184 nCrosses = xlAxisCrossesMaximum;
188 catch (uno::Exception& )
190 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
192 return nCrosses;
195 void SAL_CALL
196 ScVbaAxis::setCrossesAt( double _fCrossesAt ) throw (script::BasicErrorException, uno::RuntimeException)
200 // if (getCrosses() == xlAxisCrossesCustom){
201 setMaximumScaleIsAuto( sal_False );
202 setMinimumScaleIsAuto( sal_False );
203 mxPropertySet->setPropertyValue(ORIGIN, uno::makeAny(_fCrossesAt));
204 // }
206 catch (uno::Exception& e)
208 DebugHelper::exception(e);
212 double SAL_CALL
213 ScVbaAxis::getCrossesAt( ) throw (script::BasicErrorException, uno::RuntimeException)
215 double fCrosses = 0.0;
218 mxPropertySet->getPropertyValue(ORIGIN) >>= fCrosses;
220 catch (uno::Exception& )
222 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
224 return fCrosses;
227 void SAL_CALL
228 ScVbaAxis::setType( ::sal_Int32 _nType ) throw (script::BasicErrorException, uno::RuntimeException)
230 mnType = _nType;
233 ::sal_Int32 SAL_CALL
234 ScVbaAxis::getType( ) throw (script::BasicErrorException, uno::RuntimeException)
236 return mnType;
239 void SAL_CALL
240 ScVbaAxis::setHasTitle( ::sal_Bool _bHasTitle ) throw (script::BasicErrorException, uno::RuntimeException)
244 ScVbaChart* pChart = getChartPtr();
245 sal_Int32 nType = getType();
246 switch(nType)
248 case xlCategory:
249 pChart->mxDiagramPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasXAxisTitle")), uno::makeAny(_bHasTitle));
250 break;
251 case xlSeriesAxis:
252 pChart->mxDiagramPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasZAxisTitle")), uno::makeAny(_bHasTitle));
253 break;
254 default: // xlValue:
255 pChart->mxDiagramPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasYAxisTitle")), uno::makeAny(_bHasTitle));
259 catch (uno::Exception& e)
261 DebugHelper::exception(e);
265 ::sal_Bool SAL_CALL
266 ScVbaAxis::getHasTitle( ) throw (script::BasicErrorException, uno::RuntimeException)
268 sal_Bool bHasTitle = sal_False;
271 ScVbaChart* pChart = getChartPtr();
272 int nType = getType();
273 switch(nType)
275 case xlCategory:
276 pChart->mxDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasXAxisTitle")) ) >>= bHasTitle;
277 break;
278 case xlSeriesAxis:
279 pChart->mxDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasZAxisTitle")) ) >>= bHasTitle;
280 break;
281 default: // xlValue:
282 pChart->mxDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasYAxisTitle")) ) >>= bHasTitle;
285 catch (uno::Exception& e)
287 DebugHelper::exception(e);
289 return bHasTitle;
292 void SAL_CALL
293 ScVbaAxis::setMinorUnit( double _fMinorUnit ) throw (script::BasicErrorException, uno::RuntimeException)
297 if (isValueAxis())
298 mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StepHelp") ), uno::makeAny(_fMinorUnit));
300 catch (uno::Exception& )
302 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
306 double SAL_CALL
307 ScVbaAxis::getMinorUnit( ) throw (script::BasicErrorException, uno::RuntimeException)
309 double fMinor = 1.0;
312 if (isValueAxis())
313 mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StepHelp"))) >>= fMinor;
315 catch (uno::Exception& )
317 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
319 return fMinor;
322 void SAL_CALL
323 ScVbaAxis::setMinorUnitIsAuto( ::sal_Bool _bMinorUnitIsAuto ) throw (script::BasicErrorException, uno::RuntimeException)
327 if (isValueAxis())
328 mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoStepHelp" ) ), uno::makeAny(_bMinorUnitIsAuto));
330 catch (uno::Exception& )
332 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
336 ::sal_Bool SAL_CALL
337 ScVbaAxis::getMinorUnitIsAuto( ) throw (script::BasicErrorException, uno::RuntimeException)
339 sal_Bool bIsAuto = sal_False;
342 if (isValueAxis())
344 mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoStepHelp")) ) >>= bIsAuto;
347 catch (uno::Exception& )
349 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
351 return bIsAuto;
354 void SAL_CALL
355 ScVbaAxis::setReversePlotOrder( ::sal_Bool /*ReversePlotOrder*/ ) throw (script::BasicErrorException, uno::RuntimeException)
357 DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
360 ::sal_Bool SAL_CALL
361 ScVbaAxis::getReversePlotOrder( ) throw (script::BasicErrorException, uno::RuntimeException)
363 DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
364 return sal_False;
367 void SAL_CALL
368 ScVbaAxis::setMajorUnit( double _fMajorUnit ) throw (script::BasicErrorException, uno::RuntimeException)
372 if (isValueAxis())
374 mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StepMain")), uno::makeAny(_fMajorUnit));
377 catch (uno::Exception& )
379 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
383 double SAL_CALL
384 ScVbaAxis::getMajorUnit( ) throw (script::BasicErrorException, uno::RuntimeException)
386 double fMax = 1.0;
389 if (isValueAxis())
390 mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StepMain"))) >>= fMax;
392 catch (uno::Exception& )
394 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
396 return fMax;
399 void SAL_CALL
400 ScVbaAxis::setMajorUnitIsAuto( ::sal_Bool _bMajorUnitIsAuto ) throw (script::BasicErrorException, uno::RuntimeException)
404 if (isValueAxis())
406 mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoStepMain" ) ), uno::makeAny( _bMajorUnitIsAuto ));
409 catch (uno::Exception& )
411 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
415 ::sal_Bool SAL_CALL
416 ScVbaAxis::getMajorUnitIsAuto( ) throw (script::BasicErrorException, uno::RuntimeException)
418 sal_Bool bIsAuto = sal_False;
421 if (isValueAxis())
423 mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoStepMain"))) >>= bIsAuto;
426 catch (uno::Exception& )
428 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
430 return bIsAuto;
433 void SAL_CALL
434 ScVbaAxis::setMaximumScale( double _fMaximumScale ) throw (script::BasicErrorException, uno::RuntimeException)
438 if ( isValueAxis() )
440 mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Max" ) ), uno::makeAny(_fMaximumScale));
443 catch ( uno::Exception& )
445 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
449 double SAL_CALL
450 ScVbaAxis::getMaximumScale( ) throw (script::BasicErrorException, uno::RuntimeException)
452 double fMax = 1.0;
455 if (isValueAxis())
457 mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Max" ))) >>= fMax;
460 catch (uno::Exception& )
462 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
464 return fMax;
468 void SAL_CALL
469 ScVbaAxis::setMaximumScaleIsAuto( ::sal_Bool _bMaximumScaleIsAuto ) throw (script::BasicErrorException, uno::RuntimeException)
473 if ( isValueAxis() )
474 mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoMax" ) ), uno::makeAny( _bMaximumScaleIsAuto ));
477 catch ( uno::Exception& )
479 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
484 ::sal_Bool SAL_CALL
485 ScVbaAxis::getMaximumScaleIsAuto( ) throw (script::BasicErrorException, uno::RuntimeException)
487 sal_Bool bIsAuto = sal_False;
490 if (isValueAxis())
491 mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoMax" )) ) >>= bIsAuto;
493 catch ( uno::Exception& )
495 DebugHelper::exception( SbERR_METHOD_FAILED, rtl::OUString() );
497 return bIsAuto;
500 void SAL_CALL
501 ScVbaAxis::setMinimumScale( double _fMinimumScale ) throw (script::BasicErrorException, uno::RuntimeException)
505 if (isValueAxis())
506 mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Min") ), uno::makeAny( _fMinimumScale ) );
508 catch ( uno::Exception& )
510 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
514 double SAL_CALL
515 ScVbaAxis::getMinimumScale( ) throw (script::BasicErrorException, uno::RuntimeException)
517 double fMin = 0.0;
520 if (isValueAxis())
521 mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Min") )) >>= fMin;
523 catch (uno::Exception& e)
525 DebugHelper::exception(e);
527 return fMin;
530 void SAL_CALL
531 ScVbaAxis::setMinimumScaleIsAuto( ::sal_Bool _bMinimumScaleIsAuto ) throw (script::BasicErrorException, uno::RuntimeException)
535 if (isValueAxis())
537 mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoMin") ), uno::makeAny(_bMinimumScaleIsAuto));
540 catch (uno::Exception& )
542 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
546 ::sal_Bool SAL_CALL
547 ScVbaAxis::getMinimumScaleIsAuto( ) throw (script::BasicErrorException, uno::RuntimeException)
549 sal_Bool bIsAuto = sal_False;
552 if (isValueAxis())
554 mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoMin")) ) >>= bIsAuto;
557 catch (uno::Exception& )
559 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
561 return bIsAuto;
564 ::sal_Int32 SAL_CALL
565 ScVbaAxis::getAxisGroup( ) throw (uno::RuntimeException)
567 return mnGroup;
570 void SAL_CALL
571 ScVbaAxis::setScaleType( ::sal_Int32 _nScaleType ) throw (script::BasicErrorException, uno::RuntimeException)
575 if (isValueAxis())
577 switch (_nScaleType)
579 case xlScaleLinear:
580 mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Logarithmic" ) ), uno::makeAny( sal_False ) );
581 break;
582 case xlScaleLogarithmic:
583 mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Logarithmic" ) ), uno::makeAny( sal_True ) );
584 break;
585 default:
586 // According to MS the paramenter is ignored and no Error is thrown
587 break;
591 catch (uno::Exception& )
593 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
597 ::sal_Int32 SAL_CALL
598 ScVbaAxis::getScaleType( ) throw (script::BasicErrorException, uno::RuntimeException)
600 sal_Int32 nScaleType = xlScaleLinear;
603 if (isValueAxis())
605 sal_Bool bisLogarithmic = sal_False;
606 mxPropertySet->getPropertyValue( rtl::OUString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Logarithmic"))) ) >>= bisLogarithmic;
607 if (bisLogarithmic)
608 nScaleType = xlScaleLogarithmic;
609 else
610 nScaleType = xlScaleLinear;
613 catch (uno::Exception& )
615 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
617 return nScaleType;
620 double SAL_CALL
621 ScVbaAxis::getHeight( ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
623 return oShapeHelper->getHeight();
626 void SAL_CALL ScVbaAxis::setHeight( double height ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
628 oShapeHelper->setHeight( height );
630 double SAL_CALL ScVbaAxis::getWidth( ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
632 return oShapeHelper->getWidth( );
634 void SAL_CALL ScVbaAxis::setWidth( double width ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
636 oShapeHelper->setWidth( width );
638 double SAL_CALL ScVbaAxis::getTop( ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
640 return oShapeHelper->getTop( );
642 void SAL_CALL ScVbaAxis::setTop( double top ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
644 oShapeHelper->setTop( top );
646 double SAL_CALL ScVbaAxis::getLeft( ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
648 return oShapeHelper->getLeft( );
650 void SAL_CALL ScVbaAxis::setLeft( double left ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
652 oShapeHelper->setLeft( left );
655 rtl::OUString&
656 ScVbaAxis::getServiceImplName()
658 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaAxis") );
659 return sImplName;
662 uno::Sequence< rtl::OUString >
663 ScVbaAxis::getServiceNames()
665 static uno::Sequence< rtl::OUString > aServiceNames;
666 if ( aServiceNames.getLength() == 0 )
668 aServiceNames.realloc( 1 );
669 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Axis" ) );
671 return aServiceNames;