LibreOffice Module sw (master)  1
vbapanes.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 "vbapanes.hxx"
20 #include "vbapane.hxx"
21 #include <cppuhelper/implbase.hxx>
22 
23 using namespace ::ooo::vba;
24 using namespace ::com::sun::star;
25 
26 // I assume there is only one pane in Writer
27 class PanesIndexAccess : public ::cppu::WeakImplHelper<container::XIndexAccess >
28 {
29 private:
30  uno::Reference< XHelperInterface > mxParent;
31  uno::Reference< uno::XComponentContext > mxContext;
32  uno::Reference< frame::XModel > mxModel;
33 
34 public:
35  PanesIndexAccess( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) : mxParent( xParent ), mxContext( xContext ), mxModel( xModel ) {}
36 
37  // XIndexAccess
38  virtual sal_Int32 SAL_CALL getCount( ) override
39  {
40  return 1;
41  }
42  virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override
43  {
44  if( Index != 0 )
45  throw lang::IndexOutOfBoundsException();
46  return uno::makeAny( uno::Reference< word::XPane >( new SwVbaPane( mxParent, mxContext, mxModel ) ) );
47  }
48  virtual uno::Type SAL_CALL getElementType( ) override
49  {
51  }
52  virtual sal_Bool SAL_CALL hasElements( ) override
53  {
54  return true;
55  }
56 };
57 
59 {
60  uno::Reference<container::XIndexAccess > m_xIndexAccess;
61  sal_Int32 nIndex;
62 public:
63  explicit PanesEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {}
64  virtual sal_Bool SAL_CALL hasMoreElements( ) override
65  {
66  return ( nIndex < m_xIndexAccess->getCount() );
67  }
68 
69  virtual uno::Any SAL_CALL nextElement( ) override
70  {
71  if ( nIndex < m_xIndexAccess->getCount() )
72  return m_xIndexAccess->getByIndex( nIndex++ );
73  throw container::NoSuchElementException();
74  }
75 };
76 
77 SwVbaPanes::SwVbaPanes( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel ): SwVbaPanes_BASE( xParent, xContext, new PanesIndexAccess( xParent, xContext, xModel ) )
78 {
79 }
80 // XEnumerationAccess
83 {
85 }
86 uno::Reference< container::XEnumeration >
88 {
89  return new PanesEnumWrapper( m_xIndexAccess );
90 }
91 
93 SwVbaPanes::createCollectionObject( const css::uno::Any& aSource )
94 {
95  return aSource;
96 }
97 
98 OUString
100 {
101  return "SwVbaPanes";
102 }
103 
104 css::uno::Sequence<OUString>
106 {
107  static uno::Sequence< OUString > const sNames
108  {
109  "ooo.vba.word.Panes"
110  };
111  return sNames;
112 }
113 
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
uno::Reference< frame::XModel > mxModel
Definition: vbapanes.cxx:32
PanesIndexAccess(const uno::Reference< XHelperInterface > &xParent, const uno::Reference< uno::XComponentContext > &xContext, const uno::Reference< frame::XModel > &xModel)
Definition: vbapanes.cxx:35
virtual sal_Int32 SAL_CALL getCount() override
Definition: vbapanes.cxx:38
virtual uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
Definition: vbapanes.cxx:42
virtual css::uno::Type SAL_CALL getElementType() override
Definition: vbapanes.cxx:82
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE
virtual uno::Any SAL_CALL nextElement() override
Definition: vbapanes.cxx:69
uno::Reference< XHelperInterface > mxParent
Definition: vbapanes.cxx:30
sal_Int32 nIndex
Definition: vbapanes.cxx:61
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: vbapanes.cxx:87
PanesEnumWrapper(const uno::Reference< container::XIndexAccess > &xIndexAccess)
Definition: vbapanes.cxx:63
SwVbaPanes(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel > &xModel)
Definition: vbapanes.cxx:77
virtual OUString getServiceImplName() override
Definition: vbapanes.cxx:99
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbapanes.cxx:105
unsigned char sal_Bool
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
Definition: vbapanes.cxx:93
css::uno::Type const & get()
virtual sal_Bool SAL_CALL hasMoreElements() override
Definition: vbapanes.cxx:64
uno::Reference< uno::XComponentContext > mxContext
Definition: vbapanes.cxx:31
virtual uno::Type SAL_CALL getElementType() override
Definition: vbapanes.cxx:48
virtual sal_Bool SAL_CALL hasElements() override
Definition: vbapanes.cxx:52
uno::Reference< container::XIndexAccess > m_xIndexAccess
Definition: vbapanes.cxx:60