1*b3f79822SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b3f79822SAndrew Rist * distributed with this work for additional information 6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance 9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at 10*b3f79822SAndrew Rist * 11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*b3f79822SAndrew Rist * 13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b3f79822SAndrew Rist * software distributed under the License is distributed on an 15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the 17*b3f79822SAndrew Rist * specific language governing permissions and limitations 18*b3f79822SAndrew Rist * under the License. 19*b3f79822SAndrew Rist * 20*b3f79822SAndrew Rist *************************************************************/ 21*b3f79822SAndrew Rist 22*b3f79822SAndrew Rist 23cdf0e10cSrcweir #include "vbachart.hxx" 24cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 25cdf0e10cSrcweir #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp> 26cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp> 27cdf0e10cSrcweir #include <com/sun/star/script/BasicErrorException.hpp> 28cdf0e10cSrcweir #include <basic/sberrors.hxx> 29cdf0e10cSrcweir #include "vbachartobject.hxx" 30cdf0e10cSrcweir #include "vbachartobjects.hxx" 31cdf0e10cSrcweir 32cdf0e10cSrcweir using namespace ::com::sun::star; 33cdf0e10cSrcweir using namespace ::ooo::vba; 34cdf0e10cSrcweir 35cdf0e10cSrcweir const rtl::OUString CHART_NAME( RTL_CONSTASCII_USTRINGPARAM("Name") ); 36cdf0e10cSrcweir const rtl::OUString PERSIST_NAME( RTL_CONSTASCII_USTRINGPARAM("PersistName") ); 37cdf0e10cSrcweir 38cdf0e10cSrcweir 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 ) 39cdf0e10cSrcweir { 40cdf0e10cSrcweir xDrawPage = xDrawPageSupplier->getDrawPage(); 41cdf0e10cSrcweir xEmbeddedObjectSupplier.set( xTableChart, uno::UNO_QUERY_THROW ); 42cdf0e10cSrcweir xNamed.set( xTableChart, uno::UNO_QUERY_THROW ); 43cdf0e10cSrcweir sPersistName = getPersistName(); 44cdf0e10cSrcweir xShape = setShape(); 45cdf0e10cSrcweir setName(sPersistName); 46cdf0e10cSrcweir oShapeHelper.reset(new ShapeHelper(xShape)); 47cdf0e10cSrcweir } 48cdf0e10cSrcweir 49cdf0e10cSrcweir rtl::OUString ScVbaChartObject::getPersistName() 50cdf0e10cSrcweir { 51cdf0e10cSrcweir if ( !sPersistName.getLength() ) 52cdf0e10cSrcweir sPersistName = xNamed->getName(); 53cdf0e10cSrcweir return sPersistName; 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir uno::Reference< drawing::XShape > 57cdf0e10cSrcweir ScVbaChartObject::setShape() throw ( script::BasicErrorException ) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir try 60cdf0e10cSrcweir { 61cdf0e10cSrcweir sal_Int32 nItems = xDrawPage->getCount(); 62cdf0e10cSrcweir for (int i = 0; i < nItems; i++) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir xShape.set( xDrawPage->getByIndex(i), uno::UNO_QUERY_THROW ); 65cdf0e10cSrcweir if (xShape->getShapeType().compareToAscii("com.sun.star.drawing.OLE2Shape") == 0 ) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xShapePropertySet(xShape, uno::UNO_QUERY_THROW ); 68cdf0e10cSrcweir rtl::OUString sName; 69cdf0e10cSrcweir xShapePropertySet->getPropertyValue(PERSIST_NAME ) >>=sName; 70cdf0e10cSrcweir if ( sName.equals(sPersistName)) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir xNamedShape.set( xShape, uno::UNO_QUERY_THROW ); 73cdf0e10cSrcweir return xShape; 74cdf0e10cSrcweir } 75cdf0e10cSrcweir } 76cdf0e10cSrcweir } 77cdf0e10cSrcweir } 78cdf0e10cSrcweir catch (uno::Exception& ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir return NULL; 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir void SAL_CALL 86cdf0e10cSrcweir ScVbaChartObject::setName( const rtl::OUString& sName ) throw (css::uno::RuntimeException) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir xNamedShape->setName(sName); 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir 92cdf0e10cSrcweir ::rtl::OUString SAL_CALL 93cdf0e10cSrcweir ScVbaChartObject::getName() throw (css::uno::RuntimeException) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir return xNamedShape->getName(); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir void SAL_CALL 99cdf0e10cSrcweir ScVbaChartObject::Delete() throw ( css::script::BasicErrorException ) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir // parent of this object is sheet 102cdf0e10cSrcweir uno::Reference< excel::XWorksheet > xParent( getParent(), uno::UNO_QUERY_THROW ); 103cdf0e10cSrcweir uno::Reference< excel::XChartObjects > xColl( xParent->ChartObjects( uno::Any() ), uno::UNO_QUERY_THROW ); 104cdf0e10cSrcweir ScVbaChartObjects* pChartObjectsImpl = static_cast< ScVbaChartObjects* >( xColl.get() ); 105cdf0e10cSrcweir if (pChartObjectsImpl) 106cdf0e10cSrcweir pChartObjectsImpl->removeByName( getPersistName() ); 107cdf0e10cSrcweir else 108cdf0e10cSrcweir throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Parent is not ChartObjects" ) ) ); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir void 112cdf0e10cSrcweir ScVbaChartObject::Activate() throw ( script::BasicErrorException ) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir try 115cdf0e10cSrcweir { 116cdf0e10cSrcweir // #TODO #FIXME should be ThisWorkbook or equivelant, or in 117cdf0e10cSrcweir // fact probably the chart object should be created with 118cdf0e10cSrcweir // the XModel owner 119cdf0e10cSrcweir //uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getXModel().getCurrentController()); 120cdf0e10cSrcweir uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getCurrentExcelDoc(mxContext)->getCurrentController(), uno::UNO_QUERY_THROW ); 121cdf0e10cSrcweir xSelectionSupplier->select(uno::makeAny(xShape)); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir catch (uno::Exception& ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ChartObject Activate internal error" ) ) ); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir uno::Reference< excel::XChart > SAL_CALL 130cdf0e10cSrcweir ScVbaChartObject::getChart() throw (css::uno::RuntimeException) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir return new ScVbaChart( this, mxContext, xEmbeddedObjectSupplier->getEmbeddedObject(), xTableChart ); 133cdf0e10cSrcweir } 134cdf0e10cSrcweir 135cdf0e10cSrcweir rtl::OUString& 136cdf0e10cSrcweir ScVbaChartObject::getServiceImplName() 137cdf0e10cSrcweir { 138cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaChartObject") ); 139cdf0e10cSrcweir return sImplName; 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir uno::Sequence< rtl::OUString > 143cdf0e10cSrcweir ScVbaChartObject::getServiceNames() 144cdf0e10cSrcweir { 145cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 146cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir aServiceNames.realloc( 1 ); 149cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.ChartObject" ) ); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir return aServiceNames; 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir double 155cdf0e10cSrcweir ScVbaChartObject::getHeight() 156cdf0e10cSrcweir { 157cdf0e10cSrcweir return oShapeHelper->getHeight(); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir void 161cdf0e10cSrcweir ScVbaChartObject::setHeight(double _fheight) throw ( script::BasicErrorException ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir oShapeHelper->setHeight(_fheight); 164cdf0e10cSrcweir } 165cdf0e10cSrcweir 166cdf0e10cSrcweir double 167cdf0e10cSrcweir ScVbaChartObject::getWidth() 168cdf0e10cSrcweir { 169cdf0e10cSrcweir return oShapeHelper->getWidth(); 170cdf0e10cSrcweir } 171cdf0e10cSrcweir 172cdf0e10cSrcweir void 173cdf0e10cSrcweir ScVbaChartObject::setWidth(double _fWidth) throw ( script::BasicErrorException ) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir oShapeHelper->setWidth(_fWidth); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir double 179cdf0e10cSrcweir ScVbaChartObject::getLeft() 180cdf0e10cSrcweir { 181cdf0e10cSrcweir return oShapeHelper->getLeft(); 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir void 185cdf0e10cSrcweir ScVbaChartObject::setLeft(double _fLeft) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir oShapeHelper->setLeft(_fLeft); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir double 191cdf0e10cSrcweir ScVbaChartObject::getTop() 192cdf0e10cSrcweir { 193cdf0e10cSrcweir return oShapeHelper->getTop(); 194cdf0e10cSrcweir } 195cdf0e10cSrcweir 196cdf0e10cSrcweir void 197cdf0e10cSrcweir ScVbaChartObject::setTop(double _fTop) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir oShapeHelper->setTop(_fTop); 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir uno::Reference< uno::XInterface > 203cdf0e10cSrcweir ScVbaChartObject::getUnoObject() throw (script::BasicErrorException) 204cdf0e10cSrcweir { 205cdf0e10cSrcweir return uno::Reference< uno::XInterface >( xShape, uno::UNO_QUERY ); 206cdf0e10cSrcweir } 207