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 
27 using namespace ::ooo::vba;
28 using namespace ::com::sun::star;
29 
30 static 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::makeAny( uno::Reference< excel::XComment > (
38  new ScVbaComment( uno::Reference< XHelperInterface >(), xContext, xModel, xCellRange ) ) );
39 }
40 
41 namespace {
42 
43 class CommentEnumeration : public EnumerationHelperImpl
44 {
45  css::uno::Reference< css::frame::XModel > mxModel;
46 public:
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 
78 uno::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 
86 ScVbaComments::createCollectionObject( const css::uno::Any& aSource )
87 {
88  return AnnotationToComment( aSource, mxContext, mxModel );
89 }
90 
93 {
95 }
96 
97 OUString
99 {
100  return "ScVbaComments";
101 }
102 
103 css::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::container::XIndexAccess > m_xIndexAccess
css::uno::Reference< css::frame::XModel2 > mxModel
static uno::Any AnnotationToComment(const uno::Any &aSource, const uno::Reference< uno::XComponentContext > &xContext, const uno::Reference< frame::XModel > &xModel)
Definition: vbacomments.cxx:30
virtual OUString getServiceImplName() override
Definition: vbacomments.cxx:98
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: vbacomments.cxx:79
css::uno::WeakReference< ov::XHelperInterface > mxParent
css::uno::Type const & get()
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Sequence< OUString > getServiceNames() override
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
css::uno::Reference< css::uno::XComponentContext > m_xContext
css::uno::Reference< css::frame::XModel > mxModel
Definition: vbacomments.hxx:47
virtual css::uno::Type SAL_CALL getElementType() override
Definition: vbacomments.cxx:92
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
Definition: vbacomments.cxx:86