tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / vba / vbaaxis.cxx
blob46a5db7f0eb6e7e1989e63bbd868add77f8ac37d
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 <utility>
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");
37 ScVbaChart*
38 ScVbaAxis::getChartPtr()
40 ScVbaChart* pChart = moChartParent.get();
41 if ( !pChart )
42 throw uno::RuntimeException(u"Can't access parent chart impl"_ustr );
43 return pChart;
46 bool
47 ScVbaAxis::isValueAxis()
49 if ( getType() == xlCategory )
51 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
53 return true;
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 )
67 setType(_nType);
68 setCrosses(xlAxisCrossesAutomatic);
71 void SAL_CALL
72 ScVbaAxis::Delete( )
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;
82 try
84 ScVbaChart* pChart = getChartPtr();
86 if (getHasTitle() )
88 int nType = getType();
89 switch(nType)
91 case xlCategory:
92 xAxisTitle = new ScVbaAxisTitle(this, mxContext, pChart->xAxisXSupplier->getXAxisTitle());
93 break;
94 case xlSeriesAxis:
95 xAxisTitle = new ScVbaAxisTitle(this, mxContext, pChart->xAxisZSupplier->getZAxisTitle());
96 break;
97 default: // xlValue:
98 xAxisTitle = new ScVbaAxisTitle(this, mxContext, pChart->xAxisYSupplier->getYAxisTitle());
99 break;
103 catch (const uno::Exception& e)
105 DebugHelper::basicexception(e);
107 return xAxisTitle;
111 void SAL_CALL
112 ScVbaAxis::setDisplayUnit( ::sal_Int32 /*DisplayUnit*/ )
114 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, {});
117 ::sal_Int32 SAL_CALL
118 ScVbaAxis::getDisplayUnit( )
120 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, {});
121 return -1;
124 void SAL_CALL
125 ScVbaAxis::setCrosses( ::sal_Int32 _nCrosses )
129 double fNum = 0.0;
130 switch (_nCrosses)
132 case xlAxisCrossesAutomatic: //Microsoft Excel sets the axis crossing point.
133 mxPropertySet->setPropertyValue(AUTOORIGIN, uno::Any( true ) );
134 bCrossesAreCustomized = false;
135 return;
136 case xlAxisCrossesMinimum: // The axis crosses at the minimum value.
137 mxPropertySet->getPropertyValue(VBA_MIN) >>= fNum;
138 setCrossesAt( fNum );
139 bCrossesAreCustomized = false;
140 break;
141 case xlAxisCrossesMaximum: // The axis crosses at the maximum value.
142 mxPropertySet->getPropertyValue(VBA_MAX) >>= fNum;
143 setCrossesAt(fNum);
144 bCrossesAreCustomized = false;
145 break;
146 default: //xlAxisCrossesCustom
147 bCrossesAreCustomized = true;
148 break;
150 mxPropertySet->setPropertyValue(AUTOORIGIN, uno::Any(false) );
152 catch (const uno::Exception&)
154 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
157 ::sal_Int32 SAL_CALL
158 ScVbaAxis::getCrosses( )
160 sal_Int32 nCrosses = xlAxisCrossesCustom;
163 bool bisAutoOrigin = false;
164 mxPropertySet->getPropertyValue(AUTOORIGIN) >>= bisAutoOrigin;
165 if (bisAutoOrigin)
166 nCrosses = xlAxisCrossesAutomatic;
167 else
169 if (bCrossesAreCustomized)
170 nCrosses = xlAxisCrossesCustom;
171 else
173 double forigin = 0.0;
174 mxPropertySet->getPropertyValue(ORIGIN) >>= forigin;
175 double fmin = 0.0;
176 mxPropertySet->getPropertyValue(VBA_MIN) >>= fmin;
177 if (forigin == fmin)
178 nCrosses = xlAxisCrossesMinimum;
179 else
180 nCrosses = xlAxisCrossesMaximum;
184 catch (uno::Exception& )
186 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
188 return nCrosses;
191 void SAL_CALL
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);
206 double SAL_CALL
207 ScVbaAxis::getCrossesAt( )
209 double fCrosses = 0.0;
212 mxPropertySet->getPropertyValue(ORIGIN) >>= fCrosses;
214 catch (uno::Exception& )
216 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
218 return fCrosses;
221 void SAL_CALL
222 ScVbaAxis::setType( ::sal_Int32 _nType )
224 mnType = _nType;
227 ::sal_Int32 SAL_CALL
228 ScVbaAxis::getType( )
230 return mnType;
233 void SAL_CALL
234 ScVbaAxis::setHasTitle( sal_Bool _bHasTitle )
238 ScVbaChart* pChart = getChartPtr();
239 sal_Int32 nType = getType();
240 switch(nType)
242 case xlCategory:
243 pChart->mxDiagramPropertySet->setPropertyValue(u"HasXAxisTitle"_ustr, uno::Any(_bHasTitle));
244 break;
245 case xlSeriesAxis:
246 pChart->mxDiagramPropertySet->setPropertyValue(u"HasZAxisTitle"_ustr, uno::Any(_bHasTitle));
247 break;
248 default: // xlValue:
249 pChart->mxDiagramPropertySet->setPropertyValue(u"HasYAxisTitle"_ustr, uno::Any(_bHasTitle));
253 catch (const uno::Exception& e)
255 DebugHelper::basicexception(e);
259 sal_Bool SAL_CALL
260 ScVbaAxis::getHasTitle( )
262 bool bHasTitle = false;
265 ScVbaChart* pChart = getChartPtr();
266 int nType = getType();
267 switch(nType)
269 case xlCategory:
270 pChart->mxDiagramPropertySet->getPropertyValue(u"HasXAxisTitle"_ustr) >>= bHasTitle;
271 break;
272 case xlSeriesAxis:
273 pChart->mxDiagramPropertySet->getPropertyValue(u"HasZAxisTitle"_ustr) >>= bHasTitle;
274 break;
275 default: // xlValue:
276 pChart->mxDiagramPropertySet->getPropertyValue(u"HasYAxisTitle"_ustr) >>= bHasTitle;
279 catch (const uno::Exception& e)
281 DebugHelper::basicexception(e);
283 return bHasTitle;
286 void SAL_CALL
287 ScVbaAxis::setMinorUnit( double _fMinorUnit )
291 if (isValueAxis())
292 mxPropertySet->setPropertyValue(u"StepHelp"_ustr, uno::Any(_fMinorUnit));
294 catch (uno::Exception& )
296 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
300 double SAL_CALL
301 ScVbaAxis::getMinorUnit( )
303 double fMinor = 1.0;
306 if (isValueAxis())
307 mxPropertySet->getPropertyValue(u"StepHelp"_ustr) >>= fMinor;
309 catch (uno::Exception& )
311 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
313 return fMinor;
316 void SAL_CALL
317 ScVbaAxis::setMinorUnitIsAuto( sal_Bool _bMinorUnitIsAuto )
321 if (isValueAxis())
322 mxPropertySet->setPropertyValue(u"AutoStepHelp"_ustr, uno::Any(_bMinorUnitIsAuto));
324 catch (uno::Exception& )
326 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
330 sal_Bool SAL_CALL
331 ScVbaAxis::getMinorUnitIsAuto( )
333 bool bIsAuto = false;
336 if (isValueAxis())
338 mxPropertySet->getPropertyValue(u"AutoStepHelp"_ustr) >>= bIsAuto;
341 catch (const uno::Exception&)
343 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
345 return bIsAuto;
348 void SAL_CALL
349 ScVbaAxis::setReversePlotOrder( sal_Bool /*ReversePlotOrder*/ )
351 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, {});
354 sal_Bool SAL_CALL
355 ScVbaAxis::getReversePlotOrder( )
357 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, {});
358 return false;
361 void SAL_CALL
362 ScVbaAxis::setMajorUnit( double _fMajorUnit )
366 if (isValueAxis())
368 mxPropertySet->setPropertyValue(u"StepMain"_ustr, uno::Any(_fMajorUnit));
371 catch (const uno::Exception&)
373 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
377 double SAL_CALL
378 ScVbaAxis::getMajorUnit( )
380 double fMax = 1.0;
383 if (isValueAxis())
384 mxPropertySet->getPropertyValue(u"StepMain"_ustr) >>= fMax;
386 catch (const uno::Exception&)
388 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
390 return fMax;
393 void SAL_CALL
394 ScVbaAxis::setMajorUnitIsAuto( sal_Bool _bMajorUnitIsAuto )
398 if (isValueAxis())
400 mxPropertySet->setPropertyValue(u"AutoStepMain"_ustr, uno::Any( _bMajorUnitIsAuto ));
403 catch (const uno::Exception&)
405 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
409 sal_Bool SAL_CALL
410 ScVbaAxis::getMajorUnitIsAuto( )
412 bool bIsAuto = false;
415 if (isValueAxis())
417 mxPropertySet->getPropertyValue(u"AutoStepMain"_ustr) >>= bIsAuto;
420 catch (const uno::Exception&)
422 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
424 return bIsAuto;
427 void SAL_CALL
428 ScVbaAxis::setMaximumScale( double _fMaximumScale )
432 if ( isValueAxis() )
434 mxPropertySet->setPropertyValue(u"Max"_ustr, uno::Any(_fMaximumScale));
437 catch (const uno::Exception&)
439 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
443 double SAL_CALL
444 ScVbaAxis::getMaximumScale( )
446 double fMax = 1.0;
449 if (isValueAxis())
451 mxPropertySet->getPropertyValue(u"Max"_ustr) >>= fMax;
454 catch (const uno::Exception&)
456 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
458 return fMax;
462 void SAL_CALL
463 ScVbaAxis::setMaximumScaleIsAuto( sal_Bool _bMaximumScaleIsAuto )
467 if ( isValueAxis() )
468 mxPropertySet->setPropertyValue(u"AutoMax"_ustr, uno::Any( _bMaximumScaleIsAuto ));
471 catch (const uno::Exception&)
473 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
477 sal_Bool SAL_CALL
478 ScVbaAxis::getMaximumScaleIsAuto( )
480 bool bIsAuto = false;
483 if (isValueAxis())
484 mxPropertySet->getPropertyValue(u"AutoMax"_ustr) >>= bIsAuto;
486 catch (const uno::Exception&)
488 DebugHelper::basicexception( ERRCODE_BASIC_METHOD_FAILED, {} );
490 return bIsAuto;
493 void SAL_CALL
494 ScVbaAxis::setMinimumScale( double _fMinimumScale )
498 if (isValueAxis())
499 mxPropertySet->setPropertyValue(u"Min"_ustr, uno::Any( _fMinimumScale ) );
501 catch ( uno::Exception& )
503 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
507 double SAL_CALL
508 ScVbaAxis::getMinimumScale( )
510 double fMin = 0.0;
513 if (isValueAxis())
514 mxPropertySet->getPropertyValue(u"Min"_ustr) >>= fMin;
516 catch (const uno::Exception& e)
518 DebugHelper::basicexception(e);
520 return fMin;
523 void SAL_CALL
524 ScVbaAxis::setMinimumScaleIsAuto( sal_Bool _bMinimumScaleIsAuto )
528 if (isValueAxis())
530 mxPropertySet->setPropertyValue(u"AutoMin"_ustr, uno::Any(_bMinimumScaleIsAuto));
533 catch (const uno::Exception&)
535 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
539 sal_Bool SAL_CALL
540 ScVbaAxis::getMinimumScaleIsAuto( )
542 bool bIsAuto = false;
545 if (isValueAxis())
547 mxPropertySet->getPropertyValue(u"AutoMin"_ustr) >>= bIsAuto;
550 catch (const uno::Exception&)
552 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
554 return bIsAuto;
557 ::sal_Int32 SAL_CALL
558 ScVbaAxis::getAxisGroup( )
560 return mnGroup;
563 void SAL_CALL
564 ScVbaAxis::setScaleType( ::sal_Int32 _nScaleType )
568 if (isValueAxis())
570 switch (_nScaleType)
572 case xlScaleLinear:
573 mxPropertySet->setPropertyValue(u"Logarithmic"_ustr, uno::Any( false ) );
574 break;
575 case xlScaleLogarithmic:
576 mxPropertySet->setPropertyValue(u"Logarithmic"_ustr, uno::Any( true ) );
577 break;
578 default:
579 // According to MS the parameter is ignored and no Error is thrown
580 break;
584 catch (const uno::Exception&)
586 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
590 ::sal_Int32 SAL_CALL
591 ScVbaAxis::getScaleType( )
593 sal_Int32 nScaleType = xlScaleLinear;
596 if (isValueAxis())
598 bool bisLogarithmic = false;
599 mxPropertySet->getPropertyValue( u"Logarithmic"_ustr ) >>= bisLogarithmic;
600 if (bisLogarithmic)
601 nScaleType = xlScaleLogarithmic;
602 else
603 nScaleType = xlScaleLinear;
606 catch (const uno::Exception&)
608 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
610 return nScaleType;
613 double SAL_CALL
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 );
648 OUString
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: */