Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
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"
27 :
28 : using namespace ::com::sun::star;
29 : using namespace ::ooo::vba;
30 :
31 3 : const OUString PERSIST_NAME("PersistName");
32 :
33 0 : 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 )
34 : {
35 0 : xDrawPage = xDrawPageSupplier->getDrawPage();
36 0 : xEmbeddedObjectSupplier.set( xTableChart, uno::UNO_QUERY_THROW );
37 0 : xNamed.set( xTableChart, uno::UNO_QUERY_THROW );
38 0 : sPersistName = getPersistName();
39 0 : xShape = setShape();
40 0 : setName(sPersistName);
41 0 : oShapeHelper.reset(new ShapeHelper(xShape));
42 0 : }
43 :
44 0 : OUString ScVbaChartObject::getPersistName()
45 : {
46 0 : if ( sPersistName.isEmpty() )
47 0 : sPersistName = xNamed->getName();
48 0 : return sPersistName;
49 : }
50 :
51 : uno::Reference< drawing::XShape >
52 0 : ScVbaChartObject::setShape() throw ( script::BasicErrorException )
53 : {
54 : try
55 : {
56 0 : sal_Int32 nItems = xDrawPage->getCount();
57 0 : for (int i = 0; i < nItems; i++)
58 : {
59 0 : xShape.set( xDrawPage->getByIndex(i), uno::UNO_QUERY_THROW );
60 0 : if (xShape->getShapeType() == "com.sun.star.drawing.OLE2Shape")
61 : {
62 0 : uno::Reference< beans::XPropertySet > xShapePropertySet(xShape, uno::UNO_QUERY_THROW );
63 0 : OUString sName;
64 0 : xShapePropertySet->getPropertyValue(PERSIST_NAME ) >>=sName;
65 0 : if ( sName.equals(sPersistName))
66 : {
67 0 : xNamedShape.set( xShape, uno::UNO_QUERY_THROW );
68 0 : return xShape;
69 0 : }
70 : }
71 : }
72 : }
73 0 : catch (uno::Exception& )
74 : {
75 0 : throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, OUString() );
76 : }
77 0 : return NULL;
78 : }
79 :
80 : void SAL_CALL
81 0 : ScVbaChartObject::setName( const OUString& sName ) throw (css::uno::RuntimeException, std::exception)
82 : {
83 0 : xNamedShape->setName(sName);
84 0 : }
85 :
86 : OUString SAL_CALL
87 0 : ScVbaChartObject::getName() throw (css::uno::RuntimeException, std::exception)
88 : {
89 0 : return xNamedShape->getName();
90 : }
91 :
92 : void SAL_CALL
93 0 : ScVbaChartObject::Delete()
94 : throw (css::script::BasicErrorException,
95 : css::uno::RuntimeException, std::exception)
96 : {
97 : // parent of this object is sheet
98 0 : uno::Reference< excel::XWorksheet > xParent( getParent(), uno::UNO_QUERY_THROW );
99 0 : uno::Reference< excel::XChartObjects > xColl( xParent->ChartObjects( uno::Any() ), uno::UNO_QUERY_THROW );
100 0 : ScVbaChartObjects* pChartObjectsImpl = static_cast< ScVbaChartObjects* >( xColl.get() );
101 0 : if (pChartObjectsImpl)
102 0 : pChartObjectsImpl->removeByName( getPersistName() );
103 : else
104 0 : throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, OUString( "Parent is not ChartObjects" ) );
105 0 : }
106 :
107 : void
108 0 : ScVbaChartObject::Activate() throw ( script::BasicErrorException )
109 : {
110 : try
111 : {
112 : // #TODO #FIXME should be ThisWorkbook or equivalent, or in
113 : // fact probably the chart object should be created with
114 : // the XModel owner
115 : //uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getXModel().getCurrentController());
116 0 : uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getCurrentExcelDoc(mxContext)->getCurrentController(), uno::UNO_QUERY_THROW );
117 0 : xSelectionSupplier->select(uno::makeAny(xShape));
118 : }
119 0 : catch (uno::Exception& )
120 : {
121 0 : throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, OUString( "ChartObject Activate internal error" ) );
122 : }
123 0 : }
124 :
125 : uno::Reference< excel::XChart > SAL_CALL
126 0 : ScVbaChartObject::getChart() throw (css::uno::RuntimeException, std::exception)
127 : {
128 0 : return new ScVbaChart( this, mxContext, xEmbeddedObjectSupplier->getEmbeddedObject(), xTableChart );
129 : }
130 :
131 : OUString
132 0 : ScVbaChartObject::getServiceImplName()
133 : {
134 0 : return OUString("ScVbaChartObject");
135 : }
136 :
137 : uno::Sequence< OUString >
138 0 : ScVbaChartObject::getServiceNames()
139 : {
140 0 : static uno::Sequence< OUString > aServiceNames;
141 0 : if ( aServiceNames.getLength() == 0 )
142 : {
143 0 : aServiceNames.realloc( 1 );
144 0 : aServiceNames[ 0 ] = "ooo.vba.excel.ChartObject";
145 : }
146 0 : return aServiceNames;
147 9 : }
148 :
149 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|