Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / ui / vba / vbacomments.cxx
bloba1b2001c522a62c632ee265c0148ae20df7b670b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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::makeAny( uno::Reference< excel::XComment > (
38 new ScVbaComment( uno::Reference< XHelperInterface >(), xContext, xModel, xCellRange ) ) );
41 class CommentEnumeration : public EnumerationHelperImpl
43 css::uno::Reference< css::frame::XModel > mxModel;
44 public:
45 /// @throws uno::RuntimeException
46 CommentEnumeration(
47 const uno::Reference< XHelperInterface >& xParent,
48 const uno::Reference< uno::XComponentContext >& xContext,
49 const uno::Reference< container::XEnumeration >& xEnumeration,
50 const uno::Reference< frame::XModel >& xModel ) :
51 EnumerationHelperImpl( xParent, xContext, xEnumeration ),
52 mxModel( xModel, uno::UNO_SET_THROW )
55 virtual uno::Any SAL_CALL nextElement() override
57 return AnnotationToComment( m_xEnumeration->nextElement(), m_xContext, mxModel );
62 ScVbaComments::ScVbaComments(
63 const uno::Reference< XHelperInterface >& xParent,
64 const uno::Reference< uno::XComponentContext > & xContext,
65 const uno::Reference< frame::XModel >& xModel,
66 const uno::Reference< container::XIndexAccess >& xIndexAccess ) :
67 ScVbaComments_BASE( xParent, xContext, xIndexAccess ),
68 mxModel( xModel, uno::UNO_SET_THROW )
72 // public helper functions
74 uno::Reference< container::XEnumeration >
75 ScVbaComments::createEnumeration()
77 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
78 return new CommentEnumeration( mxParent, mxContext, xEnumAccess->createEnumeration(), mxModel );
81 uno::Any
82 ScVbaComments::createCollectionObject( const css::uno::Any& aSource )
84 return AnnotationToComment( aSource, mxContext, mxModel );
87 uno::Type
88 ScVbaComments::getElementType()
90 return cppu::UnoType<excel::XComment>::get();
93 OUString
94 ScVbaComments::getServiceImplName()
96 return "ScVbaComments";
99 css::uno::Sequence<OUString>
100 ScVbaComments::getServiceNames()
102 static uno::Sequence< OUString > const sNames
104 "ooo.vba.excel.Comments"
106 return sNames;
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */