update dev300-m58
[ooovba.git] / sw / source / ui / vba / vbapanes.cxx
blob5cd35e26964070e0715fa1f3f5a857549ea06353
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile:
10 * $Revision:
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "vbapanes.hxx"
31 #include "vbapane.hxx"
33 using namespace ::ooo::vba;
34 using namespace ::com::sun::star;
36 // I assume there is only one pane in Writer
37 typedef ::cppu::WeakImplHelper1<container::XIndexAccess > PanesIndexAccess_Base;
38 class PanesIndexAccess : public PanesIndexAccess_Base
40 private:
41 uno::Reference< XHelperInterface > mxParent;
42 uno::Reference< uno::XComponentContext > mxContext;
43 uno::Reference< frame::XModel > mxModel;
45 public:
46 PanesIndexAccess( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) : mxParent( xParent ), mxContext( xContext ), mxModel( xModel ) {}
47 ~PanesIndexAccess(){}
49 // XIndexAccess
50 virtual sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
52 return 1;
54 virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
56 if( Index != 1 )
57 throw container::NoSuchElementException();
58 return uno::makeAny( uno::Reference< word::XPane >( new SwVbaPane( mxParent, mxContext, mxModel ) ) );
60 virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
62 return word::XPane::static_type(0);
64 virtual sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
66 return sal_True;
70 class PanesEnumWrapper : public EnumerationHelper_BASE
72 uno::Reference<container::XIndexAccess > m_xIndexAccess;
73 sal_Int32 nIndex;
74 public:
75 PanesEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {}
76 virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException)
78 return ( nIndex < m_xIndexAccess->getCount() );
81 virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
83 if ( nIndex < m_xIndexAccess->getCount() )
84 return m_xIndexAccess->getByIndex( nIndex++ );
85 throw container::NoSuchElementException();
89 SwVbaPanes::SwVbaPanes( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel ): SwVbaPanes_BASE( xParent, xContext, new PanesIndexAccess( xParent, xContext, xModel ) ), mxModel( xModel )
92 // XEnumerationAccess
93 uno::Type
94 SwVbaPanes::getElementType() throw (uno::RuntimeException)
96 return word::XPane::static_type(0);
98 uno::Reference< container::XEnumeration >
99 SwVbaPanes::createEnumeration() throw (uno::RuntimeException)
101 return new PanesEnumWrapper( m_xIndexAccess );
104 uno::Any
105 SwVbaPanes::createCollectionObject( const css::uno::Any& aSource )
107 return aSource;
110 rtl::OUString&
111 SwVbaPanes::getServiceImplName()
113 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaPanes") );
114 return sImplName;
117 css::uno::Sequence<rtl::OUString>
118 SwVbaPanes::getServiceNames()
120 static uno::Sequence< rtl::OUString > sNames;
121 if ( sNames.getLength() == 0 )
123 sNames.realloc( 1 );
124 sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Panes") );
126 return sNames;