1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 #include <com/sun/star/accessibility/XAccessible.hpp>
23 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
24 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
25 #include <com/sun/star/accessibility/AccessibleRole.hpp>
26 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
27
28 #include "AccDescendantManagerEventListener.hxx"
29 #include "AccObjectManagerAgent.hxx"
30 #include "unomsaaevent.hxx"
31
32 using namespace com::sun::star::uno;
33 using namespace com::sun::star::accessibility;
34
AccDescendantManagerEventListener(com::sun::star::accessibility::XAccessible * pAcc,AccObjectManagerAgent * Agent)35 AccDescendantManagerEventListener::AccDescendantManagerEventListener(com::sun::star::accessibility::XAccessible* pAcc, AccObjectManagerAgent* Agent)
36 :AccComponentEventListener(pAcc, Agent),
37 pActiveDescendant(NULL)
38 {
39 }
40
~AccDescendantManagerEventListener()41 AccDescendantManagerEventListener::~AccDescendantManagerEventListener()
42 {
43 }
44
45 /**
46 * Uno's event notifier when event is captured
47 * @param AccessibleEventObject the event object which contains information about event
48 */
notifyEvent(const::com::sun::star::accessibility::AccessibleEventObject & aEvent)49 void AccDescendantManagerEventListener::notifyEvent( const ::com::sun::star::accessibility::AccessibleEventObject& aEvent )
50 {
51 switch (aEvent.EventId)
52 {
53 case AccessibleEventId::SELECTION_CHANGED:
54 handleSelectionChangedEvent(aEvent.OldValue, aEvent.NewValue);
55 break;
56 case AccessibleEventId::CHILD:
57 handleChildChangedEvent(aEvent.OldValue, aEvent.NewValue);
58 break;
59 case AccessibleEventId::ACTIVE_DESCENDANT_CHANGED_NOFOCUS:
60 handleChildChangedNoFocusEvent(aEvent.OldValue, aEvent.NewValue);
61 break;
62 case AccessibleEventId::SELECTION_CHANGED_ADD:
63 handleSelectionChangedAddEvent(aEvent.OldValue, aEvent.NewValue);
64 break;
65 case AccessibleEventId::SELECTION_CHANGED_REMOVE:
66 handleSelectionChangedRemoveEvent(aEvent.OldValue, aEvent.NewValue);
67 break;
68 case AccessibleEventId::SELECTION_CHANGED_WITHIN:
69 handleSelectionChangedWithinEvent(aEvent.OldValue, aEvent.NewValue);
70 break;
71 default:
72 AccComponentEventListener::notifyEvent(aEvent);
73 break;
74 }
75 }
76
77 /**
78 * handle the CHILD event
79 * @param oldValue the child to be deleted
80 * @param newValue the child to be added
81 */
handleChildChangedEvent(Any oldValue,Any newValue)82 void AccDescendantManagerEventListener::handleChildChangedEvent(Any oldValue, Any newValue)
83 {
84
85 Reference< XAccessible > xChild;
86 if( newValue >>= xChild)
87 {
88 //create a new child
89 if(xChild.is())
90 {
91 XAccessible* pAcc = xChild.get();
92 pAgent->InsertAccObj( pAcc,pAccessible);
93 pAgent->InsertChildrenAccObj(pAcc);
94
95 pAgent->NotifyAccEvent(UM_EVENT_CHILD_ADDED, pAcc);
96
97 }
98 else
99 {}
100 }
101
102 if (oldValue >>= xChild)
103 {
104 if(xChild.is())
105 {
106 XAccessible* pAcc = xChild.get();
107
108 pAgent->NotifyAccEvent(UM_EVENT_CHILD_REMOVED, pAcc);
109 pAgent->DeleteChildrenAccObj( pAcc );
110 pAgent->DeleteAccObj( pAcc );
111 }
112 else
113 {}
114 }
115
116 }
117
118 /**
119 * handle the SELECTION_CHANGED event
120 */
handleSelectionChangedEvent(Any oldValue,Any newValue)121 void AccDescendantManagerEventListener::handleSelectionChangedEvent(Any oldValue, Any newValue)
122 {
123 bool bSend =false;
124 Reference< XAccessible > xChild;
125 if(newValue >>= xChild )
126 {
127 if(xChild.is())
128 {
129 XAccessible* pAcc = xChild.get();
130 //if the Role is the SC cell ,don't add the selected state.
131 if (pAgent->GetRole(pAcc) != AccessibleRole::TABLE_CELL)
132 {
133 pAgent->IncreaseState( pAcc, AccessibleStateType::SELECTED);
134 }
135
136 pAgent->NotifyAccEvent(UM_EVENT_SELECTION_CHANGED, pAcc);
137 bSend=true;
138 }
139 }
140 if(oldValue >>= xChild )
141 {
142 if(xChild.is())
143 {
144 XAccessible* pAcc = xChild.get();
145 pAgent->DecreaseState( pAcc, AccessibleStateType::SELECTED);
146 }
147 }
148 if (!bSend)
149 {
150 pAgent->NotifyAccEvent(UM_EVENT_SELECTION_CHANGED, pAccessible);
151 }
152 }
153
154
handleChildChangedNoFocusEvent(Any oldValue,Any newValue)155 void AccDescendantManagerEventListener::handleChildChangedNoFocusEvent(Any oldValue, Any newValue)
156 {
157 Reference< XAccessible > xChild;
158 if(newValue >>= xChild )
159 {
160 if(xChild.is())
161 {
162 XAccessible* pAcc = xChild.get();
163
164 pAgent->InsertAccObj(pAcc,pAccessible);
165 pAgent->InsertChildrenAccObj(pAcc);
166
167 pActiveDescendant= pAcc;
168 }
169 }
170 if (oldValue >>= xChild)
171 {
172 if(xChild.is())
173 {
174 XAccessible* pAcc = xChild.get();
175 pAgent->DeleteChildrenAccObj( pAcc );
176 pAgent->DeleteAccObj( pAcc );
177 }
178 }
179 }
180
NotifyChildEvent(short nWinEvent,const Any & Value)181 bool AccDescendantManagerEventListener::NotifyChildEvent(short nWinEvent,const Any &Value)
182 {
183 Reference< XAccessible > xChild;
184 if(Value >>= xChild )
185 {
186 if(xChild.is())
187 {
188 XAccessible* pAcc = xChild.get();
189 pAgent->NotifyAccEvent(nWinEvent, pAcc);
190
191 if (pAgent && pAgent->IsStateManageDescendant(pAccessible) && ( nWinEvent == UM_EVENT_SELECTION_CHANGED_REMOVE) )
192 {
193 pAgent->DeleteAccObj( pAcc );
194 }
195 return true;
196 }
197 }
198 return false;
199 }
handleSelectionChangedAddEvent(const Any &,const Any & newValue)200 void AccDescendantManagerEventListener::handleSelectionChangedAddEvent(const Any& /*oldValue*/, const Any &newValue)
201 {
202 if(NotifyChildEvent(UM_EVENT_SELECTION_CHANGED_ADD,newValue))
203 {
204 return ;
205 }
206 pAgent->NotifyAccEvent(UM_EVENT_SELECTION_CHANGED_ADD,pAccessible);
207 }
handleSelectionChangedRemoveEvent(const Any &,const Any & newValue)208 void AccDescendantManagerEventListener::handleSelectionChangedRemoveEvent(const Any& /*oldValue*/, const Any &newValue)
209 {
210 if(NotifyChildEvent(UM_EVENT_SELECTION_CHANGED_REMOVE,newValue))
211 {
212 return ;
213 }
214 pAgent->NotifyAccEvent(UM_EVENT_SELECTION_CHANGED_REMOVE,pAccessible);
215 }
216
handleSelectionChangedWithinEvent(const Any &,const Any & newValue)217 void AccDescendantManagerEventListener::handleSelectionChangedWithinEvent(const Any& /*oldValue*/, const Any &newValue)
218 {
219 if(NotifyChildEvent(UM_EVENT_SELECTION_CHANGED_WITHIN,newValue))
220 {
221 return ;
222 }
223 pAgent->NotifyAccEvent(UM_EVENT_SELECTION_CHANGED_WITHIN,pAccessible);
224 }
225