1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "vbacomments.hxx"
20 #include "vbacomment.hxx"
22 #include <com/sun/star/frame/XModel.hpp>
23 #include <com/sun/star/container/XChild.hpp>
24 #include <com/sun/star/sheet/XSheetAnnotation.hpp>
25 #include <com/sun/star/table/XCellRange.hpp>
27 using namespace ::ooo::vba
;
28 using namespace ::com::sun::star
;
30 static uno::Any
AnnotationToComment( const uno::Any
& aSource
, const uno::Reference
< uno::XComponentContext
> & xContext
, const uno::Reference
< frame::XModel
>& xModel
)
32 uno::Reference
< sheet::XSheetAnnotation
> xAnno( aSource
, uno::UNO_QUERY_THROW
);
33 uno::Reference
< container::XChild
> xChild( xAnno
, uno::UNO_QUERY_THROW
);
34 uno::Reference
< table::XCellRange
> xCellRange( xChild
->getParent(), uno::UNO_QUERY_THROW
);
36 // #FIXME needs to find the correct Parent
37 return uno::Any( uno::Reference
< excel::XComment
> (
38 new ScVbaComment( uno::Reference
< XHelperInterface
>(), xContext
, xModel
, xCellRange
) ) );
43 class CommentEnumeration
: public EnumerationHelperImpl
45 css::uno::Reference
< css::frame::XModel
> mxModel
;
47 /// @throws uno::RuntimeException
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
) :
53 EnumerationHelperImpl( xParent
, xContext
, xEnumeration
),
54 mxModel( xModel
, uno::UNO_SET_THROW
)
57 virtual uno::Any SAL_CALL
nextElement() override
59 return AnnotationToComment( m_xEnumeration
->nextElement(), m_xContext
, mxModel
);
66 ScVbaComments::ScVbaComments(
67 const uno::Reference
< XHelperInterface
>& xParent
,
68 const uno::Reference
< uno::XComponentContext
> & xContext
,
69 const uno::Reference
< frame::XModel
>& xModel
,
70 const uno::Reference
< container::XIndexAccess
>& xIndexAccess
) :
71 ScVbaComments_BASE( xParent
, xContext
, xIndexAccess
),
72 mxModel( xModel
, uno::UNO_SET_THROW
)
76 // public helper functions
78 uno::Reference
< container::XEnumeration
>
79 ScVbaComments::createEnumeration()
81 uno::Reference
< container::XEnumerationAccess
> xEnumAccess( m_xIndexAccess
, uno::UNO_QUERY_THROW
);
82 return new CommentEnumeration( mxParent
, mxContext
, xEnumAccess
->createEnumeration(), mxModel
);
86 ScVbaComments::createCollectionObject( const css::uno::Any
& aSource
)
88 return AnnotationToComment( aSource
, mxContext
, mxModel
);
92 ScVbaComments::getElementType()
94 return cppu::UnoType
<excel::XComment
>::get();
98 ScVbaComments::getServiceImplName()
100 return u
"ScVbaComments"_ustr
;
103 css::uno::Sequence
<OUString
>
104 ScVbaComments::getServiceNames()
106 static uno::Sequence
< OUString
> const sNames
108 u
"ooo.vba.excel.Comments"_ustr
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */