1*5fdc4257SSteve Yin /************************************************************************* 2*5fdc4257SSteve Yin * 3*5fdc4257SSteve Yin * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*5fdc4257SSteve Yin * 5*5fdc4257SSteve Yin * Copyright IBM Corporation 2010. 6*5fdc4257SSteve Yin * Copyright 2000, 2010 Oracle and/or its affiliates. 7*5fdc4257SSteve Yin * 8*5fdc4257SSteve Yin * OpenOffice.org - a multi-platform office productivity suite 9*5fdc4257SSteve Yin * 10*5fdc4257SSteve Yin * This file is part of OpenOffice.org. 11*5fdc4257SSteve Yin * 12*5fdc4257SSteve Yin * OpenOffice.org is free software: you can redistribute it and/or modify 13*5fdc4257SSteve Yin * it under the terms of the GNU Lesser General Public License version 3 14*5fdc4257SSteve Yin * only, as published by the Free Software Foundation. 15*5fdc4257SSteve Yin * 16*5fdc4257SSteve Yin * OpenOffice.org is distributed in the hope that it will be useful, 17*5fdc4257SSteve Yin * but WITHOUT ANY WARRANTY; without even the implied warranty of 18*5fdc4257SSteve Yin * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19*5fdc4257SSteve Yin * GNU Lesser General Public License version 3 for more details 20*5fdc4257SSteve Yin * (a copy is included in the LICENSE file that accompanied this code). 21*5fdc4257SSteve Yin * 22*5fdc4257SSteve Yin * You should have received a copy of the GNU Lesser General Public License 23*5fdc4257SSteve Yin * version 3 along with OpenOffice.org. If not, see 24*5fdc4257SSteve Yin * <http://www.openoffice.org/license.html> 25*5fdc4257SSteve Yin * for a copy of the LGPLv3 License. 26*5fdc4257SSteve Yin * 27*5fdc4257SSteve Yin ************************************************************************/ 28*5fdc4257SSteve Yin 29*5fdc4257SSteve Yin #include <cppuhelper/implbase3.hxx> 30*5fdc4257SSteve Yin #include <cppuhelper/factory.hxx> 31*5fdc4257SSteve Yin #include <cppuhelper/implementationentry.hxx> 32*5fdc4257SSteve Yin 33*5fdc4257SSteve Yin #include <com/sun/star/lang/XServiceInfo.hpp> 34*5fdc4257SSteve Yin #include <com/sun/star/lang/XInitialization.hpp> 35*5fdc4257SSteve Yin #include <com/sun/star/lang/IllegalArgumentException.hpp> 36*5fdc4257SSteve Yin #include <com/sun/star/accessibility/XMSAAService.hpp> 37*5fdc4257SSteve Yin 38*5fdc4257SSteve Yin #include <com/sun/star/awt/XExtendedToolkit.hpp> 39*5fdc4257SSteve Yin #include <vcl/svapp.hxx> 40*5fdc4257SSteve Yin 41*5fdc4257SSteve Yin using namespace ::rtl; // for OUString 42*5fdc4257SSteve Yin using namespace ::com::sun::star; // for odk interfaces 43*5fdc4257SSteve Yin using namespace ::com::sun::star::uno; // for basic types 44*5fdc4257SSteve Yin using namespace ::com::sun::star::accessibility; 45*5fdc4257SSteve Yin 46*5fdc4257SSteve Yin using namespace ::com::sun::star::awt; 47*5fdc4257SSteve Yin 48*5fdc4257SSteve Yin typedef sal_Int32 HWND; 49*5fdc4257SSteve Yin 50*5fdc4257SSteve Yin #include "AccTopWindowListener.hxx" 51*5fdc4257SSteve Yin #include "g_msacc.hxx" 52*5fdc4257SSteve Yin 53*5fdc4257SSteve Yin extern void FreeTopWindowListener(); 54*5fdc4257SSteve Yin extern long GetMSComPtr(long hWnd, long lParam, long wParam); 55*5fdc4257SSteve Yin extern void handleWindowOpened_impl( long pAcc); 56*5fdc4257SSteve Yin 57*5fdc4257SSteve Yin 58*5fdc4257SSteve Yin namespace my_sc_impl 59*5fdc4257SSteve Yin { 60*5fdc4257SSteve Yin 61*5fdc4257SSteve Yin extern Sequence< OUString > SAL_CALL getSupportedServiceNames_MSAAServiceImpl(); 62*5fdc4257SSteve Yin extern OUString SAL_CALL getImplementationName_MSAAServiceImpl(); 63*5fdc4257SSteve Yin extern Reference< XInterface > SAL_CALL create_MSAAServiceImpl( 64*5fdc4257SSteve Yin Reference< XComponentContext > const & xContext ) 65*5fdc4257SSteve Yin SAL_THROW( () ); 66*5fdc4257SSteve Yin /** 67*5fdc4257SSteve Yin * Method that returns the service name. 68*5fdc4257SSteve Yin * @param 69*5fdc4257SSteve Yin * @return Name sequence. 70*5fdc4257SSteve Yin */ 71*5fdc4257SSteve Yin static Sequence< OUString > getSupportedServiceNames_MSAAServiceImpl() 72*5fdc4257SSteve Yin { 73*5fdc4257SSteve Yin static Sequence < OUString > *pNames = 0; 74*5fdc4257SSteve Yin if( ! pNames ) 75*5fdc4257SSteve Yin { 76*5fdc4257SSteve Yin // MutexGuard guard( Mutex::getGlobalMutex() ); 77*5fdc4257SSteve Yin if( !pNames ) 78*5fdc4257SSteve Yin { 79*5fdc4257SSteve Yin static Sequence< OUString > seqNames(1); 80*5fdc4257SSteve Yin seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.MSAAService")); 81*5fdc4257SSteve Yin pNames = &seqNames; 82*5fdc4257SSteve Yin } 83*5fdc4257SSteve Yin } 84*5fdc4257SSteve Yin return *pNames; 85*5fdc4257SSteve Yin } 86*5fdc4257SSteve Yin 87*5fdc4257SSteve Yin /** 88*5fdc4257SSteve Yin * Method that returns the service name. 89*5fdc4257SSteve Yin * @param 90*5fdc4257SSteve Yin * @return Name sequence. 91*5fdc4257SSteve Yin */ 92*5fdc4257SSteve Yin static OUString getImplementationName_MSAAServiceImpl() 93*5fdc4257SSteve Yin { 94*5fdc4257SSteve Yin static OUString *pImplName = 0; 95*5fdc4257SSteve Yin if( ! pImplName ) 96*5fdc4257SSteve Yin { 97*5fdc4257SSteve Yin // MutexGuard guard( Mutex::getGlobalMutex() ); 98*5fdc4257SSteve Yin if( ! pImplName ) 99*5fdc4257SSteve Yin { 100*5fdc4257SSteve Yin static OUString implName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.my_sc_implementation.MSAAService") ); 101*5fdc4257SSteve Yin pImplName = &implName; 102*5fdc4257SSteve Yin } 103*5fdc4257SSteve Yin } 104*5fdc4257SSteve Yin return *pImplName; 105*5fdc4257SSteve Yin } 106*5fdc4257SSteve Yin 107*5fdc4257SSteve Yin class MSAAServiceImpl : public ::cppu::WeakImplHelper3< 108*5fdc4257SSteve Yin XMSAAService, lang::XServiceInfo, lang::XInitialization > 109*5fdc4257SSteve Yin { 110*5fdc4257SSteve Yin OUString m_arg; 111*5fdc4257SSteve Yin public: 112*5fdc4257SSteve Yin // focus on three given interfaces, 113*5fdc4257SSteve Yin // no need to implement XInterface, XTypeProvider, XWeak 114*5fdc4257SSteve Yin MSAAServiceImpl (); 115*5fdc4257SSteve Yin virtual ~MSAAServiceImpl( void ); 116*5fdc4257SSteve Yin // XInitialization will be called upon createInstanceWithArguments[AndContext]() 117*5fdc4257SSteve Yin virtual void SAL_CALL initialize( Sequence< Any > const & args ) 118*5fdc4257SSteve Yin throw (Exception); 119*5fdc4257SSteve Yin // XMSAAService 120*5fdc4257SSteve Yin virtual sal_Int32 SAL_CALL getAccObjectPtr (long hWnd, long lParam, long wParam) 121*5fdc4257SSteve Yin throw (RuntimeException); 122*5fdc4257SSteve Yin virtual void SAL_CALL handleWindowOpened(sal_Int32) 123*5fdc4257SSteve Yin throw (RuntimeException); 124*5fdc4257SSteve Yin // XServiceInfo 125*5fdc4257SSteve Yin virtual OUString SAL_CALL getImplementationName() 126*5fdc4257SSteve Yin throw (RuntimeException); 127*5fdc4257SSteve Yin virtual sal_Bool SAL_CALL supportsService( OUString const & serviceName ) 128*5fdc4257SSteve Yin throw (RuntimeException); 129*5fdc4257SSteve Yin virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() 130*5fdc4257SSteve Yin throw (RuntimeException); 131*5fdc4257SSteve Yin }; 132*5fdc4257SSteve Yin 133*5fdc4257SSteve Yin /** 134*5fdc4257SSteve Yin * Implemention of XInitialization. 135*5fdc4257SSteve Yin * @param 136*5fdc4257SSteve Yin * @return. 137*5fdc4257SSteve Yin */ 138*5fdc4257SSteve Yin void MSAAServiceImpl::initialize( Sequence< Any > const & args ) throw (Exception) 139*5fdc4257SSteve Yin { 140*5fdc4257SSteve Yin if (1 != args.getLength()) 141*5fdc4257SSteve Yin { 142*5fdc4257SSteve Yin throw lang::IllegalArgumentException( 143*5fdc4257SSteve Yin OUString( RTL_CONSTASCII_USTRINGPARAM("give a string instanciating this component!") ), 144*5fdc4257SSteve Yin (::cppu::OWeakObject *)this, // resolve to XInterface reference 145*5fdc4257SSteve Yin 0 ); // argument pos 146*5fdc4257SSteve Yin } 147*5fdc4257SSteve Yin if (! (args[ 0 ] >>= m_arg)) 148*5fdc4257SSteve Yin { 149*5fdc4257SSteve Yin throw lang::IllegalArgumentException( 150*5fdc4257SSteve Yin OUString( RTL_CONSTASCII_USTRINGPARAM("no string given as argument!") ), 151*5fdc4257SSteve Yin (::cppu::OWeakObject *)this, // resolve to XInterface reference 152*5fdc4257SSteve Yin 0 ); // argument pos 153*5fdc4257SSteve Yin } 154*5fdc4257SSteve Yin } 155*5fdc4257SSteve Yin 156*5fdc4257SSteve Yin /** 157*5fdc4257SSteve Yin * Implemention of getAccObjectPtr. 158*5fdc4257SSteve Yin * @param 159*5fdc4257SSteve Yin * @return Com interface. 160*5fdc4257SSteve Yin */ 161*5fdc4257SSteve Yin sal_Int32 MSAAServiceImpl::getAccObjectPtr ( long hWnd, long lParam, long wParam) throw (RuntimeException) 162*5fdc4257SSteve Yin { 163*5fdc4257SSteve Yin return GetMSComPtr(hWnd, lParam, wParam); 164*5fdc4257SSteve Yin } 165*5fdc4257SSteve Yin 166*5fdc4257SSteve Yin /** 167*5fdc4257SSteve Yin * Implemention of handleWindowOpened,the method will be invoked when a top window 168*5fdc4257SSteve Yin * opened and AT starts up. 169*5fdc4257SSteve Yin * @param 170*5fdc4257SSteve Yin * @return 171*5fdc4257SSteve Yin */ 172*5fdc4257SSteve Yin void MSAAServiceImpl::handleWindowOpened( sal_Int32 pAcc) 173*5fdc4257SSteve Yin { 174*5fdc4257SSteve Yin handleWindowOpened_impl(pAcc); 175*5fdc4257SSteve Yin } 176*5fdc4257SSteve Yin 177*5fdc4257SSteve Yin /** 178*5fdc4257SSteve Yin * Implemention of XServiceInfo. 179*5fdc4257SSteve Yin * @param 180*5fdc4257SSteve Yin * @return Implementataion name. 181*5fdc4257SSteve Yin */ 182*5fdc4257SSteve Yin OUString MSAAServiceImpl::getImplementationName() throw (RuntimeException) 183*5fdc4257SSteve Yin { 184*5fdc4257SSteve Yin // unique implementation name 185*5fdc4257SSteve Yin return OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.my_sc_impl.MSAAService") ); 186*5fdc4257SSteve Yin } 187*5fdc4257SSteve Yin 188*5fdc4257SSteve Yin /** 189*5fdc4257SSteve Yin * Implemention of XServiceInfo,return support service name. 190*5fdc4257SSteve Yin * @param Service name. 191*5fdc4257SSteve Yin * @return If the service name is supported. 192*5fdc4257SSteve Yin */ 193*5fdc4257SSteve Yin sal_Bool MSAAServiceImpl::supportsService( OUString const & serviceName ) throw (RuntimeException) 194*5fdc4257SSteve Yin { 195*5fdc4257SSteve Yin // this object only supports one service, so the test is simple 196*5fdc4257SSteve Yin return serviceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.accessibility.MSAAService") ); 197*5fdc4257SSteve Yin } 198*5fdc4257SSteve Yin 199*5fdc4257SSteve Yin /** 200*5fdc4257SSteve Yin * Implemention of XServiceInfo,return all service names. 201*5fdc4257SSteve Yin * @param. 202*5fdc4257SSteve Yin * @return service name sequence. 203*5fdc4257SSteve Yin */ 204*5fdc4257SSteve Yin Sequence< OUString > MSAAServiceImpl::getSupportedServiceNames() throw (RuntimeException) 205*5fdc4257SSteve Yin { 206*5fdc4257SSteve Yin return getSupportedServiceNames_MSAAServiceImpl(); 207*5fdc4257SSteve Yin } 208*5fdc4257SSteve Yin 209*5fdc4257SSteve Yin /** 210*5fdc4257SSteve Yin * Static method that can create an entity of our MSAA Service 211*5fdc4257SSteve Yin * @param xContext No use here. 212*5fdc4257SSteve Yin * @return The object interface. 213*5fdc4257SSteve Yin */ 214*5fdc4257SSteve Yin Reference< XInterface > SAL_CALL create_MSAAServiceImpl( Reference< XComponentContext > const & /*xContext*/ ) SAL_THROW( () ) 215*5fdc4257SSteve Yin { 216*5fdc4257SSteve Yin MSAAServiceImpl* xxx = new MSAAServiceImpl(); 217*5fdc4257SSteve Yin //return static_cast< lang::XTypeProvider * >( xxx ); 218*5fdc4257SSteve Yin Reference< XMSAAService > p( xxx ); 219*5fdc4257SSteve Yin return p; 220*5fdc4257SSteve Yin } 221*5fdc4257SSteve Yin 222*5fdc4257SSteve Yin /** 223*5fdc4257SSteve Yin * Constructor. 224*5fdc4257SSteve Yin * @param 225*5fdc4257SSteve Yin * @return 226*5fdc4257SSteve Yin */ 227*5fdc4257SSteve Yin MSAAServiceImpl::MSAAServiceImpl() 228*5fdc4257SSteve Yin { 229*5fdc4257SSteve Yin Reference< XExtendedToolkit > xToolkit = 230*5fdc4257SSteve Yin Reference< XExtendedToolkit >(Application::GetVCLToolkit(), UNO_QUERY); 231*5fdc4257SSteve Yin 232*5fdc4257SSteve Yin if(xToolkit.is()) 233*5fdc4257SSteve Yin { 234*5fdc4257SSteve Yin AccTopWindowListener *accListener; 235*5fdc4257SSteve Yin accListener = new AccTopWindowListener(); 236*5fdc4257SSteve Yin g_pTop = accListener; 237*5fdc4257SSteve Yin Reference< XTopWindowListener> x(accListener); 238*5fdc4257SSteve Yin xToolkit->addTopWindowListener(x); 239*5fdc4257SSteve Yin } 240*5fdc4257SSteve Yin } 241*5fdc4257SSteve Yin 242*5fdc4257SSteve Yin /** 243*5fdc4257SSteve Yin * Static method that can create an entity of our MSAA Service 244*5fdc4257SSteve Yin * @param Destructor 245*5fdc4257SSteve Yin * @return 246*5fdc4257SSteve Yin */ 247*5fdc4257SSteve Yin MSAAServiceImpl::~MSAAServiceImpl() 248*5fdc4257SSteve Yin { 249*5fdc4257SSteve Yin 250*5fdc4257SSteve Yin // As all folders and streams contain references to their parents, 251*5fdc4257SSteve Yin // we must remove these references so that they will be deleted when 252*5fdc4257SSteve Yin // the hash_map of the root folder is cleared, releasing all subfolders 253*5fdc4257SSteve Yin // and substreams which in turn release theirs, etc. When xRootFolder is 254*5fdc4257SSteve Yin // released when this destructor completes, the folder tree should be 255*5fdc4257SSteve Yin // deleted fully (and automagically). 256*5fdc4257SSteve Yin FreeTopWindowListener(); 257*5fdc4257SSteve Yin 258*5fdc4257SSteve Yin 259*5fdc4257SSteve Yin } 260*5fdc4257SSteve Yin 261*5fdc4257SSteve Yin } 262*5fdc4257SSteve Yin 263*5fdc4257SSteve Yin /* shared lib exports implemented without helpers in service_impl1.cxx */ 264*5fdc4257SSteve Yin namespace my_sc_impl 265*5fdc4257SSteve Yin { 266*5fdc4257SSteve Yin static struct ::cppu::ImplementationEntry s_component_entries [] = 267*5fdc4257SSteve Yin { 268*5fdc4257SSteve Yin { 269*5fdc4257SSteve Yin create_MSAAServiceImpl, getImplementationName_MSAAServiceImpl, 270*5fdc4257SSteve Yin getSupportedServiceNames_MSAAServiceImpl, ::cppu::createSingleComponentFactory, 271*5fdc4257SSteve Yin 0, 0 272*5fdc4257SSteve Yin }, 273*5fdc4257SSteve Yin { 274*5fdc4257SSteve Yin create_MSAAServiceImpl, getImplementationName_MSAAServiceImpl, 275*5fdc4257SSteve Yin getSupportedServiceNames_MSAAServiceImpl, ::cppu::createSingleComponentFactory, 276*5fdc4257SSteve Yin 0, 0 277*5fdc4257SSteve Yin }, 278*5fdc4257SSteve Yin { 0, 0, 0, 0, 0, 0 } 279*5fdc4257SSteve Yin }; 280*5fdc4257SSteve Yin } 281*5fdc4257SSteve Yin 282*5fdc4257SSteve Yin extern "C" 283*5fdc4257SSteve Yin { 284*5fdc4257SSteve Yin void SAL_CALL component_getImplementationEnvironment( 285*5fdc4257SSteve Yin sal_Char const ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ ) 286*5fdc4257SSteve Yin { 287*5fdc4257SSteve Yin *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 288*5fdc4257SSteve Yin } 289*5fdc4257SSteve Yin /* 290*5fdc4257SSteve Yin sal_Bool SAL_CALL component_writeInfo( 291*5fdc4257SSteve Yin lang::XMultiServiceFactory * xMgr, registry::XRegistryKey * xRegistry ) 292*5fdc4257SSteve Yin { 293*5fdc4257SSteve Yin return ::cppu::component_writeInfoHelper( 294*5fdc4257SSteve Yin xMgr, xRegistry, ::my_sc_impl::s_component_entries ); 295*5fdc4257SSteve Yin } 296*5fdc4257SSteve Yin */ 297*5fdc4257SSteve Yin void * SAL_CALL component_getFactory( 298*5fdc4257SSteve Yin sal_Char const * implName, lang::XMultiServiceFactory * xMgr, 299*5fdc4257SSteve Yin registry::XRegistryKey * xRegistry ) 300*5fdc4257SSteve Yin { 301*5fdc4257SSteve Yin return ::cppu::component_getFactoryHelper( 302*5fdc4257SSteve Yin implName, xMgr, xRegistry, ::my_sc_impl::s_component_entries ); 303*5fdc4257SSteve Yin } 304*5fdc4257SSteve Yin } 305