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_COMPHELPER_UNO3_HXX
21 #define INCLUDED_COMPHELPER_UNO3_HXX
23 #include <rtl/instance.hxx>
24 #include <comphelper/types.hxx>
25 #include <com/sun/star/uno/XAggregation.hpp>
26 #include <comphelper/sequence.hxx>
27 #include <cppuhelper/typeprovider.hxx>
32 /** used for declaring UNO3-Defaults, i.e. acquire/release
34 #define DECLARE_UNO3_DEFAULTS(classname, baseclass) \
35 virtual void SAL_CALL acquire() throw() override { baseclass::acquire(); } \
36 virtual void SAL_CALL release() throw() override { baseclass::release(); }
38 /** used for declaring UNO3-Defaults, i.e. acquire/release if you want to forward all queryInterfaces to the base class,
39 (e.g. if you override queryAggregation)
41 #define DECLARE_UNO3_AGG_DEFAULTS(classname, baseclass) \
42 virtual void SAL_CALL acquire() throw() override { baseclass::acquire(); } \
43 virtual void SAL_CALL release() throw() override { baseclass::release(); } \
44 virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& _rType) override \
45 { return baseclass::queryInterface(_rType); }
47 /** Use this macro to forward XComponent methods to base class
49 When using the ::cppu::WeakComponentImplHelper base classes to
50 implement a UNO interface, a problem occurs when the interface
51 itself already derives from XComponent (like e.g. awt::XWindow
52 or awt::XControl): ::cppu::WeakComponentImplHelper is then
53 still abstract. Using this macro in the most derived class
54 definition provides overrides for the XComponent methods,
55 forwarding them to the given baseclass.
58 Name of the class this macro is issued within
61 Name of the baseclass that should have the XInterface methods
62 forwarded to - that's usually the WeakComponentImplHelperN base
65 Name of the baseclass that should have the XComponent methods
66 forwarded to - in the case of the WeakComponentImplHelper,
67 that would be ::cppu::WeakComponentImplHelperBase
69 #define DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS(classname, baseclass, implhelper) \
70 virtual void SAL_CALL acquire() throw() override { baseclass::acquire(); } \
71 virtual void SAL_CALL release() throw() override { baseclass::release(); } \
72 virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& _rType) override \
73 { return baseclass::queryInterface(_rType); } \
74 virtual void SAL_CALL dispose() override \
76 implhelper::dispose(); \
78 virtual void SAL_CALL addEventListener( \
79 css::uno::Reference< css::lang::XEventListener > const & xListener ) override \
81 implhelper::addEventListener(xListener); \
83 virtual void SAL_CALL removeEventListener( \
84 css::uno::Reference< css::lang::XEventListener > const & xListener ) override \
86 implhelper::removeEventListener(xListener); \
89 //= deriving from multiple XInterface-derived classes
91 //= forwarding/merging XInterface funtionality
93 #define DECLARE_XINTERFACE( ) \
94 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; \
95 virtual void SAL_CALL acquire() throw() override; \
96 virtual void SAL_CALL release() throw() override;
98 #define IMPLEMENT_FORWARD_REFCOUNT( classname, refcountbase ) \
99 void SAL_CALL classname::acquire() throw() { refcountbase::acquire(); } \
100 void SAL_CALL classname::release() throw() { refcountbase::release(); }
102 #define IMPLEMENT_FORWARD_XINTERFACE2( classname, refcountbase, baseclass2 ) \
103 IMPLEMENT_FORWARD_REFCOUNT( classname, refcountbase ) \
104 css::uno::Any SAL_CALL classname::queryInterface( const css::uno::Type& _rType ) \
106 css::uno::Any aReturn = refcountbase::queryInterface( _rType ); \
107 if ( !aReturn.hasValue() ) \
108 aReturn = baseclass2::queryInterface( _rType ); \
112 #define IMPLEMENT_FORWARD_XINTERFACE3( classname, refcountbase, baseclass2, baseclass3 ) \
113 IMPLEMENT_FORWARD_REFCOUNT( classname, refcountbase ) \
114 css::uno::Any SAL_CALL classname::queryInterface( const css::uno::Type& _rType ) \
116 css::uno::Any aReturn = refcountbase::queryInterface( _rType ); \
117 if ( !aReturn.hasValue() ) \
119 aReturn = baseclass2::queryInterface( _rType ); \
120 if ( !aReturn.hasValue() ) \
121 aReturn = baseclass3::queryInterface( _rType ); \
127 //= forwarding/merging XTypeProvider funtionality
129 #define DECLARE_XTYPEPROVIDER( ) \
130 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; \
131 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override;
133 #define IMPLEMENT_GET_IMPLEMENTATION_ID( classname ) \
134 css::uno::Sequence< sal_Int8 > SAL_CALL classname::getImplementationId( ) \
136 return css::uno::Sequence<sal_Int8>(); \
139 #define IMPLEMENT_FORWARD_XTYPEPROVIDER2( classname, baseclass1, baseclass2 ) \
140 css::uno::Sequence< css::uno::Type > SAL_CALL classname::getTypes( ) \
142 return ::comphelper::concatSequences( \
143 baseclass1::getTypes(), \
144 baseclass2::getTypes() \
148 IMPLEMENT_GET_IMPLEMENTATION_ID( classname )
150 #define IMPLEMENT_FORWARD_XTYPEPROVIDER3( classname, baseclass1, baseclass2, baseclass3 ) \
151 css::uno::Sequence< css::uno::Type > SAL_CALL classname::getTypes( ) \
153 return ::comphelper::concatSequences( \
154 baseclass1::getTypes(), \
155 baseclass2::getTypes(), \
156 baseclass3::getTypes() \
160 IMPLEMENT_GET_IMPLEMENTATION_ID( classname )
163 /** ask for an iface of an aggregated object
165 Reference<XFoo> xFoo;<br/>
166 if (query_aggregation(xAggregatedObject, xFoo))<br/>
169 template <class iface
>
170 bool query_aggregation(const css::uno::Reference
< css::uno::XAggregation
>& _rxAggregate
, css::uno::Reference
<iface
>& _rxOut
)
173 if (_rxAggregate
.is())
175 _rxAggregate
->queryAggregation(cppu::UnoType
<iface
>::get())
180 } // namespace comphelper
183 #endif // INCLUDED_COMPHELPER_UNO3_HXX
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */