1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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();
40 setName(sPersistName
);
41 oShapeHelper
.reset(new ShapeHelper(xShape
));
44 OUString
ScVbaChartObject::getPersistName()
46 if ( sPersistName
.isEmpty() )
47 sPersistName
= xNamed
->getName();
51 uno::Reference
< drawing::XShape
>
52 ScVbaChartObject::setShape() throw ( script::BasicErrorException
)
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() == "com.sun.star.drawing.OLE2Shape")
62 uno::Reference
< beans::XPropertySet
> xShapePropertySet(xShape
, uno::UNO_QUERY_THROW
);
64 xShapePropertySet
->getPropertyValue(PERSIST_NAME
) >>=sName
;
65 if ( sName
.equals(sPersistName
))
67 xNamedShape
.set( xShape
, uno::UNO_QUERY_THROW
);
73 catch (uno::Exception
& )
75 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString() );
81 ScVbaChartObject::setName( const OUString
& sName
) throw (css::uno::RuntimeException
, std::exception
)
83 xNamedShape
->setName(sName
);
87 ScVbaChartObject::getName() throw (css::uno::RuntimeException
, std::exception
)
89 return xNamedShape
->getName();
93 ScVbaChartObject::Delete()
94 throw (css::script::BasicErrorException
,
95 css::uno::RuntimeException
, std::exception
)
97 // parent of this object is sheet
98 uno::Reference
< excel::XWorksheet
> xParent( getParent(), uno::UNO_QUERY_THROW
);
99 uno::Reference
< excel::XChartObjects
> xColl( xParent
->ChartObjects( uno::Any() ), uno::UNO_QUERY_THROW
);
100 ScVbaChartObjects
* pChartObjectsImpl
= static_cast< ScVbaChartObjects
* >( xColl
.get() );
101 if (pChartObjectsImpl
)
102 pChartObjectsImpl
->removeByName( getPersistName() );
104 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString( "Parent is not ChartObjects" ) );
108 ScVbaChartObject::Activate() throw ( script::BasicErrorException
)
112 // #TODO #FIXME should be ThisWorkbook or equivalent, or in
113 // fact probably the chart object should be created with
115 //uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getXModel().getCurrentController());
116 uno::Reference
< view::XSelectionSupplier
> xSelectionSupplier( getCurrentExcelDoc(mxContext
)->getCurrentController(), uno::UNO_QUERY_THROW
);
117 xSelectionSupplier
->select(uno::makeAny(xShape
));
119 catch (uno::Exception
& )
121 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, OUString( "ChartObject Activate internal error" ) );
125 uno::Reference
< excel::XChart
> SAL_CALL
126 ScVbaChartObject::getChart() throw (css::uno::RuntimeException
, std::exception
)
128 return new ScVbaChart( this, mxContext
, xEmbeddedObjectSupplier
->getEmbeddedObject(), xTableChart
);
132 ScVbaChartObject::getServiceImplName()
134 return OUString("ScVbaChartObject");
137 uno::Sequence
< OUString
>
138 ScVbaChartObject::getServiceNames()
140 static uno::Sequence
< OUString
> aServiceNames
;
141 if ( aServiceNames
.getLength() == 0 )
143 aServiceNames
.realloc( 1 );
144 aServiceNames
[ 0 ] = "ooo.vba.excel.ChartObject";
146 return aServiceNames
;
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */