LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbachartobject.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 59 0.0 %
Date: 2014-04-14 Functions: 0 12 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             : #include "vbachart.hxx"
      20             : #include <com/sun/star/beans/XPropertySet.hpp>
      21             : #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
      22             : #include <com/sun/star/container/XNamed.hpp>
      23             : #include <com/sun/star/script/BasicErrorException.hpp>
      24             : #include <basic/sberrors.hxx>
      25             : #include "vbachartobject.hxx"
      26             : #include "vbachartobjects.hxx"
      27             : 
      28             : using namespace ::com::sun::star;
      29             : using namespace ::ooo::vba;
      30             : 
      31           0 : const OUString PERSIST_NAME("PersistName");
      32             : 
      33           0 : ScVbaChartObject::ScVbaChartObject( const css::uno::Reference< ov::XHelperInterface >& _xParent, const css::uno::Reference< css::uno::XComponentContext >& _xContext, const css::uno::Reference< css::table::XTableChart >& _xTableChart, const css::uno::Reference< css::drawing::XDrawPageSupplier >& _xDrawPageSupplier ) : ChartObjectImpl_BASE( _xParent, _xContext ), xTableChart( _xTableChart ), xDrawPageSupplier( _xDrawPageSupplier )
      34             : {
      35           0 :         xDrawPage = xDrawPageSupplier->getDrawPage();
      36           0 :         xEmbeddedObjectSupplier.set( xTableChart, uno::UNO_QUERY_THROW );
      37           0 :         xNamed.set( xTableChart, uno::UNO_QUERY_THROW );
      38           0 :         sPersistName = getPersistName();
      39           0 :         xShape = setShape();
      40           0 :         setName(sPersistName);
      41           0 :         oShapeHelper.reset(new ShapeHelper(xShape));
      42           0 : }
      43             : 
      44           0 : OUString ScVbaChartObject::getPersistName()
      45             : {
      46           0 :     if ( sPersistName.isEmpty() )
      47           0 :         sPersistName = xNamed->getName();
      48           0 :     return sPersistName;
      49             : }
      50             : 
      51             : uno::Reference< drawing::XShape >
      52           0 : ScVbaChartObject::setShape() throw ( script::BasicErrorException )
      53             : {
      54             :     try
      55             :     {
      56           0 :         sal_Int32 nItems = xDrawPage->getCount();
      57           0 :         for (int i = 0; i < nItems; i++)
      58             :         {
      59           0 :             xShape.set( xDrawPage->getByIndex(i), uno::UNO_QUERY_THROW );
      60           0 :             if (xShape->getShapeType().equalsAscii("com.sun.star.drawing.OLE2Shape") )
      61             :             {
      62           0 :                 uno::Reference< beans::XPropertySet > xShapePropertySet(xShape, uno::UNO_QUERY_THROW );
      63           0 :                 OUString sName;
      64           0 :                 xShapePropertySet->getPropertyValue(PERSIST_NAME ) >>=sName;
      65           0 :                 if ( sName.equals(sPersistName))
      66             :                 {
      67           0 :                     xNamedShape.set( xShape, uno::UNO_QUERY_THROW );
      68           0 :                     return xShape;
      69           0 :                 }
      70             :             }
      71             :         }
      72             :     }
      73           0 :     catch (uno::Exception& )
      74             :     {
      75           0 :         throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, OUString() );
      76             :     }
      77           0 :     return NULL;
      78             : }
      79             : 
      80             : void SAL_CALL
      81           0 : ScVbaChartObject::setName( const OUString& sName ) throw (css::uno::RuntimeException, std::exception)
      82             : {
      83           0 :     xNamedShape->setName(sName);
      84           0 : }
      85             : 
      86             : 
      87             : OUString SAL_CALL
      88           0 : ScVbaChartObject::getName() throw (css::uno::RuntimeException, std::exception)
      89             : {
      90           0 :     return xNamedShape->getName();
      91             : }
      92             : 
      93             : void SAL_CALL
      94           0 : ScVbaChartObject::Delete() throw ( css::script::BasicErrorException, std::exception )
      95             : {
      96             :     // parent of this object is sheet
      97           0 :     uno::Reference< excel::XWorksheet > xParent( getParent(), uno::UNO_QUERY_THROW );
      98           0 :     uno::Reference< excel::XChartObjects > xColl( xParent->ChartObjects( uno::Any() ), uno::UNO_QUERY_THROW );
      99           0 :     ScVbaChartObjects* pChartObjectsImpl = static_cast< ScVbaChartObjects* >( xColl.get() );
     100           0 :     if (pChartObjectsImpl)
     101           0 :         pChartObjectsImpl->removeByName( getPersistName() );
     102             :     else
     103           0 :         throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, OUString( "Parent is not ChartObjects" ) );
     104           0 : }
     105             : 
     106             : void
     107           0 : ScVbaChartObject::Activate() throw ( script::BasicErrorException )
     108             : {
     109             :     try
     110             :     {
     111             :         // #TODO #FIXME should be ThisWorkbook or equivelant, or in
     112             :         // fact probably the chart object should be created with
     113             :         // the XModel owner
     114             :         //uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getXModel().getCurrentController());
     115           0 :         uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getCurrentExcelDoc(mxContext)->getCurrentController(), uno::UNO_QUERY_THROW );
     116           0 :         xSelectionSupplier->select(uno::makeAny(xShape));
     117             :     }
     118           0 :     catch (uno::Exception& )
     119             :     {
     120           0 :         throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, OUString( "ChartObject Activate internal error" ) );
     121             :     }
     122           0 : }
     123             : 
     124             : uno::Reference< excel::XChart > SAL_CALL
     125           0 : ScVbaChartObject::getChart() throw (css::uno::RuntimeException, std::exception)
     126             : {
     127           0 :     return new ScVbaChart( this, mxContext, xEmbeddedObjectSupplier->getEmbeddedObject(), xTableChart );
     128             : }
     129             : 
     130             : OUString
     131           0 : ScVbaChartObject::getServiceImplName()
     132             : {
     133           0 :     return OUString("ScVbaChartObject");
     134             : }
     135             : 
     136             : uno::Sequence< OUString >
     137           0 : ScVbaChartObject::getServiceNames()
     138             : {
     139           0 :     static uno::Sequence< OUString > aServiceNames;
     140           0 :     if ( aServiceNames.getLength() == 0 )
     141             :     {
     142           0 :         aServiceNames.realloc( 1 );
     143           0 :         aServiceNames[ 0 ] = "ooo.vba.excel.ChartObject";
     144             :     }
     145           0 :     return aServiceNames;
     146           0 : }
     147             : 
     148             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10