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 _DBASHARED_APITOOLS_HXX_
21 #define _DBASHARED_APITOOLS_HXX_
23 #include <cppuhelper/component.hxx>
24 #include <osl/mutex.hxx>
25 #include <cppuhelper/interfacecontainer.hxx>
26 #include <osl/diagnose.h>
27 #include <comphelper/stl_types.hxx>
28 #include <cppuhelper/typeprovider.hxx>
29 #include <comphelper/sequence.hxx>
31 //==================================================================================
33 //==================================================================================
34 DECLARE_STL_VECTOR(::com::sun::star::uno::WeakReferenceHelper
, OWeakRefArray
);
36 //==================================================================================
37 //= OSubComponent - a component which holds a hard ref to it's parent
38 //= and is been hold itself (by the parent) with a weak ref
39 //==================================================================================
40 class OSubComponent
: public ::cppu::OComponentHelper
43 // the parent must support the tunnel implementation
44 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> m_xParent
;
45 virtual ~OSubComponent();
48 OSubComponent(::osl::Mutex
& _rMutex
,
49 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xParent
);
51 // ::com::sun::star::lang::XTypeProvider
52 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes() throw (::com::sun::star::uno::RuntimeException
);
54 // ::com::sun::star::uno::XInterface
55 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& rType
)
56 throw(::com::sun::star::uno::RuntimeException
);
57 virtual void SAL_CALL
acquire() throw();
58 virtual void SAL_CALL
release() throw();
60 inline operator ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> () const
61 { return (::com::sun::star::uno::XWeak
*)this; }
65 //==================================================================================
66 //= helper for implementing the XServiceInfo interface
68 //----------------------------------------------------------------------------------
69 // (internal - not to be used outside - usually)
70 #define IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
71 ::rtl::OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) \
73 return ::rtl::OUString::createFromAscii(implasciiname); \
76 #define IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(classname, implasciiname) \
77 ::rtl::OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) \
79 return getImplementationName_Static(); \
81 ::rtl::OUString SAL_CALL classname::getImplementationName_Static( ) throw (::com::sun::star::uno::RuntimeException) \
83 return ::rtl::OUString::createFromAscii(implasciiname); \
86 #define IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
87 sal_Bool SAL_CALL classname::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) \
89 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); \
90 const ::rtl::OUString* pSupported = aSupported.getConstArray(); \
91 for (sal_Int32 i=0; i<aSupported.getLength(); ++i, ++pSupported) \
92 if (pSupported->equals(_rServiceName)) \
98 #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED1(classname, serviceasciiname) \
99 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
101 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1); \
102 aSupported[0] = ::rtl::OUString::createFromAscii(serviceasciiname); \
106 #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(classname, serviceasciiname) \
107 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
109 return getSupportedServiceNames_Static(); \
111 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException) \
113 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1); \
114 aSupported[0] = ::rtl::OUString::createFromAscii(serviceasciiname); \
118 #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED2_STATIC(classname, serviceasciiname1, serviceasciiname2) \
119 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
121 return getSupportedServiceNames_Static(); \
123 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException) \
125 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(2); \
126 aSupported[0] = ::rtl::OUString::createFromAscii(serviceasciiname1); \
127 aSupported[1] = ::rtl::OUString::createFromAscii(serviceasciiname2); \
131 #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED2(classname, serviceasciiname1, serviceasciiname2) \
132 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
134 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(2); \
135 aSupported[0] = ::rtl::OUString::createFromAscii(serviceasciiname1); \
136 aSupported[1] = ::rtl::OUString::createFromAscii(serviceasciiname2); \
140 #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED3(classname, serviceasciiname1, serviceasciiname2, serviceasciiname3) \
141 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
143 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(3); \
144 aSupported[0] = ::rtl::OUString::createFromAscii(serviceasciiname1); \
145 aSupported[1] = ::rtl::OUString::createFromAscii(serviceasciiname2); \
146 aSupported[2] = ::rtl::OUString::createFromAscii(serviceasciiname3); \
150 #define IMPLEMENT_SERVICE_INFO_CREATE_STATIC(classname) \
151 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > \
152 SAL_CALL classname::Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB) \
154 return static_cast< XServiceInfo* >(new classname(_rxORB)); \
157 //----------------------------------------------------------------------------------
158 // declare service info methods
159 #define DECLARE_SERVICE_INFO() \
160 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); \
161 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); \
162 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
164 #define DECLARE_SERVICE_INFO_STATIC() \
165 DECLARE_SERVICE_INFO(); \
166 static ::rtl::OUString SAL_CALL getImplementationName_Static( ) throw (::com::sun::star::uno::RuntimeException); \
167 static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException); \
168 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > \
169 SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&) \
171 //----------------------------------------------------------------------------------
172 #define IMPLEMENT_SERVICE_INFO1(classname, implasciiname, serviceasciiname) \
173 IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
174 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
175 IMPLEMENT_SERVICE_INFO_GETSUPPORTED1(classname, serviceasciiname) \
177 //----------------------------------------------------------------------------------
178 #define IMPLEMENT_SERVICE_INFO1_STATIC(classname, implasciiname, serviceasciiname) \
179 IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(classname, implasciiname) \
180 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
181 IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(classname, serviceasciiname) \
182 IMPLEMENT_SERVICE_INFO_CREATE_STATIC(classname) \
184 //----------------------------------------------------------------------------------
185 #define IMPLEMENT_SERVICE_INFO2(classname, implasciiname, serviceasciiname1, serviceasciiname2) \
186 IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
187 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
188 IMPLEMENT_SERVICE_INFO_GETSUPPORTED2(classname, serviceasciiname1, serviceasciiname2)
190 //----------------------------------------------------------------------------------
191 #define IMPLEMENT_SERVICE_INFO2_STATIC(classname, implasciiname, serviceasciiname1, serviceasciiname2) \
192 IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(classname, implasciiname) \
193 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
194 IMPLEMENT_SERVICE_INFO_GETSUPPORTED2_STATIC(classname, serviceasciiname1,serviceasciiname2) \
195 IMPLEMENT_SERVICE_INFO_CREATE_STATIC(classname) \
197 //----------------------------------------------------------------------------------
198 #define IMPLEMENT_SERVICE_INFO3(classname, implasciiname, serviceasciiname1, serviceasciiname2, serviceasciiname3) \
199 IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
200 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
201 IMPLEMENT_SERVICE_INFO_GETSUPPORTED3(classname, serviceasciiname1, serviceasciiname2, serviceasciiname3) \
203 //----------------------------------------------------------------------------------
204 #define IMPLEMENT_SERVICE_INFO1_ABSTRACT(classname, serviceasciiname) \
205 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
206 IMPLEMENT_SERVICE_INFO_GETSUPPORTED1(classname, serviceasciiname) \
208 //----------------------------------------------------------------------------------
209 #define IMPLEMENT_SERVICE_INFO2_ABSTRACT(classname, serviceasciiname1, serviceasciiname2) \
210 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
211 IMPLEMENT_SERVICE_INFO_GETSUPPORTED2(classname, serviceasciiname1, serviceasciiname2) \
213 //==================================================================================
214 //= XTypeProvider helpers
216 //--------------------------------------------------------------------------
217 #define DECLARE_IMPLEMENTATION_ID( ) \
218 virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL getImplementationId( ) throw(::com::sun::star::uno::RuntimeException); \
219 static ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId() \
221 //--------------------------------------------------------------------------
222 #define DECLARE_GETTYPES( ) \
223 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException);
225 //--------------------------------------------------------------------------
226 #define DECLARE_TYPEPROVIDER( ) \
227 DECLARE_GETTYPES( ) \
228 DECLARE_IMPLEMENTATION_ID( )
230 //--------------------------------------------------------------------------
231 #define IMPLEMENT_IMPLEMENTATION_ID( classname ) \
232 ::com::sun::star::uno::Sequence< sal_Int8 > classname::getUnoTunnelImplementationId() \
234 static ::cppu::OImplementationId* pId = 0; \
237 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); \
240 static ::cppu::OImplementationId aId; \
244 return pId->getImplementationId(); \
246 ::com::sun::star::uno::Sequence< sal_Int8 > classname::getImplementationId() throw (::com::sun::star::uno::RuntimeException) \
248 return classname::getUnoTunnelImplementationId(); \
251 //--------------------------------------------------------------------------
252 #define IMPLEMENT_GETTYPES2( classname, baseclass1, baseclass2 ) \
253 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > classname::getTypes() throw (::com::sun::star::uno::RuntimeException) \
255 return ::comphelper::concatSequences( \
256 baseclass1::getTypes( ), \
257 baseclass2::getTypes( ) \
261 //--------------------------------------------------------------------------
262 #define IMPLEMENT_GETTYPES3( classname, baseclass1, baseclass2, baseclass3 ) \
263 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > classname::getTypes() throw (::com::sun::star::uno::RuntimeException) \
265 return ::comphelper::concatSequences( \
266 baseclass1::getTypes( ), \
267 baseclass2::getTypes( ), \
268 baseclass3::getTypes( ) \
272 //--------------------------------------------------------------------------
273 #define IMPLEMENT_TYPEPROVIDER2( classname, baseclass1, baseclass2 ) \
274 IMPLEMENT_IMPLEMENTATION_ID( classname) \
275 IMPLEMENT_GETTYPES2( classname, baseclass1, baseclass2 )
277 //--------------------------------------------------------------------------
278 #define IMPLEMENT_TYPEPROVIDER3( classname, baseclass1, baseclass2, baseclass3 ) \
279 IMPLEMENT_IMPLEMENTATION_ID( classname) \
280 IMPLEMENT_GETTYPES3(classname, baseclass1, baseclass2, baseclass3 )
282 //==================================================================================
283 //= helper for declaring/implementing classes based on the OPropertyContainer and an OPropertyArrayUsageHelper
284 //----------------------------------------------------------------------------------
285 #define DECLARE_PROPERTYCONTAINER_DEFAULTS( ) \
286 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException); \
287 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); \
288 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const
290 //----------------------------------------------------------------------------------
291 #define IMPLEMENT_PROPERTYCONTAINER_DEFAULTS2( classname , baseclass1) \
292 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL classname::getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException) \
294 Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); \
297 ::cppu::IPropertyArrayHelper& classname::getInfoHelper() \
299 return *baseclass1::getArrayHelper(); \
301 ::cppu::IPropertyArrayHelper* classname::createArrayHelper( ) const \
303 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > aProps; \
304 describeProperties(aProps); \
305 return new ::cppu::OPropertyArrayHelper(aProps); \
307 //----------------------------------------------------------------------------------
308 #define IMPLEMENT_PROPERTYCONTAINER_DEFAULTS( classname ) \
309 IMPLEMENT_PROPERTYCONTAINER_DEFAULTS2( classname, classname )
311 //==================================================================================
312 //= helper for implementing the createArrayHelper
313 //----------------------------------------------------------------------------------
314 #define BEGIN_PROPERTY_SEQUENCE(count) \
315 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> aDescriptor(count); \
316 ::com::sun::star::beans::Property* pDesc = aDescriptor.getArray(); \
317 sal_Int32 nPos = 0; \
319 //----------------------------------------------------------------------------------
320 #define BEGIN_PROPERTY_HELPER(count) \
321 BEGIN_PROPERTY_SEQUENCE(count)
323 //----------------------------------------------------------------------------------
324 #define DECL_PROP_IMPL(varname, cpputype) \
325 pDesc[nPos++] = ::com::sun::star::beans::Property(PROPERTY_##varname, PROPERTY_ID_##varname, cpputype,
327 //----------------------------------------------------------------------------------
328 #define DECL_PROP0(varname, type) \
329 DECL_PROP_IMPL(varname, ::getCppuType((const type *)0)) 0)
330 //----------------------------------------------------------------------------------
331 #define DECL_PROP0_BOOL(varname) \
332 DECL_PROP_IMPL(varname, ::getBooleanCppuType()) 0)
333 //----------------------------------------------------------------------------------
334 #define DECL_PROP0_IFACE(varname, iface) \
335 DECL_PROP_IMPL(varname, ::getCppuType(static_cast< ::com::sun::star::uno::Reference< iface >* >(NULL))) 0)
337 //----------------------------------------------------------------------------------
338 #define DECL_PROP1(varname, type, attrib1) \
339 DECL_PROP_IMPL(varname, ::getCppuType((const type *)0)) ::com::sun::star::beans::PropertyAttribute::attrib1)
340 //----------------------------------------------------------------------------------
341 #define DECL_PROP1_BOOL(varname, attrib1) \
342 DECL_PROP_IMPL(varname, ::getBooleanCppuType()) ::com::sun::star::beans::PropertyAttribute::attrib1)
343 //----------------------------------------------------------------------------------
344 #define DECL_PROP1_IFACE(varname, iface, attrib1) \
345 DECL_PROP_IMPL(varname, ::getCppuType(static_cast< ::com::sun::star::uno::Reference< iface >* >(NULL))) ::com::sun::star::beans::PropertyAttribute::attrib1)
346 //----------------------------------------------------------------------------------
347 #define DECL_PROP2_IFACE(varname, iface, attrib1, attrib2) \
348 DECL_PROP_IMPL(varname, ::getCppuType(static_cast< ::com::sun::star::uno::Reference< iface >* >(NULL))) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2)
350 //----------------------------------------------------------------------------------
351 #define DECL_PROP2(varname, type, attrib1, attrib2) \
352 DECL_PROP_IMPL(varname, ::getCppuType((const type *)0)) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2)
353 //----------------------------------------------------------------------------------
354 #define DECL_PROP2_BOOL(varname, attrib1, attrib2) \
355 DECL_PROP_IMPL(varname, ::getBooleanCppuType()) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2)
357 //----------------------------------------------------------------------------------
358 #define DECL_PROP3(varname, type, attrib1, attrib2, attrib3) \
359 DECL_PROP_IMPL(varname, ::getCppuType((const type *)0)) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2 | ::com::sun::star::beans::PropertyAttribute::attrib3)
360 //----------------------------------------------------------------------------------
361 #define DECL_PROP3_BOOL(varname, attrib1, attrib2, attrib3) \
362 DECL_PROP_IMPL(varname, ::getBooleanCppuType()) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2 | ::com::sun::star::beans::PropertyAttribute::attrib3)
365 //----------------------------------------------------------------------------------
366 #define END_PROPERTY_SEQUENCE() \
367 OSL_ENSURE(nPos == aDescriptor.getLength(), "forgot to adjust the count ?"); \
369 //----------------------------------------------------------------------------------
370 #define END_PROPERTY_HELPER() \
371 END_PROPERTY_SEQUENCE() \
372 return new ::cppu::OPropertyArrayHelper(aDescriptor);
375 #define NOTIFY_LISTERNERS(_rListeners,T,method) \
376 Sequence< Reference< XInterface > > aListenerSeq = _rListeners.getElements(); \
378 const Reference< XInterface >* pxIntBegin = aListenerSeq.getConstArray(); \
379 const Reference< XInterface >* pxInt = pxIntBegin + aListenerSeq.getLength(); \
382 while( pxInt > pxIntBegin ) \
386 while( pxInt > pxIntBegin ) \
389 static_cast< T* >( pxInt->get() )->method(aEvt); \
392 catch( RuntimeException& ) \
398 #endif // _DBASHARED_APITOOLS_HXX_
400 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */