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