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 <com/sun/star/uno/XAggregation.hpp>
24 #include <comphelper/sequence.hxx>
29 /** used for declaring UNO3-Defaults, i.e. acquire/release
31 #define DECLARE_UNO3_DEFAULTS(classname, baseclass) \
32 virtual void SAL_CALL acquire() noexcept override { baseclass::acquire(); } \
33 virtual void SAL_CALL release() noexcept override { baseclass::release(); }
35 /** used for declaring UNO3-Defaults, i.e. acquire/release if you want to forward all queryInterfaces to the base class,
36 (e.g. if you override queryAggregation)
38 #define DECLARE_UNO3_AGG_DEFAULTS(classname, baseclass) \
39 virtual void SAL_CALL acquire() noexcept override { baseclass::acquire(); } \
40 virtual void SAL_CALL release() noexcept override { baseclass::release(); } \
41 virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& _rType) override \
42 { return baseclass::queryInterface(_rType); }
44 /** Use this macro to forward XComponent methods to base class
46 When using the ::cppu::WeakComponentImplHelper base classes to
47 implement a UNO interface, a problem occurs when the interface
48 itself already derives from XComponent (like e.g. awt::XWindow
49 or awt::XControl): ::cppu::WeakComponentImplHelper is then
50 still abstract. Using this macro in the most derived class
51 definition provides overrides for the XComponent methods,
52 forwarding them to the given baseclass.
55 Name of the class this macro is issued within
58 Name of the baseclass that should have the XInterface methods
59 forwarded to - that's usually the WeakComponentImplHelperN base
62 Name of the baseclass that should have the XComponent methods
63 forwarded to - in the case of the WeakComponentImplHelper,
64 that would be ::cppu::WeakComponentImplHelperBase
66 #define DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS(classname, baseclass, implhelper) \
67 virtual void SAL_CALL acquire() noexcept override { baseclass::acquire(); } \
68 virtual void SAL_CALL release() noexcept override { baseclass::release(); } \
69 virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& _rType) override \
70 { return baseclass::queryInterface(_rType); } \
71 virtual void SAL_CALL dispose() override \
73 implhelper::dispose(); \
75 virtual void SAL_CALL addEventListener( \
76 css::uno::Reference< css::lang::XEventListener > const & xListener ) override \
78 implhelper::addEventListener(xListener); \
80 virtual void SAL_CALL removeEventListener( \
81 css::uno::Reference< css::lang::XEventListener > const & xListener ) override \
83 implhelper::removeEventListener(xListener); \
86 //= deriving from multiple XInterface-derived classes
88 //= forwarding/merging XInterface functionality
90 #define DECLARE_XINTERFACE( ) \
91 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; \
92 virtual void SAL_CALL acquire() noexcept override; \
93 virtual void SAL_CALL release() noexcept override;
95 #define IMPLEMENT_FORWARD_REFCOUNT( classname, refcountbase ) \
96 void SAL_CALL classname::acquire() noexcept { refcountbase::acquire(); } \
97 void SAL_CALL classname::release() noexcept { refcountbase::release(); }
99 #define IMPLEMENT_FORWARD_XINTERFACE2( classname, refcountbase, baseclass2 ) \
100 IMPLEMENT_FORWARD_REFCOUNT( classname, refcountbase ) \
101 css::uno::Any SAL_CALL classname::queryInterface( const css::uno::Type& _rType ) \
103 css::uno::Any aReturn = refcountbase::queryInterface( _rType ); \
104 if ( !aReturn.hasValue() ) \
105 aReturn = baseclass2::queryInterface( _rType ); \
109 #define IMPLEMENT_FORWARD_XINTERFACE3( classname, refcountbase, baseclass2, baseclass3 ) \
110 IMPLEMENT_FORWARD_REFCOUNT( classname, refcountbase ) \
111 css::uno::Any SAL_CALL classname::queryInterface( const css::uno::Type& _rType ) \
113 css::uno::Any aReturn = refcountbase::queryInterface( _rType ); \
114 if ( !aReturn.hasValue() ) \
116 aReturn = baseclass2::queryInterface( _rType ); \
117 if ( !aReturn.hasValue() ) \
118 aReturn = baseclass3::queryInterface( _rType ); \
124 //= forwarding/merging XTypeProvider functionality
126 #define DECLARE_XTYPEPROVIDER( ) \
127 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; \
128 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override;
130 #define IMPLEMENT_GET_IMPLEMENTATION_ID( classname ) \
131 css::uno::Sequence< sal_Int8 > SAL_CALL classname::getImplementationId( ) \
133 return css::uno::Sequence<sal_Int8>(); \
136 #define IMPLEMENT_FORWARD_XTYPEPROVIDER2( classname, baseclass1, baseclass2 ) \
137 css::uno::Sequence< css::uno::Type > SAL_CALL classname::getTypes( ) \
139 return ::comphelper::concatSequences( \
140 baseclass1::getTypes(), \
141 baseclass2::getTypes() \
145 IMPLEMENT_GET_IMPLEMENTATION_ID( classname )
147 /** ask for an iface of an aggregated object
149 Reference<XFoo> xFoo;<br/>
150 if (query_aggregation(xAggregatedObject, xFoo))<br/>
153 template <class iface
>
154 bool query_aggregation(const css::uno::Reference
< css::uno::XAggregation
>& _rxAggregate
, css::uno::Reference
<iface
>& _rxOut
)
157 if (_rxAggregate
.is())
159 _rxAggregate
->queryAggregation(cppu::UnoType
<iface
>::get())
165 /** ask for an iface of an aggregated object
167 if (auto xFoo = query_aggregation<XFoo>(xAggregatedObject))<br/>
170 template <class iface
>
171 css::uno::Reference
<iface
> query_aggregation(const css::uno::Reference
< css::uno::XAggregation
>& _rxAggregate
)
173 css::uno::Reference
<iface
> _rxOut
;
174 query_aggregation(_rxAggregate
, _rxOut
);
177 } // namespace comphelper
180 #endif // INCLUDED_COMPHELPER_UNO3_HXX
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */