GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / sc / source / ui / vba / vbaaxis.cxx
blob67b39bc802e810e99233c569d38f813a13e0304e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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");
36 ScVbaChart*
37 ScVbaAxis::getChartPtr() throw( uno::RuntimeException )
39 ScVbaChart* pChart = static_cast< ScVbaChart* >( moChartParent.get() );
40 if ( !pChart )
41 throw uno::RuntimeException("Can't access parent chart impl", uno::Reference< uno::XInterface >() );
42 return pChart;
45 sal_Bool
46 ScVbaAxis::isValueAxis() throw( script::BasicErrorException )
48 if ( getType() == xlCategory )
50 DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
52 return sal_True;
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 );
59 setType(_nType);
60 setCrosses(xlAxisCrossesAutomatic);
63 void SAL_CALL
64 ScVbaAxis::Delete( ) throw (script::BasicErrorException, uno::RuntimeException)
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)
73 uno::Reference< excel::XAxisTitle > xAxisTitle;
74 try
76 ScVbaChart* pChart = getChartPtr();
78 if (getHasTitle() )
80 int nType = getType();
81 switch(nType)
83 case xlCategory:
84 xAxisTitle = new ScVbaAxisTitle(this, mxContext, pChart->xAxisXSupplier->getXAxisTitle());
85 break;
86 case xlSeriesAxis:
87 xAxisTitle = new ScVbaAxisTitle(this, mxContext, pChart->xAxisZSupplier->getZAxisTitle());
88 break;
89 default: // xlValue:
90 xAxisTitle = new ScVbaAxisTitle(this, mxContext, pChart->xAxisYSupplier->getYAxisTitle());
91 break;
95 catch (const uno::Exception& e)
97 DebugHelper::exception(e);
99 return xAxisTitle;
103 void SAL_CALL
104 ScVbaAxis::setDisplayUnit( ::sal_Int32 /*DisplayUnit*/ ) throw (script::BasicErrorException, uno::RuntimeException)
106 DebugHelper::exception(SbERR_NOT_IMPLEMENTED, OUString());
109 ::sal_Int32 SAL_CALL
110 ScVbaAxis::getDisplayUnit( ) throw (script::BasicErrorException, uno::RuntimeException)
112 DebugHelper::exception(SbERR_NOT_IMPLEMENTED, OUString());
113 return -1;
116 void SAL_CALL
117 ScVbaAxis::setCrosses( ::sal_Int32 _nCrosses ) throw (script::BasicErrorException, uno::RuntimeException)
121 double fNum = 0.0;
122 switch (_nCrosses)
124 case xlAxisCrossesAutomatic: //Microsoft Excel sets the axis crossing point.
125 mxPropertySet->setPropertyValue(AUTOORIGIN, uno::makeAny( sal_True ) );
126 bCrossesAreCustomized = false;
127 return;
128 case xlAxisCrossesMinimum: // The axis crosses at the minimum value.
129 mxPropertySet->getPropertyValue(VBA_MIN) >>= fNum;
130 setCrossesAt( fNum );
131 bCrossesAreCustomized = false;
132 break;
133 case xlAxisCrossesMaximum: // The axis crosses at the maximum value.
134 mxPropertySet->getPropertyValue(VBA_MAX) >>= fNum;
135 setCrossesAt(fNum);
136 bCrossesAreCustomized = false;
137 break;
138 default: //xlAxisCrossesCustom
139 bCrossesAreCustomized = sal_True;
140 break;
142 mxPropertySet->setPropertyValue(AUTOORIGIN, uno::makeAny(false) );
144 catch (uno::Exception& )
146 DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
149 ::sal_Int32 SAL_CALL
150 ScVbaAxis::getCrosses( ) throw (script::BasicErrorException, uno::RuntimeException)
152 sal_Int32 nCrosses = xlAxisCrossesCustom;
155 sal_Bool bisAutoOrigin = false;
156 mxPropertySet->getPropertyValue(AUTOORIGIN) >>= bisAutoOrigin;
157 if (bisAutoOrigin)
158 nCrosses = xlAxisCrossesAutomatic;
159 else
161 if (bCrossesAreCustomized)
162 nCrosses = xlAxisCrossesCustom;
163 else
165 double forigin = 0.0;
166 mxPropertySet->getPropertyValue(ORIGIN) >>= forigin;
167 double fmin = 0.0;
168 mxPropertySet->getPropertyValue(VBA_MIN) >>= fmin;
169 if (forigin == fmin)
170 nCrosses = xlAxisCrossesMinimum;
171 else
172 nCrosses = xlAxisCrossesMaximum;
176 catch (uno::Exception& )
178 DebugHelper::exception(SbERR_METHOD_FAILED, OUString() );
180 return nCrosses;
183 void SAL_CALL
184 ScVbaAxis::setCrossesAt( double _fCrossesAt ) throw (script::BasicErrorException, uno::RuntimeException)
188 setMaximumScaleIsAuto( false );
189 setMinimumScaleIsAuto( false );
190 mxPropertySet->setPropertyValue(ORIGIN, uno::makeAny(_fCrossesAt));
192 catch (const uno::Exception& e)
194 DebugHelper::exception(e);
198 double SAL_CALL
199 ScVbaAxis::getCrossesAt( ) throw (script::BasicErrorException, uno::RuntimeException)
201 double fCrosses = 0.0;
204 mxPropertySet->getPropertyValue(ORIGIN) >>= fCrosses;
206 catch (uno::Exception& )
208 DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
210 return fCrosses;
213 void SAL_CALL
214 ScVbaAxis::setType( ::sal_Int32 _nType ) throw (script::BasicErrorException, uno::RuntimeException)
216 mnType = _nType;
219 ::sal_Int32 SAL_CALL
220 ScVbaAxis::getType( ) throw (script::BasicErrorException, uno::RuntimeException)
222 return mnType;
225 void SAL_CALL
226 ScVbaAxis::setHasTitle( ::sal_Bool _bHasTitle ) throw (script::BasicErrorException, uno::RuntimeException)
230 ScVbaChart* pChart = getChartPtr();
231 sal_Int32 nType = getType();
232 switch(nType)
234 case xlCategory:
235 pChart->mxDiagramPropertySet->setPropertyValue("HasXAxisTitle", uno::makeAny(_bHasTitle));
236 break;
237 case xlSeriesAxis:
238 pChart->mxDiagramPropertySet->setPropertyValue("HasZAxisTitle", uno::makeAny(_bHasTitle));
239 break;
240 default: // xlValue:
241 pChart->mxDiagramPropertySet->setPropertyValue("HasYAxisTitle", uno::makeAny(_bHasTitle));
245 catch (const uno::Exception& e)
247 DebugHelper::exception(e);
251 ::sal_Bool SAL_CALL
252 ScVbaAxis::getHasTitle( ) throw (script::BasicErrorException, uno::RuntimeException)
254 sal_Bool bHasTitle = false;
257 ScVbaChart* pChart = getChartPtr();
258 int nType = getType();
259 switch(nType)
261 case xlCategory:
262 pChart->mxDiagramPropertySet->getPropertyValue("HasXAxisTitle") >>= bHasTitle;
263 break;
264 case xlSeriesAxis:
265 pChart->mxDiagramPropertySet->getPropertyValue("HasZAxisTitle") >>= bHasTitle;
266 break;
267 default: // xlValue:
268 pChart->mxDiagramPropertySet->getPropertyValue("HasYAxisTitle") >>= bHasTitle;
271 catch (const uno::Exception& e)
273 DebugHelper::exception(e);
275 return bHasTitle;
278 void SAL_CALL
279 ScVbaAxis::setMinorUnit( double _fMinorUnit ) throw (script::BasicErrorException, uno::RuntimeException)
283 if (isValueAxis())
284 mxPropertySet->setPropertyValue("StepHelp", uno::makeAny(_fMinorUnit));
286 catch (uno::Exception& )
288 DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
292 double SAL_CALL
293 ScVbaAxis::getMinorUnit( ) throw (script::BasicErrorException, uno::RuntimeException)
295 double fMinor = 1.0;
298 if (isValueAxis())
299 mxPropertySet->getPropertyValue("StepHelp") >>= fMinor;
301 catch (uno::Exception& )
303 DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
305 return fMinor;
308 void SAL_CALL
309 ScVbaAxis::setMinorUnitIsAuto( ::sal_Bool _bMinorUnitIsAuto ) throw (script::BasicErrorException, uno::RuntimeException)
313 if (isValueAxis())
314 mxPropertySet->setPropertyValue("AutoStepHelp", uno::makeAny(_bMinorUnitIsAuto));
316 catch (uno::Exception& )
318 DebugHelper::exception(SbERR_METHOD_FAILED, OUString() );
322 ::sal_Bool SAL_CALL
323 ScVbaAxis::getMinorUnitIsAuto( ) throw (script::BasicErrorException, uno::RuntimeException)
325 sal_Bool bIsAuto = false;
328 if (isValueAxis())
330 mxPropertySet->getPropertyValue("AutoStepHelp") >>= bIsAuto;
333 catch (uno::Exception& )
335 DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
337 return bIsAuto;
340 void SAL_CALL
341 ScVbaAxis::setReversePlotOrder( ::sal_Bool /*ReversePlotOrder*/ ) throw (script::BasicErrorException, uno::RuntimeException)
343 DebugHelper::exception(SbERR_NOT_IMPLEMENTED, OUString());
346 ::sal_Bool SAL_CALL
347 ScVbaAxis::getReversePlotOrder( ) throw (script::BasicErrorException, uno::RuntimeException)
349 DebugHelper::exception(SbERR_NOT_IMPLEMENTED, OUString());
350 return false;
353 void SAL_CALL
354 ScVbaAxis::setMajorUnit( double _fMajorUnit ) throw (script::BasicErrorException, uno::RuntimeException)
358 if (isValueAxis())
360 mxPropertySet->setPropertyValue("StepMain", uno::makeAny(_fMajorUnit));
363 catch (uno::Exception& )
365 DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
369 double SAL_CALL
370 ScVbaAxis::getMajorUnit( ) throw (script::BasicErrorException, uno::RuntimeException)
372 double fMax = 1.0;
375 if (isValueAxis())
376 mxPropertySet->getPropertyValue("StepMain") >>= fMax;
378 catch (uno::Exception& )
380 DebugHelper::exception(SbERR_METHOD_FAILED, OUString() );
382 return fMax;
385 void SAL_CALL
386 ScVbaAxis::setMajorUnitIsAuto( ::sal_Bool _bMajorUnitIsAuto ) throw (script::BasicErrorException, uno::RuntimeException)
390 if (isValueAxis())
392 mxPropertySet->setPropertyValue("AutoStepMain", uno::makeAny( _bMajorUnitIsAuto ));
395 catch (uno::Exception& )
397 DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
401 ::sal_Bool SAL_CALL
402 ScVbaAxis::getMajorUnitIsAuto( ) throw (script::BasicErrorException, uno::RuntimeException)
404 sal_Bool bIsAuto = false;
407 if (isValueAxis())
409 mxPropertySet->getPropertyValue("AutoStepMain") >>= bIsAuto;
412 catch (uno::Exception& )
414 DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
416 return bIsAuto;
419 void SAL_CALL
420 ScVbaAxis::setMaximumScale( double _fMaximumScale ) throw (script::BasicErrorException, uno::RuntimeException)
424 if ( isValueAxis() )
426 mxPropertySet->setPropertyValue("Max", uno::makeAny(_fMaximumScale));
429 catch ( uno::Exception& )
431 DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
435 double SAL_CALL
436 ScVbaAxis::getMaximumScale( ) throw (script::BasicErrorException, uno::RuntimeException)
438 double fMax = 1.0;
441 if (isValueAxis())
443 mxPropertySet->getPropertyValue("Max") >>= fMax;
446 catch (uno::Exception& )
448 DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
450 return fMax;
454 void SAL_CALL
455 ScVbaAxis::setMaximumScaleIsAuto( ::sal_Bool _bMaximumScaleIsAuto ) throw (script::BasicErrorException, uno::RuntimeException)
459 if ( isValueAxis() )
460 mxPropertySet->setPropertyValue("AutoMax", uno::makeAny( _bMaximumScaleIsAuto ));
463 catch ( uno::Exception& )
465 DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
470 ::sal_Bool SAL_CALL
471 ScVbaAxis::getMaximumScaleIsAuto( ) throw (script::BasicErrorException, uno::RuntimeException)
473 sal_Bool bIsAuto = false;
476 if (isValueAxis())
477 mxPropertySet->getPropertyValue("AutoMax") >>= bIsAuto;
479 catch ( uno::Exception& )
481 DebugHelper::exception( SbERR_METHOD_FAILED, OUString() );
483 return bIsAuto;
486 void SAL_CALL
487 ScVbaAxis::setMinimumScale( double _fMinimumScale ) throw (script::BasicErrorException, uno::RuntimeException)
491 if (isValueAxis())
492 mxPropertySet->setPropertyValue("Min", uno::makeAny( _fMinimumScale ) );
494 catch ( uno::Exception& )
496 DebugHelper::exception(SbERR_METHOD_FAILED, OUString() );
500 double SAL_CALL
501 ScVbaAxis::getMinimumScale( ) throw (script::BasicErrorException, uno::RuntimeException)
503 double fMin = 0.0;
506 if (isValueAxis())
507 mxPropertySet->getPropertyValue("Min") >>= fMin;
509 catch (const uno::Exception& e)
511 DebugHelper::exception(e);
513 return fMin;
516 void SAL_CALL
517 ScVbaAxis::setMinimumScaleIsAuto( ::sal_Bool _bMinimumScaleIsAuto ) throw (script::BasicErrorException, uno::RuntimeException)
521 if (isValueAxis())
523 mxPropertySet->setPropertyValue("AutoMin", uno::makeAny(_bMinimumScaleIsAuto));
526 catch (uno::Exception& )
528 DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
532 ::sal_Bool SAL_CALL
533 ScVbaAxis::getMinimumScaleIsAuto( ) throw (script::BasicErrorException, uno::RuntimeException)
535 sal_Bool bIsAuto = false;
538 if (isValueAxis())
540 mxPropertySet->getPropertyValue("AutoMin") >>= bIsAuto;
543 catch (uno::Exception& )
545 DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
547 return bIsAuto;
550 ::sal_Int32 SAL_CALL
551 ScVbaAxis::getAxisGroup( ) throw (uno::RuntimeException)
553 return mnGroup;
556 void SAL_CALL
557 ScVbaAxis::setScaleType( ::sal_Int32 _nScaleType ) throw (script::BasicErrorException, uno::RuntimeException)
561 if (isValueAxis())
563 switch (_nScaleType)
565 case xlScaleLinear:
566 mxPropertySet->setPropertyValue("Logarithmic", uno::makeAny( sal_False ) );
567 break;
568 case xlScaleLogarithmic:
569 mxPropertySet->setPropertyValue("Logarithmic", uno::makeAny( sal_True ) );
570 break;
571 default:
572 // According to MS the paramenter is ignored and no Error is thrown
573 break;
577 catch (uno::Exception& )
579 DebugHelper::exception(SbERR_METHOD_FAILED, OUString() );
583 ::sal_Int32 SAL_CALL
584 ScVbaAxis::getScaleType( ) throw (script::BasicErrorException, uno::RuntimeException)
586 sal_Int32 nScaleType = xlScaleLinear;
589 if (isValueAxis())
591 sal_Bool bisLogarithmic = false;
592 mxPropertySet->getPropertyValue( OUString( OUString("Logarithmic")) ) >>= bisLogarithmic;
593 if (bisLogarithmic)
594 nScaleType = xlScaleLogarithmic;
595 else
596 nScaleType = xlScaleLinear;
599 catch (uno::Exception& )
601 DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
603 return nScaleType;
606 double SAL_CALL
607 ScVbaAxis::getHeight( ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
609 return oShapeHelper->getHeight();
612 void SAL_CALL ScVbaAxis::setHeight( double height ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
614 oShapeHelper->setHeight( height );
616 double SAL_CALL ScVbaAxis::getWidth( ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
618 return oShapeHelper->getWidth( );
620 void SAL_CALL ScVbaAxis::setWidth( double width ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
622 oShapeHelper->setWidth( width );
624 double SAL_CALL ScVbaAxis::getTop( ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
626 return oShapeHelper->getTop( );
628 void SAL_CALL ScVbaAxis::setTop( double top ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
630 oShapeHelper->setTop( top );
632 double SAL_CALL ScVbaAxis::getLeft( ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
634 return oShapeHelper->getLeft( );
636 void SAL_CALL ScVbaAxis::setLeft( double left ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
638 oShapeHelper->setLeft( left );
641 OUString
642 ScVbaAxis::getServiceImplName()
644 return OUString("ScVbaAxis");
647 uno::Sequence< OUString >
648 ScVbaAxis::getServiceNames()
650 static uno::Sequence< OUString > aServiceNames;
651 if ( aServiceNames.getLength() == 0 )
653 aServiceNames.realloc( 1 );
654 aServiceNames[ 0 ] = "ooo.vba.excel.Axis";
656 return aServiceNames;
659 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */