1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbaaxis.cxx,v $
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") );
48 ScVbaAxis::getChartPtr() throw( uno::RuntimeException
)
50 ScVbaChart
* pChart
= static_cast< ScVbaChart
* >( moChartParent
.get() );
52 throw uno::RuntimeException( rtl::OUString::createFromAscii("Can't access parent chart impl"), uno::Reference
< uno::XInterface
>() );
57 ScVbaAxis::isValueAxis() throw( script::BasicErrorException
)
59 if ( getType() == xlCategory
)
61 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
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
);
71 setCrosses(xlAxisCrossesAutomatic
);
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
;
87 ScVbaChart
* pChart
= getChartPtr();
91 int nType
= getType();
95 xAxisTitle
= new ScVbaAxisTitle(this, mxContext
, pChart
->xAxisXSupplier
->getXAxisTitle());
98 xAxisTitle
= new ScVbaAxisTitle(this, mxContext
, pChart
->xAxisZSupplier
->getZAxisTitle());
101 xAxisTitle
= new ScVbaAxisTitle(this, mxContext
, pChart
->xAxisYSupplier
->getYAxisTitle());
106 catch (uno::Exception
& e
)
108 DebugHelper::exception(e
);
115 ScVbaAxis::setDisplayUnit( ::sal_Int32
/*DisplayUnit*/ ) throw (script::BasicErrorException
, uno::RuntimeException
)
117 DebugHelper::exception(SbERR_NOT_IMPLEMENTED
, rtl::OUString());
121 ScVbaAxis::getDisplayUnit( ) throw (script::BasicErrorException
, uno::RuntimeException
)
123 DebugHelper::exception(SbERR_NOT_IMPLEMENTED
, rtl::OUString());
128 ScVbaAxis::setCrosses( ::sal_Int32 _nCrosses
) throw (script::BasicErrorException
, uno::RuntimeException
)
135 case xlAxisCrossesAutomatic
: //Microsoft Excel sets the axis crossing point.
136 mxPropertySet
->setPropertyValue(AUTOORIGIN
, uno::makeAny( sal_True
) );
137 bCrossesAreCustomized
= sal_False
;
139 case xlAxisCrossesMinimum
: // The axis crosses at the minimum value.
140 mxPropertySet
->getPropertyValue(VBA_MIN
) >>= fNum
;
141 setCrossesAt( fNum
);
142 bCrossesAreCustomized
= sal_False
;
144 case xlAxisCrossesMaximum
: // The axis crosses at the maximum value.
145 mxPropertySet
->getPropertyValue(VBA_MAX
) >>= fNum
;
147 bCrossesAreCustomized
= sal_False
;
149 default: //xlAxisCrossesCustom
150 bCrossesAreCustomized
= sal_True
;
153 mxPropertySet
->setPropertyValue(AUTOORIGIN
, uno::makeAny(sal_False
) );
155 catch (uno::Exception
& )
157 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
161 ScVbaAxis::getCrosses( ) throw (script::BasicErrorException
, uno::RuntimeException
)
163 sal_Int32 nCrosses
= xlAxisCrossesCustom
;
166 sal_Bool bisAutoOrigin
= sal_False
;
167 mxPropertySet
->getPropertyValue(AUTOORIGIN
) >>= bisAutoOrigin
;
169 nCrosses
= xlAxisCrossesAutomatic
;
172 if (bCrossesAreCustomized
)
173 nCrosses
= xlAxisCrossesCustom
;
176 double forigin
= 0.0;
177 mxPropertySet
->getPropertyValue(ORIGIN
) >>= forigin
;
178 //obsolete double fmax = AnyConverter.toDouble(mxPropertySet.getPropertyValue("Max"));
180 mxPropertySet
->getPropertyValue(VBA_MIN
) >>= fmin
;
182 nCrosses
= xlAxisCrossesMinimum
;
184 nCrosses
= xlAxisCrossesMaximum
;
188 catch (uno::Exception
& )
190 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString() );
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
));
206 catch (uno::Exception
& e
)
208 DebugHelper::exception(e
);
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());
228 ScVbaAxis::setType( ::sal_Int32 _nType
) throw (script::BasicErrorException
, uno::RuntimeException
)
234 ScVbaAxis::getType( ) throw (script::BasicErrorException
, uno::RuntimeException
)
240 ScVbaAxis::setHasTitle( ::sal_Bool _bHasTitle
) throw (script::BasicErrorException
, uno::RuntimeException
)
244 ScVbaChart
* pChart
= getChartPtr();
245 sal_Int32 nType
= getType();
249 pChart
->mxDiagramPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasXAxisTitle")), uno::makeAny(_bHasTitle
));
252 pChart
->mxDiagramPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasZAxisTitle")), uno::makeAny(_bHasTitle
));
255 pChart
->mxDiagramPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasYAxisTitle")), uno::makeAny(_bHasTitle
));
259 catch (uno::Exception
& e
)
261 DebugHelper::exception(e
);
266 ScVbaAxis::getHasTitle( ) throw (script::BasicErrorException
, uno::RuntimeException
)
268 sal_Bool bHasTitle
= sal_False
;
271 ScVbaChart
* pChart
= getChartPtr();
272 int nType
= getType();
276 pChart
->mxDiagramPropertySet
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasXAxisTitle")) ) >>= bHasTitle
;
279 pChart
->mxDiagramPropertySet
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasZAxisTitle")) ) >>= bHasTitle
;
282 pChart
->mxDiagramPropertySet
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasYAxisTitle")) ) >>= bHasTitle
;
285 catch (uno::Exception
& e
)
287 DebugHelper::exception(e
);
293 ScVbaAxis::setMinorUnit( double _fMinorUnit
) throw (script::BasicErrorException
, uno::RuntimeException
)
298 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StepHelp") ), uno::makeAny(_fMinorUnit
));
300 catch (uno::Exception
& )
302 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
307 ScVbaAxis::getMinorUnit( ) throw (script::BasicErrorException
, uno::RuntimeException
)
313 mxPropertySet
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StepHelp"))) >>= fMinor
;
315 catch (uno::Exception
& )
317 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
323 ScVbaAxis::setMinorUnitIsAuto( ::sal_Bool _bMinorUnitIsAuto
) throw (script::BasicErrorException
, uno::RuntimeException
)
328 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoStepHelp" ) ), uno::makeAny(_bMinorUnitIsAuto
));
330 catch (uno::Exception
& )
332 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString() );
337 ScVbaAxis::getMinorUnitIsAuto( ) throw (script::BasicErrorException
, uno::RuntimeException
)
339 sal_Bool bIsAuto
= sal_False
;
344 mxPropertySet
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoStepHelp")) ) >>= bIsAuto
;
347 catch (uno::Exception
& )
349 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
355 ScVbaAxis::setReversePlotOrder( ::sal_Bool
/*ReversePlotOrder*/ ) throw (script::BasicErrorException
, uno::RuntimeException
)
357 DebugHelper::exception(SbERR_NOT_IMPLEMENTED
, rtl::OUString());
361 ScVbaAxis::getReversePlotOrder( ) throw (script::BasicErrorException
, uno::RuntimeException
)
363 DebugHelper::exception(SbERR_NOT_IMPLEMENTED
, rtl::OUString());
368 ScVbaAxis::setMajorUnit( double _fMajorUnit
) throw (script::BasicErrorException
, uno::RuntimeException
)
374 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StepMain")), uno::makeAny(_fMajorUnit
));
377 catch (uno::Exception
& )
379 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
384 ScVbaAxis::getMajorUnit( ) throw (script::BasicErrorException
, uno::RuntimeException
)
390 mxPropertySet
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StepMain"))) >>= fMax
;
392 catch (uno::Exception
& )
394 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString() );
400 ScVbaAxis::setMajorUnitIsAuto( ::sal_Bool _bMajorUnitIsAuto
) throw (script::BasicErrorException
, uno::RuntimeException
)
406 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoStepMain" ) ), uno::makeAny( _bMajorUnitIsAuto
));
409 catch (uno::Exception
& )
411 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
416 ScVbaAxis::getMajorUnitIsAuto( ) throw (script::BasicErrorException
, uno::RuntimeException
)
418 sal_Bool bIsAuto
= sal_False
;
423 mxPropertySet
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoStepMain"))) >>= bIsAuto
;
426 catch (uno::Exception
& )
428 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
434 ScVbaAxis::setMaximumScale( double _fMaximumScale
) throw (script::BasicErrorException
, uno::RuntimeException
)
440 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Max" ) ), uno::makeAny(_fMaximumScale
));
443 catch ( uno::Exception
& )
445 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
450 ScVbaAxis::getMaximumScale( ) throw (script::BasicErrorException
, uno::RuntimeException
)
457 mxPropertySet
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Max" ))) >>= fMax
;
460 catch (uno::Exception
& )
462 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
469 ScVbaAxis::setMaximumScaleIsAuto( ::sal_Bool _bMaximumScaleIsAuto
) throw (script::BasicErrorException
, uno::RuntimeException
)
474 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoMax" ) ), uno::makeAny( _bMaximumScaleIsAuto
));
477 catch ( uno::Exception
& )
479 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
485 ScVbaAxis::getMaximumScaleIsAuto( ) throw (script::BasicErrorException
, uno::RuntimeException
)
487 sal_Bool bIsAuto
= sal_False
;
491 mxPropertySet
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoMax" )) ) >>= bIsAuto
;
493 catch ( uno::Exception
& )
495 DebugHelper::exception( SbERR_METHOD_FAILED
, rtl::OUString() );
501 ScVbaAxis::setMinimumScale( double _fMinimumScale
) throw (script::BasicErrorException
, uno::RuntimeException
)
506 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Min") ), uno::makeAny( _fMinimumScale
) );
508 catch ( uno::Exception
& )
510 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString() );
515 ScVbaAxis::getMinimumScale( ) throw (script::BasicErrorException
, uno::RuntimeException
)
521 mxPropertySet
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Min") )) >>= fMin
;
523 catch (uno::Exception
& e
)
525 DebugHelper::exception(e
);
531 ScVbaAxis::setMinimumScaleIsAuto( ::sal_Bool _bMinimumScaleIsAuto
) throw (script::BasicErrorException
, uno::RuntimeException
)
537 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoMin") ), uno::makeAny(_bMinimumScaleIsAuto
));
540 catch (uno::Exception
& )
542 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
547 ScVbaAxis::getMinimumScaleIsAuto( ) throw (script::BasicErrorException
, uno::RuntimeException
)
549 sal_Bool bIsAuto
= sal_False
;
554 mxPropertySet
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoMin")) ) >>= bIsAuto
;
557 catch (uno::Exception
& )
559 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
565 ScVbaAxis::getAxisGroup( ) throw (uno::RuntimeException
)
571 ScVbaAxis::setScaleType( ::sal_Int32 _nScaleType
) throw (script::BasicErrorException
, uno::RuntimeException
)
580 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Logarithmic" ) ), uno::makeAny( sal_False
) );
582 case xlScaleLogarithmic
:
583 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Logarithmic" ) ), uno::makeAny( sal_True
) );
586 // According to MS the paramenter is ignored and no Error is thrown
591 catch (uno::Exception
& )
593 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString() );
598 ScVbaAxis::getScaleType( ) throw (script::BasicErrorException
, uno::RuntimeException
)
600 sal_Int32 nScaleType
= xlScaleLinear
;
605 sal_Bool bisLogarithmic
= sal_False
;
606 mxPropertySet
->getPropertyValue( rtl::OUString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Logarithmic"))) ) >>= bisLogarithmic
;
608 nScaleType
= xlScaleLogarithmic
;
610 nScaleType
= xlScaleLinear
;
613 catch (uno::Exception
& )
615 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
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
);
656 ScVbaAxis::getServiceImplName()
658 static rtl::OUString
sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaAxis") );
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
;