LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbaaxes.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 74 1.4 %
Date: 2014-11-03 Functions: 2 23 8.7 %
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             : namespace {
      43             : 
      44           0 : class EnumWrapper : public EnumerationHelper_BASE
      45             : {
      46             :         uno::Reference<container::XIndexAccess > m_xIndexAccess;
      47             :         sal_Int32 nIndex;
      48             : public:
      49           0 :         EnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {}
      50           0 :         virtual sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      51             :         {
      52           0 :                 return ( nIndex < m_xIndexAccess->getCount() );
      53             :         }
      54             : 
      55           0 :         virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
      56             :         {
      57           0 :                 if ( nIndex < m_xIndexAccess->getCount() )
      58           0 :                         return m_xIndexAccess->getByIndex( nIndex++ );
      59           0 :                 throw container::NoSuchElementException();
      60             :         }
      61             : };
      62             : 
      63             : }
      64             : 
      65             : uno::Reference< excel::XAxis >
      66           0 : ScVbaAxes::createAxis( const uno::Reference< excel::XChart >& xChart, const uno::Reference< uno::XComponentContext >& xContext,  sal_Int32 nType, sal_Int32 nAxisGroup ) throw ( uno::RuntimeException, script::BasicErrorException )
      67             : {
      68           0 :     ScVbaChart* pChart = static_cast< ScVbaChart* >( xChart.get() );
      69           0 :     if ( !pChart )
      70           0 :         throw uno::RuntimeException("Object failure, can't access chart implementation"  );
      71             : 
      72           0 :     uno::Reference< beans::XPropertySet > xAxisPropertySet;
      73           0 :     if (((nType == xlCategory) || (nType == xlSeriesAxis) || (nType == xlValue)))
      74             :     {
      75           0 :         if ((nAxisGroup != xlPrimary) && (nAxisGroup != xlSecondary))
      76           0 :             DebugHelper::runtimeexception(SbERR_METHOD_FAILED, OUString());
      77           0 :         xAxisPropertySet.set( pChart->getAxisPropertySet(nType, nAxisGroup), uno::UNO_QUERY_THROW );
      78             :     }
      79             :     else
      80           0 :         DebugHelper::runtimeexception(SbERR_METHOD_FAILED, OUString());
      81           0 :     uno::Reference< XHelperInterface > xParent( xChart, uno::UNO_QUERY_THROW );
      82           0 :     return new ScVbaAxis( xParent, xContext, xAxisPropertySet, nType, nAxisGroup);
      83             : }
      84             : 
      85             : namespace {
      86             : 
      87           0 : class AxisIndexWrapper : public AxisIndexWrapper_BASE
      88             : {
      89             :     // if necessary for better performance we could change this into a map and cache the
      90             :     // indices -> Axis, currently we create a new Axis object
      91             :     // on each getByIndex
      92             :     uno::Reference< uno::XComponentContext > mxContext;
      93             :     vecAxesIndices mCoordinates;
      94             :     uno::Reference< excel::XChart > mxChart;
      95             : public:
      96           0 :     AxisIndexWrapper( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< excel::XChart >& xChart ) : mxContext( xContext ), mxChart( xChart )
      97             :     {
      98           0 :         if ( mxChart.is() )
      99             :         {
     100           0 :             ScVbaChart* pChart = static_cast< ScVbaChart* >( mxChart.get() );
     101             :             // primary
     102           0 :             bool bBool = false;
     103           0 :             uno::Reference< beans::XPropertySet > xDiagramPropertySet( pChart->xDiagramPropertySet() );
     104           0 :             if ( ( xDiagramPropertySet->getPropertyValue("HasXAxis") >>= bBool )  && bBool )
     105           0 :                 mCoordinates.push_back( AxesCoordinate( xlPrimary, xlCategory ) );
     106           0 :             if ( ( xDiagramPropertySet->getPropertyValue("HasYAxis") >>= bBool )  && bBool )
     107           0 :                 mCoordinates.push_back( AxesCoordinate( xlPrimary, xlSeriesAxis ) );
     108             : 
     109           0 :             if (  pChart->is3D() )
     110           0 :                 mCoordinates.push_back( AxesCoordinate( xlPrimary, xlValue ) );
     111             : 
     112             :             // secondary
     113           0 :             if ( ( xDiagramPropertySet->getPropertyValue("HasSecondaryXAxis") >>= bBool )  && bBool )
     114           0 :                 mCoordinates.push_back( AxesCoordinate( xlSecondary, xlCategory ) );
     115           0 :             if ( ( xDiagramPropertySet->getPropertyValue("HasSecondaryYAxis") >>= bBool )  && bBool )
     116           0 :                 mCoordinates.push_back( AxesCoordinate( xlSecondary, xlSeriesAxis ) );
     117             :         }
     118             : 
     119           0 :     }
     120           0 :     virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE { return mCoordinates.size(); }
     121           0 :     virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, ::uno::RuntimeException, std::exception) SAL_OVERRIDE
     122             :     {
     123             :         try
     124             :         {
     125           0 :             AxesCoordinate dIndexes = mCoordinates[ Index ];
     126           0 :             return uno::makeAny( ScVbaAxes::createAxis( mxChart, mxContext, dIndexes.second, dIndexes.first ) );
     127             :         }
     128           0 :         catch (const css::script::BasicErrorException& e)
     129             :         {
     130             :             throw css::lang::WrappedTargetException(
     131             :                    "Error Getting Index!",
     132             :                    static_cast < OWeakObject * > ( this ),
     133           0 :                    makeAny( e ) );
     134             :         }
     135             :     }
     136             :     // XElementAccess
     137           0 :     virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     138             :     {
     139           0 :         return cppu::UnoType<excel::XAxis>::get();
     140             :     }
     141           0 :     virtual sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     142             :     {
     143           0 :         return ( mCoordinates.size() > 0 );
     144             :     }
     145             : };
     146             : 
     147           0 : uno::Reference< container::XIndexAccess > createIndexWrapper( const uno::Reference< excel::XChart >& xChart, const uno::Reference< uno::XComponentContext >& xContext )
     148             : {
     149           0 :     return new AxisIndexWrapper( xContext, xChart );
     150             : }
     151             : 
     152             : }
     153             : 
     154             : // #FIXME The collection semantics will never work as this object is not yet initialised correctly
     155           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 )
     156             : {
     157           0 : }
     158             : 
     159             : uno::Type SAL_CALL
     160           0 : ScVbaAxes::getElementType() throw (css::uno::RuntimeException)
     161             : {
     162           0 :     return  cppu::UnoType<excel::XAxes>::get();
     163             : }
     164             : 
     165             : uno::Reference< container::XEnumeration > SAL_CALL
     166           0 : ScVbaAxes::createEnumeration() throw (css::uno::RuntimeException)
     167             : {
     168           0 :     return new EnumWrapper( m_xIndexAccess );
     169             : }
     170             : 
     171             : uno::Any SAL_CALL
     172           0 : ScVbaAxes::Item( const css::uno::Any& _nType, const css::uno::Any& _oAxisGroup) throw (css::script::BasicErrorException, css::uno::RuntimeException)
     173             : {
     174             :     // #TODO map the possible index combinations to a container::XIndexAccess wrapper impl
     175             :     // using a vector of valid std::pair maybe?
     176             :     // bodgy helperapi port bits
     177           0 :     sal_Int32 nAxisGroup = xlPrimary;
     178           0 :     sal_Int32 nType = -1;
     179           0 :     if ( !_nType.hasValue() || ( ( _nType >>= nType ) == false )  )
     180           0 :         throw uno::RuntimeException("Axes::Item Failed to extract type"  );
     181             : 
     182           0 :     if ( _oAxisGroup.hasValue() )
     183           0 :         _oAxisGroup >>= nAxisGroup ;
     184             : 
     185           0 :     return uno::makeAny( createAxis( moChartParent, mxContext, nType, nAxisGroup ) );
     186             : }
     187             : 
     188             : uno::Any
     189           0 : ScVbaAxes::createCollectionObject(const css::uno::Any& aSource)
     190             : {
     191           0 :     return aSource; // pass through ( it's already an XAxis object
     192             : }
     193             : 
     194             : OUString
     195           0 : ScVbaAxes::getServiceImplName()
     196             : {
     197           0 :     return OUString("ScVbaAxes");
     198             : }
     199             : 
     200             : uno::Sequence< OUString >
     201           0 : ScVbaAxes::getServiceNames()
     202             : {
     203           0 :     static uno::Sequence< OUString > aServiceNames;
     204           0 :     if ( aServiceNames.getLength() == 0 )
     205             :     {
     206           0 :         aServiceNames.realloc( 1 );
     207           0 :         aServiceNames[ 0 ] = "ooo.vba.excel.Axes";
     208             :     }
     209           0 :     return aServiceNames;
     210          12 : }
     211             : 
     212             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10