GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / sc / source / ui / vba / vbachartobjects.cxx
blob2494edbb9bbc87c1f51e05c93fdfb5bb4a6906aa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/table/XTableChartsSupplier.hpp>
23 #include <com/sun/star/table/XTableChart.hpp>
24 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
25 #include <ooo/vba/excel/XlChartType.hpp>
28 #include "vbachartobjects.hxx"
29 #include "vbachartobject.hxx"
30 #include "vbaglobals.hxx"
31 #include "cellsuno.hxx"
32 #include <vector>
33 #include <basic/sberrors.hxx>
35 using namespace ::com::sun::star;
36 using namespace ::ooo::vba;
39 class ChartObjectEnumerationImpl : public EnumerationHelperImpl
41 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier;
43 public:
45 ChartObjectEnumerationImpl( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration, const uno::Reference< drawing::XDrawPageSupplier >& _xDrawPageSupplier, const uno::Reference< XHelperInterface >& _xParent ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( _xParent, xContext, xEnumeration ), xDrawPageSupplier( _xDrawPageSupplier ) {}
46 virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
48 uno::Reference< table::XTableChart > xTableChart( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
49 // parent Object is sheet
50 return uno::makeAny( uno::Reference< excel::XChartObject > ( new ScVbaChartObject( m_xParent, m_xContext, xTableChart, xDrawPageSupplier ) ) );
55 ScVbaChartObjects::ScVbaChartObjects( const css::uno::Reference< ov::XHelperInterface >& _xParent, const css::uno::Reference< css::uno::XComponentContext >& _xContext, const css::uno::Reference< css::table::XTableCharts >& _xTableCharts, const uno::Reference< drawing::XDrawPageSupplier >& _xDrawPageSupplier ) : ChartObjects_BASE(_xParent, _xContext, css::uno::Reference< css::container::XIndexAccess >( _xTableCharts, css::uno::UNO_QUERY ) ), xTableCharts( _xTableCharts ) , xDrawPageSupplier( _xDrawPageSupplier )
60 void
61 ScVbaChartObjects::removeByName(const OUString& _sChartName)
63 xTableCharts->removeByName( _sChartName );
66 uno::Sequence< OUString >
67 ScVbaChartObjects::getChartObjectNames() throw( css::script::BasicErrorException )
69 uno::Sequence< OUString > sChartNames;
70 try
72 // c++ hackery
73 uno::Reference< uno::XInterface > xIf( xDrawPageSupplier, uno::UNO_QUERY_THROW );
74 ScCellRangesBase* pUno= dynamic_cast< ScCellRangesBase* >( xIf.get() );
75 ScDocShell* pDocShell = NULL;
76 if ( !pUno )
77 throw uno::RuntimeException("Failed to obtain the impl class from the drawpage", uno::Reference< uno::XInterface >() );
78 pDocShell = pUno->GetDocShell();
79 if ( !pDocShell )
80 throw uno::RuntimeException("Failed to obtain the docshell implclass", uno::Reference< uno::XInterface >() );
82 uno::Reference< sheet::XSpreadsheetDocument > xSpreadsheetDocument( pDocShell->GetModel(), uno::UNO_QUERY_THROW );
83 uno::Reference< sheet::XSpreadsheets > xSpreadsheets = xSpreadsheetDocument->getSheets();
84 std::vector< OUString > aChartNamesVector;
86 uno::Sequence< OUString > sSheetNames = xSpreadsheets->getElementNames();
87 sal_Int32 nItems = sSheetNames.getLength();
88 for (sal_Int32 i = 0; i < nItems; i++)
90 uno::Reference< table::XTableChartsSupplier > xLocTableChartsSupplier( xSpreadsheets->getByName(sSheetNames[i]), uno::UNO_QUERY_THROW );
91 uno::Sequence< OUString > scurchartnames = xLocTableChartsSupplier->getCharts()->getElementNames();
92 sal_Int32 nChartNames = scurchartnames.getLength();
93 for (sal_Int32 n = 0; n < nChartNames; n++ )
94 aChartNamesVector.push_back(scurchartnames[n]);
96 sChartNames.realloc( aChartNamesVector.size() );
97 std::vector< OUString > ::const_iterator it = aChartNamesVector.begin();
98 std::vector< OUString > ::const_iterator it_end = aChartNamesVector.end();
99 for ( sal_Int32 index = 0 ; it != it_end; ++it, ++index )
100 sChartNames[index] = *it;
102 catch (uno::Exception& )
104 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, OUString() );
106 return sChartNames;
109 // XChartObjects
110 uno::Any SAL_CALL
111 ScVbaChartObjects::Add( double _nX, double _nY, double _nWidth, double _nHeight ) throw (script::BasicErrorException)
115 uno::Sequence< table::CellRangeAddress > aCellRangeAddress( 1 );
116 awt::Rectangle aRectangle;
117 aRectangle.X = Millimeter::getInHundredthsOfOneMillimeter(_nX);
118 aRectangle.Y = Millimeter::getInHundredthsOfOneMillimeter(_nY);
119 aRectangle.Width = Millimeter::getInHundredthsOfOneMillimeter(_nWidth);
120 aRectangle.Height = Millimeter::getInHundredthsOfOneMillimeter(_nHeight);
121 // Note the space at the end of the stem ("Chart "). In ChartSheets only "Chart" is the stem
122 OUString sPersistChartName = ContainerUtilities::getUniqueName( getChartObjectNames(), OUString( "Chart " ) , OUString(), 1);
123 xTableCharts->addNewByName(sPersistChartName, aRectangle, aCellRangeAddress, true, false );
124 uno::Reference< excel::XChartObject > xChartObject( getItemByStringIndex( sPersistChartName ), uno::UNO_QUERY_THROW );
125 xChartObject->getChart()->setChartType(excel::XlChartType::xlColumnClustered);
126 return uno::makeAny( xChartObject );
128 catch (const uno::Exception& ex)
130 OSL_TRACE("AddItem caught exception ->%s", OUStringToOString( ex.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
132 return aNULL();
134 void SAL_CALL ScVbaChartObjects::Delete( ) throw (script::BasicErrorException)
136 uno::Sequence< OUString > sChartNames = xTableCharts->getElementNames();
137 sal_Int32 ncount = sChartNames.getLength();
138 for (sal_Int32 i = 0; i < ncount ; i++)
139 removeByName(sChartNames[i]);
142 // XEnumerationAccess
144 uno::Reference< container::XEnumeration >
145 ScVbaChartObjects::createEnumeration() throw (uno::RuntimeException)
147 css::uno::Reference< container::XEnumerationAccess > xEnumAccess( xTableCharts, uno::UNO_QUERY_THROW );
148 return new ChartObjectEnumerationImpl( mxContext, xEnumAccess->createEnumeration(), xDrawPageSupplier, getParent() /* sheet */);
151 // XElementAccess
153 uno::Type
154 ScVbaChartObjects::getElementType() throw (uno::RuntimeException)
156 return excel::XChartObject::static_type(0);
159 // ScVbaCollectionBaseImpl
160 uno::Any
161 ScVbaChartObjects::createCollectionObject( const css::uno::Any& aSource )
163 uno::Reference< table::XTableChart > xTableChart( aSource, uno::UNO_QUERY_THROW );
164 // correct parent object is sheet
165 return uno::makeAny( uno::Reference< excel::XChartObject > ( new ScVbaChartObject( getParent(), mxContext, xTableChart, xDrawPageSupplier ) ) );
168 OUString
169 ScVbaChartObjects::getServiceImplName()
171 return OUString("ScVbaChartObjects");
174 css::uno::Sequence<OUString>
175 ScVbaChartObjects::getServiceNames()
177 static uno::Sequence< OUString > sNames;
178 if ( sNames.getLength() == 0 )
180 sNames.realloc( 1 );
181 sNames[0] = "ooo.vba.excel.ChartObjects";
183 return sNames;
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */