android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / vba / vbaheadersfooters.cxx
blobbe205d8e13db42a1f381979b7f02bf168e114e3d
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 "vbaheadersfooters.hxx"
20 #include "vbaheaderfooter.hxx"
21 #include <cppuhelper/implbase.hxx>
22 #include <utility>
24 using namespace ::ooo::vba;
25 using namespace ::com::sun::star;
27 namespace {
29 // I assume there is only one headersfooters in Writer
30 class HeadersFootersIndexAccess : public ::cppu::WeakImplHelper<container::XIndexAccess >
32 private:
33 uno::Reference< XHelperInterface > mxParent;
34 uno::Reference< uno::XComponentContext > mxContext;
35 uno::Reference< frame::XModel > mxModel;
36 uno::Reference< beans::XPropertySet > mxPageStyleProps;
37 bool mbHeader;
39 public:
40 HeadersFootersIndexAccess( uno::Reference< XHelperInterface > xParent, uno::Reference< uno::XComponentContext > xContext, uno::Reference< frame::XModel > xModel, uno::Reference< beans::XPropertySet > xPageStyleProps, bool bHeader ) : mxParent(std::move( xParent )), mxContext(std::move( xContext )), mxModel(std::move( xModel )), mxPageStyleProps(std::move( xPageStyleProps )), mbHeader( bHeader ) {}
42 // XIndexAccess
43 virtual sal_Int32 SAL_CALL getCount( ) override
45 // first page, even pages and primary page
46 return 3;
48 virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override
50 if( Index < 1 || Index > 3 )
51 throw lang::IndexOutOfBoundsException();
52 return uno::Any( uno::Reference< word::XHeaderFooter >( new SwVbaHeaderFooter( mxParent, mxContext, mxModel, mxPageStyleProps, mbHeader, Index ) ) );
54 virtual uno::Type SAL_CALL getElementType( ) override
56 return cppu::UnoType<word::XHeaderFooter>::get();
58 virtual sal_Bool SAL_CALL hasElements( ) override
60 return true;
64 class HeadersFootersEnumWrapper : public EnumerationHelper_BASE
66 SwVbaHeadersFooters* m_pHeadersFooters;
67 sal_Int32 m_nIndex;
68 public:
69 explicit HeadersFootersEnumWrapper( SwVbaHeadersFooters* _pHeadersFooters ) : m_pHeadersFooters( _pHeadersFooters ), m_nIndex( 0 ) {}
70 virtual sal_Bool SAL_CALL hasMoreElements( ) override
72 return ( m_nIndex < m_pHeadersFooters->getCount() );
75 virtual uno::Any SAL_CALL nextElement( ) override
77 if ( m_nIndex < m_pHeadersFooters->getCount() )
78 return m_pHeadersFooters->Item( uno::Any( ++m_nIndex ), uno::Any() );
79 throw container::NoSuchElementException();
85 SwVbaHeadersFooters::SwVbaHeadersFooters( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel, const uno::Reference< beans::XPropertySet >& xPageStyleProps, bool isHeader ): SwVbaHeadersFooters_BASE( xParent, xContext, new HeadersFootersIndexAccess( xParent, xContext, xModel, xPageStyleProps, isHeader ) ), mxModel( xModel ), mxPageStyleProps( xPageStyleProps ), mbHeader( isHeader )
89 ::sal_Int32 SAL_CALL SwVbaHeadersFooters::getCount()
91 // wdHeaderFooterFirstPage, wdHeaderFooterPrimary and wdHeaderFooterEvenPages
92 return 3;
95 uno::Any SAL_CALL SwVbaHeadersFooters::Item( const uno::Any& Index1, const uno::Any& )
97 sal_Int32 nIndex = 0;
98 Index1 >>= nIndex;
99 if( ( nIndex < 1 ) || ( nIndex > 3 ) )
101 throw lang::IndexOutOfBoundsException();
103 return uno::Any( uno::Reference< word::XHeaderFooter >( new SwVbaHeaderFooter( this, mxContext, mxModel, mxPageStyleProps, mbHeader, nIndex ) ) );
106 // XEnumerationAccess
107 uno::Type
108 SwVbaHeadersFooters::getElementType()
110 return cppu::UnoType<word::XHeaderFooter>::get();
112 uno::Reference< container::XEnumeration >
114 SwVbaHeadersFooters::createEnumeration()
116 return new HeadersFootersEnumWrapper( this );
119 uno::Any
120 SwVbaHeadersFooters::createCollectionObject( const uno::Any& aSource )
122 return aSource;
125 OUString
126 SwVbaHeadersFooters::getServiceImplName()
128 return "SwVbaHeadersFooters";
131 uno::Sequence<OUString>
132 SwVbaHeadersFooters::getServiceNames()
134 static uno::Sequence< OUString > const sNames
136 "ooo.vba.word.HeadersFooters"
138 return sNames;
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */