LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbachartobjects.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 87 1.1 %
Date: 2015-06-13 12:38:46 Functions: 2 16 12.5 %
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             : #include "vbachart.hxx"
      20             : #include <com/sun/star/beans/XPropertySet.hpp>
      21             : #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
      22             : #include <com/sun/star/table/XTableChartsSupplier.hpp>
      23             : #include <com/sun/star/table/XTableChart.hpp>
      24             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      25             : #include <ooo/vba/excel/XlChartType.hpp>
      26             : 
      27             : #include "vbachartobjects.hxx"
      28             : #include "vbachartobject.hxx"
      29             : #include "vbaglobals.hxx"
      30             : #include "cellsuno.hxx"
      31             : #include <vector>
      32             : #include <basic/sberrors.hxx>
      33             : 
      34             : using namespace ::com::sun::star;
      35             : using namespace ::ooo::vba;
      36             : 
      37           0 : class ChartObjectEnumerationImpl : public EnumerationHelperImpl
      38             : {
      39             :     uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier;
      40             : 
      41             : public:
      42             : 
      43           0 :     ChartObjectEnumerationImpl( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration, const uno::Reference< drawing::XDrawPageSupplier >& _xDrawPageSupplier, const uno::Reference< XHelperInterface >& _xParent ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( _xParent, xContext, xEnumeration ), xDrawPageSupplier( _xDrawPageSupplier ) {}
      44           0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
      45             :     {
      46           0 :         uno::Any ret;
      47             : 
      48             :         try
      49             :         {
      50           0 :             uno::Reference< table::XTableChart > xTableChart( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
      51             :             // parent Object is sheet
      52           0 :             ret = uno::makeAny(  uno::Reference< excel::XChartObject > ( new ScVbaChartObject(  m_xParent, m_xContext, xTableChart, xDrawPageSupplier ) ) );
      53             :         }
      54           0 :         catch (const lang::WrappedTargetException&)
      55             :         {
      56           0 :             throw;
      57             :         }
      58           0 :         catch (const container::NoSuchElementException&)
      59             :         {
      60           0 :             throw;
      61             :         }
      62           0 :         catch (const uno::RuntimeException&)
      63             :         {
      64           0 :             throw;
      65             :         }
      66           0 :         catch (const uno::Exception& e)
      67             :         {
      68             :             throw lang::WrappedTargetException(
      69             :                     "Error creating ScVbaChartObject!",
      70             :                     static_cast < OWeakObject * > ( this ),
      71           0 :                     makeAny( e ) );
      72             :         }
      73           0 :         return ret;
      74             :     }
      75             : };
      76             : 
      77           0 : ScVbaChartObjects::ScVbaChartObjects( const css::uno::Reference< ov::XHelperInterface >& _xParent, const css::uno::Reference< css::uno::XComponentContext >& _xContext, const css::uno::Reference< css::table::XTableCharts >& _xTableCharts, const uno::Reference< drawing::XDrawPageSupplier >& _xDrawPageSupplier ) : ChartObjects_BASE(_xParent, _xContext, css::uno::Reference< css::container::XIndexAccess >( _xTableCharts, css::uno::UNO_QUERY ) ), xTableCharts( _xTableCharts ) , xDrawPageSupplier( _xDrawPageSupplier )
      78             : {
      79             : 
      80           0 : }
      81             : 
      82             : void
      83           0 : ScVbaChartObjects::removeByName(const OUString& _sChartName)
      84             : {
      85           0 :     xTableCharts->removeByName( _sChartName );
      86           0 : }
      87             : 
      88             : uno::Sequence< OUString >
      89           0 : ScVbaChartObjects::getChartObjectNames() throw( css::script::BasicErrorException )
      90             : {
      91           0 :     uno::Sequence< OUString > sChartNames;
      92             :     try
      93             :     {
      94             :         // c++ hackery
      95           0 :         uno::Reference< uno::XInterface > xIf( xDrawPageSupplier, uno::UNO_QUERY_THROW );
      96           0 :         ScCellRangesBase* pUno= dynamic_cast< ScCellRangesBase* >( xIf.get() );
      97           0 :         ScDocShell* pDocShell = NULL;
      98           0 :         if ( !pUno )
      99           0 :             throw uno::RuntimeException("Failed to obtain the impl class from the drawpage" );
     100           0 :         pDocShell = pUno->GetDocShell();
     101           0 :         if ( !pDocShell )
     102           0 :             throw uno::RuntimeException("Failed to obtain the docshell implclass" );
     103             : 
     104           0 :         uno::Reference< sheet::XSpreadsheetDocument > xSpreadsheetDocument( pDocShell->GetModel(), uno::UNO_QUERY_THROW );
     105           0 :         uno::Reference< sheet::XSpreadsheets > xSpreadsheets = xSpreadsheetDocument->getSheets();
     106           0 :         std::vector< OUString > aChartNamesVector;
     107             : 
     108           0 :         uno::Sequence< OUString > sSheetNames = xSpreadsheets->getElementNames();
     109           0 :         sal_Int32 nItems = sSheetNames.getLength();
     110           0 :         for (sal_Int32 i = 0; i < nItems; i++)
     111             :         {
     112           0 :             uno::Reference< table::XTableChartsSupplier > xLocTableChartsSupplier( xSpreadsheets->getByName(sSheetNames[i]), uno::UNO_QUERY_THROW );
     113           0 :             uno::Sequence< OUString > scurchartnames = xLocTableChartsSupplier->getCharts()->getElementNames();
     114           0 :             sal_Int32 nChartNames = scurchartnames.getLength();
     115           0 :             for (sal_Int32 n = 0; n < nChartNames; n++ )
     116           0 :                 aChartNamesVector.push_back(scurchartnames[n]);
     117           0 :         }
     118           0 :         sChartNames.realloc( aChartNamesVector.size() );
     119           0 :         std::vector< OUString > ::const_iterator it = aChartNamesVector.begin();
     120           0 :         std::vector< OUString > ::const_iterator it_end = aChartNamesVector.end();
     121           0 :         for ( sal_Int32 index = 0 ; it != it_end; ++it, ++index )
     122           0 :             sChartNames[index] = *it;
     123             :     }
     124           0 :     catch (uno::Exception& )
     125             :     {
     126           0 :         throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, OUString() );
     127             :     }
     128           0 :     return sChartNames;
     129             : }
     130             : 
     131             : // XChartObjects
     132             : uno::Any SAL_CALL
     133           0 : ScVbaChartObjects::Add( double _nX, double _nY, double _nWidth, double _nHeight ) throw (script::BasicErrorException, std::exception)
     134             : {
     135             :     try
     136             :     {
     137           0 :         uno::Sequence< table::CellRangeAddress > aCellRangeAddress( 1 );
     138           0 :         awt::Rectangle aRectangle;
     139           0 :         aRectangle.X =  Millimeter::getInHundredthsOfOneMillimeter(_nX);
     140           0 :         aRectangle.Y = Millimeter::getInHundredthsOfOneMillimeter(_nY);
     141           0 :         aRectangle.Width = Millimeter::getInHundredthsOfOneMillimeter(_nWidth);
     142           0 :         aRectangle.Height = Millimeter::getInHundredthsOfOneMillimeter(_nHeight);
     143             :         // Note the space at the end of the stem ("Chart "). In ChartSheets only "Chart" is the stem
     144           0 :         OUString sPersistChartName = ContainerUtilities::getUniqueName( getChartObjectNames(), OUString( "Chart " ) , OUString(), 1);
     145           0 :         xTableCharts->addNewByName(sPersistChartName, aRectangle, aCellRangeAddress, true, false );
     146           0 :         uno::Reference< excel::XChartObject > xChartObject( getItemByStringIndex( sPersistChartName ), uno::UNO_QUERY_THROW );
     147           0 :         xChartObject->getChart()->setChartType(excel::XlChartType::xlColumnClustered);
     148           0 :         return uno::makeAny( xChartObject );
     149             :     }
     150           0 :     catch (const uno::Exception& ex)
     151             :     {
     152             :         OSL_TRACE("AddItem caught exception ->%s", OUStringToOString( ex.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
     153             :     }
     154           0 :     return aNULL();
     155             : }
     156           0 : void SAL_CALL ScVbaChartObjects::Delete(  ) throw (script::BasicErrorException, std::exception)
     157             : {
     158           0 :     uno::Sequence< OUString > sChartNames = xTableCharts->getElementNames();
     159           0 :     sal_Int32 ncount = sChartNames.getLength();
     160           0 :     for (sal_Int32 i = 0; i < ncount ; i++)
     161           0 :         removeByName(sChartNames[i]);
     162           0 : }
     163             : 
     164             : // XEnumerationAccess
     165             : 
     166             : uno::Reference< container::XEnumeration >
     167           0 : ScVbaChartObjects::createEnumeration() throw (uno::RuntimeException)
     168             : {
     169           0 :     css::uno::Reference< container::XEnumerationAccess > xEnumAccess( xTableCharts, uno::UNO_QUERY_THROW );
     170           0 :     return new ChartObjectEnumerationImpl( mxContext, xEnumAccess->createEnumeration(), xDrawPageSupplier, getParent() /* sheet */);
     171             : }
     172             : 
     173             : // XElementAccess
     174             : 
     175             : uno::Type
     176           0 : ScVbaChartObjects::getElementType() throw (uno::RuntimeException)
     177             : {
     178           0 :     return cppu::UnoType<excel::XChartObject>::get();
     179             : }
     180             : 
     181             : // ScVbaCollectionBaseImpl
     182             : uno::Any
     183           0 : ScVbaChartObjects::createCollectionObject( const css::uno::Any& aSource )
     184             : {
     185           0 :     uno::Reference< table::XTableChart > xTableChart( aSource, uno::UNO_QUERY_THROW );
     186             :     // correct parent object is sheet
     187           0 :     return uno::makeAny( uno::Reference< excel::XChartObject > ( new ScVbaChartObject( getParent(), mxContext, xTableChart, xDrawPageSupplier ) ) );
     188             : }
     189             : 
     190             : OUString
     191           0 : ScVbaChartObjects::getServiceImplName()
     192             : {
     193           0 :     return OUString("ScVbaChartObjects");
     194             : }
     195             : 
     196             : css::uno::Sequence<OUString>
     197           0 : ScVbaChartObjects::getServiceNames()
     198             : {
     199           0 :     static uno::Sequence< OUString > sNames;
     200           0 :     if ( sNames.getLength() == 0 )
     201             :     {
     202           0 :         sNames.realloc( 1 );
     203           0 :         sNames[0] = "ooo.vba.excel.ChartObjects";
     204             :     }
     205           0 :     return sNames;
     206           9 : }
     207             : 
     208             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11