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 "AccListEventListener.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
AccListEventListener(com::sun::star::accessibility::XAccessible * pAcc,AccObjectManagerAgent * Agent)35 AccListEventListener::AccListEventListener(com::sun::star::accessibility::XAccessible* pAcc, AccObjectManagerAgent* Agent)
36 :AccDescendantManagerEventListener(pAcc, Agent),
37 shouldDeleteChild(true)
38 {
39 }
40
~AccListEventListener()41 AccListEventListener::~AccListEventListener()
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 AccListEventListener::notifyEvent( const ::com::sun::star::accessibility::AccessibleEventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException)
50 {
51 switch (aEvent.EventId)
52 {
53 case AccessibleEventId::ACTIVE_DESCENDANT_CHANGED:
54 handleActiveDescendantChangedEvent(aEvent.OldValue, aEvent.NewValue);
55 break;
56 case AccessibleEventId::INVALIDATE_ALL_CHILDREN:
57 // Since List items a transient a child events are mostly used
58 // to attach/detach listeners, it is save to ignore it here
59 //TODO: investigate again
60 break;
61 case AccessibleEventId::VALUE_CHANGED:
62 handleValueChangedEvent(aEvent.OldValue, aEvent.NewValue);
63 break;
64 default:
65 AccDescendantManagerEventListener::notifyEvent(aEvent);
66 break;
67 }
68 }
69
70 /**
71 * handle the ACTIVE_DESCENDANT_CHANGED event
72 * @param oldValue the child to lose active
73 * @param newValue the child to get active
74 */
handleActiveDescendantChangedEvent(Any oldValue,Any newValue)75 void AccListEventListener::handleActiveDescendantChangedEvent(Any oldValue, Any newValue)
76 {
77 Reference< XAccessible > xChild;
78
79 if(newValue >>= xChild )
80 {
81 if(xChild.is())
82 {
83 XAccessible* pAcc = xChild.get();
84
85 // Valueset has cache the child item xacc,Update state if no insert obj
86 sal_Bool bHasCache = pAgent->InsertAccObj(pAcc,pAccessible);
87 if (!bHasCache)
88 {
89 pAgent->UpdateState(pAcc);
90 }
91
92 pAgent->IncreaseState( pAcc, AccessibleStateType::FOCUSED);
93
94 pAgent->NotifyAccEvent(UM_EVENT_ACTIVE_DESCENDANT_CHANGED, pAcc);
95 pActiveDescendant= pAcc;
96 }
97 }
98 if (oldValue >>= xChild)
99 {
100 if(xChild.is())
101 {
102 XAccessible* pAcc = xChild.get();
103 pAgent->DeleteAccObj( pAcc );
104 }
105 }
106 }
107
108 /**
109 * handle the VALUE_CHANGED event
110 *
111 * @param oldValue the old value of the source of event
112 * @param newValue the new value of the source of event
113 */
handleValueChangedEvent(Any oldValue,Any newValue)114 void AccListEventListener::handleValueChangedEvent(Any oldValue, Any newValue)
115 {
116 //to enable value changed event
117 if(getParentRole() == AccessibleRole::COMBO_BOX)
118 {
119 XAccessible* pParentAcc = pAgent->GetParentXAccessible(pAccessible);
120 pAgent->UpdateValue(pParentAcc);
121 pAgent->NotifyAccEvent(UM_EVENT_OBJECT_VALUECHANGE, pParentAcc);
122 }
123 }
124