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 "vbacomments.hxx"
24
25 #include <com/sun/star/container/XChild.hpp>
26 #include <com/sun/star/sheet/XSheetAnnotation.hpp>
27
28 #include "vbaglobals.hxx"
29
30 using namespace ::ooo::vba;
31 using namespace ::com::sun::star;
32
AnnotationToComment(const uno::Any & aSource,uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<frame::XModel> & xModel)33 uno::Any AnnotationToComment( const uno::Any& aSource, uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel )
34 {
35 uno::Reference< sheet::XSheetAnnotation > xAnno( aSource, uno::UNO_QUERY_THROW );
36 uno::Reference< container::XChild > xChild( xAnno, uno::UNO_QUERY_THROW );
37 uno::Reference< table::XCellRange > xCellRange( xChild->getParent(), uno::UNO_QUERY_THROW );
38
39 // #FIXME needs to find the correct Parent
40 return uno::makeAny( uno::Reference< excel::XComment > (
41 new ScVbaComment( uno::Reference< XHelperInterface >(), xContext, xModel, xCellRange ) ) );
42 }
43
44 class CommentEnumeration : public EnumerationHelperImpl
45 {
46 css::uno::Reference< css::frame::XModel > mxModel;
47 public:
CommentEnumeration(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<container::XEnumeration> & xEnumeration,const uno::Reference<frame::XModel> & xModel)48 CommentEnumeration(
49 const uno::Reference< XHelperInterface >& xParent,
50 const uno::Reference< uno::XComponentContext >& xContext,
51 const uno::Reference< container::XEnumeration >& xEnumeration,
52 const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) :
53 EnumerationHelperImpl( xParent, xContext, xEnumeration ),
54 mxModel( xModel, uno::UNO_SET_THROW )
55 {}
56
nextElement()57 virtual uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
58 {
59 return AnnotationToComment( m_xEnumeration->nextElement(), m_xContext, mxModel );
60 }
61
62 };
63
ScVbaComments(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<frame::XModel> & xModel,const uno::Reference<container::XIndexAccess> & xIndexAccess)64 ScVbaComments::ScVbaComments(
65 const uno::Reference< XHelperInterface >& xParent,
66 const uno::Reference< uno::XComponentContext > & xContext,
67 const uno::Reference< frame::XModel >& xModel,
68 const uno::Reference< container::XIndexAccess >& xIndexAccess ) :
69 ScVbaComments_BASE( xParent, xContext, xIndexAccess ),
70 mxModel( xModel, uno::UNO_SET_THROW )
71 {
72 }
73
74 // public helper functions
75
76 uno::Reference< container::XEnumeration >
createEnumeration()77 ScVbaComments::createEnumeration() throw (uno::RuntimeException)
78 {
79 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
80 return new CommentEnumeration( mxParent, mxContext, xEnumAccess->createEnumeration(), mxModel );
81 }
82
83 uno::Any
createCollectionObject(const css::uno::Any & aSource)84 ScVbaComments::createCollectionObject( const css::uno::Any& aSource )
85 {
86 return AnnotationToComment( aSource, mxContext, mxModel );
87 }
88
89 uno::Type
getElementType()90 ScVbaComments::getElementType() throw (uno::RuntimeException)
91 {
92 return excel::XComment::static_type(0);
93 }
94
95 rtl::OUString&
getServiceImplName()96 ScVbaComments::getServiceImplName()
97 {
98 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaComments") );
99 return sImplName;
100 }
101
102 css::uno::Sequence<rtl::OUString>
getServiceNames()103 ScVbaComments::getServiceNames()
104 {
105 static uno::Sequence< rtl::OUString > sNames;
106 if ( sNames.getLength() == 0 )
107 {
108 sNames.realloc( 1 );
109 sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Comments") );
110 }
111 return sNames;
112 }
113