LibreOffice Module sw (master) 1
vbaheadersfooters.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 "vbaheadersfooters.hxx"
20#include "vbaheaderfooter.hxx"
22#include <utility>
23
24using namespace ::ooo::vba;
25using namespace ::com::sun::star;
26
27namespace {
28
29// I assume there is only one headersfooters in Writer
30class HeadersFootersIndexAccess : 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 uno::Reference< beans::XPropertySet > mxPageStyleProps;
37 bool mbHeader;
38
39public:
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 ) {}
41
42 // XIndexAccess
43 virtual sal_Int32 SAL_CALL getCount( ) override
44 {
45 // first page, even pages and primary page
46 return 3;
47 }
48 virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override
49 {
51 throw lang::IndexOutOfBoundsException();
52 return uno::Any( uno::Reference< word::XHeaderFooter >( new SwVbaHeaderFooter( mxParent, mxContext, mxModel, mxPageStyleProps, mbHeader, Index ) ) );
53 }
54 virtual uno::Type SAL_CALL getElementType( ) override
55 {
57 }
58 virtual sal_Bool SAL_CALL hasElements( ) override
59 {
60 return true;
61 }
62};
63
64class HeadersFootersEnumWrapper : public EnumerationHelper_BASE
65{
66 SwVbaHeadersFooters* m_pHeadersFooters;
67 sal_Int32 m_nIndex;
68public:
69 explicit HeadersFootersEnumWrapper( SwVbaHeadersFooters* _pHeadersFooters ) : m_pHeadersFooters( _pHeadersFooters ), m_nIndex( 0 ) {}
70 virtual sal_Bool SAL_CALL hasMoreElements( ) override
71 {
72 return ( m_nIndex < m_pHeadersFooters->getCount() );
73 }
74
75 virtual uno::Any SAL_CALL nextElement( ) override
76 {
77 if ( m_nIndex < m_pHeadersFooters->getCount() )
78 return m_pHeadersFooters->Item( uno::Any( ++m_nIndex ), uno::Any() );
79 throw container::NoSuchElementException();
80 }
81};
82
83}
84
85SwVbaHeadersFooters::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 )
86{
87}
88
89::sal_Int32 SAL_CALL SwVbaHeadersFooters::getCount()
90{
91 // wdHeaderFooterFirstPage, wdHeaderFooterPrimary and wdHeaderFooterEvenPages
92 return 3;
93}
94
95uno::Any SAL_CALL SwVbaHeadersFooters::Item( const uno::Any& Index1, const uno::Any& )
96{
97 sal_Int32 nIndex = 0;
98 Index1 >>= nIndex;
99 if( ( nIndex < 1 ) || ( nIndex > 3 ) )
100 {
101 throw lang::IndexOutOfBoundsException();
102 }
103 return uno::Any( uno::Reference< word::XHeaderFooter >( new SwVbaHeaderFooter( this, mxContext, mxModel, mxPageStyleProps, mbHeader, nIndex ) ) );
104}
105
106// XEnumerationAccess
109{
111}
112uno::Reference< container::XEnumeration >
113
115{
116 return new HeadersFootersEnumWrapper( this );
117}
118
121{
122 return aSource;
123}
124
125OUString
127{
128 return "SwVbaHeadersFooters";
129}
130
131uno::Sequence<OUString>
133{
134 static uno::Sequence< OUString > const sNames
135 {
136 "ooo.vba.word.HeadersFooters"
137 };
138 return sNames;
139}
140
141/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOIndex Index
css::uno::Reference< css::frame::XModel2 > mxModel
unotools::WeakReference< AnimationNode > mxParent
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual OUString getServiceImplName() override
css::uno::Reference< css::beans::XPropertySet > mxPageStyleProps
virtual css::uno::Sequence< OUString > getServiceNames() override
css::uno::Reference< css::frame::XModel > mxModel
SwVbaHeadersFooters(const css::uno::Reference< ooo::vba::XHelperInterface > &rParent, const css::uno::Reference< css::uno::XComponentContext > &rContext, const css::uno::Reference< css::frame::XModel > &xModel, const css::uno::Reference< css::beans::XPropertySet > &xProps, bool isHeader)
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &Index1, const css::uno::Any &) override
virtual css::uno::Type SAL_CALL getElementType() override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
virtual ::sal_Int32 SAL_CALL getCount() override
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