fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / vba / vbaaxis.cxx
blobb7baad87a4f2c32af657b7f200664adefd06e053
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" );
42 return pChart;
45 bool
46 ScVbaAxis::isValueAxis() throw( script::BasicErrorException )
48 if ( getType() == xlCategory )
50 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
52 return 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, 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;
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::basicexception(e);
99 return xAxisTitle;
103 void SAL_CALL
104 ScVbaAxis::setDisplayUnit( ::sal_Int32 /*DisplayUnit*/ ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
106 DebugHelper::basicexception(SbERR_NOT_IMPLEMENTED, OUString());
109 ::sal_Int32 SAL_CALL
110 ScVbaAxis::getDisplayUnit( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
112 DebugHelper::basicexception(SbERR_NOT_IMPLEMENTED, OUString());
113 return -1;
116 void SAL_CALL
117 ScVbaAxis::setCrosses( ::sal_Int32 _nCrosses ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
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 = true;
140 break;
142 mxPropertySet->setPropertyValue(AUTOORIGIN, uno::makeAny(false) );
144 catch (const uno::Exception&)
146 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
149 ::sal_Int32 SAL_CALL
150 ScVbaAxis::getCrosses( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
152 sal_Int32 nCrosses = xlAxisCrossesCustom;
155 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::basicexception(SbERR_METHOD_FAILED, OUString() );
180 return nCrosses;
183 void SAL_CALL
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);
198 double SAL_CALL
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());
210 return fCrosses;
213 void SAL_CALL
214 ScVbaAxis::setType( ::sal_Int32 _nType ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
216 mnType = _nType;
219 ::sal_Int32 SAL_CALL
220 ScVbaAxis::getType( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
222 return mnType;
225 void SAL_CALL
226 ScVbaAxis::setHasTitle( sal_Bool _bHasTitle ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
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::basicexception(e);
251 sal_Bool SAL_CALL
252 ScVbaAxis::getHasTitle( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
254 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::basicexception(e);
275 return bHasTitle;
278 void SAL_CALL
279 ScVbaAxis::setMinorUnit( double _fMinorUnit ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
283 if (isValueAxis())
284 mxPropertySet->setPropertyValue("StepHelp", uno::makeAny(_fMinorUnit));
286 catch (uno::Exception& )
288 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
292 double SAL_CALL
293 ScVbaAxis::getMinorUnit( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
295 double fMinor = 1.0;
298 if (isValueAxis())
299 mxPropertySet->getPropertyValue("StepHelp") >>= fMinor;
301 catch (uno::Exception& )
303 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
305 return fMinor;
308 void SAL_CALL
309 ScVbaAxis::setMinorUnitIsAuto( sal_Bool _bMinorUnitIsAuto ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
313 if (isValueAxis())
314 mxPropertySet->setPropertyValue("AutoStepHelp", uno::makeAny(_bMinorUnitIsAuto));
316 catch (uno::Exception& )
318 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString() );
322 sal_Bool SAL_CALL
323 ScVbaAxis::getMinorUnitIsAuto( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
325 bool bIsAuto = false;
328 if (isValueAxis())
330 mxPropertySet->getPropertyValue("AutoStepHelp") >>= bIsAuto;
333 catch (const uno::Exception&)
335 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
337 return bIsAuto;
340 void SAL_CALL
341 ScVbaAxis::setReversePlotOrder( sal_Bool /*ReversePlotOrder*/ ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
343 DebugHelper::basicexception(SbERR_NOT_IMPLEMENTED, OUString());
346 sal_Bool SAL_CALL
347 ScVbaAxis::getReversePlotOrder( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
349 DebugHelper::basicexception(SbERR_NOT_IMPLEMENTED, OUString());
350 return false;
353 void SAL_CALL
354 ScVbaAxis::setMajorUnit( double _fMajorUnit ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
358 if (isValueAxis())
360 mxPropertySet->setPropertyValue("StepMain", uno::makeAny(_fMajorUnit));
363 catch (const uno::Exception&)
365 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
369 double SAL_CALL
370 ScVbaAxis::getMajorUnit( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
372 double fMax = 1.0;
375 if (isValueAxis())
376 mxPropertySet->getPropertyValue("StepMain") >>= fMax;
378 catch (const uno::Exception&)
380 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString() );
382 return fMax;
385 void SAL_CALL
386 ScVbaAxis::setMajorUnitIsAuto( sal_Bool _bMajorUnitIsAuto ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
390 if (isValueAxis())
392 mxPropertySet->setPropertyValue("AutoStepMain", uno::makeAny( _bMajorUnitIsAuto ));
395 catch (const uno::Exception&)
397 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
401 sal_Bool SAL_CALL
402 ScVbaAxis::getMajorUnitIsAuto( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
404 bool bIsAuto = false;
407 if (isValueAxis())
409 mxPropertySet->getPropertyValue("AutoStepMain") >>= bIsAuto;
412 catch (const uno::Exception&)
414 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
416 return bIsAuto;
419 void SAL_CALL
420 ScVbaAxis::setMaximumScale( double _fMaximumScale ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
424 if ( isValueAxis() )
426 mxPropertySet->setPropertyValue("Max", uno::makeAny(_fMaximumScale));
429 catch (const uno::Exception&)
431 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
435 double SAL_CALL
436 ScVbaAxis::getMaximumScale( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
438 double fMax = 1.0;
441 if (isValueAxis())
443 mxPropertySet->getPropertyValue("Max") >>= fMax;
446 catch (const uno::Exception&)
448 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
450 return fMax;
454 void SAL_CALL
455 ScVbaAxis::setMaximumScaleIsAuto( sal_Bool _bMaximumScaleIsAuto ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
459 if ( isValueAxis() )
460 mxPropertySet->setPropertyValue("AutoMax", uno::makeAny( _bMaximumScaleIsAuto ));
463 catch (const uno::Exception&)
465 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
469 sal_Bool SAL_CALL
470 ScVbaAxis::getMaximumScaleIsAuto( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
472 bool bIsAuto = false;
475 if (isValueAxis())
476 mxPropertySet->getPropertyValue("AutoMax") >>= bIsAuto;
478 catch (const uno::Exception&)
480 DebugHelper::basicexception( SbERR_METHOD_FAILED, OUString() );
482 return bIsAuto;
485 void SAL_CALL
486 ScVbaAxis::setMinimumScale( double _fMinimumScale ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
490 if (isValueAxis())
491 mxPropertySet->setPropertyValue("Min", uno::makeAny( _fMinimumScale ) );
493 catch ( uno::Exception& )
495 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString() );
499 double SAL_CALL
500 ScVbaAxis::getMinimumScale( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
502 double fMin = 0.0;
505 if (isValueAxis())
506 mxPropertySet->getPropertyValue("Min") >>= fMin;
508 catch (const uno::Exception& e)
510 DebugHelper::basicexception(e);
512 return fMin;
515 void SAL_CALL
516 ScVbaAxis::setMinimumScaleIsAuto( sal_Bool _bMinimumScaleIsAuto ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
520 if (isValueAxis())
522 mxPropertySet->setPropertyValue("AutoMin", uno::makeAny(_bMinimumScaleIsAuto));
525 catch (const uno::Exception&)
527 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
531 sal_Bool SAL_CALL
532 ScVbaAxis::getMinimumScaleIsAuto( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
534 bool bIsAuto = false;
537 if (isValueAxis())
539 mxPropertySet->getPropertyValue("AutoMin") >>= bIsAuto;
542 catch (const uno::Exception&)
544 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
546 return bIsAuto;
549 ::sal_Int32 SAL_CALL
550 ScVbaAxis::getAxisGroup( ) throw (uno::RuntimeException, std::exception)
552 return mnGroup;
555 void SAL_CALL
556 ScVbaAxis::setScaleType( ::sal_Int32 _nScaleType ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
560 if (isValueAxis())
562 switch (_nScaleType)
564 case xlScaleLinear:
565 mxPropertySet->setPropertyValue("Logarithmic", uno::makeAny( sal_False ) );
566 break;
567 case xlScaleLogarithmic:
568 mxPropertySet->setPropertyValue("Logarithmic", uno::makeAny( sal_True ) );
569 break;
570 default:
571 // According to MS the paramenter is ignored and no Error is thrown
572 break;
576 catch (const uno::Exception&)
578 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
582 ::sal_Int32 SAL_CALL
583 ScVbaAxis::getScaleType( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
585 sal_Int32 nScaleType = xlScaleLinear;
588 if (isValueAxis())
590 bool bisLogarithmic = false;
591 mxPropertySet->getPropertyValue( OUString( OUString("Logarithmic")) ) >>= bisLogarithmic;
592 if (bisLogarithmic)
593 nScaleType = xlScaleLogarithmic;
594 else
595 nScaleType = xlScaleLinear;
598 catch (const uno::Exception&)
600 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
602 return nScaleType;
605 double SAL_CALL
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 );
640 OUString
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: */