merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / vba / vbacomments.cxx
blobf78a3f11b6a80444df7350198aaf8333e2795aa4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbacomments.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "vbacomments.hxx"
32 #include <com/sun/star/container/XChild.hpp>
33 #include <com/sun/star/sheet/XSheetAnnotation.hpp>
35 #include "vbaglobals.hxx"
37 using namespace ::ooo::vba;
38 using namespace ::com::sun::star;
40 uno::Any AnnotationToComment( const uno::Any& aSource, uno::Reference< uno::XComponentContext > & xContext )
42 uno::Reference< sheet::XSheetAnnotation > xAnno( aSource, uno::UNO_QUERY_THROW );
43 uno::Reference< container::XChild > xChild( xAnno, uno::UNO_QUERY_THROW );
44 uno::Reference< table::XCellRange > xCellRange( xChild->getParent(), uno::UNO_QUERY_THROW );
46 // #FIXME needs to find the correct Parent
47 return uno::makeAny( uno::Reference< excel::XComment > ( new ScVbaComment( uno::Reference< XHelperInterface >(), xContext, xCellRange ) ) );
50 class CommentEnumeration : public EnumerationHelperImpl
52 public:
53 CommentEnumeration( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( xContext, xEnumeration ) {}
55 virtual uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
57 return AnnotationToComment( m_xEnumeration->nextElement(), m_xContext );
62 ScVbaComments::ScVbaComments( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< container::XIndexAccess >& xIndexAccess )
63 : ScVbaComments_BASE( xParent, xContext, xIndexAccess )
67 // public helper functions
69 uno::Reference< container::XEnumeration >
70 ScVbaComments::createEnumeration() throw (uno::RuntimeException)
72 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
74 return new CommentEnumeration( mxContext, xEnumAccess->createEnumeration() );
77 uno::Any
78 ScVbaComments::createCollectionObject( const css::uno::Any& aSource )
80 return AnnotationToComment( aSource, mxContext );
83 uno::Type
84 ScVbaComments::getElementType() throw (uno::RuntimeException)
86 return excel::XComment::static_type(0);
89 rtl::OUString&
90 ScVbaComments::getServiceImplName()
92 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaComments") );
93 return sImplName;
96 css::uno::Sequence<rtl::OUString>
97 ScVbaComments::getServiceNames()
99 static uno::Sequence< rtl::OUString > sNames;
100 if ( sNames.getLength() == 0 )
102 sNames.realloc( 1 );
103 sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Comments") );
105 return sNames;