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 <com/sun/star/view/XSelectionSupplier.hpp>
25 #include <basic/sberrors.hxx>
27 #include "vbachartobject.hxx"
28 #include "vbachartobjects.hxx"
30 using namespace ::com::sun::star
;
31 using namespace ::ooo::vba
;
33 constexpr OUStringLiteral
PERSIST_NAME(u
"PersistName");
35 ScVbaChartObject::ScVbaChartObject( const css::uno::Reference
< ov::XHelperInterface
>& _xParent
, const css::uno::Reference
< css::uno::XComponentContext
>& _xContext
, css::uno::Reference
< css::table::XTableChart
> _xTableChart
, css::uno::Reference
< css::drawing::XDrawPageSupplier
> _xDrawPageSupplier
) : ChartObjectImpl_BASE( _xParent
, _xContext
), xTableChart(std::move( _xTableChart
)), xDrawPageSupplier(std::move( _xDrawPageSupplier
))
37 xDrawPage
= xDrawPageSupplier
->getDrawPage();
38 xEmbeddedObjectSupplier
.set( xTableChart
, uno::UNO_QUERY_THROW
);
39 xNamed
.set( xTableChart
, uno::UNO_QUERY_THROW
);
40 sPersistName
= getPersistName();
42 setName(sPersistName
);
43 oShapeHelper
.emplace(xShape
);
46 OUString
const & ScVbaChartObject::getPersistName()
48 if ( sPersistName
.isEmpty() )
49 sPersistName
= xNamed
->getName();
53 uno::Reference
< drawing::XShape
>
54 ScVbaChartObject::setShape()
58 sal_Int32 nItems
= xDrawPage
->getCount();
59 for (int i
= 0; i
< nItems
; i
++)
61 xShape
.set( xDrawPage
->getByIndex(i
), uno::UNO_QUERY_THROW
);
62 if (xShape
->getShapeType() == "com.sun.star.drawing.OLE2Shape")
64 uno::Reference
< beans::XPropertySet
> xShapePropertySet(xShape
, uno::UNO_QUERY_THROW
);
66 xShapePropertySet
->getPropertyValue(PERSIST_NAME
) >>=sName
;
67 if ( sName
== sPersistName
)
69 xNamedShape
.set( xShape
, uno::UNO_QUERY_THROW
);
75 catch (uno::Exception
& )
77 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), OUString() );
83 ScVbaChartObject::setName( const OUString
& sName
)
85 xNamedShape
->setName(sName
);
89 ScVbaChartObject::getName()
91 return xNamedShape
->getName();
95 ScVbaChartObject::Delete()
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 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), u
"Parent is not ChartObjects"_ustr
);
104 pChartObjectsImpl
->removeByName( getPersistName() );
109 ScVbaChartObject::Activate()
113 // #TODO #FIXME should be ThisWorkbook or equivalent, or in
114 // fact probably the chart object should be created with
116 //uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getXModel().getCurrentController());
117 uno::Reference
< view::XSelectionSupplier
> xSelectionSupplier( getCurrentExcelDoc(mxContext
)->getCurrentController(), uno::UNO_QUERY_THROW
);
118 xSelectionSupplier
->select(uno::Any(xShape
));
120 catch (uno::Exception
& )
122 throw script::BasicErrorException( OUString(), uno::Reference
< uno::XInterface
>(), sal_uInt32(ERRCODE_BASIC_METHOD_FAILED
), u
"ChartObject Activate internal error"_ustr
);
126 uno::Reference
< excel::XChart
> SAL_CALL
127 ScVbaChartObject::getChart()
129 return new ScVbaChart( this, mxContext
, xEmbeddedObjectSupplier
->getEmbeddedObject(), xTableChart
);
133 ScVbaChartObject::getServiceImplName()
135 return u
"ScVbaChartObject"_ustr
;
138 uno::Sequence
< OUString
>
139 ScVbaChartObject::getServiceNames()
141 static uno::Sequence
< OUString
> const aServiceNames
143 u
"ooo.vba.excel.ChartObject"_ustr
145 return aServiceNames
;
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */