1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10*efeef26fSAndrew Rist *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19*efeef26fSAndrew Rist *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir #include "vbapanes.hxx"
24cdf0e10cSrcweir #include "vbapane.hxx"
25cdf0e10cSrcweir
26cdf0e10cSrcweir using namespace ::ooo::vba;
27cdf0e10cSrcweir using namespace ::com::sun::star;
28cdf0e10cSrcweir
29cdf0e10cSrcweir // I assume there is only one pane in Writer
30cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1<container::XIndexAccess > PanesIndexAccess_Base;
31cdf0e10cSrcweir class PanesIndexAccess : public PanesIndexAccess_Base
32cdf0e10cSrcweir {
33cdf0e10cSrcweir private:
34cdf0e10cSrcweir uno::Reference< XHelperInterface > mxParent;
35cdf0e10cSrcweir uno::Reference< uno::XComponentContext > mxContext;
36cdf0e10cSrcweir uno::Reference< frame::XModel > mxModel;
37cdf0e10cSrcweir
38cdf0e10cSrcweir public:
PanesIndexAccess(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<frame::XModel> & xModel)39cdf0e10cSrcweir PanesIndexAccess( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) : mxParent( xParent ), mxContext( xContext ), mxModel( xModel ) {}
~PanesIndexAccess()40cdf0e10cSrcweir ~PanesIndexAccess(){}
41cdf0e10cSrcweir
42cdf0e10cSrcweir // XIndexAccess
getCount()43cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
44cdf0e10cSrcweir {
45cdf0e10cSrcweir return 1;
46cdf0e10cSrcweir }
getByIndex(sal_Int32 Index)47cdf0e10cSrcweir virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
48cdf0e10cSrcweir {
49cdf0e10cSrcweir if( Index != 1 )
50cdf0e10cSrcweir throw container::NoSuchElementException();
51cdf0e10cSrcweir return uno::makeAny( uno::Reference< word::XPane >( new SwVbaPane( mxParent, mxContext, mxModel ) ) );
52cdf0e10cSrcweir }
getElementType()53cdf0e10cSrcweir virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
54cdf0e10cSrcweir {
55cdf0e10cSrcweir return word::XPane::static_type(0);
56cdf0e10cSrcweir }
hasElements()57cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
58cdf0e10cSrcweir {
59cdf0e10cSrcweir return sal_True;
60cdf0e10cSrcweir }
61cdf0e10cSrcweir };
62cdf0e10cSrcweir
63cdf0e10cSrcweir class PanesEnumWrapper : public EnumerationHelper_BASE
64cdf0e10cSrcweir {
65cdf0e10cSrcweir uno::Reference<container::XIndexAccess > m_xIndexAccess;
66cdf0e10cSrcweir sal_Int32 nIndex;
67cdf0e10cSrcweir public:
PanesEnumWrapper(const uno::Reference<container::XIndexAccess> & xIndexAccess)68cdf0e10cSrcweir PanesEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {}
hasMoreElements()69cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir return ( nIndex < m_xIndexAccess->getCount() );
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
nextElement()74cdf0e10cSrcweir virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
75cdf0e10cSrcweir {
76cdf0e10cSrcweir if ( nIndex < m_xIndexAccess->getCount() )
77cdf0e10cSrcweir return m_xIndexAccess->getByIndex( nIndex++ );
78cdf0e10cSrcweir throw container::NoSuchElementException();
79cdf0e10cSrcweir }
80cdf0e10cSrcweir };
81cdf0e10cSrcweir
SwVbaPanes(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<frame::XModel> & xModel)82cdf0e10cSrcweir 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 )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir }
85cdf0e10cSrcweir // XEnumerationAccess
86cdf0e10cSrcweir uno::Type
getElementType()87cdf0e10cSrcweir SwVbaPanes::getElementType() throw (uno::RuntimeException)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir return word::XPane::static_type(0);
90cdf0e10cSrcweir }
91cdf0e10cSrcweir uno::Reference< container::XEnumeration >
createEnumeration()92cdf0e10cSrcweir SwVbaPanes::createEnumeration() throw (uno::RuntimeException)
93cdf0e10cSrcweir {
94cdf0e10cSrcweir return new PanesEnumWrapper( m_xIndexAccess );
95cdf0e10cSrcweir }
96cdf0e10cSrcweir
97cdf0e10cSrcweir uno::Any
createCollectionObject(const css::uno::Any & aSource)98cdf0e10cSrcweir SwVbaPanes::createCollectionObject( const css::uno::Any& aSource )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir return aSource;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
103cdf0e10cSrcweir rtl::OUString&
getServiceImplName()104cdf0e10cSrcweir SwVbaPanes::getServiceImplName()
105cdf0e10cSrcweir {
106cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaPanes") );
107cdf0e10cSrcweir return sImplName;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
110cdf0e10cSrcweir css::uno::Sequence<rtl::OUString>
getServiceNames()111cdf0e10cSrcweir SwVbaPanes::getServiceNames()
112cdf0e10cSrcweir {
113cdf0e10cSrcweir static uno::Sequence< rtl::OUString > sNames;
114cdf0e10cSrcweir if ( sNames.getLength() == 0 )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir sNames.realloc( 1 );
117cdf0e10cSrcweir sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Panes") );
118cdf0e10cSrcweir }
119cdf0e10cSrcweir return sNames;
120cdf0e10cSrcweir }
121