Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_COMPHELPER_UNO3_HXX
21 : #define INCLUDED_COMPHELPER_UNO3_HXX
22 :
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>
28 :
29 :
30 : namespace comphelper
31 : {
32 : /** used for declaring UNO3-Defaults, i.e. acquire/release
33 : */
34 : #define DECLARE_UNO3_DEFAULTS(classname, baseclass) \
35 : virtual void SAL_CALL acquire() throw() SAL_OVERRIDE { baseclass::acquire(); } \
36 : virtual void SAL_CALL release() throw() SAL_OVERRIDE { baseclass::release(); }
37 :
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)
40 : */
41 : #define DECLARE_UNO3_AGG_DEFAULTS(classname, baseclass) \
42 : virtual void SAL_CALL acquire() throw() SAL_OVERRIDE { baseclass::acquire(); } \
43 : virtual void SAL_CALL release() throw() SAL_OVERRIDE { baseclass::release(); } \
44 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE \
45 : { return baseclass::queryInterface(_rType); }
46 :
47 : /** Use this macro to forward XComponent methods to base class
48 :
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.
56 :
57 : @param classname
58 : Name of the class this macro is issued within
59 :
60 : @param baseclass
61 : Name of the baseclass that should have the XInterface methods
62 : forwarded to - that's usually the WeakComponentImplHelperN base
63 :
64 : @param implhelper
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
68 : */
69 : #define DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS(classname, baseclass, implhelper) \
70 : virtual void SAL_CALL acquire() throw() SAL_OVERRIDE { baseclass::acquire(); } \
71 : virtual void SAL_CALL release() throw() SAL_OVERRIDE { baseclass::release(); } \
72 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE \
73 : { return baseclass::queryInterface(_rType); } \
74 : virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE \
75 : { \
76 : implhelper::dispose(); \
77 : } \
78 : virtual void SAL_CALL addEventListener( \
79 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > const & xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE \
80 : { \
81 : implhelper::addEventListener(xListener); \
82 : } \
83 : virtual void SAL_CALL removeEventListener( \
84 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > const & xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE \
85 : { \
86 : implhelper::removeEventListener(xListener); \
87 : }
88 :
89 : //= deriving from multiple XInterface-derived classes
90 :
91 : //= forwarding/merging XInterface funtionality
92 :
93 : #define DECLARE_XINTERFACE( ) \
94 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; \
95 : virtual void SAL_CALL acquire() throw() SAL_OVERRIDE; \
96 : virtual void SAL_CALL release() throw() SAL_OVERRIDE;
97 :
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(); }
101 :
102 : #define IMPLEMENT_FORWARD_XINTERFACE2( classname, refcountbase, baseclass2 ) \
103 : IMPLEMENT_FORWARD_REFCOUNT( classname, refcountbase ) \
104 : ::com::sun::star::uno::Any SAL_CALL classname::queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException, std::exception) \
105 : { \
106 : ::com::sun::star::uno::Any aReturn = refcountbase::queryInterface( _rType ); \
107 : if ( !aReturn.hasValue() ) \
108 : aReturn = baseclass2::queryInterface( _rType ); \
109 : return aReturn; \
110 : }
111 :
112 : #define IMPLEMENT_FORWARD_XINTERFACE3( classname, refcountbase, baseclass2, baseclass3 ) \
113 : IMPLEMENT_FORWARD_REFCOUNT( classname, refcountbase ) \
114 : ::com::sun::star::uno::Any SAL_CALL classname::queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException, std::exception) \
115 : { \
116 : ::com::sun::star::uno::Any aReturn = refcountbase::queryInterface( _rType ); \
117 : if ( !aReturn.hasValue() ) \
118 : { \
119 : aReturn = baseclass2::queryInterface( _rType ); \
120 : if ( !aReturn.hasValue() ) \
121 : aReturn = baseclass3::queryInterface( _rType ); \
122 : } \
123 : return aReturn; \
124 : }
125 :
126 :
127 : //= forwarding/merging XTypeProvider funtionality
128 :
129 : #define DECLARE_XTYPEPROVIDER( ) \
130 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; \
131 : virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
132 :
133 : #define IMPLEMENT_GET_IMPLEMENTATION_ID( classname ) \
134 : ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL classname::getImplementationId( ) throw (::com::sun::star::uno::RuntimeException, std::exception) \
135 : { \
136 : return css::uno::Sequence<sal_Int8>(); \
137 : }
138 :
139 : #define IMPLEMENT_FORWARD_XTYPEPROVIDER2( classname, baseclass1, baseclass2 ) \
140 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL classname::getTypes( ) throw (::com::sun::star::uno::RuntimeException, std::exception) \
141 : { \
142 : return ::comphelper::concatSequences( \
143 : baseclass1::getTypes(), \
144 : baseclass2::getTypes() \
145 : ); \
146 : } \
147 : \
148 : IMPLEMENT_GET_IMPLEMENTATION_ID( classname )
149 :
150 : #define IMPLEMENT_FORWARD_XTYPEPROVIDER3( classname, baseclass1, baseclass2, baseclass3 ) \
151 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL classname::getTypes( ) throw (::com::sun::star::uno::RuntimeException, std::exception) \
152 : { \
153 : return ::comphelper::concatSequences( \
154 : baseclass1::getTypes(), \
155 : baseclass2::getTypes(), \
156 : baseclass3::getTypes() \
157 : ); \
158 : } \
159 : \
160 : IMPLEMENT_GET_IMPLEMENTATION_ID( classname )
161 :
162 :
163 :
164 : /** ask for an iface of an aggregated object
165 : usage:<br/>
166 : Reference<XFoo> xFoo;<br/>
167 : if (query_aggregation(xAggregatedObject, xFoo))<br/>
168 : ....
169 : */
170 : template <class iface>
171 4025 : bool query_aggregation(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation >& _rxAggregate, ::com::sun::star::uno::Reference<iface>& _rxOut)
172 : {
173 4025 : _rxOut = static_cast<iface*>(NULL);
174 4025 : if (_rxAggregate.is())
175 : {
176 : ::com::sun::star::uno::Any aCheck = _rxAggregate->queryAggregation(
177 3968 : cppu::UnoType<iface>::get());
178 3968 : if (aCheck.hasValue())
179 3770 : _rxOut = *static_cast<const ::com::sun::star::uno::Reference<iface>*>(aCheck.getValue());
180 : }
181 4025 : return _rxOut.is();
182 : }
183 : } // namespace comphelper
184 :
185 :
186 : #endif // INCLUDED_COMPHELPER_UNO3_HXX
187 :
188 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|