1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 _TOOLKIT_HELPER_MACROS_HXX_
21 #define _TOOLKIT_HELPER_MACROS_HXX_
25 #include <comphelper/servicehelper.hxx>
27 #define IMPL_XUNOTUNNEL_MINIMAL( ClassName ) \
28 sal_Int64 ClassName::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rIdentifier ) throw(::com::sun::star::uno::RuntimeException) \
30 if( ( rIdentifier.getLength() == 16 ) && ( 0 == memcmp( ClassName::GetUnoTunnelId().getConstArray(), rIdentifier.getConstArray(), 16 ) ) ) \
32 return sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_IntPtr >(this)); \
38 class the##ClassName##UnoTunnelId : public rtl::Static< UnoTunnelIdInit, the##ClassName##UnoTunnelId> {}; \
40 const ::com::sun::star::uno::Sequence< sal_Int8 >& ClassName::GetUnoTunnelId() throw() \
42 return the##ClassName##UnoTunnelId::get().getSeq(); \
45 #define IMPL_XUNOTUNNEL( ClassName ) \
46 IMPL_XUNOTUNNEL_MINIMAL( ClassName ) \
47 ClassName* ClassName::GetImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxIFace ) \
49 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( rxIFace, ::com::sun::star::uno::UNO_QUERY ); \
50 return xUT.is() ? reinterpret_cast<ClassName*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething( ClassName::GetUnoTunnelId() ))) : NULL; \
53 #define IMPL_XUNOTUNNEL2( ClassName, BaseClass ) \
54 sal_Int64 ClassName::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rIdentifier ) throw(::com::sun::star::uno::RuntimeException) \
56 if( ( rIdentifier.getLength() == 16 ) && ( 0 == memcmp( ClassName::GetUnoTunnelId().getConstArray(), rIdentifier.getConstArray(), 16 ) ) ) \
58 return sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_IntPtr >(this)); \
60 return BaseClass::getSomething( rIdentifier ); \
64 class the##ClassName##UnoTunnelId : public rtl::Static< UnoTunnelIdInit, the##ClassName##UnoTunnelId> {}; \
66 const ::com::sun::star::uno::Sequence< sal_Int8 >& ClassName::GetUnoTunnelId() throw() \
68 return the##ClassName##UnoTunnelId::get().getSeq(); \
70 ClassName* ClassName::GetImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxIFace ) \
72 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( rxIFace, ::com::sun::star::uno::UNO_QUERY ); \
73 return xUT.is() ? reinterpret_cast<ClassName*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething( ClassName::GetUnoTunnelId() ))) : NULL; \
76 // -------------------------------------------------------------------------------------
78 #define IMPL_IMPLEMENTATION_ID( ClassName ) \
79 ::com::sun::star::uno::Sequence< sal_Int8 > ClassName::getImplementationId() throw(::com::sun::star::uno::RuntimeException) \
81 static ::cppu::OImplementationId* pId = NULL; \
84 ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ); \
87 static ::cppu::OImplementationId id( sal_False ); \
91 return (*pId).getImplementationId(); \
94 #define IMPL_XTYPEPROVIDER_START( ClassName ) \
95 IMPL_IMPLEMENTATION_ID( ClassName ) \
96 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > ClassName::getTypes() throw(::com::sun::star::uno::RuntimeException) \
98 static ::cppu::OTypeCollection* pCollection = NULL; \
101 ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ); \
104 static ::cppu::OTypeCollection collection( \
105 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XTypeProvider>* ) NULL ),
107 // -------------------------------------------------------------------------------------
109 #define IMPL_XTYPEPROVIDER_END \
111 pCollection = &collection; \
114 return (*pCollection).getTypes(); \
117 // -------------------------------------------------------------------------------------
119 #define DECL_LISTENERMULTIPLEXER_START( ClassName, InterfaceName ) \
120 class ClassName : public ListenerMultiplexerBase, public InterfaceName \
123 ClassName( ::cppu::OWeakObject& rSource ); \
124 ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); \
125 void SAL_CALL acquire() throw() { ListenerMultiplexerBase::acquire(); } \
126 void SAL_CALL release() throw() { ListenerMultiplexerBase::release(); } \
127 void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
129 // -------------------------------------------------------------------------------------
131 #define DECL_LISTENERMULTIPLEXER_START_DLLPUB( ClassName, InterfaceName ) \
132 class TOOLKIT_DLLPUBLIC ClassName : public ListenerMultiplexerBase, public InterfaceName \
135 ClassName( ::cppu::OWeakObject& rSource ); \
136 ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); \
137 void SAL_CALL acquire() throw() { ListenerMultiplexerBase::acquire(); } \
138 void SAL_CALL release() throw() { ListenerMultiplexerBase::release(); } \
139 void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
141 // -------------------------------------------------------------------------------------
143 #define DECL_LISTENERMULTIPLEXER_END \
146 // -------------------------------------------------------------------------------------
148 #define IMPL_LISTENERMULTIPLEXER_BASEMETHODS( ClassName, InterfaceName ) \
149 ClassName::ClassName( ::cppu::OWeakObject& rSource ) \
150 : ListenerMultiplexerBase( rSource ) \
153 ::com::sun::star::uno::Any ClassName::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) \
155 ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, \
156 (static_cast< ::com::sun::star::lang::XEventListener* >(this)), \
157 (static_cast< InterfaceName* >(this)) ); \
158 return (aRet.hasValue() ? aRet : ListenerMultiplexerBase::queryInterface( rType )); \
160 void ClassName::disposing( const ::com::sun::star::lang::EventObject& ) throw(::com::sun::star::uno::RuntimeException) \
164 // -------------------------------------------------------------------------------------
166 #if OSL_DEBUG_LEVEL > 0
167 #define DISPLAY_EXCEPTION( ClassName, MethodName, e ) \
168 OString sMessage( #ClassName "::" #MethodName ": caught an exception!\n" ); \
169 sMessage += OString( e.Message.getStr(), e.Message.getLength(), RTL_TEXTENCODING_ASCII_US ); \
170 OSL_FAIL( sMessage.getStr() );
172 #define DISPLAY_EXCEPTION( ClassName, MethodName, e ) (void)e;
175 #define IMPL_TABLISTENERMULTIPLEXER_LISTENERMETHOD_BODY_2PARAM( ClassName, InterfaceName, MethodName, ParamType1, ParamType2 ) \
177 ParamType1 aMulti( evt ); \
178 ParamType2 aMulti2( evt2 ); \
179 ::cppu::OInterfaceIteratorHelper aIt( *this ); \
180 while( aIt.hasMoreElements() ) \
182 ::com::sun::star::uno::Reference< InterfaceName > xListener( \
183 static_cast< InterfaceName* >( aIt.next() ) ); \
186 xListener->MethodName( aMulti, aMulti2 ); \
188 catch(const ::com::sun::star::lang::DisposedException& e) \
190 OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" ); \
191 if ( e.Context == xListener || !e.Context.is() ) \
194 catch(const ::com::sun::star::uno::RuntimeException& e) \
196 DISPLAY_EXCEPTION( ClassName, MethodName, e ) \
201 #define IMPL_TABLISTENERMULTIPLEXER_LISTENERMETHOD_BODY_1PARAM( ClassName, InterfaceName, MethodName, ParamType1 ) \
203 ParamType1 aMulti( evt ); \
204 ::cppu::OInterfaceIteratorHelper aIt( *this ); \
205 while( aIt.hasMoreElements() ) \
207 ::com::sun::star::uno::Reference< InterfaceName > xListener( \
208 static_cast< InterfaceName* >( aIt.next() ) ); \
211 xListener->MethodName( aMulti ); \
213 catch(const ::com::sun::star::lang::DisposedException& e) \
215 OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" ); \
216 if ( e.Context == xListener || !e.Context.is() ) \
219 catch(const ::com::sun::star::uno::RuntimeException& e) \
221 DISPLAY_EXCEPTION( ClassName, MethodName, e ) \
226 #define IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_BODY( ClassName, InterfaceName, MethodName, EventType ) \
228 EventType aMulti( evt ); \
229 aMulti.Source = &GetContext(); \
230 ::cppu::OInterfaceIteratorHelper aIt( *this ); \
231 while( aIt.hasMoreElements() ) \
233 ::com::sun::star::uno::Reference< InterfaceName > xListener( \
234 static_cast< InterfaceName* >( aIt.next() ) ); \
237 xListener->MethodName( aMulti ); \
239 catch(const ::com::sun::star::lang::DisposedException& e) \
241 OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" ); \
242 if ( e.Context == xListener || !e.Context.is() ) \
245 catch(const ::com::sun::star::uno::RuntimeException& e) \
247 DISPLAY_EXCEPTION( ClassName, MethodName, e ) \
252 #define IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_EXCEPTION( ClassName, InterfaceName, MethodName, EventType, Exception ) \
253 void ClassName::MethodName( const EventType& evt ) throw(::com::sun::star::uno::RuntimeException, Exception) \
254 IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_BODY( ClassName, InterfaceName, MethodName, EventType )
256 #define IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( ClassName, InterfaceName, MethodName, EventType ) \
257 void ClassName::MethodName( const EventType& evt ) throw(::com::sun::star::uno::RuntimeException) \
258 IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_BODY( ClassName, InterfaceName, MethodName, EventType )
260 // -------------------------------------------------------------------------------------
262 #define DECLIMPL_SUPPORTS_SERVICE( ) \
263 sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) throw(::com::sun::star::uno::RuntimeException) \
265 ::com::sun::star::uno::Sequence< OUString > aServiceNames( getSupportedServiceNames() ); \
266 const OUString* pSupported = aServiceNames.getConstArray(); \
267 const OUString* pSupportedEnd = pSupported + aServiceNames.getLength(); \
268 for ( ; pSupported != pSupportedEnd; ++pSupported ) \
269 if ( *pSupported == rServiceName ) \
274 // -------------------------------------------------------------------------------------
276 #define DECLIMPL_SERVICEINFO_DERIVED( ImplName, BaseClass, ServiceName ) \
277 OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException) { return OUString("stardiv.Toolkit." #ImplName ); } \
278 ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException) \
280 ::com::sun::star::uno::Sequence< OUString > aNames = BaseClass::getSupportedServiceNames( ); \
281 aNames.realloc( aNames.getLength() + 1 ); \
282 aNames[ aNames.getLength() - 1 ] = OUString::createFromAscii( ServiceName ); \
286 // -------------------------------------------------------------------------------------
288 #define DECLIMPL_SERVICEINFO( ImplName, ServiceName ) \
289 OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException) { return OUString("stardiv.Toolkit." #ImplName ); } \
290 ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException) \
292 ::com::sun::star::uno::Sequence< OUString > aNames( 1 ); \
293 aNames[ 0 ] = OUString::createFromAscii( ServiceName ); \
296 DECLIMPL_SUPPORTS_SERVICE( )
303 #endif // _TOOLKIT_HELPER_MACROS_HXX_
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */