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 "AccTreeEventListener.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 
AccTreeEventListener(com::sun::star::accessibility::XAccessible * pAcc,AccObjectManagerAgent * Agent)35 AccTreeEventListener::AccTreeEventListener(com::sun::star::accessibility::XAccessible* pAcc, AccObjectManagerAgent* Agent)
36         :AccDescendantManagerEventListener(pAcc, Agent)
37 {}
~AccTreeEventListener()38 AccTreeEventListener::~AccTreeEventListener()
39 {
40 }
41 
42 /**
43  *	Uno's event notifier when event is captured
44  *	@param AccessibleEventObject	the event object which contains information about event
45  */
notifyEvent(const::com::sun::star::accessibility::AccessibleEventObject & aEvent)46 void  AccTreeEventListener::notifyEvent( const ::com::sun::star::accessibility::AccessibleEventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException)
47 {
48     switch (aEvent.EventId)
49     {
50     case AccessibleEventId::ACTIVE_DESCENDANT_CHANGED:
51         handleActiveDescendantChangedEvent(aEvent.OldValue, aEvent.NewValue);
52         break;
53     default:
54         AccDescendantManagerEventListener::notifyEvent(aEvent);
55         break;
56     }
57 }
58 
59 /**
60  *	handle the ACTIVE_DESCENDANT_CHANGED event
61  *  @param	oldValue	the child to lose active
62  *  @param	newValue	the child to get active
63  */
handleActiveDescendantChangedEvent(Any oldValue,Any newValue)64 void AccTreeEventListener::handleActiveDescendantChangedEvent(Any oldValue, Any newValue)
65 {
66     Reference< XAccessible > xChild;
67     if(newValue >>= xChild )
68     {
69         if(xChild.is())
70         {
71             XAccessible* pAcc = xChild.get();
72             pAgent->InsertAccObj(pAcc,pAccessible);
73             pAgent->NotifyAccEvent(UM_EVENT_ACTIVE_DESCENDANT_CHANGED, pAcc);
74             pActiveDescendant = pAcc;
75         }
76     }
77     if (oldValue >>= xChild)
78     {
79         //delete an existing child
80         if(xChild.is())
81         {
82             XAccessible* pAcc = xChild.get();
83             pAgent->DeleteAccObj( pAcc );
84         }
85     }
86 
87 }
88