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 "AccWindowEventListener.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 
AccWindowEventListener(com::sun::star::accessibility::XAccessible * pAcc,AccObjectManagerAgent * Agent)35 AccWindowEventListener::AccWindowEventListener(com::sun::star::accessibility::XAccessible* pAcc, AccObjectManagerAgent* Agent)
36         :AccEventListener(pAcc, Agent)
37 {}
~AccWindowEventListener()38 AccWindowEventListener::~AccWindowEventListener()
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  AccWindowEventListener::notifyEvent( const ::com::sun::star::accessibility::AccessibleEventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException)
47 {
48     switch (aEvent.EventId)
49     {
50     case AccessibleEventId::CHILD:
51         handleChildChangedEvent(aEvent.OldValue, aEvent.NewValue);
52         break;
53     case AccessibleEventId::VISIBLE_DATA_CHANGED:
54         handleVisibleDataChangedEvent();
55         break;
56     case AccessibleEventId::BOUNDRECT_CHANGED:
57         handleBoundrectChangedEvent();
58         break;
59     default:
60         AccEventListener::notifyEvent(aEvent);
61         break;
62     }
63 }
64 
65 /**
66  *	handle the VISIBLE_DATA_CHANGED event
67  */
handleVisibleDataChangedEvent()68 void AccWindowEventListener::handleVisibleDataChangedEvent()
69 {
70     AccEventListener::handleVisibleDataChangedEvent();
71 }
72 
73 /**
74  *	handle the BOUNDRECT_CHANGED event
75  */
handleBoundrectChangedEvent()76 void AccWindowEventListener::handleBoundrectChangedEvent()
77 {
78     AccEventListener::handleBoundrectChangedEvent();
79 }
80 
81 /**
82  *	handle the CHILD event
83  *	@param	oldValue	the child to be deleted
84  *	@param	newValue	the child to be added
85  */
handleChildChangedEvent(Any oldValue,Any newValue)86 void AccWindowEventListener::handleChildChangedEvent(Any oldValue, Any newValue)
87 {
88     Reference< XAccessible > xChild;
89     if( newValue >>= xChild)
90     {
91         //create a new child
92         if(xChild.is())
93         {
94             XAccessible* pAcc = xChild.get();
95             //add this child
96             pAgent->InsertAccObj( pAcc,pAccessible);
97             //add all oldValue's existing children
98             pAgent->InsertChildrenAccObj(pAcc);
99             pAgent->NotifyAccEvent(UM_EVENT_CHILD_ADDED, pAcc);
100         }
101         else
102         {}
103     }
104     else if (oldValue >>= xChild)
105     {
106         //delete a existing child
107         if(xChild.is())
108         {
109             XAccessible* pAcc = xChild.get();
110             pAgent->NotifyAccEvent(UM_EVENT_CHILD_REMOVED, pAcc);
111             pAgent->DeleteChildrenAccObj( pAcc );
112             //delete this child
113             pAgent->DeleteAccObj( pAcc );
114         }
115         else
116         {}
117     }
118 }
119 
120 /**
121  *	set the new state and fire the MSAA event
122  *	@param state	new state id
123  *	@param enable	true if state is set, false if state is unset
124  */
setComponentState(short state,bool enable)125 void AccWindowEventListener::setComponentState(short state, bool enable )
126 {
127     // only the following state can be fired state event.
128     switch (state)
129     {
130     case AccessibleStateType::ICONIFIED:
131         // no msaa state
132         break;
133     case AccessibleStateType::VISIBLE:
134         // UNO !VISIBLE == MSAA INVISIBLE
135         if( enable )
136             pAgent->IncreaseState( pAccessible, AccessibleStateType::VISIBLE );
137         else
138             pAgent->DecreaseState( pAccessible, AccessibleStateType::VISIBLE );
139         break;
140     case AccessibleStateType::SHOWING:
141         // UNO !SHOWING == MSAA OFFSCREEN
142         if( enable )
143         {
144             pAgent->IncreaseState( pAccessible, AccessibleStateType::SHOWING );
145         }
146         else
147             pAgent->DecreaseState( pAccessible, AccessibleStateType::SHOWING );
148         break;
149     default:
150         break;
151     }
152 }
153