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