1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #include "vbachart.hxx" 28*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 29*cdf0e10cSrcweir #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp> 30*cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/script/BasicErrorException.hpp> 32*cdf0e10cSrcweir #include <basic/sberrors.hxx> 33*cdf0e10cSrcweir #include "vbachartobject.hxx" 34*cdf0e10cSrcweir #include "vbachartobjects.hxx" 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir using namespace ::com::sun::star; 37*cdf0e10cSrcweir using namespace ::ooo::vba; 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir const rtl::OUString CHART_NAME( RTL_CONSTASCII_USTRINGPARAM("Name") ); 40*cdf0e10cSrcweir const rtl::OUString PERSIST_NAME( RTL_CONSTASCII_USTRINGPARAM("PersistName") ); 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir 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 ) 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir xDrawPage = xDrawPageSupplier->getDrawPage(); 45*cdf0e10cSrcweir xEmbeddedObjectSupplier.set( xTableChart, uno::UNO_QUERY_THROW ); 46*cdf0e10cSrcweir xNamed.set( xTableChart, uno::UNO_QUERY_THROW ); 47*cdf0e10cSrcweir sPersistName = getPersistName(); 48*cdf0e10cSrcweir xShape = setShape(); 49*cdf0e10cSrcweir setName(sPersistName); 50*cdf0e10cSrcweir oShapeHelper.reset(new ShapeHelper(xShape)); 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir rtl::OUString ScVbaChartObject::getPersistName() 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir if ( !sPersistName.getLength() ) 56*cdf0e10cSrcweir sPersistName = xNamed->getName(); 57*cdf0e10cSrcweir return sPersistName; 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir uno::Reference< drawing::XShape > 61*cdf0e10cSrcweir ScVbaChartObject::setShape() throw ( script::BasicErrorException ) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir try 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir sal_Int32 nItems = xDrawPage->getCount(); 66*cdf0e10cSrcweir for (int i = 0; i < nItems; i++) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir xShape.set( xDrawPage->getByIndex(i), uno::UNO_QUERY_THROW ); 69*cdf0e10cSrcweir if (xShape->getShapeType().compareToAscii("com.sun.star.drawing.OLE2Shape") == 0 ) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xShapePropertySet(xShape, uno::UNO_QUERY_THROW ); 72*cdf0e10cSrcweir rtl::OUString sName; 73*cdf0e10cSrcweir xShapePropertySet->getPropertyValue(PERSIST_NAME ) >>=sName; 74*cdf0e10cSrcweir if ( sName.equals(sPersistName)) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir xNamedShape.set( xShape, uno::UNO_QUERY_THROW ); 77*cdf0e10cSrcweir return xShape; 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir catch (uno::Exception& ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir return NULL; 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir void SAL_CALL 90*cdf0e10cSrcweir ScVbaChartObject::setName( const rtl::OUString& sName ) throw (css::uno::RuntimeException) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir xNamedShape->setName(sName); 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir ::rtl::OUString SAL_CALL 97*cdf0e10cSrcweir ScVbaChartObject::getName() throw (css::uno::RuntimeException) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir return xNamedShape->getName(); 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir void SAL_CALL 103*cdf0e10cSrcweir ScVbaChartObject::Delete() throw ( css::script::BasicErrorException ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir // parent of this object is sheet 106*cdf0e10cSrcweir uno::Reference< excel::XWorksheet > xParent( getParent(), uno::UNO_QUERY_THROW ); 107*cdf0e10cSrcweir uno::Reference< excel::XChartObjects > xColl( xParent->ChartObjects( uno::Any() ), uno::UNO_QUERY_THROW ); 108*cdf0e10cSrcweir ScVbaChartObjects* pChartObjectsImpl = static_cast< ScVbaChartObjects* >( xColl.get() ); 109*cdf0e10cSrcweir if (pChartObjectsImpl) 110*cdf0e10cSrcweir pChartObjectsImpl->removeByName( getPersistName() ); 111*cdf0e10cSrcweir else 112*cdf0e10cSrcweir throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Parent is not ChartObjects" ) ) ); 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir void 116*cdf0e10cSrcweir ScVbaChartObject::Activate() throw ( script::BasicErrorException ) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir try 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir // #TODO #FIXME should be ThisWorkbook or equivelant, or in 121*cdf0e10cSrcweir // fact probably the chart object should be created with 122*cdf0e10cSrcweir // the XModel owner 123*cdf0e10cSrcweir //uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getXModel().getCurrentController()); 124*cdf0e10cSrcweir uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getCurrentExcelDoc(mxContext)->getCurrentController(), uno::UNO_QUERY_THROW ); 125*cdf0e10cSrcweir xSelectionSupplier->select(uno::makeAny(xShape)); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir catch (uno::Exception& ) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ChartObject Activate internal error" ) ) ); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir uno::Reference< excel::XChart > SAL_CALL 134*cdf0e10cSrcweir ScVbaChartObject::getChart() throw (css::uno::RuntimeException) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir return new ScVbaChart( this, mxContext, xEmbeddedObjectSupplier->getEmbeddedObject(), xTableChart ); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir rtl::OUString& 140*cdf0e10cSrcweir ScVbaChartObject::getServiceImplName() 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaChartObject") ); 143*cdf0e10cSrcweir return sImplName; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir uno::Sequence< rtl::OUString > 147*cdf0e10cSrcweir ScVbaChartObject::getServiceNames() 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 150*cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir aServiceNames.realloc( 1 ); 153*cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.ChartObject" ) ); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir return aServiceNames; 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir double 159*cdf0e10cSrcweir ScVbaChartObject::getHeight() 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir return oShapeHelper->getHeight(); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir void 165*cdf0e10cSrcweir ScVbaChartObject::setHeight(double _fheight) throw ( script::BasicErrorException ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir oShapeHelper->setHeight(_fheight); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir double 171*cdf0e10cSrcweir ScVbaChartObject::getWidth() 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir return oShapeHelper->getWidth(); 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir void 177*cdf0e10cSrcweir ScVbaChartObject::setWidth(double _fWidth) throw ( script::BasicErrorException ) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir oShapeHelper->setWidth(_fWidth); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir double 183*cdf0e10cSrcweir ScVbaChartObject::getLeft() 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir return oShapeHelper->getLeft(); 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir void 189*cdf0e10cSrcweir ScVbaChartObject::setLeft(double _fLeft) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir oShapeHelper->setLeft(_fLeft); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir double 195*cdf0e10cSrcweir ScVbaChartObject::getTop() 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir return oShapeHelper->getTop(); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir void 201*cdf0e10cSrcweir ScVbaChartObject::setTop(double _fTop) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir oShapeHelper->setTop(_fTop); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir uno::Reference< uno::XInterface > 207*cdf0e10cSrcweir ScVbaChartObject::getUnoObject() throw (script::BasicErrorException) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir return uno::Reference< uno::XInterface >( xShape, uno::UNO_QUERY ); 210*cdf0e10cSrcweir } 211