1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
24 using namespace ::ooo::vba
;
25 using namespace ::com::sun::star
;
29 // I assume there is only one headersfooters in Writer
30 class HeadersFootersIndexAccess
: public ::cppu::WeakImplHelper
<container::XIndexAccess
>
33 uno::Reference
< XHelperInterface
> mxParent
;
34 uno::Reference
< uno::XComponentContext
> mxContext
;
35 uno::Reference
< frame::XModel
> mxModel
;
36 uno::Reference
< beans::XPropertySet
> mxPageStyleProps
;
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
) {}
43 virtual sal_Int32 SAL_CALL
getCount( ) override
45 // first page, even pages and primary page
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
64 class HeadersFootersEnumWrapper
: public EnumerationHelper_BASE
66 SwVbaHeadersFooters
* m_pHeadersFooters
;
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
95 uno::Any SAL_CALL
SwVbaHeadersFooters::Item( const uno::Any
& Index1
, const uno::Any
& )
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
108 SwVbaHeadersFooters::getElementType()
110 return cppu::UnoType
<word::XHeaderFooter
>::get();
112 uno::Reference
< container::XEnumeration
>
114 SwVbaHeadersFooters::createEnumeration()
116 return new HeadersFootersEnumWrapper( this );
120 SwVbaHeadersFooters::createCollectionObject( const uno::Any
& aSource
)
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"
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */