sc: factor out some more code
[LibreOffice.git] / sw / source / ui / vba / vbapanes.cxx
blob0c6a4765a9408c185de3dc2622646f63a16807e4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include "vbapanes.hxx"
20 #include "vbapane.hxx"
21 #include <cppuhelper/implbase.hxx>
22 #include <unotxdoc.hxx>
23 #include <utility>
25 using namespace ::ooo::vba;
26 using namespace ::com::sun::star;
28 namespace {
30 // I assume there is only one pane in Writer
31 class PanesIndexAccess : public ::cppu::WeakImplHelper<container::XIndexAccess >
33 private:
34 uno::Reference< XHelperInterface > mxParent;
35 uno::Reference< uno::XComponentContext > mxContext;
36 rtl::Reference< SwXTextDocument > mxModel;
38 public:
39 PanesIndexAccess( uno::Reference< XHelperInterface > xParent,
40 uno::Reference< uno::XComponentContext > xContext,
41 rtl::Reference< SwXTextDocument > xModel )
42 : mxParent(std::move( xParent )), mxContext(std::move( xContext )), mxModel(std::move( xModel )) {}
44 // XIndexAccess
45 virtual sal_Int32 SAL_CALL getCount( ) override
47 return 1;
49 virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override
51 if( Index != 0 )
52 throw lang::IndexOutOfBoundsException();
53 return uno::Any( uno::Reference< word::XPane >( new SwVbaPane( mxParent, mxContext, mxModel ) ) );
55 virtual uno::Type SAL_CALL getElementType( ) override
57 return cppu::UnoType<word::XPane>::get();
59 virtual sal_Bool SAL_CALL hasElements( ) override
61 return true;
65 class PanesEnumWrapper : public EnumerationHelper_BASE
67 uno::Reference<container::XIndexAccess > m_xIndexAccess;
68 sal_Int32 m_nIndex;
69 public:
70 explicit PanesEnumWrapper( uno::Reference< container::XIndexAccess > xIndexAccess ) : m_xIndexAccess(std::move( xIndexAccess )), m_nIndex( 0 ) {}
71 virtual sal_Bool SAL_CALL hasMoreElements( ) override
73 return ( m_nIndex < m_xIndexAccess->getCount() );
76 virtual uno::Any SAL_CALL nextElement( ) override
78 if ( m_nIndex < m_xIndexAccess->getCount() )
79 return m_xIndexAccess->getByIndex( m_nIndex++ );
80 throw container::NoSuchElementException();
86 SwVbaPanes::SwVbaPanes( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const rtl::Reference< SwXTextDocument >& xModel ): SwVbaPanes_BASE( xParent, xContext, new PanesIndexAccess( xParent, xContext, xModel ) )
90 // XEnumerationAccess
91 uno::Type
92 SwVbaPanes::getElementType()
94 return cppu::UnoType<word::XPane>::get();
96 uno::Reference< container::XEnumeration >
97 SwVbaPanes::createEnumeration()
99 return new PanesEnumWrapper( m_xIndexAccess );
102 uno::Any
103 SwVbaPanes::createCollectionObject( const css::uno::Any& aSource )
105 return aSource;
108 OUString
109 SwVbaPanes::getServiceImplName()
111 return u"SwVbaPanes"_ustr;
114 css::uno::Sequence<OUString>
115 SwVbaPanes::getServiceNames()
117 static uno::Sequence< OUString > const sNames
119 u"ooo.vba.word.Panes"_ustr
121 return sNames;
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */