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