1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "vbaaxis.hxx"
21 #include <ooo/vba/excel/XlAxisCrosses.hpp>
22 #include <ooo/vba/excel/XlAxisType.hpp>
23 #include <ooo/vba/excel/XlScaleType.hpp>
24 #include "vbaaxistitle.hxx"
25 #include "vbachart.hxx"
26 using namespace ::com::sun::star
;
27 using namespace ::ooo::vba
;
28 using namespace ::ooo::vba::excel::XlAxisCrosses
;
29 using namespace ::ooo::vba::excel::XlAxisType
;
30 using namespace ::ooo::vba::excel::XlScaleType
;
32 const OUString
ORIGIN("Origin");
33 const OUString
AUTOORIGIN("AutoOrigin");
34 const OUString
VBA_MIN("Max");
35 const OUString
VBA_MAX("Min");
37 ScVbaAxis::getChartPtr() throw( uno::RuntimeException
)
39 ScVbaChart
* pChart
= static_cast< ScVbaChart
* >( moChartParent
.get() );
41 throw uno::RuntimeException("Can't access parent chart impl" );
46 ScVbaAxis::isValueAxis() throw( script::BasicErrorException
)
48 if ( getType() == xlCategory
)
50 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
55 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( false )
57 oShapeHelper
.reset( new ShapeHelper( uno::Reference
< drawing::XShape
>( mxPropertySet
, uno::UNO_QUERY
) ) );
58 moChartParent
.set( xParent
, uno::UNO_QUERY_THROW
);
60 setCrosses(xlAxisCrossesAutomatic
);
64 ScVbaAxis::Delete( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
66 uno::Reference
< lang::XComponent
> xComponent( mxPropertySet
, uno::UNO_QUERY_THROW
);
67 xComponent
->dispose();
70 uno::Reference
< ::ooo::vba::excel::XAxisTitle
> SAL_CALL
71 ScVbaAxis::getAxisTitle( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
73 uno::Reference
< excel::XAxisTitle
> xAxisTitle
;
76 ScVbaChart
* pChart
= getChartPtr();
80 int nType
= getType();
84 xAxisTitle
= new ScVbaAxisTitle(this, mxContext
, pChart
->xAxisXSupplier
->getXAxisTitle());
87 xAxisTitle
= new ScVbaAxisTitle(this, mxContext
, pChart
->xAxisZSupplier
->getZAxisTitle());
90 xAxisTitle
= new ScVbaAxisTitle(this, mxContext
, pChart
->xAxisYSupplier
->getYAxisTitle());
95 catch (const uno::Exception
& e
)
97 DebugHelper::basicexception(e
);
104 ScVbaAxis::setDisplayUnit( ::sal_Int32
/*DisplayUnit*/ ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
106 DebugHelper::basicexception(SbERR_NOT_IMPLEMENTED
, OUString());
110 ScVbaAxis::getDisplayUnit( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
112 DebugHelper::basicexception(SbERR_NOT_IMPLEMENTED
, OUString());
117 ScVbaAxis::setCrosses( ::sal_Int32 _nCrosses
) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
124 case xlAxisCrossesAutomatic
: //Microsoft Excel sets the axis crossing point.
125 mxPropertySet
->setPropertyValue(AUTOORIGIN
, uno::makeAny( sal_True
) );
126 bCrossesAreCustomized
= false;
128 case xlAxisCrossesMinimum
: // The axis crosses at the minimum value.
129 mxPropertySet
->getPropertyValue(VBA_MIN
) >>= fNum
;
130 setCrossesAt( fNum
);
131 bCrossesAreCustomized
= false;
133 case xlAxisCrossesMaximum
: // The axis crosses at the maximum value.
134 mxPropertySet
->getPropertyValue(VBA_MAX
) >>= fNum
;
136 bCrossesAreCustomized
= false;
138 default: //xlAxisCrossesCustom
139 bCrossesAreCustomized
= true;
142 mxPropertySet
->setPropertyValue(AUTOORIGIN
, uno::makeAny(false) );
144 catch (const uno::Exception
&)
146 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
150 ScVbaAxis::getCrosses( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
152 sal_Int32 nCrosses
= xlAxisCrossesCustom
;
155 bool bisAutoOrigin
= false;
156 mxPropertySet
->getPropertyValue(AUTOORIGIN
) >>= bisAutoOrigin
;
158 nCrosses
= xlAxisCrossesAutomatic
;
161 if (bCrossesAreCustomized
)
162 nCrosses
= xlAxisCrossesCustom
;
165 double forigin
= 0.0;
166 mxPropertySet
->getPropertyValue(ORIGIN
) >>= forigin
;
168 mxPropertySet
->getPropertyValue(VBA_MIN
) >>= fmin
;
170 nCrosses
= xlAxisCrossesMinimum
;
172 nCrosses
= xlAxisCrossesMaximum
;
176 catch (uno::Exception
& )
178 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
184 ScVbaAxis::setCrossesAt( double _fCrossesAt
) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
188 setMaximumScaleIsAuto( false );
189 setMinimumScaleIsAuto( false );
190 mxPropertySet
->setPropertyValue(ORIGIN
, uno::makeAny(_fCrossesAt
));
192 catch (const uno::Exception
& e
)
194 DebugHelper::basicexception(e
);
199 ScVbaAxis::getCrossesAt( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
201 double fCrosses
= 0.0;
204 mxPropertySet
->getPropertyValue(ORIGIN
) >>= fCrosses
;
206 catch (uno::Exception
& )
208 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
214 ScVbaAxis::setType( ::sal_Int32 _nType
) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
220 ScVbaAxis::getType( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
226 ScVbaAxis::setHasTitle( sal_Bool _bHasTitle
) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
230 ScVbaChart
* pChart
= getChartPtr();
231 sal_Int32 nType
= getType();
235 pChart
->mxDiagramPropertySet
->setPropertyValue("HasXAxisTitle", uno::makeAny(_bHasTitle
));
238 pChart
->mxDiagramPropertySet
->setPropertyValue("HasZAxisTitle", uno::makeAny(_bHasTitle
));
241 pChart
->mxDiagramPropertySet
->setPropertyValue("HasYAxisTitle", uno::makeAny(_bHasTitle
));
245 catch (const uno::Exception
& e
)
247 DebugHelper::basicexception(e
);
252 ScVbaAxis::getHasTitle( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
254 bool bHasTitle
= false;
257 ScVbaChart
* pChart
= getChartPtr();
258 int nType
= getType();
262 pChart
->mxDiagramPropertySet
->getPropertyValue("HasXAxisTitle") >>= bHasTitle
;
265 pChart
->mxDiagramPropertySet
->getPropertyValue("HasZAxisTitle") >>= bHasTitle
;
268 pChart
->mxDiagramPropertySet
->getPropertyValue("HasYAxisTitle") >>= bHasTitle
;
271 catch (const uno::Exception
& e
)
273 DebugHelper::basicexception(e
);
279 ScVbaAxis::setMinorUnit( double _fMinorUnit
) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
284 mxPropertySet
->setPropertyValue("StepHelp", uno::makeAny(_fMinorUnit
));
286 catch (uno::Exception
& )
288 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
293 ScVbaAxis::getMinorUnit( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
299 mxPropertySet
->getPropertyValue("StepHelp") >>= fMinor
;
301 catch (uno::Exception
& )
303 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
309 ScVbaAxis::setMinorUnitIsAuto( sal_Bool _bMinorUnitIsAuto
) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
314 mxPropertySet
->setPropertyValue("AutoStepHelp", uno::makeAny(_bMinorUnitIsAuto
));
316 catch (uno::Exception
& )
318 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
323 ScVbaAxis::getMinorUnitIsAuto( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
325 bool bIsAuto
= false;
330 mxPropertySet
->getPropertyValue("AutoStepHelp") >>= bIsAuto
;
333 catch (const uno::Exception
&)
335 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
341 ScVbaAxis::setReversePlotOrder( sal_Bool
/*ReversePlotOrder*/ ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
343 DebugHelper::basicexception(SbERR_NOT_IMPLEMENTED
, OUString());
347 ScVbaAxis::getReversePlotOrder( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
349 DebugHelper::basicexception(SbERR_NOT_IMPLEMENTED
, OUString());
354 ScVbaAxis::setMajorUnit( double _fMajorUnit
) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
360 mxPropertySet
->setPropertyValue("StepMain", uno::makeAny(_fMajorUnit
));
363 catch (const uno::Exception
&)
365 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
370 ScVbaAxis::getMajorUnit( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
376 mxPropertySet
->getPropertyValue("StepMain") >>= fMax
;
378 catch (const uno::Exception
&)
380 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
386 ScVbaAxis::setMajorUnitIsAuto( sal_Bool _bMajorUnitIsAuto
) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
392 mxPropertySet
->setPropertyValue("AutoStepMain", uno::makeAny( _bMajorUnitIsAuto
));
395 catch (const uno::Exception
&)
397 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
402 ScVbaAxis::getMajorUnitIsAuto( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
404 bool bIsAuto
= false;
409 mxPropertySet
->getPropertyValue("AutoStepMain") >>= bIsAuto
;
412 catch (const uno::Exception
&)
414 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
420 ScVbaAxis::setMaximumScale( double _fMaximumScale
) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
426 mxPropertySet
->setPropertyValue("Max", uno::makeAny(_fMaximumScale
));
429 catch (const uno::Exception
&)
431 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
436 ScVbaAxis::getMaximumScale( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
443 mxPropertySet
->getPropertyValue("Max") >>= fMax
;
446 catch (const uno::Exception
&)
448 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
455 ScVbaAxis::setMaximumScaleIsAuto( sal_Bool _bMaximumScaleIsAuto
) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
460 mxPropertySet
->setPropertyValue("AutoMax", uno::makeAny( _bMaximumScaleIsAuto
));
463 catch (const uno::Exception
&)
465 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
470 ScVbaAxis::getMaximumScaleIsAuto( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
472 bool bIsAuto
= false;
476 mxPropertySet
->getPropertyValue("AutoMax") >>= bIsAuto
;
478 catch (const uno::Exception
&)
480 DebugHelper::basicexception( SbERR_METHOD_FAILED
, OUString() );
486 ScVbaAxis::setMinimumScale( double _fMinimumScale
) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
491 mxPropertySet
->setPropertyValue("Min", uno::makeAny( _fMinimumScale
) );
493 catch ( uno::Exception
& )
495 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
500 ScVbaAxis::getMinimumScale( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
506 mxPropertySet
->getPropertyValue("Min") >>= fMin
;
508 catch (const uno::Exception
& e
)
510 DebugHelper::basicexception(e
);
516 ScVbaAxis::setMinimumScaleIsAuto( sal_Bool _bMinimumScaleIsAuto
) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
522 mxPropertySet
->setPropertyValue("AutoMin", uno::makeAny(_bMinimumScaleIsAuto
));
525 catch (const uno::Exception
&)
527 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
532 ScVbaAxis::getMinimumScaleIsAuto( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
534 bool bIsAuto
= false;
539 mxPropertySet
->getPropertyValue("AutoMin") >>= bIsAuto
;
542 catch (const uno::Exception
&)
544 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
550 ScVbaAxis::getAxisGroup( ) throw (uno::RuntimeException
, std::exception
)
556 ScVbaAxis::setScaleType( ::sal_Int32 _nScaleType
) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
565 mxPropertySet
->setPropertyValue("Logarithmic", uno::makeAny( sal_False
) );
567 case xlScaleLogarithmic
:
568 mxPropertySet
->setPropertyValue("Logarithmic", uno::makeAny( sal_True
) );
571 // According to MS the paramenter is ignored and no Error is thrown
576 catch (const uno::Exception
&)
578 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
583 ScVbaAxis::getScaleType( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
585 sal_Int32 nScaleType
= xlScaleLinear
;
590 bool bisLogarithmic
= false;
591 mxPropertySet
->getPropertyValue( OUString( OUString("Logarithmic")) ) >>= bisLogarithmic
;
593 nScaleType
= xlScaleLogarithmic
;
595 nScaleType
= xlScaleLinear
;
598 catch (const uno::Exception
&)
600 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
606 ScVbaAxis::getHeight( ) throw (css::script::BasicErrorException
, css::uno::RuntimeException
, std::exception
)
608 return oShapeHelper
->getHeight();
611 void SAL_CALL
ScVbaAxis::setHeight( double height
) throw (css::script::BasicErrorException
, css::uno::RuntimeException
, std::exception
)
613 oShapeHelper
->setHeight( height
);
615 double SAL_CALL
ScVbaAxis::getWidth( ) throw (css::script::BasicErrorException
, css::uno::RuntimeException
, std::exception
)
617 return oShapeHelper
->getWidth( );
619 void SAL_CALL
ScVbaAxis::setWidth( double width
) throw (css::script::BasicErrorException
, css::uno::RuntimeException
, std::exception
)
621 oShapeHelper
->setWidth( width
);
623 double SAL_CALL
ScVbaAxis::getTop( ) throw (css::script::BasicErrorException
, css::uno::RuntimeException
, std::exception
)
625 return oShapeHelper
->getTop( );
627 void SAL_CALL
ScVbaAxis::setTop( double top
) throw (css::script::BasicErrorException
, css::uno::RuntimeException
, std::exception
)
629 oShapeHelper
->setTop( top
);
631 double SAL_CALL
ScVbaAxis::getLeft( ) throw (css::script::BasicErrorException
, css::uno::RuntimeException
, std::exception
)
633 return oShapeHelper
->getLeft( );
635 void SAL_CALL
ScVbaAxis::setLeft( double left
) throw (css::script::BasicErrorException
, css::uno::RuntimeException
, std::exception
)
637 oShapeHelper
->setLeft( left
);
641 ScVbaAxis::getServiceImplName()
643 return OUString("ScVbaAxis");
646 uno::Sequence
< OUString
>
647 ScVbaAxis::getServiceNames()
649 static uno::Sequence
< OUString
> aServiceNames
;
650 if ( aServiceNames
.getLength() == 0 )
652 aServiceNames
.realloc( 1 );
653 aServiceNames
[ 0 ] = "ooo.vba.excel.Axis";
655 return aServiceNames
;
658 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */