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