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 INCLUDED_TOOLKIT_HELPER_MACROS_HXX
21 #define INCLUDED_TOOLKIT_HELPER_MACROS_HXX
23 #include <sal/log.hxx>
24 #include <osl/diagnose.h>
25 #include <tools/diagnose_ex.h>
27 #define IMPL_IMPLEMENTATION_ID( ClassName ) \
28 css::uno::Sequence< sal_Int8 > ClassName::getImplementationId() \
30 return css::uno::Sequence<sal_Int8>(); \
34 #define DECL_LISTENERMULTIPLEXER_START( ClassName, InterfaceName ) \
35 class ClassName final : public ListenerMultiplexerBase, public InterfaceName \
38 ClassName( ::cppu::OWeakObject& rSource ); \
39 css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; \
40 void SAL_CALL acquire() throw() override; \
41 void SAL_CALL release() throw() override; \
42 void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
45 #define DECL_LISTENERMULTIPLEXER_START_DLLPUB( ClassName, InterfaceName ) \
46 class TOOLKIT_DLLPUBLIC ClassName final : public ListenerMultiplexerBase, public InterfaceName \
49 ClassName( ::cppu::OWeakObject& rSource ); \
50 css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; \
51 void SAL_CALL acquire() throw() override; \
52 void SAL_CALL release() throw() override; \
53 void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
56 #define DECL_LISTENERMULTIPLEXER_END \
60 #define IMPL_LISTENERMULTIPLEXER_BASEMETHODS( ClassName, InterfaceName ) \
61 ClassName::ClassName( ::cppu::OWeakObject& rSource ) \
62 : ListenerMultiplexerBase( rSource ) \
65 void SAL_CALL ClassName::acquire() throw() { ListenerMultiplexerBase::acquire(); } \
66 void SAL_CALL ClassName::release() throw() { ListenerMultiplexerBase::release(); } \
67 css::uno::Any ClassName::queryInterface( const css::uno::Type & rType ) \
69 css::uno::Any aRet = ::cppu::queryInterface( rType, \
70 (static_cast< css::lang::XEventListener* >(this)), \
71 (static_cast< InterfaceName* >(this)) ); \
72 return (aRet.hasValue() ? aRet : ListenerMultiplexerBase::queryInterface( rType )); \
74 void ClassName::disposing( const css::lang::EventObject& ) \
79 #if OSL_DEBUG_LEVEL > 0
80 #define DISPLAY_EXCEPTION( ClassName, MethodName ) \
81 css::uno::Any ex( cppu::getCaughtException() ); \
82 SAL_WARN( "toolkit", #ClassName "::" #MethodName ": caught an exception! " << exceptionToString(ex));
84 #define DISPLAY_EXCEPTION( ClassName, MethodName )
87 #define IMPL_TABLISTENERMULTIPLEXER_LISTENERMETHOD_BODY_1PARAM( ClassName, InterfaceName, MethodName, ParamType1 ) \
89 ParamType1 aMulti( evt ); \
90 ::comphelper::OInterfaceIteratorHelper2 aIt( *this ); \
91 while( aIt.hasMoreElements() ) \
93 css::uno::Reference< InterfaceName > xListener( \
94 static_cast< InterfaceName* >( aIt.next() ) ); \
97 xListener->MethodName( aMulti ); \
99 catch(const css::lang::DisposedException& e) \
101 OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" ); \
102 if ( e.Context == xListener || !e.Context.is() ) \
105 catch(const css::uno::RuntimeException&) \
107 DISPLAY_EXCEPTION( ClassName, MethodName ) \
112 #define IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_BODY( ClassName, InterfaceName, MethodName, EventType ) \
114 EventType aMulti( evt ); \
115 aMulti.Source = &GetContext(); \
116 ::comphelper::OInterfaceIteratorHelper2 aIt( *this ); \
117 while( aIt.hasMoreElements() ) \
119 css::uno::Reference< InterfaceName > xListener( \
120 static_cast< InterfaceName* >( aIt.next() ) ); \
123 xListener->MethodName( aMulti ); \
125 catch(const css::lang::DisposedException& e) \
127 OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" ); \
128 if ( e.Context == xListener || !e.Context.is() ) \
131 catch(const css::uno::RuntimeException&) \
133 DISPLAY_EXCEPTION( ClassName, MethodName ) \
138 #define IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_EXCEPTION( ClassName, InterfaceName, MethodName, EventType, Exception ) \
139 void ClassName::MethodName( const EventType& evt ) \
140 IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_BODY( ClassName, InterfaceName, MethodName, EventType )
142 #define IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( ClassName, InterfaceName, MethodName, EventType ) \
143 void ClassName::MethodName( const EventType& evt ) \
144 IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_BODY( ClassName, InterfaceName, MethodName, EventType )
146 #define DECLIMPL_SERVICEINFO_DERIVED( ImplName, BaseClass, ServiceName ) \
147 OUString SAL_CALL getImplementationName( ) override { return "stardiv.Toolkit." #ImplName; } \
148 css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override \
150 css::uno::Sequence< OUString > aNames = BaseClass::getSupportedServiceNames( ); \
151 aNames.realloc( aNames.getLength() + 1 ); \
152 aNames[ aNames.getLength() - 1 ] = ServiceName; \
156 #endif // INCLUDED_TOOLKIT_HELPER_MACROS_HXX
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */