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