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>
25 #include "vbaaxistitle.hxx"
26 #include "vbachart.hxx"
27 using namespace ::com::sun::star
;
28 using namespace ::ooo::vba
;
29 using namespace ::ooo::vba::excel::XlAxisCrosses
;
30 using namespace ::ooo::vba::excel::XlAxisType
;
31 using namespace ::ooo::vba::excel::XlScaleType
;
33 constexpr OUString
ORIGIN(u
"Origin"_ustr
);
34 constexpr OUString
AUTOORIGIN(u
"AutoOrigin"_ustr
);
35 constexpr OUString
VBA_MIN(u
"Max"_ustr
);
36 constexpr OUStringLiteral
VBA_MAX(u
"Min");
38 ScVbaAxis::getChartPtr()
40 ScVbaChart
* pChart
= moChartParent
.get();
42 throw uno::RuntimeException(u
"Can't access parent chart impl"_ustr
);
47 ScVbaAxis::isValueAxis()
49 if ( getType() == xlCategory
)
51 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
56 ScVbaAxis::ScVbaAxis( const rtl::Reference
< ScVbaChart
>& xParent
,
57 const uno::Reference
< uno::XComponentContext
> & xContext
,
58 uno::Reference
< beans::XPropertySet
> _xPropertySet
,
59 sal_Int32 _nType
, sal_Int32 _nGroup
)
60 : ScVbaAxis_BASE( xParent
, xContext
),
61 moChartParent(xParent
),
62 mxPropertySet(std::move( _xPropertySet
)),
63 mnType( _nType
), mnGroup( _nGroup
),
64 maShapeHelper( uno::Reference
< drawing::XShape
>( mxPropertySet
, uno::UNO_QUERY
) ),
65 bCrossesAreCustomized( false )
68 setCrosses(xlAxisCrossesAutomatic
);
74 uno::Reference
< lang::XComponent
> xComponent( mxPropertySet
, uno::UNO_QUERY_THROW
);
75 xComponent
->dispose();
78 uno::Reference
< ::ooo::vba::excel::XAxisTitle
> SAL_CALL
79 ScVbaAxis::getAxisTitle( )
81 uno::Reference
< excel::XAxisTitle
> xAxisTitle
;
84 ScVbaChart
* pChart
= getChartPtr();
88 int nType
= getType();
92 xAxisTitle
= new ScVbaAxisTitle(this, mxContext
, pChart
->xAxisXSupplier
->getXAxisTitle());
95 xAxisTitle
= new ScVbaAxisTitle(this, mxContext
, pChart
->xAxisZSupplier
->getZAxisTitle());
98 xAxisTitle
= new ScVbaAxisTitle(this, mxContext
, pChart
->xAxisYSupplier
->getYAxisTitle());
103 catch (const uno::Exception
& e
)
105 DebugHelper::basicexception(e
);
112 ScVbaAxis::setDisplayUnit( ::sal_Int32
/*DisplayUnit*/ )
114 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED
, {});
118 ScVbaAxis::getDisplayUnit( )
120 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED
, {});
125 ScVbaAxis::setCrosses( ::sal_Int32 _nCrosses
)
132 case xlAxisCrossesAutomatic
: //Microsoft Excel sets the axis crossing point.
133 mxPropertySet
->setPropertyValue(AUTOORIGIN
, uno::Any( true ) );
134 bCrossesAreCustomized
= false;
136 case xlAxisCrossesMinimum
: // The axis crosses at the minimum value.
137 mxPropertySet
->getPropertyValue(VBA_MIN
) >>= fNum
;
138 setCrossesAt( fNum
);
139 bCrossesAreCustomized
= false;
141 case xlAxisCrossesMaximum
: // The axis crosses at the maximum value.
142 mxPropertySet
->getPropertyValue(VBA_MAX
) >>= fNum
;
144 bCrossesAreCustomized
= false;
146 default: //xlAxisCrossesCustom
147 bCrossesAreCustomized
= true;
150 mxPropertySet
->setPropertyValue(AUTOORIGIN
, uno::Any(false) );
152 catch (const uno::Exception
&)
154 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
158 ScVbaAxis::getCrosses( )
160 sal_Int32 nCrosses
= xlAxisCrossesCustom
;
163 bool bisAutoOrigin
= false;
164 mxPropertySet
->getPropertyValue(AUTOORIGIN
) >>= bisAutoOrigin
;
166 nCrosses
= xlAxisCrossesAutomatic
;
169 if (bCrossesAreCustomized
)
170 nCrosses
= xlAxisCrossesCustom
;
173 double forigin
= 0.0;
174 mxPropertySet
->getPropertyValue(ORIGIN
) >>= forigin
;
176 mxPropertySet
->getPropertyValue(VBA_MIN
) >>= fmin
;
178 nCrosses
= xlAxisCrossesMinimum
;
180 nCrosses
= xlAxisCrossesMaximum
;
184 catch (uno::Exception
& )
186 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {} );
192 ScVbaAxis::setCrossesAt( double _fCrossesAt
)
196 setMaximumScaleIsAuto( false );
197 setMinimumScaleIsAuto( false );
198 mxPropertySet
->setPropertyValue(ORIGIN
, uno::Any(_fCrossesAt
));
200 catch (const uno::Exception
& e
)
202 DebugHelper::basicexception(e
);
207 ScVbaAxis::getCrossesAt( )
209 double fCrosses
= 0.0;
212 mxPropertySet
->getPropertyValue(ORIGIN
) >>= fCrosses
;
214 catch (uno::Exception
& )
216 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
222 ScVbaAxis::setType( ::sal_Int32 _nType
)
228 ScVbaAxis::getType( )
234 ScVbaAxis::setHasTitle( sal_Bool _bHasTitle
)
238 ScVbaChart
* pChart
= getChartPtr();
239 sal_Int32 nType
= getType();
243 pChart
->mxDiagramPropertySet
->setPropertyValue(u
"HasXAxisTitle"_ustr
, uno::Any(_bHasTitle
));
246 pChart
->mxDiagramPropertySet
->setPropertyValue(u
"HasZAxisTitle"_ustr
, uno::Any(_bHasTitle
));
249 pChart
->mxDiagramPropertySet
->setPropertyValue(u
"HasYAxisTitle"_ustr
, uno::Any(_bHasTitle
));
253 catch (const uno::Exception
& e
)
255 DebugHelper::basicexception(e
);
260 ScVbaAxis::getHasTitle( )
262 bool bHasTitle
= false;
265 ScVbaChart
* pChart
= getChartPtr();
266 int nType
= getType();
270 pChart
->mxDiagramPropertySet
->getPropertyValue(u
"HasXAxisTitle"_ustr
) >>= bHasTitle
;
273 pChart
->mxDiagramPropertySet
->getPropertyValue(u
"HasZAxisTitle"_ustr
) >>= bHasTitle
;
276 pChart
->mxDiagramPropertySet
->getPropertyValue(u
"HasYAxisTitle"_ustr
) >>= bHasTitle
;
279 catch (const uno::Exception
& e
)
281 DebugHelper::basicexception(e
);
287 ScVbaAxis::setMinorUnit( double _fMinorUnit
)
292 mxPropertySet
->setPropertyValue(u
"StepHelp"_ustr
, uno::Any(_fMinorUnit
));
294 catch (uno::Exception
& )
296 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
301 ScVbaAxis::getMinorUnit( )
307 mxPropertySet
->getPropertyValue(u
"StepHelp"_ustr
) >>= fMinor
;
309 catch (uno::Exception
& )
311 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
317 ScVbaAxis::setMinorUnitIsAuto( sal_Bool _bMinorUnitIsAuto
)
322 mxPropertySet
->setPropertyValue(u
"AutoStepHelp"_ustr
, uno::Any(_bMinorUnitIsAuto
));
324 catch (uno::Exception
& )
326 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {} );
331 ScVbaAxis::getMinorUnitIsAuto( )
333 bool bIsAuto
= false;
338 mxPropertySet
->getPropertyValue(u
"AutoStepHelp"_ustr
) >>= bIsAuto
;
341 catch (const uno::Exception
&)
343 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
349 ScVbaAxis::setReversePlotOrder( sal_Bool
/*ReversePlotOrder*/ )
351 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED
, {});
355 ScVbaAxis::getReversePlotOrder( )
357 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED
, {});
362 ScVbaAxis::setMajorUnit( double _fMajorUnit
)
368 mxPropertySet
->setPropertyValue(u
"StepMain"_ustr
, uno::Any(_fMajorUnit
));
371 catch (const uno::Exception
&)
373 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
378 ScVbaAxis::getMajorUnit( )
384 mxPropertySet
->getPropertyValue(u
"StepMain"_ustr
) >>= fMax
;
386 catch (const uno::Exception
&)
388 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {} );
394 ScVbaAxis::setMajorUnitIsAuto( sal_Bool _bMajorUnitIsAuto
)
400 mxPropertySet
->setPropertyValue(u
"AutoStepMain"_ustr
, uno::Any( _bMajorUnitIsAuto
));
403 catch (const uno::Exception
&)
405 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
410 ScVbaAxis::getMajorUnitIsAuto( )
412 bool bIsAuto
= false;
417 mxPropertySet
->getPropertyValue(u
"AutoStepMain"_ustr
) >>= bIsAuto
;
420 catch (const uno::Exception
&)
422 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
428 ScVbaAxis::setMaximumScale( double _fMaximumScale
)
434 mxPropertySet
->setPropertyValue(u
"Max"_ustr
, uno::Any(_fMaximumScale
));
437 catch (const uno::Exception
&)
439 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
444 ScVbaAxis::getMaximumScale( )
451 mxPropertySet
->getPropertyValue(u
"Max"_ustr
) >>= fMax
;
454 catch (const uno::Exception
&)
456 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
463 ScVbaAxis::setMaximumScaleIsAuto( sal_Bool _bMaximumScaleIsAuto
)
468 mxPropertySet
->setPropertyValue(u
"AutoMax"_ustr
, uno::Any( _bMaximumScaleIsAuto
));
471 catch (const uno::Exception
&)
473 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
478 ScVbaAxis::getMaximumScaleIsAuto( )
480 bool bIsAuto
= false;
484 mxPropertySet
->getPropertyValue(u
"AutoMax"_ustr
) >>= bIsAuto
;
486 catch (const uno::Exception
&)
488 DebugHelper::basicexception( ERRCODE_BASIC_METHOD_FAILED
, {} );
494 ScVbaAxis::setMinimumScale( double _fMinimumScale
)
499 mxPropertySet
->setPropertyValue(u
"Min"_ustr
, uno::Any( _fMinimumScale
) );
501 catch ( uno::Exception
& )
503 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {} );
508 ScVbaAxis::getMinimumScale( )
514 mxPropertySet
->getPropertyValue(u
"Min"_ustr
) >>= fMin
;
516 catch (const uno::Exception
& e
)
518 DebugHelper::basicexception(e
);
524 ScVbaAxis::setMinimumScaleIsAuto( sal_Bool _bMinimumScaleIsAuto
)
530 mxPropertySet
->setPropertyValue(u
"AutoMin"_ustr
, uno::Any(_bMinimumScaleIsAuto
));
533 catch (const uno::Exception
&)
535 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
540 ScVbaAxis::getMinimumScaleIsAuto( )
542 bool bIsAuto
= false;
547 mxPropertySet
->getPropertyValue(u
"AutoMin"_ustr
) >>= bIsAuto
;
550 catch (const uno::Exception
&)
552 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
558 ScVbaAxis::getAxisGroup( )
564 ScVbaAxis::setScaleType( ::sal_Int32 _nScaleType
)
573 mxPropertySet
->setPropertyValue(u
"Logarithmic"_ustr
, uno::Any( false ) );
575 case xlScaleLogarithmic
:
576 mxPropertySet
->setPropertyValue(u
"Logarithmic"_ustr
, uno::Any( true ) );
579 // According to MS the parameter is ignored and no Error is thrown
584 catch (const uno::Exception
&)
586 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
591 ScVbaAxis::getScaleType( )
593 sal_Int32 nScaleType
= xlScaleLinear
;
598 bool bisLogarithmic
= false;
599 mxPropertySet
->getPropertyValue( u
"Logarithmic"_ustr
) >>= bisLogarithmic
;
601 nScaleType
= xlScaleLogarithmic
;
603 nScaleType
= xlScaleLinear
;
606 catch (const uno::Exception
&)
608 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
614 ScVbaAxis::getHeight( )
616 return maShapeHelper
.getHeight();
619 void SAL_CALL
ScVbaAxis::setHeight( double height
)
621 maShapeHelper
.setHeight( height
);
623 double SAL_CALL
ScVbaAxis::getWidth( )
625 return maShapeHelper
.getWidth( );
627 void SAL_CALL
ScVbaAxis::setWidth( double width
)
629 maShapeHelper
.setWidth( width
);
631 double SAL_CALL
ScVbaAxis::getTop( )
633 return maShapeHelper
.getTop( );
635 void SAL_CALL
ScVbaAxis::setTop( double top
)
637 maShapeHelper
.setTop( top
);
639 double SAL_CALL
ScVbaAxis::getLeft( )
641 return maShapeHelper
.getLeft( );
643 void SAL_CALL
ScVbaAxis::setLeft( double left
)
645 maShapeHelper
.setLeft( left
);
649 ScVbaAxis::getServiceImplName()
651 return u
"ScVbaAxis"_ustr
;
654 uno::Sequence
< OUString
>
655 ScVbaAxis::getServiceNames()
657 static uno::Sequence
< OUString
> const aServiceNames
659 u
"ooo.vba.excel.Axis"_ustr
661 return aServiceNames
;
664 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */