2010-10-12 15:59:00 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2007-04-25 15:02:54 +00:00
/*************************************************************************
*
2008-04-10 23:51:42 +00:00
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER .
2007-04-25 15:02:54 +00:00
*
2010-02-12 15:01:35 +01:00
* Copyright 2000 , 2010 Oracle and / or its affiliates .
2007-04-25 15:02:54 +00:00
*
2008-04-10 23:51:42 +00:00
* OpenOffice . org - a multi - platform office productivity suite
2007-04-25 15:02:54 +00:00
*
2008-04-10 23:51:42 +00:00
* This file is part of OpenOffice . org .
2007-04-25 15:02:54 +00:00
*
2008-04-10 23:51:42 +00:00
* OpenOffice . org is free software : you can redistribute it and / or modify
* it under the terms of the GNU Lesser General Public License version 3
* only , as published by the Free Software Foundation .
2007-04-25 15:02:54 +00:00
*
2008-04-10 23:51:42 +00:00
* OpenOffice . org is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Lesser General Public License version 3 for more details
* ( a copy is included in the LICENSE file that accompanied this code ) .
2007-04-25 15:02:54 +00:00
*
2008-04-10 23:51:42 +00:00
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice . org . If not , see
* < http : //www.openoffice.org/license.html>
* for a copy of the LGPLv3 License .
2007-04-25 15:02:54 +00:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "vbachart.hxx"
# include <com/sun/star/beans/XPropertySet.hpp>
# include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
# include <com/sun/star/container/XNamed.hpp>
2007-12-07 09:46:35 +00:00
# include <com/sun/star/script/BasicErrorException.hpp>
# include <basic/sberrors.hxx>
2007-04-25 15:02:54 +00:00
# include "vbachartobject.hxx"
2007-12-07 09:46:35 +00:00
# include "vbachartobjects.hxx"
2007-04-25 15:02:54 +00:00
using namespace : : com : : sun : : star ;
2009-02-13 13:03:24 +00:00
using namespace : : ooo : : vba ;
2007-04-25 15:02:54 +00:00
const rtl : : OUString CHART_NAME ( RTL_CONSTASCII_USTRINGPARAM ( " Name " ) ) ;
2007-12-07 09:46:35 +00:00
const rtl : : OUString PERSIST_NAME ( RTL_CONSTASCII_USTRINGPARAM ( " PersistName " ) ) ;
2007-04-25 15:02:54 +00:00
2009-02-13 13:03:24 +00:00
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 )
2007-04-25 15:02:54 +00:00
{
2007-12-07 09:46:35 +00:00
xDrawPage = xDrawPageSupplier - > getDrawPage ( ) ;
xEmbeddedObjectSupplier . set ( xTableChart , uno : : UNO_QUERY_THROW ) ;
xNamed . set ( xTableChart , uno : : UNO_QUERY_THROW ) ;
sPersistName = getPersistName ( ) ;
xShape = setShape ( ) ;
setName ( sPersistName ) ;
oShapeHelper . reset ( new ShapeHelper ( xShape ) ) ;
2007-04-25 15:02:54 +00:00
}
2007-12-07 09:46:35 +00:00
rtl : : OUString ScVbaChartObject : : getPersistName ( )
{
if ( ! sPersistName . getLength ( ) )
sPersistName = xNamed - > getName ( ) ;
return sPersistName ;
}
2007-04-25 15:02:54 +00:00
2007-12-07 09:46:35 +00:00
uno : : Reference < drawing : : XShape >
ScVbaChartObject : : setShape ( ) throw ( script : : BasicErrorException )
{
try
{
sal_Int32 nItems = xDrawPage - > getCount ( ) ;
for ( int i = 0 ; i < nItems ; i + + )
{
xShape . set ( xDrawPage - > getByIndex ( i ) , uno : : UNO_QUERY_THROW ) ;
if ( xShape - > getShapeType ( ) . compareToAscii ( " com.sun.star.drawing.OLE2Shape " ) = = 0 )
{
uno : : Reference < beans : : XPropertySet > xShapePropertySet ( xShape , uno : : UNO_QUERY_THROW ) ;
rtl : : OUString sName ;
xShapePropertySet - > getPropertyValue ( PERSIST_NAME ) > > = sName ;
if ( sName . equals ( sPersistName ) )
{
xNamedShape . set ( xShape , uno : : UNO_QUERY_THROW ) ;
return xShape ;
}
}
}
}
catch ( uno : : Exception & )
{
throw script : : BasicErrorException ( rtl : : OUString ( ) , uno : : Reference < uno : : XInterface > ( ) , SbERR_METHOD_FAILED , rtl : : OUString ( ) ) ;
}
return NULL ;
}
2007-04-25 15:02:54 +00:00
2007-12-07 09:46:35 +00:00
void SAL_CALL
ScVbaChartObject : : setName ( const rtl : : OUString & sName ) throw ( css : : uno : : RuntimeException )
2007-04-25 15:02:54 +00:00
{
2007-12-07 09:46:35 +00:00
xNamedShape - > setName ( sName ) ;
}
2007-04-25 15:02:54 +00:00
2007-12-07 09:46:35 +00:00
: : rtl : : OUString SAL_CALL
ScVbaChartObject : : getName ( ) throw ( css : : uno : : RuntimeException )
{
return xNamedShape - > getName ( ) ;
2007-04-25 15:02:54 +00:00
}
2007-12-07 09:46:35 +00:00
void SAL_CALL
ScVbaChartObject : : Delete ( ) throw ( css : : script : : BasicErrorException )
2007-04-25 15:02:54 +00:00
{
2007-12-07 09:46:35 +00:00
// parent of this object is sheet
uno : : Reference < excel : : XWorksheet > xParent ( getParent ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < excel : : XChartObjects > xColl ( xParent - > ChartObjects ( uno : : Any ( ) ) , uno : : UNO_QUERY_THROW ) ;
ScVbaChartObjects * pChartObjectsImpl = static_cast < ScVbaChartObjects * > ( xColl . get ( ) ) ;
if ( pChartObjectsImpl )
pChartObjectsImpl - > removeByName ( getPersistName ( ) ) ;
else
throw script : : BasicErrorException ( rtl : : OUString ( ) , uno : : Reference < uno : : XInterface > ( ) , SbERR_METHOD_FAILED , rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Parent is not ChartObjects " ) ) ) ;
}
void
ScVbaChartObject : : Activate ( ) throw ( script : : BasicErrorException )
{
try
2007-04-25 15:02:54 +00:00
{
2009-09-18 15:24:22 +00:00
// #TODO #FIXME should be ThisWorkbook or equivelant, or in
// fact probably the chart object should be created with
// the XModel owner
2007-12-07 09:46:35 +00:00
//uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getXModel().getCurrentController());
2009-09-18 15:24:22 +00:00
uno : : Reference < view : : XSelectionSupplier > xSelectionSupplier ( getCurrentExcelDoc ( mxContext ) - > getCurrentController ( ) , uno : : UNO_QUERY_THROW ) ;
2007-12-07 09:46:35 +00:00
xSelectionSupplier - > select ( uno : : makeAny ( xShape ) ) ;
2007-04-25 15:02:54 +00:00
}
2007-12-07 09:46:35 +00:00
catch ( uno : : Exception & )
2007-04-25 15:02:54 +00:00
{
2007-12-07 09:46:35 +00:00
throw script : : BasicErrorException ( rtl : : OUString ( ) , uno : : Reference < uno : : XInterface > ( ) , SbERR_METHOD_FAILED , rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " ChartObject Activate internal error " ) ) ) ;
2007-04-25 15:02:54 +00:00
}
2007-12-07 09:46:35 +00:00
}
uno : : Reference < excel : : XChart > SAL_CALL
ScVbaChartObject : : getChart ( ) throw ( css : : uno : : RuntimeException )
{
return new ScVbaChart ( this , mxContext , xEmbeddedObjectSupplier - > getEmbeddedObject ( ) , xTableChart ) ;
}
rtl : : OUString &
ScVbaChartObject : : getServiceImplName ( )
{
static rtl : : OUString sImplName ( RTL_CONSTASCII_USTRINGPARAM ( " ScVbaChartObject " ) ) ;
return sImplName ;
}
uno : : Sequence < rtl : : OUString >
ScVbaChartObject : : getServiceNames ( )
{
static uno : : Sequence < rtl : : OUString > aServiceNames ;
if ( aServiceNames . getLength ( ) = = 0 )
2007-04-25 15:02:54 +00:00
{
2007-12-07 09:46:35 +00:00
aServiceNames . realloc ( 1 ) ;
2009-02-13 13:03:24 +00:00
aServiceNames [ 0 ] = rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " ooo.vba.excel.ChartObject " ) ) ;
2007-04-25 15:02:54 +00:00
}
2007-12-07 09:46:35 +00:00
return aServiceNames ;
}
2010-10-12 15:59:00 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */