LibreOffice Module sc (master) 1
vbacomments.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#include "vbacomments.hxx"
20#include "vbacomment.hxx"
21
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>
26
27using namespace ::ooo::vba;
28using namespace ::com::sun::star;
29
30static uno::Any AnnotationToComment( const uno::Any& aSource, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel )
31{
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 );
35
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 ) ) );
39}
40
41namespace {
42
43class CommentEnumeration : public EnumerationHelperImpl
44{
45 css::uno::Reference< css::frame::XModel > mxModel;
46public:
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 ) :
53 EnumerationHelperImpl( xParent, xContext, xEnumeration ),
54 mxModel( xModel, uno::UNO_SET_THROW )
55 {}
56
57 virtual uno::Any SAL_CALL nextElement() override
58 {
59 return AnnotationToComment( m_xEnumeration->nextElement(), m_xContext, mxModel );
60 }
61
62};
63
64}
65
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 )
73{
74}
75
76// public helper functions
77
78uno::Reference< container::XEnumeration >
80{
81 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
82 return new CommentEnumeration( mxParent, mxContext, xEnumAccess->createEnumeration(), mxModel );
83}
84
86ScVbaComments::createCollectionObject( const css::uno::Any& aSource )
87{
88 return AnnotationToComment( aSource, mxContext, mxModel );
89}
90
93{
95}
96
97OUString
99{
100 return "ScVbaComments";
101}
102
103css::uno::Sequence<OUString>
105{
106 static uno::Sequence< OUString > const sNames
107 {
108 "ooo.vba.excel.Comments"
109 };
110 return sNames;
111}
112
113/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::frame::XModel2 > mxModel
css::uno::Reference< css::uno::XComponentContext > mxContext
css::uno::WeakReference< ov::XHelperInterface > mxParent
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
virtual OUString getServiceImplName() override
Definition: vbacomments.cxx:98
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: vbacomments.cxx:79
virtual css::uno::Sequence< OUString > getServiceNames() override
css::uno::Reference< css::frame::XModel > mxModel
Definition: vbacomments.hxx:46
virtual css::uno::Type SAL_CALL getElementType() override
Definition: vbacomments.cxx:92
ScVbaComments(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel > &xModel, const css::uno::Reference< css::container::XIndexAccess > &xIndexAccess)
Definition: vbacomments.cxx:66
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
Definition: vbacomments.cxx:86
css::uno::Type const & get()
Reference< XModel > xModel
static uno::Any AnnotationToComment(const uno::Any &aSource, const uno::Reference< uno::XComponentContext > &xContext, const uno::Reference< frame::XModel > &xModel)
Definition: vbacomments.cxx:30