1*b3f79822SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b3f79822SAndrew Rist * distributed with this work for additional information 6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance 9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b3f79822SAndrew Rist * software distributed under the License is distributed on an 15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the 17*b3f79822SAndrew Rist * specific language governing permissions and limitations 18*b3f79822SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*b3f79822SAndrew Rist *************************************************************/ 21*b3f79822SAndrew Rist 22*b3f79822SAndrew Rist 23cdf0e10cSrcweir #include "vbacomments.hxx" 24cdf0e10cSrcweir 25cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp> 26cdf0e10cSrcweir #include <com/sun/star/sheet/XSheetAnnotation.hpp> 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include "vbaglobals.hxx" 29cdf0e10cSrcweir 30cdf0e10cSrcweir using namespace ::ooo::vba; 31cdf0e10cSrcweir using namespace ::com::sun::star; 32cdf0e10cSrcweir 33cdf0e10cSrcweir uno::Any AnnotationToComment( const uno::Any& aSource, uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel ) 34cdf0e10cSrcweir { 35cdf0e10cSrcweir uno::Reference< sheet::XSheetAnnotation > xAnno( aSource, uno::UNO_QUERY_THROW ); 36cdf0e10cSrcweir uno::Reference< container::XChild > xChild( xAnno, uno::UNO_QUERY_THROW ); 37cdf0e10cSrcweir uno::Reference< table::XCellRange > xCellRange( xChild->getParent(), uno::UNO_QUERY_THROW ); 38cdf0e10cSrcweir 39cdf0e10cSrcweir // #FIXME needs to find the correct Parent 40cdf0e10cSrcweir return uno::makeAny( uno::Reference< excel::XComment > ( 41cdf0e10cSrcweir new ScVbaComment( uno::Reference< XHelperInterface >(), xContext, xModel, xCellRange ) ) ); 42cdf0e10cSrcweir } 43cdf0e10cSrcweir 44cdf0e10cSrcweir class CommentEnumeration : public EnumerationHelperImpl 45cdf0e10cSrcweir { 46cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > mxModel; 47cdf0e10cSrcweir public: 48cdf0e10cSrcweir CommentEnumeration( 49cdf0e10cSrcweir const uno::Reference< XHelperInterface >& xParent, 50cdf0e10cSrcweir const uno::Reference< uno::XComponentContext >& xContext, 51cdf0e10cSrcweir const uno::Reference< container::XEnumeration >& xEnumeration, 52cdf0e10cSrcweir const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) : 53cdf0e10cSrcweir EnumerationHelperImpl( xParent, xContext, xEnumeration ), 54cdf0e10cSrcweir mxModel( xModel, uno::UNO_SET_THROW ) 55cdf0e10cSrcweir {} 56cdf0e10cSrcweir 57cdf0e10cSrcweir virtual uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir return AnnotationToComment( m_xEnumeration->nextElement(), m_xContext, mxModel ); 60cdf0e10cSrcweir } 61cdf0e10cSrcweir 62cdf0e10cSrcweir }; 63cdf0e10cSrcweir 64cdf0e10cSrcweir ScVbaComments::ScVbaComments( 65cdf0e10cSrcweir const uno::Reference< XHelperInterface >& xParent, 66cdf0e10cSrcweir const uno::Reference< uno::XComponentContext > & xContext, 67cdf0e10cSrcweir const uno::Reference< frame::XModel >& xModel, 68cdf0e10cSrcweir const uno::Reference< container::XIndexAccess >& xIndexAccess ) : 69cdf0e10cSrcweir ScVbaComments_BASE( xParent, xContext, xIndexAccess ), 70cdf0e10cSrcweir mxModel( xModel, uno::UNO_SET_THROW ) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir } 73cdf0e10cSrcweir 74cdf0e10cSrcweir // public helper functions 75cdf0e10cSrcweir 76cdf0e10cSrcweir uno::Reference< container::XEnumeration > 77cdf0e10cSrcweir ScVbaComments::createEnumeration() throw (uno::RuntimeException) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); 80cdf0e10cSrcweir return new CommentEnumeration( mxParent, mxContext, xEnumAccess->createEnumeration(), mxModel ); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir uno::Any 84cdf0e10cSrcweir ScVbaComments::createCollectionObject( const css::uno::Any& aSource ) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir return AnnotationToComment( aSource, mxContext, mxModel ); 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir uno::Type 90cdf0e10cSrcweir ScVbaComments::getElementType() throw (uno::RuntimeException) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir return excel::XComment::static_type(0); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir rtl::OUString& 96cdf0e10cSrcweir ScVbaComments::getServiceImplName() 97cdf0e10cSrcweir { 98cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaComments") ); 99cdf0e10cSrcweir return sImplName; 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir css::uno::Sequence<rtl::OUString> 103cdf0e10cSrcweir ScVbaComments::getServiceNames() 104cdf0e10cSrcweir { 105cdf0e10cSrcweir static uno::Sequence< rtl::OUString > sNames; 106cdf0e10cSrcweir if ( sNames.getLength() == 0 ) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir sNames.realloc( 1 ); 109cdf0e10cSrcweir sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Comments") ); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir return sNames; 112cdf0e10cSrcweir } 113