xref: /AOO41X/main/vbahelper/inc/vbahelper/vbahelperinterface.hxx (revision d4a7ee096095edc0140da98aca6f220cb09e0281)
1*d4a7ee09SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d4a7ee09SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d4a7ee09SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d4a7ee09SAndrew Rist  * distributed with this work for additional information
6*d4a7ee09SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d4a7ee09SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d4a7ee09SAndrew Rist  * "License"); you may not use this file except in compliance
9*d4a7ee09SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*d4a7ee09SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*d4a7ee09SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d4a7ee09SAndrew Rist  * software distributed under the License is distributed on an
15*d4a7ee09SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d4a7ee09SAndrew Rist  * KIND, either express or implied.  See the License for the
17*d4a7ee09SAndrew Rist  * specific language governing permissions and limitations
18*d4a7ee09SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*d4a7ee09SAndrew Rist  *************************************************************/
21*d4a7ee09SAndrew Rist 
22*d4a7ee09SAndrew Rist 
23cdf0e10cSrcweir #ifndef OOVBAAPI_VBA_HELPERINTERFACE_HXX
24cdf0e10cSrcweir #define OOVBAAPI_VBA_HELPERINTERFACE_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
27cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
28cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx>
29cdf0e10cSrcweir #include <ooo/vba/XHelperInterface.hpp>
30cdf0e10cSrcweir #include <vbahelper/vbahelper.hxx>
31cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir // use this class when you have an a object like
34cdf0e10cSrcweir // interface  XAnInterface which contains XHelperInterface in its inheritance hierarchy
35cdf0e10cSrcweir // interface XAnInterface
36cdf0e10cSrcweir // {
37cdf0e10cSrcweir //     interface XHelperInterface;
38cdf0e10cSrcweir //     [attribute, string] name;
39cdf0e10cSrcweir // }
40cdf0e10cSrcweir // or
41cdf0e10cSrcweir // interface XAnInterface : XHelperInterface;
42cdf0e10cSrcweir // {
43cdf0e10cSrcweir //     [attribute, string] name;
44cdf0e10cSrcweir // }
45cdf0e10cSrcweir //
46cdf0e10cSrcweir // then this class can provide a default implementation of XHelperInterface,
47cdf0e10cSrcweir // you can use it like this
48cdf0e10cSrcweir // typedef InheritedHelperInterfaceImpl< XAnInterface > > AnInterfaceImpl_BASE;
49cdf0e10cSrcweir // class AnInterfaceImpl : public AnInterfaceImpl_BASE
50cdf0e10cSrcweir // {
51cdf0e10cSrcweir // public:
52cdf0e10cSrcweir //     AnInterface( const Reference< HelperInterface >& xParent ) : AnInterfaceImpl_BASE( xParent ) {}
53cdf0e10cSrcweir //     // implement XAnInterface methods only, no need to implement the XHelperInterface
54cdf0e10cSrcweir //     // methods
55cdf0e10cSrcweir //     virtual void setName( const OUString& );
56cdf0e10cSrcweir //     virtual OUString getName();
57cdf0e10cSrcweir // }
58cdf0e10cSrcweir //
59cdf0e10cSrcweir const ::rtl::OUString sHelperServiceName( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.HelperServiceBase" ) );
60cdf0e10cSrcweir 
61cdf0e10cSrcweir template< typename Ifc1 >
62cdf0e10cSrcweir class InheritedHelperInterfaceImpl : public Ifc1
63cdf0e10cSrcweir {
64cdf0e10cSrcweir protected:
65cdf0e10cSrcweir 	css::uno::WeakReference< ov::XHelperInterface > mxParent;
66cdf0e10cSrcweir 	css::uno::Reference< css::uno::XComponentContext > mxContext;
67cdf0e10cSrcweir public:
InheritedHelperInterfaceImpl()68cdf0e10cSrcweir 	InheritedHelperInterfaceImpl() {}
InheritedHelperInterfaceImpl(const css::uno::Reference<css::uno::XComponentContext> & xContext)69cdf0e10cSrcweir 	InheritedHelperInterfaceImpl( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : mxContext( xContext ) {}
InheritedHelperInterfaceImpl(const css::uno::Reference<ov::XHelperInterface> & xParent,const css::uno::Reference<css::uno::XComponentContext> & xContext)70cdf0e10cSrcweir 	InheritedHelperInterfaceImpl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : mxParent( xParent ), mxContext( xContext ) {}
71cdf0e10cSrcweir 	virtual rtl::OUString& getServiceImplName() = 0;
72cdf0e10cSrcweir 	virtual css::uno::Sequence<rtl::OUString> getServiceNames() = 0;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	// XHelperInterface Methods
getCreator()75cdf0e10cSrcweir 	virtual ::sal_Int32 SAL_CALL getCreator() throw (css::script::BasicErrorException, css::uno::RuntimeException)
76cdf0e10cSrcweir 	{
77cdf0e10cSrcweir 		return 0x53756E4F;
78cdf0e10cSrcweir 	}
getParent()79cdf0e10cSrcweir 	virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException) { return mxParent; }
80cdf0e10cSrcweir 
Application()81cdf0e10cSrcweir 	virtual css::uno::Any SAL_CALL Application(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException) {
82cdf0e10cSrcweir             // The application could certainly be passed around in the context - seems
83cdf0e10cSrcweir             // to make sense
84cdf0e10cSrcweir             css::uno::Reference< css::container::XNameAccess > xNameAccess( mxContext, css::uno::UNO_QUERY_THROW );
85cdf0e10cSrcweir             return xNameAccess->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Application" ) ) );
86cdf0e10cSrcweir 	}
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	// XServiceInfo Methods
getImplementationName()89cdf0e10cSrcweir 	virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (css::uno::RuntimeException) { return getServiceImplName(); }
supportsService(const::rtl::OUString & ServiceName)90cdf0e10cSrcweir 	virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (css::uno::RuntimeException)
91cdf0e10cSrcweir 	{
92cdf0e10cSrcweir 		css::uno::Sequence< rtl::OUString > sServices = getSupportedServiceNames();
93cdf0e10cSrcweir 		const rtl::OUString* pStart = sServices.getConstArray();
94cdf0e10cSrcweir 		const rtl::OUString* pEnd = pStart + sServices.getLength();
95cdf0e10cSrcweir 		for ( ; pStart != pEnd ; ++pStart )
96cdf0e10cSrcweir 			if ( (*pStart).equals( ServiceName ) )
97cdf0e10cSrcweir 				return sal_True;
98cdf0e10cSrcweir 		return sal_False;
99cdf0e10cSrcweir 	}
getSupportedServiceNames()100cdf0e10cSrcweir 	virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (css::uno::RuntimeException)
101cdf0e10cSrcweir 	{
102cdf0e10cSrcweir 		css::uno::Sequence< rtl::OUString > aNames = getServiceNames();
103cdf0e10cSrcweir 		return aNames;
104cdf0e10cSrcweir 	}
105cdf0e10cSrcweir  };
106cdf0e10cSrcweir 
107cdf0e10cSrcweir template< typename Ifc1 >
108cdf0e10cSrcweir class InheritedHelperInterfaceImpl1 : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper1< Ifc1 > >
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     typedef InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper1< Ifc1 > > Base;
111cdf0e10cSrcweir public:
InheritedHelperInterfaceImpl1()112cdf0e10cSrcweir 	InheritedHelperInterfaceImpl1< Ifc1 >() {}
InheritedHelperInterfaceImpl1(const css::uno::Reference<css::uno::XComponentContext> & xContext)113cdf0e10cSrcweir 	InheritedHelperInterfaceImpl1< Ifc1 >( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xContext ) {}
InheritedHelperInterfaceImpl1(const css::uno::Reference<ov::XHelperInterface> & xParent,const css::uno::Reference<css::uno::XComponentContext> & xContext)114cdf0e10cSrcweir 	InheritedHelperInterfaceImpl1< Ifc1 >( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xParent, xContext ) {}
115cdf0e10cSrcweir };
116cdf0e10cSrcweir 
117cdf0e10cSrcweir template< typename Ifc1, typename Ifc2 >
118cdf0e10cSrcweir class InheritedHelperInterfaceImpl2 : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper2< Ifc1, Ifc2 > >
119cdf0e10cSrcweir {
120cdf0e10cSrcweir     typedef InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper2< Ifc1, Ifc2 > > Base;
121cdf0e10cSrcweir public:
InheritedHelperInterfaceImpl2()122cdf0e10cSrcweir 	InheritedHelperInterfaceImpl2< Ifc1, Ifc2 >() {}
InheritedHelperInterfaceImpl2(const css::uno::Reference<css::uno::XComponentContext> & xContext)123cdf0e10cSrcweir 	InheritedHelperInterfaceImpl2< Ifc1, Ifc2 >( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xContext ) {}
InheritedHelperInterfaceImpl2(const css::uno::Reference<ov::XHelperInterface> & xParent,const css::uno::Reference<css::uno::XComponentContext> & xContext)124cdf0e10cSrcweir 	InheritedHelperInterfaceImpl2< Ifc1, Ifc2 >( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xParent, xContext ) {}
125cdf0e10cSrcweir };
126cdf0e10cSrcweir 
127cdf0e10cSrcweir template< typename Ifc1, typename Ifc2, typename Ifc3 >
128cdf0e10cSrcweir class InheritedHelperInterfaceImpl3 : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper3< Ifc1, Ifc2, Ifc3 > >
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     typedef InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper3< Ifc1, Ifc2, Ifc3 > > Base;
131cdf0e10cSrcweir public:
InheritedHelperInterfaceImpl3()132cdf0e10cSrcweir 	InheritedHelperInterfaceImpl3< Ifc1, Ifc2, Ifc3 >() {}
InheritedHelperInterfaceImpl3(const css::uno::Reference<css::uno::XComponentContext> & xContext)133cdf0e10cSrcweir 	InheritedHelperInterfaceImpl3< Ifc1, Ifc2, Ifc3 >( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xContext ) {}
InheritedHelperInterfaceImpl3(const css::uno::Reference<ov::XHelperInterface> & xParent,const css::uno::Reference<css::uno::XComponentContext> & xContext)134cdf0e10cSrcweir 	InheritedHelperInterfaceImpl3< Ifc1, Ifc2, Ifc3 >( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xParent, xContext ) {}
135cdf0e10cSrcweir };
136cdf0e10cSrcweir 
137cdf0e10cSrcweir // ============================================================================
138cdf0e10cSrcweir 
139cdf0e10cSrcweir /** Helper macro to implement the method 'getServiceImplName()' of the
140cdf0e10cSrcweir     'ooo.vba.XHelperInterface' interface. Will return the class name as service
141cdf0e10cSrcweir     implementation name.
142cdf0e10cSrcweir  */
143cdf0e10cSrcweir #define VBAHELPER_IMPL_GETSERVICEIMPLNAME( classname ) \
144cdf0e10cSrcweir ::rtl::OUString& classname::getServiceImplName() \
145cdf0e10cSrcweir { \
146cdf0e10cSrcweir     static ::rtl::OUString saImplName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( #classname ) ); \
147cdf0e10cSrcweir     return saImplName; \
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir // ----------------------------------------------------------------------------
151cdf0e10cSrcweir 
152cdf0e10cSrcweir /** Helper macro to implement the method 'getServiceNames()' for a single
153cdf0e10cSrcweir     service name.
154cdf0e10cSrcweir  */
155cdf0e10cSrcweir #define VBAHELPER_IMPL_GETSERVICENAMES( classname, servicename ) \
156cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > classname::getServiceNames() \
157cdf0e10cSrcweir { \
158cdf0e10cSrcweir     static css::uno::Sequence< ::rtl::OUString > saServiceNames; \
159cdf0e10cSrcweir     if( saServiceNames.getLength() == 0 ) \
160cdf0e10cSrcweir     { \
161cdf0e10cSrcweir         saServiceNames.realloc( 1 ); \
162cdf0e10cSrcweir         saServiceNames[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( servicename ) ); \
163cdf0e10cSrcweir     } \
164cdf0e10cSrcweir     return saServiceNames; \
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir // ----------------------------------------------------------------------------
168cdf0e10cSrcweir 
169cdf0e10cSrcweir /** Helper macro to declare the methods 'getServiceImplName()' and
170cdf0e10cSrcweir     'getServiceNames()' of the 'ooo.vba.XHelperInterface' interface in a class
171cdf0e10cSrcweir     declaration.
172cdf0e10cSrcweir  */
173cdf0e10cSrcweir #define VBAHELPER_DECL_XHELPERINTERFACE \
174cdf0e10cSrcweir     virtual ::rtl::OUString& getServiceImplName(); \
175cdf0e10cSrcweir     virtual css::uno::Sequence< ::rtl::OUString > getServiceNames();
176cdf0e10cSrcweir 
177cdf0e10cSrcweir // ----------------------------------------------------------------------------
178cdf0e10cSrcweir 
179cdf0e10cSrcweir /** Helper macro to implement the methods 'getServiceImplName()' and
180cdf0e10cSrcweir     'getServiceNames()' of the 'ooo.vba.XHelperInterface' interface. Will
181cdf0e10cSrcweir     return the class name as service implementation name.
182cdf0e10cSrcweir  */
183cdf0e10cSrcweir #define VBAHELPER_IMPL_XHELPERINTERFACE( classname, servicename ) \
184cdf0e10cSrcweir VBAHELPER_IMPL_GETSERVICEIMPLNAME( classname ) \
185cdf0e10cSrcweir VBAHELPER_IMPL_GETSERVICENAMES( classname, servicename )
186cdf0e10cSrcweir 
187cdf0e10cSrcweir // ============================================================================
188cdf0e10cSrcweir 
189cdf0e10cSrcweir #endif
190