Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2008 by Sun Microsystems, Inc.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #include "vbaheadersfooters.hxx"
29 : : #include "vbaheaderfooter.hxx"
30 : : #include <ooo/vba/word/WdHeaderFooterIndex.hpp>
31 : :
32 : : using namespace ::ooo::vba;
33 : : using namespace ::com::sun::star;
34 : :
35 : : // I assume there is only one headersfooters in Writer
36 : : typedef ::cppu::WeakImplHelper1<container::XIndexAccess > HeadersFootersIndexAccess_Base;
37 : : class HeadersFootersIndexAccess : public HeadersFootersIndexAccess_Base
38 : : {
39 : : private:
40 : : uno::Reference< XHelperInterface > mxParent;
41 : : uno::Reference< uno::XComponentContext > mxContext;
42 : : uno::Reference< frame::XModel > mxModel;
43 : : uno::Reference< beans::XPropertySet > mxPageStyleProps;
44 : : sal_Bool mbHeader;
45 : :
46 : : public:
47 : 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 ) {}
48 [ # # ]: 0 : ~HeadersFootersIndexAccess(){}
49 : :
50 : : // XIndexAccess
51 : 0 : virtual sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
52 : : {
53 : : // first page, evenpages and primary page
54 : 0 : return 3;
55 : : }
56 : 0 : virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
57 : : {
58 [ # # ][ # # ]: 0 : if( Index < 1 || Index > 3 )
59 [ # # ]: 0 : throw container::NoSuchElementException();
60 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< word::XHeaderFooter >( new SwVbaHeaderFooter( mxParent, mxContext, mxModel, mxPageStyleProps, mbHeader, Index ) ) );
[ # # ]
61 : : }
62 : 0 : virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
63 : : {
64 : 0 : return word::XHeaderFooter::static_type(0);
65 : : }
66 : 0 : virtual sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
67 : : {
68 : 0 : return sal_True;
69 : : }
70 : : };
71 : :
72 [ # # ]: 0 : class HeadersFootersEnumWrapper : public EnumerationHelper_BASE
73 : : {
74 : : SwVbaHeadersFooters* pHeadersFooters;
75 : : sal_Int32 nIndex;
76 : : public:
77 : 0 : HeadersFootersEnumWrapper( SwVbaHeadersFooters* _pHeadersFooters ) : pHeadersFooters( _pHeadersFooters ), nIndex( 0 ) {}
78 : 0 : virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException)
79 : : {
80 : 0 : return ( nIndex < pHeadersFooters->getCount() );
81 : : }
82 : :
83 : 0 : virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
84 : : {
85 [ # # ]: 0 : if ( nIndex < pHeadersFooters->getCount() )
86 [ # # ][ # # ]: 0 : return pHeadersFooters->Item( uno::makeAny( ++nIndex ), uno::Any() );
87 [ # # ]: 0 : throw container::NoSuchElementException();
88 : : }
89 : : };
90 : :
91 [ # # ][ # # ]: 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 )
[ # # ]
92 : : {
93 : 0 : }
94 : :
95 : 0 : ::sal_Int32 SAL_CALL SwVbaHeadersFooters::getCount() throw (uno::RuntimeException)
96 : : {
97 : : // wdHeaderFooterFirstPage, wdHeaderFooterPrimary and wdHeaderFooterEvenPages
98 : 0 : return 3;
99 : : }
100 : :
101 : 0 : uno::Any SAL_CALL SwVbaHeadersFooters::Item( const uno::Any& Index1, const uno::Any& ) throw (uno::RuntimeException)
102 : : {
103 : 0 : sal_Int32 nIndex = 0;
104 : 0 : Index1 >>= nIndex;
105 [ # # ][ # # ]: 0 : if( ( nIndex < 1 ) || ( nIndex > 3 ) )
106 : : {
107 [ # # ]: 0 : throw container::NoSuchElementException();
108 : : }
109 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< word::XHeaderFooter >( new SwVbaHeaderFooter( this, mxContext, mxModel, mxPageStyleProps, mbHeader, nIndex ) ) );
[ # # ][ # # ]
[ # # ]
110 : : }
111 : :
112 : : // XEnumerationAccess
113 : : uno::Type
114 : 0 : SwVbaHeadersFooters::getElementType() throw (uno::RuntimeException)
115 : : {
116 : 0 : return word::XHeaderFooter::static_type(0);
117 : : }
118 : : uno::Reference< container::XEnumeration >
119 : :
120 : 0 : SwVbaHeadersFooters::createEnumeration() throw (uno::RuntimeException)
121 : : {
122 [ # # ][ # # ]: 0 : return new HeadersFootersEnumWrapper( this );
123 : : }
124 : :
125 : : uno::Any
126 : 0 : SwVbaHeadersFooters::createCollectionObject( const uno::Any& aSource )
127 : : {
128 : 0 : return aSource;
129 : : }
130 : :
131 : : rtl::OUString
132 : 0 : SwVbaHeadersFooters::getServiceImplName()
133 : : {
134 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaHeadersFooters"));
135 : : }
136 : :
137 : : uno::Sequence<rtl::OUString>
138 : 0 : SwVbaHeadersFooters::getServiceNames()
139 : : {
140 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > sNames;
[ # # ][ # # ]
141 [ # # ]: 0 : if ( sNames.getLength() == 0 )
142 : : {
143 : 0 : sNames.realloc( 1 );
144 [ # # ]: 0 : sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.HeadersFooters") );
145 : : }
146 : 0 : return sNames;
147 : : }
148 : :
149 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|