GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / sc / source / ui / vba / vbachartobject.cxx
blobe63141fd9569fd89dfa431b77c4941223b9368da
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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"
28 using namespace ::com::sun::star;
29 using namespace ::ooo::vba;
31 const OUString PERSIST_NAME("PersistName");
33 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 )
35 xDrawPage = xDrawPageSupplier->getDrawPage();
36 xEmbeddedObjectSupplier.set( xTableChart, uno::UNO_QUERY_THROW );
37 xNamed.set( xTableChart, uno::UNO_QUERY_THROW );
38 sPersistName = getPersistName();
39 xShape = setShape();
40 setName(sPersistName);
41 oShapeHelper.reset(new ShapeHelper(xShape));
44 OUString ScVbaChartObject::getPersistName()
46 if ( sPersistName.isEmpty() )
47 sPersistName = xNamed->getName();
48 return sPersistName;
51 uno::Reference< drawing::XShape >
52 ScVbaChartObject::setShape() throw ( script::BasicErrorException )
54 try
56 sal_Int32 nItems = xDrawPage->getCount();
57 for (int i = 0; i < nItems; i++)
59 xShape.set( xDrawPage->getByIndex(i), uno::UNO_QUERY_THROW );
60 if (xShape->getShapeType().equalsAscii("com.sun.star.drawing.OLE2Shape") )
62 uno::Reference< beans::XPropertySet > xShapePropertySet(xShape, uno::UNO_QUERY_THROW );
63 OUString sName;
64 xShapePropertySet->getPropertyValue(PERSIST_NAME ) >>=sName;
65 if ( sName.equals(sPersistName))
67 xNamedShape.set( xShape, uno::UNO_QUERY_THROW );
68 return xShape;
73 catch (uno::Exception& )
75 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, OUString() );
77 return NULL;
80 void SAL_CALL
81 ScVbaChartObject::setName( const OUString& sName ) throw (css::uno::RuntimeException)
83 xNamedShape->setName(sName);
87 OUString SAL_CALL
88 ScVbaChartObject::getName() throw (css::uno::RuntimeException)
90 return xNamedShape->getName();
93 void SAL_CALL
94 ScVbaChartObject::Delete() throw ( css::script::BasicErrorException )
96 // parent of this object is sheet
97 uno::Reference< excel::XWorksheet > xParent( getParent(), uno::UNO_QUERY_THROW );
98 uno::Reference< excel::XChartObjects > xColl( xParent->ChartObjects( uno::Any() ), uno::UNO_QUERY_THROW );
99 ScVbaChartObjects* pChartObjectsImpl = static_cast< ScVbaChartObjects* >( xColl.get() );
100 if (pChartObjectsImpl)
101 pChartObjectsImpl->removeByName( getPersistName() );
102 else
103 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, OUString( "Parent is not ChartObjects" ) );
106 void
107 ScVbaChartObject::Activate() throw ( script::BasicErrorException )
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 uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getCurrentExcelDoc(mxContext)->getCurrentController(), uno::UNO_QUERY_THROW );
116 xSelectionSupplier->select(uno::makeAny(xShape));
118 catch (uno::Exception& )
120 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, OUString( "ChartObject Activate internal error" ) );
124 uno::Reference< excel::XChart > SAL_CALL
125 ScVbaChartObject::getChart() throw (css::uno::RuntimeException)
127 return new ScVbaChart( this, mxContext, xEmbeddedObjectSupplier->getEmbeddedObject(), xTableChart );
130 OUString
131 ScVbaChartObject::getServiceImplName()
133 return OUString("ScVbaChartObject");
136 uno::Sequence< OUString >
137 ScVbaChartObject::getServiceNames()
139 static uno::Sequence< OUString > aServiceNames;
140 if ( aServiceNames.getLength() == 0 )
142 aServiceNames.realloc( 1 );
143 aServiceNames[ 0 ] = "ooo.vba.excel.ChartObject";
145 return aServiceNames;
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */