fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / winaccessibility / source / service / msaaservice_impl.cxx
blob36de815927c4f7f9506f6b74265e67c350cbddb8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <cppuhelper/implbase2.hxx>
22 #include <cppuhelper/factory.hxx>
23 #include <cppuhelper/implementationentry.hxx>
24 #include <cppuhelper/supportsservice.hxx>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/accessibility/XMSAAService.hpp>
28 #include <com/sun/star/accessibility/AccessibleRole.hpp>
30 #include <com/sun/star/awt/XExtendedToolkit.hpp>
31 #include <vcl/svapp.hxx>
32 #include <vcl/window.hxx>
34 #include <prewin.h>
35 #include <postwin.h>
37 using namespace ::com::sun::star; // for odk interfaces
38 using namespace ::com::sun::star::uno; // for basic types
39 using namespace ::com::sun::star::accessibility;
41 using namespace ::com::sun::star::awt;
43 #include "AccTopWindowListener.hxx"
45 namespace my_sc_impl
48 static Sequence< OUString > getSupportedServiceNames_MSAAServiceImpl()
50 Sequence< OUString > seqNames(1);
51 seqNames.getArray()[0] = "com.sun.star.accessibility.MSAAService";
52 return seqNames;
55 static OUString getImplementationName_MSAAServiceImpl()
57 return OUString( "com.sun.star.accessibility.my_sc_implementation.MSAAService" );
60 class MSAAServiceImpl : public ::cppu::WeakImplHelper2<
61 XMSAAService, lang::XServiceInfo >
63 private:
64 rtl::Reference<AccTopWindowListener> m_pTopWindowListener;
66 public:
67 MSAAServiceImpl ();
68 virtual ~MSAAServiceImpl();
70 // XComponent - as used by VCL to lifecycle manage this bridge.
71 virtual void SAL_CALL dispose();
72 virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& ) { /* dummy */ }
73 virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& ) { /* dummy */ }
75 // XMSAAService
76 virtual sal_Int64 SAL_CALL getAccObjectPtr(
77 sal_Int64 hWnd, sal_Int64 lParam, sal_Int64 wParam);
78 virtual void SAL_CALL handleWindowOpened(sal_Int64);
80 // XServiceInfo
81 virtual OUString SAL_CALL getImplementationName();
82 virtual sal_Bool SAL_CALL supportsService( OUString const & serviceName );
83 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames();
86 /**
87 * Implemention of getAccObjectPtr.
88 * @param
89 * @return Com interface.
91 sal_Int64 MSAAServiceImpl::getAccObjectPtr(
92 sal_Int64 hWnd, sal_Int64 lParam, sal_Int64 wParam)
93 throw (RuntimeException)
95 SolarMutexGuard g;
97 if (!m_pTopWindowListener.is())
99 return 0;
101 return m_pTopWindowListener->GetMSComPtr(hWnd, lParam, wParam);
105 * Implemention of handleWindowOpened, the method will be invoked when a
106 * top window is opened and AT starts up.
107 * @param
108 * @return
110 void MSAAServiceImpl::handleWindowOpened(sal_Int64 nAcc)
112 SolarMutexGuard g;
114 SAL_INFO( "iacc2", "Window opened " << nAcc );
116 if (m_pTopWindowListener.is() && nAcc)
118 m_pTopWindowListener->HandleWindowOpened(
119 static_cast<com::sun::star::accessibility::XAccessible*>(
120 reinterpret_cast<void*>(nAcc)));
124 OUString MSAAServiceImpl::getImplementationName() throw (RuntimeException)
126 return getImplementationName_MSAAServiceImpl();
130 * Implemention of XServiceInfo,return support service name.
131 * @param Service name.
132 * @return If the service name is supported.
134 sal_Bool MSAAServiceImpl::supportsService( OUString const & serviceName ) throw (RuntimeException)
136 return cppu::supportsService(this, serviceName);
140 * Implemention of XServiceInfo,return all service names.
141 * @param.
142 * @return service name sequence.
144 Sequence< OUString > MSAAServiceImpl::getSupportedServiceNames() throw (RuntimeException)
146 return getSupportedServiceNames_MSAAServiceImpl();
149 static void AccessBridgeHandleExistingWindow(const Reference< XMSAAService > &xAccMgr,
150 vcl::Window *pWindow, bool bShow)
152 if ( pWindow )
154 css::uno::Reference< css::accessibility::XAccessible > xAccessible;
156 SAL_INFO( "iacc2", "Decide whether to register existing window with IAccessible2" );
158 // Test for combo box - drop down floating windows first
159 vcl::Window * pParentWindow = pWindow->GetParent();
161 if ( pParentWindow )
165 // The parent window of a combo box floating window should have the role COMBO_BOX
166 css::uno::Reference< css::accessibility::XAccessible > xParentAccessible(pParentWindow->GetAccessible());
167 if ( xParentAccessible.is() )
169 css::uno::Reference< css::accessibility::XAccessibleContext > xParentAC( xParentAccessible->getAccessibleContext() );
170 if ( xParentAC.is() && (css::accessibility::AccessibleRole::COMBO_BOX == xParentAC->getAccessibleRole()) )
172 // O.k. - this is a combo box floating window corresponding to the child of role LIST of the parent.
173 // Let's not rely on a specific child order, just search for the child with the role LIST
174 sal_Int32 nCount = xParentAC->getAccessibleChildCount();
175 for ( sal_Int32 n = 0; (n < nCount) && !xAccessible.is(); n++)
177 css::uno::Reference< css::accessibility::XAccessible > xChild = xParentAC->getAccessibleChild(n);
178 if ( xChild.is() )
180 css::uno::Reference< css::accessibility::XAccessibleContext > xChildAC = xChild->getAccessibleContext();
181 if ( xChildAC.is() && (css::accessibility::AccessibleRole::LIST == xChildAC->getAccessibleRole()) )
183 xAccessible = xChild;
190 catch (::com::sun::star::uno::RuntimeException const&)
192 // Ignore show events that throw DisposedExceptions in getAccessibleContext(),
193 // but keep revoking these windows in hide(s).
194 if (bShow)
195 return;
199 // We have to rely on the fact that Window::GetAccessible()->getAccessibleContext() returns a valid XAccessibleContext
200 // also for other menus than menubar or toplevel popup window. Otherwise we had to traverse the hierarchy to find the
201 // context object to this menu floater. This makes the call to Window->IsMenuFloatingWindow() obsolete.
202 if ( ! xAccessible.is() )
203 xAccessible = pWindow->GetAccessible();
205 assert( xAccMgr.is() );
206 if ( xAccessible.is() )
208 xAccMgr->handleWindowOpened(
209 reinterpret_cast<sal_Int64>(xAccessible.get()));
210 SAL_INFO( "iacc2", "Decide whether to register existing window with IAccessible2" );
216 * Setup and notify the OS of Accessible peers for all existing windows.
218 static void AccessBridgeUpdateOldTopWindows( const Reference< XMSAAService > &xAccMgr )
220 sal_uInt16 nTopWindowCount = (sal_uInt16)Application::GetTopWindowCount();
222 for ( sal_uInt16 i = 0; i < nTopWindowCount; i++ )
224 vcl::Window* pTopWindow = Application::GetTopWindow( i );
225 css::uno::Reference< css::accessibility::XAccessible > xAccessible = pTopWindow->GetAccessible();
226 if ( xAccessible.is() )
228 css::uno::Reference< css::accessibility::XAccessibleContext > xAC( xAccessible->getAccessibleContext() );
229 if ( xAC.is())
231 if ( !xAC->getAccessibleName().isEmpty() )
232 AccessBridgeHandleExistingWindow( xAccMgr, pTopWindow, true );
239 * Static method that can create an entity of our MSAA Service
240 * @param xContext No use here.
241 * @return The object interface.
243 Reference< XInterface > SAL_CALL create_MSAAServiceImpl( Reference< XComponentContext > const & /*xContext*/ )
245 Reference< XMSAAService > xAccMgr( new MSAAServiceImpl() );
247 AccessBridgeUpdateOldTopWindows( xAccMgr );
249 SAL_INFO("iacc2", "Created new IAccessible2 service impl.");
251 return xAccMgr;
254 MSAAServiceImpl::MSAAServiceImpl()
256 Reference< XExtendedToolkit > xToolkit =
257 Reference< XExtendedToolkit >(Application::GetVCLToolkit(), UNO_QUERY);
259 if( xToolkit.is() )
261 m_pTopWindowListener.set(new AccTopWindowListener());
262 Reference<XTopWindowListener> const xRef(m_pTopWindowListener.get());
263 xToolkit->addTopWindowListener( xRef );
264 SAL_INFO( "iacc2", "successfully connected to the toolkit event hose" );
266 else
267 SAL_WARN( "iacc2", "No VCL toolkit interface to listen to for events");
270 MSAAServiceImpl::~MSAAServiceImpl()
274 void MSAAServiceImpl::dispose()
276 SolarMutexGuard g;
278 // As all folders and streams contain references to their parents,
279 // we must remove these references so that they will be deleted when
280 // the hash_map of the root folder is cleared, releasing all subfolders
281 // and substreams which in turn release theirs, etc. When xRootFolder is
282 // released when this destructor completes, the folder tree should be
283 // deleted fully (and automagically).
284 m_pTopWindowListener.clear();
289 /* shared lib exports implemented without helpers in service_impl1.cxx */
290 namespace my_sc_impl
292 static struct ::cppu::ImplementationEntry s_component_entries [] =
295 create_MSAAServiceImpl, getImplementationName_MSAAServiceImpl,
296 getSupportedServiceNames_MSAAServiceImpl,
297 ::cppu::createSingleComponentFactory,
298 0, 0
300 { 0, 0, 0, 0, 0, 0 }
304 extern "C"
306 SAL_DLLPUBLIC_EXPORT void * SAL_CALL iacc2_component_getFactory(
307 sal_Char const * implName, lang::XMultiServiceFactory * xMgr,
308 registry::XRegistryKey * xRegistry )
310 return ::cppu::component_getFactoryHelper(
311 implName, xMgr, xRegistry, ::my_sc_impl::s_component_entries );
315 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */