1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #include "vbapivottables.hxx" 24 #include "vbapivottable.hxx" 25 #include <com/sun/star/sheet/XDataPilotTable.hpp> 26 #include <ooo/vba/excel/XPivotTable.hpp> 27 28 29 using namespace ::com::sun::star; 30 using namespace ::ooo::vba; 31 32 uno::Any DataPilotToPivotTable( const uno::Any& aSource, uno::Reference< uno::XComponentContext > & xContext ) 33 { 34 uno::Reference< sheet::XDataPilotTable > xTable( aSource, uno::UNO_QUERY_THROW ); 35 return uno::makeAny( uno::Reference< excel::XPivotTable > ( new ScVbaPivotTable( xContext, xTable ) ) ); 36 } 37 38 class PivotTableEnumeration : public EnumerationHelperImpl 39 { 40 public: 41 PivotTableEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( xParent, xContext, xEnumeration ) {} 42 43 virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 44 { 45 return DataPilotToPivotTable( m_xEnumeration->nextElement(), m_xContext ); 46 } 47 48 }; 49 50 ScVbaPivotTables::ScVbaPivotTables( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< container::XIndexAccess >& xIndexAccess ): ScVbaPivotTables_BASE( xParent, xContext, xIndexAccess ) 51 { 52 } 53 54 uno::Reference< container::XEnumeration > 55 ScVbaPivotTables::createEnumeration() throw (uno::RuntimeException) 56 { 57 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); 58 return new PivotTableEnumeration( mxParent, mxContext, xEnumAccess->createEnumeration() ); 59 } 60 61 uno::Any 62 ScVbaPivotTables::createCollectionObject( const css::uno::Any& aSource ) 63 { 64 return DataPilotToPivotTable( aSource, mxContext ); 65 } 66 67 uno::Type 68 ScVbaPivotTables::getElementType() throw (uno::RuntimeException) 69 { 70 return excel::XPivotTable::static_type(0); 71 } 72 73 rtl::OUString& 74 ScVbaPivotTables::getServiceImplName() 75 { 76 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaPivotTables") ); 77 return sImplName; 78 } 79 80 css::uno::Sequence<rtl::OUString> 81 ScVbaPivotTables::getServiceNames() 82 { 83 static uno::Sequence< rtl::OUString > sNames; 84 if ( sNames.getLength() == 0 ) 85 { 86 sNames.realloc( 1 ); 87 sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.PivotTables") ); 88 } 89 return sNames; 90 } 91