fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / winaccessibility / source / service / AccComponentEventListener.cxx
blob4a60dd771191dd9bae19c90ab56c040f0442839e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/accessibility/XAccessible.hpp>
21 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
22 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
23 #include <com/sun/star/accessibility/AccessibleRole.hpp>
24 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
26 #include <vcl/svapp.hxx>
28 #include "AccComponentEventListener.hxx"
29 #include "AccObjectManagerAgent.hxx"
30 #include "unomsaaevent.hxx"
32 using namespace com::sun::star::uno;
33 using namespace com::sun::star::accessibility;
35 AccComponentEventListener::AccComponentEventListener(com::sun::star::accessibility::XAccessible* pAcc, AccObjectManagerAgent* Agent)
36 :AccEventListener(pAcc, Agent)
40 AccComponentEventListener::~AccComponentEventListener()
44 /**
45 * Uno's event notifier when event is captured
47 * @param AccessibleEventObject the event object which contains information about event
49 void AccComponentEventListener::notifyEvent( const ::com::sun::star::accessibility::AccessibleEventObject& aEvent )
50 throw (::com::sun::star::uno::RuntimeException)
52 SolarMutexGuard g;
54 switch (aEvent.EventId)
56 case AccessibleEventId::VALUE_CHANGED:
57 HandleValueChangedEvent(aEvent.OldValue, aEvent.NewValue);
58 break;
59 case AccessibleEventId::ACTION_CHANGED:
60 HandleActionChangedEvent();
61 break;
62 case AccessibleEventId::TEXT_CHANGED:
63 HandleTextChangedEvent(aEvent.OldValue, aEvent.NewValue);
64 break;
65 case AccessibleEventId::CARET_CHANGED:
66 HandleCaretChangedEvent(aEvent.OldValue, aEvent.NewValue);
67 break;
68 case AccessibleEventId::VISIBLE_DATA_CHANGED:
69 HandleVisibleDataChangedEvent();
70 break;
71 case AccessibleEventId::BOUNDRECT_CHANGED:
72 HandleBoundrectChangedEvent();
73 break;
74 case AccessibleEventId::SELECTION_CHANGED:
75 HandleSelectionChangedEventNoArgs();
76 break;
77 //to add TEXT_SELECTION_CHANGED event
78 case AccessibleEventId::TEXT_SELECTION_CHANGED:
79 HandleTextSelectionChangedEvent();
80 break;
81 //End
82 default:
83 AccEventListener::notifyEvent(aEvent);
84 break;
88 /**
89 * handle the VALUE_CHANGED event
91 * @param oldValue the old value of the source of event
92 * @param newValue the new value of the source of event
94 void AccComponentEventListener::HandleValueChangedEvent(Any oldValue, Any newValue)
96 pAgent->UpdateValue(m_xAccessible.get());
97 pAgent->NotifyAccEvent(UM_EVENT_OBJECT_VALUECHANGE, m_xAccessible.get());
101 * handle the NAME_CHANGED event
103 void AccComponentEventListener::HandleActionChangedEvent()
105 pAgent->UpdateAction(m_xAccessible.get());
106 pAgent->NotifyAccEvent(UM_EVENT_OBJECT_DEFACTIONCHANGE, m_xAccessible.get());
110 * handle the TEXT_CHANGED event
112 * @param oldValue the old value of the source of event
113 * @param newValue the new value of the source of event
115 void AccComponentEventListener::HandleTextChangedEvent(Any oldValue, Any newValue)
117 pAgent->UpdateValue(m_xAccessible.get(), newValue);
118 pAgent->NotifyAccEvent(UM_EVENT_OBJECT_VALUECHANGE, m_xAccessible.get());
122 * handle the CARET_CHANGED event
124 * @param oldValue the old value of the source of event
125 * @param newValue the new value of the source of event
127 void AccComponentEventListener::HandleCaretChangedEvent(Any oldValue, Any newValue)
129 pAgent->NotifyAccEvent(UM_EVENT_OBJECT_CARETCHANGE, m_xAccessible.get());
133 * set the new state and fire the MSAA event
135 * @param state new state id
136 * @param enable true if state is set, false if state is unset
138 void AccComponentEventListener::SetComponentState(short state, bool enable)
140 // only the following state can be fired state event.
141 switch (state)
143 case AccessibleStateType::CHECKED:
144 case AccessibleStateType::PRESSED:
145 case AccessibleStateType::SELECTED:
146 case AccessibleStateType::ARMED:
147 case AccessibleStateType::INDETERMINATE:
148 case AccessibleStateType::SHOWING:
149 FireStatePropertyChange(state, enable);
150 break;
151 case AccessibleStateType::VISIBLE:
152 if (GetRole() == AccessibleRole::MENU_ITEM)
154 if(enable)
156 pAgent->IncreaseState(m_xAccessible.get(), AccessibleStateType::VISIBLE);
157 pAgent->IncreaseState(m_xAccessible.get(), AccessibleStateType::FOCUSABLE);
159 else
161 pAgent->DecreaseState(m_xAccessible.get(), AccessibleStateType::VISIBLE);
162 pAgent->DecreaseState(m_xAccessible.get(), AccessibleStateType::FOCUSABLE);
165 else
167 FireStatePropertyChange(state, enable);
169 break;
170 case AccessibleStateType::FOCUSED:
171 FireStateFocusedChange(enable);
172 break;
173 case AccessibleStateType::ENABLED:
174 if(enable)
176 pAgent->UpdateState(m_xAccessible.get());
177 pAgent->DecreaseState(m_xAccessible.get(), AccessibleStateType::DEFUNC);
178 // 8. label should have no FOCUSABLE state state, Firefox has READONLY state, we can also have.
179 if ( GetRole() != AccessibleRole::LABEL
180 && GetRole() != AccessibleRole::SCROLL_BAR)
182 pAgent->IncreaseState(m_xAccessible.get(), AccessibleStateType::FOCUSABLE);
185 else
187 pAgent->UpdateState(m_xAccessible.get());
188 pAgent->IncreaseState(m_xAccessible.get(), AccessibleStateType::DEFUNC);
189 pAgent->DecreaseState(m_xAccessible.get(), AccessibleStateType::FOCUSABLE);
191 break;
192 case AccessibleStateType::ACTIVE:
193 // Only frames should be active
194 // no msaa state mapping
195 break;
196 default:
197 break;
202 * fire the MSAA state changed event
204 * @param state the state id
205 * @param set true if state is set, false if state is unset
207 void AccComponentEventListener::FireStatePropertyChange(short state, bool set)
209 if( set)
211 // new value
212 switch(state)
214 case AccessibleStateType::CHECKED:
215 case AccessibleStateType::INDETERMINATE:
216 pAgent->IncreaseState(m_xAccessible.get(), state);
217 pAgent->UpdateAction(m_xAccessible.get());
219 if(!pAgent->IsSpecialToolboItem(m_xAccessible.get()))
221 pAgent->NotifyAccEvent(UM_EVENT_STATE_CHECKED, m_xAccessible.get());
223 break;
224 case AccessibleStateType::PRESSED:
225 pAgent->IncreaseState(m_xAccessible.get(), state);
226 pAgent->NotifyAccEvent(UM_EVENT_STATE_PRESSED, m_xAccessible.get());
227 break;
228 case AccessibleStateType::SELECTED:
229 pAgent->IncreaseState(m_xAccessible.get(), state);
230 break;
231 case AccessibleStateType::ARMED:
232 pAgent->IncreaseState(m_xAccessible.get(), state);
233 pAgent->NotifyAccEvent(UM_EVENT_STATE_ARMED, m_xAccessible.get());
234 break;
235 case AccessibleStateType::SHOWING:
236 pAgent->DecreaseState(m_xAccessible.get(), AccessibleStateType::DEFUNC);
237 // UNO !SHOWING == MSAA OFFSCREEN
238 pAgent->IncreaseState(m_xAccessible.get(), AccessibleStateType::SHOWING );
239 break;
240 case AccessibleStateType::VISIBLE:
241 // UNO !VISIBLE == MSAA INVISIBLE
242 pAgent->IncreaseState(m_xAccessible.get(), AccessibleStateType::VISIBLE );
243 break;
244 default:
245 break;
248 else
250 // old value
251 switch(state)
253 case AccessibleStateType::CHECKED:
254 case AccessibleStateType::INDETERMINATE:
255 pAgent->DecreaseState(m_xAccessible.get(), state);
256 pAgent->UpdateAction(m_xAccessible.get());
258 if(!pAgent->IsSpecialToolboItem(m_xAccessible.get()))
260 pAgent->NotifyAccEvent(UM_EVENT_STATE_CHECKED, m_xAccessible.get());
262 break;
263 case AccessibleStateType::PRESSED:
264 pAgent->DecreaseState(m_xAccessible.get(), state);
265 pAgent->NotifyAccEvent(UM_EVENT_STATE_PRESSED, m_xAccessible.get());
266 break;
267 case AccessibleStateType::SELECTED:
268 pAgent->DecreaseState(m_xAccessible.get(), state);
269 //if the state is unset, no need to send MSAA SELECTION event
270 //pAgent->NotifyAccEvent(UM_EVENT_STATE_SELECTED, m_xAccessible.get());
271 break;
272 case AccessibleStateType::ARMED:
274 pAgent->DecreaseState(m_xAccessible.get(), state);
275 //if the state is unset, no need to send MSAA MENU event
276 //pAgent->NotifyAccEvent(UM_EVENT_STATE_ARMED, m_xAccessible.get());
278 break;
279 case AccessibleStateType::SHOWING:
280 pAgent->DecreaseState(m_xAccessible.get(), AccessibleStateType::DEFUNC);
281 // UNO !SHOWING == MSAA OFFSCREEN
282 pAgent->DecreaseState(m_xAccessible.get(), AccessibleStateType::SHOWING);
283 break;
284 case AccessibleStateType::VISIBLE:
285 // UNO !VISIBLE == MSAA INVISIBLE
286 pAgent->DecreaseState(m_xAccessible.get(), AccessibleStateType::VISIBLE);
287 break;
289 default:
290 break;
296 * handle the focused event
298 * @param enable true if get focus, false if lose focus
300 void AccComponentEventListener::FireStateFocusedChange(bool enable)
302 if(enable)
304 if (GetParentRole() != AccessibleRole::COMBO_BOX)
305 pAgent->NotifyAccEvent(UM_EVENT_STATE_FOCUSED, m_xAccessible.get());
307 else
309 //if lose focus, no need to send MSAA FOCUS event
310 pAgent->DecreaseState(m_xAccessible.get(), AccessibleStateType::FOCUSED);
314 void AccComponentEventListener::HandleSelectionChangedEventNoArgs()
316 pAgent->NotifyAccEvent(UM_EVENT_SELECTION_CHANGED, m_xAccessible.get());
319 //add TEXT_SELECTION_CHANGED event
320 void AccComponentEventListener::HandleTextSelectionChangedEvent()
322 pAgent->NotifyAccEvent(UM_EVENT_TEXT_SELECTION_CHANGED, m_xAccessible.get());
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */