1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #ifndef OOVBAAPI_VBA_HELPERINTERFACE_HXX 28*cdf0e10cSrcweir #define OOVBAAPI_VBA_HELPERINTERFACE_HXX 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 31*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx> 32*cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx> 33*cdf0e10cSrcweir #include <ooo/vba/XHelperInterface.hpp> 34*cdf0e10cSrcweir #include <vbahelper/vbahelper.hxx> 35*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir // use this class when you have an a object like 38*cdf0e10cSrcweir // interface XAnInterface which contains XHelperInterface in its inheritance hierarchy 39*cdf0e10cSrcweir // interface XAnInterface 40*cdf0e10cSrcweir // { 41*cdf0e10cSrcweir // interface XHelperInterface; 42*cdf0e10cSrcweir // [attribute, string] name; 43*cdf0e10cSrcweir // } 44*cdf0e10cSrcweir // or 45*cdf0e10cSrcweir // interface XAnInterface : XHelperInterface; 46*cdf0e10cSrcweir // { 47*cdf0e10cSrcweir // [attribute, string] name; 48*cdf0e10cSrcweir // } 49*cdf0e10cSrcweir // 50*cdf0e10cSrcweir // then this class can provide a default implementation of XHelperInterface, 51*cdf0e10cSrcweir // you can use it like this 52*cdf0e10cSrcweir // typedef InheritedHelperInterfaceImpl< XAnInterface > > AnInterfaceImpl_BASE; 53*cdf0e10cSrcweir // class AnInterfaceImpl : public AnInterfaceImpl_BASE 54*cdf0e10cSrcweir // { 55*cdf0e10cSrcweir // public: 56*cdf0e10cSrcweir // AnInterface( const Reference< HelperInterface >& xParent ) : AnInterfaceImpl_BASE( xParent ) {} 57*cdf0e10cSrcweir // // implement XAnInterface methods only, no need to implement the XHelperInterface 58*cdf0e10cSrcweir // // methods 59*cdf0e10cSrcweir // virtual void setName( const OUString& ); 60*cdf0e10cSrcweir // virtual OUString getName(); 61*cdf0e10cSrcweir // } 62*cdf0e10cSrcweir // 63*cdf0e10cSrcweir const ::rtl::OUString sHelperServiceName( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.HelperServiceBase" ) ); 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir template< typename Ifc1 > 66*cdf0e10cSrcweir class InheritedHelperInterfaceImpl : public Ifc1 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir protected: 69*cdf0e10cSrcweir css::uno::WeakReference< ov::XHelperInterface > mxParent; 70*cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > mxContext; 71*cdf0e10cSrcweir public: 72*cdf0e10cSrcweir InheritedHelperInterfaceImpl() {} 73*cdf0e10cSrcweir InheritedHelperInterfaceImpl( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : mxContext( xContext ) {} 74*cdf0e10cSrcweir InheritedHelperInterfaceImpl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : mxParent( xParent ), mxContext( xContext ) {} 75*cdf0e10cSrcweir virtual rtl::OUString& getServiceImplName() = 0; 76*cdf0e10cSrcweir virtual css::uno::Sequence<rtl::OUString> getServiceNames() = 0; 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir // XHelperInterface Methods 79*cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL getCreator() throw (css::script::BasicErrorException, css::uno::RuntimeException) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir return 0x53756E4F; 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) { return mxParent; } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir virtual css::uno::Any SAL_CALL Application( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) { 86*cdf0e10cSrcweir // The application could certainly be passed around in the context - seems 87*cdf0e10cSrcweir // to make sense 88*cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xNameAccess( mxContext, css::uno::UNO_QUERY_THROW ); 89*cdf0e10cSrcweir return xNameAccess->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Application" ) ) ); 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir // XServiceInfo Methods 93*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (css::uno::RuntimeException) { return getServiceImplName(); } 94*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (css::uno::RuntimeException) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > sServices = getSupportedServiceNames(); 97*cdf0e10cSrcweir const rtl::OUString* pStart = sServices.getConstArray(); 98*cdf0e10cSrcweir const rtl::OUString* pEnd = pStart + sServices.getLength(); 99*cdf0e10cSrcweir for ( ; pStart != pEnd ; ++pStart ) 100*cdf0e10cSrcweir if ( (*pStart).equals( ServiceName ) ) 101*cdf0e10cSrcweir return sal_True; 102*cdf0e10cSrcweir return sal_False; 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (css::uno::RuntimeException) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > aNames = getServiceNames(); 107*cdf0e10cSrcweir return aNames; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir }; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir template< typename Ifc1 > 112*cdf0e10cSrcweir class InheritedHelperInterfaceImpl1 : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper1< Ifc1 > > 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir typedef InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper1< Ifc1 > > Base; 115*cdf0e10cSrcweir public: 116*cdf0e10cSrcweir InheritedHelperInterfaceImpl1< Ifc1 >() {} 117*cdf0e10cSrcweir InheritedHelperInterfaceImpl1< Ifc1 >( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xContext ) {} 118*cdf0e10cSrcweir InheritedHelperInterfaceImpl1< Ifc1 >( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xParent, xContext ) {} 119*cdf0e10cSrcweir }; 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir template< typename Ifc1, typename Ifc2 > 122*cdf0e10cSrcweir class InheritedHelperInterfaceImpl2 : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper2< Ifc1, Ifc2 > > 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir typedef InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper2< Ifc1, Ifc2 > > Base; 125*cdf0e10cSrcweir public: 126*cdf0e10cSrcweir InheritedHelperInterfaceImpl2< Ifc1, Ifc2 >() {} 127*cdf0e10cSrcweir InheritedHelperInterfaceImpl2< Ifc1, Ifc2 >( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xContext ) {} 128*cdf0e10cSrcweir InheritedHelperInterfaceImpl2< Ifc1, Ifc2 >( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xParent, xContext ) {} 129*cdf0e10cSrcweir }; 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir template< typename Ifc1, typename Ifc2, typename Ifc3 > 132*cdf0e10cSrcweir class InheritedHelperInterfaceImpl3 : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper3< Ifc1, Ifc2, Ifc3 > > 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir typedef InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper3< Ifc1, Ifc2, Ifc3 > > Base; 135*cdf0e10cSrcweir public: 136*cdf0e10cSrcweir InheritedHelperInterfaceImpl3< Ifc1, Ifc2, Ifc3 >() {} 137*cdf0e10cSrcweir InheritedHelperInterfaceImpl3< Ifc1, Ifc2, Ifc3 >( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xContext ) {} 138*cdf0e10cSrcweir InheritedHelperInterfaceImpl3< Ifc1, Ifc2, Ifc3 >( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xParent, xContext ) {} 139*cdf0e10cSrcweir }; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir // ============================================================================ 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir /** Helper macro to implement the method 'getServiceImplName()' of the 144*cdf0e10cSrcweir 'ooo.vba.XHelperInterface' interface. Will return the class name as service 145*cdf0e10cSrcweir implementation name. 146*cdf0e10cSrcweir */ 147*cdf0e10cSrcweir #define VBAHELPER_IMPL_GETSERVICEIMPLNAME( classname ) \ 148*cdf0e10cSrcweir ::rtl::OUString& classname::getServiceImplName() \ 149*cdf0e10cSrcweir { \ 150*cdf0e10cSrcweir static ::rtl::OUString saImplName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( #classname ) ); \ 151*cdf0e10cSrcweir return saImplName; \ 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir // ---------------------------------------------------------------------------- 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir /** Helper macro to implement the method 'getServiceNames()' for a single 157*cdf0e10cSrcweir service name. 158*cdf0e10cSrcweir */ 159*cdf0e10cSrcweir #define VBAHELPER_IMPL_GETSERVICENAMES( classname, servicename ) \ 160*cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > classname::getServiceNames() \ 161*cdf0e10cSrcweir { \ 162*cdf0e10cSrcweir static css::uno::Sequence< ::rtl::OUString > saServiceNames; \ 163*cdf0e10cSrcweir if( saServiceNames.getLength() == 0 ) \ 164*cdf0e10cSrcweir { \ 165*cdf0e10cSrcweir saServiceNames.realloc( 1 ); \ 166*cdf0e10cSrcweir saServiceNames[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( servicename ) ); \ 167*cdf0e10cSrcweir } \ 168*cdf0e10cSrcweir return saServiceNames; \ 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir // ---------------------------------------------------------------------------- 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir /** Helper macro to declare the methods 'getServiceImplName()' and 174*cdf0e10cSrcweir 'getServiceNames()' of the 'ooo.vba.XHelperInterface' interface in a class 175*cdf0e10cSrcweir declaration. 176*cdf0e10cSrcweir */ 177*cdf0e10cSrcweir #define VBAHELPER_DECL_XHELPERINTERFACE \ 178*cdf0e10cSrcweir virtual ::rtl::OUString& getServiceImplName(); \ 179*cdf0e10cSrcweir virtual css::uno::Sequence< ::rtl::OUString > getServiceNames(); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir // ---------------------------------------------------------------------------- 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir /** Helper macro to implement the methods 'getServiceImplName()' and 184*cdf0e10cSrcweir 'getServiceNames()' of the 'ooo.vba.XHelperInterface' interface. Will 185*cdf0e10cSrcweir return the class name as service implementation name. 186*cdf0e10cSrcweir */ 187*cdf0e10cSrcweir #define VBAHELPER_IMPL_XHELPERINTERFACE( classname, servicename ) \ 188*cdf0e10cSrcweir VBAHELPER_IMPL_GETSERVICEIMPLNAME( classname ) \ 189*cdf0e10cSrcweir VBAHELPER_IMPL_GETSERVICENAMES( classname, servicename ) 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir // ============================================================================ 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir #endif 194