LibreOffice Module winaccessibility (master) 1
AccContainerEventListener.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#include <com/sun/star/accessibility/XAccessible.hpp>
21#include <com/sun/star/accessibility/AccessibleStateType.hpp>
22#include <com/sun/star/accessibility/AccessibleEventId.hpp>
23#include <com/sun/star/accessibility/AccessibleRole.hpp>
24#include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
25
26#include <vcl/svapp.hxx>
27
30#include <unomsaaevent.hxx>
31
32using namespace com::sun::star::uno;
33using namespace com::sun::star::accessibility;
34
36 :AccEventListener(pAcc, Agent)
37{
38}
39
41{
42}
43
49void AccContainerEventListener::notifyEvent( const css::accessibility::AccessibleEventObject& aEvent )
50{
52
53 switch (aEvent.EventId)
54 {
55 case AccessibleEventId::CHILD:
56 HandleChildChangedEvent(aEvent.OldValue, aEvent.NewValue);
57 break;
58 case AccessibleEventId::SELECTION_CHANGED:
59 HandleSelectionChangedEvent(aEvent.OldValue, aEvent.NewValue);
60 break;
61 case AccessibleEventId::INVALIDATE_ALL_CHILDREN:
63 break;
64 case AccessibleEventId::TEXT_CHANGED:
65 HandleTextChangedEvent(aEvent.OldValue, aEvent.NewValue);
66 [[fallthrough]]; //TODO ???
67 case AccessibleEventId::VISIBLE_DATA_CHANGED:
69 break;
70 case AccessibleEventId::BOUNDRECT_CHANGED:
72 break;
73 case AccessibleEventId::STATE_CHANGED:
74 HandleStateChangedEvent(aEvent.OldValue, aEvent.NewValue);
75 break;
76 case AccessibleEventId::VALUE_CHANGED:
77 HandleValueChangedEvent(aEvent.OldValue, aEvent.NewValue);
78 break;
79 case AccessibleEventId::SELECTION_CHANGED_ADD:
81 break;
82 case AccessibleEventId::SELECTION_CHANGED_REMOVE:
84 break;
85 case AccessibleEventId::SELECTION_CHANGED_WITHIN:
87 break;
88 case AccessibleEventId::PAGE_CHANGED:
89 HandlePageChangedEvent(aEvent.OldValue, aEvent.NewValue);
90 break;
91 case AccessibleEventId::SECTION_CHANGED:
92 HandleSectionChangedEvent(aEvent.OldValue, aEvent.NewValue);
93 break;
94 case AccessibleEventId::COLUMN_CHANGED:
95 HandleColumnChangedEvent(aEvent.OldValue, aEvent.NewValue);
96 break;
97 default:
99 break;
100 }
101}
102
104{
105 sal_Int64 State;
106 if( newValue >>= State)
107 {
109 }
110 else if (oldValue >>= State)
111 {
112 SetComponentState(State, false);
113 }
114
115}
116
123{
125 if( newValue >>= xChild)
126 {
127 //create a new child
128 if(xChild.is())
129 {
130 XAccessible* pAcc = xChild.get();
131 //add this child
132
133 if (pAgent->InsertAccObj(pAcc, m_xAccessible.get()))
134 {
135 //add all oldValue's existing children
138 }
139 }
140 }
141 else if (oldValue >>= xChild)
142 {
143 //delete an existing child
144 if(xChild.is())
145 {
146 XAccessible* pAcc = xChild.get();
148 //delete all oldValue's existing children
150 //delete this child
151 pAgent->DeleteAccObj( pAcc );
152
153 }
154 }
155
156}
157
163void AccContainerEventListener::HandleSelectionChangedEvent(const Any& /*oldValue*/, const Any& newValue)
164{
166 {
167 return ;
168 }
169
170 //menu bar does not process selection change event,just same as word behavior
171 if (GetRole()!=AccessibleRole::MENU_BAR)
173}
174
179{
180 //TODO: update all the children
181 if (m_xAccessible.is())
182 {
183 //delete all oldValue's existing children
185 //add all oldValue's existing children
188 }
189}
190
195{
196 pAgent->UpdateValue(m_xAccessible.get(), newValue);
198}
199
205void AccContainerEventListener::SetComponentState(sal_Int64 state, bool enable )
206{
207 // only the following state can be fired state event.
208
209 switch (state)
210 {
211 case AccessibleStateType::SELECTED:
212 case AccessibleStateType::BUSY:
213 case AccessibleStateType::INDETERMINATE:
214 case AccessibleStateType::OFFSCREEN:
215 case AccessibleStateType::FOCUSABLE:
216 case AccessibleStateType::SHOWING:
217 case AccessibleStateType::VISIBLE:
218 FireStatePropertyChange(state, enable);
219 break;
220 case AccessibleStateType::FOCUSED:
222 break;
223 case AccessibleStateType::ENABLED:
224 if(enable)
225 {
226 pAgent->DecreaseState(m_xAccessible.get(), AccessibleStateType::DEFUNC);
227 pAgent->IncreaseState(m_xAccessible.get(), AccessibleStateType::FOCUSABLE);
229
231 }
232 else
233 {
234 pAgent->IncreaseState(m_xAccessible.get(), AccessibleStateType::DEFUNC);
235 pAgent->DecreaseState(m_xAccessible.get(), AccessibleStateType::FOCUSABLE);
237
239 }
240 break;
241 case AccessibleStateType::ACTIVE:
242 // Only frames should be active
243 // no msaa state mapping
244 //for PAGE_TAB_LIST, there will be ACTIVE state, then it should be converted to FOCUSED event.
245 if (GetRole() == AccessibleRole::PAGE_TAB_LIST)
246 {
247 if (!enable) /* get the active state */
248 {
249 pAgent->IncreaseState(m_xAccessible.get(), AccessibleStateType::FOCUSED);
250 }
251
252 else /* lose the active state */
253 {
254 pAgent->DecreaseState(m_xAccessible.get(), AccessibleStateType::FOCUSED);
255 }
256 }
257 break;
258
259 case AccessibleStateType::EXPANDED:
260 case AccessibleStateType::COLLAPSE:
261 case AccessibleStateType::CHECKED:
262 {
265 break;
266 }
267
268 default:
269 break;
270 }
271}
272
279{
280 if( set )
281 {
282 // new value
283 switch(state)
284 {
285 case AccessibleStateType::SELECTED:
286 pAgent->IncreaseState(m_xAccessible.get(), state);
287 break;
288 case AccessibleStateType::INDETERMINATE:
289 case AccessibleStateType::BUSY:
290 case AccessibleStateType::FOCUSABLE:
291 case AccessibleStateType::OFFSCREEN:
292 pAgent->IncreaseState(m_xAccessible.get(), state);
294 break;
295 case AccessibleStateType::SHOWING:
296 // UNO !SHOWING == MSAA OFFSCREEN
297 pAgent->IncreaseState(m_xAccessible.get(), AccessibleStateType::SHOWING);
298 break;
299 case AccessibleStateType::VISIBLE:
300 // UNO !VISIBLE == MSAA INVISIBLE
301 pAgent->IncreaseState(m_xAccessible.get(), AccessibleStateType::VISIBLE);
302 break;
303 default:
304 break;
305 }
306 }
307 else
308 {
309 // old value
310 switch(state)
311 {
312 case AccessibleStateType::SELECTED:
313 pAgent->DecreaseState(m_xAccessible.get(), state);
314 break;
315 case AccessibleStateType::BUSY:
316 case AccessibleStateType::INDETERMINATE:
317 case AccessibleStateType::FOCUSABLE:
318 case AccessibleStateType::OFFSCREEN:
319 pAgent->DecreaseState(m_xAccessible.get(), state);
321 break;
322 case AccessibleStateType::SHOWING:
323 // UNO !SHOWING == MSAA OFFSCREEN
324 pAgent->DecreaseState(m_xAccessible.get(), AccessibleStateType::SHOWING);
325 break;
326 case AccessibleStateType::VISIBLE:
327 // UNO !VISIBLE == MSAA INVISIBLE
328 pAgent->DecreaseState(m_xAccessible.get(), AccessibleStateType::VISIBLE);
329 break;
330 default:
331 break;
332 }
333 }
334}
335
341{
342 if(enable)
343 {
344 pAgent->IncreaseState(m_xAccessible.get(), AccessibleStateType::FOCUSED);
345 // if the acc role is MENU_BAR, UnoMSAAEvent::MENU_START event should be sent
346 // if the acc role is POPUP_MENU, UnoMSAAEvent::MENUPOPUPSTART event should be sent
347 short role = GetRole();
348 if(role == AccessibleRole::MENU_BAR)
349 {
351 }
352 else if (role == AccessibleRole::POPUP_MENU)
354 //Disable the focused event on option_pane and Panel.
355 //only disable option_pane for toolbar has panel to get focus
356 else if (role == AccessibleRole::PANEL || role == AccessibleRole::OPTION_PANE )
357 {
358 //don't send focused event on PANEL & OPTION_PANE if the parent is not toolbar
359 short parentRole = GetParentRole();
360 if (parentRole == AccessibleRole::TOOL_BAR
361 || parentRole == AccessibleRole::SCROLL_PANE // sidebar
362 || parentRole == AccessibleRole::PANEL) // sidebar
364 }
365 else if (role == AccessibleRole::COMBO_BOX )
366 {
367 //for editable combobox, send focus event on only edit control,
368 bool bSendFocusOnCombobox = true;
369 //send focused event to the first text child
370 Reference<XAccessibleContext> mxContext = m_xAccessible->getAccessibleContext();
371 if(mxContext.is())
372 {
373 Reference<XAccessible> mxChild = mxContext->getAccessibleChild(0);
374 if(mxChild.is())
375 {
376 Reference<XAccessibleContext> mxChildContext = mxChild->getAccessibleContext();
377 short childrole = mxChildContext->getAccessibleRole();
378 if (childrole == AccessibleRole::TEXT)
379 {
380 if (IsEditable(mxChildContext))
381 {
382 pAgent->DecreaseState(m_xAccessible.get(), AccessibleStateType::FOCUSED);
383 pAgent->IncreaseState( mxChild.get(), AccessibleStateType::FOCUSED);
385 bSendFocusOnCombobox = false;
386 }
387 }
388 }
389 }
390 if (bSendFocusOnCombobox)
392 }
393 else
395 }
396 else
397 {
398 pAgent->DecreaseState(m_xAccessible.get(), AccessibleStateType::FOCUSED);
399 // if the acc role is MENU_BAR, UnoMSAAEvent::MENU_END event should be sent
400 // if the acc role is POPUP_MENU, UnoMSAAEvent::MENUPOPUPEND event should be sent
401 if (GetRole() == AccessibleRole::MENU_BAR)
402 {
404 }
405 else if (GetRole() == AccessibleRole::POPUP_MENU)
406 {
408 }
409 }
410}
411
419{
422}
423
425{
426 sal_Int64 nRState = xContext->getAccessibleStateSet();
427 return nRState & AccessibleStateType::EDITABLE;
428}
429
431{
433 if(Value >>= xChild )
434 {
435 if(xChild.is())
436 {
437 XAccessible* pAcc = xChild.get();
438 pAgent->NotifyAccEvent(eWinEvent, pAcc);
439 return true;
440 }
441 }
442 return false;
443}
444
445void AccContainerEventListener::HandleSelectionChangedAddEvent(const Any& /*oldValue*/, const Any& newValue)
446{
448 {
449 return ;
450 }
452}
453
454void AccContainerEventListener::HandleSelectionChangedRemoveEvent(const Any& /*oldValue*/, const Any& newValue)
455{
457 {
458 return ;
459 }
461}
462
463void AccContainerEventListener::HandleSelectionChangedWithinEvent(const Any& /*oldValue*/, const Any& newValue)
464{
466 {
467 return ;
468 }
470}
471
473{
474 Reference<css::accessibility::XAccessibleContext> xContext = pXAccessible->getAccessibleContext();
475 if(!xContext.is())
476 {
477 return;
478 }
479 css::accessibility::XAccessibleContext* pAccessibleContext = xContext.get();
480 if(pAccessibleContext == nullptr)
481 {
482 return;
483 }
484
485 if (pAgent && pAgent->IsStateManageDescendant(pXAccessible))
486 {
487 return;
488 }
489
490 const sal_Int64 nCount = pAccessibleContext->getAccessibleChildCount();
491 for (sal_Int64 i = 0; i < nCount; i++)
492 {
494 = pAccessibleContext->getAccessibleChild(i);
495
496 css::accessibility::XAccessible* mpAccessible = mxAccessible.get();
497 if(mpAccessible != nullptr)
498 {
499 pAgent->UpdateState(mpAccessible);
500 UpdateAllChildrenState(mpAccessible);
501 }
502 }
503}
504
505void AccContainerEventListener::HandlePageChangedEvent(const Any& /*oldValue*/, const Any& /*newValue*/)
506{
508}
509
510void AccContainerEventListener::HandleSectionChangedEvent(const Any& /*oldValue*/, const Any& /*newValue*/ )
511{
513}
514
515void AccContainerEventListener::HandleColumnChangedEvent(const Any& /*oldValue*/, const Any& /*newValue*/)
516{
518}
519
521{
522 if (GetRole() == AccessibleRole::COMBO_BOX)
523 {
525 if(mxContext.is())
526 {
527 Reference<XAccessible> mxChild = mxContext->getAccessibleChild(0);
528 if(mxChild.is())
529 {
530 Reference<XAccessibleContext> mxChildContext = mxChild->getAccessibleContext();
531 short childrole = mxChildContext->getAccessibleRole();
532 if (childrole == AccessibleRole::TEXT)
533 {
534 pAgent->UpdateAccName(mxChild.get(), name);
535 }
536 }
537 }
538 }
540}
541
542/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
virtual void SAL_CALL notifyEvent(const css::accessibility::AccessibleEventObject &aEvent) override
Uno's event notifier when event is captured.
virtual void HandleStateChangedEvent(css::uno::Any oldValue, css::uno::Any newValue) override
handle the STATE_CHANGED event
virtual void HandleSelectionChangedAddEvent(const css::uno::Any &oldValue, const css::uno::Any &newValue)
virtual void FireStateFocusedChange(bool enable) override
handle the focused event
virtual void HandlePageChangedEvent(const css::uno::Any &oldValue, const css::uno::Any &newValue)
bool NotifyChildEvent(UnoMSAAEvent eWinEvent, const css::uno::Any &Value)
virtual void HandleValueChangedEvent(css::uno::Any oldValue, css::uno::Any newValue)
handle the VALUE_CHANGED event
virtual void HandleChildChangedEvent(css::uno::Any oldValue, css::uno::Any newValue)
handle the CHILD event
virtual void HandleSelectionChangedRemoveEvent(const css::uno::Any &oldValue, const css::uno::Any &newValue)
virtual void HandleTextChangedEvent(css::uno::Any oldValue, css::uno::Any newValue)
handle the TEXT_CHANGED event
virtual void HandleSelectionChangedEvent(const css::uno::Any &oldValue, const css::uno::Any &newValue)
handle the SELECTION_CHANGED event
virtual void HandleColumnChangedEvent(const css::uno::Any &oldValue, const css::uno::Any &newValue)
virtual void FireStatePropertyChange(sal_Int64 state, bool set) override
fire the MSAA state changed event
virtual void SetComponentState(sal_Int64 state, bool enable) override
set the new state and fire the MSAA event
virtual bool IsEditable(css::uno::Reference< css::accessibility::XAccessibleContext > const &xContext)
virtual void HandleNameChangedEvent(css::uno::Any name) override
handle the NAME_CHANGED event
void UpdateAllChildrenState(css::accessibility::XAccessible *pXAccessible)
virtual void HandleSelectionChangedWithinEvent(const css::uno::Any &oldValue, const css::uno::Any &newValue)
virtual void HandleSectionChangedEvent(const css::uno::Any &oldValue, const css::uno::Any &newValue)
virtual void HandleAllChildrenChangedEvent()
handle the INVALIDATE_ALL_CHILDREN event
AccContainerEventListener(css::accessibility::XAccessible *pAcc, AccObjectManagerAgent *Agent)
virtual ~AccContainerEventListener() override
AccEventListener is the general event listener for all controls.
virtual short GetRole()
get the role of accessible object which is observed
virtual void HandleNameChangedEvent(css::uno::Any name)
handle the NAME_CHANGED event
virtual void HandleVisibleDataChangedEvent()
handle the VISIBLE_DATA_CHANGED event
virtual short GetParentRole()
get the role of accessible parent object which is observed
AccObjectManagerAgent * pAgent
virtual void HandleBoundrectChangedEvent()
handle the BOUNDRECT_CHANGED event
virtual void SAL_CALL notifyEvent(const css::accessibility::AccessibleEventObject &aEvent) override
Uno's event notifier when event is captured.
css::uno::Reference< css::accessibility::XAccessible > m_xAccessible
void DecreaseState(css::accessibility::XAccessible *pXAcc, sal_Int64 pState)
Interface of decreasing MSAA state when some UNO state is decreased.
virtual void DeleteAccObj(css::accessibility::XAccessible *pXAcc)
When a new UNO XAccessible object is destroyed, we delete its corresponding com object and remove it ...
void UpdateValue(css::accessibility::XAccessible *pXAcc)
void UpdateAccName(css::accessibility::XAccessible *pXAcc, css::uno::Any newName)
bool IsStateManageDescendant(css::accessibility::XAccessible *pXAcc)
void IncreaseState(css::accessibility::XAccessible *pXAcc, sal_Int64 pState)
Interface of increasing MSAA name when some UNO state is increased.
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 NotifyAccEvent(UnoMSAAEvent eEvent, css::accessibility::XAccessible *pXAcc=nullptr)
Interface of notify MSAA event when some UNO event occurred.
bool InsertChildrenAccObj(css::accessibility::XAccessible *pXAcc, HWND hWnd=nullptr)
When a UNO XAccessible object's new children are found by listener, we create corresponding com objec...
void UpdateState(css::accessibility::XAccessible *pXAcc)
int nCount
uno::Reference< uno::XComponentContext > mxContext
const char * name
void set(css::uno::UnoInterfaceReference const &value)
Value
int i
State
UnoMSAAEvent
@ SELECTION_CHANGED_REMOVE
@ SELECTION_CHANGED_WITHIN