1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #include "vbacomments.hxx" 28 29 #include <com/sun/star/container/XChild.hpp> 30 #include <com/sun/star/sheet/XSheetAnnotation.hpp> 31 32 #include "vbaglobals.hxx" 33 34 using namespace ::ooo::vba; 35 using namespace ::com::sun::star; 36 37 uno::Any AnnotationToComment( const uno::Any& aSource, uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel ) 38 { 39 uno::Reference< sheet::XSheetAnnotation > xAnno( aSource, uno::UNO_QUERY_THROW ); 40 uno::Reference< container::XChild > xChild( xAnno, uno::UNO_QUERY_THROW ); 41 uno::Reference< table::XCellRange > xCellRange( xChild->getParent(), uno::UNO_QUERY_THROW ); 42 43 // #FIXME needs to find the correct Parent 44 return uno::makeAny( uno::Reference< excel::XComment > ( 45 new ScVbaComment( uno::Reference< XHelperInterface >(), xContext, xModel, xCellRange ) ) ); 46 } 47 48 class CommentEnumeration : public EnumerationHelperImpl 49 { 50 css::uno::Reference< css::frame::XModel > mxModel; 51 public: 52 CommentEnumeration( 53 const uno::Reference< XHelperInterface >& xParent, 54 const uno::Reference< uno::XComponentContext >& xContext, 55 const uno::Reference< container::XEnumeration >& xEnumeration, 56 const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) : 57 EnumerationHelperImpl( xParent, xContext, xEnumeration ), 58 mxModel( xModel, uno::UNO_SET_THROW ) 59 {} 60 61 virtual uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 62 { 63 return AnnotationToComment( m_xEnumeration->nextElement(), m_xContext, mxModel ); 64 } 65 66 }; 67 68 ScVbaComments::ScVbaComments( 69 const uno::Reference< XHelperInterface >& xParent, 70 const uno::Reference< uno::XComponentContext > & xContext, 71 const uno::Reference< frame::XModel >& xModel, 72 const uno::Reference< container::XIndexAccess >& xIndexAccess ) : 73 ScVbaComments_BASE( xParent, xContext, xIndexAccess ), 74 mxModel( xModel, uno::UNO_SET_THROW ) 75 { 76 } 77 78 // public helper functions 79 80 uno::Reference< container::XEnumeration > 81 ScVbaComments::createEnumeration() throw (uno::RuntimeException) 82 { 83 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); 84 return new CommentEnumeration( mxParent, mxContext, xEnumAccess->createEnumeration(), mxModel ); 85 } 86 87 uno::Any 88 ScVbaComments::createCollectionObject( const css::uno::Any& aSource ) 89 { 90 return AnnotationToComment( aSource, mxContext, mxModel ); 91 } 92 93 uno::Type 94 ScVbaComments::getElementType() throw (uno::RuntimeException) 95 { 96 return excel::XComment::static_type(0); 97 } 98 99 rtl::OUString& 100 ScVbaComments::getServiceImplName() 101 { 102 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaComments") ); 103 return sImplName; 104 } 105 106 css::uno::Sequence<rtl::OUString> 107 ScVbaComments::getServiceNames() 108 { 109 static uno::Sequence< rtl::OUString > sNames; 110 if ( sNames.getLength() == 0 ) 111 { 112 sNames.realloc( 1 ); 113 sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Comments") ); 114 } 115 return sNames; 116 } 117