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