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 "AccMenuEventListener.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
AccMenuEventListener(com::sun::star::accessibility::XAccessible * pAcc,AccObjectManagerAgent * Agent)35 AccMenuEventListener::AccMenuEventListener(com::sun::star::accessibility::XAccessible* pAcc, AccObjectManagerAgent* Agent)
36 :AccComponentEventListener(pAcc, Agent)
37 {}
~AccMenuEventListener()38 AccMenuEventListener::~AccMenuEventListener()
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 AccMenuEventListener::notifyEvent( const ::com::sun::star::accessibility::AccessibleEventObject& aEvent )
47 throw (::com::sun::star::uno::RuntimeException)
48 {
49 switch (aEvent.EventId)
50 {
51 case AccessibleEventId::CHILD:
52 handleChildChangedEvent(aEvent.OldValue, aEvent.NewValue);
53 break;
54 case AccessibleEventId::SELECTION_CHANGED:
55 //don't need to process anything,just same as word behavior
56 //handleSelectionChangedEvent();
57 break;
58 default:
59 AccComponentEventListener::notifyEvent(aEvent);
60 break;
61 }
62 }
63
64 /**
65 * handle the CHILD event
66 * @param oldValue the child to be deleted
67 * @param newValue the child to be added
68 */
handleChildChangedEvent(Any oldValue,Any newValue)69 void AccMenuEventListener::handleChildChangedEvent(Any oldValue, Any newValue)
70 {
71
72 Reference< XAccessible > xChild;
73 if( newValue >>= xChild)
74 {
75 //create a new child
76 if(xChild.is())
77 {
78 XAccessible* pAcc = xChild.get();
79 //add this child
80 pAgent->InsertAccObj( pAcc,pAccessible);
81 //add all oldValue's existing children
82 pAgent->InsertChildrenAccObj(pAcc);
83 pAgent->NotifyAccEvent(UM_EVENT_CHILD_ADDED, pAcc);
84 }
85 else
86 {}
87 }
88 else if (oldValue >>= xChild)
89 {
90 //delete an existing child
91 if(xChild.is())
92 {
93 XAccessible* pAcc = xChild.get();
94 pAgent->NotifyAccEvent(UM_EVENT_CHILD_REMOVED, pAcc);
95 //delete all oldValue's existing children
96 pAgent->DeleteChildrenAccObj( pAcc );
97 //delete this child
98 pAgent->DeleteAccObj( pAcc );
99 }
100 else
101 {}
102 }
103
104 }
105
106 /**
107 * handle the SELECTION_CHANGED event
108 */
handleSelectionChangedEvent()109 void AccMenuEventListener::handleSelectionChangedEvent()
110 {
111 pAgent->NotifyAccEvent(UM_EVENT_SELECTION_CHANGED, pAccessible);
112 }
113
114 /**
115 * handle the Menu_popup event
116 */
fireStatePropertyChange(short state,bool set)117 void AccMenuEventListener::fireStatePropertyChange(short state, bool set)
118 {
119 if( set )
120 {
121 // new value
122 switch(state)
123 {
124 //for sub menu is popup, there is a menu selected event.
125 case AccessibleStateType::SELECTED:
126 pAgent->IncreaseState( pAccessible, state);
127
128 pAgent->UpdateChildState(pAccessible);
129 break;
130 default:
131 AccComponentEventListener::fireStatePropertyChange(state, set
132 );
133 break;
134 }
135 }
136 else
137 {
138 switch(state)
139 {
140 //for sub menu is popup, there is a menu selected event.
141 case AccessibleStateType::SELECTED:
142 pAgent->DecreaseState( pAccessible, state );
143
144 break;
145 default:
146 AccComponentEventListener::fireStatePropertyChange(state, set
147 );
148 break;
149 }
150 }
151 }
152