Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / include / toolkit / helper / macros.hxx
blob1bfd46b1bd7e1a2b6e0c8f597c7213ec68035ea8
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 <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() \
29 { \
30 return css::uno::Sequence<sal_Int8>(); \
34 #define DECL_LISTENERMULTIPLEXER_START( ClassName, InterfaceName ) \
35 class ClassName final : public ListenerMultiplexerBase, public InterfaceName \
36 { \
37 public: \
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 \
47 { \
48 public: \
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 ) \
63 { \
64 } \
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 ) \
68 { \
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 )); \
73 } \
74 void ClassName::disposing( const css::lang::EventObject& ) \
75 { \
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));
83 #else
84 #define DISPLAY_EXCEPTION( ClassName, MethodName )
85 #endif
87 #define IMPL_TABLISTENERMULTIPLEXER_LISTENERMETHOD_BODY_1PARAM( ClassName, InterfaceName, MethodName, ParamType1 ) \
88 { \
89 ParamType1 aMulti( evt ); \
90 ::comphelper::OInterfaceIteratorHelper2 aIt( *this ); \
91 while( aIt.hasMoreElements() ) \
92 { \
93 css::uno::Reference< InterfaceName > xListener( \
94 static_cast< InterfaceName* >( aIt.next() ) ); \
95 try \
96 { \
97 xListener->MethodName( aMulti ); \
98 } \
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() ) \
103 aIt.remove(); \
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() ) ); \
121 try \
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() ) \
129 aIt.remove(); \
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; \
153 return aNames; \
156 #endif // INCLUDED_TOOLKIT_HELPER_MACROS_HXX
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */