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