nss: upgrade to release 3.73
[LibreOffice.git] / include / vbahelper / vbahelperinterface.hxx
blob0bbf18992ec354dc3cc5c8eed206f87cda7ea74c
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 <com/sun/star/container/XNameAccess.hpp>
23 #include <com/sun/star/uno/Any.hxx>
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <com/sun/star/uno/RuntimeException.hpp>
26 #include <com/sun/star/uno/Sequence.hxx>
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <cppuhelper/implbase.hxx>
29 #include <cppuhelper/weakref.hxx>
30 #include <ooo/vba/XHelperInterface.hpp>
31 #include <rtl/ustring.hxx>
32 #include <sal/types.h>
33 #include <vbahelper/vbahelper.hxx>
35 // use this class when you have an object like
36 // interface XAnInterface which contains XHelperInterface in its inheritance hierarchy
37 // interface XAnInterface
38 // {
39 // interface XHelperInterface;
40 // [attribute, string] name;
41 // }
42 // or
43 // interface XAnInterface : XHelperInterface;
44 // {
45 // [attribute, string] name;
46 // }
48 // then this class can provide a default implementation of XHelperInterface,
49 // you can use it like this
50 // typedef InheritedHelperInterfaceImpl< XAnInterface > > AnInterfaceImpl_BASE;
51 // class AnInterfaceImpl : public AnInterfaceImpl_BASE
52 // {
53 // public:
54 // AnInterface( const Reference< HelperInterface >& xParent ) : AnInterfaceImpl_BASE( xParent ) {}
55 // // implement XAnInterface methods only, no need to implement the XHelperInterface
56 // // methods
57 // virtual void setName( const OUString& );
58 // virtual OUString getName();
59 // }
62 template< typename... Ifc >
63 class SAL_DLLPUBLIC_TEMPLATE InheritedHelperInterfaceImpl : public Ifc...
65 protected:
66 css::uno::WeakReference< ov::XHelperInterface > mxParent;
67 css::uno::Reference< css::uno::XComponentContext > mxContext;
68 public:
69 InheritedHelperInterfaceImpl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : mxParent( xParent ), mxContext( xContext ) {}
70 virtual OUString getServiceImplName() = 0;
71 virtual css::uno::Sequence<OUString> getServiceNames() = 0;
73 // XHelperInterface Methods
74 virtual ::sal_Int32 SAL_CALL getCreator() override
76 return 0x53756E4F;
78 virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent( ) override { return mxParent; }
80 virtual css::uno::Any SAL_CALL Application( ) override {
81 // The application could certainly be passed around in the context - seems
82 // to make sense
83 css::uno::Reference< css::container::XNameAccess > xNameAccess( mxContext, css::uno::UNO_QUERY_THROW );
84 return xNameAccess->getByName( "Application" );
87 // XServiceInfo Methods
88 virtual OUString SAL_CALL getImplementationName( ) override { return getServiceImplName(); }
89 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override
91 css::uno::Sequence< OUString > sServices = getSupportedServiceNames();
92 const OUString* pStart = sServices.getConstArray();
93 const OUString* pEnd = pStart + sServices.getLength();
94 for ( ; pStart != pEnd ; ++pStart )
95 if ( *pStart == ServiceName )
96 return true;
97 return false;
99 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override
101 css::uno::Sequence< OUString > aNames = getServiceNames();
102 return aNames;
106 template <typename... Ifc >
107 class SAL_DLLPUBLIC_TEMPLATE InheritedHelperInterfaceWeakImpl : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper< Ifc... > >
109 typedef InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper< Ifc... > > Base;
110 public:
111 InheritedHelperInterfaceWeakImpl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xParent, xContext ) {}
115 /** Helper macro to declare the methods 'getServiceImplName()' and
116 'getServiceNames()' of the 'ooo.vba.XHelperInterface' interface in a class
117 declaration.
119 #define VBAHELPER_DECL_XHELPERINTERFACE \
120 virtual OUString getServiceImplName() override; \
121 virtual css::uno::Sequence< OUString > getServiceNames() override;
124 /** Helper macro to implement the methods 'getServiceImplName()' and
125 'getServiceNames()' of the 'ooo.vba.XHelperInterface' interface. Will
126 return the class name as service implementation name.
128 #define VBAHELPER_IMPL_XHELPERINTERFACE( classname, servicename ) \
129 OUString classname::getServiceImplName() \
131 return #classname; \
133 css::uno::Sequence< OUString > classname::getServiceNames() \
135 static css::uno::Sequence< OUString > saServiceNames; \
136 if( saServiceNames.getLength() == 0 ) \
138 saServiceNames.realloc( 1 ); \
139 saServiceNames[ 0 ] = servicename; \
141 return saServiceNames; \
145 #endif
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */