1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: apitools.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _DBASHARED_APITOOLS_HXX_
32 #define _DBASHARED_APITOOLS_HXX_
34 #ifndef _CPPUHELPER_COMPONENT_HXX_
35 #include <cppuhelper/component.hxx>
37 #ifndef _OSL_MUTEX_HXX_
38 #include <osl/mutex.hxx>
40 #ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_
41 #include <cppuhelper/interfacecontainer.hxx>
43 #ifndef _OSL_DIAGNOSE_H_
44 #include <osl/diagnose.h>
46 #ifndef _COMPHELPER_STLTYPES_HXX_
47 #include <comphelper/stl_types.hxx>
49 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
50 #include <cppuhelper/typeprovider.hxx>
52 #ifndef _COMPHELPER_SEQUENCE_HXX_
53 #include <comphelper/sequence.hxx>
56 //==================================================================================
58 //==================================================================================
59 DECLARE_STL_VECTOR(::com::sun::star::uno::WeakReferenceHelper
, OWeakRefArray
);
61 //==================================================================================
62 //= OSubComponent - a component which holds a hard ref to it's parent
63 //= and is been hold itself (by the parent) with a weak ref
64 //==================================================================================
65 class OSubComponent
: public ::cppu::OComponentHelper
68 // the parent must support the tunnel implementation
69 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> m_xParent
;
70 virtual ~OSubComponent();
73 OSubComponent(::osl::Mutex
& _rMutex
,
74 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xParent
);
76 // ::com::sun::star::lang::XTypeProvider
77 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes() throw (::com::sun::star::uno::RuntimeException
);
79 // ::com::sun::star::uno::XInterface
80 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& rType
)
81 throw(::com::sun::star::uno::RuntimeException
);
82 virtual void SAL_CALL
acquire() throw();
83 virtual void SAL_CALL
release() throw();
85 inline operator ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> () const
86 { return (::com::sun::star::uno::XWeak
*)this; }
90 //==================================================================================
91 //= helper for implementing the XServiceInfo interface
93 //----------------------------------------------------------------------------------
94 // (internal - not to be used outside - usually)
95 #define IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
96 ::rtl::OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) \
98 return ::rtl::OUString::createFromAscii(implasciiname); \
101 #define IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(classname, implasciiname) \
102 ::rtl::OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) \
104 return getImplementationName_Static(); \
106 ::rtl::OUString SAL_CALL classname::getImplementationName_Static( ) throw (::com::sun::star::uno::RuntimeException) \
108 return ::rtl::OUString::createFromAscii(implasciiname); \
111 #define IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
112 sal_Bool SAL_CALL classname::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) \
114 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); \
115 const ::rtl::OUString* pSupported = aSupported.getConstArray(); \
116 for (sal_Int32 i=0; i<aSupported.getLength(); ++i, ++pSupported) \
117 if (pSupported->equals(_rServiceName)) \
123 #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED1(classname, serviceasciiname) \
124 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
126 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1); \
127 aSupported[0] = ::rtl::OUString::createFromAscii(serviceasciiname); \
131 #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(classname, serviceasciiname) \
132 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
134 return getSupportedServiceNames_Static(); \
136 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException) \
138 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1); \
139 aSupported[0] = ::rtl::OUString::createFromAscii(serviceasciiname); \
143 #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED2_STATIC(classname, serviceasciiname1, serviceasciiname2) \
144 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
146 return getSupportedServiceNames_Static(); \
148 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException) \
150 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(2); \
151 aSupported[0] = ::rtl::OUString::createFromAscii(serviceasciiname1); \
152 aSupported[1] = ::rtl::OUString::createFromAscii(serviceasciiname2); \
156 #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED2(classname, serviceasciiname1, serviceasciiname2) \
157 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
159 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(2); \
160 aSupported[0] = ::rtl::OUString::createFromAscii(serviceasciiname1); \
161 aSupported[1] = ::rtl::OUString::createFromAscii(serviceasciiname2); \
165 #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED3(classname, serviceasciiname1, serviceasciiname2, serviceasciiname3) \
166 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
168 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(3); \
169 aSupported[0] = ::rtl::OUString::createFromAscii(serviceasciiname1); \
170 aSupported[1] = ::rtl::OUString::createFromAscii(serviceasciiname2); \
171 aSupported[2] = ::rtl::OUString::createFromAscii(serviceasciiname3); \
175 #define IMPLEMENT_SERVICE_INFO_CREATE_STATIC(classname) \
176 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > \
177 SAL_CALL classname::Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB) \
179 return static_cast< XServiceInfo* >(new classname(_rxORB)); \
182 //----------------------------------------------------------------------------------
183 // declare service info methods - no getImplementationName, so the class is abstract
184 #define DECLARE_SERVICE_INFO_ABSTRACT() \
185 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); \
186 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
188 //----------------------------------------------------------------------------------
189 // declare service info methods
190 #define DECLARE_SERVICE_INFO() \
191 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); \
192 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); \
193 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
195 #define DECLARE_SERVICE_INFO_STATIC() \
196 DECLARE_SERVICE_INFO(); \
197 static ::rtl::OUString SAL_CALL getImplementationName_Static( ) throw (::com::sun::star::uno::RuntimeException); \
198 static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException); \
199 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > \
200 SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&) \
202 //----------------------------------------------------------------------------------
203 #define IMPLEMENT_SERVICE_INFO1(classname, implasciiname, serviceasciiname) \
204 IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
205 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
206 IMPLEMENT_SERVICE_INFO_GETSUPPORTED1(classname, serviceasciiname) \
208 //----------------------------------------------------------------------------------
209 #define IMPLEMENT_SERVICE_INFO1_STATIC(classname, implasciiname, serviceasciiname) \
210 IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(classname, implasciiname) \
211 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
212 IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(classname, serviceasciiname) \
213 IMPLEMENT_SERVICE_INFO_CREATE_STATIC(classname) \
215 //----------------------------------------------------------------------------------
216 #define IMPLEMENT_SERVICE_INFO2(classname, implasciiname, serviceasciiname1, serviceasciiname2) \
217 IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
218 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
219 IMPLEMENT_SERVICE_INFO_GETSUPPORTED2(classname, serviceasciiname1, serviceasciiname2)
221 //----------------------------------------------------------------------------------
222 #define IMPLEMENT_SERVICE_INFO2_STATIC(classname, implasciiname, serviceasciiname1, serviceasciiname2) \
223 IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(classname, implasciiname) \
224 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
225 IMPLEMENT_SERVICE_INFO_GETSUPPORTED2_STATIC(classname, serviceasciiname1,serviceasciiname2) \
226 IMPLEMENT_SERVICE_INFO_CREATE_STATIC(classname) \
228 //----------------------------------------------------------------------------------
229 #define IMPLEMENT_SERVICE_INFO3(classname, implasciiname, serviceasciiname1, serviceasciiname2, serviceasciiname3) \
230 IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
231 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
232 IMPLEMENT_SERVICE_INFO_GETSUPPORTED3(classname, serviceasciiname1, serviceasciiname2, serviceasciiname3) \
234 //----------------------------------------------------------------------------------
235 #define IMPLEMENT_SERVICE_INFO1_ABSTRACT(classname, serviceasciiname) \
236 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
237 IMPLEMENT_SERVICE_INFO_GETSUPPORTED1(classname, serviceasciiname) \
239 //----------------------------------------------------------------------------------
240 #define IMPLEMENT_SERVICE_INFO2_ABSTRACT(classname, serviceasciiname1, serviceasciiname2) \
241 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
242 IMPLEMENT_SERVICE_INFO_GETSUPPORTED2(classname, serviceasciiname1, serviceasciiname2) \
244 //==================================================================================
245 //= XTypeProvider helpers
247 //--------------------------------------------------------------------------
248 #define DECLARE_IMPLEMENTATION_ID( ) \
249 virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL getImplementationId( ) throw(::com::sun::star::uno::RuntimeException); \
250 static ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId() \
252 //--------------------------------------------------------------------------
253 #define DECLARE_GETTYPES( ) \
254 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException);
256 //--------------------------------------------------------------------------
257 #define DECLARE_TYPEPROVIDER( ) \
258 DECLARE_GETTYPES( ) \
259 DECLARE_IMPLEMENTATION_ID( )
261 //--------------------------------------------------------------------------
262 #define IMPLEMENT_IMPLEMENTATION_ID( classname ) \
263 ::com::sun::star::uno::Sequence< sal_Int8 > classname::getUnoTunnelImplementationId() \
265 static ::cppu::OImplementationId* pId = 0; \
268 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); \
271 static ::cppu::OImplementationId aId; \
275 return pId->getImplementationId(); \
277 ::com::sun::star::uno::Sequence< sal_Int8 > classname::getImplementationId() throw (::com::sun::star::uno::RuntimeException) \
279 return classname::getUnoTunnelImplementationId(); \
282 //--------------------------------------------------------------------------
283 #define IMPLEMENT_GETTYPES2( classname, baseclass1, baseclass2 ) \
284 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > classname::getTypes() throw (::com::sun::star::uno::RuntimeException) \
286 return ::comphelper::concatSequences( \
287 baseclass1::getTypes( ), \
288 baseclass2::getTypes( ) \
292 //--------------------------------------------------------------------------
293 #define IMPLEMENT_GETTYPES3( classname, baseclass1, baseclass2, baseclass3 ) \
294 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > classname::getTypes() throw (::com::sun::star::uno::RuntimeException) \
296 return ::comphelper::concatSequences( \
297 baseclass1::getTypes( ), \
298 baseclass2::getTypes( ), \
299 baseclass3::getTypes( ) \
303 //--------------------------------------------------------------------------
304 #define IMPLEMENT_TYPEPROVIDER2( classname, baseclass1, baseclass2 ) \
305 IMPLEMENT_IMPLEMENTATION_ID( classname) \
306 IMPLEMENT_GETTYPES2( classname, baseclass1, baseclass2 )
308 //--------------------------------------------------------------------------
309 #define IMPLEMENT_TYPEPROVIDER3( classname, baseclass1, baseclass2, baseclass3 ) \
310 IMPLEMENT_IMPLEMENTATION_ID( classname) \
311 IMPLEMENT_GETTYPES3(classname, baseclass1, baseclass2, baseclass3 )
313 //==================================================================================
314 //= helper for declaring/implementing classes based on the OPropertyContainer and an OPropertyArrayUsageHelper
315 //----------------------------------------------------------------------------------
316 #define DECLARE_PROPERTYCONTAINER_DEFAULTS( ) \
317 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException); \
318 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); \
319 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const
321 //----------------------------------------------------------------------------------
322 #define IMPLEMENT_PROPERTYCONTAINER_DEFAULTS2( classname , baseclass1) \
323 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL classname::getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException) \
325 Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); \
328 ::cppu::IPropertyArrayHelper& classname::getInfoHelper() \
330 return *baseclass1::getArrayHelper(); \
332 ::cppu::IPropertyArrayHelper* classname::createArrayHelper( ) const \
334 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > aProps; \
335 describeProperties(aProps); \
336 return new ::cppu::OPropertyArrayHelper(aProps); \
338 //----------------------------------------------------------------------------------
339 #define IMPLEMENT_PROPERTYCONTAINER_DEFAULTS( classname ) \
340 IMPLEMENT_PROPERTYCONTAINER_DEFAULTS2( classname, classname )
342 //==================================================================================
343 //= helper for implementing the createArrayHelper
344 //----------------------------------------------------------------------------------
345 #define BEGIN_PROPERTY_SEQUENCE(count) \
346 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> aDescriptor(count); \
347 ::com::sun::star::beans::Property* pDesc = aDescriptor.getArray(); \
348 sal_Int32 nPos = 0; \
350 //----------------------------------------------------------------------------------
351 #define BEGIN_PROPERTY_HELPER(count) \
352 BEGIN_PROPERTY_SEQUENCE(count)
354 //----------------------------------------------------------------------------------
355 #define DECL_PROP_IMPL(varname, cpputype) \
356 pDesc[nPos++] = ::com::sun::star::beans::Property(PROPERTY_##varname, PROPERTY_ID_##varname, cpputype,
358 //----------------------------------------------------------------------------------
359 #define DECL_PROP0(varname, type) \
360 DECL_PROP_IMPL(varname, ::getCppuType((const type *)0)) 0)
361 //----------------------------------------------------------------------------------
362 #define DECL_PROP0_BOOL(varname) \
363 DECL_PROP_IMPL(varname, ::getBooleanCppuType()) 0)
364 //----------------------------------------------------------------------------------
365 #define DECL_PROP0_IFACE(varname, iface) \
366 DECL_PROP_IMPL(varname, ::getCppuType(static_cast< ::com::sun::star::uno::Reference< iface >* >(NULL))) 0)
368 //----------------------------------------------------------------------------------
369 #define DECL_PROP1(varname, type, attrib1) \
370 DECL_PROP_IMPL(varname, ::getCppuType((const type *)0)) ::com::sun::star::beans::PropertyAttribute::attrib1)
371 //----------------------------------------------------------------------------------
372 #define DECL_PROP1_BOOL(varname, attrib1) \
373 DECL_PROP_IMPL(varname, ::getBooleanCppuType()) ::com::sun::star::beans::PropertyAttribute::attrib1)
374 //----------------------------------------------------------------------------------
375 #define DECL_PROP1_IFACE(varname, iface, attrib1) \
376 DECL_PROP_IMPL(varname, ::getCppuType(static_cast< ::com::sun::star::uno::Reference< iface >* >(NULL))) ::com::sun::star::beans::PropertyAttribute::attrib1)
377 //----------------------------------------------------------------------------------
378 #define DECL_PROP2_IFACE(varname, iface, attrib1, attrib2) \
379 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)
381 //----------------------------------------------------------------------------------
382 #define DECL_PROP2(varname, type, attrib1, attrib2) \
383 DECL_PROP_IMPL(varname, ::getCppuType((const type *)0)) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2)
384 //----------------------------------------------------------------------------------
385 #define DECL_PROP2_BOOL(varname, attrib1, attrib2) \
386 DECL_PROP_IMPL(varname, ::getBooleanCppuType()) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2)
388 //----------------------------------------------------------------------------------
389 #define DECL_PROP3(varname, type, attrib1, attrib2, attrib3) \
390 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)
391 //----------------------------------------------------------------------------------
392 #define DECL_PROP3_BOOL(varname, attrib1, attrib2, attrib3) \
393 DECL_PROP_IMPL(varname, ::getBooleanCppuType()) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2 | ::com::sun::star::beans::PropertyAttribute::attrib3)
396 //----------------------------------------------------------------------------------
397 #define END_PROPERTY_SEQUENCE() \
398 OSL_ENSURE(nPos == aDescriptor.getLength(), "forgot to adjust the count ?"); \
400 //----------------------------------------------------------------------------------
401 #define END_PROPERTY_HELPER() \
402 END_PROPERTY_SEQUENCE() \
403 return new ::cppu::OPropertyArrayHelper(aDescriptor);
406 #define NOTIFY_LISTERNERS(_rListeners,T,method) \
407 Sequence< Reference< XInterface > > aListenerSeq = _rListeners.getElements(); \
409 const Reference< XInterface >* pxIntBegin = aListenerSeq.getConstArray(); \
410 const Reference< XInterface >* pxInt = pxIntBegin + aListenerSeq.getLength(); \
413 while( pxInt > pxIntBegin ) \
417 while( pxInt > pxIntBegin ) \
420 static_cast< T* >( pxInt->get() )->method(aEvt); \
423 catch( RuntimeException& ) \
429 #define NOTIFY_LISTERNERS1(_rListeners,T,method,arg1) \
430 Sequence< Reference< XInterface > > aListenerSeq = _rListeners.getElements(); \
432 const Reference< XInterface >* pxIntBegin = aListenerSeq.getConstArray(); \
433 const Reference< XInterface >* pxInt = pxIntBegin + aListenerSeq.getLength(); \
436 while( pxInt > pxIntBegin ) \
440 while( pxInt > pxIntBegin ) \
443 static_cast< T* >( pxInt->get() )->method(aEvt,arg1); \
446 catch( RuntimeException& ) \
453 //==================================================================================
457 #endif // _DBASHARED_APITOOLS_HXX_