Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / toolkit / helper / macros.hxx
blob0bb97433cbfe2cc458ebf90b911cfe161c56faa9
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 .
20 #ifndef INCLUDED_TOOLKIT_HELPER_MACROS_HXX
21 #define INCLUDED_TOOLKIT_HELPER_MACROS_HXX
23 #include <string.h>
25 #include <comphelper/servicehelper.hxx>
27 #define IMPL_XUNOTUNNEL_MINIMAL( ClassName ) \
28 sal_Int64 ClassName::getSomething( const css::uno::Sequence< sal_Int8 >& rIdentifier ) \
29 { \
30 if( ( rIdentifier.getLength() == 16 ) && ( 0 == memcmp( ClassName::GetUnoTunnelId().getConstArray(), rIdentifier.getConstArray(), 16 ) ) ) \
31 { \
32 return sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_IntPtr >(this)); \
33 } \
34 return 0; \
35 } \
36 namespace \
37 { \
38 class the##ClassName##UnoTunnelId : public rtl::Static< UnoTunnelIdInit, the##ClassName##UnoTunnelId> {}; \
39 } \
40 const css::uno::Sequence< sal_Int8 >& ClassName::GetUnoTunnelId() throw() \
41 { \
42 return the##ClassName##UnoTunnelId::get().getSeq(); \
45 #define IMPL_XUNOTUNNEL( ClassName ) \
46 IMPL_XUNOTUNNEL_MINIMAL( ClassName ) \
47 ClassName* ClassName::GetImplementation( const css::uno::Reference< css::uno::XInterface >& rxIFace ) \
48 { \
49 css::uno::Reference< css::lang::XUnoTunnel > xUT( rxIFace, css::uno::UNO_QUERY ); \
50 return xUT.is() ? reinterpret_cast<ClassName*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething( ClassName::GetUnoTunnelId() ))) : nullptr; \
53 #define IMPL_IMPLEMENTATION_ID( ClassName ) \
54 css::uno::Sequence< sal_Int8 > ClassName::getImplementationId() \
55 { \
56 return css::uno::Sequence<sal_Int8>(); \
59 #define IMPL_XTYPEPROVIDER_START( ClassName ) \
60 IMPL_IMPLEMENTATION_ID( ClassName ) \
61 css::uno::Sequence< css::uno::Type > ClassName::getTypes() \
62 { \
63 static ::cppu::OTypeCollection* pCollection = nullptr; \
64 if( !pCollection ) \
65 { \
66 ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ); \
67 if( !pCollection ) \
68 { \
69 static ::cppu::OTypeCollection collection( \
70 cppu::UnoType<css::lang::XTypeProvider>::get(),
73 #define IMPL_XTYPEPROVIDER_END \
74 ); \
75 pCollection = &collection; \
76 } \
77 } \
78 return (*pCollection).getTypes(); \
82 #define DECL_LISTENERMULTIPLEXER_START( ClassName, InterfaceName ) \
83 class ClassName : public ListenerMultiplexerBase, public InterfaceName \
84 { \
85 public: \
86 ClassName( ::cppu::OWeakObject& rSource ); \
87 css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; \
88 void SAL_CALL acquire() throw() override; \
89 void SAL_CALL release() throw() override; \
90 void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
93 #define DECL_LISTENERMULTIPLEXER_START_DLLPUB( ClassName, InterfaceName ) \
94 class TOOLKIT_DLLPUBLIC ClassName : public ListenerMultiplexerBase, public InterfaceName \
95 { \
96 public: \
97 ClassName( ::cppu::OWeakObject& rSource ); \
98 css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; \
99 void SAL_CALL acquire() throw() override; \
100 void SAL_CALL release() throw() override; \
101 void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
104 #define DECL_LISTENERMULTIPLEXER_END \
108 #define IMPL_LISTENERMULTIPLEXER_BASEMETHODS( ClassName, InterfaceName ) \
109 ClassName::ClassName( ::cppu::OWeakObject& rSource ) \
110 : ListenerMultiplexerBase( rSource ) \
113 void SAL_CALL ClassName::acquire() throw() { ListenerMultiplexerBase::acquire(); } \
114 void SAL_CALL ClassName::release() throw() { ListenerMultiplexerBase::release(); } \
115 css::uno::Any ClassName::queryInterface( const css::uno::Type & rType ) \
117 css::uno::Any aRet = ::cppu::queryInterface( rType, \
118 (static_cast< css::lang::XEventListener* >(this)), \
119 (static_cast< InterfaceName* >(this)) ); \
120 return (aRet.hasValue() ? aRet : ListenerMultiplexerBase::queryInterface( rType )); \
122 void ClassName::disposing( const css::lang::EventObject& ) \
127 #if OSL_DEBUG_LEVEL > 0
128 #define DISPLAY_EXCEPTION( ClassName, MethodName, e ) \
129 OString sMessage( #ClassName "::" #MethodName ": caught an exception!\n" ); \
130 sMessage += OString( e.Message.getStr(), e.Message.getLength(), RTL_TEXTENCODING_ASCII_US ); \
131 OSL_FAIL( sMessage.getStr() );
132 #else
133 #define DISPLAY_EXCEPTION( ClassName, MethodName, e ) (void)e;
134 #endif
136 #define IMPL_TABLISTENERMULTIPLEXER_LISTENERMETHOD_BODY_1PARAM( ClassName, InterfaceName, MethodName, ParamType1 ) \
138 ParamType1 aMulti( evt ); \
139 ::comphelper::OInterfaceIteratorHelper2 aIt( *this ); \
140 while( aIt.hasMoreElements() ) \
142 css::uno::Reference< InterfaceName > xListener( \
143 static_cast< InterfaceName* >( aIt.next() ) ); \
144 try \
146 xListener->MethodName( aMulti ); \
148 catch(const css::lang::DisposedException& e) \
150 OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" ); \
151 if ( e.Context == xListener || !e.Context.is() ) \
152 aIt.remove(); \
154 catch(const css::uno::RuntimeException& e) \
156 DISPLAY_EXCEPTION( ClassName, MethodName, e ) \
161 #define IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_BODY( ClassName, InterfaceName, MethodName, EventType ) \
163 EventType aMulti( evt ); \
164 aMulti.Source = &GetContext(); \
165 ::comphelper::OInterfaceIteratorHelper2 aIt( *this ); \
166 while( aIt.hasMoreElements() ) \
168 css::uno::Reference< InterfaceName > xListener( \
169 static_cast< InterfaceName* >( aIt.next() ) ); \
170 try \
172 xListener->MethodName( aMulti ); \
174 catch(const css::lang::DisposedException& e) \
176 OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" ); \
177 if ( e.Context == xListener || !e.Context.is() ) \
178 aIt.remove(); \
180 catch(const css::uno::RuntimeException& e) \
182 DISPLAY_EXCEPTION( ClassName, MethodName, e ) \
187 #define IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_EXCEPTION( ClassName, InterfaceName, MethodName, EventType, Exception ) \
188 void ClassName::MethodName( const EventType& evt ) \
189 IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_BODY( ClassName, InterfaceName, MethodName, EventType )
191 #define IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( ClassName, InterfaceName, MethodName, EventType ) \
192 void ClassName::MethodName( const EventType& evt ) \
193 IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_BODY( ClassName, InterfaceName, MethodName, EventType )
195 #define DECLIMPL_SERVICEINFO_DERIVED( ImplName, BaseClass, ServiceName ) \
196 OUString SAL_CALL getImplementationName( ) override { return OUString("stardiv.Toolkit." #ImplName ); } \
197 css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override \
199 css::uno::Sequence< OUString > aNames = BaseClass::getSupportedServiceNames( ); \
200 aNames.realloc( aNames.getLength() + 1 ); \
201 aNames[ aNames.getLength() - 1 ] = ServiceName; \
202 return aNames; \
205 #endif // INCLUDED_TOOLKIT_HELPER_MACROS_HXX
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */