Fix rudimentary Emscripten Qt6 copy -> paste support
[LibreOffice.git] / include / vbahelper / vbahelperinterface.hxx
blob6d4b78979a2c9cd21c8082471abe6eb54e13361d
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 <utility>
34 #include <vbahelper/vbahelper.hxx>
36 // use this class when you have an object like
37 // interface XAnInterface which contains XHelperInterface in its inheritance hierarchy
38 // interface XAnInterface
39 // {
40 // interface XHelperInterface;
41 // [attribute, string] name;
42 // }
43 // or
44 // interface XAnInterface : XHelperInterface;
45 // {
46 // [attribute, string] name;
47 // }
49 // then this class can provide a default implementation of XHelperInterface,
50 // you can use it like this
51 // typedef InheritedHelperInterfaceImpl< XAnInterface > > AnInterfaceImpl_BASE;
52 // class AnInterfaceImpl : public AnInterfaceImpl_BASE
53 // {
54 // public:
55 // AnInterface( const Reference< HelperInterface >& xParent ) : AnInterfaceImpl_BASE( xParent ) {}
56 // // implement XAnInterface methods only, no need to implement the XHelperInterface
57 // // methods
58 // virtual void setName( const OUString& );
59 // virtual OUString getName();
60 // }
63 template< typename... Ifc >
64 class SAL_DLLPUBLIC_TEMPLATE InheritedHelperInterfaceImpl : public Ifc...
66 protected:
67 css::uno::WeakReference< ov::XHelperInterface > mxParent;
68 css::uno::Reference< css::uno::XComponentContext > mxContext;
69 public:
70 InheritedHelperInterfaceImpl( const css::uno::Reference< ov::XHelperInterface >& xParent, css::uno::Reference< css::uno::XComponentContext > xContext ) : mxParent( xParent ), mxContext(std::move( xContext )) {}
71 virtual OUString getServiceImplName() = 0;
72 virtual css::uno::Sequence<OUString> getServiceNames() = 0;
74 // XHelperInterface Methods
75 virtual ::sal_Int32 SAL_CALL getCreator() override
77 return 0x53756E4F;
79 virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent( ) override { return mxParent; }
81 virtual css::uno::Any SAL_CALL Application( ) override {
82 // The application could certainly be passed around in the context - seems
83 // to make sense
84 css::uno::Reference< css::container::XNameAccess > xNameAccess( mxContext, css::uno::UNO_QUERY_THROW );
85 return xNameAccess->getByName( u"Application"_ustr );
88 // XServiceInfo Methods
89 virtual OUString SAL_CALL getImplementationName( ) override { return getServiceImplName(); }
90 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override
92 css::uno::Sequence< OUString > sServices = getSupportedServiceNames();
93 const OUString* pStart = sServices.getConstArray();
94 const OUString* pEnd = pStart + sServices.getLength();
95 for ( ; pStart != pEnd ; ++pStart )
96 if ( *pStart == ServiceName )
97 return true;
98 return false;
100 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override
102 css::uno::Sequence< OUString > aNames = getServiceNames();
103 return aNames;
107 template <typename... Ifc >
108 class SAL_DLLPUBLIC_TEMPLATE InheritedHelperInterfaceWeakImpl : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper< Ifc... > >
110 typedef InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper< Ifc... > > Base;
111 public:
112 InheritedHelperInterfaceWeakImpl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xParent, xContext ) {}
116 /** Helper macro to declare the methods 'getServiceImplName()' and
117 'getServiceNames()' of the 'ooo.vba.XHelperInterface' interface in a class
118 declaration.
120 #define VBAHELPER_DECL_XHELPERINTERFACE \
121 virtual OUString getServiceImplName() override; \
122 virtual css::uno::Sequence< OUString > getServiceNames() override;
125 /** Helper macro to implement the methods 'getServiceImplName()' and
126 'getServiceNames()' of the 'ooo.vba.XHelperInterface' interface. Will
127 return the class name as service implementation name.
129 #define VBAHELPER_IMPL_XHELPERINTERFACE( classname, servicename ) \
130 OUString classname::getServiceImplName() \
132 return u"" #classname ""_ustr; \
134 css::uno::Sequence< OUString > classname::getServiceNames() \
136 static const css::uno::Sequence< OUString > saServiceNames { servicename }; \
137 return saServiceNames; \
141 #endif
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */