1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <rtl/ref.hxx>
21 #include <sal/log.hxx>
22 #include <cppuhelper/implbase.hxx>
23 #include <cppuhelper/factory.hxx>
24 #include <cppuhelper/implementationentry.hxx>
25 #include <cppuhelper/supportsservice.hxx>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/accessibility/XMSAAService.hpp>
29 #include <com/sun/star/accessibility/AccessibleRole.hpp>
31 #include <com/sun/star/awt/XExtendedToolkit.hpp>
32 #include <vcl/svapp.hxx>
33 #include <vcl/window.hxx>
38 #include <AccTopWindowListener.hxx>
40 using namespace ::com::sun::star
; // for odk interfaces
41 using namespace ::com::sun::star::uno
; // for basic types
42 using namespace ::com::sun::star::accessibility
;
44 using namespace ::com::sun::star::awt
;
51 class MSAAServiceImpl
: public ::cppu::WeakImplHelper
<
52 XMSAAService
, lang::XServiceInfo
>
55 rtl::Reference
<AccTopWindowListener
> m_pTopWindowListener
;
60 // XComponent - as used by VCL to lifecycle manage this bridge.
61 virtual void SAL_CALL
dispose() override
;
62 virtual void SAL_CALL
addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& ) override
64 virtual void SAL_CALL
removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& ) override
68 virtual sal_Int64 SAL_CALL
getAccObjectPtr(
69 sal_Int64 hWnd
, sal_Int64 lParam
, sal_Int64 wParam
) override
;
70 virtual void SAL_CALL
handleWindowOpened(sal_Int64
) override
;
73 virtual OUString SAL_CALL
getImplementationName() override
;
74 virtual sal_Bool SAL_CALL
supportsService( OUString
const & serviceName
) override
;
75 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
81 * Implementation of getAccObjectPtr.
83 * @return Com interface.
85 sal_Int64
MSAAServiceImpl::getAccObjectPtr(
86 sal_Int64 hWnd
, sal_Int64 lParam
, sal_Int64 wParam
)
88 // tdf#155794: this must complete without taking SolarMutex
90 if (!m_pTopWindowListener
.is())
94 return m_pTopWindowListener
->GetMSComPtr(hWnd
, lParam
, wParam
);
98 * Implementation of handleWindowOpened, the method will be invoked when a
99 * top window is opened and AT starts up.
103 void MSAAServiceImpl::handleWindowOpened(sal_Int64 nAcc
)
107 SAL_INFO( "iacc2", "Window opened " << nAcc
);
109 if (m_pTopWindowListener
.is() && nAcc
)
111 m_pTopWindowListener
->HandleWindowOpened(
112 static_cast<vcl::Window
*>(
113 reinterpret_cast<void*>(nAcc
)));
117 OUString
MSAAServiceImpl::getImplementationName()
119 return "com.sun.star.accessibility.my_sc_implementation.MSAAService";
123 * Implementation of XServiceInfo, return support service name.
124 * @param Service name.
125 * @return If the service name is supported.
127 sal_Bool
MSAAServiceImpl::supportsService( OUString
const & serviceName
)
129 return cppu::supportsService(this, serviceName
);
133 * Implementation of XServiceInfo, return all service names.
135 * @return service name sequence.
137 Sequence
< OUString
> MSAAServiceImpl::getSupportedServiceNames()
139 return { "com.sun.star.accessibility.MSAAService" };
142 static void AccessBridgeHandleExistingWindow(const Reference
< XMSAAService
>& xAccMgr
,
143 vcl::Window
* pWindow
)
145 assert(xAccMgr
.is());
147 xAccMgr
->handleWindowOpened(reinterpret_cast<sal_Int64
>(pWindow
));
151 * Setup and notify the OS of Accessible peers for all existing windows.
153 static void AccessBridgeUpdateOldTopWindows( const Reference
< XMSAAService
> &xAccMgr
)
155 tools::Long nTopWindowCount
= Application::GetTopWindowCount();
156 for (tools::Long i
= 0; i
< nTopWindowCount
; i
++)
158 vcl::Window
* pTopWindow
= Application::GetTopWindow( i
);
159 css::uno::Reference
< css::accessibility::XAccessible
> xAccessible
= pTopWindow
->GetAccessible();
160 if ( xAccessible
.is() )
162 css::uno::Reference
< css::accessibility::XAccessibleContext
> xAC( xAccessible
->getAccessibleContext() );
165 if ( !xAC
->getAccessibleName().isEmpty() )
166 AccessBridgeHandleExistingWindow(xAccMgr
, pTopWindow
);
172 MSAAServiceImpl::MSAAServiceImpl()
174 Reference
< XExtendedToolkit
> xToolkit(Application::GetVCLToolkit(), UNO_QUERY
);
178 m_pTopWindowListener
.set(new AccTopWindowListener());
179 Reference
<XTopWindowListener
> const xRef(m_pTopWindowListener
);
180 xToolkit
->addTopWindowListener( xRef
);
181 SAL_INFO( "iacc2", "successfully connected to the toolkit event hose" );
184 SAL_WARN( "iacc2", "No VCL toolkit interface to listen to for events");
187 void MSAAServiceImpl::dispose()
191 // As all folders and streams contain references to their parents,
192 // we must remove these references so that they will be deleted when
193 // the hash_map of the root folder is cleared, releasing all subfolders
194 // and substreams which in turn release theirs, etc. When xRootFolder is
195 // released when this destructor completes, the folder tree should be
196 // deleted fully (and automagically).
197 m_pTopWindowListener
.clear();
200 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
201 winaccessibility_MSAAServiceImpl_get_implementation(
202 css::uno::XComponentContext
* , css::uno::Sequence
<css::uno::Any
> const&)
204 Reference
< XMSAAService
> xAccMgr( new MSAAServiceImpl() );
206 AccessBridgeUpdateOldTopWindows( xAccMgr
);
208 SAL_INFO("iacc2", "Created new IAccessible2 service impl.");
211 return xAccMgr
.get();
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */