1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbachartobject.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "vbachart.hxx"
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
33 #include <com/sun/star/container/XNamed.hpp>
34 #include <com/sun/star/script/BasicErrorException.hpp>
35 #include <basic/sberrors.hxx>
36 #include "vbachartobject.hxx"
37 #include "vbachartobjects.hxx"
39 using namespace ::com::sun::star
;
40 using namespace ::ooo::vba
;
42 const rtl::OUString
CHART_NAME( RTL_CONSTASCII_USTRINGPARAM("Name") );
43 const rtl::OUString
PERSIST_NAME( RTL_CONSTASCII_USTRINGPARAM("PersistName") );
45 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
)
47 xDrawPage
= xDrawPageSupplier
->getDrawPage();
48 xEmbeddedObjectSupplier
.set( xTableChart
, uno::UNO_QUERY_THROW
);
49 xNamed
.set( xTableChart
, uno::UNO_QUERY_THROW
);
50 sPersistName
= getPersistName();
52 setName(sPersistName
);
53 oShapeHelper
.reset(new ShapeHelper(xShape
));
56 rtl::OUString
ScVbaChartObject::getPersistName()
58 if ( !sPersistName
.getLength() )
59 sPersistName
= xNamed
->getName();
63 uno::Reference
< drawing::XShape
>
64 ScVbaChartObject::setShape() throw ( script::BasicErrorException
)
68 sal_Int32 nItems
= xDrawPage
->getCount();
69 for (int i
= 0; i
< nItems
; i
++)
71 xShape
.set( xDrawPage
->getByIndex(i
), uno::UNO_QUERY_THROW
);
72 if (xShape
->getShapeType().compareToAscii("com.sun.star.drawing.OLE2Shape") == 0 )
74 uno::Reference
< beans::XPropertySet
> xShapePropertySet(xShape
, uno::UNO_QUERY_THROW
);
76 xShapePropertySet
->getPropertyValue(PERSIST_NAME
) >>=sName
;
77 if ( sName
.equals(sPersistName
))
79 xNamedShape
.set( xShape
, uno::UNO_QUERY_THROW
);
85 catch (uno::Exception
& )
87 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString() );
93 ScVbaChartObject::setName( const rtl::OUString
& sName
) throw (css::uno::RuntimeException
)
95 xNamedShape
->setName(sName
);
99 ::rtl::OUString SAL_CALL
100 ScVbaChartObject::getName() throw (css::uno::RuntimeException
)
102 return xNamedShape
->getName();
106 ScVbaChartObject::Delete() throw ( css::script::BasicErrorException
)
108 // parent of this object is sheet
109 uno::Reference
< excel::XWorksheet
> xParent( getParent(), uno::UNO_QUERY_THROW
);
110 uno::Reference
< excel::XChartObjects
> xColl( xParent
->ChartObjects( uno::Any() ), uno::UNO_QUERY_THROW
);
111 ScVbaChartObjects
* pChartObjectsImpl
= static_cast< ScVbaChartObjects
* >( xColl
.get() );
112 if (pChartObjectsImpl
)
113 pChartObjectsImpl
->removeByName( getPersistName() );
115 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Parent is not ChartObjects" ) ) );
119 ScVbaChartObject::Activate() throw ( script::BasicErrorException
)
123 // #TODO #FIXME should be ThisWorkbook or equivelant, or in
124 // fact probably the chart object should be created with
126 //uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getXModel().getCurrentController());
127 uno::Reference
< view::XSelectionSupplier
> xSelectionSupplier( getCurrentExcelDoc(mxContext
)->getCurrentController(), uno::UNO_QUERY_THROW
);
128 xSelectionSupplier
->select(uno::makeAny(xShape
));
130 catch (uno::Exception
& )
132 throw script::BasicErrorException( rtl::OUString(), uno::Reference
< uno::XInterface
>(), SbERR_METHOD_FAILED
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ChartObject Activate internal error" ) ) );
136 uno::Reference
< excel::XChart
> SAL_CALL
137 ScVbaChartObject::getChart() throw (css::uno::RuntimeException
)
139 return new ScVbaChart( this, mxContext
, xEmbeddedObjectSupplier
->getEmbeddedObject(), xTableChart
);
143 ScVbaChartObject::getServiceImplName()
145 static rtl::OUString
sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaChartObject") );
149 uno::Sequence
< rtl::OUString
>
150 ScVbaChartObject::getServiceNames()
152 static uno::Sequence
< rtl::OUString
> aServiceNames
;
153 if ( aServiceNames
.getLength() == 0 )
155 aServiceNames
.realloc( 1 );
156 aServiceNames
[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.ChartObject" ) );
158 return aServiceNames
;
162 ScVbaChartObject::getHeight()
164 return oShapeHelper
->getHeight();
168 ScVbaChartObject::setHeight(double _fheight
) throw ( script::BasicErrorException
)
170 oShapeHelper
->setHeight(_fheight
);
174 ScVbaChartObject::getWidth()
176 return oShapeHelper
->getWidth();
180 ScVbaChartObject::setWidth(double _fWidth
) throw ( script::BasicErrorException
)
182 oShapeHelper
->setWidth(_fWidth
);
186 ScVbaChartObject::getLeft()
188 return oShapeHelper
->getLeft();
192 ScVbaChartObject::setLeft(double _fLeft
)
194 oShapeHelper
->setLeft(_fLeft
);
198 ScVbaChartObject::getTop()
200 return oShapeHelper
->getTop();
204 ScVbaChartObject::setTop(double _fTop
)
206 oShapeHelper
->setTop(_fTop
);
209 uno::Reference
< uno::XInterface
>
210 ScVbaChartObject::getUnoObject() throw (script::BasicErrorException
)
212 return uno::Reference
< uno::XInterface
>( xShape
, uno::UNO_QUERY
);