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/table/XTableChartsSupplier.hpp>
32 : : #include <com/sun/star/table/XTableChart.hpp>
33 : : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
34 : : #include <ooo/vba/excel/XlChartType.hpp>
35 : :
36 : :
37 : : #include "vbachartobjects.hxx"
38 : : #include "vbachartobject.hxx"
39 : : #include "vbaglobals.hxx"
40 : : #include "cellsuno.hxx"
41 : : #include <vector>
42 : : #include <basic/sberrors.hxx>
43 : :
44 : : using namespace ::com::sun::star;
45 : : using namespace ::ooo::vba;
46 : :
47 : :
48 [ # # ]: 0 : class ChartObjectEnumerationImpl : public EnumerationHelperImpl
49 : : {
50 : : uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier;
51 : :
52 : : public:
53 : :
54 : 0 : 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 ) {}
55 : 0 : virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
56 : : {
57 [ # # ][ # # ]: 0 : uno::Reference< table::XTableChart > xTableChart( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
[ # # ]
58 : : // parent Object is sheet
59 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< excel::XChartObject > ( new ScVbaChartObject( m_xParent, m_xContext, xTableChart, xDrawPageSupplier ) ) );
[ # # ][ # # ]
[ # # ]
60 : : }
61 : : };
62 : :
63 : :
64 [ # # ]: 0 : 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 )
65 : : {
66 : :
67 : 0 : }
68 : :
69 : : void
70 : 0 : ScVbaChartObjects::removeByName(const rtl::OUString& _sChartName)
71 : : {
72 : 0 : xTableCharts->removeByName( _sChartName );
73 : 0 : }
74 : :
75 : : uno::Sequence< rtl::OUString >
76 : 0 : ScVbaChartObjects::getChartObjectNames() throw( css::script::BasicErrorException )
77 : : {
78 : 0 : uno::Sequence< rtl::OUString > sChartNames;
79 : : try
80 : : {
81 : : // c++ hackery
82 [ # # ]: 0 : uno::Reference< uno::XInterface > xIf( xDrawPageSupplier, uno::UNO_QUERY_THROW );
83 [ # # ][ # # ]: 0 : ScCellRangesBase* pUno= dynamic_cast< ScCellRangesBase* >( xIf.get() );
84 : 0 : ScDocShell* pDocShell = NULL;
85 [ # # ]: 0 : if ( !pUno )
86 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Failed to obtain the impl class from the drawpage")), uno::Reference< uno::XInterface >() );
87 : 0 : pDocShell = pUno->GetDocShell();
88 [ # # ]: 0 : if ( !pDocShell )
89 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Failed to obtain the docshell implclass")), uno::Reference< uno::XInterface >() );
90 : :
91 [ # # ][ # # ]: 0 : uno::Reference< sheet::XSpreadsheetDocument > xSpreadsheetDocument( pDocShell->GetModel(), uno::UNO_QUERY_THROW );
92 [ # # ][ # # ]: 0 : uno::Reference< sheet::XSpreadsheets > xSpreadsheets = xSpreadsheetDocument->getSheets();
93 [ # # ]: 0 : std::vector< rtl::OUString > aChartNamesVector;
94 : :
95 [ # # ][ # # ]: 0 : uno::Sequence< rtl::OUString > sSheetNames = xSpreadsheets->getElementNames();
96 : 0 : sal_Int32 nItems = sSheetNames.getLength();
97 [ # # ]: 0 : for (sal_Int32 i = 0; i < nItems; i++)
98 : : {
99 [ # # ][ # # ]: 0 : uno::Reference< table::XTableChartsSupplier > xLocTableChartsSupplier( xSpreadsheets->getByName(sSheetNames[i]), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
100 [ # # ][ # # ]: 0 : uno::Sequence< rtl::OUString > scurchartnames = xLocTableChartsSupplier->getCharts()->getElementNames();
[ # # ][ # # ]
101 : 0 : sal_Int32 nChartNames = scurchartnames.getLength();
102 [ # # ]: 0 : for (sal_Int32 n = 0; n < nChartNames; n++ )
103 [ # # ][ # # ]: 0 : aChartNamesVector.push_back(scurchartnames[n]);
104 [ # # ]: 0 : }
105 [ # # ]: 0 : sChartNames.realloc( aChartNamesVector.size() );
106 [ # # ]: 0 : std::vector< rtl::OUString > ::const_iterator it = aChartNamesVector.begin();
107 [ # # ]: 0 : std::vector< rtl::OUString > ::const_iterator it_end = aChartNamesVector.end();
108 [ # # ][ # # ]: 0 : for ( sal_Int32 index = 0 ; it != it_end; ++it, ++index )
109 [ # # ][ # # ]: 0 : sChartNames[index] = *it;
110 : : }
111 [ # # ]: 0 : catch (uno::Exception& )
112 : : {
113 [ # # ]: 0 : throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() );
114 : : }
115 : 0 : return sChartNames;
116 : : }
117 : :
118 : : // XChartObjects
119 : : uno::Any SAL_CALL
120 : 0 : ScVbaChartObjects::Add( double _nX, double _nY, double _nWidth, double _nHeight ) throw (script::BasicErrorException)
121 : : {
122 : : try
123 : : {
124 [ # # ]: 0 : uno::Sequence< table::CellRangeAddress > aCellRangeAddress( 1 );
125 : 0 : awt::Rectangle aRectangle;
126 [ # # ]: 0 : aRectangle.X = Millimeter::getInHundredthsOfOneMillimeter(_nX);
127 [ # # ]: 0 : aRectangle.Y = Millimeter::getInHundredthsOfOneMillimeter(_nY);
128 [ # # ]: 0 : aRectangle.Width = Millimeter::getInHundredthsOfOneMillimeter(_nWidth);
129 [ # # ]: 0 : aRectangle.Height = Millimeter::getInHundredthsOfOneMillimeter(_nHeight);
130 : : // Note the space at the end of the stem ("Chart "). In ChartSheets only "Chart" is the stem
131 [ # # ][ # # ]: 0 : rtl::OUString sPersistChartName = ContainerUtilities::getUniqueName( getChartObjectNames(), rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Chart " ) ) , rtl::OUString(), 1);
[ # # ][ # # ]
132 [ # # ][ # # ]: 0 : xTableCharts->addNewByName(sPersistChartName, aRectangle, aCellRangeAddress, true, false );
133 [ # # ][ # # ]: 0 : uno::Reference< excel::XChartObject > xChartObject( getItemByStringIndex( sPersistChartName ), uno::UNO_QUERY_THROW );
134 [ # # ][ # # ]: 0 : xChartObject->getChart()->setChartType(excel::XlChartType::xlColumnClustered);
[ # # ][ # # ]
135 [ # # ][ # # ]: 0 : return uno::makeAny( xChartObject );
[ # # ]
136 : : }
137 : 0 : catch (const uno::Exception& ex)
138 : : {
139 : : OSL_TRACE("AddItem caught exception ->%s", rtl::OUStringToOString( ex.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
140 : : }
141 : 0 : return aNULL();
142 : : }
143 : 0 : void SAL_CALL ScVbaChartObjects::Delete( ) throw (script::BasicErrorException)
144 : : {
145 [ # # ][ # # ]: 0 : uno::Sequence< rtl::OUString > sChartNames = xTableCharts->getElementNames();
146 : 0 : sal_Int32 ncount = sChartNames.getLength();
147 [ # # ]: 0 : for (sal_Int32 i = 0; i < ncount ; i++)
148 [ # # ][ # # ]: 0 : removeByName(sChartNames[i]);
[ # # ]
149 : 0 : }
150 : :
151 : : // XEnumerationAccess
152 : :
153 : : uno::Reference< container::XEnumeration >
154 : 0 : ScVbaChartObjects::createEnumeration() throw (uno::RuntimeException)
155 : : {
156 [ # # ]: 0 : css::uno::Reference< container::XEnumerationAccess > xEnumAccess( xTableCharts, uno::UNO_QUERY_THROW );
157 [ # # ][ # # ]: 0 : return new ChartObjectEnumerationImpl( mxContext, xEnumAccess->createEnumeration(), xDrawPageSupplier, getParent() /* sheet */);
[ # # ][ # # ]
[ # # ][ # # ]
158 : : }
159 : :
160 : : // XElementAccess
161 : :
162 : : uno::Type
163 : 0 : ScVbaChartObjects::getElementType() throw (uno::RuntimeException)
164 : : {
165 : 0 : return excel::XChartObject::static_type(0);
166 : : }
167 : :
168 : : // ScVbaCollectionBaseImpl
169 : : uno::Any
170 : 0 : ScVbaChartObjects::createCollectionObject( const css::uno::Any& aSource )
171 : : {
172 [ # # ]: 0 : uno::Reference< table::XTableChart > xTableChart( aSource, uno::UNO_QUERY_THROW );
173 : : // correct parent object is sheet
174 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< excel::XChartObject > ( new ScVbaChartObject( getParent(), mxContext, xTableChart, xDrawPageSupplier ) ) );
[ # # ][ # # ]
[ # # ]
175 : : }
176 : :
177 : : rtl::OUString
178 : 0 : ScVbaChartObjects::getServiceImplName()
179 : : {
180 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScVbaChartObjects"));
181 : : }
182 : :
183 : : css::uno::Sequence<rtl::OUString>
184 : 0 : ScVbaChartObjects::getServiceNames()
185 : : {
186 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > sNames;
[ # # ][ # # ]
187 [ # # ]: 0 : if ( sNames.getLength() == 0 )
188 : : {
189 : 0 : sNames.realloc( 1 );
190 [ # # ]: 0 : sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.ChartObjects") );
191 : : }
192 : 0 : return sNames;
193 : : }
194 : :
195 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|