1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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;
31
32 const OUString ORIGIN("Origin");
33 const OUString AUTOORIGIN("AutoOrigin");
34 const OUString VBA_MIN("Max");
35 const OUString VBA_MAX("Min");
36 ScVbaChart*
getChartPtr()37 ScVbaAxis::getChartPtr()
38 {
39 ScVbaChart* pChart = static_cast< ScVbaChart* >( moChartParent.get() );
40 if ( !pChart )
41 throw uno::RuntimeException("Can't access parent chart impl" );
42 return pChart;
43 }
44
45 bool
isValueAxis()46 ScVbaAxis::isValueAxis()
47 {
48 if ( getType() == xlCategory )
49 {
50 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString());
51 }
52 return true;
53 }
54
ScVbaAxis(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<beans::XPropertySet> & _xPropertySet,sal_Int32 _nType,sal_Int32 _nGroup)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 )
56 {
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);
61 }
62
63 void SAL_CALL
Delete()64 ScVbaAxis::Delete( )
65 {
66 uno::Reference< lang::XComponent > xComponent( mxPropertySet, uno::UNO_QUERY_THROW );
67 xComponent->dispose();
68 }
69
70 uno::Reference< ::ooo::vba::excel::XAxisTitle > SAL_CALL
getAxisTitle()71 ScVbaAxis::getAxisTitle( )
72 {
73 uno::Reference< excel::XAxisTitle > xAxisTitle;
74 try
75 {
76 ScVbaChart* pChart = getChartPtr();
77
78 if (getHasTitle() )
79 {
80 int nType = getType();
81 switch(nType)
82 {
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;
92 }
93 }
94 }
95 catch (const uno::Exception& e)
96 {
97 DebugHelper::basicexception(e);
98 }
99 return xAxisTitle;
100
101 }
102
103 void SAL_CALL
setDisplayUnit(::sal_Int32)104 ScVbaAxis::setDisplayUnit( ::sal_Int32 /*DisplayUnit*/ )
105 {
106 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, OUString());
107 }
108
109 ::sal_Int32 SAL_CALL
getDisplayUnit()110 ScVbaAxis::getDisplayUnit( )
111 {
112 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, OUString());
113 return -1;
114 }
115
116 void SAL_CALL
setCrosses(::sal_Int32 _nCrosses)117 ScVbaAxis::setCrosses( ::sal_Int32 _nCrosses )
118 {
119 try
120 {
121 double fNum = 0.0;
122 switch (_nCrosses)
123 {
124 case xlAxisCrossesAutomatic: //Microsoft Excel sets the axis crossing point.
125 mxPropertySet->setPropertyValue(AUTOORIGIN, uno::makeAny( 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;
141 }
142 mxPropertySet->setPropertyValue(AUTOORIGIN, uno::makeAny(false) );
143 }
144 catch (const uno::Exception&)
145 {
146 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString());
147 }
148 }
149 ::sal_Int32 SAL_CALL
getCrosses()150 ScVbaAxis::getCrosses( )
151 {
152 sal_Int32 nCrosses = xlAxisCrossesCustom;
153 try
154 {
155 bool bisAutoOrigin = false;
156 mxPropertySet->getPropertyValue(AUTOORIGIN) >>= bisAutoOrigin;
157 if (bisAutoOrigin)
158 nCrosses = xlAxisCrossesAutomatic;
159 else
160 {
161 if (bCrossesAreCustomized)
162 nCrosses = xlAxisCrossesCustom;
163 else
164 {
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;
173 }
174 }
175 }
176 catch (uno::Exception& )
177 {
178 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString() );
179 }
180 return nCrosses;
181 }
182
183 void SAL_CALL
setCrossesAt(double _fCrossesAt)184 ScVbaAxis::setCrossesAt( double _fCrossesAt )
185 {
186 try
187 {
188 setMaximumScaleIsAuto( false );
189 setMinimumScaleIsAuto( false );
190 mxPropertySet->setPropertyValue(ORIGIN, uno::makeAny(_fCrossesAt));
191 }
192 catch (const uno::Exception& e)
193 {
194 DebugHelper::basicexception(e);
195 }
196 }
197
198 double SAL_CALL
getCrossesAt()199 ScVbaAxis::getCrossesAt( )
200 {
201 double fCrosses = 0.0;
202 try
203 {
204 mxPropertySet->getPropertyValue(ORIGIN) >>= fCrosses;
205 }
206 catch (uno::Exception& )
207 {
208 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString());
209 }
210 return fCrosses;
211 }
212
213 void SAL_CALL
setType(::sal_Int32 _nType)214 ScVbaAxis::setType( ::sal_Int32 _nType )
215 {
216 mnType = _nType;
217 }
218
219 ::sal_Int32 SAL_CALL
getType()220 ScVbaAxis::getType( )
221 {
222 return mnType;
223 }
224
225 void SAL_CALL
setHasTitle(sal_Bool _bHasTitle)226 ScVbaAxis::setHasTitle( sal_Bool _bHasTitle )
227 {
228 try
229 {
230 ScVbaChart* pChart = getChartPtr();
231 sal_Int32 nType = getType();
232 switch(nType)
233 {
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));
242 }
243
244 }
245 catch (const uno::Exception& e)
246 {
247 DebugHelper::basicexception(e);
248 }
249 }
250
251 sal_Bool SAL_CALL
getHasTitle()252 ScVbaAxis::getHasTitle( )
253 {
254 bool bHasTitle = false;
255 try
256 {
257 ScVbaChart* pChart = getChartPtr();
258 int nType = getType();
259 switch(nType)
260 {
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;
269 }
270 }
271 catch (const uno::Exception& e)
272 {
273 DebugHelper::basicexception(e);
274 }
275 return bHasTitle;
276 }
277
278 void SAL_CALL
setMinorUnit(double _fMinorUnit)279 ScVbaAxis::setMinorUnit( double _fMinorUnit )
280 {
281 try
282 {
283 if (isValueAxis())
284 mxPropertySet->setPropertyValue("StepHelp", uno::makeAny(_fMinorUnit));
285 }
286 catch (uno::Exception& )
287 {
288 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString());
289 }
290 }
291
292 double SAL_CALL
getMinorUnit()293 ScVbaAxis::getMinorUnit( )
294 {
295 double fMinor = 1.0;
296 try
297 {
298 if (isValueAxis())
299 mxPropertySet->getPropertyValue("StepHelp") >>= fMinor;
300 }
301 catch (uno::Exception& )
302 {
303 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString());
304 }
305 return fMinor;
306 }
307
308 void SAL_CALL
setMinorUnitIsAuto(sal_Bool _bMinorUnitIsAuto)309 ScVbaAxis::setMinorUnitIsAuto( sal_Bool _bMinorUnitIsAuto )
310 {
311 try
312 {
313 if (isValueAxis())
314 mxPropertySet->setPropertyValue("AutoStepHelp", uno::makeAny(_bMinorUnitIsAuto));
315 }
316 catch (uno::Exception& )
317 {
318 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString() );
319 }
320 }
321
322 sal_Bool SAL_CALL
getMinorUnitIsAuto()323 ScVbaAxis::getMinorUnitIsAuto( )
324 {
325 bool bIsAuto = false;
326 try
327 {
328 if (isValueAxis())
329 {
330 mxPropertySet->getPropertyValue("AutoStepHelp") >>= bIsAuto;
331 }
332 }
333 catch (const uno::Exception&)
334 {
335 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString());
336 }
337 return bIsAuto;
338 }
339
340 void SAL_CALL
setReversePlotOrder(sal_Bool)341 ScVbaAxis::setReversePlotOrder( sal_Bool /*ReversePlotOrder*/ )
342 {
343 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, OUString());
344 }
345
346 sal_Bool SAL_CALL
getReversePlotOrder()347 ScVbaAxis::getReversePlotOrder( )
348 {
349 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, OUString());
350 return false;
351 }
352
353 void SAL_CALL
setMajorUnit(double _fMajorUnit)354 ScVbaAxis::setMajorUnit( double _fMajorUnit )
355 {
356 try
357 {
358 if (isValueAxis())
359 {
360 mxPropertySet->setPropertyValue("StepMain", uno::makeAny(_fMajorUnit));
361 }
362 }
363 catch (const uno::Exception&)
364 {
365 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString());
366 }
367 }
368
369 double SAL_CALL
getMajorUnit()370 ScVbaAxis::getMajorUnit( )
371 {
372 double fMax = 1.0;
373 try
374 {
375 if (isValueAxis())
376 mxPropertySet->getPropertyValue("StepMain") >>= fMax;
377 }
378 catch (const uno::Exception&)
379 {
380 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString() );
381 }
382 return fMax;
383 }
384
385 void SAL_CALL
setMajorUnitIsAuto(sal_Bool _bMajorUnitIsAuto)386 ScVbaAxis::setMajorUnitIsAuto( sal_Bool _bMajorUnitIsAuto )
387 {
388 try
389 {
390 if (isValueAxis())
391 {
392 mxPropertySet->setPropertyValue("AutoStepMain", uno::makeAny( _bMajorUnitIsAuto ));
393 }
394 }
395 catch (const uno::Exception&)
396 {
397 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString());
398 }
399 }
400
401 sal_Bool SAL_CALL
getMajorUnitIsAuto()402 ScVbaAxis::getMajorUnitIsAuto( )
403 {
404 bool bIsAuto = false;
405 try
406 {
407 if (isValueAxis())
408 {
409 mxPropertySet->getPropertyValue("AutoStepMain") >>= bIsAuto;
410 }
411 }
412 catch (const uno::Exception&)
413 {
414 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString());
415 }
416 return bIsAuto;
417 }
418
419 void SAL_CALL
setMaximumScale(double _fMaximumScale)420 ScVbaAxis::setMaximumScale( double _fMaximumScale )
421 {
422 try
423 {
424 if ( isValueAxis() )
425 {
426 mxPropertySet->setPropertyValue("Max", uno::makeAny(_fMaximumScale));
427 }
428 }
429 catch (const uno::Exception&)
430 {
431 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString());
432 }
433 }
434
435 double SAL_CALL
getMaximumScale()436 ScVbaAxis::getMaximumScale( )
437 {
438 double fMax = 1.0;
439 try
440 {
441 if (isValueAxis())
442 {
443 mxPropertySet->getPropertyValue("Max") >>= fMax;
444 }
445 }
446 catch (const uno::Exception&)
447 {
448 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString());
449 }
450 return fMax;
451
452 }
453
454 void SAL_CALL
setMaximumScaleIsAuto(sal_Bool _bMaximumScaleIsAuto)455 ScVbaAxis::setMaximumScaleIsAuto( sal_Bool _bMaximumScaleIsAuto )
456 {
457 try
458 {
459 if ( isValueAxis() )
460 mxPropertySet->setPropertyValue("AutoMax", uno::makeAny( _bMaximumScaleIsAuto ));
461
462 }
463 catch (const uno::Exception&)
464 {
465 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString());
466 }
467 }
468
469 sal_Bool SAL_CALL
getMaximumScaleIsAuto()470 ScVbaAxis::getMaximumScaleIsAuto( )
471 {
472 bool bIsAuto = false;
473 try
474 {
475 if (isValueAxis())
476 mxPropertySet->getPropertyValue("AutoMax") >>= bIsAuto;
477 }
478 catch (const uno::Exception&)
479 {
480 DebugHelper::basicexception( ERRCODE_BASIC_METHOD_FAILED, OUString() );
481 }
482 return bIsAuto;
483 }
484
485 void SAL_CALL
setMinimumScale(double _fMinimumScale)486 ScVbaAxis::setMinimumScale( double _fMinimumScale )
487 {
488 try
489 {
490 if (isValueAxis())
491 mxPropertySet->setPropertyValue("Min", uno::makeAny( _fMinimumScale ) );
492 }
493 catch ( uno::Exception& )
494 {
495 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString() );
496 }
497 }
498
499 double SAL_CALL
getMinimumScale()500 ScVbaAxis::getMinimumScale( )
501 {
502 double fMin = 0.0;
503 try
504 {
505 if (isValueAxis())
506 mxPropertySet->getPropertyValue("Min") >>= fMin;
507 }
508 catch (const uno::Exception& e)
509 {
510 DebugHelper::basicexception(e);
511 }
512 return fMin;
513 }
514
515 void SAL_CALL
setMinimumScaleIsAuto(sal_Bool _bMinimumScaleIsAuto)516 ScVbaAxis::setMinimumScaleIsAuto( sal_Bool _bMinimumScaleIsAuto )
517 {
518 try
519 {
520 if (isValueAxis())
521 {
522 mxPropertySet->setPropertyValue("AutoMin", uno::makeAny(_bMinimumScaleIsAuto));
523 }
524 }
525 catch (const uno::Exception&)
526 {
527 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString());
528 }
529 }
530
531 sal_Bool SAL_CALL
getMinimumScaleIsAuto()532 ScVbaAxis::getMinimumScaleIsAuto( )
533 {
534 bool bIsAuto = false;
535 try
536 {
537 if (isValueAxis())
538 {
539 mxPropertySet->getPropertyValue("AutoMin") >>= bIsAuto;
540 }
541 }
542 catch (const uno::Exception&)
543 {
544 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString());
545 }
546 return bIsAuto;
547 }
548
549 ::sal_Int32 SAL_CALL
getAxisGroup()550 ScVbaAxis::getAxisGroup( )
551 {
552 return mnGroup;
553 }
554
555 void SAL_CALL
setScaleType(::sal_Int32 _nScaleType)556 ScVbaAxis::setScaleType( ::sal_Int32 _nScaleType )
557 {
558 try
559 {
560 if (isValueAxis())
561 {
562 switch (_nScaleType)
563 {
564 case xlScaleLinear:
565 mxPropertySet->setPropertyValue("Logarithmic", uno::makeAny( false ) );
566 break;
567 case xlScaleLogarithmic:
568 mxPropertySet->setPropertyValue("Logarithmic", uno::makeAny( true ) );
569 break;
570 default:
571 // According to MS the parameter is ignored and no Error is thrown
572 break;
573 }
574 }
575 }
576 catch (const uno::Exception&)
577 {
578 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString());
579 }
580 }
581
582 ::sal_Int32 SAL_CALL
getScaleType()583 ScVbaAxis::getScaleType( )
584 {
585 sal_Int32 nScaleType = xlScaleLinear;
586 try
587 {
588 if (isValueAxis())
589 {
590 bool bisLogarithmic = false;
591 mxPropertySet->getPropertyValue( "Logarithmic" ) >>= bisLogarithmic;
592 if (bisLogarithmic)
593 nScaleType = xlScaleLogarithmic;
594 else
595 nScaleType = xlScaleLinear;
596 }
597 }
598 catch (const uno::Exception&)
599 {
600 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, OUString());
601 }
602 return nScaleType;
603 }
604
605 double SAL_CALL
getHeight()606 ScVbaAxis::getHeight( )
607 {
608 return oShapeHelper->getHeight();
609 }
610
setHeight(double height)611 void SAL_CALL ScVbaAxis::setHeight( double height )
612 {
613 oShapeHelper->setHeight( height );
614 }
getWidth()615 double SAL_CALL ScVbaAxis::getWidth( )
616 {
617 return oShapeHelper->getWidth( );
618 }
setWidth(double width)619 void SAL_CALL ScVbaAxis::setWidth( double width )
620 {
621 oShapeHelper->setWidth( width );
622 }
getTop()623 double SAL_CALL ScVbaAxis::getTop( )
624 {
625 return oShapeHelper->getTop( );
626 }
setTop(double top)627 void SAL_CALL ScVbaAxis::setTop( double top )
628 {
629 oShapeHelper->setTop( top );
630 }
getLeft()631 double SAL_CALL ScVbaAxis::getLeft( )
632 {
633 return oShapeHelper->getLeft( );
634 }
setLeft(double left)635 void SAL_CALL ScVbaAxis::setLeft( double left )
636 {
637 oShapeHelper->setLeft( left );
638 }
639
640 OUString
getServiceImplName()641 ScVbaAxis::getServiceImplName()
642 {
643 return "ScVbaAxis";
644 }
645
646 uno::Sequence< OUString >
getServiceNames()647 ScVbaAxis::getServiceNames()
648 {
649 static uno::Sequence< OUString > const aServiceNames
650 {
651 "ooo.vba.excel.Axis"
652 };
653 return aServiceNames;
654 }
655
656 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
657