fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / vba / vbachartobjects.cxx
blob1b6928a30470d635ba1a218054e6a591dba85f67
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>
27 #include "vbachartobjects.hxx"
28 #include "vbachartobject.hxx"
29 #include "vbaglobals.hxx"
30 #include "cellsuno.hxx"
31 #include <vector>
32 #include <basic/sberrors.hxx>
34 using namespace ::com::sun::star;
35 using namespace ::ooo::vba;
37 class ChartObjectEnumerationImpl : public EnumerationHelperImpl
39 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier;
41 public:
43 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 ) {}
44 virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
46 uno::Any ret;
48 try
50 uno::Reference< table::XTableChart > xTableChart( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
51 // parent Object is sheet
52 ret = uno::makeAny( uno::Reference< excel::XChartObject > ( new ScVbaChartObject( m_xParent, m_xContext, xTableChart, xDrawPageSupplier ) ) );
54 catch (const lang::WrappedTargetException&)
56 throw;
58 catch (const container::NoSuchElementException&)
60 throw;
62 catch (const uno::RuntimeException&)
64 throw;
66 catch (const uno::Exception& e)
68 throw lang::WrappedTargetException(
69 "Error creating ScVbaChartObject!",
70 static_cast < OWeakObject * > ( this ),
71 makeAny( e ) );
73 return ret;
77 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 )
82 void
83 ScVbaChartObjects::removeByName(const OUString& _sChartName)
85 xTableCharts->removeByName( _sChartName );
88 uno::Sequence< OUString >
89 ScVbaChartObjects::getChartObjectNames() throw( css::script::BasicErrorException )
91 uno::Sequence< OUString > sChartNames;
92 try
94 // c++ hackery
95 uno::Reference< uno::XInterface > xIf( xDrawPageSupplier, uno::UNO_QUERY_THROW );
96 ScCellRangesBase* pUno= dynamic_cast< ScCellRangesBase* >( xIf.get() );
97 ScDocShell* pDocShell = NULL;
98 if ( !pUno )
99 throw uno::RuntimeException("Failed to obtain the impl class from the drawpage" );
100 pDocShell = pUno->GetDocShell();
101 if ( !pDocShell )
102 throw uno::RuntimeException("Failed to obtain the docshell implclass" );
104 uno::Reference< sheet::XSpreadsheetDocument > xSpreadsheetDocument( pDocShell->GetModel(), uno::UNO_QUERY_THROW );
105 uno::Reference< sheet::XSpreadsheets > xSpreadsheets = xSpreadsheetDocument->getSheets();
106 std::vector< OUString > aChartNamesVector;
108 uno::Sequence< OUString > sSheetNames = xSpreadsheets->getElementNames();
109 sal_Int32 nItems = sSheetNames.getLength();
110 for (sal_Int32 i = 0; i < nItems; i++)
112 uno::Reference< table::XTableChartsSupplier > xLocTableChartsSupplier( xSpreadsheets->getByName(sSheetNames[i]), uno::UNO_QUERY_THROW );
113 uno::Sequence< OUString > scurchartnames = xLocTableChartsSupplier->getCharts()->getElementNames();
114 sal_Int32 nChartNames = scurchartnames.getLength();
115 for (sal_Int32 n = 0; n < nChartNames; n++ )
116 aChartNamesVector.push_back(scurchartnames[n]);
118 sChartNames.realloc( aChartNamesVector.size() );
119 std::vector< OUString > ::const_iterator it = aChartNamesVector.begin();
120 std::vector< OUString > ::const_iterator it_end = aChartNamesVector.end();
121 for ( sal_Int32 index = 0 ; it != it_end; ++it, ++index )
122 sChartNames[index] = *it;
124 catch (uno::Exception& )
126 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, OUString() );
128 return sChartNames;
131 // XChartObjects
132 uno::Any SAL_CALL
133 ScVbaChartObjects::Add( double _nX, double _nY, double _nWidth, double _nHeight ) throw (script::BasicErrorException, std::exception)
137 uno::Sequence< table::CellRangeAddress > aCellRangeAddress( 1 );
138 awt::Rectangle aRectangle;
139 aRectangle.X = Millimeter::getInHundredthsOfOneMillimeter(_nX);
140 aRectangle.Y = Millimeter::getInHundredthsOfOneMillimeter(_nY);
141 aRectangle.Width = Millimeter::getInHundredthsOfOneMillimeter(_nWidth);
142 aRectangle.Height = Millimeter::getInHundredthsOfOneMillimeter(_nHeight);
143 // Note the space at the end of the stem ("Chart "). In ChartSheets only "Chart" is the stem
144 OUString sPersistChartName = ContainerUtilities::getUniqueName( getChartObjectNames(), OUString( "Chart " ) , OUString(), 1);
145 xTableCharts->addNewByName(sPersistChartName, aRectangle, aCellRangeAddress, true, false );
146 uno::Reference< excel::XChartObject > xChartObject( getItemByStringIndex( sPersistChartName ), uno::UNO_QUERY_THROW );
147 xChartObject->getChart()->setChartType(excel::XlChartType::xlColumnClustered);
148 return uno::makeAny( xChartObject );
150 catch (const uno::Exception& ex)
152 OSL_TRACE("AddItem caught exception ->%s", OUStringToOString( ex.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
154 return aNULL();
156 void SAL_CALL ScVbaChartObjects::Delete( ) throw (script::BasicErrorException, std::exception)
158 uno::Sequence< OUString > sChartNames = xTableCharts->getElementNames();
159 sal_Int32 ncount = sChartNames.getLength();
160 for (sal_Int32 i = 0; i < ncount ; i++)
161 removeByName(sChartNames[i]);
164 // XEnumerationAccess
166 uno::Reference< container::XEnumeration >
167 ScVbaChartObjects::createEnumeration() throw (uno::RuntimeException)
169 css::uno::Reference< container::XEnumerationAccess > xEnumAccess( xTableCharts, uno::UNO_QUERY_THROW );
170 return new ChartObjectEnumerationImpl( mxContext, xEnumAccess->createEnumeration(), xDrawPageSupplier, getParent() /* sheet */);
173 // XElementAccess
175 uno::Type
176 ScVbaChartObjects::getElementType() throw (uno::RuntimeException)
178 return cppu::UnoType<excel::XChartObject>::get();
181 // ScVbaCollectionBaseImpl
182 uno::Any
183 ScVbaChartObjects::createCollectionObject( const css::uno::Any& aSource )
185 uno::Reference< table::XTableChart > xTableChart( aSource, uno::UNO_QUERY_THROW );
186 // correct parent object is sheet
187 return uno::makeAny( uno::Reference< excel::XChartObject > ( new ScVbaChartObject( getParent(), mxContext, xTableChart, xDrawPageSupplier ) ) );
190 OUString
191 ScVbaChartObjects::getServiceImplName()
193 return OUString("ScVbaChartObjects");
196 css::uno::Sequence<OUString>
197 ScVbaChartObjects::getServiceNames()
199 static uno::Sequence< OUString > sNames;
200 if ( sNames.getLength() == 0 )
202 sNames.realloc( 1 );
203 sNames[0] = "ooo.vba.excel.ChartObjects";
205 return sNames;
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */