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 : :
29 : : #include "vbaaxes.hxx"
30 : : #include "vbaaxis.hxx"
31 : : #include "vbachart.hxx"
32 : : #include <ooo/vba/excel/XlAxisType.hpp>
33 : : #include <ooo/vba/excel/XlAxisGroup.hpp>
34 : : #include <ooo/vba/excel/XAxis.hpp>
35 : : #include <map>
36 : :
37 : : using namespace ::com::sun::star;
38 : : using namespace ::ooo::vba;
39 : : using namespace ::ooo::vba::excel::XlAxisType;
40 : : using namespace ::ooo::vba::excel::XlAxisGroup;
41 : :
42 : : // each 'Item' in the Axes collection is indexed via 2 indexes, group and type.
43 : : // We need to 'flatten' this into a single index in order to be able to wrap
44 : : // iteration over the set of Axis(s) in a XIndexAccess implementation
45 : : //
46 : : typedef ::std::pair<sal_Int32, sal_Int32 > AxesCoordinate; // type and group combination
47 : : typedef ::std::vector< AxesCoordinate > vecAxesIndices;
48 : :
49 : : typedef ::cppu::WeakImplHelper1< container::XIndexAccess > AxisIndexWrapper_BASE;
50 : :
51 [ # # ]: 0 : class EnumWrapper : public EnumerationHelper_BASE
52 : : {
53 : : uno::Reference<container::XIndexAccess > m_xIndexAccess;
54 : : sal_Int32 nIndex;
55 : : public:
56 : 0 : EnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {}
57 : 0 : virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException)
58 : : {
59 : 0 : return ( nIndex < m_xIndexAccess->getCount() );
60 : : }
61 : :
62 : 0 : virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
63 : : {
64 [ # # ]: 0 : if ( nIndex < m_xIndexAccess->getCount() )
65 : 0 : return m_xIndexAccess->getByIndex( nIndex++ );
66 [ # # ]: 0 : throw container::NoSuchElementException();
67 : : }
68 : : };
69 : :
70 : :
71 : : uno::Reference< excel::XAxis >
72 : 0 : ScVbaAxes::createAxis( const uno::Reference< excel::XChart >& xChart, const uno::Reference< uno::XComponentContext >& xContext, sal_Int32 nType, sal_Int32 nAxisGroup ) throw ( uno::RuntimeException )
73 : : {
74 [ # # ][ # # ]: 0 : ScVbaChart* pChart = static_cast< ScVbaChart* >( xChart.get() );
75 [ # # ]: 0 : if ( !pChart )
76 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Object failure, can't access chart implementation" )), uno::Reference< uno::XInterface >() );
77 : :
78 : 0 : uno::Reference< beans::XPropertySet > xAxisPropertySet;
79 [ # # ][ # # ]: 0 : if (((nType == xlCategory) || (nType == xlSeriesAxis) || (nType == xlValue)))
[ # # ]
80 : : {
81 [ # # ][ # # ]: 0 : if ((nAxisGroup != xlPrimary) && (nAxisGroup != xlSecondary))
82 [ # # ][ # # ]: 0 : throw script::BasicErrorException( rtl::OUString(), NULL, SbERR_METHOD_FAILED, rtl::OUString());
83 [ # # ][ # # ]: 0 : xAxisPropertySet.set( pChart->getAxisPropertySet(nType, nAxisGroup), uno::UNO_QUERY_THROW );
84 : : }
85 : : else
86 [ # # ][ # # ]: 0 : throw script::BasicErrorException( rtl::OUString(), NULL, SbERR_METHOD_FAILED, rtl::OUString());
87 [ # # ]: 0 : uno::Reference< XHelperInterface > xParent( xChart, uno::UNO_QUERY_THROW );
88 [ # # ][ # # ]: 0 : return new ScVbaAxis( xParent, xContext, xAxisPropertySet, nType, nAxisGroup);
[ # # ]
89 : : }
90 : :
91 [ # # ]: 0 : class AxisIndexWrapper : public AxisIndexWrapper_BASE
92 : : {
93 : : // if necessary for better performance we could change this into a map and cache the
94 : : // indices -> Axis, currently we create a new Axis object
95 : : // on each getByIndex
96 : : uno::Reference< uno::XComponentContext > mxContext;
97 : : vecAxesIndices mCoordinates;
98 : : uno::Reference< excel::XChart > mxChart;
99 : : public:
100 [ # # ]: 0 : AxisIndexWrapper( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< excel::XChart >& xChart ) : mxContext( xContext ), mxChart( xChart )
101 : : {
102 [ # # ]: 0 : if ( mxChart.is() )
103 : : {
104 [ # # ][ # # ]: 0 : ScVbaChart* pChart = static_cast< ScVbaChart* >( mxChart.get() );
105 : : // primary
106 : 0 : sal_Bool bBool = false;
107 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xDiagramPropertySet( pChart->xDiagramPropertySet() );
108 [ # # ][ # # ]: 0 : if ( ( xDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasXAxis" ) ) ) >>= bBool ) && bBool )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
109 [ # # ][ # # ]: 0 : mCoordinates.push_back( AxesCoordinate( xlPrimary, xlCategory ) );
110 [ # # ][ # # ]: 0 : if ( ( xDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasYAxis" ) ) ) >>= bBool ) && bBool )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
111 [ # # ][ # # ]: 0 : mCoordinates.push_back( AxesCoordinate( xlPrimary, xlSeriesAxis ) );
112 : :
113 [ # # ][ # # ]: 0 : if ( pChart->is3D() )
114 [ # # ][ # # ]: 0 : mCoordinates.push_back( AxesCoordinate( xlPrimary, xlValue ) );
115 : :
116 : : // secondary
117 [ # # ][ # # ]: 0 : if ( ( xDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasSecondaryXAxis" ) ) ) >>= bBool ) && bBool )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
118 [ # # ][ # # ]: 0 : mCoordinates.push_back( AxesCoordinate( xlSecondary, xlCategory ) );
119 [ # # ][ # # ]: 0 : if ( ( xDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasSecondaryYAxis" ) ) ) >>= bBool ) && bBool )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
120 [ # # ][ # # ]: 0 : mCoordinates.push_back( AxesCoordinate( xlSecondary, xlSeriesAxis ) );
121 : : }
122 : :
123 : 0 : }
124 : 0 : virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException) { return mCoordinates.size(); }
125 : 0 : virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, ::uno::RuntimeException)
126 : : {
127 [ # # ]: 0 : AxesCoordinate dIndexes = mCoordinates[ Index ];
128 [ # # ][ # # ]: 0 : return uno::makeAny( ScVbaAxes::createAxis( mxChart, mxContext, dIndexes.second, dIndexes.first ) );
129 : : }
130 : : // XElementAccess
131 : 0 : virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException)
132 : : {
133 : 0 : return excel::XAxis::static_type(0);
134 : : }
135 : 0 : virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
136 : : {
137 : 0 : return ( mCoordinates.size() > 0 );
138 : : }
139 : : };
140 : :
141 : 0 : uno::Reference< container::XIndexAccess > createIndexWrapper( const uno::Reference< excel::XChart >& xChart, const uno::Reference< uno::XComponentContext >& xContext )
142 : : {
143 [ # # ][ # # ]: 0 : return new AxisIndexWrapper( xContext, xChart );
144 : : }
145 : :
146 : : // #FIXME The collection semantics will never work as this object is not yet initialised correctly
147 [ # # ]: 0 : ScVbaAxes::ScVbaAxes( const uno::Reference< XHelperInterface >& xParent,const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< excel::XChart >& xChart ) : ScVbaAxes_BASE( xParent, xContext, createIndexWrapper( xChart, xContext )), moChartParent( xChart )
148 : : {
149 : 0 : }
150 : :
151 : : uno::Type SAL_CALL
152 : 0 : ScVbaAxes::getElementType() throw (css::uno::RuntimeException)
153 : : {
154 : 0 : return excel::XAxes::static_type(0);
155 : : }
156 : :
157 : : uno::Reference< container::XEnumeration > SAL_CALL
158 : 0 : ScVbaAxes::createEnumeration() throw (css::uno::RuntimeException)
159 : : {
160 [ # # ][ # # ]: 0 : return new EnumWrapper( m_xIndexAccess );
161 : : }
162 : :
163 : : uno::Any SAL_CALL
164 : 0 : ScVbaAxes::Item( const css::uno::Any& _nType, const css::uno::Any& _oAxisGroup) throw (css::uno::RuntimeException)
165 : : {
166 : : // #TODO map the possible index combinations to a container::XIndexAccess wrapper impl
167 : : // using a vector of valid std::pair maybe?
168 : : // bodgy helperapi port bits
169 : 0 : sal_Int32 nAxisGroup = xlPrimary;
170 : 0 : sal_Int32 nType = -1;
171 [ # # ][ # # ]: 0 : if ( !_nType.hasValue() || ( ( _nType >>= nType ) == false ) )
[ # # ]
172 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Axes::Item Failed to extract type" )), uno::Reference< uno::XInterface >() );
173 : :
174 [ # # ]: 0 : if ( _oAxisGroup.hasValue() )
175 : 0 : _oAxisGroup >>= nAxisGroup ;
176 : :
177 [ # # ][ # # ]: 0 : return uno::makeAny( createAxis( moChartParent, mxContext, nType, nAxisGroup ) );
178 : : }
179 : :
180 : : uno::Any
181 : 0 : ScVbaAxes::createCollectionObject(const css::uno::Any& aSource)
182 : : {
183 : 0 : return aSource; // pass through ( it's already an XAxis object
184 : : }
185 : :
186 : : rtl::OUString
187 : 0 : ScVbaAxes::getServiceImplName()
188 : : {
189 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScVbaAxes"));
190 : : }
191 : :
192 : : uno::Sequence< rtl::OUString >
193 : 0 : ScVbaAxes::getServiceNames()
194 : : {
195 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
196 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
197 : : {
198 : 0 : aServiceNames.realloc( 1 );
199 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Axes" ) );
200 : : }
201 : 0 : return aServiceNames;
202 : : }
203 : :
204 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|