Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / winaccessibility / source / service / AccDescendantManagerEventListener.cxx
blobc38f19e32cd8bcb3de091cb2ffec932b8c0cd7c3
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 <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>
26 #include <vcl/svapp.hxx>
28 #include <AccDescendantManagerEventListener.hxx>
29 #include <AccObjectManagerAgent.hxx>
30 #include <unomsaaevent.hxx>
32 using namespace com::sun::star::uno;
33 using namespace com::sun::star::accessibility;
35 AccDescendantManagerEventListener::AccDescendantManagerEventListener(css::accessibility::XAccessible* pAcc, AccObjectManagerAgent* Agent)
36 : AccComponentEventListener(pAcc, Agent)
40 AccDescendantManagerEventListener::~AccDescendantManagerEventListener()
44 /**
45 * Uno's event notifier when event is captured
46 * @param AccessibleEventObject the event object which contains information about event
48 void AccDescendantManagerEventListener::notifyEvent( const css::accessibility::AccessibleEventObject& aEvent )
50 SolarMutexGuard g;
52 switch (aEvent.EventId)
54 case AccessibleEventId::SELECTION_CHANGED:
55 HandleSelectionChangedEvent(aEvent.OldValue, aEvent.NewValue);
56 break;
57 case AccessibleEventId::CHILD:
58 HandleChildChangedEvent(aEvent.OldValue, aEvent.NewValue);
59 break;
60 case AccessibleEventId::ACTIVE_DESCENDANT_CHANGED_NOFOCUS:
61 HandleChildChangedNoFocusEvent(aEvent.OldValue, aEvent.NewValue);
62 break;
63 case AccessibleEventId::SELECTION_CHANGED_ADD:
64 HandleSelectionChangedAddEvent(aEvent.OldValue, aEvent.NewValue);
65 break;
66 case AccessibleEventId::SELECTION_CHANGED_REMOVE:
67 HandleSelectionChangedRemoveEvent(aEvent.OldValue, aEvent.NewValue);
68 break;
69 case AccessibleEventId::SELECTION_CHANGED_WITHIN:
70 HandleSelectionChangedWithinEvent(aEvent.OldValue, aEvent.NewValue);
71 break;
72 default:
73 AccComponentEventListener::notifyEvent(aEvent);
74 break;
78 /**
79 * handle the CHILD event
80 * @param oldValue the child to be deleted
81 * @param newValue the child to be added
83 void AccDescendantManagerEventListener::HandleChildChangedEvent(Any oldValue, Any newValue)
86 Reference< XAccessible > xChild;
87 if( newValue >>= xChild)
89 //create a new child
90 if(xChild.is())
92 XAccessible* pAcc = xChild.get();
93 pAgent->InsertAccObj(pAcc, m_xAccessible.get());
94 pAgent->InsertChildrenAccObj(pAcc);
96 pAgent->NotifyAccEvent(UnoMSAAEvent::CHILD_ADDED, pAcc);
101 if (oldValue >>= xChild)
103 if(xChild.is())
105 XAccessible* pAcc = xChild.get();
107 pAgent->NotifyAccEvent(UnoMSAAEvent::CHILD_REMOVED, pAcc);
108 pAgent->DeleteChildrenAccObj( pAcc );
109 pAgent->DeleteAccObj( pAcc );
116 * handle the SELECTION_CHANGED event
118 void AccDescendantManagerEventListener::HandleSelectionChangedEvent(Any oldValue, Any newValue)
120 bool bSend =false;
121 Reference< XAccessible > xChild;
122 if(newValue >>= xChild )
124 if(xChild.is())
126 XAccessible* pAcc = xChild.get();
127 //if the Role is the SC cell ,don't add the selected state.
128 if (pAgent->GetRole(pAcc) != AccessibleRole::TABLE_CELL)
130 pAgent->IncreaseState( pAcc, AccessibleStateType::SELECTED);
133 pAgent->NotifyAccEvent(UnoMSAAEvent::SELECTION_CHANGED, pAcc);
134 bSend=true;
137 if(oldValue >>= xChild )
139 if(xChild.is())
141 XAccessible* pAcc = xChild.get();
142 pAgent->DecreaseState( pAcc, AccessibleStateType::SELECTED);
145 if (!bSend)
147 pAgent->NotifyAccEvent(UnoMSAAEvent::SELECTION_CHANGED, m_xAccessible.get());
152 void AccDescendantManagerEventListener::HandleChildChangedNoFocusEvent(Any oldValue, Any newValue)
154 Reference< XAccessible > xChild;
155 if(newValue >>= xChild )
157 if(xChild.is())
159 XAccessible* pAcc = xChild.get();
161 pAgent->InsertAccObj(pAcc, m_xAccessible.get());
162 pAgent->InsertChildrenAccObj(pAcc);
165 if (oldValue >>= xChild)
167 if(xChild.is())
169 XAccessible* pAcc = xChild.get();
170 pAgent->DeleteChildrenAccObj( pAcc );
171 pAgent->DeleteAccObj( pAcc );
176 bool AccDescendantManagerEventListener::NotifyChildEvent(UnoMSAAEvent eWinEvent, const Any& Value)
178 Reference< XAccessible > xChild;
179 if(Value >>= xChild )
181 if(xChild.is())
183 XAccessible* pAcc = xChild.get();
184 pAgent->NotifyAccEvent(eWinEvent, pAcc);
186 if (pAgent->IsStateManageDescendant(m_xAccessible.get()))
188 if (eWinEvent == UnoMSAAEvent::SELECTION_CHANGED_REMOVE)
190 // The object has just been sent in a SELECTION_CHANGED_REMOVE event
191 // and accessibility tools may query for the object and call methods on
192 // it as a response to this.
193 // Therefore, don't delete the object yet, but remember it for deletion
194 // once the next event of a different type occurs.
195 m_aUnselectedChildrenForDeletion.push_back(pAcc);
197 else
199 // handle any pending deletions for objects previously removed from selection
200 for (XAccessible* pAcc2 : m_aUnselectedChildrenForDeletion)
201 pAgent->DeleteAccObj(pAcc2);
202 m_aUnselectedChildrenForDeletion.clear();
205 return true;
208 return false;
210 void AccDescendantManagerEventListener::HandleSelectionChangedAddEvent(const Any& /*oldValue*/, const Any &newValue)
212 if (NotifyChildEvent(UnoMSAAEvent::SELECTION_CHANGED_ADD, newValue))
214 return ;
216 pAgent->NotifyAccEvent(UnoMSAAEvent::SELECTION_CHANGED_ADD, m_xAccessible.get());
219 void AccDescendantManagerEventListener::HandleSelectionChangedRemoveEvent(const Any& /*oldValue*/, const Any &newValue)
221 if (NotifyChildEvent(UnoMSAAEvent::SELECTION_CHANGED_REMOVE, newValue))
223 return ;
225 pAgent->NotifyAccEvent(UnoMSAAEvent::SELECTION_CHANGED_REMOVE, m_xAccessible.get());
228 void AccDescendantManagerEventListener::HandleSelectionChangedWithinEvent(const Any& /*oldValue*/, const Any &newValue)
230 if (NotifyChildEvent(UnoMSAAEvent::SELECTION_CHANGED_WITHIN, newValue))
232 return ;
234 pAgent->NotifyAccEvent(UnoMSAAEvent::SELECTION_CHANGED_WITHIN, m_xAccessible.get());
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */