LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/vba - vbaaxes.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 71 0.0 %
Date: 2012-12-27 Functions: 0 21 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "vbaaxes.hxx"
      21             : #include "vbaaxis.hxx"
      22             : #include "vbachart.hxx"
      23             : #include <ooo/vba/excel/XlAxisType.hpp>
      24             : #include <ooo/vba/excel/XlAxisGroup.hpp>
      25             : #include <ooo/vba/excel/XAxis.hpp>
      26             : #include <map>
      27             : 
      28             : using namespace ::com::sun::star;
      29             : using namespace ::ooo::vba;
      30             : using namespace ::ooo::vba::excel::XlAxisType;
      31             : using namespace ::ooo::vba::excel::XlAxisGroup;
      32             : 
      33             : // each 'Item' in the Axes collection is  indexed via 2 indexes,  group and type.
      34             : // We need to 'flatten' this into a single index in order to be able to wrap
      35             : // iteration over the set of Axis(s) in a XIndexAccess implementation
      36             : //
      37             : typedef ::std::pair<sal_Int32, sal_Int32 > AxesCoordinate; // type and group combination
      38             : typedef ::std::vector< AxesCoordinate > vecAxesIndices;
      39             : 
      40             : typedef ::cppu::WeakImplHelper1< container::XIndexAccess > AxisIndexWrapper_BASE;
      41             : 
      42           0 : class EnumWrapper : public EnumerationHelper_BASE
      43             : {
      44             :         uno::Reference<container::XIndexAccess > m_xIndexAccess;
      45             :         sal_Int32 nIndex;
      46             : public:
      47           0 :         EnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {}
      48           0 :         virtual ::sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException)
      49             :         {
      50           0 :                 return ( nIndex < m_xIndexAccess->getCount() );
      51             :         }
      52             : 
      53           0 :         virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
      54             :         {
      55           0 :                 if ( nIndex < m_xIndexAccess->getCount() )
      56           0 :                         return m_xIndexAccess->getByIndex( nIndex++ );
      57           0 :                 throw container::NoSuchElementException();
      58             :         }
      59             : };
      60             : 
      61             : 
      62             : uno::Reference< excel::XAxis >
      63           0 : ScVbaAxes::createAxis( const uno::Reference< excel::XChart >& xChart, const uno::Reference< uno::XComponentContext >& xContext,  sal_Int32 nType, sal_Int32 nAxisGroup ) throw ( uno::RuntimeException )
      64             : {
      65           0 :     ScVbaChart* pChart = static_cast< ScVbaChart* >( xChart.get() );
      66           0 :     if ( !pChart )
      67           0 :         throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Object failure, can't access chart implementation" )), uno::Reference< uno::XInterface >()  );
      68             : 
      69           0 :     uno::Reference< beans::XPropertySet > xAxisPropertySet;
      70           0 :     if (((nType == xlCategory) || (nType == xlSeriesAxis) || (nType == xlValue)))
      71             :     {
      72           0 :         if ((nAxisGroup != xlPrimary) && (nAxisGroup != xlSecondary))
      73           0 :             throw script::BasicErrorException( rtl::OUString(), NULL, SbERR_METHOD_FAILED, rtl::OUString());
      74           0 :         xAxisPropertySet.set( pChart->getAxisPropertySet(nType, nAxisGroup), uno::UNO_QUERY_THROW );
      75             :     }
      76             :     else
      77           0 :         throw script::BasicErrorException( rtl::OUString(), NULL, SbERR_METHOD_FAILED, rtl::OUString());
      78           0 :     uno::Reference< XHelperInterface > xParent( xChart, uno::UNO_QUERY_THROW );
      79           0 :     return new ScVbaAxis( xParent, xContext, xAxisPropertySet, nType, nAxisGroup);
      80             : }
      81             : 
      82           0 : class AxisIndexWrapper : public AxisIndexWrapper_BASE
      83             : {
      84             :     // if necessary for better performance we could change this into a map and cache the
      85             :     // indices -> Axis, currently we create a new Axis object
      86             :     // on each getByIndex
      87             :     uno::Reference< uno::XComponentContext > mxContext;
      88             :     vecAxesIndices mCoordinates;
      89             :     uno::Reference< excel::XChart > mxChart;
      90             : public:
      91           0 :     AxisIndexWrapper( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< excel::XChart >& xChart ) : mxContext( xContext ), mxChart( xChart )
      92             :     {
      93           0 :         if ( mxChart.is() )
      94             :         {
      95           0 :             ScVbaChart* pChart = static_cast< ScVbaChart* >( mxChart.get() );
      96             :             // primary
      97           0 :             sal_Bool bBool = false;
      98           0 :             uno::Reference< beans::XPropertySet > xDiagramPropertySet( pChart->xDiagramPropertySet() );
      99           0 :             if ( ( xDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasXAxis" ) ) ) >>= bBool )  && bBool )
     100           0 :                 mCoordinates.push_back( AxesCoordinate( xlPrimary, xlCategory ) );
     101           0 :             if ( ( xDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasYAxis" ) ) ) >>= bBool )  && bBool )
     102           0 :                 mCoordinates.push_back( AxesCoordinate( xlPrimary, xlSeriesAxis ) );
     103             : 
     104           0 :             if (  pChart->is3D() )
     105           0 :                 mCoordinates.push_back( AxesCoordinate( xlPrimary, xlValue ) );
     106             : 
     107             :             // secondary
     108           0 :             if ( ( xDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasSecondaryXAxis" ) ) ) >>= bBool )  && bBool )
     109           0 :                 mCoordinates.push_back( AxesCoordinate( xlSecondary, xlCategory ) );
     110           0 :             if ( ( xDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasSecondaryYAxis" ) ) ) >>= bBool )  && bBool )
     111           0 :                 mCoordinates.push_back( AxesCoordinate( xlSecondary, xlSeriesAxis ) );
     112             :         }
     113             : 
     114           0 :     }
     115           0 :     virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException) { return mCoordinates.size(); }
     116           0 :     virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, ::uno::RuntimeException)
     117             :     {
     118           0 :             AxesCoordinate dIndexes = mCoordinates[ Index ];
     119           0 :             return uno::makeAny( ScVbaAxes::createAxis( mxChart, mxContext, dIndexes.second, dIndexes.first ) );
     120             :     }
     121             :     // XElementAccess
     122           0 :     virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException)
     123             :     {
     124           0 :         return excel::XAxis::static_type(0);
     125             :     }
     126           0 :     virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
     127             :     {
     128           0 :         return ( mCoordinates.size() > 0 );
     129             :     }
     130             : };
     131             : 
     132           0 : uno::Reference< container::XIndexAccess > createIndexWrapper( const uno::Reference< excel::XChart >& xChart, const uno::Reference< uno::XComponentContext >& xContext )
     133             : {
     134           0 :     return new AxisIndexWrapper( xContext, xChart );
     135             : }
     136             : 
     137             : // #FIXME The collection semantics will never work as this object is not yet initialised correctly
     138           0 : ScVbaAxes::ScVbaAxes( const uno::Reference< XHelperInterface >& xParent,const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< excel::XChart >& xChart ) : ScVbaAxes_BASE( xParent, xContext, createIndexWrapper( xChart, xContext )), moChartParent( xChart )
     139             : {
     140           0 : }
     141             : 
     142             : uno::Type SAL_CALL
     143           0 : ScVbaAxes::getElementType() throw (css::uno::RuntimeException)
     144             : {
     145           0 :     return  excel::XAxes::static_type(0);
     146             : }
     147             : 
     148             : uno::Reference< container::XEnumeration > SAL_CALL
     149           0 : ScVbaAxes::createEnumeration() throw (css::uno::RuntimeException)
     150             : {
     151           0 :     return new EnumWrapper( m_xIndexAccess );
     152             : }
     153             : 
     154             : uno::Any SAL_CALL
     155           0 : ScVbaAxes::Item( const css::uno::Any& _nType, const css::uno::Any& _oAxisGroup) throw (css::uno::RuntimeException)
     156             : {
     157             :     // #TODO map the possible index combinations to a container::XIndexAccess wrapper impl
     158             :     // using a vector of valid std::pair maybe?
     159             :     // bodgy helperapi port bits
     160           0 :     sal_Int32 nAxisGroup = xlPrimary;
     161           0 :     sal_Int32 nType = -1;
     162           0 :     if ( !_nType.hasValue() || ( ( _nType >>= nType ) == false )  )
     163           0 :         throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Axes::Item Failed to extract type" )), uno::Reference< uno::XInterface >()  );
     164             : 
     165           0 :     if ( _oAxisGroup.hasValue() )
     166           0 :         _oAxisGroup >>= nAxisGroup ;
     167             : 
     168           0 :     return uno::makeAny( createAxis( moChartParent, mxContext, nType, nAxisGroup ) );
     169             : }
     170             : 
     171             : uno::Any
     172           0 : ScVbaAxes::createCollectionObject(const css::uno::Any& aSource)
     173             : {
     174           0 :     return aSource; // pass through ( it's already an XAxis object
     175             : }
     176             : 
     177             : rtl::OUString
     178           0 : ScVbaAxes::getServiceImplName()
     179             : {
     180           0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScVbaAxes"));
     181             : }
     182             : 
     183             : uno::Sequence< rtl::OUString >
     184           0 : ScVbaAxes::getServiceNames()
     185             : {
     186           0 :     static uno::Sequence< rtl::OUString > aServiceNames;
     187           0 :     if ( aServiceNames.getLength() == 0 )
     188             :     {
     189           0 :         aServiceNames.realloc( 1 );
     190           0 :         aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Axes" ) );
     191             :     }
     192           0 :     return aServiceNames;
     193             : }
     194             : 
     195             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10