LibreOffice Module winaccessibility (master) 1
AccTopWindowListener.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <sal/log.hxx>
22#include <vcl/window.hxx>
25
26#include <vcl/sysdata.hxx>
27#include <vcl/svapp.hxx>
28
30#include <unomsaaevent.hxx>
31
32#include <com/sun/star/accessibility/AccessibleRole.hpp>
33
34using namespace com::sun::star::uno;
35
41void AccTopWindowListener::HandleWindowOpened( css::accessibility::XAccessible* pAccessible )
42{
43 //get SystemData from window
45 if (auto pvclwindow = dynamic_cast<VCLXWindow*>(pAccessible))
46 window = pvclwindow->GetWindow();
47 else if (auto pvclxcomponent = dynamic_cast<VCLXAccessibleComponent*>(pAccessible))
48 window = pvclxcomponent->GetWindow();
49 assert(window);
50 // The SalFrame of window may be destructed at this time
51 const SystemEnvData* systemdata = nullptr;
52 try
53 {
54 systemdata = window->GetSystemData();
55 }
56 catch(...)
57 {
58 systemdata = nullptr;
59 }
60 Reference<css::accessibility::XAccessibleContext> xContext = pAccessible->getAccessibleContext();
61 if(!xContext.is())
62 return;
63
64 css::accessibility::XAccessibleContext* pAccessibleContext = xContext.get();
65 //Only AccessibleContext exist, add all listeners
66 if(pAccessibleContext != nullptr && systemdata != nullptr)
67 {
68 accManagerAgent.SaveTopWindowHandle(systemdata->hWnd, pAccessible);
69
70 AddAllListeners(pAccessible,nullptr,systemdata->hWnd);
71
72 if( window->GetStyle() & WB_MOVEABLE )
73 accManagerAgent.IncreaseState( pAccessible, static_cast<unsigned short>(-1) /* U_MOVEBLE */ );
74
75 short role = pAccessibleContext->getAccessibleRole();
76
77 if (role == css::accessibility::AccessibleRole::POPUP_MENU ||
78 role == css::accessibility::AccessibleRole::MENU )
79 {
81 }
82
83 if (role == css::accessibility::AccessibleRole::FRAME ||
84 role == css::accessibility::AccessibleRole::DIALOG ||
85 role == css::accessibility::AccessibleRole::WINDOW ||
86 role == css::accessibility::AccessibleRole::ALERT)
87 {
89 }
90 }
91}
92
94 : accManagerAgent()
95{
96}
97
99{
100}
101
105void AccTopWindowListener::windowOpened( const css::lang::EventObject& e )
106{
107 SAL_INFO( "iacc2", "windowOpened triggered" );
108
109 if ( !e.Source.is())
110 return;
111
112 Reference< css::accessibility::XAccessible > xAccessible ( e.Source, UNO_QUERY );
113 css::accessibility::XAccessible* pAccessible = xAccessible.get();
114 if ( !pAccessible )
115 return;
116
118
119 HandleWindowOpened( pAccessible );
120}
121
128void AccTopWindowListener::AddAllListeners(css::accessibility::XAccessible* pAccessible, css::accessibility::XAccessible* pParentXAcc, HWND pWND)
129{
130 Reference<css::accessibility::XAccessibleContext> xContext = pAccessible->getAccessibleContext();
131 if(!xContext.is())
132 {
133 return;
134 }
135 css::accessibility::XAccessibleContext* pAccessibleContext = xContext.get();
136 if(pAccessibleContext == nullptr)
137 {
138 return;
139 }
140
141 accManagerAgent.InsertAccObj(pAccessible, pParentXAcc, pWND);
142
143 if (!accManagerAgent.IsContainer(pAccessible))
144 {
145 return;
146 }
147
148
149 short role = pAccessibleContext->getAccessibleRole();
150 if(css::accessibility::AccessibleRole::DOCUMENT == role ||
151 css::accessibility::AccessibleRole::DOCUMENT_PRESENTATION == role ||
152 css::accessibility::AccessibleRole::DOCUMENT_SPREADSHEET == role ||
153 css::accessibility::AccessibleRole::DOCUMENT_TEXT == role)
154 {
156 {
157 return ;
158 }
159 }
160
161 sal_Int64 nCount = pAccessibleContext->getAccessibleChildCount();
162 for (sal_Int64 i = 0; i < nCount; i++)
163 {
165 = pAccessibleContext->getAccessibleChild(i);
166
167 css::accessibility::XAccessible* mpAccessible = mxAccessible.get();
168 if(mpAccessible != nullptr)
169 {
171 = mpAccessible->getAccessibleContext();
172 css::accessibility::XAccessibleContext* mpContext = mxAccessibleContext.get();
173 if(mpContext != nullptr)
174 AddAllListeners( mpAccessible, pAccessible, pWND);
175 }
176 }
177}
178
179void AccTopWindowListener::windowClosing( const css::lang::EventObject& )
180{
181 SAL_INFO( "iacc2", "windowClosing triggered" );
182}
183
189void AccTopWindowListener::windowClosed( const css::lang::EventObject& e )
190{
191 SAL_INFO( "iacc2", "windowClosed triggered" );
192
193 if ( !e.Source.is())
194 return;
195
196 Reference< css::accessibility::XAccessible > xAccessible ( e.Source, UNO_QUERY );
197 css::accessibility::XAccessible* pAccessible = xAccessible.get();
198 if ( pAccessible == nullptr)
199 return;
200
201 Reference<css::accessibility::XAccessibleContext> xContext = pAccessible->getAccessibleContext();
202 if(!xContext.is())
203 {
204 return;
205 }
206 css::accessibility::XAccessibleContext* pAccessibleContext = xContext.get();
207
208 short role = -1;
209 if(pAccessibleContext != nullptr)
210 {
211 role = pAccessibleContext->getAccessibleRole();
212
213 if (role == css::accessibility::AccessibleRole::POPUP_MENU ||
214 role == css::accessibility::AccessibleRole::MENU)
215 {
217 }
218 }
219
220
222 if( role != css::accessibility::AccessibleRole::POPUP_MENU )
223 accManagerAgent.DeleteAccObj( pAccessible );
224
225}
226
227void AccTopWindowListener::windowMinimized( const css::lang::EventObject& )
228{
229}
230
231void AccTopWindowListener::windowNormalized( const css::lang::EventObject& )
232{
233}
234
235void AccTopWindowListener::windowActivated( const css::lang::EventObject& )
236{
237}
238
239void AccTopWindowListener::windowDeactivated( const css::lang::EventObject& )
240{
241}
242
243void AccTopWindowListener::disposing( const css::lang::EventObject& )
244{
245}
246
248 sal_Int64 hWnd, sal_Int64 lParam, sal_Int64 wParam)
249{
250 return accManagerAgent.Get_ToATInterface(hWnd, lParam, wParam);
251}
252
253/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void DeleteAccObj(css::accessibility::XAccessible *pXAcc)
When a new UNO XAccessible object is destroyed, we delete its corresponding com object and remove it ...
bool IsStateManageDescendant(css::accessibility::XAccessible *pXAcc)
void SaveTopWindowHandle(HWND hWnd, css::accessibility::XAccessible *pXAcc)
save the pair <topwindowhandle, XAccessible>
void IncreaseState(css::accessibility::XAccessible *pXAcc, sal_Int64 pState)
Interface of increasing MSAA name when some UNO state is increased.
sal_Int64 Get_ToATInterface(sal_Int64 hWnd, sal_Int64 lParam, sal_Int64 wParam)
Implementation of interface XMSAAService's method getAccObjectPtr() that returns the corresponding CO...
void DeleteChildrenAccObj(css::accessibility::XAccessible *pXAcc)
When new UNO children XAccessible objects are destroyed, we delete their corresponding com objects an...
virtual bool InsertAccObj(css::accessibility::XAccessible *pXAcc, css::accessibility::XAccessible *pParentXAcc, HWND hWnd=nullptr)
When a new UNO XAccessible object is found by listener, we create a corresponding com object and inse...
bool IsContainer(css::accessibility::XAccessible *pXAcc)
Judge whether a XAccessible object is a container object.
bool NotifyAccEvent(UnoMSAAEvent eEvent, css::accessibility::XAccessible *pXAcc=nullptr)
Interface of notify MSAA event when some UNO event occurred.
AccObjectManagerAgent accManagerAgent
virtual ~AccTopWindowListener() override
virtual void HandleWindowOpened(css::accessibility::XAccessible *pAccessible)
For the new opened window, generate all the UNO accessible's object, COM object and add accessible li...
virtual void SAL_CALL windowDeactivated(const css::lang::EventObject &e) override
virtual void SAL_CALL windowOpened(const css::lang::EventObject &e) override
It is invoked when a new window is opened, the source of this EventObject is the window.
virtual void SAL_CALL windowClosing(const css::lang::EventObject &e) override
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
virtual void SAL_CALL windowClosed(const css::lang::EventObject &e) override
Invoke this method when the top window is closed, remove all the objects and its children from curren...
virtual void AddAllListeners(css::accessibility::XAccessible *pAccessible, css::accessibility::XAccessible *pParentXAcc, HWND pWND)
Add the accessible event listener to object and all its children objects.
sal_Int64 GetMSComPtr(sal_Int64 hWnd, sal_Int64 lParam, sal_Int64 wParam)
virtual void SAL_CALL windowActivated(const css::lang::EventObject &e) override
virtual void SAL_CALL windowMinimized(const css::lang::EventObject &e) override
virtual void SAL_CALL windowNormalized(const css::lang::EventObject &e) override
int nCount
#define SAL_INFO(area, stream)
int i
ParserContextSharedPtr mpContext
WinBits const WB_MOVEABLE