Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #include "vbachart.hxx"
29 : : #include <com/sun/star/beans/XPropertySet.hpp>
30 : : #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
31 : : #include <com/sun/star/container/XNamed.hpp>
32 : : #include <com/sun/star/script/BasicErrorException.hpp>
33 : : #include <basic/sberrors.hxx>
34 : : #include "vbachartobject.hxx"
35 : : #include "vbachartobjects.hxx"
36 : :
37 : : using namespace ::com::sun::star;
38 : : using namespace ::ooo::vba;
39 : :
40 : 3 : const rtl::OUString PERSIST_NAME( RTL_CONSTASCII_USTRINGPARAM("PersistName") );
41 : :
42 : 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 )
43 : : {
44 [ # # ][ # # ]: 0 : xDrawPage = xDrawPageSupplier->getDrawPage();
[ # # ]
45 [ # # ]: 0 : xEmbeddedObjectSupplier.set( xTableChart, uno::UNO_QUERY_THROW );
46 [ # # ]: 0 : xNamed.set( xTableChart, uno::UNO_QUERY_THROW );
47 [ # # ]: 0 : sPersistName = getPersistName();
48 [ # # ][ # # ]: 0 : xShape = setShape();
49 [ # # ]: 0 : setName(sPersistName);
50 [ # # ][ # # ]: 0 : oShapeHelper.reset(new ShapeHelper(xShape));
51 : 0 : }
52 : :
53 : 0 : rtl::OUString ScVbaChartObject::getPersistName()
54 : : {
55 [ # # ]: 0 : if ( sPersistName.isEmpty() )
56 : 0 : sPersistName = xNamed->getName();
57 : 0 : return sPersistName;
58 : : }
59 : :
60 : : uno::Reference< drawing::XShape >
61 : 0 : ScVbaChartObject::setShape() throw ( script::BasicErrorException )
62 : : {
63 : : try
64 : : {
65 [ # # ][ # # ]: 0 : sal_Int32 nItems = xDrawPage->getCount();
66 [ # # ]: 0 : for (int i = 0; i < nItems; i++)
67 : : {
68 [ # # ][ # # ]: 0 : xShape.set( xDrawPage->getByIndex(i), uno::UNO_QUERY_THROW );
[ # # ]
69 [ # # ][ # # ]: 0 : if (xShape->getShapeType().compareToAscii("com.sun.star.drawing.OLE2Shape") == 0 )
[ # # ]
70 : : {
71 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xShapePropertySet(xShape, uno::UNO_QUERY_THROW );
72 : 0 : rtl::OUString sName;
73 [ # # ][ # # ]: 0 : xShapePropertySet->getPropertyValue(PERSIST_NAME ) >>=sName;
74 [ # # ]: 0 : if ( sName.equals(sPersistName))
75 : : {
76 [ # # ]: 0 : xNamedShape.set( xShape, uno::UNO_QUERY_THROW );
77 : 0 : return xShape;
78 [ # # ][ # # ]: 0 : }
79 : : }
80 : : }
81 : : }
82 [ # # ]: 0 : catch (uno::Exception& )
83 : : {
84 [ # # ]: 0 : throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() );
85 : : }
86 : 0 : return NULL;
87 : : }
88 : :
89 : : void SAL_CALL
90 : 0 : ScVbaChartObject::setName( const rtl::OUString& sName ) throw (css::uno::RuntimeException)
91 : : {
92 : 0 : xNamedShape->setName(sName);
93 : 0 : }
94 : :
95 : :
96 : : ::rtl::OUString SAL_CALL
97 : 0 : ScVbaChartObject::getName() throw (css::uno::RuntimeException)
98 : : {
99 : 0 : return xNamedShape->getName();
100 : : }
101 : :
102 : : void SAL_CALL
103 : 0 : ScVbaChartObject::Delete() throw ( css::script::BasicErrorException )
104 : : {
105 : : // parent of this object is sheet
106 [ # # ][ # # ]: 0 : uno::Reference< excel::XWorksheet > xParent( getParent(), uno::UNO_QUERY_THROW );
107 [ # # ][ # # ]: 0 : uno::Reference< excel::XChartObjects > xColl( xParent->ChartObjects( uno::Any() ), uno::UNO_QUERY_THROW );
[ # # ]
108 [ # # ][ # # ]: 0 : ScVbaChartObjects* pChartObjectsImpl = static_cast< ScVbaChartObjects* >( xColl.get() );
109 [ # # ]: 0 : if (pChartObjectsImpl)
110 [ # # ][ # # ]: 0 : pChartObjectsImpl->removeByName( getPersistName() );
111 : : else
112 [ # # ][ # # ]: 0 : throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Parent is not ChartObjects" ) ) );
113 : 0 : }
114 : :
115 : : void
116 : 0 : ScVbaChartObject::Activate() throw ( script::BasicErrorException )
117 : : {
118 : : try
119 : : {
120 : : // #TODO #FIXME should be ThisWorkbook or equivelant, or in
121 : : // fact probably the chart object should be created with
122 : : // the XModel owner
123 : : //uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getXModel().getCurrentController());
124 [ # # ][ # # ]: 0 : uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getCurrentExcelDoc(mxContext)->getCurrentController(), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
125 [ # # ][ # # ]: 0 : xSelectionSupplier->select(uno::makeAny(xShape));
[ # # ]
126 : : }
127 [ # # ]: 0 : catch (uno::Exception& )
128 : : {
129 [ # # # # ]: 0 : throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ChartObject Activate internal error" ) ) );
130 : : }
131 : 0 : }
132 : :
133 : : uno::Reference< excel::XChart > SAL_CALL
134 : 0 : ScVbaChartObject::getChart() throw (css::uno::RuntimeException)
135 : : {
136 [ # # ][ # # ]: 0 : return new ScVbaChart( this, mxContext, xEmbeddedObjectSupplier->getEmbeddedObject(), xTableChart );
[ # # ][ # # ]
[ # # ]
137 : : }
138 : :
139 : : rtl::OUString
140 : 0 : ScVbaChartObject::getServiceImplName()
141 : : {
142 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScVbaChartObject"));
143 : : }
144 : :
145 : : uno::Sequence< rtl::OUString >
146 : 0 : ScVbaChartObject::getServiceNames()
147 : : {
148 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
149 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
150 : : {
151 : 0 : aServiceNames.realloc( 1 );
152 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.ChartObject" ) );
153 : : }
154 : 0 : return aServiceNames;
155 [ + - ][ + - ]: 9 : }
156 : :
157 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|