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()
39 ScVbaChart
* pChart
= static_cast< ScVbaChart
* >( moChartParent
.get() );
41 throw uno::RuntimeException("Can't access parent chart impl" );
46 ScVbaAxis::isValueAxis()
48 if ( getType() == xlCategory
)
50 DebugHelper::basicexception(ERRCODE_BASIC_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
);
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( )
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*/ )
106 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED
, OUString());
110 ScVbaAxis::getDisplayUnit( )
112 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED
, OUString());
117 ScVbaAxis::setCrosses( ::sal_Int32 _nCrosses
)
124 case xlAxisCrossesAutomatic
: //Microsoft Excel sets the axis crossing point.
125 mxPropertySet
->setPropertyValue(AUTOORIGIN
, uno::makeAny( 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(ERRCODE_BASIC_METHOD_FAILED
, OUString());
150 ScVbaAxis::getCrosses( )
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(ERRCODE_BASIC_METHOD_FAILED
, OUString() );
184 ScVbaAxis::setCrossesAt( double _fCrossesAt
)
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( )
201 double fCrosses
= 0.0;
204 mxPropertySet
->getPropertyValue(ORIGIN
) >>= fCrosses
;
206 catch (uno::Exception
& )
208 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, OUString());
214 ScVbaAxis::setType( ::sal_Int32 _nType
)
220 ScVbaAxis::getType( )
226 ScVbaAxis::setHasTitle( sal_Bool _bHasTitle
)
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( )
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
)
284 mxPropertySet
->setPropertyValue("StepHelp", uno::makeAny(_fMinorUnit
));
286 catch (uno::Exception
& )
288 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, OUString());
293 ScVbaAxis::getMinorUnit( )
299 mxPropertySet
->getPropertyValue("StepHelp") >>= fMinor
;
301 catch (uno::Exception
& )
303 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, OUString());
309 ScVbaAxis::setMinorUnitIsAuto( sal_Bool _bMinorUnitIsAuto
)
314 mxPropertySet
->setPropertyValue("AutoStepHelp", uno::makeAny(_bMinorUnitIsAuto
));
316 catch (uno::Exception
& )
318 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, OUString() );
323 ScVbaAxis::getMinorUnitIsAuto( )
325 bool bIsAuto
= false;
330 mxPropertySet
->getPropertyValue("AutoStepHelp") >>= bIsAuto
;
333 catch (const uno::Exception
&)
335 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, OUString());
341 ScVbaAxis::setReversePlotOrder( sal_Bool
/*ReversePlotOrder*/ )
343 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED
, OUString());
347 ScVbaAxis::getReversePlotOrder( )
349 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED
, OUString());
354 ScVbaAxis::setMajorUnit( double _fMajorUnit
)
360 mxPropertySet
->setPropertyValue("StepMain", uno::makeAny(_fMajorUnit
));
363 catch (const uno::Exception
&)
365 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, OUString());
370 ScVbaAxis::getMajorUnit( )
376 mxPropertySet
->getPropertyValue("StepMain") >>= fMax
;
378 catch (const uno::Exception
&)
380 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, OUString() );
386 ScVbaAxis::setMajorUnitIsAuto( sal_Bool _bMajorUnitIsAuto
)
392 mxPropertySet
->setPropertyValue("AutoStepMain", uno::makeAny( _bMajorUnitIsAuto
));
395 catch (const uno::Exception
&)
397 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, OUString());
402 ScVbaAxis::getMajorUnitIsAuto( )
404 bool bIsAuto
= false;
409 mxPropertySet
->getPropertyValue("AutoStepMain") >>= bIsAuto
;
412 catch (const uno::Exception
&)
414 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, OUString());
420 ScVbaAxis::setMaximumScale( double _fMaximumScale
)
426 mxPropertySet
->setPropertyValue("Max", uno::makeAny(_fMaximumScale
));
429 catch (const uno::Exception
&)
431 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, OUString());
436 ScVbaAxis::getMaximumScale( )
443 mxPropertySet
->getPropertyValue("Max") >>= fMax
;
446 catch (const uno::Exception
&)
448 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, OUString());
455 ScVbaAxis::setMaximumScaleIsAuto( sal_Bool _bMaximumScaleIsAuto
)
460 mxPropertySet
->setPropertyValue("AutoMax", uno::makeAny( _bMaximumScaleIsAuto
));
463 catch (const uno::Exception
&)
465 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, OUString());
470 ScVbaAxis::getMaximumScaleIsAuto( )
472 bool bIsAuto
= false;
476 mxPropertySet
->getPropertyValue("AutoMax") >>= bIsAuto
;
478 catch (const uno::Exception
&)
480 DebugHelper::basicexception( ERRCODE_BASIC_METHOD_FAILED
, OUString() );
486 ScVbaAxis::setMinimumScale( double _fMinimumScale
)
491 mxPropertySet
->setPropertyValue("Min", uno::makeAny( _fMinimumScale
) );
493 catch ( uno::Exception
& )
495 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, OUString() );
500 ScVbaAxis::getMinimumScale( )
506 mxPropertySet
->getPropertyValue("Min") >>= fMin
;
508 catch (const uno::Exception
& e
)
510 DebugHelper::basicexception(e
);
516 ScVbaAxis::setMinimumScaleIsAuto( sal_Bool _bMinimumScaleIsAuto
)
522 mxPropertySet
->setPropertyValue("AutoMin", uno::makeAny(_bMinimumScaleIsAuto
));
525 catch (const uno::Exception
&)
527 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, OUString());
532 ScVbaAxis::getMinimumScaleIsAuto( )
534 bool bIsAuto
= false;
539 mxPropertySet
->getPropertyValue("AutoMin") >>= bIsAuto
;
542 catch (const uno::Exception
&)
544 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, OUString());
550 ScVbaAxis::getAxisGroup( )
556 ScVbaAxis::setScaleType( ::sal_Int32 _nScaleType
)
565 mxPropertySet
->setPropertyValue("Logarithmic", uno::makeAny( false ) );
567 case xlScaleLogarithmic
:
568 mxPropertySet
->setPropertyValue("Logarithmic", uno::makeAny( true ) );
571 // According to MS the parameter is ignored and no Error is thrown
576 catch (const uno::Exception
&)
578 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, OUString());
583 ScVbaAxis::getScaleType( )
585 sal_Int32 nScaleType
= xlScaleLinear
;
590 bool bisLogarithmic
= false;
591 mxPropertySet
->getPropertyValue( "Logarithmic" ) >>= bisLogarithmic
;
593 nScaleType
= xlScaleLogarithmic
;
595 nScaleType
= xlScaleLinear
;
598 catch (const uno::Exception
&)
600 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, OUString());
606 ScVbaAxis::getHeight( )
608 return oShapeHelper
->getHeight();
611 void SAL_CALL
ScVbaAxis::setHeight( double height
)
613 oShapeHelper
->setHeight( height
);
615 double SAL_CALL
ScVbaAxis::getWidth( )
617 return oShapeHelper
->getWidth( );
619 void SAL_CALL
ScVbaAxis::setWidth( double width
)
621 oShapeHelper
->setWidth( width
);
623 double SAL_CALL
ScVbaAxis::getTop( )
625 return oShapeHelper
->getTop( );
627 void SAL_CALL
ScVbaAxis::setTop( double top
)
629 oShapeHelper
->setTop( top
);
631 double SAL_CALL
ScVbaAxis::getLeft( )
633 return oShapeHelper
->getLeft( );
635 void SAL_CALL
ScVbaAxis::setLeft( double left
)
637 oShapeHelper
->setLeft( left
);
641 ScVbaAxis::getServiceImplName()
646 uno::Sequence
< OUString
>
647 ScVbaAxis::getServiceNames()
649 static uno::Sequence
< OUString
> const aServiceNames
653 return aServiceNames
;
656 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */