update emoji autocorrect entries from po-files
[LibreOffice.git] / include / vbahelper / vbahelperinterface.hxx
blob2c9710090d3425219de5140e3c6a0320cd7125c7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_VBAHELPER_VBAHELPERINTERFACE_HXX
20 #define INCLUDED_VBAHELPER_VBAHELPERINTERFACE_HXX
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>
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 // }
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 // }
56 template< typename Ifc1 >
57 class SAL_DLLPUBLIC_TEMPLATE InheritedHelperInterfaceImpl : public Ifc1
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 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;
69 // XHelperInterface Methods
70 virtual ::sal_Int32 SAL_CALL getCreator() throw (css::script::BasicErrorException, css::uno::RuntimeException) SAL_OVERRIDE
72 return 0x53756E4F;
74 virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) SAL_OVERRIDE { return mxParent; }
76 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 css::uno::Reference< css::container::XNameAccess > xNameAccess( mxContext, css::uno::UNO_QUERY_THROW );
80 return xNameAccess->getByName( "Application" );
83 // XServiceInfo Methods
84 virtual OUString SAL_CALL getImplementationName( ) throw (css::uno::RuntimeException) SAL_OVERRIDE { return getServiceImplName(); }
85 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (css::uno::RuntimeException) SAL_OVERRIDE
87 css::uno::Sequence< OUString > sServices = getSupportedServiceNames();
88 const OUString* pStart = sServices.getConstArray();
89 const OUString* pEnd = pStart + sServices.getLength();
90 for ( ; pStart != pEnd ; ++pStart )
91 if ( (*pStart).equals( ServiceName ) )
92 return sal_True;
93 return sal_False;
95 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (css::uno::RuntimeException) SAL_OVERRIDE
97 css::uno::Sequence< OUString > aNames = getServiceNames();
98 return aNames;
102 template< typename Ifc1 >
103 class SAL_DLLPUBLIC_TEMPLATE InheritedHelperInterfaceImpl1 : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper1< Ifc1 > >
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 InheritedHelperInterfaceImpl1< Ifc1 >( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xParent, xContext ) {}
112 template< typename Ifc1, typename Ifc2 >
113 class SAL_DLLPUBLIC_TEMPLATE InheritedHelperInterfaceImpl2 : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper2< Ifc1, Ifc2 > >
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 ) {}
122 template< typename Ifc1, typename Ifc2, typename Ifc3 >
123 class SAL_DLLPUBLIC_TEMPLATE InheritedHelperInterfaceImpl3 : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper3< Ifc1, Ifc2, Ifc3 > >
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 ) {}
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.
138 #define VBAHELPER_IMPL_GETSERVICEIMPLNAME( classname ) \
139 OUString classname::getServiceImplName() \
141 return OUString( #classname ); \
146 /** Helper macro to implement the method 'getServiceNames()' for a single
147 service name.
149 #define VBAHELPER_IMPL_GETSERVICENAMES( classname, servicename ) \
150 css::uno::Sequence< OUString > classname::getServiceNames() \
152 static css::uno::Sequence< OUString > saServiceNames; \
153 if( saServiceNames.getLength() == 0 ) \
155 saServiceNames.realloc( 1 ); \
156 saServiceNames[ 0 ] = servicename; \
158 return saServiceNames; \
163 /** Helper macro to declare the methods 'getServiceImplName()' and
164 'getServiceNames()' of the 'ooo.vba.XHelperInterface' interface in a class
165 declaration.
167 #define VBAHELPER_DECL_XHELPERINTERFACE \
168 virtual OUString getServiceImplName() SAL_OVERRIDE; \
169 virtual css::uno::Sequence< OUString > getServiceNames() SAL_OVERRIDE;
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.
177 #define VBAHELPER_IMPL_XHELPERINTERFACE( classname, servicename ) \
178 VBAHELPER_IMPL_GETSERVICEIMPLNAME( classname ) \
179 VBAHELPER_IMPL_GETSERVICENAMES( classname, servicename )
183 #endif
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */