1*3a700b0aSSteve Yin /************************************************************** 25fdc4257SSteve Yin * 3*3a700b0aSSteve Yin * Licensed to the Apache Software Foundation (ASF) under one 4*3a700b0aSSteve Yin * or more contributor license agreements. See the NOTICE file 5*3a700b0aSSteve Yin * distributed with this work for additional information 6*3a700b0aSSteve Yin * regarding copyright ownership. The ASF licenses this file 7*3a700b0aSSteve Yin * to you under the Apache License, Version 2.0 (the 8*3a700b0aSSteve Yin * "License"); you may not use this file except in compliance 9*3a700b0aSSteve Yin * with the License. You may obtain a copy of the License at 105fdc4257SSteve Yin * 11*3a700b0aSSteve Yin * http://www.apache.org/licenses/LICENSE-2.0 125fdc4257SSteve Yin * 13*3a700b0aSSteve Yin * Unless required by applicable law or agreed to in writing, 14*3a700b0aSSteve Yin * software distributed under the License is distributed on an 15*3a700b0aSSteve Yin * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*3a700b0aSSteve Yin * KIND, either express or implied. See the License for the 17*3a700b0aSSteve Yin * specific language governing permissions and limitations 18*3a700b0aSSteve Yin * under the License. 195fdc4257SSteve Yin * 20*3a700b0aSSteve Yin *************************************************************/ 215fdc4257SSteve Yin 225fdc4257SSteve Yin #include <cppuhelper/implbase3.hxx> 235fdc4257SSteve Yin #include <cppuhelper/factory.hxx> 245fdc4257SSteve Yin #include <cppuhelper/implementationentry.hxx> 255fdc4257SSteve Yin 265fdc4257SSteve Yin #include <com/sun/star/lang/XServiceInfo.hpp> 275fdc4257SSteve Yin #include <com/sun/star/lang/XInitialization.hpp> 285fdc4257SSteve Yin #include <com/sun/star/lang/IllegalArgumentException.hpp> 295fdc4257SSteve Yin #include <com/sun/star/accessibility/XMSAAService.hpp> 305fdc4257SSteve Yin 315fdc4257SSteve Yin #include <com/sun/star/awt/XExtendedToolkit.hpp> 325fdc4257SSteve Yin #include <vcl/svapp.hxx> 335fdc4257SSteve Yin 345fdc4257SSteve Yin using namespace ::rtl; // for OUString 355fdc4257SSteve Yin using namespace ::com::sun::star; // for odk interfaces 365fdc4257SSteve Yin using namespace ::com::sun::star::uno; // for basic types 375fdc4257SSteve Yin using namespace ::com::sun::star::accessibility; 385fdc4257SSteve Yin 395fdc4257SSteve Yin using namespace ::com::sun::star::awt; 405fdc4257SSteve Yin 415fdc4257SSteve Yin typedef sal_Int32 HWND; 425fdc4257SSteve Yin 435fdc4257SSteve Yin #include "AccTopWindowListener.hxx" 445fdc4257SSteve Yin #include "g_msacc.hxx" 455fdc4257SSteve Yin 465fdc4257SSteve Yin extern void FreeTopWindowListener(); 475fdc4257SSteve Yin extern long GetMSComPtr(long hWnd, long lParam, long wParam); 485fdc4257SSteve Yin extern void handleWindowOpened_impl( long pAcc); 495fdc4257SSteve Yin 505fdc4257SSteve Yin 515fdc4257SSteve Yin namespace my_sc_impl 525fdc4257SSteve Yin { 535fdc4257SSteve Yin 545fdc4257SSteve Yin extern Sequence< OUString > SAL_CALL getSupportedServiceNames_MSAAServiceImpl(); 555fdc4257SSteve Yin extern OUString SAL_CALL getImplementationName_MSAAServiceImpl(); 565fdc4257SSteve Yin extern Reference< XInterface > SAL_CALL create_MSAAServiceImpl( 575fdc4257SSteve Yin Reference< XComponentContext > const & xContext ) 585fdc4257SSteve Yin SAL_THROW( () ); 595fdc4257SSteve Yin /** 605fdc4257SSteve Yin * Method that returns the service name. 615fdc4257SSteve Yin * @param 625fdc4257SSteve Yin * @return Name sequence. 635fdc4257SSteve Yin */ 645fdc4257SSteve Yin static Sequence< OUString > getSupportedServiceNames_MSAAServiceImpl() 655fdc4257SSteve Yin { 665fdc4257SSteve Yin static Sequence < OUString > *pNames = 0; 675fdc4257SSteve Yin if( ! pNames ) 685fdc4257SSteve Yin { 695fdc4257SSteve Yin // MutexGuard guard( Mutex::getGlobalMutex() ); 705fdc4257SSteve Yin if( !pNames ) 715fdc4257SSteve Yin { 725fdc4257SSteve Yin static Sequence< OUString > seqNames(1); 735fdc4257SSteve Yin seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.MSAAService")); 745fdc4257SSteve Yin pNames = &seqNames; 755fdc4257SSteve Yin } 765fdc4257SSteve Yin } 775fdc4257SSteve Yin return *pNames; 785fdc4257SSteve Yin } 795fdc4257SSteve Yin 805fdc4257SSteve Yin /** 815fdc4257SSteve Yin * Method that returns the service name. 825fdc4257SSteve Yin * @param 835fdc4257SSteve Yin * @return Name sequence. 845fdc4257SSteve Yin */ 855fdc4257SSteve Yin static OUString getImplementationName_MSAAServiceImpl() 865fdc4257SSteve Yin { 875fdc4257SSteve Yin static OUString *pImplName = 0; 885fdc4257SSteve Yin if( ! pImplName ) 895fdc4257SSteve Yin { 905fdc4257SSteve Yin // MutexGuard guard( Mutex::getGlobalMutex() ); 915fdc4257SSteve Yin if( ! pImplName ) 925fdc4257SSteve Yin { 935fdc4257SSteve Yin static OUString implName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.my_sc_implementation.MSAAService") ); 945fdc4257SSteve Yin pImplName = &implName; 955fdc4257SSteve Yin } 965fdc4257SSteve Yin } 975fdc4257SSteve Yin return *pImplName; 985fdc4257SSteve Yin } 995fdc4257SSteve Yin 1005fdc4257SSteve Yin class MSAAServiceImpl : public ::cppu::WeakImplHelper3< 1015fdc4257SSteve Yin XMSAAService, lang::XServiceInfo, lang::XInitialization > 1025fdc4257SSteve Yin { 1035fdc4257SSteve Yin OUString m_arg; 1045fdc4257SSteve Yin public: 1055fdc4257SSteve Yin // focus on three given interfaces, 1065fdc4257SSteve Yin // no need to implement XInterface, XTypeProvider, XWeak 1075fdc4257SSteve Yin MSAAServiceImpl (); 1085fdc4257SSteve Yin virtual ~MSAAServiceImpl( void ); 1095fdc4257SSteve Yin // XInitialization will be called upon createInstanceWithArguments[AndContext]() 1105fdc4257SSteve Yin virtual void SAL_CALL initialize( Sequence< Any > const & args ) 1115fdc4257SSteve Yin throw (Exception); 1125fdc4257SSteve Yin // XMSAAService 1135fdc4257SSteve Yin virtual sal_Int32 SAL_CALL getAccObjectPtr (long hWnd, long lParam, long wParam) 1145fdc4257SSteve Yin throw (RuntimeException); 1155fdc4257SSteve Yin virtual void SAL_CALL handleWindowOpened(sal_Int32) 1165fdc4257SSteve Yin throw (RuntimeException); 1175fdc4257SSteve Yin // XServiceInfo 1185fdc4257SSteve Yin virtual OUString SAL_CALL getImplementationName() 1195fdc4257SSteve Yin throw (RuntimeException); 1205fdc4257SSteve Yin virtual sal_Bool SAL_CALL supportsService( OUString const & serviceName ) 1215fdc4257SSteve Yin throw (RuntimeException); 1225fdc4257SSteve Yin virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() 1235fdc4257SSteve Yin throw (RuntimeException); 1245fdc4257SSteve Yin }; 1255fdc4257SSteve Yin 1265fdc4257SSteve Yin /** 1275fdc4257SSteve Yin * Implemention of XInitialization. 1285fdc4257SSteve Yin * @param 1295fdc4257SSteve Yin * @return. 1305fdc4257SSteve Yin */ 1315fdc4257SSteve Yin void MSAAServiceImpl::initialize( Sequence< Any > const & args ) throw (Exception) 1325fdc4257SSteve Yin { 1335fdc4257SSteve Yin if (1 != args.getLength()) 1345fdc4257SSteve Yin { 1355fdc4257SSteve Yin throw lang::IllegalArgumentException( 1365fdc4257SSteve Yin OUString( RTL_CONSTASCII_USTRINGPARAM("give a string instanciating this component!") ), 1375fdc4257SSteve Yin (::cppu::OWeakObject *)this, // resolve to XInterface reference 1385fdc4257SSteve Yin 0 ); // argument pos 1395fdc4257SSteve Yin } 1405fdc4257SSteve Yin if (! (args[ 0 ] >>= m_arg)) 1415fdc4257SSteve Yin { 1425fdc4257SSteve Yin throw lang::IllegalArgumentException( 1435fdc4257SSteve Yin OUString( RTL_CONSTASCII_USTRINGPARAM("no string given as argument!") ), 1445fdc4257SSteve Yin (::cppu::OWeakObject *)this, // resolve to XInterface reference 1455fdc4257SSteve Yin 0 ); // argument pos 1465fdc4257SSteve Yin } 1475fdc4257SSteve Yin } 1485fdc4257SSteve Yin 1495fdc4257SSteve Yin /** 1505fdc4257SSteve Yin * Implemention of getAccObjectPtr. 1515fdc4257SSteve Yin * @param 1525fdc4257SSteve Yin * @return Com interface. 1535fdc4257SSteve Yin */ 1545fdc4257SSteve Yin sal_Int32 MSAAServiceImpl::getAccObjectPtr ( long hWnd, long lParam, long wParam) throw (RuntimeException) 1555fdc4257SSteve Yin { 1565fdc4257SSteve Yin return GetMSComPtr(hWnd, lParam, wParam); 1575fdc4257SSteve Yin } 1585fdc4257SSteve Yin 1595fdc4257SSteve Yin /** 1605fdc4257SSteve Yin * Implemention of handleWindowOpened,the method will be invoked when a top window 1615fdc4257SSteve Yin * opened and AT starts up. 1625fdc4257SSteve Yin * @param 1635fdc4257SSteve Yin * @return 1645fdc4257SSteve Yin */ 1655fdc4257SSteve Yin void MSAAServiceImpl::handleWindowOpened( sal_Int32 pAcc) 1665fdc4257SSteve Yin { 1675fdc4257SSteve Yin handleWindowOpened_impl(pAcc); 1685fdc4257SSteve Yin } 1695fdc4257SSteve Yin 1705fdc4257SSteve Yin /** 1715fdc4257SSteve Yin * Implemention of XServiceInfo. 1725fdc4257SSteve Yin * @param 1735fdc4257SSteve Yin * @return Implementataion name. 1745fdc4257SSteve Yin */ 1755fdc4257SSteve Yin OUString MSAAServiceImpl::getImplementationName() throw (RuntimeException) 1765fdc4257SSteve Yin { 1775fdc4257SSteve Yin // unique implementation name 1785fdc4257SSteve Yin return OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.my_sc_impl.MSAAService") ); 1795fdc4257SSteve Yin } 1805fdc4257SSteve Yin 1815fdc4257SSteve Yin /** 1825fdc4257SSteve Yin * Implemention of XServiceInfo,return support service name. 1835fdc4257SSteve Yin * @param Service name. 1845fdc4257SSteve Yin * @return If the service name is supported. 1855fdc4257SSteve Yin */ 1865fdc4257SSteve Yin sal_Bool MSAAServiceImpl::supportsService( OUString const & serviceName ) throw (RuntimeException) 1875fdc4257SSteve Yin { 1885fdc4257SSteve Yin // this object only supports one service, so the test is simple 1895fdc4257SSteve Yin return serviceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.accessibility.MSAAService") ); 1905fdc4257SSteve Yin } 1915fdc4257SSteve Yin 1925fdc4257SSteve Yin /** 1935fdc4257SSteve Yin * Implemention of XServiceInfo,return all service names. 1945fdc4257SSteve Yin * @param. 1955fdc4257SSteve Yin * @return service name sequence. 1965fdc4257SSteve Yin */ 1975fdc4257SSteve Yin Sequence< OUString > MSAAServiceImpl::getSupportedServiceNames() throw (RuntimeException) 1985fdc4257SSteve Yin { 1995fdc4257SSteve Yin return getSupportedServiceNames_MSAAServiceImpl(); 2005fdc4257SSteve Yin } 2015fdc4257SSteve Yin 2025fdc4257SSteve Yin /** 2035fdc4257SSteve Yin * Static method that can create an entity of our MSAA Service 2045fdc4257SSteve Yin * @param xContext No use here. 2055fdc4257SSteve Yin * @return The object interface. 2065fdc4257SSteve Yin */ 2075fdc4257SSteve Yin Reference< XInterface > SAL_CALL create_MSAAServiceImpl( Reference< XComponentContext > const & /*xContext*/ ) SAL_THROW( () ) 2085fdc4257SSteve Yin { 2095fdc4257SSteve Yin MSAAServiceImpl* xxx = new MSAAServiceImpl(); 2105fdc4257SSteve Yin //return static_cast< lang::XTypeProvider * >( xxx ); 2115fdc4257SSteve Yin Reference< XMSAAService > p( xxx ); 2125fdc4257SSteve Yin return p; 2135fdc4257SSteve Yin } 2145fdc4257SSteve Yin 2155fdc4257SSteve Yin /** 2165fdc4257SSteve Yin * Constructor. 2175fdc4257SSteve Yin * @param 2185fdc4257SSteve Yin * @return 2195fdc4257SSteve Yin */ 2205fdc4257SSteve Yin MSAAServiceImpl::MSAAServiceImpl() 2215fdc4257SSteve Yin { 2225fdc4257SSteve Yin Reference< XExtendedToolkit > xToolkit = 2235fdc4257SSteve Yin Reference< XExtendedToolkit >(Application::GetVCLToolkit(), UNO_QUERY); 2245fdc4257SSteve Yin 2255fdc4257SSteve Yin if(xToolkit.is()) 2265fdc4257SSteve Yin { 2275fdc4257SSteve Yin AccTopWindowListener *accListener; 2285fdc4257SSteve Yin accListener = new AccTopWindowListener(); 2295fdc4257SSteve Yin g_pTop = accListener; 2305fdc4257SSteve Yin Reference< XTopWindowListener> x(accListener); 2315fdc4257SSteve Yin xToolkit->addTopWindowListener(x); 2325fdc4257SSteve Yin } 2335fdc4257SSteve Yin } 2345fdc4257SSteve Yin 2355fdc4257SSteve Yin /** 2365fdc4257SSteve Yin * Static method that can create an entity of our MSAA Service 2375fdc4257SSteve Yin * @param Destructor 2385fdc4257SSteve Yin * @return 2395fdc4257SSteve Yin */ 2405fdc4257SSteve Yin MSAAServiceImpl::~MSAAServiceImpl() 2415fdc4257SSteve Yin { 2425fdc4257SSteve Yin 2435fdc4257SSteve Yin // As all folders and streams contain references to their parents, 2445fdc4257SSteve Yin // we must remove these references so that they will be deleted when 2455fdc4257SSteve Yin // the hash_map of the root folder is cleared, releasing all subfolders 2465fdc4257SSteve Yin // and substreams which in turn release theirs, etc. When xRootFolder is 2475fdc4257SSteve Yin // released when this destructor completes, the folder tree should be 2485fdc4257SSteve Yin // deleted fully (and automagically). 2495fdc4257SSteve Yin FreeTopWindowListener(); 2505fdc4257SSteve Yin 2515fdc4257SSteve Yin 2525fdc4257SSteve Yin } 2535fdc4257SSteve Yin 2545fdc4257SSteve Yin } 2555fdc4257SSteve Yin 2565fdc4257SSteve Yin /* shared lib exports implemented without helpers in service_impl1.cxx */ 2575fdc4257SSteve Yin namespace my_sc_impl 2585fdc4257SSteve Yin { 2595fdc4257SSteve Yin static struct ::cppu::ImplementationEntry s_component_entries [] = 2605fdc4257SSteve Yin { 2615fdc4257SSteve Yin { 2625fdc4257SSteve Yin create_MSAAServiceImpl, getImplementationName_MSAAServiceImpl, 2635fdc4257SSteve Yin getSupportedServiceNames_MSAAServiceImpl, ::cppu::createSingleComponentFactory, 2645fdc4257SSteve Yin 0, 0 2655fdc4257SSteve Yin }, 2665fdc4257SSteve Yin { 2675fdc4257SSteve Yin create_MSAAServiceImpl, getImplementationName_MSAAServiceImpl, 2685fdc4257SSteve Yin getSupportedServiceNames_MSAAServiceImpl, ::cppu::createSingleComponentFactory, 2695fdc4257SSteve Yin 0, 0 2705fdc4257SSteve Yin }, 2715fdc4257SSteve Yin { 0, 0, 0, 0, 0, 0 } 2725fdc4257SSteve Yin }; 2735fdc4257SSteve Yin } 2745fdc4257SSteve Yin 2755fdc4257SSteve Yin extern "C" 2765fdc4257SSteve Yin { 2775fdc4257SSteve Yin void SAL_CALL component_getImplementationEnvironment( 2785fdc4257SSteve Yin sal_Char const ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ ) 2795fdc4257SSteve Yin { 2805fdc4257SSteve Yin *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 2815fdc4257SSteve Yin } 2825fdc4257SSteve Yin void * SAL_CALL component_getFactory( 2835fdc4257SSteve Yin sal_Char const * implName, lang::XMultiServiceFactory * xMgr, 2845fdc4257SSteve Yin registry::XRegistryKey * xRegistry ) 2855fdc4257SSteve Yin { 2865fdc4257SSteve Yin return ::cppu::component_getFactoryHelper( 2875fdc4257SSteve Yin implName, xMgr, xRegistry, ::my_sc_impl::s_component_entries ); 2885fdc4257SSteve Yin } 2895fdc4257SSteve Yin } 290