xref: /aoo41x/main/sw/source/ui/vba/vbapanes.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #include "vbapanes.hxx"
28 #include "vbapane.hxx"
29 
30 using namespace ::ooo::vba;
31 using namespace ::com::sun::star;
32 
33 // I assume there is only one pane in Writer
34 typedef ::cppu::WeakImplHelper1<container::XIndexAccess > PanesIndexAccess_Base;
35 class PanesIndexAccess : public PanesIndexAccess_Base
36 {
37 private:
38     uno::Reference< XHelperInterface > mxParent;
39     uno::Reference< uno::XComponentContext > mxContext;
40     uno::Reference< frame::XModel > mxModel;
41 
42 public:
43     PanesIndexAccess( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) : mxParent( xParent ), mxContext( xContext ), mxModel( xModel ) {}
44     ~PanesIndexAccess(){}
45 
46     // XIndexAccess
47     virtual sal_Int32 SAL_CALL getCount(  ) throw (uno::RuntimeException)
48     {
49         return 1;
50     }
51     virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
52     {
53         if( Index != 1 )
54             throw container::NoSuchElementException();
55         return uno::makeAny( uno::Reference< word::XPane >( new SwVbaPane( mxParent,  mxContext, mxModel ) ) );
56     }
57     virtual uno::Type SAL_CALL getElementType(  ) throw (uno::RuntimeException)
58     {
59         return word::XPane::static_type(0);
60     }
61     virtual sal_Bool SAL_CALL hasElements(  ) throw (uno::RuntimeException)
62     {
63         return sal_True;
64     }
65 };
66 
67 class PanesEnumWrapper : public EnumerationHelper_BASE
68 {
69 	uno::Reference<container::XIndexAccess > m_xIndexAccess;
70 	sal_Int32 nIndex;
71 public:
72 	PanesEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {}
73 	virtual ::sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException)
74 	{
75 		return ( nIndex < m_xIndexAccess->getCount() );
76 	}
77 
78 	virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
79 	{
80 		if ( nIndex < m_xIndexAccess->getCount() )
81 			return m_xIndexAccess->getByIndex( nIndex++ );
82 		throw container::NoSuchElementException();
83 	}
84 };
85 
86 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 )
87 {
88 }
89 // XEnumerationAccess
90 uno::Type
91 SwVbaPanes::getElementType() throw (uno::RuntimeException)
92 {
93 	return word::XPane::static_type(0);
94 }
95 uno::Reference< container::XEnumeration >
96 SwVbaPanes::createEnumeration() throw (uno::RuntimeException)
97 {
98     return new PanesEnumWrapper( m_xIndexAccess );
99 }
100 
101 uno::Any
102 SwVbaPanes::createCollectionObject( const css::uno::Any& aSource )
103 {
104     return aSource;
105 }
106 
107 rtl::OUString&
108 SwVbaPanes::getServiceImplName()
109 {
110 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaPanes") );
111 	return sImplName;
112 }
113 
114 css::uno::Sequence<rtl::OUString>
115 SwVbaPanes::getServiceNames()
116 {
117 	static uno::Sequence< rtl::OUString > sNames;
118 	if ( sNames.getLength() == 0 )
119 	{
120 		sNames.realloc( 1 );
121 		sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Panes") );
122 	}
123 	return sNames;
124 }
125