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